Lines Matching full:led

3  *	LED Flash class driver for the AAT1290
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 */
57 /* max LED brightness level */
67 /* corresponding LED Flash class device */
96 static void aat1290_as2cwire_write(struct aat1290_led *led, int addr, int value) in aat1290_as2cwire_write() argument
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()
126 static void aat1290_set_flash_safety_timer(struct aat1290_led *led, in aat1290_set_flash_safety_timer() argument
129 struct led_classdev_flash *fled_cdev = &led->fled_cdev; in aat1290_set_flash_safety_timer()
134 aat1290_as2cwire_write(led, AAT1290_FLASH_SAFETY_TIMER_ADDR, in aat1290_set_flash_safety_timer()
138 /* LED subsystem callbacks */
144 struct aat1290_led *led = fled_cdev_to_led(fled_cdev); in aat1290_led_brightness_set() local
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()
154 aat1290_as2cwire_write(led, in aat1290_led_brightness_set()
157 led->movie_mode = true; in aat1290_led_brightness_set()
160 aat1290_as2cwire_write(led, AAT1290_MOVIE_MODE_CURRENT_ADDR, in aat1290_led_brightness_set()
162 aat1290_as2cwire_write(led, AAT1290_MOVIE_MODE_CONFIG_ADDR, in aat1290_led_brightness_set()
166 mutex_unlock(&led->lock); in aat1290_led_brightness_set()
175 struct aat1290_led *led = fled_cdev_to_led(fled_cdev); in aat1290_led_flash_strobe_set() local
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()
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()
215 static int aat1290_led_parse_dt(struct aat1290_led *led, in aat1290_led_parse_dt() argument
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()
253 dev_err(dev, "No DT child node found for connected LED.\n"); in aat1290_led_parse_dt()
257 ret = of_property_read_u32(child_node, "led-max-microamp", 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()
291 static void aat1290_led_validate_mm_current(struct aat1290_led *led, in aat1290_led_validate_mm_current() argument
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()
308 static int init_mm_current_scale(struct aat1290_led *led, in init_mm_current_scale() argument
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()
325 led->mm_current_scale[i] = max_mm_current * in init_mm_current_scale()
331 static int aat1290_led_get_configuration(struct aat1290_led *led, in aat1290_led_get_configuration() argument
337 ret = aat1290_led_parse_dt(led, cfg, sub_node); in aat1290_led_get_configuration()
342 * on the max flash current from led configuration. in aat1290_led_get_configuration()
344 ret = init_mm_current_scale(led, cfg); in aat1290_led_get_configuration()
348 aat1290_led_validate_mm_current(led, cfg); in aat1290_led_get_configuration()
352 devm_kfree(&led->pdev->dev, led->mm_current_scale); in aat1290_led_get_configuration()
358 static void aat1290_init_flash_timeout(struct aat1290_led *led, in aat1290_init_flash_timeout() argument
361 struct led_classdev_flash *fled_cdev = &led->fled_cdev; in aat1290_init_flash_timeout()
378 struct aat1290_led *led = fled_cdev_to_led(fled_cdev); in aat1290_intensity_to_brightness() local
382 if (intensity >= led->mm_current_scale[i]) in aat1290_intensity_to_brightness()
392 struct aat1290_led *led = fled_cdev_to_led(fled_cdev); in aat1290_brightness_to_intensity() local
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() local
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()
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()
421 static void aat1290_init_v4l2_flash_config(struct aat1290_led *led, in aat1290_init_v4l2_flash_config() argument
425 struct led_classdev *led_cdev = &led->fled_cdev.led_cdev; in aat1290_init_v4l2_flash_config()
432 s->min = led->mm_current_scale[0]; in aat1290_init_v4l2_flash_config()
446 static inline void aat1290_init_v4l2_flash_config(struct aat1290_led *led, in aat1290_init_v4l2_flash_config() argument
463 struct aat1290_led *led; in aat1290_led_probe() local
471 led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); in aat1290_led_probe()
472 if (!led) in aat1290_led_probe()
475 led->pdev = pdev; in aat1290_led_probe()
476 platform_set_drvdata(pdev, led); in aat1290_led_probe()
478 fled_cdev = &led->fled_cdev; in aat1290_led_probe()
482 ret = aat1290_led_get_configuration(led, &led_cfg, &sub_node); in aat1290_led_probe()
486 mutex_init(&led->lock); in aat1290_led_probe()
488 /* Initialize LED Flash class device */ in aat1290_led_probe()
493 aat1290_init_flash_timeout(led, &led_cfg); in aat1290_led_probe()
498 /* Register LED Flash class device */ in aat1290_led_probe()
504 aat1290_init_v4l2_flash_config(led, &led_cfg, &v4l2_sd_cfg); 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()
527 struct aat1290_led *led = platform_get_drvdata(pdev); in aat1290_led_remove() local
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()