diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2023-01-18 16:48:17 +0100 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2023-02-17 15:59:52 +0100 |
commit | 327437884e9a752ccbf759cbab641439ca708f5b (patch) | |
tree | d6a8520d3b6344663cf775655889cc703ab7d205 /drivers/pwm | |
parent | 486dd4e846814016443abfcbfee0b8b3f3b35330 (diff) | |
download | linux-327437884e9a752ccbf759cbab641439ca708f5b.tar.gz linux-327437884e9a752ccbf759cbab641439ca708f5b.tar.bz2 linux-327437884e9a752ccbf759cbab641439ca708f5b.zip |
pwm: ab8500: Implement .get_state()
The registers are readable, so it's possible to implement the
.get_state() callback for this PWM.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm')
-rw-r--r-- | drivers/pwm/pwm-ab8500.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/pwm/pwm-ab8500.c b/drivers/pwm/pwm-ab8500.c index c5239eef3b8f..507ff0d5f7bd 100644 --- a/drivers/pwm/pwm-ab8500.c +++ b/drivers/pwm/pwm-ab8500.c @@ -136,8 +136,51 @@ static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return ret; } +static int ab8500_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_state *state) +{ + u8 ctrl7, lower_val, higher_val; + int ret; + struct ab8500_pwm_chip *ab8500 = ab8500_pwm_from_chip(chip); + unsigned int div, duty_steps; + + ret = abx500_get_register_interruptible(chip->dev, AB8500_MISC, + AB8500_PWM_OUT_CTRL7_REG, + &ctrl7); + if (ret) + return ret; + + state->polarity = PWM_POLARITY_NORMAL; + + if (!(ctrl7 & 1 << ab8500->hwid)) { + state->enabled = false; + return 0; + } + + ret = abx500_get_register_interruptible(chip->dev, AB8500_MISC, + AB8500_PWM_OUT_CTRL1_REG + (ab8500->hwid * 2), + &lower_val); + if (ret) + return ret; + + ret = abx500_get_register_interruptible(chip->dev, AB8500_MISC, + AB8500_PWM_OUT_CTRL2_REG + (ab8500->hwid * 2), + &higher_val); + if (ret) + return ret; + + div = 32 - ((higher_val & 0xf0) >> 4); + duty_steps = ((higher_val & 3) << 8 | lower_val) + 1; + + state->period = DIV64_U64_ROUND_UP((u64)div << 10, AB8500_PWM_CLKRATE); + state->duty_cycle = DIV64_U64_ROUND_UP((u64)div * duty_steps, AB8500_PWM_CLKRATE); + + return 0; +} + static const struct pwm_ops ab8500_pwm_ops = { .apply = ab8500_pwm_apply, + .get_state = ab8500_pwm_get_state, .owner = THIS_MODULE, }; |