Skip to content

Commit

Permalink
pwm: stm32: Search an appropriate duty_cycle if period cannot be modi…
Browse files Browse the repository at this point in the history
…fied

If another channel is already enabled period must not be modified. If
the requested period is smaller than this unchangable period the driver
is still supposed to search a duty_cycle according to the usual rounding
rules.

So don't set the duty_cycle to 0 but continue to determine an
appropriate value for ccr.

Fixes: deaba9c ("pwm: stm32: Implementation of the waveform callbacks")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/f0c50df31daa3d6069bfa8d7fb3e71fae241b026.1743844730.git.u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
  • Loading branch information
Uwe Kleine-König authored and Uwe Kleine-König committed Apr 7, 2025
1 parent 00e53d0 commit fda6e00
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions drivers/pwm/pwm-stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,16 @@ static int stm32_pwm_round_waveform_tohw(struct pwm_chip *chip,
if (ret)
goto out;

/*
* calculate the best value for ARR for the given PSC, refuse if
* the resulting period gets bigger than the requested one.
*/
arr = mul_u64_u64_div_u64(wf->period_length_ns, rate,
(u64)NSEC_PER_SEC * (wfhw->psc + 1));
if (arr <= wfhw->arr) {
/*
* requested period is small than the currently
* requested period is smaller than the currently
* configured and unchangable period, report back the smallest
* possible period, i.e. the current state; Initialize
* ccr to anything valid.
* possible period, i.e. the current state and return 1
* to indicate the wrong rounding direction.
*/
wfhw->ccr = 0;
ret = 1;
goto out;
}

} else {
Expand Down

0 comments on commit fda6e00

Please sign in to comment.