]> git.baikalelectronics.ru Git - kernel.git/commitdiff
pwm: crc: Implement get_state() method
authorHans de Goede <hdegoede@redhat.com>
Thu, 3 Sep 2020 11:23:33 +0000 (13:23 +0200)
committerHans de Goede <hdegoede@redhat.com>
Sun, 6 Sep 2020 13:38:05 +0000 (15:38 +0200)
Implement the pwm_ops.get_state() method to complete the support for the
new atomic PWM API.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200903112337.4113-14-hdegoede@redhat.com
drivers/pwm/pwm-crc.c

index 27dc308824245ede6ca7e716f46ce17ac33abb38..ecfdfac0c2d9349ba2f2154768ef2f645d0eab20 100644 (file)
@@ -121,8 +121,39 @@ static int crc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
        return 0;
 }
 
+static void crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
+                             struct pwm_state *state)
+{
+       struct crystalcove_pwm *crc_pwm = to_crc_pwm(chip);
+       struct device *dev = crc_pwm->chip.dev;
+       unsigned int clk_div, clk_div_reg, duty_cycle_reg;
+       int error;
+
+       error = regmap_read(crc_pwm->regmap, PWM0_CLK_DIV, &clk_div_reg);
+       if (error) {
+               dev_err(dev, "Error reading PWM0_CLK_DIV %d\n", error);
+               return;
+       }
+
+       error = regmap_read(crc_pwm->regmap, PWM0_DUTY_CYCLE, &duty_cycle_reg);
+       if (error) {
+               dev_err(dev, "Error reading PWM0_DUTY_CYCLE %d\n", error);
+               return;
+       }
+
+       clk_div = (clk_div_reg & ~PWM_OUTPUT_ENABLE) + 1;
+
+       state->period =
+               DIV_ROUND_UP(clk_div * NSEC_PER_USEC * 256, PWM_BASE_CLK_MHZ);
+       state->duty_cycle =
+               DIV_ROUND_UP_ULL(duty_cycle_reg * state->period, PWM_MAX_LEVEL);
+       state->polarity = PWM_POLARITY_NORMAL;
+       state->enabled = !!(clk_div_reg & PWM_OUTPUT_ENABLE);
+}
+
 static const struct pwm_ops crc_pwm_ops = {
        .apply = crc_pwm_apply,
+       .get_state = crc_pwm_get_state,
 };
 
 static int crystalcove_pwm_probe(struct platform_device *pdev)