Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

backlight: pwm_bl: Disable PWM on shutdown, suspend and remove

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>
Link: https://lore.kernel.org/r/20231009093223.227286-1-u.kleine-koenig@pengutronix.de
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Uwe Kleine-König and committed by
Lee Jones
40da4737 02c4e661

+22
+22
drivers/video/backlight/pwm_bl.c
··· 626 626 { 627 627 struct backlight_device *bl = platform_get_drvdata(pdev); 628 628 struct pwm_bl_data *pb = bl_get_data(bl); 629 + struct pwm_state state; 629 630 630 631 backlight_device_unregister(bl); 631 632 pwm_backlight_power_off(pb); 633 + pwm_get_state(pb->pwm, &state); 634 + state.duty_cycle = 0; 635 + state.enabled = false; 636 + pwm_apply_state(pb->pwm, &state); 632 637 633 638 if (pb->exit) 634 639 pb->exit(&pdev->dev); ··· 643 638 { 644 639 struct backlight_device *bl = platform_get_drvdata(pdev); 645 640 struct pwm_bl_data *pb = bl_get_data(bl); 641 + struct pwm_state state; 646 642 647 643 pwm_backlight_power_off(pb); 644 + pwm_get_state(pb->pwm, &state); 645 + state.duty_cycle = 0; 646 + state.enabled = false; 647 + pwm_apply_state(pb->pwm, &state); 648 648 } 649 649 650 650 #ifdef CONFIG_PM_SLEEP ··· 657 647 { 658 648 struct backlight_device *bl = dev_get_drvdata(dev); 659 649 struct pwm_bl_data *pb = bl_get_data(bl); 650 + struct pwm_state state; 660 651 661 652 if (pb->notify) 662 653 pb->notify(pb->dev, 0); 663 654 664 655 pwm_backlight_power_off(pb); 656 + 657 + /* 658 + * Note that disabling the PWM doesn't guarantee that the output stays 659 + * at its inactive state. However without the PWM disabled, the PWM 660 + * driver refuses to suspend. So disable here even though this might 661 + * enable the backlight on poorly designed boards. 662 + */ 663 + pwm_get_state(pb->pwm, &state); 664 + state.duty_cycle = 0; 665 + state.enabled = false; 666 + pwm_apply_state(pb->pwm, &state); 665 667 666 668 if (pb->notify_after) 667 669 pb->notify_after(pb->dev, 0);