linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm: core: Permit unset period when applying configuration of disabled PWMs
@ 2023-05-11 18:18 Marek Vasut
  2023-05-11 21:08 ` Brian Norris
  2023-05-12  6:22 ` Uwe Kleine-König
  0 siblings, 2 replies; 8+ messages in thread
From: Marek Vasut @ 2023-05-11 18:18 UTC (permalink / raw)
  To: linux-pwm
  Cc: Marek Vasut, Brian Norris, Uwe Kleine-König,
	Geert Uytterhoeven, Thierry Reding, Yoshihiro Shimoda

In case the PWM is not enabled, the period can still be left unconfigured,
i.e. zero . Currently the pwm_class_apply_state() errors out in such a case.
This e.g. makes suspend fail on systems where pwmchip has been exported via
sysfs interface, but left unconfigured before suspend occurred.

Failing case:
"
$ echo 1 > /sys/class/pwm/pwmchip4/export
$ echo mem > /sys/power/state
...
pwm pwmchip4: PM: dpm_run_callback(): pwm_class_suspend+0x1/0xa8 returns -22
pwm pwmchip4: PM: failed to suspend: error -22
PM: Some devices failed to suspend, or early wake event detected
"

Working case:
"
$ echo 1 > /sys/class/pwm/pwmchip4/export
$ echo 100 > /sys/class/pwm/pwmchip4/pwm1/period
$ echo 10 > /sys/class/pwm/pwmchip4/pwm1/duty_cycle
$ echo mem > /sys/power/state
...
"

Permit unset period in pwm_class_apply_state() in case the PWM is disabled
to fix this issue.

Fixes: ef2bf4997f7d ("pwm: Improve args checking in pwm_apply_state()")
Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: Brian Norris <briannorris@chromium.org>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: linux-pwm@vger.kernel.org
---
 drivers/pwm/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 3dacceaef4a9b..87252b70f1c81 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -510,8 +510,8 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
 	 */
 	might_sleep();
 
-	if (!pwm || !state || !state->period ||
-	    state->duty_cycle > state->period)
+	if (!pwm || !state || (state->enabled &&
+	    (!state->period || state->duty_cycle > state->period)))
 		return -EINVAL;
 
 	chip = pwm->chip;
-- 
2.39.2


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

end of thread, other threads:[~2023-05-16  9:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-11 18:18 [PATCH] pwm: core: Permit unset period when applying configuration of disabled PWMs Marek Vasut
2023-05-11 21:08 ` Brian Norris
2023-05-11 23:32   ` Marek Vasut
2023-05-12  0:51     ` Brian Norris
2023-05-12 16:50       ` Marek Vasut
2023-05-12  6:22 ` Uwe Kleine-König
2023-05-12 12:20   ` Marek Vasut
2023-05-16  9:42     ` Thierry Reding

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).