Skip to content

Commit b2eaa11

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: Assume a disabled PWM to emit a constant inactive output
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>
1 parent 2ea25aa commit b2eaa11

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/pwm/core.c

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

469-
if (state->enabled &&
469+
if (state->enabled && s2.enabled &&
470470
last->polarity == state->polarity &&
471471
last->period > s2.period &&
472472
last->period <= state->period)
473473
dev_warn(pwmchip_parent(chip),
474474
".apply didn't pick the best available period (requested: %llu, applied: %llu, possible: %llu)\n",
475475
state->period, s2.period, last->period);
476476

477-
if (state->enabled && state->period < s2.period)
477+
/*
478+
* Rounding period up is fine only if duty_cycle is 0 then, because a
479+
* flat line doesn't have a characteristic period.
480+
*/
481+
if (state->enabled && s2.enabled && state->period < s2.period && s2.duty_cycle)
478482
dev_warn(pwmchip_parent(chip),
479483
".apply is supposed to round down period (requested: %llu, applied: %llu)\n",
480484
state->period, s2.period);
@@ -490,7 +494,7 @@ static void pwm_apply_debug(struct pwm_device *pwm,
490494
s2.duty_cycle, s2.period,
491495
last->duty_cycle, last->period);
492496

493-
if (state->enabled && state->duty_cycle < s2.duty_cycle)
497+
if (state->enabled && s2.enabled && state->duty_cycle < s2.duty_cycle)
494498
dev_warn(pwmchip_parent(chip),
495499
".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n",
496500
state->duty_cycle, state->period,

0 commit comments

Comments
 (0)