diff mbox series

[v3] backlight: pwm_bl: Disable PWM on shutdown and suspend

Message ID 20230926150116.2124384-1-u.kleine-koenig@pengutronix.de
State Superseded
Headers show
Series [v3] backlight: pwm_bl: Disable PWM on shutdown and suspend | expand

Commit Message

Uwe Kleine-König Sept. 26, 2023, 3:01 p.m. UTC
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,

On Tue, Sep 26, 2023 at 12:11:37PM +0100, Daniel Thompson wrote:
> Changes proposed look good (and the comment about badly designed boards
> going to HiZ state we super helpful).

I didn't mention Hi-Z and note that disabling a PWM can even result in
the hardware driving to the active level. (This can happen for example
for pwm-mxs and pwm-imx27.)

> Only thing from my is why there is no attempt to disable the PWM
> from the .remove_new() callback.

Good catch, good I didn't manage to send out a v3 for the email address
fix yet :-) So here comes a v3 with two improvments:

Changes since v2
(https://lore.kernel.org/dri-devel/20230926084612.2074692-1-u.kleine-koenig@pengutronix.de):

 - Fix Aisheng Dong's email address
 - also disable PWM in .remove and adapt commit log accordingly (Thanks
   to Daniel Thompson for spotting that).

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


base-commit: 8fff9184d1b5810dca5dd1a02726d4f844af88fc

Comments

kernel test robot Sept. 30, 2023, 4:48 a.m. UTC | #1
Hi Uwe,

kernel test robot noticed the following build errors:

[auto build test ERROR on 8fff9184d1b5810dca5dd1a02726d4f844af88fc]

url:    https://github.com/intel-lab-lkp/linux/commits/Uwe-Kleine-K-nig/backlight-pwm_bl-Disable-PWM-on-shutdown-and-suspend/20230926-230323
base:   8fff9184d1b5810dca5dd1a02726d4f844af88fc
patch link:    https://lore.kernel.org/r/20230926150116.2124384-1-u.kleine-koenig%40pengutronix.de
patch subject: [PATCH v3] backlight: pwm_bl: Disable PWM on shutdown and suspend
config: mips-allmodconfig (https://download.01.org/0day-ci/archive/20230930/202309301206.OT7dbPq7-lkp@intel.com/config)
compiler: mips-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230930/202309301206.OT7dbPq7-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202309301206.OT7dbPq7-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/video/backlight/pwm_bl.c: In function 'pwm_backlight_remove':
>> drivers/video/backlight/pwm_bl.c:632:33: error: 'state' undeclared (first use in this function); did you mean 'statx'?
     632 |         pwm_get_state(pb->pwm, &state);
         |                                 ^~~~~
         |                                 statx
   drivers/video/backlight/pwm_bl.c:632:33: note: each undeclared identifier is reported only once for each function it appears in


vim +632 drivers/video/backlight/pwm_bl.c

   624	
   625	static void pwm_backlight_remove(struct platform_device *pdev)
   626	{
   627		struct backlight_device *bl = platform_get_drvdata(pdev);
   628		struct pwm_bl_data *pb = bl_get_data(bl);
   629	
   630		backlight_device_unregister(bl);
   631		pwm_backlight_power_off(pb);
 > 632		pwm_get_state(pb->pwm, &state);
   633		state.duty_cycle = 0;
   634		state.enabled = false;
   635		pwm_apply_state(pb->pwm, &state);
   636	
   637		if (pb->exit)
   638			pb->exit(&pdev->dev);
   639	}
   640
diff mbox series

Patch

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index a51fbab96368..390398ae07b9 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -629,6 +629,10 @@  static void pwm_backlight_remove(struct platform_device *pdev)
 
 	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 +642,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 +656,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);