linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] drm/bridge: it6505: Power management fixes for it6505 bridge
@ 2022-10-03  5:03 Pin-yen Lin
  2022-10-03  5:03 ` [PATCH v2 1/2] drm/bridge: it6505: Adapt runtime power management framework Pin-yen Lin
  2022-10-03  5:03 ` [PATCH v2 2/2] drm/bridge: it6505: Add pre_enable/post_disable callback Pin-yen Lin
  0 siblings, 2 replies; 5+ messages in thread
From: Pin-yen Lin @ 2022-10-03  5:03 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter
  Cc: linux-kernel, Hermes Wu, AngeloGioacchino Del Regno, Allen Chen,
	Hsin-Yi Wang, dri-devel, Pin-yen Lin

This series contains 2 fixes related to it6505 power management.

Changes in v2:
- Handle the error from pm_runtime_get_sync in it6505_extcon_work

Pin-yen Lin (2):
  drm/bridge: it6505: Adapt runtime power management framework
  drm/bridge: it6505: Add pre_enable/post_disable callback

 drivers/gpu/drm/bridge/ite-it6505.c | 57 ++++++++++++++++++++++++-----
 1 file changed, 48 insertions(+), 9 deletions(-)

-- 
2.38.0.rc1.362.ged0d419d3c-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] drm/bridge: it6505: Adapt runtime power management framework
  2022-10-03  5:03 [PATCH v2 0/2] drm/bridge: it6505: Power management fixes for it6505 bridge Pin-yen Lin
@ 2022-10-03  5:03 ` Pin-yen Lin
  2022-10-03 11:38   ` AngeloGioacchino Del Regno
  2022-10-03  5:03 ` [PATCH v2 2/2] drm/bridge: it6505: Add pre_enable/post_disable callback Pin-yen Lin
  1 sibling, 1 reply; 5+ messages in thread
From: Pin-yen Lin @ 2022-10-03  5:03 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter
  Cc: linux-kernel, Hermes Wu, AngeloGioacchino Del Regno, Allen Chen,
	Hsin-Yi Wang, dri-devel, Pin-yen Lin

Use pm_runtime_(get|put)_sync to control the bridge power, and add
SET_SYSTEM_SLEEP_PM_OPS with pm_runtime_force_(suspend|resume) to it6505
driver. Without SET_SYSTEM_SLEEP_PM_OPS, the bridge will be powered on
unnecessarily when no external display is connected.

Fixes: b5c84a9edcd4 ("drm/bridge: add it6505 driver")
Signed-off-by: Pin-yen Lin <treapking@chromium.org>

---

Changes in v2:
- Handle the error from pm_runtime_get_sync in it6505_extcon_work

 drivers/gpu/drm/bridge/ite-it6505.c | 33 +++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
index 2bb957cffd94..685d8e750b12 100644
--- a/drivers/gpu/drm/bridge/ite-it6505.c
+++ b/drivers/gpu/drm/bridge/ite-it6505.c
@@ -421,6 +421,7 @@ struct it6505 {
 	struct notifier_block event_nb;
 	struct extcon_dev *extcon;
 	struct work_struct extcon_wq;
+	int extcon_state;
 	enum drm_connector_status connector_status;
 	enum link_train_status link_state;
 	struct work_struct link_works;
@@ -2685,31 +2686,42 @@ static void it6505_extcon_work(struct work_struct *work)
 {
 	struct it6505 *it6505 = container_of(work, struct it6505, extcon_wq);
 	struct device *dev = &it6505->client->dev;
-	int state = extcon_get_state(it6505->extcon, EXTCON_DISP_DP);
-	unsigned int pwroffretry = 0;
+	int state, ret;
 
 	if (it6505->enable_drv_hold)
 		return;
 
 	mutex_lock(&it6505->extcon_lock);
 
+	state = extcon_get_state(it6505->extcon, EXTCON_DISP_DP);
 	DRM_DEV_DEBUG_DRIVER(dev, "EXTCON_DISP_DP = 0x%02x", state);
+
+	if (state == it6505->extcon_state)
+		goto unlock;
+
 	if (state > 0) {
 		DRM_DEV_DEBUG_DRIVER(dev, "start to power on");
 		msleep(100);
-		it6505_poweron(it6505);
+		ret = pm_runtime_get_sync(dev);
+
+		/*
+		 * On system resume, extcon_work can be triggered before
+		 * pm_runtime_force_resume re-enables runtime power management.
+		 * Handling the error here to make sure the bridge is powered on.
+		 */
+		if (ret)
+			it6505_poweron(it6505);
 	} else {
 		DRM_DEV_DEBUG_DRIVER(dev, "start to power off");
-		while (it6505_poweroff(it6505) && pwroffretry++ < 5) {
-			DRM_DEV_DEBUG_DRIVER(dev, "power off fail %d times",
-					     pwroffretry);
-		}
+		pm_runtime_put_sync(dev);
 
 		drm_helper_hpd_irq_event(it6505->bridge.dev);
 		memset(it6505->dpcd, 0, sizeof(it6505->dpcd));
 		DRM_DEV_DEBUG_DRIVER(dev, "power off it6505 success!");
 	}
+	it6505->extcon_state = state;
 
+unlock:
 	mutex_unlock(&it6505->extcon_lock);
 }
 
@@ -3032,8 +3044,10 @@ static __maybe_unused int it6505_bridge_suspend(struct device *dev)
 	return it6505_poweroff(it6505);
 }
 
-static SIMPLE_DEV_PM_OPS(it6505_bridge_pm_ops, it6505_bridge_suspend,
-			 it6505_bridge_resume);
+static const struct dev_pm_ops it6505_bridge_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
+	SET_RUNTIME_PM_OPS(it6505_bridge_suspend, it6505_bridge_resume, NULL)
+};
 
 static int it6505_init_pdata(struct it6505 *it6505)
 {
@@ -3315,6 +3329,7 @@ static int it6505_i2c_probe(struct i2c_client *client,
 
 	DRM_DEV_DEBUG_DRIVER(dev, "it6505 device name: %s", dev_name(dev));
 	debugfs_init(it6505);
+	pm_runtime_enable(dev);
 
 	it6505->bridge.funcs = &it6505_bridge_funcs;
 	it6505->bridge.type = DRM_MODE_CONNECTOR_DisplayPort;
-- 
2.38.0.rc1.362.ged0d419d3c-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] drm/bridge: it6505: Add pre_enable/post_disable callback
  2022-10-03  5:03 [PATCH v2 0/2] drm/bridge: it6505: Power management fixes for it6505 bridge Pin-yen Lin
  2022-10-03  5:03 ` [PATCH v2 1/2] drm/bridge: it6505: Adapt runtime power management framework Pin-yen Lin
@ 2022-10-03  5:03 ` Pin-yen Lin
  2022-10-03 11:38   ` AngeloGioacchino Del Regno
  1 sibling, 1 reply; 5+ messages in thread
From: Pin-yen Lin @ 2022-10-03  5:03 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter
  Cc: linux-kernel, Hermes Wu, AngeloGioacchino Del Regno, Allen Chen,
	Hsin-Yi Wang, dri-devel, Pin-yen Lin

Add atomic_pre_enable and atomic_post_disable callback to make sure the
bridge is not powered off until atomic_post_disable is called. This
prevents a power leakage when it6505 is powered off, but the upstream
DRM bridge is still sending display signals.

Fixes: b5c84a9edcd4 ("drm/bridge: add it6505 driver")
Signed-off-by: Pin-yen Lin <treapking@chromium.org>

---

(no changes since v1)

 drivers/gpu/drm/bridge/ite-it6505.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
index 685d8e750b12..27de6652f842 100644
--- a/drivers/gpu/drm/bridge/ite-it6505.c
+++ b/drivers/gpu/drm/bridge/ite-it6505.c
@@ -2992,6 +2992,28 @@ static void it6505_bridge_atomic_disable(struct drm_bridge *bridge,
 	}
 }
 
+static void it6505_bridge_atomic_pre_enable(struct drm_bridge *bridge,
+					    struct drm_bridge_state *old_state)
+{
+	struct it6505 *it6505 = bridge_to_it6505(bridge);
+	struct device *dev = &it6505->client->dev;
+
+	DRM_DEV_DEBUG_DRIVER(dev, "start");
+
+	pm_runtime_get_sync(dev);
+}
+
+static void it6505_bridge_atomic_post_disable(struct drm_bridge *bridge,
+					      struct drm_bridge_state *old_state)
+{
+	struct it6505 *it6505 = bridge_to_it6505(bridge);
+	struct device *dev = &it6505->client->dev;
+
+	DRM_DEV_DEBUG_DRIVER(dev, "start");
+
+	pm_runtime_put_sync(dev);
+}
+
 static enum drm_connector_status
 it6505_bridge_detect(struct drm_bridge *bridge)
 {
@@ -3026,6 +3048,8 @@ static const struct drm_bridge_funcs it6505_bridge_funcs = {
 	.mode_valid = it6505_bridge_mode_valid,
 	.atomic_enable = it6505_bridge_atomic_enable,
 	.atomic_disable = it6505_bridge_atomic_disable,
+	.atomic_pre_enable = it6505_bridge_atomic_pre_enable,
+	.atomic_post_disable = it6505_bridge_atomic_post_disable,
 	.detect = it6505_bridge_detect,
 	.get_edid = it6505_bridge_get_edid,
 };
-- 
2.38.0.rc1.362.ged0d419d3c-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] drm/bridge: it6505: Add pre_enable/post_disable callback
  2022-10-03  5:03 ` [PATCH v2 2/2] drm/bridge: it6505: Add pre_enable/post_disable callback Pin-yen Lin
@ 2022-10-03 11:38   ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 5+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-10-03 11:38 UTC (permalink / raw)
  To: Pin-yen Lin, Andrzej Hajda, Neil Armstrong, Robert Foss,
	Laurent Pinchart, Jonas Karlman, Jernej Skrabec, David Airlie,
	Daniel Vetter
  Cc: linux-kernel, Hermes Wu, Allen Chen, Hsin-Yi Wang, dri-devel

Il 03/10/22 07:03, Pin-yen Lin ha scritto:
> Add atomic_pre_enable and atomic_post_disable callback to make sure the
> bridge is not powered off until atomic_post_disable is called. This
> prevents a power leakage when it6505 is powered off, but the upstream
> DRM bridge is still sending display signals.
> 
> Fixes: b5c84a9edcd4 ("drm/bridge: add it6505 driver")
> Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> 

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] drm/bridge: it6505: Adapt runtime power management framework
  2022-10-03  5:03 ` [PATCH v2 1/2] drm/bridge: it6505: Adapt runtime power management framework Pin-yen Lin
@ 2022-10-03 11:38   ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 5+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-10-03 11:38 UTC (permalink / raw)
  To: Pin-yen Lin, Andrzej Hajda, Neil Armstrong, Robert Foss,
	Laurent Pinchart, Jonas Karlman, Jernej Skrabec, David Airlie,
	Daniel Vetter
  Cc: linux-kernel, Hermes Wu, Allen Chen, Hsin-Yi Wang, dri-devel

Il 03/10/22 07:03, Pin-yen Lin ha scritto:
> Use pm_runtime_(get|put)_sync to control the bridge power, and add
> SET_SYSTEM_SLEEP_PM_OPS with pm_runtime_force_(suspend|resume) to it6505
> driver. Without SET_SYSTEM_SLEEP_PM_OPS, the bridge will be powered on
> unnecessarily when no external display is connected.
> 
> Fixes: b5c84a9edcd4 ("drm/bridge: add it6505 driver")
> Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> 
> ---
> 
> Changes in v2:
> - Handle the error from pm_runtime_get_sync in it6505_extcon_work
> 
>   drivers/gpu/drm/bridge/ite-it6505.c | 33 +++++++++++++++++++++--------
>   1 file changed, 24 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
> index 2bb957cffd94..685d8e750b12 100644
> --- a/drivers/gpu/drm/bridge/ite-it6505.c
> +++ b/drivers/gpu/drm/bridge/ite-it6505.c
> @@ -421,6 +421,7 @@ struct it6505 {
>   	struct notifier_block event_nb;
>   	struct extcon_dev *extcon;
>   	struct work_struct extcon_wq;
> +	int extcon_state;
>   	enum drm_connector_status connector_status;
>   	enum link_train_status link_state;
>   	struct work_struct link_works;
> @@ -2685,31 +2686,42 @@ static void it6505_extcon_work(struct work_struct *work)
>   {
>   	struct it6505 *it6505 = container_of(work, struct it6505, extcon_wq);
>   	struct device *dev = &it6505->client->dev;
> -	int state = extcon_get_state(it6505->extcon, EXTCON_DISP_DP);
> -	unsigned int pwroffretry = 0;
> +	int state, ret;
>   
>   	if (it6505->enable_drv_hold)
>   		return;
>   
>   	mutex_lock(&it6505->extcon_lock);
>   
> +	state = extcon_get_state(it6505->extcon, EXTCON_DISP_DP);
>   	DRM_DEV_DEBUG_DRIVER(dev, "EXTCON_DISP_DP = 0x%02x", state);
> +
> +	if (state == it6505->extcon_state)
> +		goto unlock;

Even if it's unlikely for anything bad to happen, please add error handling,
or we might end up with unbalanced pm_runtime calls.

	if (state == it6505->extcon_state || unlikely(state < 0))
		goto unlock;
	it6505->extcon_state = state;
	if (state) {
		....
	} else {
		....
	}

Regards,
Angelo


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-03 11:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-03  5:03 [PATCH v2 0/2] drm/bridge: it6505: Power management fixes for it6505 bridge Pin-yen Lin
2022-10-03  5:03 ` [PATCH v2 1/2] drm/bridge: it6505: Adapt runtime power management framework Pin-yen Lin
2022-10-03 11:38   ` AngeloGioacchino Del Regno
2022-10-03  5:03 ` [PATCH v2 2/2] drm/bridge: it6505: Add pre_enable/post_disable callback Pin-yen Lin
2022-10-03 11:38   ` AngeloGioacchino Del Regno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).