Commit fc3c5512 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Thierry Reding

pwm: Introduce local struct pwm_chip in pwm_apply_state()

pwm->chip is dereferenced several times in the pwm_apply_state()
function. Introducing a local variable for it helps keeping some lines a
bit shorter.
Signed-off-by: default avatarUwe Kleine-König <uwe@kleine-koenig.org>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent ba73deb1
...@@ -454,20 +454,23 @@ EXPORT_SYMBOL_GPL(pwm_free); ...@@ -454,20 +454,23 @@ EXPORT_SYMBOL_GPL(pwm_free);
*/ */
int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
{ {
struct pwm_chip *chip;
int err; int err;
if (!pwm || !state || !state->period || if (!pwm || !state || !state->period ||
state->duty_cycle > state->period) state->duty_cycle > state->period)
return -EINVAL; return -EINVAL;
chip = pwm->chip;
if (state->period == pwm->state.period && if (state->period == pwm->state.period &&
state->duty_cycle == pwm->state.duty_cycle && state->duty_cycle == pwm->state.duty_cycle &&
state->polarity == pwm->state.polarity && state->polarity == pwm->state.polarity &&
state->enabled == pwm->state.enabled) state->enabled == pwm->state.enabled)
return 0; return 0;
if (pwm->chip->ops->apply) { if (chip->ops->apply) {
err = pwm->chip->ops->apply(pwm->chip, pwm, state); err = chip->ops->apply(chip, pwm, state);
if (err) if (err)
return err; return err;
...@@ -477,7 +480,7 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) ...@@ -477,7 +480,7 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
* FIXME: restore the initial state in case of error. * FIXME: restore the initial state in case of error.
*/ */
if (state->polarity != pwm->state.polarity) { if (state->polarity != pwm->state.polarity) {
if (!pwm->chip->ops->set_polarity) if (!chip->ops->set_polarity)
return -ENOTSUPP; return -ENOTSUPP;
/* /*
...@@ -486,12 +489,12 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) ...@@ -486,12 +489,12 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
* ->apply(). * ->apply().
*/ */
if (pwm->state.enabled) { if (pwm->state.enabled) {
pwm->chip->ops->disable(pwm->chip, pwm); chip->ops->disable(chip, pwm);
pwm->state.enabled = false; pwm->state.enabled = false;
} }
err = pwm->chip->ops->set_polarity(pwm->chip, pwm, err = chip->ops->set_polarity(chip, pwm,
state->polarity); state->polarity);
if (err) if (err)
return err; return err;
...@@ -500,9 +503,9 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) ...@@ -500,9 +503,9 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
if (state->period != pwm->state.period || if (state->period != pwm->state.period ||
state->duty_cycle != pwm->state.duty_cycle) { state->duty_cycle != pwm->state.duty_cycle) {
err = pwm->chip->ops->config(pwm->chip, pwm, err = chip->ops->config(pwm->chip, pwm,
state->duty_cycle, state->duty_cycle,
state->period); state->period);
if (err) if (err)
return err; return err;
...@@ -512,11 +515,11 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) ...@@ -512,11 +515,11 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
if (state->enabled != pwm->state.enabled) { if (state->enabled != pwm->state.enabled) {
if (state->enabled) { if (state->enabled) {
err = pwm->chip->ops->enable(pwm->chip, pwm); err = chip->ops->enable(chip, pwm);
if (err) if (err)
return err; return err;
} else { } else {
pwm->chip->ops->disable(pwm->chip, pwm); chip->ops->disable(chip, pwm);
} }
pwm->state.enabled = state->enabled; pwm->state.enabled = state->enabled;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment