Lines Matching +full:lock +full:- +full:state
1 // SPDX-License-Identifier: GPL-2.0-or-later
20 struct mutex lock; member
33 return export->pwm; in child_to_pwm_device()
41 struct pwm_state state; in period_show() local
43 pwm_get_state(pwm, &state); in period_show()
45 return sysfs_emit(buf, "%llu\n", state.period); in period_show()
53 struct pwm_device *pwm = export->pwm; in period_store()
54 struct pwm_state state; in period_store() local
62 mutex_lock(&export->lock); in period_store()
63 pwm_get_state(pwm, &state); in period_store()
64 state.period = val; in period_store()
65 ret = pwm_apply_might_sleep(pwm, &state); in period_store()
66 mutex_unlock(&export->lock); in period_store()
76 struct pwm_state state; in duty_cycle_show() local
78 pwm_get_state(pwm, &state); in duty_cycle_show()
80 return sysfs_emit(buf, "%llu\n", state.duty_cycle); in duty_cycle_show()
88 struct pwm_device *pwm = export->pwm; in duty_cycle_store()
89 struct pwm_state state; in duty_cycle_store() local
97 mutex_lock(&export->lock); in duty_cycle_store()
98 pwm_get_state(pwm, &state); in duty_cycle_store()
99 state.duty_cycle = val; in duty_cycle_store()
100 ret = pwm_apply_might_sleep(pwm, &state); in duty_cycle_store()
101 mutex_unlock(&export->lock); in duty_cycle_store()
111 struct pwm_state state; in enable_show() local
113 pwm_get_state(pwm, &state); in enable_show()
115 return sysfs_emit(buf, "%d\n", state.enabled); in enable_show()
123 struct pwm_device *pwm = export->pwm; in enable_store()
124 struct pwm_state state; in enable_store() local
131 mutex_lock(&export->lock); in enable_store()
133 pwm_get_state(pwm, &state); in enable_store()
137 state.enabled = false; in enable_store()
140 state.enabled = true; in enable_store()
143 ret = -EINVAL; in enable_store()
147 ret = pwm_apply_might_sleep(pwm, &state); in enable_store()
150 mutex_unlock(&export->lock); in enable_store()
160 struct pwm_state state; in polarity_show() local
162 pwm_get_state(pwm, &state); in polarity_show()
164 switch (state.polarity) { in polarity_show()
182 struct pwm_device *pwm = export->pwm; in polarity_store()
184 struct pwm_state state; in polarity_store() local
192 return -EINVAL; in polarity_store()
194 mutex_lock(&export->lock); in polarity_store()
195 pwm_get_state(pwm, &state); in polarity_store()
196 state.polarity = polarity; in polarity_store()
197 ret = pwm_apply_might_sleep(pwm, &state); in polarity_store()
198 mutex_unlock(&export->lock); in polarity_store()
247 if (test_and_set_bit(PWMF_EXPORTED, &pwm->flags)) in pwm_export_child()
248 return -EBUSY; in pwm_export_child()
252 clear_bit(PWMF_EXPORTED, &pwm->flags); in pwm_export_child()
253 return -ENOMEM; in pwm_export_child()
256 export->pwm = pwm; in pwm_export_child()
257 mutex_init(&export->lock); in pwm_export_child()
259 export->child.release = pwm_export_release; in pwm_export_child()
260 export->child.parent = parent; in pwm_export_child()
261 export->child.devt = MKDEV(0, 0); in pwm_export_child()
262 export->child.groups = pwm_groups; in pwm_export_child()
263 dev_set_name(&export->child, "pwm%u", pwm->hwpwm); in pwm_export_child()
265 ret = device_register(&export->child); in pwm_export_child()
267 clear_bit(PWMF_EXPORTED, &pwm->flags); in pwm_export_child()
268 put_device(&export->child); in pwm_export_child()
272 pwm_prop[0] = kasprintf(GFP_KERNEL, "EXPORT=pwm%u", pwm->hwpwm); in pwm_export_child()
274 kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop); in pwm_export_child()
290 if (!test_and_clear_bit(PWMF_EXPORTED, &pwm->flags)) in pwm_unexport_child()
291 return -ENODEV; in pwm_unexport_child()
295 return -ENODEV; in pwm_unexport_child()
297 pwm_prop[0] = kasprintf(GFP_KERNEL, "UNEXPORT=pwm%u", pwm->hwpwm); in pwm_unexport_child()
299 kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop); in pwm_unexport_child()
323 if (hwpwm >= chip->npwm) in export_store()
324 return -ENODEV; in export_store()
350 if (hwpwm >= chip->npwm) in unexport_store()
351 return -ENODEV; in unexport_store()
353 ret = pwm_unexport_child(parent, &chip->pwms[hwpwm]); in unexport_store()
364 return sysfs_emit(buf, "%u\n", chip->npwm); in npwm_show()
376 /* takes export->lock on success */
379 struct pwm_state *state) in pwm_class_get_state() argument
384 if (!test_bit(PWMF_EXPORTED, &pwm->flags)) in pwm_class_get_state()
394 mutex_lock(&export->lock); in pwm_class_get_state()
395 pwm_get_state(pwm, state); in pwm_class_get_state()
402 struct pwm_state *state) in pwm_class_apply_state() argument
404 int ret = pwm_apply_might_sleep(pwm, state); in pwm_class_apply_state()
406 /* release lock taken in pwm_class_get_state */ in pwm_class_apply_state()
407 mutex_unlock(&export->lock); in pwm_class_apply_state()
419 struct pwm_device *pwm = &chip->pwms[i]; in pwm_class_resume_npwm()
420 struct pwm_state state; in pwm_class_resume_npwm() local
423 export = pwm_class_get_state(parent, pwm, &state); in pwm_class_resume_npwm()
428 if (!export->suspend.enabled) { in pwm_class_resume_npwm()
429 /* release lock taken in pwm_class_get_state */ in pwm_class_resume_npwm()
430 mutex_unlock(&export->lock); in pwm_class_resume_npwm()
434 state.enabled = export->suspend.enabled; in pwm_class_resume_npwm()
435 ret = pwm_class_apply_state(export, pwm, &state); in pwm_class_resume_npwm()
449 for (i = 0; i < chip->npwm; i++) { in pwm_class_suspend()
450 struct pwm_device *pwm = &chip->pwms[i]; in pwm_class_suspend()
451 struct pwm_state state; in pwm_class_suspend() local
454 export = pwm_class_get_state(parent, pwm, &state); in pwm_class_suspend()
460 * state for resume time and do nothing else. in pwm_class_suspend()
462 export->suspend = state; in pwm_class_suspend()
463 if (!state.enabled) { in pwm_class_suspend()
464 /* release lock taken in pwm_class_get_state */ in pwm_class_suspend()
465 mutex_unlock(&export->lock); in pwm_class_suspend()
469 state.enabled = false; in pwm_class_suspend()
470 ret = pwm_class_apply_state(export, pwm, &state); in pwm_class_suspend()
488 return pwm_class_resume_npwm(parent, chip->npwm); in pwm_class_resume()
512 parent = device_create(&pwm_class, chip->dev, MKDEV(0, 0), chip, in pwmchip_sysfs_export()
513 "pwmchip%d", chip->id); in pwmchip_sysfs_export()
515 dev_warn(chip->dev, in pwmchip_sysfs_export()
530 for (i = 0; i < chip->npwm; i++) { in pwmchip_sysfs_unexport()
531 struct pwm_device *pwm = &chip->pwms[i]; in pwmchip_sysfs_unexport()
533 if (test_bit(PWMF_EXPORTED, &pwm->flags)) in pwmchip_sysfs_unexport()