pwm: Add the pwm_is_enabled() helper
Some PWM drivers are testing the PWMF_ENABLED flag. Create a helper function to hide the logic behind enabled test. This will allow us to smoothly move from the current approach to an atomic PWM update approach. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
This commit is contained in:

committed by
Thierry Reding

parent
d770e558e2
commit
5c31252c4a
@@ -97,7 +97,7 @@ static int ecap_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
|
||||
writew(reg_val, pc->mmio_base + ECCTL2);
|
||||
|
||||
if (!test_bit(PWMF_ENABLED, &pwm->flags)) {
|
||||
if (!pwm_is_enabled(pwm)) {
|
||||
/* Update active registers if not running */
|
||||
writel(duty_cycles, pc->mmio_base + CAP2);
|
||||
writel(period_cycles, pc->mmio_base + CAP1);
|
||||
@@ -111,7 +111,7 @@ static int ecap_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
writel(period_cycles, pc->mmio_base + CAP3);
|
||||
}
|
||||
|
||||
if (!test_bit(PWMF_ENABLED, &pwm->flags)) {
|
||||
if (!pwm_is_enabled(pwm)) {
|
||||
reg_val = readw(pc->mmio_base + ECCTL2);
|
||||
/* Disable APWM mode to put APWM output Low */
|
||||
reg_val &= ~ECCTL2_APWM_MODE;
|
||||
@@ -179,7 +179,7 @@ static void ecap_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
|
||||
static void ecap_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
{
|
||||
if (test_bit(PWMF_ENABLED, &pwm->flags)) {
|
||||
if (pwm_is_enabled(pwm)) {
|
||||
dev_warn(chip->dev, "Removing PWM device without disabling\n");
|
||||
pm_runtime_put_sync(chip->dev);
|
||||
}
|
||||
@@ -306,7 +306,7 @@ static int ecap_pwm_suspend(struct device *dev)
|
||||
ecap_pwm_save_context(pc);
|
||||
|
||||
/* Disable explicitly if PWM is running */
|
||||
if (test_bit(PWMF_ENABLED, &pwm->flags))
|
||||
if (pwm_is_enabled(pwm))
|
||||
pm_runtime_put_sync(dev);
|
||||
|
||||
return 0;
|
||||
@@ -318,7 +318,7 @@ static int ecap_pwm_resume(struct device *dev)
|
||||
struct pwm_device *pwm = pc->chip.pwms;
|
||||
|
||||
/* Enable explicitly if PWM was running */
|
||||
if (test_bit(PWMF_ENABLED, &pwm->flags))
|
||||
if (pwm_is_enabled(pwm))
|
||||
pm_runtime_get_sync(dev);
|
||||
|
||||
ecap_pwm_restore_context(pc);
|
||||
|
Reference in New Issue
Block a user