Lines Matching refs:pwm

44 static struct pwm_device *pwm_to_device(unsigned int pwm)  in pwm_to_device()  argument
46 return radix_tree_lookup(&pwm_tree, pwm); in pwm_to_device()
49 static int alloc_pwms(int pwm, unsigned int count) in alloc_pwms() argument
54 if (pwm >= MAX_PWMS) in alloc_pwms()
57 if (pwm >= 0) in alloc_pwms()
58 from = pwm; in alloc_pwms()
63 if (pwm >= 0 && start != pwm) in alloc_pwms()
77 struct pwm_device *pwm = &chip->pwms[i]; in free_pwms() local
79 radix_tree_delete(&pwm_tree, pwm->pwm); in free_pwms()
111 static int pwm_device_request(struct pwm_device *pwm, const char *label) in pwm_device_request() argument
115 if (test_bit(PWMF_REQUESTED, &pwm->flags)) in pwm_device_request()
118 if (!try_module_get(pwm->chip->ops->owner)) in pwm_device_request()
121 if (pwm->chip->ops->request) { in pwm_device_request()
122 err = pwm->chip->ops->request(pwm->chip, pwm); in pwm_device_request()
124 module_put(pwm->chip->ops->owner); in pwm_device_request()
129 set_bit(PWMF_REQUESTED, &pwm->flags); in pwm_device_request()
130 pwm->label = label; in pwm_device_request()
138 struct pwm_device *pwm; in of_pwm_xlate_with_flags() local
151 pwm = pwm_request_from_chip(pc, args->args[0], NULL); in of_pwm_xlate_with_flags()
152 if (IS_ERR(pwm)) in of_pwm_xlate_with_flags()
153 return pwm; in of_pwm_xlate_with_flags()
155 pwm->args.period = args->args[1]; in of_pwm_xlate_with_flags()
156 pwm->args.polarity = PWM_POLARITY_NORMAL; in of_pwm_xlate_with_flags()
159 pwm->args.polarity = PWM_POLARITY_INVERSED; in of_pwm_xlate_with_flags()
161 return pwm; in of_pwm_xlate_with_flags()
168 struct pwm_device *pwm; in of_pwm_simple_xlate() local
181 pwm = pwm_request_from_chip(pc, args->args[0], NULL); in of_pwm_simple_xlate()
182 if (IS_ERR(pwm)) in of_pwm_simple_xlate()
183 return pwm; in of_pwm_simple_xlate()
185 pwm->args.period = args->args[1]; in of_pwm_simple_xlate()
187 return pwm; in of_pwm_simple_xlate()
216 int pwm_set_chip_data(struct pwm_device *pwm, void *data) in pwm_set_chip_data() argument
218 if (!pwm) in pwm_set_chip_data()
221 pwm->chip_data = data; in pwm_set_chip_data()
233 void *pwm_get_chip_data(struct pwm_device *pwm) in pwm_get_chip_data() argument
235 return pwm ? pwm->chip_data : NULL; in pwm_get_chip_data()
266 struct pwm_device *pwm; in pwmchip_add_with_polarity() local
282 chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL); in pwmchip_add_with_polarity()
291 pwm = &chip->pwms[i]; in pwmchip_add_with_polarity()
293 pwm->chip = chip; in pwmchip_add_with_polarity()
294 pwm->pwm = chip->base + i; in pwmchip_add_with_polarity()
295 pwm->hwpwm = i; in pwmchip_add_with_polarity()
296 pwm->state.polarity = polarity; in pwmchip_add_with_polarity()
299 chip->ops->get_state(chip, pwm, &pwm->state); in pwmchip_add_with_polarity()
301 radix_tree_insert(&pwm_tree, pwm->pwm, pwm); in pwmchip_add_with_polarity()
356 struct pwm_device *pwm = &chip->pwms[i]; in pwmchip_remove() local
358 if (test_bit(PWMF_REQUESTED, &pwm->flags)) { in pwmchip_remove()
389 struct pwm_device *pwm_request(int pwm, const char *label) in pwm_request() argument
394 if (pwm < 0 || pwm >= MAX_PWMS) in pwm_request()
399 dev = pwm_to_device(pwm); in pwm_request()
430 struct pwm_device *pwm; in pwm_request_from_chip() local
437 pwm = &chip->pwms[index]; in pwm_request_from_chip()
439 err = pwm_device_request(pwm, label); in pwm_request_from_chip()
441 pwm = ERR_PTR(err); in pwm_request_from_chip()
444 return pwm; in pwm_request_from_chip()
454 void pwm_free(struct pwm_device *pwm) in pwm_free() argument
456 pwm_put(pwm); in pwm_free()
467 int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) in pwm_apply_state() argument
471 if (!pwm || !state || !state->period || in pwm_apply_state()
475 if (!memcmp(state, &pwm->state, sizeof(*state))) in pwm_apply_state()
478 if (pwm->chip->ops->apply) { in pwm_apply_state()
479 err = pwm->chip->ops->apply(pwm->chip, pwm, state); in pwm_apply_state()
483 pwm->state = *state; in pwm_apply_state()
488 if (state->polarity != pwm->state.polarity) { in pwm_apply_state()
489 if (!pwm->chip->ops->set_polarity) in pwm_apply_state()
497 if (pwm->state.enabled) { in pwm_apply_state()
498 pwm->chip->ops->disable(pwm->chip, pwm); in pwm_apply_state()
499 pwm->state.enabled = false; in pwm_apply_state()
502 err = pwm->chip->ops->set_polarity(pwm->chip, pwm, in pwm_apply_state()
507 pwm->state.polarity = state->polarity; in pwm_apply_state()
510 if (state->period != pwm->state.period || in pwm_apply_state()
511 state->duty_cycle != pwm->state.duty_cycle) { in pwm_apply_state()
512 err = pwm->chip->ops->config(pwm->chip, pwm, in pwm_apply_state()
518 pwm->state.duty_cycle = state->duty_cycle; in pwm_apply_state()
519 pwm->state.period = state->period; in pwm_apply_state()
522 if (state->enabled != pwm->state.enabled) { in pwm_apply_state()
524 err = pwm->chip->ops->enable(pwm->chip, pwm); in pwm_apply_state()
528 pwm->chip->ops->disable(pwm->chip, pwm); in pwm_apply_state()
531 pwm->state.enabled = state->enabled; in pwm_apply_state()
547 int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, in pwm_capture() argument
552 if (!pwm || !pwm->chip->ops) in pwm_capture()
555 if (!pwm->chip->ops->capture) in pwm_capture()
559 err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout); in pwm_capture()
574 int pwm_adjust_config(struct pwm_device *pwm) in pwm_adjust_config() argument
579 pwm_get_args(pwm, &pargs); in pwm_adjust_config()
580 pwm_get_state(pwm, &state); in pwm_adjust_config()
595 return pwm_apply_state(pwm, &state); in pwm_adjust_config()
618 return pwm_apply_state(pwm, &state); in pwm_adjust_config()
660 struct pwm_device *pwm = NULL; in of_pwm_get() local
684 pwm = ERR_CAST(pc); in of_pwm_get()
688 pwm = pc->of_xlate(pc, &args); in of_pwm_get()
689 if (IS_ERR(pwm)) in of_pwm_get()
704 pwm->label = con_id; in of_pwm_get()
709 return pwm; in of_pwm_get()
765 struct pwm_device *pwm; in pwm_get() local
847 pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id); in pwm_get()
848 if (IS_ERR(pwm)) in pwm_get()
849 return pwm; in pwm_get()
851 pwm->args.period = chosen->period; in pwm_get()
852 pwm->args.polarity = chosen->polarity; in pwm_get()
854 return pwm; in pwm_get()
862 void pwm_put(struct pwm_device *pwm) in pwm_put() argument
864 if (!pwm) in pwm_put()
869 if (!test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) { in pwm_put()
874 if (pwm->chip->ops->free) in pwm_put()
875 pwm->chip->ops->free(pwm->chip, pwm); in pwm_put()
877 pwm->label = NULL; in pwm_put()
879 module_put(pwm->chip->ops->owner); in pwm_put()
903 struct pwm_device **ptr, *pwm; in devm_pwm_get() local
909 pwm = pwm_get(dev, con_id); in devm_pwm_get()
910 if (!IS_ERR(pwm)) { in devm_pwm_get()
911 *ptr = pwm; in devm_pwm_get()
917 return pwm; in devm_pwm_get()
936 struct pwm_device **ptr, *pwm; in devm_of_pwm_get() local
942 pwm = of_pwm_get(np, con_id); in devm_of_pwm_get()
943 if (!IS_ERR(pwm)) { in devm_of_pwm_get()
944 *ptr = pwm; in devm_of_pwm_get()
950 return pwm; in devm_of_pwm_get()
973 void devm_pwm_put(struct device *dev, struct pwm_device *pwm) in devm_pwm_put() argument
975 WARN_ON(devres_release(dev, devm_pwm_release, devm_pwm_match, pwm)); in devm_pwm_put()
985 struct pwm_device *pwm = &chip->pwms[i]; in pwm_dbg_show() local
988 pwm_get_state(pwm, &state); in pwm_dbg_show()
990 seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label); in pwm_dbg_show()
992 if (test_bit(PWMF_REQUESTED, &pwm->flags)) in pwm_dbg_show()