Lines Matching refs:led
143 static inline bool max77693_fled_used(struct max77693_led_device *led, in max77693_fled_used() argument
148 return led->fled_mask & fled_bit; in max77693_fled_used()
151 static int max77693_set_mode_reg(struct max77693_led_device *led, u8 mode) in max77693_set_mode_reg() argument
153 struct regmap *rmap = led->regmap; in max77693_set_mode_reg()
183 static int max77693_add_mode(struct max77693_led_device *led, u8 mode) in max77693_add_mode() argument
188 if (led->iout_joint) in max77693_add_mode()
199 led->mode_flags &= (~MODE_TORCH(i) & ~MODE_FLASH(i)); in max77693_add_mode()
201 new_mode_flags = mode | led->mode_flags; in max77693_add_mode()
202 new_mode_flags &= led->allowed_modes; in max77693_add_mode()
204 if (new_mode_flags ^ led->mode_flags) in max77693_add_mode()
205 led->mode_flags = new_mode_flags; in max77693_add_mode()
209 ret = max77693_set_mode_reg(led, led->mode_flags); in max77693_add_mode()
218 led->mode_flags &= ~mode; in max77693_add_mode()
223 static int max77693_clear_mode(struct max77693_led_device *led, in max77693_clear_mode() argument
226 if (led->iout_joint) in max77693_clear_mode()
230 led->mode_flags &= ~mode; in max77693_clear_mode()
232 return max77693_set_mode_reg(led, led->mode_flags); in max77693_clear_mode()
235 static void max77693_add_allowed_modes(struct max77693_led_device *led, in max77693_add_allowed_modes() argument
239 led->allowed_modes |= (MODE_FLASH(fled_id) | in max77693_add_allowed_modes()
242 led->allowed_modes |= MODE_TORCH(fled_id); in max77693_add_allowed_modes()
245 static void max77693_distribute_currents(struct max77693_led_device *led, in max77693_distribute_currents() argument
249 if (!led->iout_joint) { in max77693_distribute_currents()
251 max77693_add_allowed_modes(led, fled_id, mode); in max77693_distribute_currents()
259 led->allowed_modes &= ~MODE_FLASH_MASK; in max77693_distribute_currents()
261 led->allowed_modes &= ~MODE_TORCH_MASK; in max77693_distribute_currents()
263 max77693_add_allowed_modes(led, FLED1, mode); in max77693_distribute_currents()
266 max77693_add_allowed_modes(led, FLED2, mode); in max77693_distribute_currents()
269 static int max77693_set_torch_current(struct max77693_led_device *led, in max77693_set_torch_current() argument
272 struct regmap *rmap = led->regmap; in max77693_set_torch_current()
276 max77693_distribute_currents(led, fled_id, TORCH, micro_amp, in max77693_set_torch_current()
277 led->iout_torch_max, iout); in max77693_set_torch_current()
279 if (fled_id == FLED1 || led->iout_joint) { in max77693_set_torch_current()
281 led->torch_iout_reg &= TORCH_IOUT_MASK(TORCH_IOUT2_SHIFT); in max77693_set_torch_current()
283 if (fled_id == FLED2 || led->iout_joint) { in max77693_set_torch_current()
285 led->torch_iout_reg &= TORCH_IOUT_MASK(TORCH_IOUT1_SHIFT); in max77693_set_torch_current()
288 led->torch_iout_reg |= ((iout1_reg << TORCH_IOUT1_SHIFT) | in max77693_set_torch_current()
292 led->torch_iout_reg); in max77693_set_torch_current()
295 static int max77693_set_flash_current(struct max77693_led_device *led, in max77693_set_flash_current() argument
299 struct regmap *rmap = led->regmap; in max77693_set_flash_current()
304 max77693_distribute_currents(led, fled_id, FLASH, micro_amp, in max77693_set_flash_current()
305 led->iout_flash_max, iout); in max77693_set_flash_current()
307 if (fled_id == FLED1 || led->iout_joint) { in max77693_set_flash_current()
314 if (fled_id == FLED2 || led->iout_joint) { in max77693_set_flash_current()
323 static int max77693_set_timeout(struct max77693_led_device *led, u32 microsec) in max77693_set_timeout() argument
325 struct regmap *rmap = led->regmap; in max77693_set_timeout()
335 led->current_flash_timeout = microsec; in max77693_set_timeout()
340 static int max77693_get_strobe_status(struct max77693_led_device *led, in max77693_get_strobe_status() argument
343 struct regmap *rmap = led->regmap; in max77693_get_strobe_status()
358 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_get_flash_faults() local
359 struct regmap *rmap = led->regmap; in max77693_get_flash_faults()
366 if (led->iout_joint) { in max77693_get_flash_faults()
393 static int max77693_setup(struct max77693_led_device *led, in max77693_setup() argument
396 struct regmap *rmap = led->regmap; in max77693_setup()
406 if (led->iout_joint) { in max77693_setup()
412 first_led = max77693_fled_used(led, FLED1) ? FLED1 : FLED2; in max77693_setup()
413 last_led = max77693_fled_used(led, FLED2) ? FLED2 : FLED1; in max77693_setup()
419 ret = max77693_set_flash_current(led, i, in max77693_setup()
448 if (max77693_fled_used(led, FLED1) && max77693_fled_used(led, FLED2)) in max77693_setup()
460 return max77693_set_mode_reg(led, MODE_OFF); in max77693_setup()
469 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_brightness_set() local
472 mutex_lock(&led->lock); in max77693_led_brightness_set()
475 ret = max77693_clear_mode(led, MODE_TORCH(fled_id)); in max77693_led_brightness_set()
477 dev_dbg(&led->pdev->dev, in max77693_led_brightness_set()
483 ret = max77693_set_torch_current(led, fled_id, value * TORCH_IOUT_STEP); in max77693_led_brightness_set()
485 dev_dbg(&led->pdev->dev, in max77693_led_brightness_set()
491 ret = max77693_add_mode(led, MODE_TORCH(fled_id)); in max77693_led_brightness_set()
493 dev_dbg(&led->pdev->dev, in max77693_led_brightness_set()
497 mutex_unlock(&led->lock); in max77693_led_brightness_set()
507 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_brightness_set() local
510 mutex_lock(&led->lock); in max77693_led_flash_brightness_set()
511 ret = max77693_set_flash_current(led, sub_led->fled_id, brightness); in max77693_led_flash_brightness_set()
512 mutex_unlock(&led->lock); in max77693_led_flash_brightness_set()
522 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_strobe_set() local
526 mutex_lock(&led->lock); in max77693_led_flash_strobe_set()
529 ret = max77693_clear_mode(led, MODE_FLASH(fled_id)); in max77693_led_flash_strobe_set()
533 if (sub_led->flash_timeout != led->current_flash_timeout) { in max77693_led_flash_strobe_set()
534 ret = max77693_set_timeout(led, sub_led->flash_timeout); in max77693_led_flash_strobe_set()
539 led->strobing_sub_led_id = fled_id; in max77693_led_flash_strobe_set()
541 ret = max77693_add_mode(led, MODE_FLASH(fled_id)); in max77693_led_flash_strobe_set()
548 mutex_unlock(&led->lock); in max77693_led_flash_strobe_set()
568 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_strobe_get() local
574 mutex_lock(&led->lock); in max77693_led_flash_strobe_get()
576 ret = max77693_get_strobe_status(led, state); in max77693_led_flash_strobe_get()
578 *state = !!(*state && (led->strobing_sub_led_id == sub_led->fled_id)); in max77693_led_flash_strobe_get()
580 mutex_unlock(&led->lock); in max77693_led_flash_strobe_get()
590 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_timeout_set() local
592 mutex_lock(&led->lock); in max77693_led_flash_timeout_set()
594 mutex_unlock(&led->lock); in max77693_led_flash_timeout_set()
599 static int max77693_led_parse_dt(struct max77693_led_device *led, in max77693_led_parse_dt() argument
603 struct device *dev = &led->pdev->dev; in max77693_led_parse_dt()
604 struct max77693_sub_led *sub_leds = led->sub_leds; in max77693_led_parse_dt()
634 led->fled_mask = FLED1_IOUT | FLED2_IOUT; in max77693_led_parse_dt()
637 led->fled_mask |= FLED1_IOUT; in max77693_led_parse_dt()
640 led->fled_mask |= FLED2_IOUT; in max77693_led_parse_dt()
686 (max77693_fled_used(led, FLED1) && in max77693_led_parse_dt()
687 max77693_fled_used(led, FLED2))) { in max77693_led_parse_dt()
708 static void max77693_align_iout_current(struct max77693_led_device *led, in max77693_align_iout_current() argument
713 if (led->iout_joint) { in max77693_align_iout_current()
725 if (max77693_fled_used(led, i)) in max77693_align_iout_current()
731 static void max77693_led_validate_configuration(struct max77693_led_device *led, in max77693_led_validate_configuration() argument
739 max77693_fled_used(led, FLED1) && max77693_fled_used(led, FLED2)) in max77693_led_validate_configuration()
740 led->iout_joint = true; in max77693_led_validate_configuration()
746 if ((cfg->boost_mode == MAX77693_LED_BOOST_NONE) && led->iout_joint) in max77693_led_validate_configuration()
749 max77693_align_iout_current(led, cfg->iout_torch_max, in max77693_led_validate_configuration()
752 max77693_align_iout_current(led, cfg->iout_flash_max, in max77693_led_validate_configuration()
767 static int max77693_led_get_configuration(struct max77693_led_device *led, in max77693_led_get_configuration() argument
773 ret = max77693_led_parse_dt(led, cfg, sub_nodes); in max77693_led_get_configuration()
777 max77693_led_validate_configuration(led, cfg); in max77693_led_get_configuration()
779 memcpy(led->iout_torch_max, cfg->iout_torch_max, in max77693_led_get_configuration()
780 sizeof(led->iout_torch_max)); in max77693_led_get_configuration()
781 memcpy(led->iout_flash_max, cfg->iout_flash_max, in max77693_led_get_configuration()
782 sizeof(led->iout_flash_max)); in max77693_led_get_configuration()
799 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_init_flash_settings() local
806 setting->max = led->iout_joint ? in max77693_init_flash_settings()
829 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_external_strobe_set() local
833 mutex_lock(&led->lock); in max77693_led_external_strobe_set()
836 ret = max77693_add_mode(led, MODE_FLASH_EXTERNAL(fled_id)); in max77693_led_external_strobe_set()
838 ret = max77693_clear_mode(led, MODE_FLASH_EXTERNAL(fled_id)); in max77693_led_external_strobe_set()
840 mutex_unlock(&led->lock); in max77693_led_external_strobe_set()
849 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_init_v4l2_flash_config() local
850 struct device *dev = &led->pdev->dev; in max77693_init_v4l2_flash_config()
889 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_init_fled_cdev() local
902 led_cdev->max_brightness = (led->iout_joint ? in max77693_init_fled_cdev()
919 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_register_led() local
921 struct device *dev = &led->pdev->dev; in max77693_register_led()
952 struct max77693_led_device *led; in max77693_led_probe() local
958 led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); in max77693_led_probe()
959 if (!led) in max77693_led_probe()
962 led->pdev = pdev; in max77693_led_probe()
963 led->regmap = iodev->regmap; in max77693_led_probe()
964 led->allowed_modes = MODE_FLASH_MASK; in max77693_led_probe()
965 sub_leds = led->sub_leds; in max77693_led_probe()
967 platform_set_drvdata(pdev, led); in max77693_led_probe()
968 ret = max77693_led_get_configuration(led, &led_cfg, sub_nodes); in max77693_led_probe()
972 ret = max77693_setup(led, &led_cfg); in max77693_led_probe()
976 mutex_init(&led->lock); in max77693_led_probe()
979 led->iout_joint || max77693_fled_used(led, FLED1); in max77693_led_probe()
981 !led->iout_joint && max77693_fled_used(led, FLED2); in max77693_led_probe()
1017 mutex_destroy(&led->lock); in max77693_led_probe()
1024 struct max77693_led_device *led = platform_get_drvdata(pdev); in max77693_led_remove() local
1025 struct max77693_sub_led *sub_leds = led->sub_leds; in max77693_led_remove()
1027 if (led->iout_joint || max77693_fled_used(led, FLED1)) { in max77693_led_remove()
1032 if (!led->iout_joint && max77693_fled_used(led, FLED2)) { in max77693_led_remove()
1037 mutex_destroy(&led->lock); in max77693_led_remove()