Skip to content

Commit e369246

Browse files
ukleinekgregkh
authored andcommitted
pwm: Assume a disabled PWM to emit a constant inactive output
[ Upstream commit b2eaa11 ] Some PWM hardwares (e.g. MC33XS2410) cannot implement a zero duty cycle but can instead disable the hardware which also results in a constant inactive output. There are some checks (enabled with CONFIG_PWM_DEBUG) to help implementing a driver without violating the normal rounding rules. Make them less strict to let above described hardware pass without warning. Reported-by: Dimitri Fedrau <dima.fedrau@gmail.com> Link: https://lore.kernel.org/r/20241103205215.GA509903@debian Fixes: 3ad1f3a ("pwm: Implement some checks for lowlevel drivers") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Reviewed-by: Dimitri Fedrau <dima.fedrau@gmail.com> Tested-by: Dimitri Fedrau <dima.fedrau@gmail.com> Link: https://lore.kernel.org/r/20241105153521.1001864-2-u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 11b0543 commit e369246

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

drivers/pwm/core.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,19 @@ static void pwm_apply_debug(struct pwm_device *pwm,
7575
state->duty_cycle < state->period)
7676
dev_warn(pwmchip_parent(chip), ".apply ignored .polarity\n");
7777

78-
if (state->enabled &&
78+
if (state->enabled && s2.enabled &&
7979
last->polarity == state->polarity &&
8080
last->period > s2.period &&
8181
last->period <= state->period)
8282
dev_warn(pwmchip_parent(chip),
8383
".apply didn't pick the best available period (requested: %llu, applied: %llu, possible: %llu)\n",
8484
state->period, s2.period, last->period);
8585

86-
if (state->enabled && state->period < s2.period)
86+
/*
87+
* Rounding period up is fine only if duty_cycle is 0 then, because a
88+
* flat line doesn't have a characteristic period.
89+
*/
90+
if (state->enabled && s2.enabled && state->period < s2.period && s2.duty_cycle)
8791
dev_warn(pwmchip_parent(chip),
8892
".apply is supposed to round down period (requested: %llu, applied: %llu)\n",
8993
state->period, s2.period);
@@ -99,7 +103,7 @@ static void pwm_apply_debug(struct pwm_device *pwm,
99103
s2.duty_cycle, s2.period,
100104
last->duty_cycle, last->period);
101105

102-
if (state->enabled && state->duty_cycle < s2.duty_cycle)
106+
if (state->enabled && s2.enabled && state->duty_cycle < s2.duty_cycle)
103107
dev_warn(pwmchip_parent(chip),
104108
".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n",
105109
state->duty_cycle, state->period,

0 commit comments

Comments
 (0)