10 #include <linux/module.h>
12 #include <linux/i2c.h>
14 #include <linux/slab.h>
21 #define REG_FILT_TIME (0x0)
22 #define REG_IVFM_MODE (0x1)
23 #define REG_TORCH_TIME (0x6)
24 #define REG_FLASH (0x8)
25 #define REG_I_CTRL (0x9)
26 #define REG_ENABLE (0xA)
27 #define REG_FLAG (0xB)
30 #define UVLO_EN_SHIFT (7)
31 #define IVM_D_TH_SHIFT (2)
32 #define TORCH_RAMP_UP_TIME_SHIFT (3)
33 #define TORCH_RAMP_DN_TIME_SHIFT (0)
34 #define INDUCTOR_I_LIMIT_SHIFT (6)
35 #define FLASH_RAMP_TIME_SHIFT (3)
36 #define FLASH_TOUT_TIME_SHIFT (0)
37 #define TORCH_I_SHIFT (4)
38 #define FLASH_I_SHIFT (0)
39 #define IVFM_SHIFT (7)
40 #define TX_PIN_EN_SHIFT (6)
41 #define STROBE_PIN_EN_SHIFT (5)
42 #define TORCH_PIN_EN_SHIFT (4)
43 #define MODE_BITS_SHIFT (0)
45 #define UVLO_EN_MASK (0x1)
46 #define IVM_D_TH_MASK (0x7)
47 #define TORCH_RAMP_UP_TIME_MASK (0x7)
48 #define TORCH_RAMP_DN_TIME_MASK (0x7)
49 #define INDUCTOR_I_LIMIT_MASK (0x1)
50 #define FLASH_RAMP_TIME_MASK (0x7)
51 #define FLASH_TOUT_TIME_MASK (0x7)
52 #define TORCH_I_MASK (0x7)
53 #define FLASH_I_MASK (0xF)
54 #define IVFM_MASK (0x1)
55 #define TX_PIN_EN_MASK (0x1)
56 #define STROBE_PIN_EN_MASK (0x1)
57 #define TORCH_PIN_EN_MASK (0x1)
58 #define MODE_BITS_MASK (0x73)
59 #define EX_PIN_CONTROL_MASK (0x71)
60 #define EX_PIN_ENABLE_MASK (0x70)
105 dev_err(chip->
dev,
"Failed to update REG_ENABLE Register\n");
117 dev_err(chip->
dev,
"Failed to read REG_FLAG Register\n");
161 dev_err(chip->
dev,
"Failed to write REG_I_CTRL Register\n");
203 dev_err(chip->
dev,
"%s:i2c access fail to register\n", __func__);
206 dev_err(chip->
dev,
"%s: fail to change str to int\n", __func__);
212 static void lm3642_deferred_torch_brightness_set(
struct work_struct *
work)
237 const char *buf,
size_t size)
260 dev_err(chip->
dev,
"%s:i2c access fail to register\n", __func__);
263 dev_err(chip->
dev,
"%s: fail to change str to int\n", __func__);
269 static void lm3642_deferred_strobe_brightness_set(
struct work_struct *
work)
290 static void lm3642_deferred_indicator_brightness_set(
struct work_struct *
work)
310 static const struct regmap_config lm3642_regmap = {
325 dev_err(&client->
dev,
"i2c functionality check fail.\n");
330 dev_err(&client->
dev,
"needs Platform Data.\n");
347 if (IS_ERR(chip->
regmap)) {
348 err = PTR_ERR(chip->
regmap);
349 dev_err(&client->
dev,
"Failed to allocate register map: %d\n",
355 i2c_set_clientdata(client, chip);
357 err = lm3642_chip_init(chip);
365 chip->
cdev_flash.brightness_set = lm3642_strobe_brightness_set;
369 dev_err(chip->
dev,
"failed to register flash\n");
374 dev_err(chip->
dev,
"failed to create strobe-pin file\n");
375 goto err_create_flash_pin_file;
382 chip->
cdev_torch.brightness_set = lm3642_torch_brightness_set;
386 dev_err(chip->
dev,
"failed to register torch\n");
387 goto err_create_torch_file;
391 dev_err(chip->
dev,
"failed to create torch-pin file\n");
392 goto err_create_torch_pin_file;
397 lm3642_deferred_indicator_brightness_set);
400 chip->
cdev_indicator.brightness_set = lm3642_indicator_brightness_set;
404 dev_err(chip->
dev,
"failed to register indicator\n");
405 goto err_create_indicator_file;
411 err_create_indicator_file:
413 err_create_torch_pin_file:
415 err_create_torch_file:
417 err_create_flash_pin_file:
446 static struct i2c_driver lm3642_i2c_driver = {
452 .probe = lm3642_probe,
454 .id_table = lm3642_id,