Skip to content

Commit a85e08a

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: axi-pwmgen: Let .round_waveform_tohw() signal when request was rounded up
The .round_waveform_tohw() is supposed to return 1 if the requested waveform cannot be implemented by rounding down all parameters. Also adapt the corresponding comment to better describe why the implemented procedure is right. Signed-off-by: Uwe Kleine-König <[email protected]> Tested-by: Trevor Gamblin <[email protected]> Link: https://lore.kernel.org/r/ba451573f0218d76645f068cec78bd97802cf010.1743844730.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent fda6e00 commit a85e08a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/pwm/pwm-axi-pwmgen.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static int axi_pwmgen_round_waveform_tohw(struct pwm_chip *chip,
7575
{
7676
struct axi_pwmgen_waveform *wfhw = _wfhw;
7777
struct axi_pwmgen_ddata *ddata = axi_pwmgen_ddata_from_chip(chip);
78+
int ret = 0;
7879

7980
if (wf->period_length_ns == 0) {
8081
*wfhw = (struct axi_pwmgen_waveform){
@@ -91,12 +92,15 @@ static int axi_pwmgen_round_waveform_tohw(struct pwm_chip *chip,
9192
if (wfhw->period_cnt == 0) {
9293
/*
9394
* The specified period is too short for the hardware.
94-
* Let's round .duty_cycle down to 0 to get a (somewhat)
95-
* valid result.
95+
* So round up .period_cnt to 1 (i.e. the smallest
96+
* possible period). With .duty_cycle and .duty_offset
97+
* being less than or equal to .period, their rounded
98+
* value must be 0.
9699
*/
97100
wfhw->period_cnt = 1;
98101
wfhw->duty_cycle_cnt = 0;
99102
wfhw->duty_offset_cnt = 0;
103+
ret = 1;
100104
} else {
101105
wfhw->duty_cycle_cnt = min_t(u64,
102106
mul_u64_u32_div(wf->duty_length_ns, ddata->clk_rate_hz, NSEC_PER_SEC),
@@ -111,7 +115,7 @@ static int axi_pwmgen_round_waveform_tohw(struct pwm_chip *chip,
111115
pwm->hwpwm, wf->duty_length_ns, wf->period_length_ns, wf->duty_offset_ns,
112116
ddata->clk_rate_hz, wfhw->period_cnt, wfhw->duty_cycle_cnt, wfhw->duty_offset_cnt);
113117

114-
return 0;
118+
return ret;
115119
}
116120

117121
static int axi_pwmgen_round_waveform_fromhw(struct pwm_chip *chip, struct pwm_device *pwm,

0 commit comments

Comments
 (0)