2 * drivers/media/video/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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 * - Check hardware FSTROBE control when sensor driver add support for this
28 #include <linux/delay.h>
29 #include <linux/i2c.h>
30 #include <linux/module.h>
31 #include <linux/mutex.h>
32 #include <linux/slab.h>
34 #include <media/as3645a.h>
35 #include <media/v4l2-ctrls.h>
36 #include <media/v4l2-device.h>
38 #define AS_TIMER_MS_TO_CODE(t) (((t) - 100) / 50)
39 #define AS_TIMER_CODE_TO_MS(c) (50 * (c) + 100)
41 /* Register definitions */
43 /* Read-only Design info register: Reset state: xxxx 0001 */
44 #define AS_DESIGN_INFO_REG 0x00
45 #define AS_DESIGN_INFO_FACTORY(x) (((x) >> 4))
46 #define AS_DESIGN_INFO_MODEL(x) ((x) & 0x0f)
48 /* Read-only Version control register: Reset state: 0000 0000
49 * for first engineering samples
51 #define AS_VERSION_CONTROL_REG 0x01
52 #define AS_VERSION_CONTROL_RFU(x) (((x) >> 4))
53 #define AS_VERSION_CONTROL_VERSION(x) ((x) & 0x0f)
55 /* Read / Write (Indicator and timer register): Reset state: 0000 1111 */
56 #define AS_INDICATOR_AND_TIMER_REG 0x02
57 #define AS_INDICATOR_AND_TIMER_TIMEOUT_SHIFT 0
58 #define AS_INDICATOR_AND_TIMER_VREF_SHIFT 4
59 #define AS_INDICATOR_AND_TIMER_INDICATOR_SHIFT 6
61 /* Read / Write (Current set register): Reset state: 0110 1001 */
62 #define AS_CURRENT_SET_REG 0x03
63 #define AS_CURRENT_ASSIST_LIGHT_SHIFT 0
64 #define AS_CURRENT_LED_DET_ON (1 << 3)
65 #define AS_CURRENT_FLASH_CURRENT_SHIFT 4
67 /* Read / Write (Control register): Reset state: 1011 0100 */
68 #define AS_CONTROL_REG 0x04
69 #define AS_CONTROL_MODE_SETTING_SHIFT 0
70 #define AS_CONTROL_STROBE_ON (1 << 2)
71 #define AS_CONTROL_OUT_ON (1 << 3)
72 #define AS_CONTROL_EXT_TORCH_ON (1 << 4)
73 #define AS_CONTROL_STROBE_TYPE_EDGE (0 << 5)
74 #define AS_CONTROL_STROBE_TYPE_LEVEL (1 << 5)
75 #define AS_CONTROL_COIL_PEAK_SHIFT 6
77 /* Read only (D3 is read / write) (Fault and info): Reset state: 0000 x000 */
78 #define AS_FAULT_INFO_REG 0x05
79 #define AS_FAULT_INFO_INDUCTOR_PEAK_LIMIT (1 << 1)
80 #define AS_FAULT_INFO_INDICATOR_LED (1 << 2)
81 #define AS_FAULT_INFO_LED_AMOUNT (1 << 3)
82 #define AS_FAULT_INFO_TIMEOUT (1 << 4)
83 #define AS_FAULT_INFO_OVER_TEMPERATURE (1 << 5)
84 #define AS_FAULT_INFO_SHORT_CIRCUIT (1 << 6)
85 #define AS_FAULT_INFO_OVER_VOLTAGE (1 << 7)
88 #define AS_BOOST_REG 0x0d
89 #define AS_BOOST_CURRENT_DISABLE (0 << 0)
90 #define AS_BOOST_CURRENT_ENABLE (1 << 0)
92 /* Password register is used to unlock boost register writing */
93 #define AS_PASSWORD_REG 0x0f
94 #define AS_PASSWORD_UNLOCK_VALUE 0x55
97 AS_MODE_EXT_TORCH
= 0 << AS_CONTROL_MODE_SETTING_SHIFT
,
98 AS_MODE_INDICATOR
= 1 << AS_CONTROL_MODE_SETTING_SHIFT
,
99 AS_MODE_ASSIST
= 2 << AS_CONTROL_MODE_SETTING_SHIFT
,
100 AS_MODE_FLASH
= 3 << AS_CONTROL_MODE_SETTING_SHIFT
,
106 * @subdev: V4L2 subdev
107 * @pdata: Flash platform data
108 * @power_lock: Protects power_count
109 * @power_count: Power reference count
110 * @led_mode: V4L2 flash LED mode
111 * @timeout: Flash timeout in microseconds
112 * @flash_current: Flash current (0=200mA ... 15=500mA). Maximum
113 * values are 400mA for two LEDs and 500mA for one LED.
114 * @assist_current: Torch/Assist light current (0=20mA, 1=40mA ... 7=160mA)
115 * @indicator_current: Indicator LED current (0=0mA, 1=2.5mA ... 4=10mA)
116 * @strobe_source: Flash strobe source (software or external)
119 struct v4l2_subdev subdev
;
120 const struct as3645a_platform_data
*pdata
;
122 struct mutex power_lock
;
126 struct v4l2_ctrl_handler ctrls
;
128 enum v4l2_flash_led_mode led_mode
;
129 unsigned int timeout
;
132 u8 indicator_current
;
133 enum v4l2_flash_strobe_source strobe_source
;
136 #define to_as3645a(sd) container_of(sd, struct as3645a, subdev)
138 /* Return negative errno else zero on success */
139 static int as3645a_write(struct as3645a
*flash
, u8 addr
, u8 val
)
141 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
144 rval
= i2c_smbus_write_byte_data(client
, addr
, val
);
146 dev_dbg(&client
->dev
, "Write Addr:%02X Val:%02X %s\n", addr
, val
,
147 rval
< 0 ? "fail" : "ok");
152 /* Return negative errno else a data byte received from the device. */
153 static int as3645a_read(struct as3645a
*flash
, u8 addr
)
155 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
158 rval
= i2c_smbus_read_byte_data(client
, addr
);
160 dev_dbg(&client
->dev
, "Read Addr:%02X Val:%02X %s\n", addr
, rval
,
161 rval
< 0 ? "fail" : "ok");
166 /* -----------------------------------------------------------------------------
167 * Hardware configuration and trigger
171 * as3645a_set_config - Set flash configuration registers
174 * Configure the hardware with flash, assist and indicator currents, as well as
177 * Return 0 on success, or a negative error code if an I2C communication error
180 static int as3645a_set_config(struct as3645a
*flash
)
185 val
= (flash
->flash_current
<< AS_CURRENT_FLASH_CURRENT_SHIFT
)
186 | (flash
->assist_current
<< AS_CURRENT_ASSIST_LIGHT_SHIFT
)
187 | AS_CURRENT_LED_DET_ON
;
189 ret
= as3645a_write(flash
, AS_CURRENT_SET_REG
, val
);
193 val
= AS_TIMER_MS_TO_CODE(flash
->timeout
/ 1000)
194 << AS_INDICATOR_AND_TIMER_TIMEOUT_SHIFT
;
196 val
|= (flash
->pdata
->vref
<< AS_INDICATOR_AND_TIMER_VREF_SHIFT
)
197 | ((flash
->indicator_current
? flash
->indicator_current
- 1 : 0)
198 << AS_INDICATOR_AND_TIMER_INDICATOR_SHIFT
);
200 return as3645a_write(flash
, AS_INDICATOR_AND_TIMER_REG
, val
);
204 * as3645a_set_control - Set flash control register
206 * @mode: Desired output mode
207 * @on: Desired output state
209 * Configure the hardware with output mode and state.
211 * Return 0 on success, or a negative error code if an I2C communication error
215 as3645a_set_control(struct as3645a
*flash
, enum as_mode mode
, bool on
)
219 /* Configure output parameters and operation mode. */
220 reg
= (flash
->pdata
->peak
<< AS_CONTROL_COIL_PEAK_SHIFT
)
221 | (on
? AS_CONTROL_OUT_ON
: 0)
224 if (flash
->led_mode
== V4L2_FLASH_LED_MODE_FLASH
&&
225 flash
->strobe_source
== V4L2_FLASH_STROBE_SOURCE_EXTERNAL
) {
226 reg
|= AS_CONTROL_STROBE_TYPE_LEVEL
227 | AS_CONTROL_STROBE_ON
;
230 return as3645a_write(flash
, AS_CONTROL_REG
, reg
);
234 * as3645a_set_output - Configure output and operation mode
235 * @flash: Flash controller
236 * @strobe: Strobe the flash (only valid in flash mode)
238 * Turn the LEDs output on/off and set the operation mode based on the current
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
246 * In indicator and assist modes, turn the output on/off based on the indicator
247 * and torch currents. In software strobe flash mode, turn the output on/off
248 * based on the strobe parameter.
250 static int as3645a_set_output(struct as3645a
*flash
, bool strobe
)
255 switch (flash
->led_mode
) {
256 case V4L2_FLASH_LED_MODE_NONE
:
257 on
= flash
->indicator_current
!= 0;
258 mode
= AS_MODE_INDICATOR
;
260 case V4L2_FLASH_LED_MODE_TORCH
:
262 mode
= AS_MODE_ASSIST
;
264 case V4L2_FLASH_LED_MODE_FLASH
:
266 mode
= AS_MODE_FLASH
;
272 /* Configure output parameters and operation mode. */
273 return as3645a_set_control(flash
, mode
, on
);
276 /* -----------------------------------------------------------------------------
280 static int as3645a_is_active(struct as3645a
*flash
)
284 ret
= as3645a_read(flash
, AS_CONTROL_REG
);
285 return ret
< 0 ? ret
: !!(ret
& AS_CONTROL_OUT_ON
);
288 static int as3645a_read_fault(struct as3645a
*flash
)
290 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
293 /* NOTE: reading register clear fault status */
294 rval
= as3645a_read(flash
, AS_FAULT_INFO_REG
);
298 if (rval
& AS_FAULT_INFO_INDUCTOR_PEAK_LIMIT
)
299 dev_dbg(&client
->dev
, "Inductor Peak limit fault\n");
301 if (rval
& AS_FAULT_INFO_INDICATOR_LED
)
302 dev_dbg(&client
->dev
, "Indicator LED fault: "
303 "Short circuit or open loop\n");
305 dev_dbg(&client
->dev
, "%u connected LEDs\n",
306 rval
& AS_FAULT_INFO_LED_AMOUNT
? 2 : 1);
308 if (rval
& AS_FAULT_INFO_TIMEOUT
)
309 dev_dbg(&client
->dev
, "Timeout fault\n");
311 if (rval
& AS_FAULT_INFO_OVER_TEMPERATURE
)
312 dev_dbg(&client
->dev
, "Over temperature fault\n");
314 if (rval
& AS_FAULT_INFO_SHORT_CIRCUIT
)
315 dev_dbg(&client
->dev
, "Short circuit fault\n");
317 if (rval
& AS_FAULT_INFO_OVER_VOLTAGE
)
318 dev_dbg(&client
->dev
, "Over voltage fault: "
319 "Indicates missing capacitor or open connection\n");
324 static int as3645a_get_ctrl(struct v4l2_ctrl
*ctrl
)
326 struct as3645a
*flash
=
327 container_of(ctrl
->handler
, struct as3645a
, ctrls
);
328 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
332 case V4L2_CID_FLASH_FAULT
:
333 value
= as3645a_read_fault(flash
);
338 if (value
& AS_FAULT_INFO_SHORT_CIRCUIT
)
339 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_SHORT_CIRCUIT
;
340 if (value
& AS_FAULT_INFO_OVER_TEMPERATURE
)
341 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_OVER_TEMPERATURE
;
342 if (value
& AS_FAULT_INFO_TIMEOUT
)
343 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_TIMEOUT
;
344 if (value
& AS_FAULT_INFO_OVER_VOLTAGE
)
345 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_OVER_VOLTAGE
;
346 if (value
& AS_FAULT_INFO_INDUCTOR_PEAK_LIMIT
)
347 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_OVER_CURRENT
;
348 if (value
& AS_FAULT_INFO_INDICATOR_LED
)
349 ctrl
->cur
.val
|= V4L2_FLASH_FAULT_INDICATOR
;
352 case V4L2_CID_FLASH_STROBE_STATUS
:
353 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
) {
358 value
= as3645a_is_active(flash
);
362 ctrl
->cur
.val
= value
;
366 dev_dbg(&client
->dev
, "G_CTRL %08x:%d\n", ctrl
->id
, ctrl
->cur
.val
);
371 static int as3645a_set_ctrl(struct v4l2_ctrl
*ctrl
)
373 struct as3645a
*flash
=
374 container_of(ctrl
->handler
, struct as3645a
, ctrls
);
375 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
378 dev_dbg(&client
->dev
, "S_CTRL %08x:%d\n", ctrl
->id
, ctrl
->val
);
380 /* If a control that doesn't apply to the current mode is modified,
381 * we store the value and return immediately. The setting will be
382 * applied when the LED mode is changed. Otherwise we apply the setting
387 case V4L2_CID_FLASH_LED_MODE
:
388 if (flash
->indicator_current
)
391 ret
= as3645a_set_config(flash
);
395 flash
->led_mode
= ctrl
->val
;
396 return as3645a_set_output(flash
, false);
398 case V4L2_CID_FLASH_STROBE_SOURCE
:
399 flash
->strobe_source
= ctrl
->val
;
401 /* Applies to flash mode only. */
402 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
405 return as3645a_set_output(flash
, false);
407 case V4L2_CID_FLASH_STROBE
:
408 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
411 return as3645a_set_output(flash
, true);
413 case V4L2_CID_FLASH_STROBE_STOP
:
414 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
417 return as3645a_set_output(flash
, false);
419 case V4L2_CID_FLASH_TIMEOUT
:
420 flash
->timeout
= ctrl
->val
;
422 /* Applies to flash mode only. */
423 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
426 return as3645a_set_config(flash
);
428 case V4L2_CID_FLASH_INTENSITY
:
429 flash
->flash_current
= (ctrl
->val
- AS3645A_FLASH_INTENSITY_MIN
)
430 / AS3645A_FLASH_INTENSITY_STEP
;
432 /* Applies to flash mode only. */
433 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_FLASH
)
436 return as3645a_set_config(flash
);
438 case V4L2_CID_FLASH_TORCH_INTENSITY
:
439 flash
->assist_current
=
440 (ctrl
->val
- AS3645A_TORCH_INTENSITY_MIN
)
441 / AS3645A_TORCH_INTENSITY_STEP
;
443 /* Applies to torch mode only. */
444 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_TORCH
)
447 return as3645a_set_config(flash
);
449 case V4L2_CID_FLASH_INDICATOR_INTENSITY
:
450 if (flash
->led_mode
!= V4L2_FLASH_LED_MODE_NONE
)
453 flash
->indicator_current
=
454 (ctrl
->val
- AS3645A_INDICATOR_INTENSITY_MIN
)
455 / AS3645A_INDICATOR_INTENSITY_STEP
;
457 ret
= as3645a_set_config(flash
);
461 if ((ctrl
->val
== 0) == (ctrl
->cur
.val
== 0))
464 return as3645a_set_output(flash
, false);
470 static const struct v4l2_ctrl_ops as3645a_ctrl_ops
= {
471 .g_volatile_ctrl
= as3645a_get_ctrl
,
472 .s_ctrl
= as3645a_set_ctrl
,
475 /* -----------------------------------------------------------------------------
476 * V4L2 subdev core operations
479 /* Put device into know state. */
480 static int as3645a_setup(struct as3645a
*flash
)
482 struct i2c_client
*client
= v4l2_get_subdevdata(&flash
->subdev
);
486 ret
= as3645a_read(flash
, AS_FAULT_INFO_REG
);
490 dev_dbg(&client
->dev
, "Fault info: %02x\n", ret
);
492 ret
= as3645a_set_config(flash
);
496 ret
= as3645a_set_output(flash
, false);
501 ret
= as3645a_read_fault(flash
);
505 dev_dbg(&client
->dev
, "AS_INDICATOR_AND_TIMER_REG: %02x\n",
506 as3645a_read(flash
, AS_INDICATOR_AND_TIMER_REG
));
507 dev_dbg(&client
->dev
, "AS_CURRENT_SET_REG: %02x\n",
508 as3645a_read(flash
, AS_CURRENT_SET_REG
));
509 dev_dbg(&client
->dev
, "AS_CONTROL_REG: %02x\n",
510 as3645a_read(flash
, AS_CONTROL_REG
));
512 return ret
& ~AS_FAULT_INFO_LED_AMOUNT
? -EIO
: 0;
515 static int __as3645a_set_power(struct as3645a
*flash
, int on
)
520 as3645a_set_control(flash
, AS_MODE_EXT_TORCH
, false);
522 if (flash
->pdata
->set_power
) {
523 ret
= flash
->pdata
->set_power(&flash
->subdev
, on
);
531 ret
= as3645a_setup(flash
);
533 if (flash
->pdata
->set_power
)
534 flash
->pdata
->set_power(&flash
->subdev
, 0);
540 static int as3645a_set_power(struct v4l2_subdev
*sd
, int on
)
542 struct as3645a
*flash
= to_as3645a(sd
);
545 mutex_lock(&flash
->power_lock
);
547 if (flash
->power_count
== !on
) {
548 ret
= __as3645a_set_power(flash
, !!on
);
553 flash
->power_count
+= on
? 1 : -1;
554 WARN_ON(flash
->power_count
< 0);
557 mutex_unlock(&flash
->power_lock
);
561 static int as3645a_registered(struct v4l2_subdev
*sd
)
563 struct as3645a
*flash
= to_as3645a(sd
);
564 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
565 int rval
, man
, model
, rfu
, version
;
568 /* Power up the flash driver and read manufacturer ID, model ID, RFU
571 rval
= as3645a_set_power(&flash
->subdev
, 1);
575 rval
= as3645a_read(flash
, AS_DESIGN_INFO_REG
);
579 man
= AS_DESIGN_INFO_FACTORY(rval
);
580 model
= AS_DESIGN_INFO_MODEL(rval
);
582 rval
= as3645a_read(flash
, AS_VERSION_CONTROL_REG
);
586 rfu
= AS_VERSION_CONTROL_RFU(rval
);
587 version
= AS_VERSION_CONTROL_VERSION(rval
);
589 /* Verify the chip model and version. */
590 if (model
!= 0x01 || rfu
!= 0x00) {
591 dev_err(&client
->dev
, "AS3645A not detected "
592 "(model %d rfu %d)\n", model
, rfu
);
599 vendor
= "AMS, Austria Micro Systems";
602 vendor
= "ADI, Analog Devices Inc.";
605 vendor
= "NSC, National Semiconductor";
611 vendor
= "TI, Texas Instrument";
617 dev_info(&client
->dev
, "Chip vendor: %s (%d) Version: %d\n", vendor
,
620 rval
= as3645a_write(flash
, AS_PASSWORD_REG
, AS_PASSWORD_UNLOCK_VALUE
);
624 rval
= as3645a_write(flash
, AS_BOOST_REG
, AS_BOOST_CURRENT_DISABLE
);
628 /* Setup default values. This makes sure that the chip is in a known
629 * state, in case the power rail can't be controlled.
631 rval
= as3645a_setup(flash
);
634 as3645a_set_power(&flash
->subdev
, 0);
639 static int as3645a_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
641 return as3645a_set_power(sd
, 1);
644 static int as3645a_close(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
646 return as3645a_set_power(sd
, 0);
649 static const struct v4l2_subdev_core_ops as3645a_core_ops
= {
650 .s_power
= as3645a_set_power
,
653 static const struct v4l2_subdev_ops as3645a_ops
= {
654 .core
= &as3645a_core_ops
,
657 static const struct v4l2_subdev_internal_ops as3645a_internal_ops
= {
658 .registered
= as3645a_registered
,
659 .open
= as3645a_open
,
660 .close
= as3645a_close
,
663 /* -----------------------------------------------------------------------------
668 static int as3645a_suspend(struct device
*dev
)
670 struct i2c_client
*client
= to_i2c_client(dev
);
671 struct v4l2_subdev
*subdev
= i2c_get_clientdata(client
);
672 struct as3645a
*flash
= to_as3645a(subdev
);
675 if (flash
->power_count
== 0)
678 rval
= __as3645a_set_power(flash
, 0);
680 dev_dbg(&client
->dev
, "Suspend %s\n", rval
< 0 ? "failed" : "ok");
685 static int as3645a_resume(struct device
*dev
)
687 struct i2c_client
*client
= to_i2c_client(dev
);
688 struct v4l2_subdev
*subdev
= i2c_get_clientdata(client
);
689 struct as3645a
*flash
= to_as3645a(subdev
);
692 if (flash
->power_count
== 0)
695 rval
= __as3645a_set_power(flash
, 1);
697 dev_dbg(&client
->dev
, "Resume %s\n", rval
< 0 ? "fail" : "ok");
704 #define as3645a_suspend NULL
705 #define as3645a_resume NULL
707 #endif /* CONFIG_PM */
710 * as3645a_init_controls - Create controls
713 * The number of LEDs reported in platform data is used to compute default
714 * limits. Parameters passed through platform data can override those limits.
716 static int as3645a_init_controls(struct as3645a
*flash
)
718 const struct as3645a_platform_data
*pdata
= flash
->pdata
;
719 struct v4l2_ctrl
*ctrl
;
722 v4l2_ctrl_handler_init(&flash
->ctrls
, 10);
724 /* V4L2_CID_FLASH_LED_MODE */
725 v4l2_ctrl_new_std_menu(&flash
->ctrls
, &as3645a_ctrl_ops
,
726 V4L2_CID_FLASH_LED_MODE
, 2, ~7,
727 V4L2_FLASH_LED_MODE_NONE
);
729 /* V4L2_CID_FLASH_STROBE_SOURCE */
730 v4l2_ctrl_new_std_menu(&flash
->ctrls
, &as3645a_ctrl_ops
,
731 V4L2_CID_FLASH_STROBE_SOURCE
,
732 pdata
->ext_strobe
? 1 : 0,
733 pdata
->ext_strobe
? ~3 : ~1,
734 V4L2_FLASH_STROBE_SOURCE_SOFTWARE
);
736 flash
->strobe_source
= V4L2_FLASH_STROBE_SOURCE_SOFTWARE
;
738 /* V4L2_CID_FLASH_STROBE */
739 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
740 V4L2_CID_FLASH_STROBE
, 0, 0, 0, 0);
742 /* V4L2_CID_FLASH_STROBE_STOP */
743 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
744 V4L2_CID_FLASH_STROBE_STOP
, 0, 0, 0, 0);
746 /* V4L2_CID_FLASH_STROBE_STATUS */
747 ctrl
= v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
748 V4L2_CID_FLASH_STROBE_STATUS
, 0, 1, 1, 1);
750 ctrl
->flags
|= V4L2_CTRL_FLAG_VOLATILE
;
752 /* V4L2_CID_FLASH_TIMEOUT */
753 maximum
= pdata
->timeout_max
;
755 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
756 V4L2_CID_FLASH_TIMEOUT
, AS3645A_FLASH_TIMEOUT_MIN
,
757 maximum
, AS3645A_FLASH_TIMEOUT_STEP
, maximum
);
759 flash
->timeout
= maximum
;
761 /* V4L2_CID_FLASH_INTENSITY */
762 maximum
= pdata
->flash_max_current
;
764 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
765 V4L2_CID_FLASH_INTENSITY
, AS3645A_FLASH_INTENSITY_MIN
,
766 maximum
, AS3645A_FLASH_INTENSITY_STEP
, maximum
);
768 flash
->flash_current
= (maximum
- AS3645A_FLASH_INTENSITY_MIN
)
769 / AS3645A_FLASH_INTENSITY_STEP
;
771 /* V4L2_CID_FLASH_TORCH_INTENSITY */
772 maximum
= pdata
->torch_max_current
;
774 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
775 V4L2_CID_FLASH_TORCH_INTENSITY
,
776 AS3645A_TORCH_INTENSITY_MIN
, maximum
,
777 AS3645A_TORCH_INTENSITY_STEP
,
778 AS3645A_TORCH_INTENSITY_MIN
);
780 flash
->assist_current
= 0;
782 /* V4L2_CID_FLASH_INDICATOR_INTENSITY */
783 v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
784 V4L2_CID_FLASH_INDICATOR_INTENSITY
,
785 AS3645A_INDICATOR_INTENSITY_MIN
,
786 AS3645A_INDICATOR_INTENSITY_MAX
,
787 AS3645A_INDICATOR_INTENSITY_STEP
,
788 AS3645A_INDICATOR_INTENSITY_MIN
);
790 flash
->indicator_current
= 0;
792 /* V4L2_CID_FLASH_FAULT */
793 ctrl
= v4l2_ctrl_new_std(&flash
->ctrls
, &as3645a_ctrl_ops
,
794 V4L2_CID_FLASH_FAULT
, 0,
795 V4L2_FLASH_FAULT_OVER_VOLTAGE
|
796 V4L2_FLASH_FAULT_TIMEOUT
|
797 V4L2_FLASH_FAULT_OVER_TEMPERATURE
|
798 V4L2_FLASH_FAULT_SHORT_CIRCUIT
, 0, 0);
800 ctrl
->flags
|= V4L2_CTRL_FLAG_VOLATILE
;
802 flash
->subdev
.ctrl_handler
= &flash
->ctrls
;
804 return flash
->ctrls
.error
;
807 static int as3645a_probe(struct i2c_client
*client
,
808 const struct i2c_device_id
*devid
)
810 struct as3645a
*flash
;
813 if (client
->dev
.platform_data
== NULL
)
816 flash
= kzalloc(sizeof(*flash
), GFP_KERNEL
);
820 flash
->pdata
= client
->dev
.platform_data
;
822 v4l2_i2c_subdev_init(&flash
->subdev
, client
, &as3645a_ops
);
823 flash
->subdev
.internal_ops
= &as3645a_internal_ops
;
824 flash
->subdev
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
826 ret
= as3645a_init_controls(flash
);
830 ret
= media_entity_init(&flash
->subdev
.entity
, 0, NULL
, 0);
834 flash
->subdev
.entity
.type
= MEDIA_ENT_T_V4L2_SUBDEV_FLASH
;
836 mutex_init(&flash
->power_lock
);
838 flash
->led_mode
= V4L2_FLASH_LED_MODE_NONE
;
842 v4l2_ctrl_handler_free(&flash
->ctrls
);
849 static int __exit
as3645a_remove(struct i2c_client
*client
)
851 struct v4l2_subdev
*subdev
= i2c_get_clientdata(client
);
852 struct as3645a
*flash
= to_as3645a(subdev
);
854 v4l2_device_unregister_subdev(subdev
);
855 v4l2_ctrl_handler_free(&flash
->ctrls
);
856 media_entity_cleanup(&flash
->subdev
.entity
);
857 mutex_destroy(&flash
->power_lock
);
863 static const struct i2c_device_id as3645a_id_table
[] = {
867 MODULE_DEVICE_TABLE(i2c
, as3645a_id_table
);
869 static const struct dev_pm_ops as3645a_pm_ops
= {
870 .suspend
= as3645a_suspend
,
871 .resume
= as3645a_resume
,
874 static struct i2c_driver as3645a_i2c_driver
= {
876 .name
= AS3645A_NAME
,
877 .pm
= &as3645a_pm_ops
,
879 .probe
= as3645a_probe
,
880 .remove
= __exit_p(as3645a_remove
),
881 .id_table
= as3645a_id_table
,
884 static int __init
as3645a_init(void)
888 rval
= i2c_add_driver(&as3645a_i2c_driver
);
890 pr_err("%s: Failed to register the driver\n", AS3645A_NAME
);
895 static void __exit
as3645a_exit(void)
897 i2c_del_driver(&as3645a_i2c_driver
);
900 module_init(as3645a_init
);
901 module_exit(as3645a_exit
);
903 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
904 MODULE_DESCRIPTION("LED flash driver for AS3645A, LM3555 and their clones");
905 MODULE_LICENSE("GPL");