Lines Matching full:flash
3 * General device driver for awinic aw36518, FLASH LED Driver
19 #include <linux/rk-led-flash.h>
52 /* FLASH Brightness
79 /* FLASH TIMEOUT DURATION
136 static int aw36518_i2c_write(struct aw36518_flash *flash, u8 reg, u8 val) in aw36518_i2c_write() argument
138 struct i2c_client *client = flash->client; in aw36518_i2c_write()
147 v4l2_dbg(2, debug, &flash->leds[0].sd, in aw36518_i2c_write()
154 static int aw36518_i2c_read(struct aw36518_flash *flash, u8 reg) in aw36518_i2c_read() argument
156 struct i2c_client *client = flash->client; in aw36518_i2c_read()
170 static int aw36518_led_on(struct aw36518_flash *flash, bool on) in aw36518_led_on() argument
173 struct i2c_client *client = flash->client; in aw36518_led_on()
177 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_led_on()
180 temp = aw36518_i2c_read(flash, AW36518_REG_ENABLE); in aw36518_led_on()
186 if (flash->led_mode == V4L2_FLASH_LED_MODE_FLASH && on) in aw36518_led_on()
191 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_led_on()
194 ret = aw36518_i2c_write(flash, AW36518_REG_ENABLE, val | temp); in aw36518_led_on()
195 flash->leds[0].timestamp = ns_to_kernel_old_timeval(ktime_get_ns()); in aw36518_led_on()
196 flash->leds[1].timestamp = flash->leds[0].timestamp; in aw36518_led_on()
200 static int aw36518_get_fault(struct aw36518_flash *flash) in aw36518_get_fault() argument
205 fault = aw36518_i2c_read(flash, AW36518_REG_FAULT); in aw36518_get_fault()
207 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_get_fault()
211 temp = aw36518_i2c_read(flash, AW36518_REG_FAULT2); in aw36518_get_fault()
217 static int aw36518_timeout_cal(struct aw36518_flash *flash) in aw36518_timeout_cal() argument
221 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_timeout_cal()
222 "%s: timeout:%dUS\n", __func__, flash->flash_timeout); in aw36518_timeout_cal()
224 if (flash->flash_timeout < 400000) in aw36518_timeout_cal()
225 val = AW36518_FLASH_TOUT_ms_TO_REG(flash->flash_timeout); in aw36518_timeout_cal()
227 val = (flash->flash_timeout - 0x400000) / TIMEOUT_STEP2; in aw36518_timeout_cal()
234 static int aw36518_set_timeout(struct aw36518_flash *flash, u32 timeout) in aw36518_set_timeout() argument
239 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_set_timeout()
241 __func__, flash->flash_timeout); in aw36518_set_timeout()
243 flash->flash_timeout = timeout; in aw36518_set_timeout()
244 ret = aw36518_i2c_read(flash, 0x08); in aw36518_set_timeout()
248 val = aw36518_timeout_cal(flash); in aw36518_set_timeout()
250 return aw36518_i2c_write(flash, 0x08, val | (ret & 0xf0)); in aw36518_set_timeout()
253 static int aw36518_torch_brt(struct aw36518_flash *flash, in aw36518_torch_brt() argument
256 struct aw36518_led *led = &flash->leds[id]; in aw36518_torch_brt()
264 return aw36518_i2c_write(flash, reg, val); in aw36518_torch_brt()
267 static int aw36518_flash_brt(struct aw36518_flash *flash, in aw36518_flash_brt() argument
270 struct aw36518_led *led = &flash->leds[id]; in aw36518_flash_brt()
278 return aw36518_i2c_write(flash, reg, val); in aw36518_flash_brt()
281 static int aw36518_set_mode(struct aw36518_flash *flash, in aw36518_set_mode() argument
286 v4l2_dbg(1, debug, &flash->leds[id].sd, in aw36518_set_mode()
288 mode, flash->led_mode); in aw36518_set_mode()
290 if (flash->led_mode == mode) in aw36518_set_mode()
293 aw36518_led_on(flash, false); in aw36518_set_mode()
295 flash->led_mode = mode; in aw36518_set_mode()
298 ret = aw36518_i2c_write(flash, 0x01, 0x0C); in aw36518_set_mode()
299 ret |= aw36518_flash_brt(flash, LED0); in aw36518_set_mode()
301 //ret = aw36518_i2c_write(flash, 0x01, 0x08); in aw36518_set_mode()
303 ret = aw36518_i2c_write(flash, 0x01, AW36518_HW_TORCH); in aw36518_set_mode()
304 ret |= aw36518_torch_brt(flash, LED0); in aw36518_set_mode()
305 ret |= aw36518_led_on(flash, true); in aw36518_set_mode()
306 if (flash->torch_gpio) { in aw36518_set_mode()
307 v4l2_dbg(1, debug, &flash->leds[id].sd, in aw36518_set_mode()
309 gpiod_set_value_cansleep(flash->torch_gpio, 1); in aw36518_set_mode()
313 ret = aw36518_i2c_write(flash, 0x01, 0x00); in aw36518_set_mode()
314 if (flash->torch_gpio) { in aw36518_set_mode()
315 v4l2_dbg(1, debug, &flash->leds[id].sd, in aw36518_set_mode()
317 gpiod_set_value_cansleep(flash->torch_gpio, 0); in aw36518_set_mode()
325 static int aw36518_strobe(struct aw36518_flash *flash, bool on) in aw36518_strobe() argument
329 v4l2_dbg(1, debug, &flash->leds[0].sd, in aw36518_strobe()
332 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) in aw36518_strobe()
334 ret = aw36518_led_on(flash, on); in aw36518_strobe()
343 struct aw36518_flash *flash = in aw36518_get_ctrl() local
346 struct i2c_client *client = flash->client; in aw36518_get_ctrl()
348 v4l2_dbg(1, debug, &flash->leds[id].sd, in aw36518_get_ctrl()
351 mutex_lock(&flash->lock); in aw36518_get_ctrl()
354 ret = aw36518_get_fault(flash); in aw36518_get_ctrl()
373 mutex_unlock(&flash->lock); in aw36518_get_ctrl()
381 struct aw36518_flash *flash = in aw36518_set_ctrl() local
384 struct i2c_client *client = flash->client; in aw36518_set_ctrl()
390 mutex_lock(&flash->lock); in aw36518_set_ctrl()
392 ret = aw36518_get_fault(flash); in aw36518_set_ctrl()
405 ret = aw36518_set_mode(flash, id, ctrl->val); in aw36518_set_ctrl()
408 ret = aw36518_strobe(flash, true); in aw36518_set_ctrl()
411 ret = aw36518_strobe(flash, false); in aw36518_set_ctrl()
414 ret = aw36518_set_timeout(flash, ctrl->val); in aw36518_set_ctrl()
417 ret = aw36518_flash_brt(flash, id); in aw36518_set_ctrl()
420 ret = aw36518_torch_brt(flash, id); in aw36518_set_ctrl()
430 mutex_unlock(&flash->lock); in aw36518_set_ctrl()
465 static int aw36518_init_controls(struct aw36518_flash *flash, in aw36518_init_controls() argument
469 struct v4l2_ctrl_handler *hdl = &flash->leds[id].ctrls; in aw36518_init_controls()
471 struct aw36518_led *led = &flash->leds[id]; in aw36518_init_controls()
478 flash->led_mode = V4L2_FLASH_LED_MODE_NONE; in aw36518_init_controls()
495 flash->flash_timeout = led->max_flash_timeout; in aw36518_init_controls()
497 flash->leds[id].flash_brt = in aw36518_init_controls()
505 flash->leds[id].torch_brt = in aw36518_init_controls()
525 flash->leds[id].sd.ctrl_handler = hdl; in aw36518_init_controls()
622 struct aw36518_flash *flash = in aw36518_s_power() local
625 struct i2c_client *client = flash->client; in aw36518_s_power()
628 mutex_lock(&flash->lock); in aw36518_s_power()
631 if (flash->power_on == !!on) in aw36518_s_power()
640 flash->power_on = true; in aw36518_s_power()
643 flash->power_on = false; in aw36518_s_power()
647 mutex_unlock(&flash->lock); in aw36518_s_power()
669 static int __aw36518_set_power(struct aw36518_flash *flash, bool on) in __aw36518_set_power() argument
671 gpiod_direction_output(flash->en_gpio, on); in __aw36518_set_power()
676 static int aw36518_check_id(struct aw36518_flash *flash) in aw36518_check_id() argument
680 __aw36518_set_power(flash, true); in aw36518_check_id()
681 ret = aw36518_i2c_read(flash, AW36518_REG_ID); in aw36518_check_id()
683 dev_err(&flash->client->dev, in aw36518_check_id()
688 dev_info(&flash->client->dev, in aw36518_check_id()
689 "Detected aw36518 flash id:0x%x\n", ret); in aw36518_check_id()
694 struct aw36518_flash *flash) in aw36518_of_init() argument
709 &flash->module_index); in aw36518_of_init()
712 &flash->module_facing); in aw36518_of_init()
719 flash->en_gpio = devm_gpiod_get(&client->dev, in aw36518_of_init()
721 if (IS_ERR(flash->en_gpio)) { in aw36518_of_init()
722 flash->en_gpio = NULL; in aw36518_of_init()
727 flash->torch_gpio = devm_gpiod_get(&client->dev, in aw36518_of_init()
729 if (IS_ERR(flash->torch_gpio)) { in aw36518_of_init()
730 flash->torch_gpio = NULL; in aw36518_of_init()
735 flash->strobe_gpio = devm_gpiod_get(&client->dev, in aw36518_of_init()
737 if (IS_ERR(flash->strobe_gpio)) { in aw36518_of_init()
738 flash->strobe_gpio = NULL; in aw36518_of_init()
743 flash->tx_gpio = devm_gpiod_get(&client->dev, in aw36518_of_init()
745 if (IS_ERR(flash->tx_gpio)) { in aw36518_of_init()
746 flash->tx_gpio = NULL; in aw36518_of_init()
759 led = &flash->leds[id]; in aw36518_of_init()
761 if (of_property_read_u32(child, "flash-max-timeout-us", in aw36518_of_init()
764 "get led%d flash-max-timeout-us fail\n", id); in aw36518_of_init()
770 if (of_property_read_u32(child, "flash-max-microamp", in aw36518_of_init()
773 "get led%d flash-max-microamp fail\n", id); in aw36518_of_init()
789 "led%d max torch:%dUA flash:%dUA timeout:%dUS\n", in aw36518_of_init()
800 static int aw36518_init_device(struct aw36518_flash *flash) in aw36518_init_device() argument
804 struct i2c_client *client = flash->client; in aw36518_init_device()
807 flash->led_mode = V4L2_FLASH_LED_MODE_NONE; in aw36518_init_device()
808 ret = aw36518_set_mode(flash, 0, 0); in aw36518_init_device()
812 reg_val = aw36518_i2c_read(flash, AW36518_REG_FAULT); in aw36518_init_device()
815 if (flash->tx_gpio) in aw36518_init_device()
816 gpiod_direction_output(flash->tx_gpio, 0); in aw36518_init_device()
818 if (flash->torch_gpio) in aw36518_init_device()
819 gpiod_set_value_cansleep(flash->torch_gpio, 0); in aw36518_init_device()
827 struct aw36518_flash *flash; in aw36518_probe() local
837 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); in aw36518_probe()
838 if (!flash) in aw36518_probe()
841 flash->client = client; in aw36518_probe()
843 ret = aw36518_of_init(client, flash); in aw36518_probe()
847 ret = aw36518_check_id(flash); in aw36518_probe()
852 sd = &flash->leds[i].sd; in aw36518_probe()
858 if (strcmp(flash->module_facing, "back") == 0) in aw36518_probe()
868 flash->module_index, facing, in aw36518_probe()
871 ret = aw36518_init_controls(flash, i); in aw36518_probe()
885 ret = aw36518_init_device(flash); in aw36518_probe()
889 i2c_set_clientdata(client, flash); in aw36518_probe()
891 mutex_init(&flash->lock); in aw36518_probe()
901 media_entity_cleanup(&flash->leds[i].sd.entity); in aw36518_probe()
903 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in aw36518_probe()
906 v4l2_device_unregister_subdev(&flash->leds[i].sd); in aw36518_probe()
907 media_entity_cleanup(&flash->leds[i].sd.entity); in aw36518_probe()
908 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in aw36518_probe()
911 __aw36518_set_power(flash, false); in aw36518_probe()
917 struct aw36518_flash *flash = i2c_get_clientdata(client); in aw36518_remove() local
922 v4l2_device_unregister_subdev(&flash->leds[i].sd); in aw36518_remove()
923 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in aw36518_remove()
924 media_entity_cleanup(&flash->leds[i].sd.entity); in aw36518_remove()
926 mutex_destroy(&flash->lock); in aw36518_remove()
933 struct aw36518_flash *flash = i2c_get_clientdata(client); in aw36518_runtime_suspend() local
935 return __aw36518_set_power(flash, false); in aw36518_runtime_suspend()
941 struct aw36518_flash *flash = i2c_get_clientdata(client); in aw36518_runtime_resume() local
943 return __aw36518_set_power(flash, true); in aw36518_runtime_resume()
975 MODULE_DESCRIPTION("AW36518 LED flash driver");