Lines Matching full:led

3  * LED Flash class driver for the flash cell of max77693 mfd.
11 #include <linux/led-class-flash.h>
20 #include <media/v4l2-flash-led-class.h>
59 /* corresponding LED Flash class device */
80 /* sub led data */
140 static inline bool max77693_fled_used(struct max77693_led_device *led, in max77693_fled_used() argument
145 return led->fled_mask & fled_bit; in max77693_fled_used()
148 static int max77693_set_mode_reg(struct max77693_led_device *led, u8 mode) in max77693_set_mode_reg() argument
150 struct regmap *rmap = led->regmap; in max77693_set_mode_reg()
163 * camera sensors use torch led to fathom ambient light in max77693_set_mode_reg()
180 static int max77693_add_mode(struct max77693_led_device *led, u8 mode) in max77693_add_mode() argument
185 if (led->iout_joint) in max77693_add_mode()
196 led->mode_flags &= (~MODE_TORCH(i) & ~MODE_FLASH(i)); in max77693_add_mode()
198 new_mode_flags = mode | led->mode_flags; in max77693_add_mode()
199 new_mode_flags &= led->allowed_modes; in max77693_add_mode()
201 if (new_mode_flags ^ led->mode_flags) in max77693_add_mode()
202 led->mode_flags = new_mode_flags; in max77693_add_mode()
206 ret = max77693_set_mode_reg(led, led->mode_flags); in max77693_add_mode()
215 led->mode_flags &= ~mode; in max77693_add_mode()
220 static int max77693_clear_mode(struct max77693_led_device *led, in max77693_clear_mode() argument
223 if (led->iout_joint) in max77693_clear_mode()
227 led->mode_flags &= ~mode; in max77693_clear_mode()
229 return max77693_set_mode_reg(led, led->mode_flags); in max77693_clear_mode()
232 static void max77693_add_allowed_modes(struct max77693_led_device *led, in max77693_add_allowed_modes() argument
236 led->allowed_modes |= (MODE_FLASH(fled_id) | in max77693_add_allowed_modes()
239 led->allowed_modes |= MODE_TORCH(fled_id); in max77693_add_allowed_modes()
242 static void max77693_distribute_currents(struct max77693_led_device *led, in max77693_distribute_currents() argument
246 if (!led->iout_joint) { in max77693_distribute_currents()
248 max77693_add_allowed_modes(led, fled_id, mode); in max77693_distribute_currents()
256 led->allowed_modes &= ~MODE_FLASH_MASK; in max77693_distribute_currents()
258 led->allowed_modes &= ~MODE_TORCH_MASK; in max77693_distribute_currents()
260 max77693_add_allowed_modes(led, FLED1, mode); in max77693_distribute_currents()
263 max77693_add_allowed_modes(led, FLED2, mode); in max77693_distribute_currents()
266 static int max77693_set_torch_current(struct max77693_led_device *led, in max77693_set_torch_current() argument
269 struct regmap *rmap = led->regmap; in max77693_set_torch_current()
273 max77693_distribute_currents(led, fled_id, TORCH, micro_amp, in max77693_set_torch_current()
274 led->iout_torch_max, iout); in max77693_set_torch_current()
276 if (fled_id == FLED1 || led->iout_joint) { in max77693_set_torch_current()
278 led->torch_iout_reg &= TORCH_IOUT_MASK(TORCH_IOUT2_SHIFT); in max77693_set_torch_current()
280 if (fled_id == FLED2 || led->iout_joint) { in max77693_set_torch_current()
282 led->torch_iout_reg &= TORCH_IOUT_MASK(TORCH_IOUT1_SHIFT); in max77693_set_torch_current()
285 led->torch_iout_reg |= ((iout1_reg << TORCH_IOUT1_SHIFT) | in max77693_set_torch_current()
289 led->torch_iout_reg); in max77693_set_torch_current()
292 static int max77693_set_flash_current(struct max77693_led_device *led, in max77693_set_flash_current() argument
296 struct regmap *rmap = led->regmap; in max77693_set_flash_current()
301 max77693_distribute_currents(led, fled_id, FLASH, micro_amp, in max77693_set_flash_current()
302 led->iout_flash_max, iout); in max77693_set_flash_current()
304 if (fled_id == FLED1 || led->iout_joint) { in max77693_set_flash_current()
311 if (fled_id == FLED2 || led->iout_joint) { in max77693_set_flash_current()
320 static int max77693_set_timeout(struct max77693_led_device *led, u32 microsec) in max77693_set_timeout() argument
322 struct regmap *rmap = led->regmap; in max77693_set_timeout()
332 led->current_flash_timeout = microsec; in max77693_set_timeout()
337 static int max77693_get_strobe_status(struct max77693_led_device *led, in max77693_get_strobe_status() argument
340 struct regmap *rmap = led->regmap; in max77693_get_strobe_status()
355 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_get_flash_faults() local
356 struct regmap *rmap = led->regmap; in max77693_get_flash_faults()
363 if (led->iout_joint) { in max77693_get_flash_faults()
390 static int max77693_setup(struct max77693_led_device *led, in max77693_setup() argument
393 struct regmap *rmap = led->regmap; in max77693_setup()
403 if (led->iout_joint) { in max77693_setup()
409 first_led = max77693_fled_used(led, FLED1) ? FLED1 : FLED2; in max77693_setup()
410 last_led = max77693_fled_used(led, FLED2) ? FLED2 : FLED1; in max77693_setup()
416 ret = max77693_set_flash_current(led, i, in max77693_setup()
445 if (max77693_fled_used(led, FLED1) && max77693_fled_used(led, FLED2)) in max77693_setup()
457 return max77693_set_mode_reg(led, MODE_OFF); in max77693_setup()
460 /* LED subsystem callbacks */
466 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_brightness_set() local
469 mutex_lock(&led->lock); in max77693_led_brightness_set()
472 ret = max77693_clear_mode(led, MODE_TORCH(fled_id)); in max77693_led_brightness_set()
474 dev_dbg(&led->pdev->dev, in max77693_led_brightness_set()
480 ret = max77693_set_torch_current(led, fled_id, value * TORCH_IOUT_STEP); in max77693_led_brightness_set()
482 dev_dbg(&led->pdev->dev, in max77693_led_brightness_set()
488 ret = max77693_add_mode(led, MODE_TORCH(fled_id)); in max77693_led_brightness_set()
490 dev_dbg(&led->pdev->dev, in max77693_led_brightness_set()
494 mutex_unlock(&led->lock); in max77693_led_brightness_set()
504 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_brightness_set() local
507 mutex_lock(&led->lock); in max77693_led_flash_brightness_set()
508 ret = max77693_set_flash_current(led, sub_led->fled_id, brightness); in max77693_led_flash_brightness_set()
509 mutex_unlock(&led->lock); in max77693_led_flash_brightness_set()
519 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_strobe_set() local
523 mutex_lock(&led->lock); in max77693_led_flash_strobe_set()
526 ret = max77693_clear_mode(led, MODE_FLASH(fled_id)); in max77693_led_flash_strobe_set()
530 if (sub_led->flash_timeout != led->current_flash_timeout) { in max77693_led_flash_strobe_set()
531 ret = max77693_set_timeout(led, sub_led->flash_timeout); in max77693_led_flash_strobe_set()
536 led->strobing_sub_led_id = fled_id; in max77693_led_flash_strobe_set()
538 ret = max77693_add_mode(led, MODE_FLASH(fled_id)); in max77693_led_flash_strobe_set()
545 mutex_unlock(&led->lock); in max77693_led_flash_strobe_set()
565 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_strobe_get() local
571 mutex_lock(&led->lock); in max77693_led_flash_strobe_get()
573 ret = max77693_get_strobe_status(led, state); in max77693_led_flash_strobe_get()
575 *state = !!(*state && (led->strobing_sub_led_id == sub_led->fled_id)); in max77693_led_flash_strobe_get()
577 mutex_unlock(&led->lock); in max77693_led_flash_strobe_get()
587 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_timeout_set() local
589 mutex_lock(&led->lock); in max77693_led_flash_timeout_set()
591 mutex_unlock(&led->lock); in max77693_led_flash_timeout_set()
596 static int max77693_led_parse_dt(struct max77693_led_device *led, in max77693_led_parse_dt() argument
600 struct device *dev = &led->pdev->dev; in max77693_led_parse_dt()
601 struct max77693_sub_led *sub_leds = led->sub_leds; in max77693_led_parse_dt()
612 prop = of_find_property(child_node, "led-sources", NULL); in max77693_led_parse_dt()
624 "led-sources DT property missing\n"); in max77693_led_parse_dt()
630 led->fled_mask = FLED1_IOUT | FLED2_IOUT; in max77693_led_parse_dt()
633 led->fled_mask |= FLED1_IOUT; in max77693_led_parse_dt()
636 led->fled_mask |= FLED2_IOUT; in max77693_led_parse_dt()
639 "Wrong led-sources DT property value.\n"); in max77693_led_parse_dt()
645 "Conflicting \"led-sources\" DT properties\n"); in max77693_led_parse_dt()
656 ret = of_property_read_u32(child_node, "led-max-microamp", in max77693_led_parse_dt()
660 dev_warn(dev, "led-max-microamp DT property missing\n"); in max77693_led_parse_dt()
680 (max77693_fled_used(led, FLED1) && in max77693_led_parse_dt()
681 max77693_fled_used(led, FLED2))) in max77693_led_parse_dt()
686 dev_err(dev, "No DT child node found for connected LED(s).\n"); in max77693_led_parse_dt()
700 static void max77693_align_iout_current(struct max77693_led_device *led, in max77693_align_iout_current() argument
705 if (led->iout_joint) { in max77693_align_iout_current()
717 if (max77693_fled_used(led, i)) in max77693_align_iout_current()
723 static void max77693_led_validate_configuration(struct max77693_led_device *led, in max77693_led_validate_configuration() argument
731 max77693_fled_used(led, FLED1) && max77693_fled_used(led, FLED2)) in max77693_led_validate_configuration()
732 led->iout_joint = true; in max77693_led_validate_configuration()
738 if ((cfg->boost_mode == MAX77693_LED_BOOST_NONE) && led->iout_joint) in max77693_led_validate_configuration()
741 max77693_align_iout_current(led, cfg->iout_torch_max, in max77693_led_validate_configuration()
744 max77693_align_iout_current(led, cfg->iout_flash_max, in max77693_led_validate_configuration()
759 static int max77693_led_get_configuration(struct max77693_led_device *led, in max77693_led_get_configuration() argument
765 ret = max77693_led_parse_dt(led, cfg, sub_nodes); in max77693_led_get_configuration()
769 max77693_led_validate_configuration(led, cfg); in max77693_led_get_configuration()
771 memcpy(led->iout_torch_max, cfg->iout_torch_max, in max77693_led_get_configuration()
772 sizeof(led->iout_torch_max)); in max77693_led_get_configuration()
773 memcpy(led->iout_flash_max, cfg->iout_flash_max, in max77693_led_get_configuration()
774 sizeof(led->iout_flash_max)); in max77693_led_get_configuration()
791 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_init_flash_settings() local
798 setting->max = led->iout_joint ? in max77693_init_flash_settings()
821 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_external_strobe_set() local
825 mutex_lock(&led->lock); in max77693_led_external_strobe_set()
828 ret = max77693_add_mode(led, MODE_FLASH_EXTERNAL(fled_id)); in max77693_led_external_strobe_set()
830 ret = max77693_clear_mode(led, MODE_FLASH_EXTERNAL(fled_id)); in max77693_led_external_strobe_set()
832 mutex_unlock(&led->lock); in max77693_led_external_strobe_set()
841 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_init_v4l2_flash_config() local
842 struct device *dev = &led->pdev->dev; in max77693_init_v4l2_flash_config()
881 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_init_fled_cdev() local
886 /* Initialize LED Flash class device */ in max77693_init_fled_cdev()
894 led_cdev->max_brightness = (led->iout_joint ? in max77693_init_fled_cdev()
911 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_register_led() local
913 struct device *dev = &led->pdev->dev; in max77693_register_led()
917 /* Register in the LED subsystem */ in max77693_register_led()
944 struct max77693_led_device *led; in max77693_led_probe() local
950 led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); in max77693_led_probe()
951 if (!led) in max77693_led_probe()
954 led->pdev = pdev; in max77693_led_probe()
955 led->regmap = iodev->regmap; in max77693_led_probe()
956 led->allowed_modes = MODE_FLASH_MASK; in max77693_led_probe()
957 sub_leds = led->sub_leds; in max77693_led_probe()
959 platform_set_drvdata(pdev, led); in max77693_led_probe()
960 ret = max77693_led_get_configuration(led, &led_cfg, sub_nodes); in max77693_led_probe()
964 ret = max77693_setup(led, &led_cfg); in max77693_led_probe()
968 mutex_init(&led->lock); in max77693_led_probe()
971 led->iout_joint || max77693_fled_used(led, FLED1); in max77693_led_probe()
973 !led->iout_joint && max77693_fled_used(led, FLED2); in max77693_led_probe()
979 /* Initialize LED Flash class device */ in max77693_led_probe()
983 * Register LED Flash class device and corresponding in max77693_led_probe()
1011 mutex_destroy(&led->lock); in max77693_led_probe()
1021 struct max77693_led_device *led = platform_get_drvdata(pdev); in max77693_led_remove() local
1022 struct max77693_sub_led *sub_leds = led->sub_leds; in max77693_led_remove()
1024 if (led->iout_joint || max77693_fled_used(led, FLED1)) { in max77693_led_remove()
1029 if (!led->iout_joint && max77693_fled_used(led, FLED2)) { in max77693_led_remove()
1034 mutex_destroy(&led->lock); in max77693_led_remove()
1038 { .compatible = "maxim,max77693-led" },
1047 .name = "max77693-led",
1056 MODULE_DESCRIPTION("Maxim MAX77693 led flash driver");