0005-drm-bridge-ps8640-Rework-power-state-handling.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. From 5bb60fe7c748a0aae2bdbab10e73b2dc48c09dda Mon Sep 17 00:00:00 2001
  2. From: Enric Balletbo i Serra <enric.balletbo@collabora.com>
  3. Date: Wed, 26 Aug 2020 10:15:26 +0200
  4. Subject: [PATCH 5/5] drm/bridge: ps8640: Rework power state handling
  5. The get_edid() callback can be triggered anytime by an ioctl, i.e
  6. drm_mode_getconnector (ioctl)
  7. -> drm_helper_probe_single_connector_modes
  8. -> drm_bridge_connector_get_modes
  9. -> ps8640_bridge_get_edid
  10. Actually if the bridge pre_enable() function was not called before
  11. get_edid(), the driver will not be able to get the EDID properly and
  12. display will not work until a second get_edid() call is issued and if
  13. pre_enable() is called before. The side effect of this, for example, is
  14. that you see anything when `Frecon` starts, neither the splash screen,
  15. until the graphical session manager starts.
  16. To fix this we need to make sure that all we need is enabled before
  17. reading the EDID. This means the following:
  18. 1. If get_edid() is called before having the device powered we need to
  19. power on the device. In such case, the driver will power off again the
  20. device.
  21. 2. If get_edid() is called after having the device powered, all should
  22. just work. We added a powered flag in order to avoid recurrent calls
  23. to ps8640_bridge_poweron() and unneeded delays.
  24. 3. This seems to be specific for this device, but we need to make sure
  25. the panel is powered on before do a power on cycle on this device.
  26. Otherwise the device fails to retrieve the EDID.
  27. Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
  28. ---
  29. drivers/gpu/drm/bridge/parade-ps8640.c | 64 +++++++++++++++++++++++---
  30. 1 file changed, 58 insertions(+), 6 deletions(-)
  31. diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c b/drivers/gpu/drm/bridge/parade-ps8640.c
  32. index 9f7b7a9c53c5..c5d76e209bda 100644
  33. --- a/drivers/gpu/drm/bridge/parade-ps8640.c
  34. +++ b/drivers/gpu/drm/bridge/parade-ps8640.c
  35. @@ -65,6 +65,7 @@ struct ps8640 {
  36. struct regulator_bulk_data supplies[2];
  37. struct gpio_desc *gpio_reset;
  38. struct gpio_desc *gpio_powerdown;
  39. + bool powered;
  40. };
  41. static inline struct ps8640 *bridge_to_ps8640(struct drm_bridge *e)
  42. @@ -91,13 +92,15 @@ static int ps8640_bridge_vdo_control(struct ps8640 *ps_bridge,
  43. return 0;
  44. }
  45. -static void ps8640_pre_enable(struct drm_bridge *bridge)
  46. +static void ps8640_bridge_poweron(struct ps8640 *ps_bridge)
  47. {
  48. - struct ps8640 *ps_bridge = bridge_to_ps8640(bridge);
  49. struct i2c_client *client = ps_bridge->page[PAGE2_TOP_CNTL];
  50. unsigned long timeout;
  51. int ret, status;
  52. + if (ps_bridge->powered)
  53. + return;
  54. +
  55. ret = regulator_bulk_enable(ARRAY_SIZE(ps_bridge->supplies),
  56. ps_bridge->supplies);
  57. if (ret < 0) {
  58. @@ -164,6 +167,8 @@ static void ps8640_pre_enable(struct drm_bridge *bridge)
  59. goto err_regulators_disable;
  60. }
  61. + ps_bridge->powered = true;
  62. +
  63. return;
  64. err_regulators_disable:
  65. @@ -171,12 +176,12 @@ static void ps8640_pre_enable(struct drm_bridge *bridge)
  66. ps_bridge->supplies);
  67. }
  68. -static void ps8640_post_disable(struct drm_bridge *bridge)
  69. +static void ps8640_bridge_poweroff(struct ps8640 *ps_bridge)
  70. {
  71. - struct ps8640 *ps_bridge = bridge_to_ps8640(bridge);
  72. int ret;
  73. - ps8640_bridge_vdo_control(ps_bridge, DISABLE);
  74. + if (!ps_bridge->powered)
  75. + return;
  76. gpiod_set_value(ps_bridge->gpio_reset, 1);
  77. gpiod_set_value(ps_bridge->gpio_powerdown, 1);
  78. @@ -184,6 +189,28 @@ static void ps8640_post_disable(struct drm_bridge *bridge)
  79. ps_bridge->supplies);
  80. if (ret < 0)
  81. DRM_ERROR("cannot disable regulators %d\n", ret);
  82. +
  83. + ps_bridge->powered = false;
  84. +}
  85. +
  86. +static void ps8640_pre_enable(struct drm_bridge *bridge)
  87. +{
  88. + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge);
  89. + int ret;
  90. +
  91. + ps8640_bridge_poweron(ps_bridge);
  92. +
  93. + ret = ps8640_bridge_vdo_control(ps_bridge, DISABLE);
  94. + if (ret < 0)
  95. + ps8640_bridge_poweroff(ps_bridge);
  96. +}
  97. +
  98. +static void ps8640_post_disable(struct drm_bridge *bridge)
  99. +{
  100. + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge);
  101. +
  102. + ps8640_bridge_vdo_control(ps_bridge, DISABLE);
  103. + ps8640_bridge_poweroff(ps_bridge);
  104. }
  105. static int ps8640_bridge_attach(struct drm_bridge *bridge,
  106. @@ -249,9 +276,34 @@ static struct edid *ps8640_bridge_get_edid(struct drm_bridge *bridge,
  107. struct drm_connector *connector)
  108. {
  109. struct ps8640 *ps_bridge = bridge_to_ps8640(bridge);
  110. + bool poweroff = !ps_bridge->powered;
  111. + struct edid *edid;
  112. +
  113. + /*
  114. + * When we end calling get_edid() triggered by an ioctl, i.e
  115. + *
  116. + * drm_mode_getconnector (ioctl)
  117. + * -> drm_helper_probe_single_connector_modes
  118. + * -> drm_bridge_connector_get_modes
  119. + * -> ps8640_bridge_get_edid
  120. + *
  121. + * We need to make sure that what we need is enabled before reading
  122. + * EDID, for this chip, we need to do a full poweron, otherwise it will
  123. + * fail.
  124. + */
  125. + drm_bridge_chain_pre_enable(bridge);
  126. - return drm_get_edid(connector,
  127. + edid = drm_get_edid(connector,
  128. ps_bridge->page[PAGE0_DP_CNTL]->adapter);
  129. +
  130. + /*
  131. + * If we call the get_edid() function without having enabled the chip
  132. + * before, return the chip to its original power state.
  133. + */
  134. + if (poweroff)
  135. + drm_bridge_chain_post_disable(bridge);
  136. +
  137. + return edid;
  138. }
  139. static const struct drm_bridge_funcs ps8640_bridge_funcs = {
  140. --
  141. 2.25.1