Skip to content

Commit c1330cb

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: atmel-tcb: Simplify checking the companion output
The two outputs provided by the supported hardware share some settings, so access to the other PWM is required when one of them is configured. Instead of an explicit if to deterimine the other PWM just use hwpwm ^ 1. Further atcbpwm is never NULL, so drop the corresponding check. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com> Link: https://lore.kernel.org/r/20240709101806.52394-4-u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent 9dd42d0 commit c1330cb

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

drivers/pwm/pwm-atmel-tcb.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
260260
{
261261
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
262262
struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
263-
struct atmel_tcb_pwm_device *atcbpwm = NULL;
263+
/* companion PWM sharing register values period and div */
264+
struct atmel_tcb_pwm_device *atcbpwm = &tcbpwmc->pwms[pwm->hwpwm ^ 1];
264265
int i = 0;
265266
int slowclk = 0;
266267
unsigned period;
@@ -305,11 +306,6 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
305306
duty = div_u64(duty_ns, min);
306307
period = div_u64(period_ns, min);
307308

308-
if (pwm->hwpwm == 0)
309-
atcbpwm = &tcbpwmc->pwms[1];
310-
else
311-
atcbpwm = &tcbpwmc->pwms[0];
312-
313309
/*
314310
* PWM devices provided by the TCB driver are grouped by 2.
315311
* PWM devices in a given group must be configured with the
@@ -318,8 +314,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
318314
* We're checking the period value of the second PWM device
319315
* in this group before applying the new config.
320316
*/
321-
if ((atcbpwm && atcbpwm->duty > 0 &&
322-
atcbpwm->duty != atcbpwm->period) &&
317+
if ((atcbpwm->duty > 0 && atcbpwm->duty != atcbpwm->period) &&
323318
(atcbpwm->div != i || atcbpwm->period != period)) {
324319
dev_err(pwmchip_parent(chip),
325320
"failed to configure period_ns: PWM group already configured with a different value\n");

0 commit comments

Comments
 (0)