29 #include <linux/i2c.h>
30 #include <linux/module.h>
32 #include <linux/slab.h>
38 #define AS_TIMER_MS_TO_CODE(t) (((t) - 100) / 50)
39 #define AS_TIMER_CODE_TO_MS(c) (50 * (c) + 100)
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)
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)
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
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
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
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)
93 #define AS_PASSWORD_REG 0x0f
94 #define AS_PASSWORD_UNLOCK_VALUE 0x55
136 #define to_as3645a(sd) container_of(sd, struct as3645a, subdev)
146 dev_dbg(&client->
dev,
"Write Addr:%02X Val:%02X %s\n", addr, val,
147 rval < 0 ?
"fail" :
"ok");
160 dev_dbg(&client->
dev,
"Read Addr:%02X Val:%02X %s\n", addr, rval,
161 rval < 0 ?
"fail" :
"ok");
250 static int as3645a_set_output(
struct as3645a *flash,
bool strobe)
273 return as3645a_set_control(flash, mode, on);
280 static int as3645a_is_active(
struct as3645a *flash)
288 static int as3645a_read_fault(
struct as3645a *flash)
299 dev_dbg(&client->
dev,
"Inductor Peak limit fault\n");
303 "Short circuit or open loop\n");
312 dev_dbg(&client->
dev,
"Over temperature fault\n");
315 dev_dbg(&client->
dev,
"Short circuit fault\n");
319 "Indicates missing capacitor or open connection\n");
333 value = as3645a_read_fault(flash);
338 if (value & AS_FAULT_INFO_SHORT_CIRCUIT)
340 if (value & AS_FAULT_INFO_OVER_TEMPERATURE)
342 if (value & AS_FAULT_INFO_TIMEOUT)
346 if (value & AS_FAULT_INFO_INDUCTOR_PEAK_LIMIT)
348 if (value & AS_FAULT_INFO_INDICATOR_LED)
358 value = as3645a_is_active(flash);
371 static int as3645a_set_ctrl(
struct v4l2_ctrl *ctrl)
391 ret = as3645a_set_config(flash);
396 return as3645a_set_output(flash,
false);
405 return as3645a_set_output(flash,
false);
411 return as3645a_set_output(flash,
true);
417 return as3645a_set_output(flash,
false);
426 return as3645a_set_config(flash);
436 return as3645a_set_config(flash);
447 return as3645a_set_config(flash);
457 ret = as3645a_set_config(flash);
461 if ((ctrl->
val == 0) == (ctrl->
cur.
val == 0))
464 return as3645a_set_output(flash,
false);
471 .g_volatile_ctrl = as3645a_get_ctrl,
472 .s_ctrl = as3645a_set_ctrl,
480 static int as3645a_setup(
struct as3645a *flash)
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",
507 dev_dbg(&client->
dev,
"AS_CURRENT_SET_REG: %02x\n",
509 dev_dbg(&client->
dev,
"AS_CONTROL_REG: %02x\n",
515 static int __as3645a_set_power(
struct as3645a *flash,
int on)
522 if (flash->
pdata->set_power) {
531 ret = as3645a_setup(flash);
533 if (flash->
pdata->set_power)
548 ret = __as3645a_set_power(flash, !!on);
561 static int as3645a_registered(
struct v4l2_subdev *sd)
564 struct i2c_client *client = v4l2_get_subdevdata(sd);
571 rval = as3645a_set_power(&flash->
subdev, 1);
590 if (model != 0x01 || rfu != 0x00) {
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,
631 rval = as3645a_setup(flash);
634 as3645a_set_power(&flash->
subdev, 0);
641 return as3645a_set_power(sd, 1);
646 return as3645a_set_power(sd, 0);
650 .s_power = as3645a_set_power,
654 .core = &as3645a_core_ops,
658 .registered = as3645a_registered,
659 .open = as3645a_open,
660 .close = as3645a_close,
678 rval = __as3645a_set_power(flash, 0);
680 dev_dbg(&client->
dev,
"Suspend %s\n", rval < 0 ?
"failed" :
"ok");
688 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
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
804 return flash->
ctrls.error;
813 if (client->
dev.platform_data ==
NULL)
820 flash->
pdata = client->
dev.platform_data;
823 flash->
subdev.internal_ops = &as3645a_internal_ops;
826 ret = as3645a_init_controls(flash);
851 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
869 static const struct dev_pm_ops as3645a_pm_ops = {
874 static struct i2c_driver as3645a_i2c_driver = {
877 .pm = &as3645a_pm_ops,
879 .probe = as3645a_probe,
881 .id_table = as3645a_id_table,