Skip to content

Commit ecc827c

Browse files
Uwe Kleine-Königclaudiubeznea
authored andcommitted
pwm: ab8500: Implement .apply instead of .config, .enable and .disable
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply(). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
1 parent b2edb16 commit ecc827c

1 file changed

Lines changed: 25 additions & 28 deletions

File tree

drivers/pwm/pwm-ab8500.c

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,65 +24,62 @@ struct ab8500_pwm_chip {
2424
struct pwm_chip chip;
2525
};
2626

27-
static int ab8500_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
28-
int duty_ns, int period_ns)
27+
static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
28+
const struct pwm_state *state)
2929
{
30-
int ret = 0;
31-
unsigned int higher_val, lower_val;
30+
int ret;
3231
u8 reg;
32+
unsigned int higher_val, lower_val;
33+
34+
if (state->polarity != PWM_POLARITY_NORMAL)
35+
return -EINVAL;
36+
37+
if (!state->enabled) {
38+
ret = abx500_mask_and_set_register_interruptible(chip->dev,
39+
AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
40+
1 << (chip->base - 1), 0);
41+
42+
if (ret < 0)
43+
dev_err(chip->dev, "%s: Failed to disable PWM, Error %d\n",
44+
pwm->label, ret);
45+
return ret;
46+
}
3347

3448
/*
3549
* get the first 8 bits that are be written to
3650
* AB8500_PWM_OUT_CTRL1_REG[0:7]
3751
*/
38-
lower_val = duty_ns & 0x00FF;
52+
lower_val = state->duty_cycle & 0x00FF;
3953
/*
4054
* get bits [9:10] that are to be written to
4155
* AB8500_PWM_OUT_CTRL2_REG[0:1]
4256
*/
43-
higher_val = ((duty_ns & 0x0300) >> 8);
57+
higher_val = ((state->duty_cycle & 0x0300) >> 8);
4458

4559
reg = AB8500_PWM_OUT_CTRL1_REG + ((chip->base - 1) * 2);
4660

4761
ret = abx500_set_register_interruptible(chip->dev, AB8500_MISC,
4862
reg, (u8)lower_val);
4963
if (ret < 0)
5064
return ret;
65+
5166
ret = abx500_set_register_interruptible(chip->dev, AB8500_MISC,
5267
(reg + 1), (u8)higher_val);
53-
54-
return ret;
55-
}
56-
57-
static int ab8500_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
58-
{
59-
int ret;
68+
if (ret < 0)
69+
return ret;
6070

6171
ret = abx500_mask_and_set_register_interruptible(chip->dev,
6272
AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
6373
1 << (chip->base - 1), 1 << (chip->base - 1));
6474
if (ret < 0)
6575
dev_err(chip->dev, "%s: Failed to enable PWM, Error %d\n",
6676
pwm->label, ret);
67-
return ret;
68-
}
6977

70-
static void ab8500_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
71-
{
72-
int ret;
73-
74-
ret = abx500_mask_and_set_register_interruptible(chip->dev,
75-
AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
76-
1 << (chip->base - 1), 0);
77-
if (ret < 0)
78-
dev_err(chip->dev, "%s: Failed to disable PWM, Error %d\n",
79-
pwm->label, ret);
78+
return ret;
8079
}
8180

8281
static const struct pwm_ops ab8500_pwm_ops = {
83-
.config = ab8500_pwm_config,
84-
.enable = ab8500_pwm_enable,
85-
.disable = ab8500_pwm_disable,
82+
.apply = ab8500_pwm_apply,
8683
.owner = THIS_MODULE,
8784
};
8885

0 commit comments

Comments
 (0)