Lines Matching +full:sub +full:- +full:units
1 // SPDX-License-Identifier: GPL-2.0-only
3 * V4L2 flash LED sub-device registration helpers.
9 #include <linux/led-class-flash.h>
15 #include <media/v4l2-flash-led-class.h>
18 (v4l2_flash && v4l2_flash->ops && v4l2_flash->ops->op)
22 v4l2_flash->ops->op(v4l2_flash, arg) : \
23 -EINVAL)
46 intensity -= ctrl->minimum; in __intensity_to_led_brightness()
47 intensity /= (u32) ctrl->step; in __intensity_to_led_brightness()
55 if (ctrl->minimum) in __intensity_to_led_brightness()
73 if (ctrl->id != V4L2_CID_FLASH_INDICATOR_INTENSITY) in __led_brightness_to_intensity()
74 --brightness; in __led_brightness_to_intensity()
76 return (brightness * ctrl->step) + ctrl->minimum; in __led_brightness_to_intensity()
82 struct v4l2_ctrl **ctrls = v4l2_flash->ctrls; in v4l2_flash_set_led_brightness()
89 ctrl->val); in v4l2_flash_set_led_brightness()
91 brightness = __intensity_to_led_brightness(ctrl, ctrl->val); in v4l2_flash_set_led_brightness()
94 * brightness <-> intensity conversion, it also must have defined in v4l2_flash_set_led_brightness()
100 ctrl->val = call_flash_op(v4l2_flash, in v4l2_flash_set_led_brightness()
105 if (ctrls[LED_MODE]->val != V4L2_FLASH_LED_MODE_TORCH) in v4l2_flash_set_led_brightness()
108 if (WARN_ON_ONCE(!v4l2_flash->fled_cdev)) in v4l2_flash_set_led_brightness()
109 return -EINVAL; in v4l2_flash_set_led_brightness()
111 led_cdev = &v4l2_flash->fled_cdev->led_cdev; in v4l2_flash_set_led_brightness()
113 if (WARN_ON_ONCE(!v4l2_flash->iled_cdev)) in v4l2_flash_set_led_brightness()
114 return -EINVAL; in v4l2_flash_set_led_brightness()
116 led_cdev = v4l2_flash->iled_cdev; in v4l2_flash_set_led_brightness()
125 struct v4l2_ctrl **ctrls = v4l2_flash->ctrls; in v4l2_flash_update_led_brightness()
136 if (ctrls[LED_MODE]->val != V4L2_FLASH_LED_MODE_TORCH) in v4l2_flash_update_led_brightness()
139 if (WARN_ON_ONCE(!v4l2_flash->fled_cdev)) in v4l2_flash_update_led_brightness()
140 return -EINVAL; in v4l2_flash_update_led_brightness()
142 led_cdev = &v4l2_flash->fled_cdev->led_cdev; in v4l2_flash_update_led_brightness()
144 if (WARN_ON_ONCE(!v4l2_flash->iled_cdev)) in v4l2_flash_update_led_brightness()
145 return -EINVAL; in v4l2_flash_update_led_brightness()
147 led_cdev = v4l2_flash->iled_cdev; in v4l2_flash_update_led_brightness()
155 ctrl->val = call_flash_op(v4l2_flash, in v4l2_flash_update_led_brightness()
157 led_cdev->brightness); in v4l2_flash_update_led_brightness()
159 ctrl->val = __led_brightness_to_intensity(ctrl, in v4l2_flash_update_led_brightness()
160 led_cdev->brightness); in v4l2_flash_update_led_brightness()
168 struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; in v4l2_flash_g_volatile_ctrl()
172 switch (c->id) { in v4l2_flash_g_volatile_ctrl()
179 return -EINVAL; in v4l2_flash_g_volatile_ctrl()
181 switch (c->id) { in v4l2_flash_g_volatile_ctrl()
188 * microamperes for flash intensity units. in v4l2_flash_g_volatile_ctrl()
190 c->val = fled_cdev->brightness.val; in v4l2_flash_g_volatile_ctrl()
196 c->val = is_strobing; in v4l2_flash_g_volatile_ctrl()
200 return led_get_flash_fault(fled_cdev, &c->val); in v4l2_flash_g_volatile_ctrl()
202 return -EINVAL; in v4l2_flash_g_volatile_ctrl()
208 return ((ctrls[LED_MODE]->val != V4L2_FLASH_LED_MODE_FLASH) || in __software_strobe_mode_inactive()
209 (ctrls[STROBE_SOURCE] && (ctrls[STROBE_SOURCE]->val != in __software_strobe_mode_inactive()
216 struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; in v4l2_flash_s_ctrl()
218 struct v4l2_ctrl **ctrls = v4l2_flash->ctrls; in v4l2_flash_s_ctrl()
222 switch (c->id) { in v4l2_flash_s_ctrl()
229 return -EINVAL; in v4l2_flash_s_ctrl()
231 led_cdev = &fled_cdev->led_cdev; in v4l2_flash_s_ctrl()
233 switch (c->id) { in v4l2_flash_s_ctrl()
235 switch (c->val) { in v4l2_flash_s_ctrl()
243 external_strobe = (ctrls[STROBE_SOURCE]->val == in v4l2_flash_s_ctrl()
269 external_strobe = (c->val == V4L2_FLASH_STROBE_SOURCE_EXTERNAL); in v4l2_flash_s_ctrl()
276 if (ctrls[LED_MODE]->val != V4L2_FLASH_LED_MODE_FLASH) in v4l2_flash_s_ctrl()
283 return -EBUSY; in v4l2_flash_s_ctrl()
287 return -EBUSY; in v4l2_flash_s_ctrl()
292 * microseconds for flash timeout units. in v4l2_flash_s_ctrl()
294 return led_set_flash_timeout(fled_cdev, c->val); in v4l2_flash_s_ctrl()
298 * microamperes for flash intensity units. in v4l2_flash_s_ctrl()
300 return led_set_flash_brightness(fled_cdev, c->val); in v4l2_flash_s_ctrl()
303 return -EINVAL; in v4l2_flash_s_ctrl()
314 c->min = s->min; in __lfs_to_v4l2_ctrl_config()
315 c->max = s->max; in __lfs_to_v4l2_ctrl_config()
316 c->step = s->step; in __lfs_to_v4l2_ctrl_config()
317 c->def = s->val; in __lfs_to_v4l2_ctrl_config()
324 struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; in __fill_ctrl_init_data()
325 struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev : NULL; in __fill_ctrl_init_data()
330 if (v4l2_flash->iled_cdev) { in __fill_ctrl_init_data()
334 __lfs_to_v4l2_ctrl_config(&flash_cfg->intensity, in __fill_ctrl_init_data()
336 ctrl_cfg->id = V4L2_CID_FLASH_INDICATOR_INTENSITY; in __fill_ctrl_init_data()
337 ctrl_cfg->min = 0; in __fill_ctrl_init_data()
338 ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE | in __fill_ctrl_init_data()
342 if (!led_cdev || WARN_ON(!(led_cdev->flags & LED_DEV_CAP_FLASH))) in __fill_ctrl_init_data()
346 if (flash_cfg->flash_faults) { in __fill_ctrl_init_data()
349 ctrl_cfg->id = V4L2_CID_FLASH_FAULT; in __fill_ctrl_init_data()
350 ctrl_cfg->max = flash_cfg->flash_faults; in __fill_ctrl_init_data()
351 ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE | in __fill_ctrl_init_data()
358 if (led_cdev->flags & LED_DEV_CAP_FLASH) in __fill_ctrl_init_data()
363 ctrl_cfg->id = V4L2_CID_FLASH_LED_MODE; in __fill_ctrl_init_data()
364 ctrl_cfg->max = V4L2_FLASH_LED_MODE_TORCH; in __fill_ctrl_init_data()
365 ctrl_cfg->menu_skip_mask = ~mask; in __fill_ctrl_init_data()
366 ctrl_cfg->def = V4L2_FLASH_LED_MODE_NONE; in __fill_ctrl_init_data()
367 ctrl_cfg->flags = 0; in __fill_ctrl_init_data()
372 __lfs_to_v4l2_ctrl_config(&flash_cfg->intensity, ctrl_cfg); in __fill_ctrl_init_data()
373 ctrl_cfg->id = V4L2_CID_FLASH_TORCH_INTENSITY; in __fill_ctrl_init_data()
374 ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE | in __fill_ctrl_init_data()
380 ctrl_cfg->id = V4L2_CID_FLASH_STROBE; in __fill_ctrl_init_data()
385 ctrl_cfg->id = V4L2_CID_FLASH_STROBE_STOP; in __fill_ctrl_init_data()
388 if (flash_cfg->has_external_strobe) { in __fill_ctrl_init_data()
394 ctrl_cfg->id = V4L2_CID_FLASH_STROBE_SOURCE; in __fill_ctrl_init_data()
395 ctrl_cfg->max = V4L2_FLASH_STROBE_SOURCE_EXTERNAL; in __fill_ctrl_init_data()
396 ctrl_cfg->menu_skip_mask = ~mask; in __fill_ctrl_init_data()
397 ctrl_cfg->def = V4L2_FLASH_STROBE_SOURCE_SOFTWARE; in __fill_ctrl_init_data()
405 ctrl_cfg->id = V4L2_CID_FLASH_STROBE_STATUS; in __fill_ctrl_init_data()
406 ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE | in __fill_ctrl_init_data()
414 __lfs_to_v4l2_ctrl_config(&fled_cdev->timeout, ctrl_cfg); in __fill_ctrl_init_data()
415 ctrl_cfg->id = V4L2_CID_FLASH_TIMEOUT; in __fill_ctrl_init_data()
422 __lfs_to_v4l2_ctrl_config(&fled_cdev->brightness, ctrl_cfg); in __fill_ctrl_init_data()
423 ctrl_cfg->id = V4L2_CID_FLASH_INTENSITY; in __fill_ctrl_init_data()
424 ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE | in __fill_ctrl_init_data()
438 v4l2_flash->ctrls = devm_kcalloc(v4l2_flash->sd.dev, in v4l2_flash_init_controls()
440 sizeof(*v4l2_flash->ctrls), in v4l2_flash_init_controls()
442 if (!v4l2_flash->ctrls) in v4l2_flash_init_controls()
443 return -ENOMEM; in v4l2_flash_init_controls()
449 return -ENOMEM; in v4l2_flash_init_controls()
457 v4l2_ctrl_handler_init(&v4l2_flash->hdl, num_ctrls); in v4l2_flash_init_controls()
464 if (ctrl_cfg->id == V4L2_CID_FLASH_LED_MODE || in v4l2_flash_init_controls()
465 ctrl_cfg->id == V4L2_CID_FLASH_STROBE_SOURCE) in v4l2_flash_init_controls()
466 ctrl = v4l2_ctrl_new_std_menu(&v4l2_flash->hdl, in v4l2_flash_init_controls()
468 ctrl_cfg->id, in v4l2_flash_init_controls()
469 ctrl_cfg->max, in v4l2_flash_init_controls()
470 ctrl_cfg->menu_skip_mask, in v4l2_flash_init_controls()
471 ctrl_cfg->def); in v4l2_flash_init_controls()
473 ctrl = v4l2_ctrl_new_std(&v4l2_flash->hdl, in v4l2_flash_init_controls()
475 ctrl_cfg->id, in v4l2_flash_init_controls()
476 ctrl_cfg->min, in v4l2_flash_init_controls()
477 ctrl_cfg->max, in v4l2_flash_init_controls()
478 ctrl_cfg->step, in v4l2_flash_init_controls()
479 ctrl_cfg->def); in v4l2_flash_init_controls()
482 ctrl->flags |= ctrl_cfg->flags; in v4l2_flash_init_controls()
485 v4l2_flash->ctrls[i] = ctrl; in v4l2_flash_init_controls()
490 if (v4l2_flash->hdl.error) { in v4l2_flash_init_controls()
491 ret = v4l2_flash->hdl.error; in v4l2_flash_init_controls()
495 v4l2_ctrl_handler_setup(&v4l2_flash->hdl); in v4l2_flash_init_controls()
497 v4l2_flash->sd.ctrl_handler = &v4l2_flash->hdl; in v4l2_flash_init_controls()
502 v4l2_ctrl_handler_free(&v4l2_flash->hdl); in v4l2_flash_init_controls()
508 struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; in __sync_device_with_v4l2_controls()
509 struct v4l2_ctrl **ctrls = v4l2_flash->ctrls; in __sync_device_with_v4l2_controls()
528 return -EINVAL; in __sync_device_with_v4l2_controls()
531 ctrls[FLASH_TIMEOUT]->val); in __sync_device_with_v4l2_controls()
538 return -EINVAL; in __sync_device_with_v4l2_controls()
541 ctrls[FLASH_INTENSITY]->val); in __sync_device_with_v4l2_controls()
553 ctrls[LED_MODE]->val != V4L2_FLASH_LED_MODE_TORCH) in __sync_device_with_v4l2_controls()
555 ctrls[STROBE_SOURCE]->val); in __sync_device_with_v4l2_controls()
567 struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; in v4l2_flash_open()
568 struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev : NULL; in v4l2_flash_open()
569 struct led_classdev *led_cdev_ind = v4l2_flash->iled_cdev; in v4l2_flash_open()
572 if (!v4l2_fh_is_singular(&fh->vfh)) in v4l2_flash_open()
576 mutex_lock(&led_cdev->led_access); in v4l2_flash_open()
581 mutex_unlock(&led_cdev->led_access); in v4l2_flash_open()
585 mutex_lock(&led_cdev_ind->led_access); in v4l2_flash_open()
590 mutex_unlock(&led_cdev_ind->led_access); in v4l2_flash_open()
600 mutex_lock(&led_cdev->led_access); in v4l2_flash_open()
602 mutex_unlock(&led_cdev->led_access); in v4l2_flash_open()
606 mutex_lock(&led_cdev_ind->led_access); in v4l2_flash_open()
608 mutex_unlock(&led_cdev_ind->led_access); in v4l2_flash_open()
617 struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; in v4l2_flash_close()
618 struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev : NULL; in v4l2_flash_close()
619 struct led_classdev *led_cdev_ind = v4l2_flash->iled_cdev; in v4l2_flash_close()
622 if (!v4l2_fh_is_singular(&fh->vfh)) in v4l2_flash_close()
626 mutex_lock(&led_cdev->led_access); in v4l2_flash_close()
628 if (v4l2_flash->ctrls[STROBE_SOURCE]) in v4l2_flash_close()
630 v4l2_flash->ctrls[STROBE_SOURCE], in v4l2_flash_close()
634 mutex_unlock(&led_cdev->led_access); in v4l2_flash_close()
638 mutex_lock(&led_cdev_ind->led_access); in v4l2_flash_close()
640 mutex_unlock(&led_cdev_ind->led_access); in v4l2_flash_close()
663 return ERR_PTR(-EINVAL); in __v4l2_flash_init()
667 return ERR_PTR(-ENOMEM); in __v4l2_flash_init()
669 sd = &v4l2_flash->sd; in __v4l2_flash_init()
670 v4l2_flash->fled_cdev = fled_cdev; in __v4l2_flash_init()
671 v4l2_flash->iled_cdev = iled_cdev; in __v4l2_flash_init()
672 v4l2_flash->ops = ops; in __v4l2_flash_init()
673 sd->dev = dev; in __v4l2_flash_init()
674 sd->fwnode = fwn ? fwn : dev_fwnode(dev); in __v4l2_flash_init()
676 sd->internal_ops = &v4l2_flash_subdev_internal_ops; in __v4l2_flash_init()
677 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in __v4l2_flash_init()
678 strscpy(sd->name, config->dev_name, sizeof(sd->name)); in __v4l2_flash_init()
680 ret = media_entity_pads_init(&sd->entity, 0, NULL); in __v4l2_flash_init()
684 sd->entity.function = MEDIA_ENT_F_FLASH; in __v4l2_flash_init()
690 fwnode_handle_get(sd->fwnode); in __v4l2_flash_init()
699 fwnode_handle_put(sd->fwnode); in __v4l2_flash_init()
700 v4l2_ctrl_handler_free(sd->ctrl_handler); in __v4l2_flash_init()
702 media_entity_cleanup(&sd->entity); in __v4l2_flash_init()
733 sd = &v4l2_flash->sd; in v4l2_flash_release()
737 fwnode_handle_put(sd->fwnode); in v4l2_flash_release()
739 v4l2_ctrl_handler_free(sd->ctrl_handler); in v4l2_flash_release()
740 media_entity_cleanup(&sd->entity); in v4l2_flash_release()
745 MODULE_DESCRIPTION("V4L2 Flash sub-device helpers");