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

pwm: samsung: Implement .apply() callback

To eventually get rid of all legacy drivers convert this driver to the
modern world implementing .apply().

The size check for state->period is moved to .apply() to make sure that
the values of state->duty_cycle and state->period are passed to
pwm_samsung_config without change while they are discarded to int.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Uwe Kleine-König and committed by
Thierry Reding
daa986d5 762c4e7f

+42 -12
+42 -12
drivers/pwm/pwm-samsung.c
··· 321 321 struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm); 322 322 u32 tin_ns = chan->tin_ns, tcnt, tcmp, oldtcmp; 323 323 324 - /* 325 - * We currently avoid using 64bit arithmetic by using the 326 - * fact that anything faster than 1Hz is easily representable 327 - * by 32bits. 328 - */ 329 - if (period_ns > NSEC_PER_SEC) 330 - return -ERANGE; 331 - 332 324 tcnt = readl(our_chip->base + REG_TCNTB(pwm->hwpwm)); 333 325 oldtcmp = readl(our_chip->base + REG_TCMPB(pwm->hwpwm)); 334 326 ··· 430 438 return 0; 431 439 } 432 440 441 + static int pwm_samsung_apply(struct pwm_chip *chip, struct pwm_device *pwm, 442 + const struct pwm_state *state) 443 + { 444 + int err, enabled = pwm->state.enabled; 445 + 446 + if (state->polarity != pwm->state.polarity) { 447 + if (enabled) { 448 + pwm_samsung_disable(chip, pwm); 449 + enabled = false; 450 + } 451 + 452 + err = pwm_samsung_set_polarity(chip, pwm, state->polarity); 453 + if (err) 454 + return err; 455 + } 456 + 457 + if (!state->enabled) { 458 + if (enabled) 459 + pwm_samsung_disable(chip, pwm); 460 + 461 + return 0; 462 + } 463 + 464 + /* 465 + * We currently avoid using 64bit arithmetic by using the 466 + * fact that anything faster than 1Hz is easily representable 467 + * by 32bits. 468 + */ 469 + if (state->period > NSEC_PER_SEC) 470 + return -ERANGE; 471 + 472 + err = pwm_samsung_config(chip, pwm, state->duty_cycle, state->period); 473 + if (err) 474 + return err; 475 + 476 + if (!pwm->state.enabled) 477 + err = pwm_samsung_enable(chip, pwm); 478 + 479 + return err; 480 + } 481 + 433 482 static const struct pwm_ops pwm_samsung_ops = { 434 483 .request = pwm_samsung_request, 435 484 .free = pwm_samsung_free, 436 - .enable = pwm_samsung_enable, 437 - .disable = pwm_samsung_disable, 438 - .config = pwm_samsung_config, 439 - .set_polarity = pwm_samsung_set_polarity, 485 + .apply = pwm_samsung_apply, 440 486 .owner = THIS_MODULE, 441 487 }; 442 488