Lines Matching refs:gpwm

58 static u64 pwm_gpio_toggle(struct pwm_gpio *gpwm, bool level)  in pwm_gpio_toggle()  argument
60 const struct pwm_state *state = &gpwm->state; in pwm_gpio_toggle()
63 gpwm->level = level; in pwm_gpio_toggle()
64 gpiod_set_value(gpwm->gpio, gpwm->level ^ invert); in pwm_gpio_toggle()
67 gpwm->running = false; in pwm_gpio_toggle()
71 gpwm->running = true; in pwm_gpio_toggle()
77 struct pwm_gpio *gpwm = container_of(gpio_timer, struct pwm_gpio, in pwm_gpio_timer() local
82 guard(spinlock_irqsave)(&gpwm->lock); in pwm_gpio_timer()
85 if (!gpwm->level && gpwm->changing) { in pwm_gpio_timer()
86 gpwm->changing = false; in pwm_gpio_timer()
87 gpwm->state = gpwm->next_state; in pwm_gpio_timer()
88 new_level = !!gpwm->state.duty_cycle; in pwm_gpio_timer()
90 new_level = !gpwm->level; in pwm_gpio_timer()
93 next_toggle = pwm_gpio_toggle(gpwm, new_level); in pwm_gpio_timer()
104 struct pwm_gpio *gpwm = pwmchip_get_drvdata(chip); in pwm_gpio_apply() local
115 hrtimer_cancel(&gpwm->gpio_timer); in pwm_gpio_apply()
116 } else if (!gpwm->running) { in pwm_gpio_apply()
123 ret = gpiod_direction_output(gpwm->gpio, invert); in pwm_gpio_apply()
128 guard(spinlock_irqsave)(&gpwm->lock); in pwm_gpio_apply()
131 pwm_gpio_round(&gpwm->state, state); in pwm_gpio_apply()
132 gpwm->running = false; in pwm_gpio_apply()
133 gpwm->changing = false; in pwm_gpio_apply()
135 gpiod_set_value(gpwm->gpio, invert); in pwm_gpio_apply()
136 } else if (gpwm->running) { in pwm_gpio_apply()
137 pwm_gpio_round(&gpwm->next_state, state); in pwm_gpio_apply()
138 gpwm->changing = true; in pwm_gpio_apply()
142 pwm_gpio_round(&gpwm->state, state); in pwm_gpio_apply()
143 gpwm->changing = false; in pwm_gpio_apply()
145 next_toggle = pwm_gpio_toggle(gpwm, !!state->duty_cycle); in pwm_gpio_apply()
147 hrtimer_start(&gpwm->gpio_timer, next_toggle, in pwm_gpio_apply()
157 struct pwm_gpio *gpwm = pwmchip_get_drvdata(chip); in pwm_gpio_get_state() local
159 guard(spinlock_irqsave)(&gpwm->lock); in pwm_gpio_get_state()
161 if (gpwm->changing) in pwm_gpio_get_state()
162 *state = gpwm->next_state; in pwm_gpio_get_state()
164 *state = gpwm->state; in pwm_gpio_get_state()
176 struct pwm_gpio *gpwm = data; in pwm_gpio_disable_hrtimer() local
178 hrtimer_cancel(&gpwm->gpio_timer); in pwm_gpio_disable_hrtimer()
185 struct pwm_gpio *gpwm; in pwm_gpio_probe() local
188 chip = devm_pwmchip_alloc(dev, 1, sizeof(*gpwm)); in pwm_gpio_probe()
192 gpwm = pwmchip_get_drvdata(chip); in pwm_gpio_probe()
194 spin_lock_init(&gpwm->lock); in pwm_gpio_probe()
196 gpwm->gpio = devm_gpiod_get(dev, NULL, GPIOD_ASIS); in pwm_gpio_probe()
197 if (IS_ERR(gpwm->gpio)) in pwm_gpio_probe()
198 return dev_err_probe(dev, PTR_ERR(gpwm->gpio), in pwm_gpio_probe()
202 if (gpiod_cansleep(gpwm->gpio)) in pwm_gpio_probe()
210 hrtimer_init(&gpwm->gpio_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in pwm_gpio_probe()
211 ret = devm_add_action_or_reset(dev, pwm_gpio_disable_hrtimer, gpwm); in pwm_gpio_probe()
215 gpwm->gpio_timer.function = pwm_gpio_timer; in pwm_gpio_probe()