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: pxa: Implement .apply() callback

To eventually get rid of all legacy drivers convert this driver to the
modern world implementing .apply(). This just pushes down a slightly
optimized variant of how legacy drivers are handled in the core.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Uwe Kleine-König and committed by
Thierry Reding
657e54e5 431c3222

+28 -5
+28 -5
drivers/pwm/pwm-pxa.c
··· 58 58 * duty_ns = 10^9 * (PRESCALE + 1) * DC / PWM_CLK_RATE 59 59 */ 60 60 static int pxa_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 61 - int duty_ns, int period_ns) 61 + u64 duty_ns, u64 period_ns) 62 62 { 63 63 struct pxa_pwm_chip *pc = to_pxa_pwm_chip(chip); 64 64 unsigned long long c; ··· 84 84 if (duty_ns == period_ns) 85 85 dc = PWMDCR_FD; 86 86 else 87 - dc = (pv + 1) * duty_ns / period_ns; 87 + dc = mul_u64_u64_div_u64(pv + 1, duty_ns, period_ns); 88 88 89 89 /* NOTE: the clock to PWM has to be enabled first 90 90 * before writing to the registers ··· 115 115 clk_disable_unprepare(pc->clk); 116 116 } 117 117 118 + static int pxa_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 119 + const struct pwm_state *state) 120 + { 121 + int err; 122 + 123 + if (state->polarity != PWM_POLARITY_NORMAL) 124 + return -EINVAL; 125 + 126 + if (!state->enabled) { 127 + if (pwm->state.enabled) 128 + pxa_pwm_disable(chip, pwm); 129 + 130 + return 0; 131 + } 132 + 133 + err = pxa_pwm_config(chip, pwm, state->duty_cycle, state->period); 134 + if (err) 135 + return err; 136 + 137 + if (!pwm->state.enabled) 138 + return pxa_pwm_enable(chip, pwm); 139 + 140 + return 0; 141 + } 142 + 118 143 static const struct pwm_ops pxa_pwm_ops = { 119 - .config = pxa_pwm_config, 120 - .enable = pxa_pwm_enable, 121 - .disable = pxa_pwm_disable, 144 + .apply = pxa_pwm_apply, 122 145 .owner = THIS_MODULE, 123 146 }; 124 147