Skip to content

Commit 38ba835

Browse files
Marek Vasutthierryreding
authored andcommitted
pwm: sysfs: Do not apply state to already disabled PWMs
If the PWM is exported but not enabled, do not call pwm_class_apply_state(). First of all, in this case, period may still be unconfigured and this would make pwm_class_apply_state() return -EINVAL, and then suspend would fail. Second, it makes little sense to apply state onto PWM that is not enabled before suspend. 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 ... " Do not call pwm_class_apply_state() in case the PWM is disabled to fix this issue. Fixes: 7fd4edc ("pwm: sysfs: Add suspend/resume support") Signed-off-by: Marek Vasut <marex@denx.de> Fixes: ef2bf49 ("pwm: Improve args checking in pwm_apply_state()") Reviewed-by: Brian Norris <briannorris@chromium.org> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
1 parent 661dfb7 commit 38ba835

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

drivers/pwm/sysfs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ static int pwm_class_resume_npwm(struct device *parent, unsigned int npwm)
424424
if (!export)
425425
continue;
426426

427+
/* If pwmchip was not enabled before suspend, do nothing. */
428+
if (!export->suspend.enabled) {
429+
/* release lock taken in pwm_class_get_state */
430+
mutex_unlock(&export->lock);
431+
continue;
432+
}
433+
427434
state.enabled = export->suspend.enabled;
428435
ret = pwm_class_apply_state(export, pwm, &state);
429436
if (ret < 0)
@@ -448,7 +455,17 @@ static int pwm_class_suspend(struct device *parent)
448455
if (!export)
449456
continue;
450457

458+
/*
459+
* If pwmchip was not enabled before suspend, save
460+
* state for resume time and do nothing else.
461+
*/
451462
export->suspend = state;
463+
if (!state.enabled) {
464+
/* release lock taken in pwm_class_get_state */
465+
mutex_unlock(&export->lock);
466+
continue;
467+
}
468+
452469
state.enabled = false;
453470
ret = pwm_class_apply_state(export, pwm, &state);
454471
if (ret < 0) {

0 commit comments

Comments
 (0)