static int gpio_pwm_config_nosleep(struct pwm_channel *p, struct pwm_channel_config *c) { struct gpio_pwm *gp = to_gpio_pwm(p); int ret = 0; unsigned long flags; spin_lock_irqsave(&p->lock, flags); switch (c->config_mask) { case PWM_CONFIG_DUTY_TICKS: p->duty_ticks = c->duty_ticks; break; case PWM_CONFIG_START: if (!hrtimer_active(&gp->timer)) { gpio_pwm_start(p); } break; default: ret = -EINVAL; break; } spin_unlock_irqrestore(&p->lock, flags); return ret; }
static int gpio_pwm_config(struct pwm_channel *p, struct pwm_channel_config *c) { struct gpio_pwm *gp = to_gpio_pwm(p); int was_on = 0; if (p->pwm->config_nosleep) { if (!p->pwm->config_nosleep(p, c)) return 0; } might_sleep(); was_on = gpio_pwm_stop_sync(p); if (was_on < 0) return was_on; if (c->config_mask & PWM_CONFIG_PERIOD_TICKS) p->period_ticks = c->period_ticks; if (c->config_mask & PWM_CONFIG_DUTY_TICKS) p->duty_ticks = c->duty_ticks; if (c->config_mask & PWM_CONFIG_POLARITY) { gp->polarity = c->polarity ? 1 : 0; p->active_high = gp->polarity; } if ((c->config_mask & PWM_CONFIG_START) || (was_on && !(c->config_mask & PWM_CONFIG_STOP))) gpio_pwm_start(p); return 0; }