Lines Matching refs:led
146 static inline bool max77693_fled_used(struct max77693_led_device *led, in max77693_fled_used() argument
151 return led->fled_mask & fled_bit; in max77693_fled_used()
154 static int max77693_set_mode_reg(struct max77693_led_device *led, u8 mode) in max77693_set_mode_reg() argument
156 struct regmap *rmap = led->regmap; in max77693_set_mode_reg()
186 static int max77693_add_mode(struct max77693_led_device *led, u8 mode) in max77693_add_mode() argument
191 if (led->iout_joint) in max77693_add_mode()
202 led->mode_flags &= (~MODE_TORCH(i) & ~MODE_FLASH(i)); in max77693_add_mode()
204 new_mode_flags = mode | led->mode_flags; in max77693_add_mode()
205 new_mode_flags &= led->allowed_modes; in max77693_add_mode()
207 if (new_mode_flags ^ led->mode_flags) in max77693_add_mode()
208 led->mode_flags = new_mode_flags; in max77693_add_mode()
212 ret = max77693_set_mode_reg(led, led->mode_flags); in max77693_add_mode()
221 led->mode_flags &= ~mode; in max77693_add_mode()
226 static int max77693_clear_mode(struct max77693_led_device *led, in max77693_clear_mode() argument
229 if (led->iout_joint) in max77693_clear_mode()
233 led->mode_flags &= ~mode; in max77693_clear_mode()
235 return max77693_set_mode_reg(led, led->mode_flags); in max77693_clear_mode()
238 static void max77693_add_allowed_modes(struct max77693_led_device *led, in max77693_add_allowed_modes() argument
242 led->allowed_modes |= (MODE_FLASH(fled_id) | in max77693_add_allowed_modes()
245 led->allowed_modes |= MODE_TORCH(fled_id); in max77693_add_allowed_modes()
248 static void max77693_distribute_currents(struct max77693_led_device *led, in max77693_distribute_currents() argument
252 if (!led->iout_joint) { in max77693_distribute_currents()
254 max77693_add_allowed_modes(led, fled_id, mode); in max77693_distribute_currents()
262 led->allowed_modes &= ~MODE_FLASH_MASK; in max77693_distribute_currents()
264 led->allowed_modes &= ~MODE_TORCH_MASK; in max77693_distribute_currents()
266 max77693_add_allowed_modes(led, FLED1, mode); in max77693_distribute_currents()
269 max77693_add_allowed_modes(led, FLED2, mode); in max77693_distribute_currents()
272 static int max77693_set_torch_current(struct max77693_led_device *led, in max77693_set_torch_current() argument
275 struct regmap *rmap = led->regmap; in max77693_set_torch_current()
279 max77693_distribute_currents(led, fled_id, TORCH, micro_amp, in max77693_set_torch_current()
280 led->iout_torch_max, iout); in max77693_set_torch_current()
282 if (fled_id == FLED1 || led->iout_joint) { in max77693_set_torch_current()
284 led->torch_iout_reg &= TORCH_IOUT_MASK(TORCH_IOUT2_SHIFT); in max77693_set_torch_current()
286 if (fled_id == FLED2 || led->iout_joint) { in max77693_set_torch_current()
288 led->torch_iout_reg &= TORCH_IOUT_MASK(TORCH_IOUT1_SHIFT); in max77693_set_torch_current()
291 led->torch_iout_reg |= ((iout1_reg << TORCH_IOUT1_SHIFT) | in max77693_set_torch_current()
295 led->torch_iout_reg); in max77693_set_torch_current()
298 static int max77693_set_flash_current(struct max77693_led_device *led, in max77693_set_flash_current() argument
302 struct regmap *rmap = led->regmap; in max77693_set_flash_current()
307 max77693_distribute_currents(led, fled_id, FLASH, micro_amp, in max77693_set_flash_current()
308 led->iout_flash_max, iout); in max77693_set_flash_current()
310 if (fled_id == FLED1 || led->iout_joint) { in max77693_set_flash_current()
317 if (fled_id == FLED2 || led->iout_joint) { in max77693_set_flash_current()
326 static int max77693_set_timeout(struct max77693_led_device *led, u32 microsec) in max77693_set_timeout() argument
328 struct regmap *rmap = led->regmap; in max77693_set_timeout()
338 led->current_flash_timeout = microsec; in max77693_set_timeout()
343 static int max77693_get_strobe_status(struct max77693_led_device *led, in max77693_get_strobe_status() argument
346 struct regmap *rmap = led->regmap; in max77693_get_strobe_status()
361 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_get_flash_faults() local
362 struct regmap *rmap = led->regmap; in max77693_get_flash_faults()
369 if (led->iout_joint) { in max77693_get_flash_faults()
396 static int max77693_setup(struct max77693_led_device *led, in max77693_setup() argument
399 struct regmap *rmap = led->regmap; in max77693_setup()
409 if (led->iout_joint) { in max77693_setup()
415 first_led = max77693_fled_used(led, FLED1) ? FLED1 : FLED2; in max77693_setup()
416 last_led = max77693_fled_used(led, FLED2) ? FLED2 : FLED1; in max77693_setup()
422 ret = max77693_set_flash_current(led, i, in max77693_setup()
451 if (max77693_fled_used(led, FLED1) && max77693_fled_used(led, FLED2)) in max77693_setup()
463 return max77693_set_mode_reg(led, MODE_OFF); in max77693_setup()
466 static int __max77693_led_brightness_set(struct max77693_led_device *led, in __max77693_led_brightness_set() argument
471 mutex_lock(&led->lock); in __max77693_led_brightness_set()
474 ret = max77693_clear_mode(led, MODE_TORCH(fled_id)); in __max77693_led_brightness_set()
476 dev_dbg(&led->pdev->dev, in __max77693_led_brightness_set()
482 ret = max77693_set_torch_current(led, fled_id, value * TORCH_IOUT_STEP); in __max77693_led_brightness_set()
484 dev_dbg(&led->pdev->dev, in __max77693_led_brightness_set()
490 ret = max77693_add_mode(led, MODE_TORCH(fled_id)); in __max77693_led_brightness_set()
492 dev_dbg(&led->pdev->dev, in __max77693_led_brightness_set()
496 mutex_unlock(&led->lock); in __max77693_led_brightness_set()
506 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_brightness_set_work() local
508 __max77693_led_brightness_set(led, sub_led->fled_id, in max77693_led_brightness_set_work()
520 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_brightness_set_sync() local
522 return __max77693_led_brightness_set(led, sub_led->fled_id, value); in max77693_led_brightness_set_sync()
541 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_brightness_set() local
544 mutex_lock(&led->lock); in max77693_led_flash_brightness_set()
545 ret = max77693_set_flash_current(led, sub_led->fled_id, brightness); in max77693_led_flash_brightness_set()
546 mutex_unlock(&led->lock); in max77693_led_flash_brightness_set()
556 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_strobe_set() local
560 mutex_lock(&led->lock); in max77693_led_flash_strobe_set()
563 ret = max77693_clear_mode(led, MODE_FLASH(fled_id)); in max77693_led_flash_strobe_set()
567 if (sub_led->flash_timeout != led->current_flash_timeout) { in max77693_led_flash_strobe_set()
568 ret = max77693_set_timeout(led, sub_led->flash_timeout); in max77693_led_flash_strobe_set()
573 led->strobing_sub_led_id = fled_id; in max77693_led_flash_strobe_set()
575 ret = max77693_add_mode(led, MODE_FLASH(fled_id)); in max77693_led_flash_strobe_set()
582 mutex_unlock(&led->lock); in max77693_led_flash_strobe_set()
602 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_strobe_get() local
608 mutex_lock(&led->lock); in max77693_led_flash_strobe_get()
610 ret = max77693_get_strobe_status(led, state); in max77693_led_flash_strobe_get()
612 *state = !!(*state && (led->strobing_sub_led_id == sub_led->fled_id)); in max77693_led_flash_strobe_get()
614 mutex_unlock(&led->lock); in max77693_led_flash_strobe_get()
624 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_flash_timeout_set() local
626 mutex_lock(&led->lock); in max77693_led_flash_timeout_set()
628 mutex_unlock(&led->lock); in max77693_led_flash_timeout_set()
633 static int max77693_led_parse_dt(struct max77693_led_device *led, in max77693_led_parse_dt() argument
637 struct device *dev = &led->pdev->dev; in max77693_led_parse_dt()
638 struct max77693_sub_led *sub_leds = led->sub_leds; in max77693_led_parse_dt()
668 led->fled_mask = FLED1_IOUT | FLED2_IOUT; in max77693_led_parse_dt()
671 led->fled_mask |= FLED1_IOUT; in max77693_led_parse_dt()
674 led->fled_mask |= FLED2_IOUT; in max77693_led_parse_dt()
719 (max77693_fled_used(led, FLED1) && in max77693_led_parse_dt()
720 max77693_fled_used(led, FLED2))) { in max77693_led_parse_dt()
741 static void max77693_align_iout_current(struct max77693_led_device *led, in max77693_align_iout_current() argument
746 if (led->iout_joint) { in max77693_align_iout_current()
758 if (max77693_fled_used(led, i)) in max77693_align_iout_current()
764 static void max77693_led_validate_configuration(struct max77693_led_device *led, in max77693_led_validate_configuration() argument
772 max77693_fled_used(led, FLED1) && max77693_fled_used(led, FLED2)) in max77693_led_validate_configuration()
773 led->iout_joint = true; in max77693_led_validate_configuration()
779 if ((cfg->boost_mode == MAX77693_LED_BOOST_NONE) && led->iout_joint) in max77693_led_validate_configuration()
782 max77693_align_iout_current(led, cfg->iout_torch_max, in max77693_led_validate_configuration()
785 max77693_align_iout_current(led, cfg->iout_flash_max, in max77693_led_validate_configuration()
800 static int max77693_led_get_configuration(struct max77693_led_device *led, in max77693_led_get_configuration() argument
806 ret = max77693_led_parse_dt(led, cfg, sub_nodes); in max77693_led_get_configuration()
810 max77693_led_validate_configuration(led, cfg); in max77693_led_get_configuration()
812 memcpy(led->iout_torch_max, cfg->iout_torch_max, in max77693_led_get_configuration()
813 sizeof(led->iout_torch_max)); in max77693_led_get_configuration()
814 memcpy(led->iout_flash_max, cfg->iout_flash_max, in max77693_led_get_configuration()
815 sizeof(led->iout_flash_max)); in max77693_led_get_configuration()
832 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_init_flash_settings() local
839 setting->max = led->iout_joint ? in max77693_init_flash_settings()
862 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_led_external_strobe_set() local
866 mutex_lock(&led->lock); in max77693_led_external_strobe_set()
869 ret = max77693_add_mode(led, MODE_FLASH_EXTERNAL(fled_id)); in max77693_led_external_strobe_set()
871 ret = max77693_clear_mode(led, MODE_FLASH_EXTERNAL(fled_id)); in max77693_led_external_strobe_set()
873 mutex_unlock(&led->lock); in max77693_led_external_strobe_set()
882 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_init_v4l2_flash_config() local
883 struct device *dev = &led->pdev->dev; in max77693_init_v4l2_flash_config()
922 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_init_fled_cdev() local
936 led_cdev->max_brightness = (led->iout_joint ? in max77693_init_fled_cdev()
955 struct max77693_led_device *led = sub_led_to_led(sub_led); in max77693_register_led() local
957 struct device *dev = &led->pdev->dev; in max77693_register_led()
987 struct max77693_led_device *led; in max77693_led_probe() local
993 led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); in max77693_led_probe()
994 if (!led) in max77693_led_probe()
997 led->pdev = pdev; in max77693_led_probe()
998 led->regmap = iodev->regmap; in max77693_led_probe()
999 led->allowed_modes = MODE_FLASH_MASK; in max77693_led_probe()
1000 sub_leds = led->sub_leds; in max77693_led_probe()
1002 platform_set_drvdata(pdev, led); in max77693_led_probe()
1003 ret = max77693_led_get_configuration(led, &led_cfg, sub_nodes); in max77693_led_probe()
1007 ret = max77693_setup(led, &led_cfg); in max77693_led_probe()
1011 mutex_init(&led->lock); in max77693_led_probe()
1014 led->iout_joint || max77693_fled_used(led, FLED1); in max77693_led_probe()
1016 !led->iout_joint && max77693_fled_used(led, FLED2); in max77693_led_probe()
1052 mutex_destroy(&led->lock); in max77693_led_probe()
1059 struct max77693_led_device *led = platform_get_drvdata(pdev); in max77693_led_remove() local
1060 struct max77693_sub_led *sub_leds = led->sub_leds; in max77693_led_remove()
1062 if (led->iout_joint || max77693_fled_used(led, FLED1)) { in max77693_led_remove()
1068 if (!led->iout_joint && max77693_fled_used(led, FLED2)) { in max77693_led_remove()
1074 mutex_destroy(&led->lock); in max77693_led_remove()