pwm: lpc18xx: Implement .apply() callback
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply(). This pushes a variant of pwm_apply_legacy into the driver that was slightly simplified because the .set_polarity callback was a noop. There is no change in behavior. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
This commit is contained in:
parent
758de66f4b
commit
c449a8ca5e
@ -226,14 +226,7 @@ static int lpc18xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lpc18xx_pwm_set_polarity(struct pwm_chip *chip,
|
static int lpc18xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm, enum pwm_polarity polarity)
|
||||||
struct pwm_device *pwm,
|
|
||||||
enum pwm_polarity polarity)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lpc18xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
|
||||||
{
|
{
|
||||||
struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
|
struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
|
||||||
struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm];
|
struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm];
|
||||||
@ -249,7 +242,7 @@ static int lpc18xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
|||||||
LPC18XX_PWM_EVSTATEMSK(lpc18xx_data->duty_event),
|
LPC18XX_PWM_EVSTATEMSK(lpc18xx_data->duty_event),
|
||||||
LPC18XX_PWM_EVSTATEMSK_ALL);
|
LPC18XX_PWM_EVSTATEMSK_ALL);
|
||||||
|
|
||||||
if (pwm_get_polarity(pwm) == PWM_POLARITY_NORMAL) {
|
if (polarity == PWM_POLARITY_NORMAL) {
|
||||||
set_event = lpc18xx_pwm->period_event;
|
set_event = lpc18xx_pwm->period_event;
|
||||||
clear_event = lpc18xx_data->duty_event;
|
clear_event = lpc18xx_data->duty_event;
|
||||||
res_action = LPC18XX_PWM_RES_SET;
|
res_action = LPC18XX_PWM_RES_SET;
|
||||||
@ -308,11 +301,35 @@ static void lpc18xx_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
|
|||||||
clear_bit(lpc18xx_data->duty_event, &lpc18xx_pwm->event_map);
|
clear_bit(lpc18xx_data->duty_event, &lpc18xx_pwm->event_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int lpc18xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||||
|
const struct pwm_state *state)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
bool enabled = pwm->state.enabled;
|
||||||
|
|
||||||
|
if (state->polarity != pwm->state.polarity && pwm->state.enabled) {
|
||||||
|
lpc18xx_pwm_disable(chip, pwm);
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!state->enabled) {
|
||||||
|
if (enabled)
|
||||||
|
lpc18xx_pwm_disable(chip, pwm);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = lpc18xx_pwm_config(pwm->chip, pwm, state->duty_cycle, state->period);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
if (!enabled)
|
||||||
|
err = lpc18xx_pwm_enable(chip, pwm, state->polarity);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
static const struct pwm_ops lpc18xx_pwm_ops = {
|
static const struct pwm_ops lpc18xx_pwm_ops = {
|
||||||
.config = lpc18xx_pwm_config,
|
.apply = lpc18xx_pwm_apply,
|
||||||
.set_polarity = lpc18xx_pwm_set_polarity,
|
|
||||||
.enable = lpc18xx_pwm_enable,
|
|
||||||
.disable = lpc18xx_pwm_disable,
|
|
||||||
.request = lpc18xx_pwm_request,
|
.request = lpc18xx_pwm_request,
|
||||||
.free = lpc18xx_pwm_free,
|
.free = lpc18xx_pwm_free,
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
|
Loading…
Reference in New Issue
Block a user