]> www.infradead.org Git - users/hch/xfs.git/commitdiff
pwm: atmel-tcb: Simplify checking the companion output
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Tue, 9 Jul 2024 10:18:06 +0000 (12:18 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Wed, 10 Jul 2024 15:55:12 +0000 (17:55 +0200)
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>
drivers/pwm/pwm-atmel-tcb.c

index aca11493239a59d336164b0fe80c31b78ae6229c..2feee3744b50305b7c9afa01826ee4bebd901743 100644 (file)
@@ -260,7 +260,8 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 {
        struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
        struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
-       struct atmel_tcb_pwm_device *atcbpwm = NULL;
+       /* companion PWM sharing register values period and div */
+       struct atmel_tcb_pwm_device *atcbpwm = &tcbpwmc->pwms[pwm->hwpwm ^ 1];
        int i = 0;
        int slowclk = 0;
        unsigned period;
@@ -305,11 +306,6 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
        duty = div_u64(duty_ns, min);
        period = div_u64(period_ns, min);
 
-       if (pwm->hwpwm == 0)
-               atcbpwm = &tcbpwmc->pwms[1];
-       else
-               atcbpwm = &tcbpwmc->pwms[0];
-
        /*
         * PWM devices provided by the TCB driver are grouped by 2.
         * 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,
         * We're checking the period value of the second PWM device
         * in this group before applying the new config.
         */
-       if ((atcbpwm && atcbpwm->duty > 0 &&
-                       atcbpwm->duty != atcbpwm->period) &&
+       if ((atcbpwm->duty > 0 && atcbpwm->duty != atcbpwm->period) &&
                (atcbpwm->div != i || atcbpwm->period != period)) {
                dev_err(pwmchip_parent(chip),
                        "failed to configure period_ns: PWM group already configured with a different value\n");