Lines Matching +full:flash +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-only
3 * LED Flash class driver for the AAT1290
4 * 1.5A Step-Up Current Regulator for Flash LEDs
12 #include <linux/led-class-flash.h>
20 #include <media/v4l2-flash-led-class.h>
49 /* maximum LED current in movie mode */
51 /* maximum LED current in flash mode */
53 /* maximum flash timeout */
67 /* corresponding LED Flash class device */
69 /* V4L2 Flash device */
76 /* movie mode current scale */
78 /* device mode */
100 gpiod_direction_output(led->gpio_fl_en, 0); in aat1290_as2cwire_write()
101 gpiod_direction_output(led->gpio_en_set, 0); in aat1290_as2cwire_write()
108 gpiod_direction_output(led->gpio_en_set, 0); in aat1290_as2cwire_write()
110 gpiod_direction_output(led->gpio_en_set, 1); in aat1290_as2cwire_write()
118 gpiod_direction_output(led->gpio_en_set, 0); in aat1290_as2cwire_write()
120 gpiod_direction_output(led->gpio_en_set, 1); in aat1290_as2cwire_write()
129 struct led_classdev_flash *fled_cdev = &led->fled_cdev; in aat1290_set_flash_safety_timer()
130 struct led_flash_setting *flash_tm = &fled_cdev->timeout; in aat1290_set_flash_safety_timer()
131 int flash_tm_reg = AAT1290_FLASH_TM_NUM_LEVELS - in aat1290_set_flash_safety_timer()
132 (micro_sec / flash_tm->step) + 1; in aat1290_set_flash_safety_timer()
146 mutex_lock(&led->lock); in aat1290_led_brightness_set()
149 gpiod_direction_output(led->gpio_fl_en, 0); in aat1290_led_brightness_set()
150 gpiod_direction_output(led->gpio_en_set, 0); in aat1290_led_brightness_set()
151 led->movie_mode = false; in aat1290_led_brightness_set()
153 if (!led->movie_mode) { in aat1290_led_brightness_set()
157 led->movie_mode = true; in aat1290_led_brightness_set()
161 AAT1290_MAX_MM_CURR_PERCENT_0 - brightness); in aat1290_led_brightness_set()
166 mutex_unlock(&led->lock); in aat1290_led_brightness_set()
176 struct led_classdev *led_cdev = &fled_cdev->led_cdev; in aat1290_led_flash_strobe_set()
177 struct led_flash_setting *timeout = &fled_cdev->timeout; in aat1290_led_flash_strobe_set()
179 mutex_lock(&led->lock); in aat1290_led_flash_strobe_set()
182 aat1290_set_flash_safety_timer(led, timeout->val); in aat1290_led_flash_strobe_set()
183 gpiod_direction_output(led->gpio_fl_en, 1); in aat1290_led_flash_strobe_set()
185 gpiod_direction_output(led->gpio_fl_en, 0); in aat1290_led_flash_strobe_set()
186 gpiod_direction_output(led->gpio_en_set, 0); in aat1290_led_flash_strobe_set()
190 * To reenter movie mode after a flash event the part must be cycled in aat1290_led_flash_strobe_set()
191 * off and back on to reset the movie mode and reprogrammed via the in aat1290_led_flash_strobe_set()
195 led_cdev->brightness = 0; in aat1290_led_flash_strobe_set()
196 led->movie_mode = false; in aat1290_led_flash_strobe_set()
198 mutex_unlock(&led->lock); in aat1290_led_flash_strobe_set()
207 * Don't do anything - flash timeout is cached in the led-class-flash in aat1290_led_flash_timeout_set()
209 * safety timer register spuriously turns the torch mode on. in aat1290_led_flash_timeout_set()
219 struct device *dev = &led->pdev->dev; in aat1290_led_parse_dt()
226 led->gpio_fl_en = devm_gpiod_get(dev, "flen", GPIOD_ASIS); in aat1290_led_parse_dt()
227 if (IS_ERR(led->gpio_fl_en)) { in aat1290_led_parse_dt()
228 ret = PTR_ERR(led->gpio_fl_en); in aat1290_led_parse_dt()
233 led->gpio_en_set = devm_gpiod_get(dev, "enset", GPIOD_ASIS); in aat1290_led_parse_dt()
234 if (IS_ERR(led->gpio_en_set)) { in aat1290_led_parse_dt()
235 ret = PTR_ERR(led->gpio_en_set); in aat1290_led_parse_dt()
241 pinctrl = devm_pinctrl_get_select_default(&led->pdev->dev); in aat1290_led_parse_dt()
243 cfg->has_external_strobe = false; in aat1290_led_parse_dt()
247 cfg->has_external_strobe = true; in aat1290_led_parse_dt()
254 return -EINVAL; in aat1290_led_parse_dt()
257 ret = of_property_read_u32(child_node, "led-max-microamp", in aat1290_led_parse_dt()
258 &cfg->max_mm_current); in aat1290_led_parse_dt()
260 * led-max-microamp will default to 1/20 of flash-max-microamp in aat1290_led_parse_dt()
265 "led-max-microamp DT property missing\n"); in aat1290_led_parse_dt()
267 ret = of_property_read_u32(child_node, "flash-max-microamp", in aat1290_led_parse_dt()
268 &cfg->max_flash_current); in aat1290_led_parse_dt()
271 "flash-max-microamp DT property missing\n"); in aat1290_led_parse_dt()
275 ret = of_property_read_u32(child_node, "flash-max-timeout-us", in aat1290_led_parse_dt()
276 &cfg->max_flash_tm); in aat1290_led_parse_dt()
279 "flash-max-timeout-us DT property missing\n"); in aat1290_led_parse_dt()
296 while (e - b > 1) { in aat1290_led_validate_mm_current()
297 i = b + (e - b) / 2; in aat1290_led_validate_mm_current()
298 if (cfg->max_mm_current < led->mm_current_scale[i]) in aat1290_led_validate_mm_current()
304 cfg->max_mm_current = led->mm_current_scale[b]; in aat1290_led_validate_mm_current()
305 cfg->max_brightness = b + 1; in aat1290_led_validate_mm_current()
316 AAT1290_MAX_MM_CURRENT(cfg->max_flash_current); in init_mm_current_scale()
318 led->mm_current_scale = devm_kzalloc(&led->pdev->dev, in init_mm_current_scale()
321 if (!led->mm_current_scale) in init_mm_current_scale()
322 return -ENOMEM; in init_mm_current_scale()
325 led->mm_current_scale[i] = max_mm_current * in init_mm_current_scale()
341 * Init non-linear movie mode current scale basing in aat1290_led_get_configuration()
342 * on the max flash current from led configuration. in aat1290_led_get_configuration()
352 devm_kfree(&led->pdev->dev, led->mm_current_scale); in aat1290_led_get_configuration()
361 struct led_classdev_flash *fled_cdev = &led->fled_cdev; in aat1290_init_flash_timeout()
364 /* Init flash timeout setting */ in aat1290_init_flash_timeout()
365 setting = &fled_cdev->timeout; in aat1290_init_flash_timeout()
366 setting->min = cfg->max_flash_tm / AAT1290_FLASH_TM_NUM_LEVELS; in aat1290_init_flash_timeout()
367 setting->max = cfg->max_flash_tm; in aat1290_init_flash_timeout()
368 setting->step = setting->min; in aat1290_init_flash_timeout()
369 setting->val = setting->max; in aat1290_init_flash_timeout()
377 struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; in aat1290_intensity_to_brightness()
381 for (i = AAT1290_MM_CURRENT_SCALE_SIZE - 1; i >= 0; --i) in aat1290_intensity_to_brightness()
382 if (intensity >= led->mm_current_scale[i]) in aat1290_intensity_to_brightness()
391 struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; in aat1290_brightness_to_intensity()
394 return led->mm_current_scale[brightness - 1]; in aat1290_brightness_to_intensity()
400 struct aat1290_led *led = fled_cdev_to_led(v4l2_flash->fled_cdev); in aat1290_led_external_strobe_set()
401 struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; in aat1290_led_external_strobe_set()
402 struct led_classdev *led_cdev = &fled_cdev->led_cdev; in aat1290_led_external_strobe_set()
405 gpiod_direction_output(led->gpio_fl_en, 0); in aat1290_led_external_strobe_set()
406 gpiod_direction_output(led->gpio_en_set, 0); in aat1290_led_external_strobe_set()
408 led->movie_mode = false; in aat1290_led_external_strobe_set()
409 led_cdev->brightness = 0; in aat1290_led_external_strobe_set()
411 pinctrl = devm_pinctrl_get_select(&led->pdev->dev, in aat1290_led_external_strobe_set()
414 dev_warn(&led->pdev->dev, "Unable to switch strobe source.\n"); in aat1290_led_external_strobe_set()
425 struct led_classdev *led_cdev = &led->fled_cdev.led_cdev; in aat1290_init_v4l2_flash_config()
428 strscpy(v4l2_sd_cfg->dev_name, led_cdev->dev->kobj.name, in aat1290_init_v4l2_flash_config()
429 sizeof(v4l2_sd_cfg->dev_name)); in aat1290_init_v4l2_flash_config()
431 s = &v4l2_sd_cfg->intensity; in aat1290_init_v4l2_flash_config()
432 s->min = led->mm_current_scale[0]; in aat1290_init_v4l2_flash_config()
433 s->max = led_cfg->max_mm_current; in aat1290_init_v4l2_flash_config()
434 s->step = 1; in aat1290_init_v4l2_flash_config()
435 s->val = s->max; in aat1290_init_v4l2_flash_config()
437 v4l2_sd_cfg->has_external_strobe = led_cfg->has_external_strobe; in aat1290_init_v4l2_flash_config()
461 struct device *dev = &pdev->dev; in aat1290_led_probe()
473 return -ENOMEM; in aat1290_led_probe()
475 led->pdev = pdev; in aat1290_led_probe()
478 fled_cdev = &led->fled_cdev; in aat1290_led_probe()
479 fled_cdev->ops = &flash_ops; in aat1290_led_probe()
480 led_cdev = &fled_cdev->led_cdev; in aat1290_led_probe()
486 mutex_init(&led->lock); in aat1290_led_probe()
488 /* Initialize LED Flash class device */ in aat1290_led_probe()
489 led_cdev->brightness_set_blocking = aat1290_led_brightness_set; in aat1290_led_probe()
490 led_cdev->max_brightness = led_cfg.max_brightness; in aat1290_led_probe()
491 led_cdev->flags |= LED_DEV_CAP_FLASH; in aat1290_led_probe()
498 /* Register LED Flash class device */ in aat1290_led_probe()
499 ret = led_classdev_flash_register_ext(&pdev->dev, fled_cdev, in aat1290_led_probe()
506 /* Create V4L2 Flash subdev. */ in aat1290_led_probe()
507 led->v4l2_flash = v4l2_flash_init(dev, of_fwnode_handle(sub_node), in aat1290_led_probe()
510 if (IS_ERR(led->v4l2_flash)) { in aat1290_led_probe()
511 ret = PTR_ERR(led->v4l2_flash); in aat1290_led_probe()
520 mutex_destroy(&led->lock); in aat1290_led_probe()
529 v4l2_flash_release(led->v4l2_flash); in aat1290_led_remove()
530 led_classdev_flash_unregister(&led->fled_cdev); in aat1290_led_remove()
532 mutex_destroy(&led->lock); in aat1290_led_remove()
555 MODULE_DESCRIPTION("Skyworks Current Regulator for Flash LEDs");