Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pwm: brcmstb: Implement .apply() callback

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>
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Uwe Kleine-König and committed by
Thierry Reding
0dcfafe7 5a471520

+25 -22
+25 -22
drivers/pwm/pwm-brcmstb.c
··· 95 95 * "on" time, so this translates directly into our HW programming here. 96 96 */ 97 97 static int brcmstb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 98 - int duty_ns, int period_ns) 98 + u64 duty_ns, u64 period_ns) 99 99 { 100 100 struct brcmstb_pwm *p = to_brcmstb_pwm(chip); 101 101 unsigned long pc, dc, cword = CONST_VAR_F_MAX; ··· 114 114 } 115 115 116 116 while (1) { 117 - u64 rate, tmp; 117 + u64 rate; 118 118 119 119 /* 120 120 * Calculate the base rate from base frequency and current 121 121 * cword 122 122 */ 123 123 rate = (u64)clk_get_rate(p->clk) * (u64)cword; 124 - do_div(rate, 1 << CWORD_BIT_SIZE); 124 + rate >>= CWORD_BIT_SIZE; 125 125 126 - tmp = period_ns * rate; 127 - do_div(tmp, NSEC_PER_SEC); 128 - pc = tmp; 129 - 130 - tmp = (duty_ns + 1) * rate; 131 - do_div(tmp, NSEC_PER_SEC); 132 - dc = tmp; 126 + pc = mul_u64_u64_div_u64(period_ns, rate, NSEC_PER_SEC); 127 + dc = mul_u64_u64_div_u64(duty_ns + 1, rate, NSEC_PER_SEC); 133 128 134 129 /* 135 130 * We can be called with separate duty and period updates, ··· 197 202 spin_unlock(&p->lock); 198 203 } 199 204 200 - static int brcmstb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 205 + static int brcmstb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 206 + const struct pwm_state *state) 201 207 { 202 208 struct brcmstb_pwm *p = to_brcmstb_pwm(chip); 209 + int err; 203 210 204 - brcmstb_pwm_enable_set(p, pwm->hwpwm, true); 211 + if (state->polarity != PWM_POLARITY_NORMAL) 212 + return -EINVAL; 213 + 214 + if (!state->enabled) { 215 + if (pwm->state.enabled) 216 + brcmstb_pwm_enable_set(p, pwm->hwpwm, false); 217 + 218 + return 0; 219 + } 220 + 221 + err = brcmstb_pwm_config(chip, pwm, state->duty_cycle, state->period); 222 + if (err) 223 + return err; 224 + 225 + if (!pwm->state.enabled) 226 + brcmstb_pwm_enable_set(p, pwm->hwpwm, true); 205 227 206 228 return 0; 207 229 } 208 230 209 - static void brcmstb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 210 - { 211 - struct brcmstb_pwm *p = to_brcmstb_pwm(chip); 212 - 213 - brcmstb_pwm_enable_set(p, pwm->hwpwm, false); 214 - } 215 - 216 231 static const struct pwm_ops brcmstb_pwm_ops = { 217 - .config = brcmstb_pwm_config, 218 - .enable = brcmstb_pwm_enable, 219 - .disable = brcmstb_pwm_disable, 232 + .apply = brcmstb_pwm_apply, 220 233 .owner = THIS_MODULE, 221 234 }; 222 235