Lines Matching full:flash
3 * drivers/leds/leds-as3645a.c - AS3645A and LM3555 flash controllers driver
16 #include <linux/led-class-flash.h>
23 #include <media/v4l2-flash-led-class.h>
156 static int as3645a_write(struct as3645a *flash, u8 addr, u8 val) in as3645a_write() argument
158 struct i2c_client *client = flash->client; in as3645a_write()
170 static int as3645a_read(struct as3645a *flash, u8 addr) in as3645a_read() argument
172 struct i2c_client *client = flash->client; in as3645a_read()
188 * as3645a_set_config - Set flash configuration registers
189 * @flash: The flash
191 * Configure the hardware with flash, assist and indicator currents, as well as
192 * flash timeout.
197 static int as3645a_set_current(struct as3645a *flash) in as3645a_set_current() argument
201 val = (flash->flash_current << AS_CURRENT_FLASH_CURRENT_SHIFT) in as3645a_set_current()
202 | (flash->assist_current << AS_CURRENT_ASSIST_LIGHT_SHIFT) in as3645a_set_current()
205 return as3645a_write(flash, AS_CURRENT_SET_REG, val); in as3645a_set_current()
208 static int as3645a_set_timeout(struct as3645a *flash) in as3645a_set_timeout() argument
212 val = flash->timeout << AS_INDICATOR_AND_TIMER_TIMEOUT_SHIFT; in as3645a_set_timeout()
214 val |= (flash->cfg.voltage_reference in as3645a_set_timeout()
216 | ((flash->indicator_current ? flash->indicator_current - 1 : 0) in as3645a_set_timeout()
219 return as3645a_write(flash, AS_INDICATOR_AND_TIMER_REG, val); in as3645a_set_timeout()
223 * as3645a_set_control - Set flash control register
224 * @flash: The flash
234 as3645a_set_control(struct as3645a *flash, enum as_mode mode, bool on) in as3645a_set_control() argument
239 reg = (flash->cfg.peak << AS_CONTROL_COIL_PEAK_SHIFT) in as3645a_set_control()
244 flash->strobe_source == V4L2_FLASH_STROBE_SOURCE_EXTERNAL) in as3645a_set_control()
248 return as3645a_write(flash, AS_CONTROL_REG, reg); in as3645a_set_control()
253 struct as3645a *flash = fled_to_as3645a(fled); in as3645a_get_fault() local
257 rval = as3645a_read(flash, AS_FAULT_INFO_REG); in as3645a_get_fault()
267 dev_dbg(&flash->client->dev, "%u connected LEDs\n", in as3645a_get_fault()
298 static unsigned int as3645a_current_to_reg(struct as3645a *flash, bool is_flash, in as3645a_current_to_reg() argument
303 flash->cfg.assist_max_ua, in as3645a_current_to_reg()
307 flash->cfg.flash_max_ua, in as3645a_current_to_reg()
314 struct as3645a *flash = iled_cdev_to_as3645a(iled_cdev); in as3645a_set_indicator_brightness() local
317 flash->indicator_current = brightness; in as3645a_set_indicator_brightness()
319 rval = as3645a_set_timeout(flash); in as3645a_set_indicator_brightness()
323 return as3645a_set_control(flash, AS_MODE_INDICATOR, brightness); in as3645a_set_indicator_brightness()
330 struct as3645a *flash = fled_to_as3645a(fled); in as3645a_set_assist_brightness() local
335 flash->assist_current = brightness - 1; in as3645a_set_assist_brightness()
337 rval = as3645a_set_current(flash); in as3645a_set_assist_brightness()
342 return as3645a_set_control(flash, AS_MODE_ASSIST, brightness); in as3645a_set_assist_brightness()
348 struct as3645a *flash = fled_to_as3645a(fled); in as3645a_set_flash_brightness() local
350 flash->flash_current = as3645a_current_to_reg(flash, true, in as3645a_set_flash_brightness()
353 return as3645a_set_current(flash); in as3645a_set_flash_brightness()
359 struct as3645a *flash = fled_to_as3645a(fled); in as3645a_set_flash_timeout() local
361 flash->timeout = AS_TIMER_US_TO_CODE(timeout_us); in as3645a_set_flash_timeout()
363 return as3645a_set_timeout(flash); in as3645a_set_flash_timeout()
368 struct as3645a *flash = fled_to_as3645a(fled); in as3645a_set_strobe() local
370 return as3645a_set_control(flash, AS_MODE_FLASH, state); in as3645a_set_strobe()
380 static int as3645a_setup(struct as3645a *flash) in as3645a_setup() argument
382 struct device *dev = &flash->client->dev; in as3645a_setup()
387 rval = as3645a_read(flash, AS_FAULT_INFO_REG); in as3645a_setup()
393 rval = as3645a_set_current(flash); in as3645a_setup()
397 rval = as3645a_set_timeout(flash); in as3645a_setup()
401 rval = as3645a_set_control(flash, AS_MODE_INDICATOR, false); in as3645a_setup()
406 rval = as3645a_get_fault(&flash->fled, &fault); in as3645a_setup()
411 as3645a_read(flash, AS_INDICATOR_AND_TIMER_REG)); in as3645a_setup()
413 as3645a_read(flash, AS_CURRENT_SET_REG)); in as3645a_setup()
415 as3645a_read(flash, AS_CONTROL_REG)); in as3645a_setup()
420 static int as3645a_detect(struct as3645a *flash) in as3645a_detect() argument
422 struct device *dev = &flash->client->dev; in as3645a_detect()
426 rval = as3645a_read(flash, AS_DESIGN_INFO_REG); in as3645a_detect()
435 rval = as3645a_read(flash, AS_VERSION_CONTROL_REG); in as3645a_detect()
474 rval = as3645a_write(flash, AS_PASSWORD_REG, AS_PASSWORD_UNLOCK_VALUE); in as3645a_detect()
478 return as3645a_write(flash, AS_BOOST_REG, AS_BOOST_CURRENT_DISABLE); in as3645a_detect()
481 static int as3645a_parse_node(struct as3645a *flash, in as3645a_parse_node() argument
484 struct as3645a_config *cfg = &flash->cfg; in as3645a_parse_node()
495 flash->flash_node = child; in as3645a_parse_node()
499 flash->indicator_node = child; in as3645a_parse_node()
503 dev_warn(&flash->client->dev, in as3645a_parse_node()
509 if (!flash->flash_node) { in as3645a_parse_node()
510 dev_err(&flash->client->dev, "can't find flash node\n"); in as3645a_parse_node()
514 rval = fwnode_property_read_u32(flash->flash_node, "flash-timeout-us", in as3645a_parse_node()
517 dev_err(&flash->client->dev, in as3645a_parse_node()
518 "can't read flash-timeout-us property for flash\n"); in as3645a_parse_node()
522 rval = fwnode_property_read_u32(flash->flash_node, "flash-max-microamp", in as3645a_parse_node()
525 dev_err(&flash->client->dev, in as3645a_parse_node()
526 "can't read flash-max-microamp property for flash\n"); in as3645a_parse_node()
530 rval = fwnode_property_read_u32(flash->flash_node, "led-max-microamp", in as3645a_parse_node()
533 dev_err(&flash->client->dev, in as3645a_parse_node()
534 "can't read led-max-microamp property for flash\n"); in as3645a_parse_node()
538 fwnode_property_read_u32(flash->flash_node, "voltage-reference", in as3645a_parse_node()
541 fwnode_property_read_u32(flash->flash_node, "ams,input-max-microamp", in as3645a_parse_node()
545 if (!flash->indicator_node) { in as3645a_parse_node()
546 dev_warn(&flash->client->dev, in as3645a_parse_node()
552 rval = fwnode_property_read_u32(flash->indicator_node, in as3645a_parse_node()
556 dev_err(&flash->client->dev, in as3645a_parse_node()
564 fwnode_handle_put(flash->flash_node); in as3645a_parse_node()
565 fwnode_handle_put(flash->indicator_node); in as3645a_parse_node()
570 static int as3645a_led_class_setup(struct as3645a *flash) in as3645a_led_class_setup() argument
572 struct led_classdev *fled_cdev = &flash->fled.led_cdev; in as3645a_led_class_setup()
573 struct led_classdev *iled_cdev = &flash->iled_cdev; in as3645a_led_class_setup()
580 flash->cfg.indicator_max_ua / AS_INDICATOR_INTENSITY_STEP; in as3645a_led_class_setup()
583 init_data.fwnode = flash->indicator_node; in as3645a_led_class_setup()
587 rval = led_classdev_register_ext(&flash->client->dev, iled_cdev, in as3645a_led_class_setup()
592 cfg = &flash->fled.brightness; in as3645a_led_class_setup()
594 cfg->max = flash->cfg.flash_max_ua; in as3645a_led_class_setup()
596 cfg->val = flash->cfg.flash_max_ua; in as3645a_led_class_setup()
598 cfg = &flash->fled.timeout; in as3645a_led_class_setup()
600 cfg->max = flash->cfg.flash_timeout_us; in as3645a_led_class_setup()
602 cfg->val = flash->cfg.flash_timeout_us; in as3645a_led_class_setup()
604 flash->fled.ops = &as3645a_led_flash_ops; in as3645a_led_class_setup()
609 as3645a_current_to_reg(flash, false, in as3645a_led_class_setup()
610 flash->cfg.assist_max_ua) + 1; in as3645a_led_class_setup()
613 init_data.fwnode = flash->flash_node; in as3645a_led_class_setup()
615 init_data.default_label = "flash"; in as3645a_led_class_setup()
617 rval = led_classdev_flash_register_ext(&flash->client->dev, in as3645a_led_class_setup()
618 &flash->fled, &init_data); in as3645a_led_class_setup()
626 dev_err(&flash->client->dev, in as3645a_led_class_setup()
632 static int as3645a_v4l2_setup(struct as3645a *flash) in as3645a_v4l2_setup() argument
634 struct led_classdev_flash *fled = &flash->fled; in as3645a_v4l2_setup()
639 .max = flash->cfg.assist_max_ua, in as3645a_v4l2_setup()
641 .val = flash->cfg.assist_max_ua, in as3645a_v4l2_setup()
647 .max = flash->cfg.indicator_max_ua, in as3645a_v4l2_setup()
649 .val = flash->cfg.indicator_max_ua, in as3645a_v4l2_setup()
654 strlcpy(cfgind.dev_name, flash->iled_cdev.dev->kobj.name, in as3645a_v4l2_setup()
657 flash->vf = v4l2_flash_init( in as3645a_v4l2_setup()
658 &flash->client->dev, flash->flash_node, &flash->fled, NULL, in as3645a_v4l2_setup()
660 if (IS_ERR(flash->vf)) in as3645a_v4l2_setup()
661 return PTR_ERR(flash->vf); in as3645a_v4l2_setup()
663 flash->vfind = v4l2_flash_indicator_init( in as3645a_v4l2_setup()
664 &flash->client->dev, flash->indicator_node, &flash->iled_cdev, in as3645a_v4l2_setup()
666 if (IS_ERR(flash->vfind)) { in as3645a_v4l2_setup()
667 v4l2_flash_release(flash->vf); in as3645a_v4l2_setup()
668 return PTR_ERR(flash->vfind); in as3645a_v4l2_setup()
676 struct as3645a *flash; in as3645a_probe() local
682 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); in as3645a_probe()
683 if (flash == NULL) in as3645a_probe()
686 flash->client = client; in as3645a_probe()
688 rval = as3645a_parse_node(flash, dev_fwnode(&client->dev)); in as3645a_probe()
692 rval = as3645a_detect(flash); in as3645a_probe()
696 mutex_init(&flash->mutex); in as3645a_probe()
697 i2c_set_clientdata(client, flash); in as3645a_probe()
699 rval = as3645a_setup(flash); in as3645a_probe()
703 rval = as3645a_led_class_setup(flash); in as3645a_probe()
707 rval = as3645a_v4l2_setup(flash); in as3645a_probe()
714 led_classdev_flash_unregister(&flash->fled); in as3645a_probe()
717 mutex_destroy(&flash->mutex); in as3645a_probe()
720 fwnode_handle_put(flash->flash_node); in as3645a_probe()
721 fwnode_handle_put(flash->indicator_node); in as3645a_probe()
728 struct as3645a *flash = i2c_get_clientdata(client); in as3645a_remove() local
730 as3645a_set_control(flash, AS_MODE_EXT_TORCH, false); in as3645a_remove()
732 v4l2_flash_release(flash->vf); in as3645a_remove()
733 v4l2_flash_release(flash->vfind); in as3645a_remove()
735 led_classdev_flash_unregister(&flash->fled); in as3645a_remove()
736 led_classdev_unregister(&flash->iled_cdev); in as3645a_remove()
738 mutex_destroy(&flash->mutex); in as3645a_remove()
740 fwnode_handle_put(flash->flash_node); in as3645a_remove()
741 fwnode_handle_put(flash->indicator_node); in as3645a_remove()
772 MODULE_DESCRIPTION("LED flash driver for AS3645A, LM3555 and their clones");