All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] backlight: pwm_bl: Disable PWM on shutdown, suspend and remove
@ 2023-10-09  9:32 Uwe Kleine-König
  2023-10-09 10:18   ` Daniel Thompson
  2023-10-12  9:32 ` Lee Jones
  0 siblings, 2 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2023-10-09  9:32 UTC (permalink / raw)
  To: Lee Jones, Daniel Thompson, Jingoo Han
  Cc: Aisheng Dong, linux-pwm, linux-fbdev, Helge Deller, dri-devel,
	Thierry Reding, kernel

Since commit 00e7e698bff1 ("backlight: pwm_bl: Configure pwm only once
per backlight toggle") calling pwm_backlight_power_off() doesn't disable
the PWM any more. However this is necessary to suspend because PWM
drivers usually refuse to suspend if they are still enabled.

Also adapt shutdown and remove callbacks to disable the PWM for similar
reasons.

Fixes: 00e7e698bff1 ("backlight: pwm_bl: Configure pwm only once per backlight toggle")
Reported-by: Aisheng Dong <aisheng.dong@nxp.com>
Tested-by: Aisheng Dong <aisheng.dong@nxp.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

Changes since v3 (available at
https://lore.kernel.org/linux-fbdev/20230926150116.2124384-1-u.kleine-koenig@pengutronix.de):

 - Fix buildfailure identified by the kernel test robot. (*Sigh*, that's
   what you get if you improve a patch without build testing ...)
 - Fix the Subject to also mention "remove".

Best regards
Uwe

 drivers/video/backlight/pwm_bl.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index a51fbab96368..289bd9ce4d36 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -626,9 +626,14 @@ static void pwm_backlight_remove(struct platform_device *pdev)
 {
 	struct backlight_device *bl = platform_get_drvdata(pdev);
 	struct pwm_bl_data *pb = bl_get_data(bl);
+	struct pwm_state state;
 
 	backlight_device_unregister(bl);
 	pwm_backlight_power_off(pb);
+	pwm_get_state(pb->pwm, &state);
+	state.duty_cycle = 0;
+	state.enabled = false;
+	pwm_apply_state(pb->pwm, &state);
 
 	if (pb->exit)
 		pb->exit(&pdev->dev);
@@ -638,8 +643,13 @@ static void pwm_backlight_shutdown(struct platform_device *pdev)
 {
 	struct backlight_device *bl = platform_get_drvdata(pdev);
 	struct pwm_bl_data *pb = bl_get_data(bl);
+	struct pwm_state state;
 
 	pwm_backlight_power_off(pb);
+	pwm_get_state(pb->pwm, &state);
+	state.duty_cycle = 0;
+	state.enabled = false;
+	pwm_apply_state(pb->pwm, &state);
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -647,12 +657,24 @@ static int pwm_backlight_suspend(struct device *dev)
 {
 	struct backlight_device *bl = dev_get_drvdata(dev);
 	struct pwm_bl_data *pb = bl_get_data(bl);
+	struct pwm_state state;
 
 	if (pb->notify)
 		pb->notify(pb->dev, 0);
 
 	pwm_backlight_power_off(pb);
 
+	/*
+	 * Note that disabling the PWM doesn't guarantee that the output stays
+	 * at its inactive state. However without the PWM disabled, the PWM
+	 * driver refuses to suspend. So disable here even though this might
+	 * enable the backlight on poorly designed boards.
+	 */
+	pwm_get_state(pb->pwm, &state);
+	state.duty_cycle = 0;
+	state.enabled = false;
+	pwm_apply_state(pb->pwm, &state);
+
 	if (pb->notify_after)
 		pb->notify_after(pb->dev, 0);
 

base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
-- 
2.40.1


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

* Re: [PATCH v4] backlight: pwm_bl: Disable PWM on shutdown, suspend and remove
  2023-10-09  9:32 [PATCH v4] backlight: pwm_bl: Disable PWM on shutdown, suspend and remove Uwe Kleine-König
@ 2023-10-09 10:18   ` Daniel Thompson
  2023-10-12  9:32 ` Lee Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Thompson @ 2023-10-09 10:18 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lee Jones, Jingoo Han, Aisheng Dong, linux-pwm, linux-fbdev,
	Helge Deller, dri-devel, Thierry Reding, kernel

On Mon, Oct 09, 2023 at 11:32:23AM +0200, Uwe Kleine-König wrote:
> Since commit 00e7e698bff1 ("backlight: pwm_bl: Configure pwm only once
> per backlight toggle") calling pwm_backlight_power_off() doesn't disable
> the PWM any more. However this is necessary to suspend because PWM
> drivers usually refuse to suspend if they are still enabled.
>
> Also adapt shutdown and remove callbacks to disable the PWM for similar
> reasons.
>
> Fixes: 00e7e698bff1 ("backlight: pwm_bl: Configure pwm only once per backlight toggle")
> Reported-by: Aisheng Dong <aisheng.dong@nxp.com>
> Tested-by: Aisheng Dong <aisheng.dong@nxp.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>


Daniel.

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

* Re: [PATCH v4] backlight: pwm_bl: Disable PWM on shutdown, suspend and remove
@ 2023-10-09 10:18   ` Daniel Thompson
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Thompson @ 2023-10-09 10:18 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Aisheng Dong, linux-pwm, linux-fbdev, Jingoo Han, Helge Deller,
	Lee Jones, dri-devel, Thierry Reding, kernel

On Mon, Oct 09, 2023 at 11:32:23AM +0200, Uwe Kleine-König wrote:
> Since commit 00e7e698bff1 ("backlight: pwm_bl: Configure pwm only once
> per backlight toggle") calling pwm_backlight_power_off() doesn't disable
> the PWM any more. However this is necessary to suspend because PWM
> drivers usually refuse to suspend if they are still enabled.
>
> Also adapt shutdown and remove callbacks to disable the PWM for similar
> reasons.
>
> Fixes: 00e7e698bff1 ("backlight: pwm_bl: Configure pwm only once per backlight toggle")
> Reported-by: Aisheng Dong <aisheng.dong@nxp.com>
> Tested-by: Aisheng Dong <aisheng.dong@nxp.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>


Daniel.

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

* Re: [PATCH v4] backlight: pwm_bl: Disable PWM on shutdown, suspend and remove
  2023-10-09  9:32 [PATCH v4] backlight: pwm_bl: Disable PWM on shutdown, suspend and remove Uwe Kleine-König
  2023-10-09 10:18   ` Daniel Thompson
@ 2023-10-12  9:32 ` Lee Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Lee Jones @ 2023-10-12  9:32 UTC (permalink / raw)
  To: Lee Jones, Daniel Thompson, Jingoo Han, Uwe Kleine-König
  Cc: Aisheng Dong, linux-pwm, linux-fbdev, Helge Deller, dri-devel,
	Thierry Reding, kernel

On Mon, 09 Oct 2023 11:32:23 +0200, Uwe Kleine-König wrote:
> Since commit 00e7e698bff1 ("backlight: pwm_bl: Configure pwm only once
> per backlight toggle") calling pwm_backlight_power_off() doesn't disable
> the PWM any more. However this is necessary to suspend because PWM
> drivers usually refuse to suspend if they are still enabled.
> 
> Also adapt shutdown and remove callbacks to disable the PWM for similar
> reasons.
> 
> [...]

Applied, thanks!

[1/1] backlight: pwm_bl: Disable PWM on shutdown, suspend and remove
      commit: 40da4737717b252fd01d92ff38d3b95a491167cc

--
Lee Jones [李琼斯]


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

end of thread, other threads:[~2023-10-12  9:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09  9:32 [PATCH v4] backlight: pwm_bl: Disable PWM on shutdown, suspend and remove Uwe Kleine-König
2023-10-09 10:18 ` Daniel Thompson
2023-10-09 10:18   ` Daniel Thompson
2023-10-12  9:32 ` Lee Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.