Add LM3644 new Flash drivers v4l2&LED subsystem
authora0414807local <a0414807local@uva0414807>
Mon, 28 Jul 2014 00:54:13 +0000 (09:54 +0900)
committera0414807local <a0414807local@uva0414807>
Mon, 28 Jul 2014 00:54:13 +0000 (09:54 +0900)
Signed-off-by: a0414807local <a0414807local@uva0414807>
drivers/leds/Kconfig
drivers/leds/Makefile
drivers/leds/leds-lm3644.c [new file with mode: 0644]
drivers/media/i2c/Kconfig
drivers/media/i2c/Makefile
drivers/media/i2c/lm3644.c [new file with mode: 0644]
include/linux/platform_data/leds-lm3644.h [new file with mode: 0644]
include/media/lm3644.h [new file with mode: 0644]

index b5609c0dcb946121a45244068970bf6544a3c078..0a6fe2ffc6576977c4a10d032286a048aaacc3f3 100644 (file)
@@ -82,6 +82,15 @@ config LEDS_LM3643
          The LM3643 is a 2/4MHz fixed-frequency synchronous boost
          converter with 1.5A constant current LED driver.
 
+config LEDS_LM3644
+       tristate "LED support for LM3644 Chip"
+       depends on LEDS_CLASS && I2C
+       select REGMAP_I2C
+       help
+         This option enables support for LEDs connected to LM3644.
+         The LM3644 is a 2/4MHz fixed-frequency synchronous boost
+         converter with 1.5A constant current LED driver.
+
 config LEDS_LOCOMO
        tristate "LED Support for Locomo device"
        depends on LEDS_CLASS
index 9bfa0819f1d6f038dcfec8db7358c71dfaa705c8..03aa44f4c145c8d150effd302a1d9f6e9a753d80 100644 (file)
@@ -13,6 +13,7 @@ obj-$(CONFIG_LEDS_LM3530)             += leds-lm3530.o
 obj-$(CONFIG_LEDS_LM3533)              += leds-lm3533.o
 obj-$(CONFIG_LEDS_LM3642)              += leds-lm3642.o
 obj-$(CONFIG_LEDS_LM3643)              += leds-lm3643.o
+obj-$(CONFIG_LEDS_LM3644)              += leds-lm3644.o
 obj-$(CONFIG_LEDS_MIKROTIK_RB532)      += leds-rb532.o
 obj-$(CONFIG_LEDS_S3C24XX)             += leds-s3c24xx.o
 obj-$(CONFIG_LEDS_NET48XX)             += leds-net48xx.o
diff --git a/drivers/leds/leds-lm3644.c b/drivers/leds/leds-lm3644.c
new file mode 100644 (file)
index 0000000..baf2fbb
--- /dev/null
@@ -0,0 +1,699 @@
+/*
+ * drivers/leds/leds-lm3644.c
+ * General device driver for TI LM3644, FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong <gshark.jeong@gmail.com>
+ *                     Ldd-Mlp <ldd-mlp@list.ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/leds.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/fs.h>
+#include <linux/regmap.h>
+#include <linux/workqueue.h>
+#include <linux/platform_data/leds-lm3644.h>
+
+/* registers definitions */
+#define REG_ENABLE             0x01
+#define REG_FLASH_LED0_BR      0x03
+#define REG_FLASH_LED1_BR      0x04
+#define REG_TORCH_LED0_BR      0x05
+#define REG_TORCH_LED1_BR      0x06
+#define REG_FLASH_TOUT         0x08
+#define REG_FLAG0              0x0a
+#define REG_FLAG1              0x0b
+
+enum lm3644_devid {
+       ID_FLASH0 = 0x0,
+       ID_FLASH1,
+       ID_TORCH0,
+       ID_TORCH1,
+       ID_MAX
+};
+
+enum lm3644_mode {
+       MODE_STDBY = 0x0,
+       MODE_IR,
+       MODE_TORCH,
+       MODE_FLASH,
+       MODE_MAX
+};
+
+enum lm3644_devfile {
+       DFILE_FLASH0_ENABLE = 0,
+       DFILE_FLASH0_ONOFF,
+       DFILE_FLASH0_SOURCE,
+       DFILE_FLASH0_TIMEOUT,
+       DFILE_FLASH1_ENABLE,
+       DFILE_FLASH1_ONOFF,
+       DFILE_TORCH0_ENABLE,
+       DFILE_TORCH0_ONOFF,
+       DFILE_TORCH0_SOURCE,
+       DFILE_TORCH1_ENABLE,
+       DFILE_TORCH1_ONOFF,
+       DFILE_MAX
+};
+
+#define to_lm3644(_ctrl, _no) container_of(_ctrl, struct lm3644, cdev[_no])
+
+struct lm3644 {
+       struct device *dev;
+
+       u8 brightness[ID_MAX];
+       struct work_struct work[ID_MAX];
+       struct led_classdev cdev[ID_MAX];
+
+       struct lm3644_platform_data *pdata;
+       struct regmap *regmap;
+       struct mutex lock;
+};
+
+static void lm3644_read_flag(struct lm3644 *pchip)
+{
+
+       int rval;
+       unsigned int flag0, flag1;
+
+       rval = regmap_read(pchip->regmap, REG_FLAG0, &flag0);
+       rval |= regmap_read(pchip->regmap, REG_FLAG1, &flag1);
+
+       if (rval < 0)
+               dev_err(pchip->dev, "i2c access fail.\n");
+
+       dev_info(pchip->dev, "[flag1] 0x%x, [flag0] 0x%x\n",
+                flag1 & 0x1f, flag0);
+}
+
+/* torch0 brightness control */
+static void lm3644_deferred_torch0_brightness_set(struct work_struct *work)
+{
+       struct lm3644 *pchip = container_of(work,
+                                           struct lm3644, work[ID_TORCH0]);
+
+       if (regmap_update_bits(pchip->regmap,
+                              REG_TORCH_LED0_BR, 0x7f,
+                              pchip->brightness[ID_TORCH0]))
+               dev_err(pchip->dev, "i2c access fail.\n");
+       lm3644_read_flag(pchip);
+}
+
+static void lm3644_torch0_brightness_set(struct led_classdev *cdev,
+                                        enum led_brightness brightness)
+{
+       struct lm3644 *pchip =
+           container_of(cdev, struct lm3644, cdev[ID_TORCH0]);
+
+       pchip->brightness[ID_TORCH0] = brightness;
+       schedule_work(&pchip->work[ID_TORCH0]);
+}
+
+/* torch1 brightness control */
+static void lm3644_deferred_torch1_brightness_set(struct work_struct *work)
+{
+       struct lm3644 *pchip = container_of(work,
+                                           struct lm3644, work[ID_TORCH1]);
+
+       if (regmap_update_bits(pchip->regmap,
+                              REG_TORCH_LED1_BR, 0x7f,
+                              pchip->brightness[ID_TORCH1]))
+               dev_err(pchip->dev, "i2c access fail.\n");
+       lm3644_read_flag(pchip);
+}
+
+static void lm3644_torch1_brightness_set(struct led_classdev *cdev,
+                                        enum led_brightness brightness)
+{
+       struct lm3644 *pchip =
+           container_of(cdev, struct lm3644, cdev[ID_TORCH1]);
+
+       pchip->brightness[ID_TORCH1] = brightness;
+       schedule_work(&pchip->work[ID_TORCH1]);
+}
+
+/* flash0 brightness control */
+static void lm3644_deferred_flash0_brightness_set(struct work_struct *work)
+{
+       struct lm3644 *pchip = container_of(work,
+                                           struct lm3644, work[ID_FLASH0]);
+
+       if (regmap_update_bits(pchip->regmap,
+                              REG_FLASH_LED0_BR, 0x7f,
+                              pchip->brightness[ID_FLASH0]))
+               dev_err(pchip->dev, "i2c access fail.\n");
+       lm3644_read_flag(pchip);
+}
+
+static void lm3644_flash0_brightness_set(struct led_classdev *cdev,
+                                        enum led_brightness brightness)
+{
+       struct lm3644 *pchip =
+           container_of(cdev, struct lm3644, cdev[ID_FLASH0]);
+
+       pchip->brightness[ID_FLASH0] = brightness;
+       schedule_work(&pchip->work[ID_FLASH0]);
+}
+
+/* flash1 brightness control */
+static void lm3644_deferred_flash1_brightness_set(struct work_struct *work)
+{
+       struct lm3644 *pchip = container_of(work,
+                                           struct lm3644, work[ID_FLASH1]);
+
+       if (regmap_update_bits(pchip->regmap,
+                              REG_FLASH_LED1_BR, 0x7f,
+                              pchip->brightness[ID_FLASH1]))
+               dev_err(pchip->dev, "i2c access fail.\n");
+       lm3644_read_flag(pchip);
+}
+
+static void lm3644_flash1_brightness_set(struct led_classdev *cdev,
+                                        enum led_brightness brightness)
+{
+       struct lm3644 *pchip =
+           container_of(cdev, struct lm3644, cdev[ID_FLASH1]);
+
+       pchip->brightness[ID_FLASH1] = brightness;
+       schedule_work(&pchip->work[ID_FLASH1]);
+}
+
+struct lm3644_devices {
+       struct led_classdev cdev;
+       work_func_t func;
+};
+
+static struct lm3644_devices lm3644_leds[ID_MAX] = {
+       [ID_FLASH0] = {
+                      .cdev.name = "flash0",
+                      .cdev.brightness = 0,
+                      .cdev.max_brightness = 0x7f,
+                      .cdev.brightness_set = lm3644_flash0_brightness_set,
+                      .cdev.default_trigger = "flash0",
+                      .func = lm3644_deferred_flash0_brightness_set},
+       [ID_FLASH1] = {
+                      .cdev.name = "flash1",
+                      .cdev.brightness = 0,
+                      .cdev.max_brightness = 0x7f,
+                      .cdev.brightness_set = lm3644_flash1_brightness_set,
+                      .cdev.default_trigger = "flash1",
+                      .func = lm3644_deferred_flash1_brightness_set},
+       [ID_TORCH0] = {
+                      .cdev.name = "torch0",
+                      .cdev.brightness = 0,
+                      .cdev.max_brightness = 0x7f,
+                      .cdev.brightness_set = lm3644_torch0_brightness_set,
+                      .cdev.default_trigger = "torch0",
+                      .func = lm3644_deferred_torch0_brightness_set},
+       [ID_TORCH1] = {
+                      .cdev.name = "torch1",
+                      .cdev.brightness = 0,
+                      .cdev.max_brightness = 0x7f,
+                      .cdev.brightness_set = lm3644_torch1_brightness_set,
+                      .cdev.default_trigger = "torch1",
+                      .func = lm3644_deferred_torch1_brightness_set},
+};
+
+static void lm3644_led_unregister(struct lm3644 *pchip, enum lm3644_devid id)
+{
+       int icnt;
+
+       for (icnt = id; icnt > 0; icnt--)
+               led_classdev_unregister(&pchip->cdev[icnt - 1]);
+}
+
+static int lm3644_led_register(struct lm3644 *pchip)
+{
+       int icnt, rval;
+
+       for (icnt = 0; icnt < ID_MAX; icnt++) {
+               INIT_WORK(&pchip->work[icnt], lm3644_leds[icnt].func);
+               pchip->cdev[icnt].name = lm3644_leds[icnt].cdev.name;
+               pchip->cdev[icnt].max_brightness =
+                   lm3644_leds[icnt].cdev.max_brightness;
+               pchip->cdev[icnt].brightness =
+                   lm3644_leds[icnt].cdev.brightness;
+               pchip->cdev[icnt].brightness_set =
+                   lm3644_leds[icnt].cdev.brightness_set;
+               pchip->cdev[icnt].default_trigger =
+                   lm3644_leds[icnt].cdev.default_trigger;
+               rval = led_classdev_register((struct device *)
+                                            pchip->dev, &pchip->cdev[icnt]);
+               if (rval < 0) {
+                       lm3644_led_unregister(pchip, icnt);
+                       return rval;
+               }
+       }
+       return 0;
+}
+
+/* device files to control registers */
+struct lm3644_commands {
+       char *str;
+       int size;
+};
+
+enum lm3644_cmd_id {
+       CMD_ENABLE = 0,
+       CMD_DISABLE,
+       CMD_ON,
+       CMD_OFF,
+       CMD_IRMODE,
+       CMD_OVERRIDE,
+       CMD_MAX
+};
+
+struct lm3644_commands cmds[CMD_MAX] = {
+       [CMD_ENABLE] = {"enable", 6},
+       [CMD_DISABLE] = {"disable", 7},
+       [CMD_ON] = {"on", 2},
+       [CMD_OFF] = {"off", 3},
+       [CMD_IRMODE] = {"irmode", 6},
+       [CMD_OVERRIDE] = {"override", 8},
+};
+
+struct lm3644_files {
+       enum lm3644_devid id;
+       struct device_attribute attr;
+};
+
+static size_t lm3644_ctrl(struct device *dev,
+                         const char *buf, enum lm3644_devid id,
+                         enum lm3644_devfile dfid, size_t size)
+{
+       struct led_classdev *led_cdev = dev_get_drvdata(dev);
+       struct lm3644 *pchip = to_lm3644(led_cdev, id);
+       enum lm3644_cmd_id icnt;
+       int tout, rval;
+
+       mutex_lock(&pchip->lock);
+       for (icnt = 0; icnt < CMD_MAX; icnt++) {
+               if (strncmp(buf, cmds[icnt].str, cmds[icnt].size) == 0)
+                       break;
+       }
+
+       switch (dfid) {
+               /* led 0 enable */
+       case DFILE_FLASH0_ENABLE:
+       case DFILE_TORCH0_ENABLE:
+               if (icnt == CMD_ENABLE)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x1,
+                                              0x1);
+               else if (icnt == CMD_DISABLE)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x1,
+                                              0x0);
+               break;
+               /* led 1 enable, flash override */
+       case DFILE_FLASH1_ENABLE:
+               if (icnt == CMD_ENABLE) {
+                       rval = regmap_update_bits(pchip->regmap,
+                                                 REG_FLASH_LED0_BR, 0x80, 0x0);
+                       rval |=
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x2,
+                                              0x2);
+               } else if (icnt == CMD_DISABLE) {
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x2,
+                                              0x0);
+               } else if (icnt == CMD_OVERRIDE) {
+                       rval = regmap_update_bits(pchip->regmap,
+                                                 REG_FLASH_LED0_BR, 0x80,
+                                                 0x80);
+                       rval |=
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x2,
+                                              0x2);
+               }
+               break;
+               /* led 1 enable, torch override */
+       case DFILE_TORCH1_ENABLE:
+               if (icnt == CMD_ENABLE) {
+                       rval = regmap_update_bits(pchip->regmap,
+                                                 REG_TORCH_LED0_BR, 0x80, 0x0);
+                       rval |=
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x2,
+                                              0x2);
+               } else if (icnt == CMD_DISABLE) {
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x2,
+                                              0x0);
+               } else if (icnt == CMD_OVERRIDE) {
+                       rval = regmap_update_bits(pchip->regmap,
+                                                 REG_TORCH_LED0_BR, 0x80,
+                                                 0x80);
+                       rval |=
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x2,
+                                              0x2);
+               }
+               break;
+               /* mode control flash/ir */
+       case DFILE_FLASH0_ONOFF:
+       case DFILE_FLASH1_ONOFF:
+               if (icnt == CMD_ON)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0xc,
+                                              0xc);
+               else if (icnt == CMD_OFF)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0xc,
+                                              0x0);
+               else if (icnt == CMD_IRMODE)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0xc,
+                                              0x4);
+               break;
+               /* mode control torch */
+       case DFILE_TORCH0_ONOFF:
+       case DFILE_TORCH1_ONOFF:
+               if (icnt == CMD_ON)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0xc,
+                                              0x8);
+               else if (icnt == CMD_OFF)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0xc,
+                                              0x0);
+               break;
+               /* strobe pin control */
+       case DFILE_FLASH0_SOURCE:
+               if (icnt == CMD_ON)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x20,
+                                              0x20);
+               else if (icnt == CMD_OFF)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x20,
+                                              0x0);
+               break;
+       case DFILE_TORCH0_SOURCE:
+               if (icnt == CMD_ON)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x10,
+                                              0x10);
+               else if (icnt == CMD_OFF)
+                       rval =
+                           regmap_update_bits(pchip->regmap, REG_ENABLE, 0x10,
+                                              0x0);
+               break;
+               /* flash time out */
+       case DFILE_FLASH0_TIMEOUT:
+               rval = kstrtouint((const char *)buf, 10, &tout);
+               if (rval < 0)
+                       break;
+               rval = regmap_update_bits(pchip->regmap,
+                                         REG_FLASH_TOUT, 0x0f, tout);
+               break;
+       default:
+               dev_err(pchip->dev, "error : undefined dev file\n");
+               break;
+       }
+       lm3644_read_flag(pchip);
+       mutex_unlock(&pchip->lock);
+       return size;
+}
+
+/* flash enable control */
+static ssize_t lm3644_flash0_enable_store(struct device *dev,
+                                         struct device_attribute *devAttr,
+                                         const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_FLASH0, DFILE_FLASH0_ENABLE, size);
+}
+
+static ssize_t lm3644_flash1_enable_store(struct device *dev,
+                                         struct device_attribute *devAttr,
+                                         const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_FLASH1, DFILE_FLASH1_ENABLE, size);
+}
+
+/* flash onoff control */
+static ssize_t lm3644_flash0_onoff_store(struct device *dev,
+                                        struct device_attribute *devAttr,
+                                        const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_FLASH0, DFILE_FLASH0_ONOFF, size);
+}
+
+static ssize_t lm3644_flash1_onoff_store(struct device *dev,
+                                        struct device_attribute *devAttr,
+                                        const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_FLASH1, DFILE_FLASH1_ONOFF, size);
+}
+
+/* flash timeout control */
+static ssize_t lm3644_flash0_timeout_store(struct device *dev,
+                                          struct device_attribute *devAttr,
+                                          const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_FLASH0, DFILE_FLASH0_TIMEOUT, size);
+}
+
+/* flash source control */
+static ssize_t lm3644_flash0_source_store(struct device *dev,
+                                         struct device_attribute *devAttr,
+                                         const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_FLASH0, DFILE_FLASH0_SOURCE, size);
+}
+
+/* torch enable control */
+static ssize_t lm3644_torch0_enable_store(struct device *dev,
+                                         struct device_attribute *devAttr,
+                                         const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_FLASH0, DFILE_TORCH0_ENABLE, size);
+}
+
+static ssize_t lm3644_torch1_enable_store(struct device *dev,
+                                         struct device_attribute *devAttr,
+                                         const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_TORCH1, DFILE_TORCH1_ENABLE, size);
+}
+
+/* torch onoff control */
+static ssize_t lm3644_torch0_onoff_store(struct device *dev,
+                                        struct device_attribute *devAttr,
+                                        const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_TORCH0, DFILE_TORCH0_ONOFF, size);
+}
+
+static ssize_t lm3644_torch1_onoff_store(struct device *dev,
+                                        struct device_attribute *devAttr,
+                                        const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_TORCH1, DFILE_TORCH1_ONOFF, size);
+}
+
+/* torch source control */
+static ssize_t lm3644_torch0_source_store(struct device *dev,
+                                         struct device_attribute *devAttr,
+                                         const char *buf, size_t size)
+{
+       return lm3644_ctrl(dev, buf, ID_TORCH0, DFILE_TORCH0_SOURCE, size);
+}
+
+#define lm3644_attr(_name, _show, _store)\
+{\
+       .attr = {\
+               .name = _name,\
+               .mode = 0644,\
+       },\
+       .show = _show,\
+       .store = _store,\
+}
+
+static struct lm3644_files lm3644_devfiles[DFILE_MAX] = {
+       [DFILE_FLASH0_ENABLE] = {
+                                .id = ID_FLASH0,
+                                .attr =
+                                lm3644_attr("enable", NULL,
+                                            lm3644_flash0_enable_store),
+                                },
+       [DFILE_FLASH0_ONOFF] = {
+                               .id = ID_FLASH0,
+                               .attr =
+                               lm3644_attr("onoff", NULL,
+                                           lm3644_flash0_onoff_store),
+                               },
+       [DFILE_FLASH0_SOURCE] = {
+                                .id = ID_FLASH0,
+                                .attr =
+                                lm3644_attr("source", NULL,
+                                            lm3644_flash0_source_store),
+                                },
+       [DFILE_FLASH0_TIMEOUT] = {
+                                 .id = ID_FLASH0,
+                                 .attr =
+                                 lm3644_attr("timeout", NULL,
+                                             lm3644_flash0_timeout_store),
+                                 },
+       [DFILE_FLASH1_ENABLE] = {
+                                .id = ID_FLASH1,
+                                .attr =
+                                lm3644_attr("enable", NULL,
+                                            lm3644_flash1_enable_store),
+                                },
+       [DFILE_FLASH1_ONOFF] = {
+                               .id = ID_FLASH1,
+                               .attr =
+                               lm3644_attr("onoff", NULL,
+                                           lm3644_flash1_onoff_store),
+                               },
+       [DFILE_TORCH0_ENABLE] = {
+                                .id = ID_TORCH0,
+                                .attr =
+                                lm3644_attr("enable", NULL,
+                                            lm3644_torch0_enable_store),
+                                },
+       [DFILE_TORCH0_ONOFF] = {
+                               .id = ID_TORCH0,
+                               .attr =
+                               lm3644_attr("onoff", NULL,
+                                           lm3644_torch0_onoff_store),
+                               },
+       [DFILE_TORCH0_SOURCE] = {
+                                .id = ID_TORCH0,
+                                .attr =
+                                lm3644_attr("source", NULL,
+                                            lm3644_torch0_source_store),
+                                },
+       [DFILE_TORCH1_ENABLE] = {
+                                .id = ID_TORCH1,
+                                .attr =
+                                lm3644_attr("enable", NULL,
+                                            lm3644_torch1_enable_store),
+                                },
+       [DFILE_TORCH1_ONOFF] = {
+                               .id = ID_TORCH1,
+                               .attr =
+                               lm3644_attr("onoff", NULL,
+                                           lm3644_torch1_onoff_store),
+                               }
+};
+
+static void lm3644_df_remove(struct lm3644 *pchip, enum lm3644_devfile dfid)
+{
+       enum lm3644_devfile icnt;
+
+       for (icnt = dfid; icnt > 0; icnt--)
+               device_remove_file(pchip->cdev[lm3644_devfiles[icnt - 1].id].
+                                  dev, &lm3644_devfiles[icnt - 1].attr);
+}
+
+static int lm3644_df_create(struct lm3644 *pchip)
+{
+       enum lm3644_devfile icnt;
+       int rval;
+
+       for (icnt = 0; icnt < DFILE_MAX; icnt++) {
+               rval =
+                   device_create_file(pchip->cdev[lm3644_devfiles[icnt].id].
+                                      dev, &lm3644_devfiles[icnt].attr);
+               if (rval < 0) {
+                       lm3644_df_remove(pchip, icnt);
+                       return rval;
+               }
+       }
+       return 0;
+}
+
+static const struct regmap_config lm3644_regmap = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = 0xff,
+};
+
+static int lm3644_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       struct lm3644 *pchip;
+       int rval;
+
+       /* i2c check */
+       if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+               dev_err(&client->dev, "i2c functionality check fail.\n");
+               return -EOPNOTSUPP;
+       }
+
+       pchip = devm_kzalloc(&client->dev, sizeof(struct lm3644), GFP_KERNEL);
+       if (!pchip)
+               return -ENOMEM;
+
+       pchip->dev = &client->dev;
+       pchip->regmap = devm_regmap_init_i2c(client, &lm3644_regmap);
+       if (IS_ERR(pchip->regmap)) {
+               rval = PTR_ERR(pchip->regmap);
+               dev_err(&client->dev, "Failed to allocate register map: %d\n",
+                       rval);
+               return rval;
+       }
+       mutex_init(&pchip->lock);
+       i2c_set_clientdata(client, pchip);
+
+       /* led class register */
+       rval = lm3644_led_register(pchip);
+       if (rval < 0)
+               return rval;
+
+       /* create dev files */
+       rval = lm3644_df_create(pchip);
+       if (rval < 0) {
+               lm3644_led_unregister(pchip, ID_MAX);
+               return rval;
+       }
+
+       dev_info(pchip->dev, "lm3644 leds initialized\n");
+       return 0;
+}
+
+static int lm3644_remove(struct i2c_client *client)
+{
+       struct lm3644 *pchip = i2c_get_clientdata(client);
+
+       lm3644_df_remove(pchip, DFILE_MAX);
+       lm3644_led_unregister(pchip, ID_MAX);
+
+       return 0;
+}
+
+static const struct i2c_device_id lm3644_id[] = {
+       {LM3644_NAME, 0},
+       {}
+};
+
+MODULE_DEVICE_TABLE(i2c, lm3644_id);
+
+static struct i2c_driver lm3644_i2c_driver = {
+       .driver = {
+                  .name = LM3644_NAME,
+                  .owner = THIS_MODULE,
+                  .pm = NULL,
+                  },
+       .probe = lm3644_probe,
+       .remove = lm3644_remove,
+       .id_table = lm3644_id,
+};
+
+module_i2c_driver(lm3644_i2c_driver);
+
+MODULE_DESCRIPTION("Texas Instruments Flash Lighting driver for LM3644");
+MODULE_AUTHOR("Daniel Jeong <daniel.jeong@ti.com>");
+MODULE_LICENSE("GPL v2");
index f5218581be3c46be834489f699ea83b4423f73c4..f2aac4eedd9d745ccc3a3e37f475a4f82f7dbfbb 100644 (file)
@@ -638,6 +638,14 @@ config VIDEO_LM3643
          This is a driver for the lm3643 dual flash controllers. It controls
          flash, torch and ir modes.
 
+config VIDEO_LM3644
+       tristate "LM3644 dual flash driver support"
+       depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+       depends on MEDIA_CAMERA_SUPPORT
+       select REGMAP_I2C
+       ---help---
+         This is a driver for the lm3644 dual flash controllers. It controls
+         flash, torch and ir modes.
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
index d35fe250797c41e2a86978646261c6505cfa68f7..a73441d568dc0350ae825903efa80fe02c14df1a 100644 (file)
@@ -73,6 +73,7 @@ obj-$(CONFIG_VIDEO_ADP1653)   += adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)    += as3645a.o
 obj-$(CONFIG_VIDEO_LM3560)     += lm3560.o
 obj-$(CONFIG_VIDEO_LM3643)     += lm3643.o
+obj-$(CONFIG_VIDEO_LM3643)     += lm3644.o
 obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o
 obj-$(CONFIG_VIDEO_AK881X)             += ak881x.o
 obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
diff --git a/drivers/media/i2c/lm3644.c b/drivers/media/i2c/lm3644.c
new file mode 100644 (file)
index 0000000..c1e3d2f
--- /dev/null
@@ -0,0 +1,506 @@
+/*
+ * drivers/media/i2c/lm3644.c
+ * General device driver for TI LM3644, FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong <gshark.jeong@gmail.com>
+ *                     Ldd-Mlp <ldd-mlp@list.ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/videodev2.h>
+#include <media/lm3644.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+
+/* registers definitions */
+#define REG_ENABLE             0x01
+#define REG_FLASH_LED0_BR      0x03
+#define REG_FLASH_LED1_BR      0x04
+#define REG_TORCH_LED0_BR      0x05
+#define REG_TORCH_LED1_BR      0x06
+#define REG_FLASH_TOUT         0x08
+#define REG_FLAG0              0x0a
+#define REG_FLAG1              0x0b
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_SHORT_CIRCUIT    (0x70)
+#define FAULT_UVLO             (1<<1)
+#define FAULT_IVFM             (1<<2)
+#define FAULT_OCP              (1<<3)
+#define FAULT_OVERTEMP (1<<2)
+#define FAULT_NTC_TRIP (1<<0)
+#define FAULT_OVP              (1<<1)
+
+#define MASK_MODE      0x0C
+enum led_mode {
+       MODE_SHDN = 0x00,
+       MODE_IR_DRV = 0x04,
+       MODE_TORCH = 0x08,
+       MODE_FLASH = 0x0C,
+};
+
+/*
+ * struct lm3644_flash
+ *
+ * @pdata: platform data
+ * @regmap: reg. map for i2c
+ * @lock: muxtex for serial access.
+ * @led_mode: V4L2 LED mode
+ * @ctrls_led: V4L2 contols
+ * @subdev_led: V4L2 subdev
+ */
+struct lm3644_flash {
+       struct device *dev;
+       struct lm3644_platform_data *pdata;
+       struct regmap *regmap;
+       struct mutex lock;
+
+       struct v4l2_ctrl_handler ctrls_led[LM3644_LED_MAX];
+       struct v4l2_subdev subdev_led[LM3644_LED_MAX];
+       /* caching control register to reduce redundant i2c accesses */
+       u8 enable_reg;
+
+};
+
+#define to_lm3644_flash(_ctrl, _no)    \
+       container_of(_ctrl->handler, struct lm3644_flash, ctrls_led[_no])
+
+/* enable mode control */
+static int lm3644_mode_ctrl(struct lm3644_flash *flash,
+                           enum v4l2_flash_led_mode led_mode)
+{
+       switch (led_mode) {
+       case V4L2_FLASH_LED_MODE_NONE:
+               return regmap_write(flash->regmap,
+                                   REG_ENABLE, flash->enable_reg | MODE_SHDN);
+       case V4L2_FLASH_LED_MODE_IR:
+               return regmap_write(flash->regmap,
+                                   REG_ENABLE,
+                                   flash->enable_reg | MODE_IR_DRV);
+       case V4L2_FLASH_LED_MODE_TORCH:
+               return regmap_write(flash->regmap,
+                                   REG_ENABLE, flash->enable_reg | MODE_TORCH);
+       case V4L2_FLASH_LED_MODE_FLASH:
+               return regmap_write(flash->regmap,
+                                   REG_ENABLE, flash->enable_reg | MODE_FLASH);
+       }
+       return -EINVAL;
+}
+
+/* torch0/1 brightness control */
+static int lm3644_torch_brt_ctrl(struct lm3644_flash *flash,
+                                enum lm3644_led_id led_no, unsigned int brt)
+{
+       int rval;
+       u8 br_bits;
+
+       br_bits = LM3644_TORCH_BRT_uA_TO_REG(brt);
+       if (led_no == LM3644_LED0)
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_TORCH_LED0_BR, 0x7f, br_bits);
+       else
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_TORCH_LED1_BR, 0x7f, br_bits);
+       return rval;
+}
+
+/* flash0/1 brightness control */
+static int lm3644_flash_brt_ctrl(struct lm3644_flash *flash,
+                                enum lm3644_led_id led_no, unsigned int brt)
+{
+       int rval;
+       u8 br_bits;
+
+       br_bits = LM3644_FLASH_BRT_uA_TO_REG(brt);
+       if (led_no == LM3644_LED0)
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_FLASH_LED0_BR, 0x7f, br_bits);
+       else
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_FLASH_LED1_BR, 0x7f, br_bits);
+       return rval;
+}
+
+static int lm3644_get_ctrl(struct v4l2_ctrl *ctrl, enum lm3644_led_id led_no)
+{
+       struct lm3644_flash *flash = to_lm3644_flash(ctrl, led_no);
+       int rval = -EINVAL;
+
+       mutex_lock(&flash->lock);
+
+       if (ctrl->id == V4L2_CID_FLASH_FAULT) {
+               unsigned int reg_val;
+
+               rval = regmap_read(flash->regmap, REG_FLAG0, &reg_val);
+               if (rval < 0)
+                       goto out;
+               ctrl->val = 0;
+               if (reg_val & FAULT_TIMEOUT)
+                       ctrl->val |= V4L2_FLASH_FAULT_TIMEOUT;
+               if (reg_val & FAULT_UVLO)
+                       ctrl->val |= V4L2_FLASH_FAULT_UNDER_VOLTAGE;
+               if (reg_val & FAULT_OVERTEMP)
+                       ctrl->val |= V4L2_FLASH_FAULT_OVER_TEMPERATURE;
+               if (reg_val & FAULT_OCP)
+                       ctrl->val |= V4L2_FLASH_FAULT_OVER_CURRENT;
+               if (reg_val & FAULT_SHORT_CIRCUIT)
+                       ctrl->val |= V4L2_FLASH_FAULT_SHORT_CIRCUIT;
+
+               rval = regmap_read(flash->regmap, REG_FLAG1, &reg_val);
+               if (rval < 0)
+                       goto out;
+               if (reg_val & FAULT_IVFM)
+                       ctrl->val |= V4L2_FLASH_FAULT_INPUT_VOLTAGE;
+               if (reg_val & FAULT_NTC_TRIP)
+                       ctrl->val |= V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE;
+               if (reg_val & FAULT_OVP)
+                       ctrl->val |= V4L2_FLASH_FAULT_OVER_VOLTAGE;
+       }
+
+out:
+       mutex_unlock(&flash->lock);
+       return rval;
+}
+
+static int lm3644_set_ctrl(struct v4l2_ctrl *ctrl, enum lm3644_led_id led_no)
+{
+       struct lm3644_flash *flash = to_lm3644_flash(ctrl, led_no);
+       u8 tout_bits;
+       int rval = -EINVAL;
+       unsigned int reg_val;
+
+       mutex_lock(&flash->lock);
+
+       switch (ctrl->id) {
+       case V4L2_CID_FLASH_LED_MODE:
+               if (ctrl->val != V4L2_FLASH_LED_MODE_FLASH) {
+                       rval = lm3644_mode_ctrl(flash, ctrl->val);
+                       break;
+               }
+               /* switch to SHDN mode before flash strobe on */
+               rval = lm3644_mode_ctrl(flash, V4L2_FLASH_LED_MODE_NONE);
+               break;
+
+       case V4L2_CID_FLASH_STROBE_SOURCE:
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_ENABLE, 0x20, (ctrl->val) << 6);
+               if (rval < 0)
+                       goto err_out;
+               rval = regmap_read(flash->regmap, REG_ENABLE, &reg_val);
+               if (rval < 0)
+                       goto err_out;
+               flash->enable_reg = reg_val & (~MASK_MODE);
+               break;
+
+       case V4L2_CID_FLASH_STROBE:
+
+               /* read and check current mode of chip to start flash */
+               rval = regmap_read(flash->regmap, REG_ENABLE, &reg_val);
+               if (rval < 0 || ((reg_val & MASK_MODE) != MODE_SHDN))
+                       goto err_out;
+               /* flash on */
+               rval = lm3644_mode_ctrl(flash, V4L2_FLASH_LED_MODE_FLASH);
+               break;
+
+       case V4L2_CID_FLASH_STROBE_STOP:
+               /*
+                * flash mode will be turned automatically
+                * from FLASH mode to SHDN mode after flash duration timeout
+                * read and check current mode of chip to stop flash
+                */
+               rval = regmap_read(flash->regmap, REG_ENABLE, &reg_val);
+               if (rval < 0)
+                       goto err_out;
+               if ((reg_val & MASK_MODE) == MODE_FLASH)
+                       rval = lm3644_mode_ctrl(flash,
+                                               V4L2_FLASH_LED_MODE_NONE);
+               break;
+
+       case V4L2_CID_FLASH_TIMEOUT:
+               tout_bits = LM3644_FLASH_TOUT_ms_TO_REG(ctrl->val);
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_FLASH_TOUT, 0x0f, tout_bits);
+               break;
+
+       case V4L2_CID_FLASH_INTENSITY:
+               rval = lm3644_flash_brt_ctrl(flash, led_no, ctrl->val);
+               break;
+
+       case V4L2_CID_FLASH_TORCH_INTENSITY:
+               rval = lm3644_torch_brt_ctrl(flash, led_no, ctrl->val);
+               break;
+       }
+
+err_out:
+       mutex_unlock(&flash->lock);
+       return rval;
+}
+
+static int lm3644_led1_get_ctrl(struct v4l2_ctrl *ctrl)
+{
+       return lm3644_get_ctrl(ctrl, LM3644_LED1);
+}
+
+static int lm3644_led1_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+       return lm3644_set_ctrl(ctrl, LM3644_LED1);
+}
+
+static int lm3644_led0_get_ctrl(struct v4l2_ctrl *ctrl)
+{
+       return lm3644_get_ctrl(ctrl, LM3644_LED0);
+}
+
+static int lm3644_led0_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+       return lm3644_set_ctrl(ctrl, LM3644_LED0);
+}
+
+static const struct v4l2_ctrl_ops lm3644_led_ctrl_ops[LM3644_LED_MAX] = {
+       [LM3644_LED0] = {
+                        .g_volatile_ctrl = lm3644_led0_get_ctrl,
+                        .s_ctrl = lm3644_led0_set_ctrl,
+                        },
+       [LM3644_LED1] = {
+                        .g_volatile_ctrl = lm3644_led1_get_ctrl,
+                        .s_ctrl = lm3644_led1_set_ctrl,
+                        }
+};
+
+static int lm3644_init_controls(struct lm3644_flash *flash,
+                               enum lm3644_led_id led_no)
+{
+       struct v4l2_ctrl *fault;
+       struct v4l2_ctrl_handler *hdl = &flash->ctrls_led[led_no];
+       const struct v4l2_ctrl_ops *ops = &lm3644_led_ctrl_ops[led_no];
+
+       v4l2_ctrl_handler_init(hdl, 8);
+
+       /* flash mode */
+       v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_FLASH_LED_MODE,
+                              V4L2_FLASH_LED_MODE_IR, ~0x7,
+                              V4L2_FLASH_LED_MODE_NONE);
+
+       /* flash source */
+       v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_FLASH_STROBE_SOURCE,
+                              0x1, ~0x3, V4L2_FLASH_STROBE_SOURCE_SOFTWARE);
+
+       /* flash strobe */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_STROBE, 0, 0, 0, 0);
+
+       /* flash strobe stop */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_STROBE_STOP, 0, 0, 0, 0);
+
+       /* flash strobe timeout */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_TIMEOUT,
+                         LM3644_FLASH_TOUT_MIN,
+                         LM3644_FLASH_TOUT_MAX,
+                         LM3644_FLASH_TOUT_LOW_STEP, LM3644_FLASH_TOUT_MAX);
+
+       /* flash brt */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_INTENSITY,
+                         LM3644_FLASH_BRT_MIN, LM3644_FLASH_BRT_MAX,
+                         LM3644_FLASH_BRT_STEP, LM3644_FLASH_BRT_MAX);
+
+       /* torch brt */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_TORCH_INTENSITY,
+                         LM3644_TORCH_BRT_MIN, LM3644_TORCH_BRT_MAX,
+                         LM3644_TORCH_BRT_STEP, LM3644_TORCH_BRT_MAX);
+
+       /* fault */
+       fault = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_FAULT, 0,
+                                 V4L2_FLASH_FAULT_TIMEOUT
+                                 | V4L2_FLASH_FAULT_SHORT_CIRCUIT
+                                 | V4L2_FLASH_FAULT_UNDER_VOLTAGE
+                                 | V4L2_FLASH_FAULT_INPUT_VOLTAGE
+                                 | V4L2_FLASH_FAULT_OVER_CURRENT
+                                 | V4L2_FLASH_FAULT_OVER_TEMPERATURE
+                                 | V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE
+                                 | V4L2_FLASH_FAULT_OVER_VOLTAGE, 0, 0);
+       if (fault != NULL)
+               fault->flags |= V4L2_CTRL_FLAG_VOLATILE;
+
+       if (hdl->error)
+               return hdl->error;
+
+       flash->subdev_led[led_no].ctrl_handler = hdl;
+       return 0;
+}
+
+/* initialize device */
+static const struct v4l2_subdev_ops lm3644_ops = {
+       .core = NULL,
+};
+
+static const struct regmap_config lm3644_regmap = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = 0xFF,
+};
+
+static int lm3644_subdev_init(struct lm3644_flash *flash,
+                             enum lm3644_led_id led_no, char *led_name)
+{
+       struct i2c_client *client = to_i2c_client(flash->dev);
+       int rval;
+
+       v4l2_i2c_subdev_init(&flash->subdev_led[led_no], client, &lm3644_ops);
+       flash->subdev_led[led_no].flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+       strcpy(flash->subdev_led[led_no].name, led_name);
+       rval = lm3644_init_controls(flash, led_no);
+       if (rval)
+               goto err_out;
+       rval = media_entity_init(&flash->subdev_led[led_no].entity, 0, NULL, 0);
+       if (rval < 0)
+               goto err_out;
+       flash->subdev_led[led_no].entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH;
+
+       return rval;
+
+err_out:
+       v4l2_ctrl_handler_free(&flash->ctrls_led[led_no]);
+       return rval;
+}
+
+static int lm3644_init_device(struct lm3644_flash *flash)
+{
+       struct lm3644_platform_data *pdata = flash->pdata;
+       int rval;
+       unsigned int reg_val;
+
+       rval = regmap_read(flash->regmap, REG_ENABLE, &reg_val);
+       if (rval < 0)
+               return rval;
+       /* set led0/1 enable bits */
+       reg_val |= flash->pdata->led0_enable;
+       reg_val |= flash->pdata->led1_enable;
+       /* save enable register to reduce redundant i2c accesses */
+       flash->enable_reg = reg_val & 0xf3;
+
+       rval = regmap_write(flash->regmap, REG_ENABLE, reg_val);
+       if (rval < 0)
+               return rval;
+
+       /* set output mode */
+       rval = lm3644_mode_ctrl(flash, V4L2_FLASH_LED_MODE_NONE);
+       if (rval < 0)
+               return rval;
+
+       /* set override */
+       rval = regmap_update_bits(flash->regmap,
+                 REG_FLASH_LED0_BR, 0x80, pdata->flash1_override);
+       rval |= regmap_update_bits(flash->regmap,
+                 REG_TORCH_LED0_BR, 0x80, pdata->torch1_override);
+       if (rval < 0)
+               return rval;
+
+       /* Reset flag 0 register */
+       rval = regmap_read(flash->regmap, REG_FLAG0, &reg_val);
+       if (rval < 0)
+               return rval;
+
+       /* Reset flag 1 register */
+       return regmap_read(flash->regmap, REG_FLAG1, &reg_val);
+
+}
+
+static int lm3644_probe(struct i2c_client *client,
+                       const struct i2c_device_id *devid)
+{
+       struct lm3644_flash *flash;
+       struct lm3644_platform_data *pdata = dev_get_platdata(&client->dev);
+       int rval;
+
+       flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL);
+       if (flash == NULL)
+               return -ENOMEM;
+
+       flash->regmap = devm_regmap_init_i2c(client, &lm3644_regmap);
+       if (IS_ERR(flash->regmap))
+               return PTR_ERR(flash->regmap);
+
+       /* if there is no platform data, use chip default value */
+       if (pdata == NULL) {
+               pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
+               if (pdata == NULL)
+                       return -ENODEV;
+               pdata->led0_enable = 0x01;
+               pdata->led1_enable = 0x01 << 1;
+               pdata->flash1_override = 0x01 << 7;
+               pdata->torch1_override = 0x01 << 7;
+       }
+       flash->pdata = pdata;
+       flash->dev = &client->dev;
+       mutex_init(&flash->lock);
+
+       rval = lm3644_subdev_init(flash, LM3644_LED0, "lm3644-led0");
+       if (rval < 0)
+               return rval;
+
+       rval = lm3644_subdev_init(flash, LM3644_LED1, "lm3644-led1");
+       if (rval < 0)
+               return rval;
+
+       rval = lm3644_init_device(flash);
+       if (rval < 0)
+               return rval;
+
+       i2c_set_clientdata(client, flash);
+
+       return 0;
+}
+
+static int lm3644_remove(struct i2c_client *client)
+{
+       struct lm3644_flash *flash = i2c_get_clientdata(client);
+       unsigned int i;
+
+       for (i = LM3644_LED0; i < LM3644_LED_MAX; i++) {
+               v4l2_device_unregister_subdev(&flash->subdev_led[i]);
+               v4l2_ctrl_handler_free(&flash->ctrls_led[i]);
+               media_entity_cleanup(&flash->subdev_led[i].entity);
+       }
+
+       return 0;
+}
+
+static const struct i2c_device_id lm3644_id_table[] = {
+       {LM3644_NAME, 0},
+       {}
+};
+
+MODULE_DEVICE_TABLE(i2c, lm3644_id_table);
+
+static struct i2c_driver lm3644_i2c_driver = {
+       .driver = {
+                  .name = LM3644_NAME,
+                  .pm = NULL,
+                  },
+       .probe = lm3644_probe,
+       .remove = lm3644_remove,
+       .id_table = lm3644_id_table,
+};
+
+module_i2c_driver(lm3644_i2c_driver);
+
+MODULE_AUTHOR("Daniel Jeong <gshark.jeong@gmail.com>");
+MODULE_AUTHOR("Ldd Mlp <ldd-mlp@list.ti.com>");
+MODULE_DESCRIPTION("Texas Instruments LM3644 LED flash driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/platform_data/leds-lm3644.h b/include/linux/platform_data/leds-lm3644.h
new file mode 100644 (file)
index 0000000..d9063bf
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Simple driver for Texas Instruments LM3644 LED Flash driver chip
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef __LM3644_H
+#define __LM3644_H
+
+#define LM3644_NAME "leds-lm3644"
+#define LM3644_ADDR 0x63
+
+#endif /* __LM3644_H */
diff --git a/include/media/lm3644.h b/include/media/lm3644.h
new file mode 100644 (file)
index 0000000..f105b74
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * include/media/lm3644.h
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong <gshark.jeong@gmail.com>
+ *                     Ldd-Mlp <ldd-mlp@list.ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#ifndef __LM3644_H__
+#define __LM3644_H__
+
+#include <media/v4l2-subdev.h>
+
+#define LM3644_NAME    "lm3644"
+#define LM3644_I2C_ADDR        (0x63)
+
+/*  FLASH Brightness
+ *     min 11310uA, step 11720uA, max 1500000uA
+ */
+#define LM3644_FLASH_BRT_MIN   11310
+#define LM3644_FLASH_BRT_STEP  11720
+#define LM3644_FLASH_BRT_MAX   1500000
+#define LM3644_FLASH_BRT_uA_TO_REG(a)  \
+       ((a) < LM3644_FLASH_BRT_MIN ? 0 :       \
+        (((a) - LM3644_FLASH_BRT_MIN) / LM3644_FLASH_BRT_STEP))
+
+/*  TORCH BRT
+ *     min 1060uA, step 1460uA, max 187000uA
+ */
+#define LM3644_TORCH_BRT_MIN 1060
+#define LM3644_TORCH_BRT_STEP 1460
+#define LM3644_TORCH_BRT_MAX 187000
+#define LM3644_TORCH_BRT_uA_TO_REG(a)  \
+       ((a) < LM3644_TORCH_BRT_MIN ? 0 :       \
+        (((a) - LM3644_TORCH_BRT_MIN) / LM3644_TORCH_BRT_STEP))
+
+/*  FLASH TIMEOUT DURATION
+ *     min 10ms, max 400ms
+ *  step 10ms in range from  10ms to 100ms
+ *  setp 50ms in range from 100ms to 400ms
+ */
+#define LM3644_FLASH_TOUT_MIN          10
+#define LM3644_FLASH_TOUT_LOW_STEP     10
+#define LM3644_FLASH_TOUT_LOW_MAX      100
+#define LM3644_FLASH_TOUT_HIGH_STEP    50
+#define LM3644_FLASH_TOUT_MAX          400
+#define LM3644_FLASH_TOUT_ms_TO_REG(a) \
+       ((a) < LM3644_FLASH_TOUT_MIN ? 0 :      \
+        ((a) <= LM3644_FLASH_TOUT_LOW_MAX ?    \
+         (((a) - LM3644_FLASH_TOUT_MIN) / LM3644_FLASH_TOUT_LOW_STEP) :        \
+          ((((a) - LM3644_FLASH_TOUT_LOW_MAX) / LM3644_FLASH_TOUT_HIGH_STEP)   \
+               +((LM3644_FLASH_TOUT_LOW_MAX - LM3644_FLASH_TOUT_MIN)   \
+               / LM3644_FLASH_TOUT_LOW_STEP))))
+
+enum lm3644_led_id {
+       LM3644_LED0 = 0,
+       LM3644_LED1,
+       LM3644_LED_MAX
+};
+
+/*
+ * struct lm3644_platform_data
+ * @led0_enable : led0 enable
+ * @led1_enable : led1 enable
+ * @flash1_override : led1 flash current override
+ * @torch1_override : led1 torch current override
+ */
+struct lm3644_platform_data {
+
+       u8 led0_enable;
+       u8 led1_enable;
+       u8 flash1_override;
+       u8 torch1_override;
+};
+
+#endif /* __LM3644_H__ */