Lines Matching refs:state

37  * Do not confuse this with the PWM state: PWM arguments represent the initial
39 * current PWM hardware state.
52 * struct pwm_state - state of a PWM channel
77 * @state: last applied state
78 * @last: last implemented state (for PWM_DEBUG)
89 struct pwm_state state;
94 * pwm_get_state() - retrieve the current PWM state
96 * @state: state to fill with the current PWM state
98 static inline void pwm_get_state(const struct pwm_device *pwm, struct pwm_state *state)
100 *state = pwm->state;
105 struct pwm_state state;
107 pwm_get_state(pwm, &state);
109 return state.enabled;
115 pwm->state.period = period;
121 struct pwm_state state;
123 pwm_get_state(pwm, &state);
125 return state.period;
131 pwm->state.duty_cycle = duty;
137 struct pwm_state state;
139 pwm_get_state(pwm, &state);
141 return state.duty_cycle;
146 struct pwm_state state;
148 pwm_get_state(pwm, &state);
150 return state.polarity;
159 * pwm_init_state() - prepare a new state to be applied with pwm_apply_state()
161 * @state: state to fill with the prepared PWM state
163 * This functions prepares a state that can later be tweaked and applied
165 * that first retrieves the current PWM state and the replaces the period
175 static inline void pwm_init_state(const struct pwm_device *pwm, struct pwm_state *state)
179 /* First get the current state. */
180 pwm_get_state(pwm, state);
185 state->period = args.period;
186 state->polarity = args.polarity;
187 state->duty_cycle = 0;
192 * @state: PWM state to extract the duty cycle from
195 * This functions converts the absolute duty cycle stored in @state (expressed
200 * pwm_get_state(pwm, &state);
201 * duty = pwm_get_relative_duty_cycle(&state, 100);
203 static inline unsigned int pwm_get_relative_duty_cycle(const struct pwm_state *state, unsigned int scale)
205 if (!state->period) {
209 return DIV_ROUND_CLOSEST_ULL((u64)state->duty_cycle * scale, state->period);
214 * @state: PWM state to fill
219 * in nanoseconds), and puts the result in state->duty_cycle.
223 * pwm_init_state(pwm, &state);
224 * pwm_set_relative_duty_cycle(&state, 50, 100);
225 * pwm_apply_state(pwm, &state);
230 static inline int pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle, unsigned int scale)
236 state->duty_cycle = DIV_ROUND_CLOSEST_ULL((u64)duty_cycle * state->period, scale);
247 * @get_state: get the current PWM state. This function is only
260 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state);
261 void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state);
310 int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state);
323 struct pwm_state state;
333 pwm_get_state(pwm, &state);
334 if (state.duty_cycle == duty_ns && state.period == period_ns) {
338 state.duty_cycle = duty_ns;
339 state.period = period_ns;
340 return pwm_apply_state(pwm, &state);
351 struct pwm_state state;
357 pwm_get_state(pwm, &state);
358 if (state.enabled) {
362 state.enabled = true;
363 return pwm_apply_state(pwm, &state);
372 struct pwm_state state;
378 pwm_get_state(pwm, &state);
379 if (!state.enabled) {
383 state.enabled = false;
384 pwm_apply_state(pwm, &state);
417 static inline int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
513 struct pwm_state state = {};
527 * To fulfill this requirement, we apply a new state which disables
536 state.enabled = false;
537 state.polarity = pwm->args.polarity;
538 state.period = pwm->args.period;
540 pwm_apply_state(pwm, &state);