2 * drivers/media/i2c/as3645a.c - AS3645A and LM3555 flash controllers driver
4 * Copyright (C) 2008-2011 Nokia Corporation
5 * Copyright (c) 2011, Intel Corporation.
7 * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 * - Check hardware FSTROBE control when sensor driver add support for this
23 #include <linux/delay.h>
24 #include <linux/i2c.h>
25 #include <linux/module.h>
26 #include <linux/mutex.h>
27 #include <linux/slab.h>
29 #include <media/i2c/as3645a.h>
30 #include <media/v4l2-ctrls.h>
31 #include <media/v4l2-device.h>
33 #define AS_TIMER_MS_TO_CODE(t) (((t) - 100) / 50)
34 #define AS_TIMER_CODE_TO_MS(c) (50 * (c) + 100)
36 /* Register definitions */
38 /* Read-only Design info register: Reset state: xxxx 0001 */
39 #define AS_DESIGN_INFO_REG 0x00
40 #define AS_DESIGN_INFO_FACTORY(x) (((x) >> 4))
41 #define AS_DESIGN_INFO_MODEL(x) ((x) & 0x0f)
43 /* Read-only Version control register: Reset state: 0000 0000
44 * for first engineering samples
46 #define AS_VERSION_CONTROL_REG 0x01
47 #define AS_VERSION_CONTROL_RFU(x) (((x) >> 4))
48 #define AS_VERSION_CONTROL_VERSION(x) ((x) & 0x0f)
50 /* Read / Write (Indicator and timer register): Reset state: 0000 1111 */
51 #define AS_INDICATOR_AND_TIMER_REG 0x02
52 #define AS_INDICATOR_AND_TIMER_TIMEOUT_SHIFT 0
53 #define AS_INDICATOR_AND_TIMER_VREF_SHIFT 4
54 #define AS_INDICATOR_AND_TIMER_INDICATOR_SHIFT 6
56 /* Read / Write (Current set register): Reset state: 0110 1001 */
57 #define AS_CURRENT_SET_REG 0x03
58 #define AS_CURRENT_ASSIST_LIGHT_SHIFT 0
59 #define AS_CURRENT_LED_DET_ON (1 << 3)
60 #define AS_CURRENT_FLASH_CURRENT_SHIFT 4
62 /* Read / Write (Control register): Reset state: 1011 0100 */
63 #define AS_CONTROL_REG 0x04
64 #define AS_CONTROL_MODE_SETTING_SHIFT 0
65 #define AS_CONTROL_STROBE_ON (1 << 2)
66 #define AS_CONTROL_OUT_ON (1 << 3)
67 #define AS_CONTROL_EXT_TORCH_ON (1 << 4)
68 #define AS_CONTROL_STROBE_TYPE_EDGE (0 << 5)
69 #define AS_CONTROL_STROBE_TYPE_LEVEL (1 << 5)
70 #define AS_CONTROL_COIL_PEAK_SHIFT 6
72 /* Read only (D3 is read / write) (Fault and info): Reset state: 0000 x000 */
73 #define AS_FAULT_INFO_REG 0x05
74 #define AS_FAULT_INFO_INDUCTOR_PEAK_LIMIT (1 << 1)
75 #define AS_FAULT_INFO_INDICATOR_LED (1 << 2)
76 #define AS_FAULT_INFO_LED_AMOUNT (1 << 3)
77 #define AS_FAULT_INFO_TIMEOUT (1 << 4)
78 #define AS_FAULT_INFO_OVER_TEMPERATURE (1 << 5)
79 #define AS_FAULT_INFO_SHORT_CIRCUIT (1 << 6)
80 #define AS_FAULT_INFO_OVER_VOLTAGE (1 << 7)
83 #define AS_BOOST_REG 0x0d
84 #define AS_BOOST_CURRENT_DISABLE (0 << 0)
85 #define AS_BOOST_CURRENT_ENABLE (1 << 0)
87 /* Password register is used to unlock boost register writing */
88 #define AS_PASSWORD_REG 0x0f
89 #define AS_PASSWORD_UNLOCK_VALUE 0x55
92 AS_MODE_EXT_TORCH
= 0 << AS_CONTROL_MODE_SETTING_SHIFT
,
93 AS_MODE_INDICATOR
= 1 << AS_CONTROL_MODE_SETTING_SHIFT
,
94 AS_MODE_ASSIST
= 2 << AS_CONTROL_MODE_SETTING_SHIFT
,
95 AS_MODE_FLASH
= 3 << AS_CONTROL_MODE_SETTING_SHIFT
,
101 * @subdev: V4L2 subdev
102 * @pdata: Flash platform data
103 * @power_lock: Protects power_count
104 * @power_count: Power reference count
105 * @led_mode: V4L2 flash LED mode
106 * @timeout: Flash timeout in microseconds
107 * @flash_current: Flash current (0=200mA ... 15=500mA). Maximum
108 * values are 400mA for two LEDs and 500mA for one LED.
109 * @assist_current: Torch/Assist light current (0=20mA, 1=40mA ... 7=160mA)
110 * @indicator_current: Indicator LED current (0=0mA, 1=2.5mA ... 4=10mA)
111 * @strobe_source: Flash strobe source (software or external)
114 struct v4l2_subdev subdev
;
115 const struct as3645a_platform_data
*pdata
;
117 struct mutex power_lock
;
121 struct v4l2_ctrl_handler ctrls
;
123 enum v4l2_flash_led_mode led_mode
;
124 unsigned int timeout
;
127 u8 indicator_current
;
128 enum v4l2_flash_strobe_source strobe_source
;
131 #define to_as3645a(sd) container_of(sd, struct as3645a, subdev)
133 /* Return negative errno else zero on success */
134 static int as3645a_write(struct as3645a
*flash
, u8 addr
, u8 val
)
136 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
139 rval
= i2c_smbus_write_byte_data(client
, addr
, val
);
141 dev_dbg(&client
->dev
, "Write Addr:%02X Val:%02X %s\n", addr
, val
,
142 rval
< 0 ? "fail" : "ok");
147 /* Return negative errno else a data byte received from the device. */
148 static int as3645a_read(struct as3645a
*flash
, u8 addr
)
150 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
153 rval
= i2c_smbus_read_byte_data(client
, addr
);
155 dev_dbg(&client
->dev
, "Read Addr:%02X Val:%02X %s\n", addr
, rval
,
156 rval
< 0 ? "fail" : "ok");
161 /* -----------------------------------------------------------------------------
162 * Hardware configuration and trigger
166 * as3645a_set_config - Set flash configuration registers
169 * Configure the hardware with flash, assist and indicator currents, as well as
172 * Return 0 on success, or a negative error code if an I2C communication error
175 static int as3645a_set_config(struct as3645a
*flash
)
180 val
= (flash
->flash_current
<< AS_CURRENT_FLASH_CURRENT_SHIFT
)
181 | (flash
->assist_current
<< AS_CURRENT_ASSIST_LIGHT_SHIFT
)
182 | AS_CURRENT_LED_DET_ON
;
184 ret
= as3645a_write(flash
, AS_CURRENT_SET_REG
, val
);
188 val
= AS_TIMER_MS_TO_CODE(flash
->timeout
/ 1000)
189 << AS_INDICATOR_AND_TIMER_TIMEOUT_SHIFT
;
191 val
|= (flash
->pdata
->vref
<< AS_INDICATOR_AND_TIMER_VREF_SHIFT
)
192 | ((flash
->indicator_current
? flash
->indicator_current
- 1 : 0)
193 << AS_INDICATOR_AND_TIMER_INDICATOR_SHIFT
);
195 return as3645a_write(flash
, AS_INDICATOR_AND_TIMER_REG
, val
);
199 * as3645a_set_control - Set flash control register
201 * @mode: Desired output mode
202 * @on: Desired output state
204 * Configure the hardware with output mode and state.
206 * Return 0 on success, or a negative error code if an I2C communication error
210 as3645a_set_control(struct as3645a
*flash
, enum as_mode mode
, bool on
)
214 /* Configure output parameters and operation mode. */
215 reg
= (flash
->pdata
->peak
<< AS_CONTROL_COIL_PEAK_SHIFT
)
216 | (on
? AS_CONTROL_OUT_ON
: 0)
219 if (flash
->led_mode
== V4L2_FLASH_LED_MODE_FLASH
&&
220 flash
->strobe_source
== V4L2_FLASH_STROBE_SOURCE_EXTERNAL
) {
221 reg
|= AS_CONTROL_STROBE_TYPE_LEVEL
222 | AS_CONTROL_STROBE_ON
;
225 return as3645a_write(flash
, AS_CONTROL_REG
, reg
);
229 * as3645a_set_output - Configure output and operation mode
230 * @flash: Flash controller
231 * @strobe: Strobe the flash (only valid in flash mode)
233 * Turn the LEDs output on/off and set the operation mode based on the current
236 * The AS3645A can't control the indicator LED independently of the flash/torch
237 * LED. If the flash controller is in V4L2_FLASH_LED_MODE_NONE mode, set the
238 * chip to indicator mode. Otherwise set it to assist light (torch) or flash
241 * In indicator and assist modes, turn the output on/off based on the indicator
242 * and torch currents. In software strobe flash mode, turn the output on/off
243 * based on the strobe parameter.
245 static int as3645a_set_output(struct as3645a
*flash
, bool strobe
)
250 switch (flash
->led_mode
) {
251 case V4L2_FLASH_LED_MODE_NONE
:
252 on
= flash
->indicator_current
!= 0;
253 mode
= AS_MODE_INDICATOR
;
255 case V4L2_FLASH_LED_MODE_TORCH
:
257 mode
= AS_MODE_ASSIST
;
259 case V4L2_FLASH_LED_MODE_FLASH
:
261 mode
= AS_MODE_FLASH
;
267 /* Configure output parameters and operation mode. */
268 return as3645a_set_control(flash
, mode
, on
);
271 /* -----------------------------------------------------------------------------
275 static int as3645a_is_active(struct as3645a
*flash
)
279 ret
= as3645a_read(flash
, AS_CONTROL_REG
);
280 return ret
< 0 ? ret
: !!(ret
& AS_CONTROL_OUT_ON
);
283 static int as3645a_read_fault(struct as3645a
*flash
)
285 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
288 /* NOTE: reading register clear fault status */
289 rval
= as3645a_read(flash
, AS_FAULT_INFO_REG
);
293 if (rval
& AS_FAULT_INFO_INDUCTOR_PEAK_LIMIT
)
294 dev_dbg(&client
->dev
, "Inductor Peak limit fault\n");
296 if (rval
& AS_FAULT_INFO_INDICATOR_LED
)
297 dev_dbg(&client
->dev
, "Indicator LED fault: "
298 "Short circuit or open loop\n");
300 dev_dbg(&client
->dev
, "%u connected LEDs\n",
301 rval
& AS_FAULT_INFO_LED_AMOUNT
? 2 : 1);
303 if (rval
& AS_FAULT_INFO_TIMEOUT
)
304 dev_dbg(&client
->dev
, "Timeout fault\n");
306 if (rval
& AS_FAULT_INFO_OVER_TEMPERATURE
)
307 dev_dbg(&client
->dev
, "Over temperature fault\n");
309 if (rval
& AS_FAULT_INFO_SHORT_CIRCUIT
)
310 dev_dbg(&client
->dev
, "Short circuit fault\n");
312 if (rval
& AS_FAULT_INFO_OVER_VOLTAGE
)
313 dev_dbg(&client
->dev
, "Over voltage fault: "
314 "Indicates missing capacitor or open connection\n");
319 static int as3645a_get_ctrl(struct v4l2_ctrl
*ctrl
)
321 struct as3645a
*flash
=
322 container_of(ctrl
->handler
, struct as3645a
, ctrls
);
323 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
327 case V4L2_CID_FLASH_FAULT
:
328 value
= as3645a_read_fault(flash
);
333 if (value
& AS_FAULT_INFO_SHORT_CIRCUIT
)
334 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_SHORT_CIRCUIT
;
335 if (value
& AS_FAULT_INFO_OVER_TEMPERATURE
)
336 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_OVER_TEMPERATURE
;
337 if (value
& AS_FAULT_INFO_TIMEOUT
)
338 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_TIMEOUT
;
339 if (value
& AS_FAULT_INFO_OVER_VOLTAGE
)
340 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_OVER_VOLTAGE
;
341 if (value
& AS_FAULT_INFO_INDUCTOR_PEAK_LIMIT
)
342 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_OVER_CURRENT
;
343 if (value
& AS_FAULT_INFO_INDICATOR_LED
)
344 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_INDICATOR
;
347 case V4L2_CID_FLASH_STROBE_STATUS
:
348 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
) {
353 value
= as3645a_is_active(flash
);
357 ctrl
->cur
.val
= value
;
361 dev_dbg(&client
->dev
, "G_CTRL %08x:%d\n", ctrl
->id
, ctrl
->cur
.val
);
366 static int as3645a_set_ctrl(struct v4l2_ctrl
*ctrl
)
368 struct as3645a
*flash
=
369 container_of(ctrl
->handler
, struct as3645a
, ctrls
);
370 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
373 dev_dbg(&client
->dev
, "S_CTRL %08x:%d\n", ctrl
->id
, ctrl
->val
);
375 /* If a control that doesn't apply to the current mode is modified,
376 * we store the value and return immediately. The setting will be
377 * applied when the LED mode is changed. Otherwise we apply the setting
382 case V4L2_CID_FLASH_LED_MODE
:
383 if (flash
->indicator_current
)
386 ret
= as3645a_set_config(flash
);
390 flash
->led_mode
= ctrl
->val
;
391 return as3645a_set_output(flash
, false);
393 case V4L2_CID_FLASH_STROBE_SOURCE
:
394 flash
->strobe_source
= ctrl
->val
;
396 /* Applies to flash mode only. */
397 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
400 return as3645a_set_output(flash
, false);
402 case V4L2_CID_FLASH_STROBE
:
403 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
406 return as3645a_set_output(flash
, true);
408 case V4L2_CID_FLASH_STROBE_STOP
:
409 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
412 return as3645a_set_output(flash
, false);
414 case V4L2_CID_FLASH_TIMEOUT
:
415 flash
->timeout
= ctrl
->val
;
417 /* Applies to flash mode only. */
418 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
421 return as3645a_set_config(flash
);
423 case V4L2_CID_FLASH_INTENSITY
:
424 flash
->flash_current
= (ctrl
->val
- AS3645A_FLASH_INTENSITY_MIN
)
425 / AS3645A_FLASH_INTENSITY_STEP
;
427 /* Applies to flash mode only. */
428 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
431 return as3645a_set_config(flash
);
433 case V4L2_CID_FLASH_TORCH_INTENSITY
:
434 flash
->assist_current
=
435 (ctrl
->val
- AS3645A_TORCH_INTENSITY_MIN
)
436 / AS3645A_TORCH_INTENSITY_STEP
;
438 /* Applies to torch mode only. */
439 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_TORCH
)
442 return as3645a_set_config(flash
);
444 case V4L2_CID_FLASH_INDICATOR_INTENSITY
:
445 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_NONE
)
448 flash
->indicator_current
=
449 (ctrl
->val
- AS3645A_INDICATOR_INTENSITY_MIN
)
450 / AS3645A_INDICATOR_INTENSITY_STEP
;
452 ret
= as3645a_set_config(flash
);
456 if ((ctrl
->val
== 0) == (ctrl
->cur
.val
== 0))
459 return as3645a_set_output(flash
, false);
465 static const struct v4l2_ctrl_ops as3645a_ctrl_ops
= {
466 .g_volatile_ctrl
= as3645a_get_ctrl
,
467 .s_ctrl
= as3645a_set_ctrl
,
470 /* -----------------------------------------------------------------------------
471 * V4L2 subdev core operations
474 /* Put device into know state. */
475 static int as3645a_setup(struct as3645a
*flash
)
477 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
481 ret
= as3645a_read(flash
, AS_FAULT_INFO_REG
);
485 dev_dbg(&client
->dev
, "Fault info: %02x\n", ret
);
487 ret
= as3645a_set_config(flash
);
491 ret
= as3645a_set_output(flash
, false);
496 ret
= as3645a_read_fault(flash
);
500 dev_dbg(&client
->dev
, "AS_INDICATOR_AND_TIMER_REG: %02x\n",
501 as3645a_read(flash
, AS_INDICATOR_AND_TIMER_REG
));
502 dev_dbg(&client
->dev
, "AS_CURRENT_SET_REG: %02x\n",
503 as3645a_read(flash
, AS_CURRENT_SET_REG
));
504 dev_dbg(&client
->dev
, "AS_CONTROL_REG: %02x\n",
505 as3645a_read(flash
, AS_CONTROL_REG
));
507 return ret
& ~AS_FAULT_INFO_LED_AMOUNT
? -EIO
: 0;
510 static int __as3645a_set_power(struct as3645a
*flash
, int on
)
515 as3645a_set_control(flash
, AS_MODE_EXT_TORCH
, false);
517 if (flash
->pdata
->set_power
) {
518 ret
= flash
->pdata
->set_power(&flash
->subdev
, on
);
526 ret
= as3645a_setup(flash
);
528 if (flash
->pdata
->set_power
)
529 flash
->pdata
->set_power(&flash
->subdev
, 0);
535 static int as3645a_set_power(struct v4l2_subdev
*sd
, int on
)
537 struct as3645a
*flash
= to_as3645a(sd
);
540 mutex_lock(&flash
->power_lock
);
542 if (flash
->power_count
== !on
) {
543 ret
= __as3645a_set_power(flash
, !!on
);
548 flash
->power_count
+= on
? 1 : -1;
549 WARN_ON(flash
->power_count
< 0);
552 mutex_unlock(&flash
->power_lock
);
556 static int as3645a_registered(struct v4l2_subdev
*sd
)
558 struct as3645a
*flash
= to_as3645a(sd
);
559 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
560 int rval
, man
, model
, rfu
, version
;
563 /* Power up the flash driver and read manufacturer ID, model ID, RFU
566 rval
= as3645a_set_power(&flash
->subdev
, 1);
570 rval
= as3645a_read(flash
, AS_DESIGN_INFO_REG
);
574 man
= AS_DESIGN_INFO_FACTORY(rval
);
575 model
= AS_DESIGN_INFO_MODEL(rval
);
577 rval
= as3645a_read(flash
, AS_VERSION_CONTROL_REG
);
581 rfu
= AS_VERSION_CONTROL_RFU(rval
);
582 version
= AS_VERSION_CONTROL_VERSION(rval
);
584 /* Verify the chip model and version. */
585 if (model
!= 0x01 || rfu
!= 0x00) {
586 dev_err(&client
->dev
, "AS3645A not detected "
587 "(model %d rfu %d)\n", model
, rfu
);
594 vendor
= "AMS, Austria Micro Systems";
597 vendor
= "ADI, Analog Devices Inc.";
600 vendor
= "NSC, National Semiconductor";
606 vendor
= "TI, Texas Instrument";
612 dev_info(&client
->dev
, "Chip vendor: %s (%d) Version: %d\n", vendor
,
615 rval
= as3645a_write(flash
, AS_PASSWORD_REG
, AS_PASSWORD_UNLOCK_VALUE
);
619 rval
= as3645a_write(flash
, AS_BOOST_REG
, AS_BOOST_CURRENT_DISABLE
);
623 /* Setup default values. This makes sure that the chip is in a known
624 * state, in case the power rail can't be controlled.
626 rval
= as3645a_setup(flash
);
629 as3645a_set_power(&flash
->subdev
, 0);
634 static int as3645a_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
636 return as3645a_set_power(sd
, 1);
639 static int as3645a_close(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
641 return as3645a_set_power(sd
, 0);
644 static const struct v4l2_subdev_core_ops as3645a_core_ops
= {
645 .s_power
= as3645a_set_power
,
648 static const struct v4l2_subdev_ops as3645a_ops
= {
649 .core
= &as3645a_core_ops
,
652 static const struct v4l2_subdev_internal_ops as3645a_internal_ops
= {
653 .registered
= as3645a_registered
,
654 .open
= as3645a_open
,
655 .close
= as3645a_close
,
658 /* -----------------------------------------------------------------------------
663 static int as3645a_suspend(struct device
*dev
)
665 struct i2c_client
*client
= to_i2c_client(dev
);
666 struct v4l2_subdev
*subdev
= i2c_get_clientdata(client
);
667 struct as3645a
*flash
= to_as3645a(subdev
);
670 if (flash
->power_count
== 0)
673 rval
= __as3645a_set_power(flash
, 0);
675 dev_dbg(&client
->dev
, "Suspend %s\n", rval
< 0 ? "failed" : "ok");
680 static int as3645a_resume(struct device
*dev
)
682 struct i2c_client
*client
= to_i2c_client(dev
);
683 struct v4l2_subdev
*subdev
= i2c_get_clientdata(client
);
684 struct as3645a
*flash
= to_as3645a(subdev
);
687 if (flash
->power_count
== 0)
690 rval
= __as3645a_set_power(flash
, 1);
692 dev_dbg(&client
->dev
, "Resume %s\n", rval
< 0 ? "fail" : "ok");
699 #define as3645a_suspend NULL
700 #define as3645a_resume NULL
702 #endif /* CONFIG_PM */
705 * as3645a_init_controls - Create controls
708 * The number of LEDs reported in platform data is used to compute default
709 * limits. Parameters passed through platform data can override those limits.
711 static int as3645a_init_controls(struct as3645a
*flash
)
713 const struct as3645a_platform_data
*pdata
= flash
->pdata
;
714 struct v4l2_ctrl
*ctrl
;
717 v4l2_ctrl_handler_init(&flash
->ctrls
, 10);
719 /* V4L2_CID_FLASH_LED_MODE */
720 v4l2_ctrl_new_std_menu(&flash
->ctrls
, &as3645a_ctrl_ops
,
721 V4L2_CID_FLASH_LED_MODE
, 2, ~7,
722 V4L2_FLASH_LED_MODE_NONE
);
724 /* V4L2_CID_FLASH_STROBE_SOURCE */
725 v4l2_ctrl_new_std_menu(&flash
->ctrls
, &as3645a_ctrl_ops
,
726 V4L2_CID_FLASH_STROBE_SOURCE
,
727 pdata
->ext_strobe
? 1 : 0,
728 pdata
->ext_strobe
? ~3 : ~1,
729 V4L2_FLASH_STROBE_SOURCE_SOFTWARE
);
731 flash
->strobe_source
= V4L2_FLASH_STROBE_SOURCE_SOFTWARE
;
733 /* V4L2_CID_FLASH_STROBE */
734 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
735 V4L2_CID_FLASH_STROBE
, 0, 0, 0, 0);
737 /* V4L2_CID_FLASH_STROBE_STOP */
738 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
739 V4L2_CID_FLASH_STROBE_STOP
, 0, 0, 0, 0);
741 /* V4L2_CID_FLASH_STROBE_STATUS */
742 ctrl
= v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
743 V4L2_CID_FLASH_STROBE_STATUS
, 0, 1, 1, 1);
745 ctrl
->flags
|= V4L2_CTRL_FLAG_VOLATILE
;
747 /* V4L2_CID_FLASH_TIMEOUT */
748 maximum
= pdata
->timeout_max
;
750 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
751 V4L2_CID_FLASH_TIMEOUT
, AS3645A_FLASH_TIMEOUT_MIN
,
752 maximum
, AS3645A_FLASH_TIMEOUT_STEP
, maximum
);
754 flash
->timeout
= maximum
;
756 /* V4L2_CID_FLASH_INTENSITY */
757 maximum
= pdata
->flash_max_current
;
759 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
760 V4L2_CID_FLASH_INTENSITY
, AS3645A_FLASH_INTENSITY_MIN
,
761 maximum
, AS3645A_FLASH_INTENSITY_STEP
, maximum
);
763 flash
->flash_current
= (maximum
- AS3645A_FLASH_INTENSITY_MIN
)
764 / AS3645A_FLASH_INTENSITY_STEP
;
766 /* V4L2_CID_FLASH_TORCH_INTENSITY */
767 maximum
= pdata
->torch_max_current
;
769 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
770 V4L2_CID_FLASH_TORCH_INTENSITY
,
771 AS3645A_TORCH_INTENSITY_MIN
, maximum
,
772 AS3645A_TORCH_INTENSITY_STEP
,
773 AS3645A_TORCH_INTENSITY_MIN
);
775 flash
->assist_current
= 0;
777 /* V4L2_CID_FLASH_INDICATOR_INTENSITY */
778 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
779 V4L2_CID_FLASH_INDICATOR_INTENSITY
,
780 AS3645A_INDICATOR_INTENSITY_MIN
,
781 AS3645A_INDICATOR_INTENSITY_MAX
,
782 AS3645A_INDICATOR_INTENSITY_STEP
,
783 AS3645A_INDICATOR_INTENSITY_MIN
);
785 flash
->indicator_current
= 0;
787 /* V4L2_CID_FLASH_FAULT */
788 ctrl
= v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
789 V4L2_CID_FLASH_FAULT
, 0,
790 V4L2_FLASH_FAULT_OVER_VOLTAGE
|
791 V4L2_FLASH_FAULT_TIMEOUT
|
792 V4L2_FLASH_FAULT_OVER_TEMPERATURE
|
793 V4L2_FLASH_FAULT_SHORT_CIRCUIT
, 0, 0);
795 ctrl
->flags
|= V4L2_CTRL_FLAG_VOLATILE
;
797 flash
->subdev
.ctrl_handler
= &flash
->ctrls
;
799 return flash
->ctrls
.error
;
802 static int as3645a_probe(struct i2c_client
*client
,
803 const struct i2c_device_id
*devid
)
805 struct as3645a
*flash
;
808 if (client
->dev
.platform_data
== NULL
)
811 flash
= devm_kzalloc(&client
->dev
, sizeof(*flash
), GFP_KERNEL
);
815 flash
->pdata
= client
->dev
.platform_data
;
817 v4l2_i2c_subdev_init(&flash
->subdev
, client
, &as3645a_ops
);
818 flash
->subdev
.internal_ops
= &as3645a_internal_ops
;
819 flash
->subdev
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
821 ret
= as3645a_init_controls(flash
);
825 ret
= media_entity_pads_init(&flash
->subdev
.entity
, 0, NULL
);
829 flash
->subdev
.entity
.function
= MEDIA_ENT_F_FLASH
;
831 mutex_init(&flash
->power_lock
);
833 flash
->led_mode
= V4L2_FLASH_LED_MODE_NONE
;
837 v4l2_ctrl_handler_free(&flash
->ctrls
);
842 static int as3645a_remove(struct i2c_client
*client
)
844 struct v4l2_subdev
*subdev
= i2c_get_clientdata(client
);
845 struct as3645a
*flash
= to_as3645a(subdev
);
847 v4l2_device_unregister_subdev(subdev
);
848 v4l2_ctrl_handler_free(&flash
->ctrls
);
849 media_entity_cleanup(&flash
->subdev
.entity
);
850 mutex_destroy(&flash
->power_lock
);
855 static const struct i2c_device_id as3645a_id_table
[] = {
859 MODULE_DEVICE_TABLE(i2c
, as3645a_id_table
);
861 static const struct dev_pm_ops as3645a_pm_ops
= {
862 .suspend
= as3645a_suspend
,
863 .resume
= as3645a_resume
,
866 static struct i2c_driver as3645a_i2c_driver
= {
868 .name
= AS3645A_NAME
,
869 .pm
= &as3645a_pm_ops
,
871 .probe
= as3645a_probe
,
872 .remove
= as3645a_remove
,
873 .id_table
= as3645a_id_table
,
876 module_i2c_driver(as3645a_i2c_driver
);
878 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
879 MODULE_DESCRIPTION("LED flash driver for AS3645A, LM3555 and their clones");
880 MODULE_LICENSE("GPL");