pwm: Introduce the pwm_args concept

Currently the PWM core mixes the current PWM state with the per-platform
reference config (specified through the PWM lookup table, DT definition
or directly hardcoded in PWM drivers).

Create a struct pwm_args to store this reference configuration, so that
PWM users can differentiate between the current and reference
configurations.

Patch all places where pwm->args should be initialized. We keep the
pwm_set_polarity/period() calls until all PWM users are patched to use
pwm_args instead of pwm_get_period/polarity().

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
[thierry.reding@gmail.com: reword kerneldoc comments]
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
This commit is contained in:
Boris Brezillon 2016-04-14 21:17:21 +02:00 committed by Thierry Reding
parent f55532a0c0
commit e39c0df1be
4 changed files with 49 additions and 9 deletions

View file

@ -128,6 +128,13 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
set_bit(PWMF_REQUESTED, &pwm->flags);
pwm->label = label;
/*
* FIXME: This should be removed once all PWM users properly make use
* of struct pwm_args to initialize the PWM device. As long as this is
* here, the PWM state and hardware state can get out of sync.
*/
pwm_apply_args(pwm);
return 0;
}
@ -146,12 +153,12 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
if (IS_ERR(pwm))
return pwm;
pwm_set_period(pwm, args->args[1]);
pwm->args.period = args->args[1];
if (args->args[2] & PWM_POLARITY_INVERTED)
pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
pwm->args.polarity = PWM_POLARITY_INVERSED;
else
pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
pwm->args.polarity = PWM_POLARITY_NORMAL;
return pwm;
}
@ -172,7 +179,7 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
if (IS_ERR(pwm))
return pwm;
pwm_set_period(pwm, args->args[1]);
pwm->args.period = args->args[1];
return pwm;
}
@ -747,13 +754,13 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
if (!chip)
goto out;
pwm->args.period = chosen->period;
pwm->args.polarity = chosen->polarity;
pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
if (IS_ERR(pwm))
goto out;
pwm_set_period(pwm, chosen->period);
pwm_set_polarity(pwm, chosen->polarity);
out:
mutex_unlock(&pwm_lookup_lock);
return pwm;