Lines Matching full:flash

14 #include <linux/rk-led-flash.h>
93 static int sgm3784_i2c_write(struct sgm3784_flash *flash, u8 reg, u8 val) in sgm3784_i2c_write() argument
95 struct i2c_client *client = flash->client; in sgm3784_i2c_write()
104 v4l2_dbg(2, debug, &flash->leds[0].sd, in sgm3784_i2c_write()
111 static int sgm3784_i2c_read(struct sgm3784_flash *flash, u8 reg) in sgm3784_i2c_read() argument
113 struct i2c_client *client = flash->client; in sgm3784_i2c_read()
122 v4l2_dbg(2, debug, &flash->leds[0].sd, in sgm3784_i2c_read()
128 static int sgm3784_led_on(struct sgm3784_flash *flash, bool on) in sgm3784_led_on() argument
133 v4l2_dbg(1, debug, &flash->leds[0].sd, in sgm3784_led_on()
137 ret = sgm3784_i2c_write(flash, SGM3784_REG_ENABLE, val); in sgm3784_led_on()
138 flash->leds[0].timestamp = ns_to_kernel_old_timeval(ktime_get_ns()); in sgm3784_led_on()
139 flash->leds[1].timestamp = flash->leds[0].timestamp; in sgm3784_led_on()
143 static int sgm3784_get_fault(struct sgm3784_flash *flash) in sgm3784_get_fault() argument
147 fault = sgm3784_i2c_read(flash, SGM3784_REG_FAULT); in sgm3784_get_fault()
154 v4l2_info(&flash->leds[0].sd, in sgm3784_get_fault()
159 static int sgm3784_set_timeout(struct sgm3784_flash *flash) in sgm3784_set_timeout() argument
164 v4l2_dbg(1, debug, &flash->leds[0].sd, in sgm3784_set_timeout()
166 __func__, flash->flash_timeout); in sgm3784_set_timeout()
168 ret = sgm3784_i2c_read(flash, 0x02); in sgm3784_set_timeout()
172 val = (flash->flash_timeout - TIMEOUT_MIN) / TIMEOUT_STEP; in sgm3784_set_timeout()
173 return sgm3784_i2c_write(flash, 0x02, val | (ret & 0xf0)); in sgm3784_set_timeout()
176 static int sgm3784_torch_brt(struct sgm3784_flash *flash, in sgm3784_torch_brt() argument
179 struct sgm3784_led *led = &flash->leds[id]; in sgm3784_torch_brt()
187 return sgm3784_i2c_write(flash, reg, val); in sgm3784_torch_brt()
190 static int sgm3784_flash_brt(struct sgm3784_flash *flash, in sgm3784_flash_brt() argument
193 struct sgm3784_led *led = &flash->leds[id]; in sgm3784_flash_brt()
201 return sgm3784_i2c_write(flash, reg, val); in sgm3784_flash_brt()
204 static int sgm3784_set_mode(struct sgm3784_flash *flash, in sgm3784_set_mode() argument
210 v4l2_dbg(1, debug, &flash->leds[id].sd, in sgm3784_set_mode()
212 mode, flash->cur_mode); in sgm3784_set_mode()
214 if (flash->cur_mode == mode) in sgm3784_set_mode()
217 sgm3784_led_on(flash, false); in sgm3784_set_mode()
219 flash->cur_mode = mode; in sgm3784_set_mode()
221 val = (flash->flash_timeout - TIMEOUT_MIN) / TIMEOUT_STEP; in sgm3784_set_mode()
223 if (flash->torch_gpio) in sgm3784_set_mode()
224 gpiod_direction_output(flash->torch_gpio, 0); in sgm3784_set_mode()
225 ret = sgm3784_i2c_write(flash, 0x01, 0xfb); in sgm3784_set_mode()
226 ret |= sgm3784_i2c_write(flash, 0x02, val | 0xc0); in sgm3784_set_mode()
227 ret |= sgm3784_i2c_write(flash, 0x03, 0x48); in sgm3784_set_mode()
228 ret |= sgm3784_flash_brt(flash, LED0); in sgm3784_set_mode()
229 ret |= sgm3784_flash_brt(flash, LED1); in sgm3784_set_mode()
230 gpiod_direction_output(flash->strobe_gpio, 1); in sgm3784_set_mode()
232 gpiod_direction_output(flash->strobe_gpio, 0); in sgm3784_set_mode()
233 if (flash->torch_gpio) { in sgm3784_set_mode()
235 ret = sgm3784_i2c_write(flash, 0x01, 0xf8); in sgm3784_set_mode()
236 ret |= sgm3784_i2c_write(flash, 0x02, val | 0xf0); in sgm3784_set_mode()
239 ret = sgm3784_i2c_write(flash, 0x01, 0xfa); in sgm3784_set_mode()
240 ret |= sgm3784_i2c_write(flash, 0x02, val | 0xc0); in sgm3784_set_mode()
242 ret |= sgm3784_i2c_write(flash, 0x03, 0x48); in sgm3784_set_mode()
243 ret |= sgm3784_torch_brt(flash, LED0); in sgm3784_set_mode()
244 ret |= sgm3784_torch_brt(flash, LED1); in sgm3784_set_mode()
245 ret |= sgm3784_led_on(flash, true); in sgm3784_set_mode()
246 if (flash->torch_gpio) in sgm3784_set_mode()
247 gpiod_direction_output(flash->torch_gpio, 1); in sgm3784_set_mode()
249 ret = sgm3784_i2c_write(flash, 0x01, 0xf8); in sgm3784_set_mode()
250 gpiod_direction_output(flash->strobe_gpio, 0); in sgm3784_set_mode()
251 if (flash->torch_gpio) in sgm3784_set_mode()
252 gpiod_direction_output(flash->torch_gpio, 0); in sgm3784_set_mode()
258 static int sgm3784_strobe(struct sgm3784_flash *flash, bool on) in sgm3784_strobe() argument
260 v4l2_dbg(1, debug, &flash->leds[0].sd, in sgm3784_strobe()
263 if (flash->cur_mode != V4L2_FLASH_LED_MODE_FLASH) in sgm3784_strobe()
266 return sgm3784_led_on(flash, on); in sgm3784_strobe()
273 struct sgm3784_flash *flash = in sgm3784_get_ctrl() local
280 mutex_lock(&flash->lock); in sgm3784_get_ctrl()
283 ret = sgm3784_get_fault(flash); in sgm3784_get_ctrl()
302 mutex_unlock(&flash->lock); in sgm3784_get_ctrl()
310 struct sgm3784_flash *flash = in sgm3784_set_ctrl() local
318 mutex_lock(&flash->lock); in sgm3784_set_ctrl()
320 ret = sgm3784_get_fault(flash); in sgm3784_set_ctrl()
335 ret = sgm3784_set_mode(flash, id, ctrl->val); in sgm3784_set_ctrl()
338 ret = sgm3784_strobe(flash, true); in sgm3784_set_ctrl()
341 ret = sgm3784_strobe(flash, false); in sgm3784_set_ctrl()
344 ret = sgm3784_set_timeout(flash); in sgm3784_set_ctrl()
347 ret = sgm3784_flash_brt(flash, id); in sgm3784_set_ctrl()
350 ret = sgm3784_torch_brt(flash, id); in sgm3784_set_ctrl()
360 mutex_unlock(&flash->lock); in sgm3784_set_ctrl()
395 static int sgm3784_init_controls(struct sgm3784_flash *flash, in sgm3784_init_controls() argument
399 struct v4l2_ctrl_handler *hdl = &flash->leds[id].ctrls; in sgm3784_init_controls()
401 struct sgm3784_led *led = &flash->leds[id]; in sgm3784_init_controls()
408 flash->cur_mode = V4L2_FLASH_LED_MODE_NONE; in sgm3784_init_controls()
425 flash->flash_timeout = led->max_flash_timeout; in sgm3784_init_controls()
427 flash->leds[id].flash_brt = in sgm3784_init_controls()
435 flash->leds[id].torch_brt = in sgm3784_init_controls()
455 flash->leds[id].sd.ctrl_handler = hdl; in sgm3784_init_controls()
569 static int __sgm3784_set_power(struct sgm3784_flash *flash, bool on) in __sgm3784_set_power() argument
571 gpiod_direction_output(flash->en_gpio, on); in __sgm3784_set_power()
576 static int sgm3784_check_id(struct sgm3784_flash *flash) in sgm3784_check_id() argument
580 __sgm3784_set_power(flash, true); in sgm3784_check_id()
581 ret = sgm3784_i2c_read(flash, SGM3784_REG_ID); in sgm3784_check_id()
582 __sgm3784_set_power(flash, false); in sgm3784_check_id()
584 dev_err(&flash->client->dev, in sgm3784_check_id()
589 dev_info(&flash->client->dev, in sgm3784_check_id()
590 "Detected sgm3784 flash id:0x%x\n", ret); in sgm3784_check_id()
595 struct sgm3784_flash *flash) in sgm3784_of_init() argument
610 &flash->module_index); in sgm3784_of_init()
613 &flash->module_facing); in sgm3784_of_init()
620 flash->en_gpio = devm_gpiod_get(&client->dev, in sgm3784_of_init()
622 if (IS_ERR(flash->en_gpio)) { in sgm3784_of_init()
627 flash->torch_gpio = devm_gpiod_get(&client->dev, in sgm3784_of_init()
629 if (IS_ERR(flash->torch_gpio)) { in sgm3784_of_init()
630 flash->torch_gpio = NULL; in sgm3784_of_init()
635 flash->strobe_gpio = devm_gpiod_get(&client->dev, in sgm3784_of_init()
637 if (IS_ERR(flash->en_gpio)) { in sgm3784_of_init()
650 led = &flash->leds[id]; in sgm3784_of_init()
652 if (of_property_read_u32(child, "flash-max-timeout-us", in sgm3784_of_init()
655 "get led%d flash-max-timeout-us fail\n", id); in sgm3784_of_init()
661 if (of_property_read_u32(child, "flash-max-microamp", in sgm3784_of_init()
664 "get led%d flash-max-microamp fail\n", id); in sgm3784_of_init()
680 "led%d max torch:%dUA flash:%dUA timeout:%dUS\n", in sgm3784_of_init()
694 struct sgm3784_flash *flash; in sgm3784_probe() local
704 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); in sgm3784_probe()
705 if (!flash) in sgm3784_probe()
708 flash->client = client; in sgm3784_probe()
710 ret = sgm3784_of_init(client, flash); in sgm3784_probe()
714 ret = sgm3784_check_id(flash); in sgm3784_probe()
719 sd = &flash->leds[i].sd; in sgm3784_probe()
725 if (strcmp(flash->module_facing, "back") == 0) in sgm3784_probe()
735 flash->module_index, facing, in sgm3784_probe()
738 ret = sgm3784_init_controls(flash, i); in sgm3784_probe()
752 i2c_set_clientdata(client, flash); in sgm3784_probe()
754 mutex_init(&flash->lock); in sgm3784_probe()
764 media_entity_cleanup(&flash->leds[i].sd.entity); in sgm3784_probe()
766 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in sgm3784_probe()
769 v4l2_device_unregister_subdev(&flash->leds[i].sd); in sgm3784_probe()
770 media_entity_cleanup(&flash->leds[i].sd.entity); in sgm3784_probe()
771 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in sgm3784_probe()
778 struct sgm3784_flash *flash = i2c_get_clientdata(client); in sgm3784_remove() local
783 v4l2_device_unregister_subdev(&flash->leds[i].sd); in sgm3784_remove()
784 v4l2_ctrl_handler_free(&flash->leds[i].ctrls); in sgm3784_remove()
785 media_entity_cleanup(&flash->leds[i].sd.entity); in sgm3784_remove()
787 mutex_destroy(&flash->lock); in sgm3784_remove()
794 struct sgm3784_flash *flash = i2c_get_clientdata(client); in sgm3784_runtime_suspend() local
796 return __sgm3784_set_power(flash, false); in sgm3784_runtime_suspend()
802 struct sgm3784_flash *flash = i2c_get_clientdata(client); in sgm3784_runtime_resume() local
804 return __sgm3784_set_power(flash, true); in sgm3784_runtime_resume()
836 MODULE_DESCRIPTION("SGM3784 LED flash driver");