Lines Matching refs:led
11 #include <linux/led-class-flash.h>
20 #include <media/v4l2-flash-led-class.h>
80 /* sub led data */
140 static inline bool max77693_fled_used(struct max77693_led_device *led,
145 return led->fled_mask & fled_bit;
148 static int max77693_set_mode_reg(struct max77693_led_device *led, u8 mode)
150 struct regmap *rmap = led->regmap;
163 * camera sensors use torch led to fathom ambient light
180 static int max77693_add_mode(struct max77693_led_device *led, u8 mode)
185 if (led->iout_joint)
196 led->mode_flags &= (~MODE_TORCH(i) & ~MODE_FLASH(i));
198 new_mode_flags = mode | led->mode_flags;
199 new_mode_flags &= led->allowed_modes;
201 if (new_mode_flags ^ led->mode_flags)
202 led->mode_flags = new_mode_flags;
206 ret = max77693_set_mode_reg(led, led->mode_flags);
215 led->mode_flags &= ~mode;
220 static int max77693_clear_mode(struct max77693_led_device *led,
223 if (led->iout_joint)
227 led->mode_flags &= ~mode;
229 return max77693_set_mode_reg(led, led->mode_flags);
232 static void max77693_add_allowed_modes(struct max77693_led_device *led,
236 led->allowed_modes |= (MODE_FLASH(fled_id) |
239 led->allowed_modes |= MODE_TORCH(fled_id);
242 static void max77693_distribute_currents(struct max77693_led_device *led,
246 if (!led->iout_joint) {
248 max77693_add_allowed_modes(led, fled_id, mode);
256 led->allowed_modes &= ~MODE_FLASH_MASK;
258 led->allowed_modes &= ~MODE_TORCH_MASK;
260 max77693_add_allowed_modes(led, FLED1, mode);
263 max77693_add_allowed_modes(led, FLED2, mode);
266 static int max77693_set_torch_current(struct max77693_led_device *led,
269 struct regmap *rmap = led->regmap;
273 max77693_distribute_currents(led, fled_id, TORCH, micro_amp,
274 led->iout_torch_max, iout);
276 if (fled_id == FLED1 || led->iout_joint) {
278 led->torch_iout_reg &= TORCH_IOUT_MASK(TORCH_IOUT2_SHIFT);
280 if (fled_id == FLED2 || led->iout_joint) {
282 led->torch_iout_reg &= TORCH_IOUT_MASK(TORCH_IOUT1_SHIFT);
285 led->torch_iout_reg |= ((iout1_reg << TORCH_IOUT1_SHIFT) |
289 led->torch_iout_reg);
292 static int max77693_set_flash_current(struct max77693_led_device *led,
296 struct regmap *rmap = led->regmap;
301 max77693_distribute_currents(led, fled_id, FLASH, micro_amp,
302 led->iout_flash_max, iout);
304 if (fled_id == FLED1 || led->iout_joint) {
311 if (fled_id == FLED2 || led->iout_joint) {
320 static int max77693_set_timeout(struct max77693_led_device *led, u32 microsec)
322 struct regmap *rmap = led->regmap;
332 led->current_flash_timeout = microsec;
337 static int max77693_get_strobe_status(struct max77693_led_device *led,
340 struct regmap *rmap = led->regmap;
355 struct max77693_led_device *led = sub_led_to_led(sub_led);
356 struct regmap *rmap = led->regmap;
363 if (led->iout_joint) {
390 static int max77693_setup(struct max77693_led_device *led,
393 struct regmap *rmap = led->regmap;
403 if (led->iout_joint) {
409 first_led = max77693_fled_used(led, FLED1) ? FLED1 : FLED2;
410 last_led = max77693_fled_used(led, FLED2) ? FLED2 : FLED1;
416 ret = max77693_set_flash_current(led, i,
445 if (max77693_fled_used(led, FLED1) && max77693_fled_used(led, FLED2))
457 return max77693_set_mode_reg(led, MODE_OFF);
466 struct max77693_led_device *led = sub_led_to_led(sub_led);
469 mutex_lock(&led->lock);
472 ret = max77693_clear_mode(led, MODE_TORCH(fled_id));
474 dev_dbg(&led->pdev->dev,
480 ret = max77693_set_torch_current(led, fled_id, value * TORCH_IOUT_STEP);
482 dev_dbg(&led->pdev->dev,
488 ret = max77693_add_mode(led, MODE_TORCH(fled_id));
490 dev_dbg(&led->pdev->dev,
494 mutex_unlock(&led->lock);
504 struct max77693_led_device *led = sub_led_to_led(sub_led);
507 mutex_lock(&led->lock);
508 ret = max77693_set_flash_current(led, sub_led->fled_id, brightness);
509 mutex_unlock(&led->lock);
519 struct max77693_led_device *led = sub_led_to_led(sub_led);
523 mutex_lock(&led->lock);
526 ret = max77693_clear_mode(led, MODE_FLASH(fled_id));
530 if (sub_led->flash_timeout != led->current_flash_timeout) {
531 ret = max77693_set_timeout(led, sub_led->flash_timeout);
536 led->strobing_sub_led_id = fled_id;
538 ret = max77693_add_mode(led, MODE_FLASH(fled_id));
545 mutex_unlock(&led->lock);
565 struct max77693_led_device *led = sub_led_to_led(sub_led);
571 mutex_lock(&led->lock);
573 ret = max77693_get_strobe_status(led, state);
575 *state = !!(*state && (led->strobing_sub_led_id == sub_led->fled_id));
577 mutex_unlock(&led->lock);
587 struct max77693_led_device *led = sub_led_to_led(sub_led);
589 mutex_lock(&led->lock);
591 mutex_unlock(&led->lock);
596 static int max77693_led_parse_dt(struct max77693_led_device *led,
600 struct device *dev = &led->pdev->dev;
601 struct max77693_sub_led *sub_leds = led->sub_leds;
612 prop = of_find_property(child_node, "led-sources", NULL);
624 "led-sources DT property missing\n");
631 led->fled_mask = FLED1_IOUT | FLED2_IOUT;
634 led->fled_mask |= FLED1_IOUT;
637 led->fled_mask |= FLED2_IOUT;
640 "Wrong led-sources DT property value.\n");
647 "Conflicting \"led-sources\" DT properties\n");
659 ret = of_property_read_u32(child_node, "led-max-microamp",
663 dev_warn(dev, "led-max-microamp DT property missing\n");
683 (max77693_fled_used(led, FLED1) &&
684 max77693_fled_used(led, FLED2))) {
705 static void max77693_align_iout_current(struct max77693_led_device *led,
710 if (led->iout_joint) {
722 if (max77693_fled_used(led, i))
728 static void max77693_led_validate_configuration(struct max77693_led_device *led,
736 max77693_fled_used(led, FLED1) && max77693_fled_used(led, FLED2))
737 led->iout_joint = true;
743 if ((cfg->boost_mode == MAX77693_LED_BOOST_NONE) && led->iout_joint)
746 max77693_align_iout_current(led, cfg->iout_torch_max,
749 max77693_align_iout_current(led, cfg->iout_flash_max,
764 static int max77693_led_get_configuration(struct max77693_led_device *led,
770 ret = max77693_led_parse_dt(led, cfg, sub_nodes);
774 max77693_led_validate_configuration(led, cfg);
776 memcpy(led->iout_torch_max, cfg->iout_torch_max,
777 sizeof(led->iout_torch_max));
778 memcpy(led->iout_flash_max, cfg->iout_flash_max,
779 sizeof(led->iout_flash_max));
796 struct max77693_led_device *led = sub_led_to_led(sub_led);
803 setting->max = led->iout_joint ?
826 struct max77693_led_device *led = sub_led_to_led(sub_led);
830 mutex_lock(&led->lock);
833 ret = max77693_add_mode(led, MODE_FLASH_EXTERNAL(fled_id));
835 ret = max77693_clear_mode(led, MODE_FLASH_EXTERNAL(fled_id));
837 mutex_unlock(&led->lock);
846 struct max77693_led_device *led = sub_led_to_led(sub_led);
847 struct device *dev = &led->pdev->dev;
886 struct max77693_led_device *led = sub_led_to_led(sub_led);
899 led_cdev->max_brightness = (led->iout_joint ?
916 struct max77693_led_device *led = sub_led_to_led(sub_led);
918 struct device *dev = &led->pdev->dev;
949 struct max77693_led_device *led;
955 led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
956 if (!led)
959 led->pdev = pdev;
960 led->regmap = iodev->regmap;
961 led->allowed_modes = MODE_FLASH_MASK;
962 sub_leds = led->sub_leds;
964 platform_set_drvdata(pdev, led);
965 ret = max77693_led_get_configuration(led, &led_cfg, sub_nodes);
969 ret = max77693_setup(led, &led_cfg);
973 mutex_init(&led->lock);
976 led->iout_joint || max77693_fled_used(led, FLED1);
978 !led->iout_joint && max77693_fled_used(led, FLED2);
1014 mutex_destroy(&led->lock);
1021 struct max77693_led_device *led = platform_get_drvdata(pdev);
1022 struct max77693_sub_led *sub_leds = led->sub_leds;
1024 if (led->iout_joint || max77693_fled_used(led, FLED1)) {
1029 if (!led->iout_joint && max77693_fled_used(led, FLED2)) {
1034 mutex_destroy(&led->lock);
1040 { .compatible = "maxim,max77693-led" },
1049 .name = "max77693-led",
1058 MODULE_DESCRIPTION("Maxim MAX77693 led flash driver");