Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pwm: rzg2l-gpt: Accept requests for too high period length

The period setting is shared for each pair of PWM channels. So if the
twin channel is in use, the period must not be changed. According to the
usual practise to pick the next smaller possible period, accept a
request for a period that is bigger than the unchangable value.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Tested-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20250423095715.2952692-2-u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
e373991e b6b5683e

+8 -4
+8 -4
drivers/pwm/pwm-rzg2l-gpt.c
··· 270 270 * prescale and period can NOT be modified when there are multiple IOs 271 271 * in use with different settings. 272 272 */ 273 - if (rzg2l_gpt->channel_request_count[ch] > 1 && period_ticks != rzg2l_gpt->period_ticks[ch]) 274 - return -EBUSY; 273 + if (rzg2l_gpt->channel_request_count[ch] > 1) { 274 + if (period_ticks < rzg2l_gpt->period_ticks[ch]) 275 + return -EBUSY; 276 + else 277 + period_ticks = rzg2l_gpt->period_ticks[ch]; 278 + } 275 279 276 280 prescale = rzg2l_gpt_calculate_prescale(rzg2l_gpt, period_ticks); 277 281 pv = rzg2l_gpt_calculate_pv_or_dc(period_ticks, prescale); 278 282 279 283 duty_ticks = mul_u64_u64_div_u64(state->duty_cycle, rzg2l_gpt->rate_khz, USEC_PER_SEC); 280 - if (duty_ticks > RZG2L_MAX_TICKS) 281 - duty_ticks = RZG2L_MAX_TICKS; 284 + if (duty_ticks > period_ticks) 285 + duty_ticks = period_ticks; 282 286 dc = rzg2l_gpt_calculate_pv_or_dc(duty_ticks, prescale); 283 287 284 288 /*