Lines Matching full:flash
2 * drivers/media/video/as3645a.c - AS3645A and LM3555 flash controllers driver
107 * @pdata: Flash platform data
110 * @led_mode: V4L2 flash LED mode
111 * @timeout: Flash timeout in microseconds
112 * @flash_current: Flash current (0=200mA ... 15=500mA). Maximum
116 * @strobe_source: Flash strobe source (software or external)
139 static int as3645a_write(struct as3645a *flash, u8 addr, u8 val) in as3645a_write() argument
141 struct i2c_client *client = v4l2_get_subdevdata(&flash->subdev); in as3645a_write()
153 static int as3645a_read(struct as3645a *flash, u8 addr) in as3645a_read() argument
155 struct i2c_client *client = v4l2_get_subdevdata(&flash->subdev); in as3645a_read()
171 * as3645a_set_config - Set flash configuration registers
172 * @flash: The flash
174 * Configure the hardware with flash, assist and indicator currents, as well as
175 * flash timeout.
180 static int as3645a_set_config(struct as3645a *flash) in as3645a_set_config() argument
185 val = (flash->flash_current << AS_CURRENT_FLASH_CURRENT_SHIFT) in as3645a_set_config()
186 | (flash->assist_current << AS_CURRENT_ASSIST_LIGHT_SHIFT) in as3645a_set_config()
189 ret = as3645a_write(flash, AS_CURRENT_SET_REG, val); in as3645a_set_config()
193 val = AS_TIMER_MS_TO_CODE(flash->timeout / 1000) in as3645a_set_config()
196 val |= (flash->pdata->vref << AS_INDICATOR_AND_TIMER_VREF_SHIFT) in as3645a_set_config()
197 | ((flash->indicator_current ? flash->indicator_current - 1 : 0) in as3645a_set_config()
200 return as3645a_write(flash, AS_INDICATOR_AND_TIMER_REG, val); in as3645a_set_config()
204 * as3645a_set_control - Set flash control register
205 * @flash: The flash
215 as3645a_set_control(struct as3645a *flash, enum as_mode mode, bool on) in as3645a_set_control() argument
220 reg = (flash->pdata->peak << AS_CONTROL_COIL_PEAK_SHIFT) in as3645a_set_control()
224 if (flash->led_mode == V4L2_FLASH_LED_MODE_FLASH && in as3645a_set_control()
225 flash->strobe_source == V4L2_FLASH_STROBE_SOURCE_EXTERNAL) { in as3645a_set_control()
230 return as3645a_write(flash, AS_CONTROL_REG, reg); in as3645a_set_control()
235 * @flash: Flash controller
236 * @strobe: Strobe the flash (only valid in flash mode)
241 * The AS3645A can't control the indicator LED independently of the flash/torch
242 * LED. If the flash controller is in V4L2_FLASH_LED_MODE_NONE mode, set the
243 * chip to indicator mode. Otherwise set it to assist light (torch) or flash
247 * and torch currents. In software strobe flash mode, turn the output on/off
250 static int as3645a_set_output(struct as3645a *flash, bool strobe) in as3645a_set_output() argument
255 switch (flash->led_mode) { in as3645a_set_output()
257 on = flash->indicator_current != 0; in as3645a_set_output()
273 return as3645a_set_control(flash, mode, on); in as3645a_set_output()
280 static int as3645a_is_active(struct as3645a *flash) in as3645a_is_active() argument
284 ret = as3645a_read(flash, AS_CONTROL_REG); in as3645a_is_active()
288 static int as3645a_read_fault(struct as3645a *flash) in as3645a_read_fault() argument
290 struct i2c_client *client = v4l2_get_subdevdata(&flash->subdev); in as3645a_read_fault()
294 rval = as3645a_read(flash, AS_FAULT_INFO_REG); in as3645a_read_fault()
326 struct as3645a *flash = in as3645a_get_ctrl() local
328 struct i2c_client *client = v4l2_get_subdevdata(&flash->subdev); in as3645a_get_ctrl()
333 value = as3645a_read_fault(flash); in as3645a_get_ctrl()
353 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) { in as3645a_get_ctrl()
358 value = as3645a_is_active(flash); in as3645a_get_ctrl()
373 struct as3645a *flash = in as3645a_set_ctrl() local
375 struct i2c_client *client = v4l2_get_subdevdata(&flash->subdev); in as3645a_set_ctrl()
388 if (flash->indicator_current) in as3645a_set_ctrl()
391 ret = as3645a_set_config(flash); in as3645a_set_ctrl()
395 flash->led_mode = ctrl->val; in as3645a_set_ctrl()
396 return as3645a_set_output(flash, false); in as3645a_set_ctrl()
399 flash->strobe_source = ctrl->val; in as3645a_set_ctrl()
401 /* Applies to flash mode only. */ in as3645a_set_ctrl()
402 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) in as3645a_set_ctrl()
405 return as3645a_set_output(flash, false); in as3645a_set_ctrl()
408 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) in as3645a_set_ctrl()
411 return as3645a_set_output(flash, true); in as3645a_set_ctrl()
414 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) in as3645a_set_ctrl()
417 return as3645a_set_output(flash, false); in as3645a_set_ctrl()
420 flash->timeout = ctrl->val; in as3645a_set_ctrl()
422 /* Applies to flash mode only. */ in as3645a_set_ctrl()
423 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) in as3645a_set_ctrl()
426 return as3645a_set_config(flash); in as3645a_set_ctrl()
429 flash->flash_current = (ctrl->val - AS3645A_FLASH_INTENSITY_MIN) in as3645a_set_ctrl()
432 /* Applies to flash mode only. */ in as3645a_set_ctrl()
433 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) in as3645a_set_ctrl()
436 return as3645a_set_config(flash); in as3645a_set_ctrl()
439 flash->assist_current = in as3645a_set_ctrl()
444 if (flash->led_mode != V4L2_FLASH_LED_MODE_TORCH) in as3645a_set_ctrl()
447 return as3645a_set_config(flash); in as3645a_set_ctrl()
450 if (flash->led_mode != V4L2_FLASH_LED_MODE_NONE) in as3645a_set_ctrl()
453 flash->indicator_current = in as3645a_set_ctrl()
457 ret = as3645a_set_config(flash); in as3645a_set_ctrl()
464 return as3645a_set_output(flash, false); in as3645a_set_ctrl()
480 static int as3645a_setup(struct as3645a *flash) in as3645a_setup() argument
482 struct i2c_client *client = v4l2_get_subdevdata(&flash->subdev); in as3645a_setup()
486 ret = as3645a_read(flash, AS_FAULT_INFO_REG); in as3645a_setup()
492 ret = as3645a_set_config(flash); in as3645a_setup()
496 ret = as3645a_set_output(flash, false); in as3645a_setup()
501 ret = as3645a_read_fault(flash); in as3645a_setup()
506 as3645a_read(flash, AS_INDICATOR_AND_TIMER_REG)); in as3645a_setup()
508 as3645a_read(flash, AS_CURRENT_SET_REG)); in as3645a_setup()
510 as3645a_read(flash, AS_CONTROL_REG)); in as3645a_setup()
515 static int __as3645a_set_power(struct as3645a *flash, int on) in __as3645a_set_power() argument
520 as3645a_set_control(flash, AS_MODE_EXT_TORCH, false); in __as3645a_set_power()
522 if (flash->pdata->set_power) { in __as3645a_set_power()
523 ret = flash->pdata->set_power(&flash->subdev, on); in __as3645a_set_power()
531 ret = as3645a_setup(flash); in __as3645a_set_power()
533 if (flash->pdata->set_power) in __as3645a_set_power()
534 flash->pdata->set_power(&flash->subdev, 0); in __as3645a_set_power()
542 struct as3645a *flash = to_as3645a(sd); in as3645a_set_power() local
545 mutex_lock(&flash->power_lock); in as3645a_set_power()
547 if (flash->power_count == !on) { in as3645a_set_power()
548 ret = __as3645a_set_power(flash, !!on); in as3645a_set_power()
553 flash->power_count += on ? 1 : -1; in as3645a_set_power()
554 WARN_ON(flash->power_count < 0); in as3645a_set_power()
557 mutex_unlock(&flash->power_lock); in as3645a_set_power()
563 struct as3645a *flash = to_as3645a(sd); in as3645a_registered() local
568 /* Power up the flash driver and read manufacturer ID, model ID, RFU in as3645a_registered()
571 rval = as3645a_set_power(&flash->subdev, 1); in as3645a_registered()
575 rval = as3645a_read(flash, AS_DESIGN_INFO_REG); in as3645a_registered()
582 rval = as3645a_read(flash, AS_VERSION_CONTROL_REG); in as3645a_registered()
620 rval = as3645a_write(flash, AS_PASSWORD_REG, AS_PASSWORD_UNLOCK_VALUE); in as3645a_registered()
624 rval = as3645a_write(flash, AS_BOOST_REG, AS_BOOST_CURRENT_DISABLE); in as3645a_registered()
631 rval = as3645a_setup(flash); in as3645a_registered()
634 as3645a_set_power(&flash->subdev, 0); in as3645a_registered()
672 struct as3645a *flash = to_as3645a(subdev); in as3645a_suspend() local
675 if (flash->power_count == 0) in as3645a_suspend()
678 rval = __as3645a_set_power(flash, 0); in as3645a_suspend()
689 struct as3645a *flash = to_as3645a(subdev); in as3645a_resume() local
692 if (flash->power_count == 0) in as3645a_resume()
695 rval = __as3645a_set_power(flash, 1); in as3645a_resume()
711 * @flash: The flash
716 static int as3645a_init_controls(struct as3645a *flash) in as3645a_init_controls() argument
718 const struct as3645a_platform_data *pdata = flash->pdata; in as3645a_init_controls()
722 v4l2_ctrl_handler_init(&flash->ctrls, 10); in as3645a_init_controls()
725 v4l2_ctrl_new_std_menu(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
730 v4l2_ctrl_new_std_menu(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
736 flash->strobe_source = V4L2_FLASH_STROBE_SOURCE_SOFTWARE; in as3645a_init_controls()
739 v4l2_ctrl_new_std(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
743 v4l2_ctrl_new_std(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
747 ctrl = v4l2_ctrl_new_std(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
755 v4l2_ctrl_new_std(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
759 flash->timeout = maximum; in as3645a_init_controls()
764 v4l2_ctrl_new_std(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
768 flash->flash_current = (maximum - AS3645A_FLASH_INTENSITY_MIN) in as3645a_init_controls()
774 v4l2_ctrl_new_std(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
780 flash->assist_current = 0; in as3645a_init_controls()
783 v4l2_ctrl_new_std(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
790 flash->indicator_current = 0; in as3645a_init_controls()
793 ctrl = v4l2_ctrl_new_std(&flash->ctrls, &as3645a_ctrl_ops, in as3645a_init_controls()
802 flash->subdev.ctrl_handler = &flash->ctrls; in as3645a_init_controls()
804 return flash->ctrls.error; in as3645a_init_controls()
810 struct as3645a *flash; in as3645a_probe() local
816 flash = kzalloc(sizeof(*flash), GFP_KERNEL); in as3645a_probe()
817 if (flash == NULL) in as3645a_probe()
820 flash->pdata = client->dev.platform_data; in as3645a_probe()
822 v4l2_i2c_subdev_init(&flash->subdev, client, &as3645a_ops); in as3645a_probe()
823 flash->subdev.internal_ops = &as3645a_internal_ops; in as3645a_probe()
824 flash->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in as3645a_probe()
826 ret = as3645a_init_controls(flash); in as3645a_probe()
830 ret = media_entity_init(&flash->subdev.entity, 0, NULL, 0); in as3645a_probe()
834 flash->subdev.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH; in as3645a_probe()
836 mutex_init(&flash->power_lock); in as3645a_probe()
838 flash->led_mode = V4L2_FLASH_LED_MODE_NONE; in as3645a_probe()
842 v4l2_ctrl_handler_free(&flash->ctrls); in as3645a_probe()
843 kfree(flash); in as3645a_probe()
852 struct as3645a *flash = to_as3645a(subdev); in as3645a_remove() local
855 v4l2_ctrl_handler_free(&flash->ctrls); in as3645a_remove()
856 media_entity_cleanup(&flash->subdev.entity); in as3645a_remove()
857 mutex_destroy(&flash->power_lock); in as3645a_remove()
858 kfree(flash); in as3645a_remove()
904 MODULE_DESCRIPTION("LED flash driver for AS3645A, LM3555 and their clones");