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

pwm: tiehrpwm: 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
5f027d9b 6b94ee66

+35 -5
+35 -5
drivers/pwm/pwm-tiehrpwm.c
··· 216 216 * duty_ns = 10^9 * (ps_divval * duty_cycles) / PWM_CLK_RATE 217 217 */ 218 218 static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 219 - int duty_ns, int period_ns) 219 + u64 duty_ns, u64 period_ns) 220 220 { 221 221 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); 222 222 u32 period_cycles, duty_cycles; ··· 401 401 pc->period_cycles[pwm->hwpwm] = 0; 402 402 } 403 403 404 + static int ehrpwm_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 405 + const struct pwm_state *state) 406 + { 407 + int err; 408 + bool enabled = pwm->state.enabled; 409 + 410 + if (state->polarity != pwm->state.polarity) { 411 + if (enabled) { 412 + ehrpwm_pwm_disable(chip, pwm); 413 + enabled = false; 414 + } 415 + 416 + err = ehrpwm_pwm_set_polarity(chip, pwm, state->polarity); 417 + if (err) 418 + return err; 419 + } 420 + 421 + if (!state->enabled) { 422 + if (enabled) 423 + ehrpwm_pwm_disable(chip, pwm); 424 + return 0; 425 + } 426 + 427 + err = ehrpwm_pwm_config(chip, pwm, state->duty_cycle, state->period); 428 + if (err) 429 + return err; 430 + 431 + if (!enabled) 432 + err = ehrpwm_pwm_enable(chip, pwm); 433 + 434 + return err; 435 + } 436 + 404 437 static const struct pwm_ops ehrpwm_pwm_ops = { 405 438 .free = ehrpwm_pwm_free, 406 - .config = ehrpwm_pwm_config, 407 - .set_polarity = ehrpwm_pwm_set_polarity, 408 - .enable = ehrpwm_pwm_enable, 409 - .disable = ehrpwm_pwm_disable, 439 + .apply = ehrpwm_pwm_apply, 410 440 .owner = THIS_MODULE, 411 441 }; 412 442