Re: [PATCH] media: i2c: add new driver for single string flash.

2015-01-20 Thread Daniel Jeong

Hi.

On Mon, 2015-01-19 at 17:25 +0900, Daniel Jeong wrote:

This patch adds the driver for the single string flash products of TI.
Several single string flash controllers of TI have similar register map
and bit data. This driver supports four products,lm3556, lm3561, lm3642
and lm3648.

Why not to name it as lm3648 to be in align with other drivers?

I tried to match it with the above line. I will fix it.


Or even better solution (I suppose) to create a "library" and on top of
that one driver per each device?

Sakari, what do you think?

Sakrai, I'd like to keep it but please let me know your opinion.

Signed-off-by: Daniel Jeong 
---
  drivers/media/i2c/Kconfig   |9 +
  drivers/media/i2c/Makefile  |1 +
  drivers/media/i2c/ti-ss-flash.c |  744 +++
  include/media/ti-ss-flash.h |   33 ++
  4 files changed, 787 insertions(+)
  create mode 100644 drivers/media/i2c/ti-ss-flash.c
  create mode 100644 include/media/ti-ss-flash.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 205d713..886c1fb 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -638,6 +638,15 @@ config VIDEO_LM3646
  This is a driver for the lm3646 dual flash controllers. It controls
  flash, torch LEDs.
  
+config VIDEO_TI_SS_FLASH

+   tristate "TI Single String 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 signle string flash controllers of TI.
+ It supports LM3556, LM3561, LM3642 and LM3648.
+
  comment "Video improvement chips"
  
  config VIDEO_UPD64031A

diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 98589001..0e523ec 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -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_LM3646)+= lm3646.o
+obj-$(CONFIG_VIDEO_TI_SS_FLASH)+= ti-ss-flash.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/ti-ss-flash.c b/drivers/media/i2c/ti-ss-flash.c
new file mode 100644
index 000..035aeba
--- /dev/null
+++ b/drivers/media/i2c/ti-ss-flash.c
@@ -0,0 +1,744 @@
+/*
+ * drivers/media/i2c/ti-ss-flash.c
+ * General device driver for Single String FLASH LED Drivers of TI
+ * It covers lm3556, lm3561, lm3642 and lm3648.
+ *
+ * Copyright (C) 2015 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* operation mode */
+enum led_opmode {
+   OPMODE_SHDN = 0x0,
+   OPMODE_INDI_IR,
+   OPMODE_TORCH,
+   OPMODE_FLASH,
+};
+
+/*
+ * register data
+ * @reg : register
+ * @mask : mask bits
+ * @shift : bit shift of data
+ */
+struct ctrl_reg {
+   unsigned int reg;
+   unsigned int mask;
+   unsigned int shift;
+};
+
+/*
+ * unit data
+ * @min : min value of brightness or timeout
+ *brightness : uA
+ *   timeout: ms
+ * @step : step value of brightness or timeout
+ *brightness : uA
+ *   timeout: ms
+ * @knee: knee point of step of brightness/timeout
+ *brightness : uA
+ *   timeout: ms
+ * @knee_step : step value of brightness or timeout after knee point
+ *brightness : uA
+ *   timeout: ms
+ * @max : max value of brightness or timeout
+ *brightness : uA
+ *   timeout: ms
+ * @ctrl : register info to control brightness or timeout
+ */
+struct ssflash_config {
+   unsigned int min;
+   unsigned int step;
+   unsigned int knee;
+   unsigned int knee_step;
+   unsigned int max;
+   struct ctrl_reg ctrl;
+};
+
+/*
+ * @reg : fault register
+ * @mask : fault mask bit
+ * @v4l2_fault : bit mapping to V4L2_FLASH_FAULT_
+ *   refer to include//uapi/linux/v4l2-controls.h
+ */
+struct ssflash_fault {
+   unsigned int reg;
+   unsigned int mask;
+   unsigned int v4l2_fault;
+};
+
+#define NUM_V4L2_FAULT 9
+
+/*
+ * ssflash data
+ * @name: device name
+ * @mode: operation mode control data
+ * @flash_br: flash brightness register and bit data
+ * @timeout: timeout control data
+ * @strobe: strobe control data
+ * @torch_br: torch brightness register and bit data
+ * @fault: fault data
+ * @func: initialize function
+ */
+struct ssflash_data

[PATCH] media: i2c: add new driver for single string flash.

2015-01-19 Thread Daniel Jeong
This patch adds the driver for the single string flash products of TI.
Several single string flash controllers of TI have similar register map
and bit data. This driver supports four products,lm3556, lm3561, lm3642
and lm3648.

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig   |9 +
 drivers/media/i2c/Makefile  |1 +
 drivers/media/i2c/ti-ss-flash.c |  744 +++
 include/media/ti-ss-flash.h |   33 ++
 4 files changed, 787 insertions(+)
 create mode 100644 drivers/media/i2c/ti-ss-flash.c
 create mode 100644 include/media/ti-ss-flash.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 205d713..886c1fb 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -638,6 +638,15 @@ config VIDEO_LM3646
  This is a driver for the lm3646 dual flash controllers. It controls
  flash, torch LEDs.
 
+config VIDEO_TI_SS_FLASH
+   tristate "TI Single String 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 signle string flash controllers of TI.
+ It supports LM3556, LM3561, LM3642 and LM3648.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 98589001..0e523ec 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -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_LM3646) += lm3646.o
+obj-$(CONFIG_VIDEO_TI_SS_FLASH)+= ti-ss-flash.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/ti-ss-flash.c b/drivers/media/i2c/ti-ss-flash.c
new file mode 100644
index 000..035aeba
--- /dev/null
+++ b/drivers/media/i2c/ti-ss-flash.c
@@ -0,0 +1,744 @@
+/*
+ * drivers/media/i2c/ti-ss-flash.c
+ * General device driver for Single String FLASH LED Drivers of TI
+ * It covers lm3556, lm3561, lm3642 and lm3648.
+ *
+ * Copyright (C) 2015 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* operation mode */
+enum led_opmode {
+   OPMODE_SHDN = 0x0,
+   OPMODE_INDI_IR,
+   OPMODE_TORCH,
+   OPMODE_FLASH,
+};
+
+/*
+ * register data
+ * @reg : register
+ * @mask : mask bits
+ * @shift : bit shift of data
+ */
+struct ctrl_reg {
+   unsigned int reg;
+   unsigned int mask;
+   unsigned int shift;
+};
+
+/*
+ * unit data
+ * @min : min value of brightness or timeout
+ *brightness : uA
+ *   timeout: ms
+ * @step : step value of brightness or timeout
+ *brightness : uA
+ *   timeout: ms
+ * @knee: knee point of step of brightness/timeout
+ *brightness : uA
+ *   timeout: ms
+ * @knee_step : step value of brightness or timeout after knee point
+ *brightness : uA
+ *   timeout: ms
+ * @max : max value of brightness or timeout
+ *brightness : uA
+ *   timeout: ms
+ * @ctrl : register info to control brightness or timeout
+ */
+struct ssflash_config {
+   unsigned int min;
+   unsigned int step;
+   unsigned int knee;
+   unsigned int knee_step;
+   unsigned int max;
+   struct ctrl_reg ctrl;
+};
+
+/*
+ * @reg : fault register
+ * @mask : fault mask bit
+ * @v4l2_fault : bit mapping to V4L2_FLASH_FAULT_
+ *   refer to include//uapi/linux/v4l2-controls.h
+ */
+struct ssflash_fault {
+   unsigned int reg;
+   unsigned int mask;
+   unsigned int v4l2_fault;
+};
+
+#define NUM_V4L2_FAULT 9
+
+/*
+ * ssflash data
+ * @name: device name
+ * @mode: operation mode control data
+ * @flash_br: flash brightness register and bit data
+ * @timeout: timeout control data
+ * @strobe: strobe control data
+ * @torch_br: torch brightness register and bit data
+ * @fault: fault data
+ * @func: initialize function
+ */
+struct ssflash_data {
+   char *name;
+   struct ctrl_reg mode;
+   struct ssflash_config flash_br;
+   struct ssflash_config timeout;
+   struct ctrl_reg strobe;
+
+   struct ssflash_config torch_br;
+   struct ssflash_fault fault[NUM_V4L2_FAULT];
+
+   int (*func)(struct regmap *regmap);
+};
+
+/*
+ * struct ssflash_flash
+ * @dev: device
+ * @regmap: reg map for interface
+ * @ctrls_led: V4L2 contols
+ * @subd

Re: [PATCH 28/46] [media] lm3560: simplify boolean tests

2014-09-04 Thread Daniel Jeong

Hi.


On Wed, Sep 03, 2014 at 05:33:00PM -0300, Mauro Carvalho Chehab wrote:

Instead of using if (on == true), just use
if (on).

That allows a faster mental parsing when analyzing the
code.

Signed-off-by: Mauro Carvalho Chehab 

Acked-by: Sakari Ailus 


I will keep it in my mind for my next patch files.

Thank you.

Acked-by: Daniel Jeong 

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v7 0/3] add new Dual LED FLASH LM3646

2014-03-03 Thread Daniel Jeong
 This patch is to add new dual led flash, lm3646.
 LM3646 is the product of ti and it has two 1.5A sync. boost 
 converter with dual white current source.
 2 files are created and 4 files are modified.
 And 3 patch files are created and sent.

 v7 - change log
   Changed V4L2_FLASH_FAULT_UNDER_VOLTAGE description in DocBook.
   Changed lm3646_get_ctrl

 v6 - change log
   Changed description in DocBook.

 v5 - change log
   Added control register caching to avoid redundant i2c access.
   Removed dt to create a seperate patch.
   Changed description in DocBook.

Daniel Jeong (3):
  [RFC] v4l2-controls.h:
  [RFC] DocBook:Media:v4l:controls.xml
  [RFC] media: i2c: add new dual LED Flash driver, lm3646

 Documentation/DocBook/media/v4l/controls.xml |   18 ++
 drivers/media/i2c/Kconfig|9 +
 drivers/media/i2c/Makefile   |1 +
 drivers/media/i2c/lm3646.c   |  414 ++
 include/media/lm3646.h   |   87 ++
 include/uapi/linux/v4l2-controls.h   |3 +
 6 files changed, 532 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v7,2/3] controls.xml : add addtional Flash fault bits

2014-03-03 Thread Daniel Jeong
Descriptions for flash faluts.
 V4L2_FLASH_FAULT_UNDER_VOLTAGE,
 V4L2_FLASH_FAULT_INPUT_VOLTAGE,
 and V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE

v7 : Changed V4L2_FLASH_FAULT_UNDER_VOLTAGE description

Signed-off-by: Daniel Jeong 
---
 Documentation/DocBook/media/v4l/controls.xml |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index a5a3188..569861f 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4370,6 +4370,24 @@ interface and may change in the future.
  The flash controller has detected a short or open
  circuit condition on the indicator LED.

+   
+ 
V4L2_FLASH_FAULT_UNDER_VOLTAGE
+ Flash controller voltage to the flash LED
+ has been below the minimum limit specific to the flash
+ controller.
+   
+   
+ 
V4L2_FLASH_FAULT_INPUT_VOLTAGE
+ The input voltage of the flash controller is below
+ the limit under which strobing the flash at full current
+ will not be possible.The condition persists until this flag
+ is no longer set.
+   
+   
+ 
V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE
+ The temperature of the LED has exceeded its
+ allowed upper limit.
+   
  

  
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v7 1/3] v4l2-controls.h: add addtional Flash fault bits

2014-03-03 Thread Daniel Jeong
 Three Flash fault are added.
 V4L2_FLASH_FAULT_UNDER_VOLTAGE for the case low voltage below the min. limit.
 V4L2_FLASH_FAULT_INPUT_VOLTAGE for the case falling input voltage and chip  
 adjust flash current not occur under voltage event.
 V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE for the case the temperature exceed
 the maximun limit

Signed-off-by: Daniel Jeong 
---
 include/uapi/linux/v4l2-controls.h |3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 2cbe605..1d662f6 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -812,6 +812,9 @@ enum v4l2_flash_strobe_source {
 #define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3)
 #define V4L2_FLASH_FAULT_OVER_CURRENT  (1 << 4)
 #define V4L2_FLASH_FAULT_INDICATOR (1 << 5)
+#define V4L2_FLASH_FAULT_UNDER_VOLTAGE (1 << 6)
+#define V4L2_FLASH_FAULT_INPUT_VOLTAGE (1 << 7)
+#define V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE  (1 << 8)
 
 #define V4L2_CID_FLASH_CHARGE  (V4L2_CID_FLASH_CLASS_BASE + 11)
 #define V4L2_CID_FLASH_READY   (V4L2_CID_FLASH_CLASS_BASE + 12)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v7,3/3] media: i2c: add new dual LED Flash driver, lm364

2014-03-03 Thread Daniel Jeong
 This patch adds the driver for the LM3646, dual LED Flash driver.
The LM3646 has two 1.5A sync. boost converter with dual white current source.
It is controlled via an I2C compatible interface.
Each flash brightness, torch brightness and enable/disable can be controlled.
Under voltage, input voltage monitor and thermal threshhold Faults are added.
Please refer the datasheet http://www.ti.com/lit/ds/snvs962/snvs962.pdf

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3646.c |  414 
 include/media/lm3646.h |   87 ++
 4 files changed, 511 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 4aa9c53..c7f2823 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -629,6 +629,15 @@ config VIDEO_LM3560
  This is a driver for the lm3560 dual flash controllers. It controls
  flash, torch LEDs.
 
+config VIDEO_LM3646
+   tristate "LM3646 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 lm3646 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 4ae..01b6bfc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_VIDEO_S5C73M3)   += s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
 obj-$(CONFIG_VIDEO_LM3560) += lm3560.o
+obj-$(CONFIG_VIDEO_LM3646) += lm3646.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/lm3646.c b/drivers/media/i2c/lm3646.c
new file mode 100644
index 000..626fb46
--- /dev/null
+++ b/drivers/media/i2c/lm3646.c
@@ -0,0 +1,414 @@
+/*
+ * drivers/media/i2c/lm3646.c
+ * General device driver for TI lm3646, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x01
+#define REG_TORCH_BR   0x05
+#define REG_FLASH_BR   0x05
+#define REG_FLASH_TOUT 0x04
+#define REG_FLAG   0x08
+#define REG_STROBE_SRC 0x06
+#define REG_LED1_FLASH_BR 0x06
+#define REG_LED1_TORCH_BR 0x07
+
+#define MASK_ENABLE0x03
+#define MASK_TORCH_BR  0x70
+#define MASK_FLASH_BR  0x0F
+#define MASK_FLASH_TOUT0x07
+#define MASK_FLAG  0xFF
+#define MASK_STROBE_SRC0x80
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_SHORT_CIRCUIT(1<<1)
+#define FAULT_UVLO (1<<2)
+#define FAULT_IVFM (1<<3)
+#define FAULT_OCP  (1<<4)
+#define FAULT_OVERTEMP (1<<5)
+#define FAULT_NTC_TRIP (1<<6)
+#define FAULT_OVP  (1<<7)
+
+enum led_mode {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/*
+ * struct lm3646_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
+ * @mode_reg : mode register value
+ */
+struct lm3646_flash {
+   struct device *dev;
+   struct lm3646_platform_data *pdata;
+   struct regmap *regmap;
+
+   struct v4l2_ctrl_handler ctrls_led;
+   struct v4l2_subdev subdev_led;
+
+   u8 mode_reg;
+};
+
+#define to_lm3646_flash(_ctrl) \
+   container_of(_ctrl->handler, struct lm3646_flash, ctrls_led)
+
+/* enable mode control */
+static int lm3646_mode_ctrl(struct lm3646_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->mode_reg | MODE_SHDN);
+   case V4L2_FLASH_LED_MODE_TORCH:
+   return regmap_write(flash->regmap,
+   REG_ENABLE, flash->mode_reg | MODE_TORCH);
+   case V4L2_FLASH_LED_MODE_FLASH:
+   return regmap_write(flash->regmap,
+   REG_ENABLE, flash->mode_reg | MOD

Re: [RFC v6,3/3] media: i2c: add new dual LED Flash driver, lm364

2014-03-03 Thread Daniel Jeong

2014년 02월 26일 21:56, Sakari Ailus 쓴 글:

Hi Daniel,

Just a few minor comments.

On Wed, Feb 26, 2014 at 04:04:11PM +0900, Daniel Jeong wrote:

  This patch adds the driver for the LM3646, dual LED Flash driver.
The LM3646 has two 1.5A sync. boost converter with dual white current source.
It is controlled via an I2C compatible interface.
Each flash brightness, torch brightness and enable/disable can be controlled.
Under voltage, input voltage monitor and thermal threshhold Faults are added.
Please refer the datasheet http://www.ti.com/lit/ds/snvs962/snvs962.pdf

Signed-off-by: Daniel Jeong 
---
  drivers/media/i2c/Kconfig  |9 +
  drivers/media/i2c/Makefile |1 +
  drivers/media/i2c/lm3646.c |  419 
  include/media/lm3646.h |   87 +
  4 files changed, 516 insertions(+)
  create mode 100644 drivers/media/i2c/lm3646.c
  create mode 100644 include/media/lm3646.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 4aa9c53..c7f2823 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -629,6 +629,15 @@ config VIDEO_LM3560
  This is a driver for the lm3560 dual flash controllers. It controls
  flash, torch LEDs.
  
+config VIDEO_LM3646

+   tristate "LM3646 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 lm3646 dual flash controllers. It controls
+ flash, torch LEDs.
+
  comment "Video improvement chips"
  
  config VIDEO_UPD64031A

diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 4ae..01b6bfc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_VIDEO_S5C73M3)   += s5c73m3/
  obj-$(CONFIG_VIDEO_ADP1653)   += adp1653.o
  obj-$(CONFIG_VIDEO_AS3645A)   += as3645a.o
  obj-$(CONFIG_VIDEO_LM3560)+= lm3560.o
+obj-$(CONFIG_VIDEO_LM3646) += lm3646.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/lm3646.c b/drivers/media/i2c/lm3646.c
new file mode 100644
index 000..97d79a7
--- /dev/null
+++ b/drivers/media/i2c/lm3646.c
@@ -0,0 +1,419 @@
+/*
+ * drivers/media/i2c/lm3646.c
+ * General device driver for TI lm3646, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 

Alphabetical order.


+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x01
+#define REG_TORCH_BR   0x05
+#define REG_FLASH_BR   0x05
+#define REG_FLASH_TOUT 0x04
+#define REG_FLAG   0x08
+#define REG_STROBE_SRC 0x06
+#define REG_LED1_FLASH_BR 0x06
+#define REG_LED1_TORCH_BR 0x07
+
+#define MASK_ENABLE0x03
+#define MASK_TORCH_BR  0x70
+#define MASK_FLASH_BR  0x0F
+#define MASK_FLASH_TOUT0x07
+#define MASK_FLAG  0xFF
+#define MASK_STROBE_SRC0x80
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_SHORT_CIRCUIT(1<<1)
+#define FAULT_UVLO (1<<2)
+#define FAULT_IVFM (1<<3)
+#define FAULT_OCP  (1<<4)
+#define FAULT_OVERTEMP (1<<5)
+#define FAULT_NTC_TRIP (1<<6)
+#define FAULT_OVP  (1<<7)
+
+enum led_mode {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/*
+ * struct lm3646_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
+ * @mode_reg : mode register value
+ */
+struct lm3646_flash {
+   struct device *dev;
+   struct lm3646_platform_data *pdata;
+   struct regmap *regmap;
+
+   struct v4l2_ctrl_handler ctrls_led;
+   struct v4l2_subdev subdev_led;
+
+   u8 mode_reg;
+};
+
+#define to_lm3646_flash(_ctrl) \
+   container_of(_ctrl->handler, struct lm3646_flash, ctrls_led)
+
+/* enable mode control */
+static int lm3646_mode_ctrl(struct lm3646_flash *flash,
+   enum v4l2_flash_led_mode led_mode)
+{
+   int rval = -EINVAL;
+
+   switch (led_mode) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   rval = regmap_write(flash->regmap,
+   REG_ENABLE, flash->mode_reg | MODE_SHDN);

You could return here, and remove rval altogerher, as you do in
lm3646_set_ctrl().


+   bre

[RFC v6,3/3] media: i2c: add new dual LED Flash driver, lm364

2014-02-25 Thread Daniel Jeong
 This patch adds the driver for the LM3646, dual LED Flash driver.
The LM3646 has two 1.5A sync. boost converter with dual white current source.
It is controlled via an I2C compatible interface.
Each flash brightness, torch brightness and enable/disable can be controlled.
Under voltage, input voltage monitor and thermal threshhold Faults are added.
Please refer the datasheet http://www.ti.com/lit/ds/snvs962/snvs962.pdf

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3646.c |  419 
 include/media/lm3646.h |   87 +
 4 files changed, 516 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 4aa9c53..c7f2823 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -629,6 +629,15 @@ config VIDEO_LM3560
  This is a driver for the lm3560 dual flash controllers. It controls
  flash, torch LEDs.
 
+config VIDEO_LM3646
+   tristate "LM3646 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 lm3646 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 4ae..01b6bfc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_VIDEO_S5C73M3)   += s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
 obj-$(CONFIG_VIDEO_LM3560) += lm3560.o
+obj-$(CONFIG_VIDEO_LM3646) += lm3646.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/lm3646.c b/drivers/media/i2c/lm3646.c
new file mode 100644
index 000..97d79a7
--- /dev/null
+++ b/drivers/media/i2c/lm3646.c
@@ -0,0 +1,419 @@
+/*
+ * drivers/media/i2c/lm3646.c
+ * General device driver for TI lm3646, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x01
+#define REG_TORCH_BR   0x05
+#define REG_FLASH_BR   0x05
+#define REG_FLASH_TOUT 0x04
+#define REG_FLAG   0x08
+#define REG_STROBE_SRC 0x06
+#define REG_LED1_FLASH_BR 0x06
+#define REG_LED1_TORCH_BR 0x07
+
+#define MASK_ENABLE0x03
+#define MASK_TORCH_BR  0x70
+#define MASK_FLASH_BR  0x0F
+#define MASK_FLASH_TOUT0x07
+#define MASK_FLAG  0xFF
+#define MASK_STROBE_SRC0x80
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_SHORT_CIRCUIT(1<<1)
+#define FAULT_UVLO (1<<2)
+#define FAULT_IVFM (1<<3)
+#define FAULT_OCP  (1<<4)
+#define FAULT_OVERTEMP (1<<5)
+#define FAULT_NTC_TRIP (1<<6)
+#define FAULT_OVP  (1<<7)
+
+enum led_mode {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/*
+ * struct lm3646_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
+ * @mode_reg : mode register value
+ */
+struct lm3646_flash {
+   struct device *dev;
+   struct lm3646_platform_data *pdata;
+   struct regmap *regmap;
+
+   struct v4l2_ctrl_handler ctrls_led;
+   struct v4l2_subdev subdev_led;
+
+   u8 mode_reg;
+};
+
+#define to_lm3646_flash(_ctrl) \
+   container_of(_ctrl->handler, struct lm3646_flash, ctrls_led)
+
+/* enable mode control */
+static int lm3646_mode_ctrl(struct lm3646_flash *flash,
+   enum v4l2_flash_led_mode led_mode)
+{
+   int rval = -EINVAL;
+
+   switch (led_mode) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   rval = regmap_write(flash->regmap,
+   REG_ENABLE, flash->mode_reg | MODE_SHDN);
+   break;
+   case V4L2_FLASH_LED_MODE_TORCH:
+   rval = regmap_write(flash->regmap,
+   REG_ENABLE, flash->mode_reg | MODE_TORCH);
+   break;
+   case V4L2_FLASH_LED_MODE_FLASH:
+   rval = regmap_write(flash->regmap

[RFC v6 1/3] v4l2-controls.h: add addtional Flash fault bits

2014-02-25 Thread Daniel Jeong
 Three Flash fault are added.
 V4L2_FLASH_FAULT_UNDER_VOLTAGE for the case low voltage below the min. limit.
 V4L2_FLASH_FAULT_INPUT_VOLTAGE for the case falling input voltage and chip  
 adjust flash current not occur under voltage event.
 V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE for the case the temperature exceed
 the maximun limit

Signed-off-by: Daniel Jeong 
---
 include/uapi/linux/v4l2-controls.h |3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 2cbe605..1d662f6 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -812,6 +812,9 @@ enum v4l2_flash_strobe_source {
 #define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3)
 #define V4L2_FLASH_FAULT_OVER_CURRENT  (1 << 4)
 #define V4L2_FLASH_FAULT_INDICATOR (1 << 5)
+#define V4L2_FLASH_FAULT_UNDER_VOLTAGE (1 << 6)
+#define V4L2_FLASH_FAULT_INPUT_VOLTAGE (1 << 7)
+#define V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE  (1 << 8)
 
 #define V4L2_CID_FLASH_CHARGE  (V4L2_CID_FLASH_CLASS_BASE + 11)
 #define V4L2_CID_FLASH_READY   (V4L2_CID_FLASH_CLASS_BASE + 12)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v6,2/3] controls.xml : add addtional Flash fault bits

2014-02-25 Thread Daniel Jeong
Descriptions for flash faluts.
 V4L2_FLASH_FAULT_UNDER_VOLTAGE,
 V4L2_FLASH_FAULT_INPUT_VOLTAGE,
 and V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE

Signed-off-by: Daniel Jeong 
---
 Documentation/DocBook/media/v4l/controls.xml |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index a5a3188..16f8af3 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4370,6 +4370,24 @@ interface and may change in the future.
  The flash controller has detected a short or open
  circuit condition on the indicator LED.

+   
+ 
V4L2_FLASH_FAULT_UNDER_VOLTAGE
+ Flash controller voltage to the flash LED
+ has been below the minimum limit specific to the flash
+ controller.
+   
+   
+ 
V4L2_FLASH_FAULT_INPUT_VOLTAGE
+ The flash current can't reach to the target current
+ because the input voltage is dropped below lower limit. 
+ and Flash controller have adjusted the flash current
+ not to occur under voltage event.
+   
+   
+ 
V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE
+ The temperature of the LED has exceeded its
+ allowed upper limit.
+   
  

  
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v6 0/3] add new Dual LED FLASH LM3646

2014-02-25 Thread Daniel Jeong
 This patch is to add new dual led flash, lm3646.
 LM3646 is the product of ti and it has two 1.5A sync. boost 
 converter with dual white current source.
 2 files are created and 4 files are modified.
 And 3 patch files are created and sent.

 v6 - change log
   Changed description in DocBook.

 v5 - change log
   Added control register caching to avoid redundant i2c access.
   Removed dt to create a seperate patch.
   Changed description in DocBook.

Daniel Jeong (3):
  [RFC] v4l2-controls.h:
  [RFC] DocBook:Media:v4l:controls.xml
  [RFC] media: i2c: add new dual LED Flash driver, lm3646

 Documentation/DocBook/media/v4l/controls.xml |   18 ++
 drivers/media/i2c/Kconfig|9 +
 drivers/media/i2c/Makefile   |1 +
 drivers/media/i2c/lm3646.c   |  419 ++
 include/media/lm3646.h   |   87 ++
 include/uapi/linux/v4l2-controls.h   |3 +
 6 files changed, 537 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC v5,2/3] controls.xml : add addtional Flash fault bits

2014-02-23 Thread Daniel Jeong

Hi Sakari
Thank you for your comments.

Hi Daniel,

Daniel Jeong wrote:
Added more comment about Input voltage flash monitor and external 
temp function.


Signed-off-by: Daniel Jeong 
---
  Documentation/DocBook/media/v4l/controls.xml |   18 ++
  1 file changed, 18 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml

index a5a3188..145a127 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4370,6 +4370,24 @@ interface and may change in the future.
The flash controller has detected a short or open
circuit condition on the indicator LED.
  
+
+ V4L2_FLASH_FAULT_UNDER_VOLTAGE
+  Flash controller voltage to the flash LED
+  has been below the minimum limit specific to the flash
+  controller.
+
+
+ V4L2_FLASH_FAULT_INPUT_VOLTAGE
+  The flash controller has detected adjustment by 
IVFM

+  (Input Voltage Flash Monitor) block.
+  If during the flash current turn-on, the input voltage falls
+  below the threshold input voltage, IVFM adjust level


Could you add an explanation what does this fault actually mean to the 
user?


"IVFM" at least doesn't say anything to me...


How about this ?
"The flash current can't reach to the target current due to the input 
voltage falling below lower limit
and flash controller adjusted the flash current not to occur low voltage 
envent"

+
+
+ 
V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE
+  The flash controller has detected that TEMP 
input has

+  crossed threshold by external temperature sensor.


How about this instead?

"The temperature of the LED has exceeded its allowed upper limit."


Ok.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v5,3/3] media: i2c: add new dual LED Flash driver, lm3646

2014-02-20 Thread Daniel Jeong
To prevent redundant i2c access, Mode register is caching at initial time.
And it will be written with control mode.
There are many bit data in mode register so it is hard to set zero all.
DT is removed and will be created a seperated patch

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3646.c |  419 
 include/media/lm3646.h |   87 +
 4 files changed, 516 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 4aa9c53..c7f2823 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -629,6 +629,15 @@ config VIDEO_LM3560
  This is a driver for the lm3560 dual flash controllers. It controls
  flash, torch LEDs.
 
+config VIDEO_LM3646
+   tristate "LM3646 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 lm3646 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 4ae..01b6bfc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_VIDEO_S5C73M3)   += s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
 obj-$(CONFIG_VIDEO_LM3560) += lm3560.o
+obj-$(CONFIG_VIDEO_LM3646) += lm3646.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/lm3646.c b/drivers/media/i2c/lm3646.c
new file mode 100644
index 000..97d79a7
--- /dev/null
+++ b/drivers/media/i2c/lm3646.c
@@ -0,0 +1,419 @@
+/*
+ * drivers/media/i2c/lm3646.c
+ * General device driver for TI lm3646, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x01
+#define REG_TORCH_BR   0x05
+#define REG_FLASH_BR   0x05
+#define REG_FLASH_TOUT 0x04
+#define REG_FLAG   0x08
+#define REG_STROBE_SRC 0x06
+#define REG_LED1_FLASH_BR 0x06
+#define REG_LED1_TORCH_BR 0x07
+
+#define MASK_ENABLE0x03
+#define MASK_TORCH_BR  0x70
+#define MASK_FLASH_BR  0x0F
+#define MASK_FLASH_TOUT0x07
+#define MASK_FLAG  0xFF
+#define MASK_STROBE_SRC0x80
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_SHORT_CIRCUIT(1<<1)
+#define FAULT_UVLO (1<<2)
+#define FAULT_IVFM (1<<3)
+#define FAULT_OCP  (1<<4)
+#define FAULT_OVERTEMP (1<<5)
+#define FAULT_NTC_TRIP (1<<6)
+#define FAULT_OVP  (1<<7)
+
+enum led_mode {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/*
+ * struct lm3646_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
+ * @mode_reg : mode register value
+ */
+struct lm3646_flash {
+   struct device *dev;
+   struct lm3646_platform_data *pdata;
+   struct regmap *regmap;
+
+   struct v4l2_ctrl_handler ctrls_led;
+   struct v4l2_subdev subdev_led;
+
+   u8 mode_reg;
+};
+
+#define to_lm3646_flash(_ctrl) \
+   container_of(_ctrl->handler, struct lm3646_flash, ctrls_led)
+
+/* enable mode control */
+static int lm3646_mode_ctrl(struct lm3646_flash *flash,
+   enum v4l2_flash_led_mode led_mode)
+{
+   int rval = -EINVAL;
+
+   switch (led_mode) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   rval = regmap_write(flash->regmap,
+   REG_ENABLE, flash->mode_reg | MODE_SHDN);
+   break;
+   case V4L2_FLASH_LED_MODE_TORCH:
+   rval = regmap_write(flash->regmap,
+   REG_ENABLE, flash->mode_reg | MODE_TORCH);
+   break;
+   case V4L2_FLASH_LED_MODE_FLASH:
+   rval = regmap_write(flash->regmap,
+   REG_ENABLE, flash->mode_reg | MODE_FLASH);
+   break;
+   }
+   return rval;
+}
+
+/* V4L2 controls  */
+static

[RFC v5,2/3] controls.xml : add addtional Flash fault bits

2014-02-20 Thread Daniel Jeong
Added more comment about Input voltage flash monitor and external temp function.

Signed-off-by: Daniel Jeong 
---
 Documentation/DocBook/media/v4l/controls.xml |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index a5a3188..145a127 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4370,6 +4370,24 @@ interface and may change in the future.
  The flash controller has detected a short or open
  circuit condition on the indicator LED.

+   
+ 
V4L2_FLASH_FAULT_UNDER_VOLTAGE
+ Flash controller voltage to the flash LED
+ has been below the minimum limit specific to the flash
+ controller.
+   
+   
+ 
V4L2_FLASH_FAULT_INPUT_VOLTAGE
+ The flash controller has detected adjustment by IVFM
+ (Input Voltage Flash Monitor) block.
+ If during the flash current turn-on, the input voltage falls
+ below the threshold input voltage, IVFM adjust level
+   
+   
+ 
V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE
+ The flash controller has detected that TEMP input has
+ crossed threshold by external temperature sensor.
+   
  

  
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v5, 1/3] v4l2-controls.h: add addtional Flash fault bits

2014-02-20 Thread Daniel Jeong
Same with v3 and v4.

Signed-off-by: Daniel Jeong 
---
 include/uapi/linux/v4l2-controls.h |3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 2cbe605..1d662f6 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -812,6 +812,9 @@ enum v4l2_flash_strobe_source {
 #define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3)
 #define V4L2_FLASH_FAULT_OVER_CURRENT  (1 << 4)
 #define V4L2_FLASH_FAULT_INDICATOR (1 << 5)
+#define V4L2_FLASH_FAULT_UNDER_VOLTAGE (1 << 6)
+#define V4L2_FLASH_FAULT_INPUT_VOLTAGE (1 << 7)
+#define V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE  (1 << 8)
 
 #define V4L2_CID_FLASH_CHARGE  (V4L2_CID_FLASH_CLASS_BASE + 11)
 #define V4L2_CID_FLASH_READY   (V4L2_CID_FLASH_CLASS_BASE + 12)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC v3,2/3] controls.xml : add addtional Flash fault bits

2014-02-18 Thread Daniel Jeong

Hi Sakari.

Thank you for you comments.


Hi Daniel,

Thanks for the update.

Daniel Jeong wrote:

Add addtional falult bits for FLASH
V4L2_FLASH_FAULT_UNDER_VOLTAGE  : UVLO
V4L2_FLASH_FAULT_INPUT_VOLTAGE  : input voltage is adjusted by IVFM
V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE : NTC Trip point is crossed.

Signed-off-by: Daniel Jeong 
---
  Documentation/DocBook/media/v4l/controls.xml |   16 
  1 file changed, 16 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index a5a3188..8121f7e 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4370,6 +4370,22 @@ interface and may change in the future.
  The flash controller has detected a short or open
  circuit condition on the indicator LED.

+   
+ 
V4L2_FLASH_FAULT_UNDER_VOLTAGE
+ Flash controller voltage to the flash LED
+ has been below the minimum limit specific to the flash
+ controller.
+   
+   
+ 
V4L2_FLASH_FAULT_INPUT_VOLTAGE
+ The flash controller has detected adjustment of input
+ voltage by Input Volage Flash Monitor(IVFM).

Volage -> Voltage; space before "(".

I still feel uncomfortable with the reference to the IVFM. That appears
clearely an implementation specific term.

You previously mentioned the flash current may be adjusted by the flash
controller. It should be mentioned here.

Is it possible to read the adjusted value from the chip?


Unfornatley it is NOT possible.
Usually thresholds can be selected,for example 2.9V, 3.0V, 3.1V, and 3.2V.
Chip adjusts the current value if the input voltage cross the thresholds.
We just read this flault flag from chip. So we need this.

I will describe more next patch.


+   
+   
+ 
V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE
+ The flash controller has detected that TEMP input has
+ crossed NTC Trip Voltage.

Even if the NTC resistor might be the actual implementation, I wouldn't
refer to it here. There could be a real temperature sensor, for instance.


I will fix it.


+   
  

  



--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v4,3/3] media: i2c: add new dual LED Flash driver, lm3646

2014-02-16 Thread Daniel Jeong
harware description check priorities
platform data -> device tree -> default data

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3646.c |  456 
 include/media/lm3646.h |   87 +
 4 files changed, 553 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 4aa9c53..c7f2823 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -629,6 +629,15 @@ config VIDEO_LM3560
  This is a driver for the lm3560 dual flash controllers. It controls
  flash, torch LEDs.
 
+config VIDEO_LM3646
+   tristate "LM3646 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 lm3646 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 4ae..01b6bfc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_VIDEO_S5C73M3)   += s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
 obj-$(CONFIG_VIDEO_LM3560) += lm3560.o
+obj-$(CONFIG_VIDEO_LM3646) += lm3646.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/lm3646.c b/drivers/media/i2c/lm3646.c
new file mode 100644
index 000..acf5961
--- /dev/null
+++ b/drivers/media/i2c/lm3646.c
@@ -0,0 +1,456 @@
+/*
+ * drivers/media/i2c/lm3646.c
+ * General device driver for TI lm3646, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x01
+#define REG_TORCH_BR   0x05
+#define REG_FLASH_BR   0x05
+#define REG_FLASH_TOUT 0x04
+#define REG_FLAG   0x08
+#define REG_STROBE_SRC 0x06
+#define REG_LED1_FLASH_BR 0x06
+#define REG_LED1_TORCH_BR 0x07
+
+#define MASK_ENABLE0x03
+#define MASK_TORCH_BR  0x70
+#define MASK_FLASH_BR  0x0F
+#define MASK_FLASH_TOUT0x07
+#define MASK_FLAG  0xFF
+#define MASK_STROBE_SRC0x80
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_SHORT_CIRCUIT(1<<1)
+#define FAULT_UVLO (1<<2)
+#define FAULT_IVFM (1<<3)
+#define FAULT_OCP  (1<<4)
+#define FAULT_OVERTEMP (1<<5)
+#define FAULT_NTC_TRIP (1<<6)
+#define FAULT_OVP  (1<<7)
+
+enum led_mode {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/*
+ * struct lm3646_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 lm3646_flash {
+   struct device *dev;
+   struct lm3646_platform_data *pdata;
+   struct regmap *regmap;
+
+   struct v4l2_ctrl_handler ctrls_led;
+   struct v4l2_subdev subdev_led;
+};
+
+#define to_lm3646_flash(_ctrl) \
+   container_of(_ctrl->handler, struct lm3646_flash, ctrls_led)
+
+/* enable mode control */
+static int lm3646_mode_ctrl(struct lm3646_flash *flash,
+   enum v4l2_flash_led_mode led_mode)
+{
+   int rval = -EINVAL;
+
+   switch (led_mode) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_SHDN);
+   break;
+   case V4L2_FLASH_LED_MODE_TORCH:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_TORCH);
+   break;
+   case V4L2_FLASH_LED_MODE_FLASH:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_FLASH);
+   break;
+   }
+   return rval;
+}
+
+/* V4L2 controls  */
+static int lm3646_get_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct lm3646_flash *flash = to_lm3646_flash(ctrl);
+   int rval = -EINVAL;
+
+   if (ctrl->id == V4L2_CID_FLASH_FAULT) {
+   s32 fa

[RFC v3,3/3] media: i2c: add new dual LED Flash driver, lm3646

2014-02-14 Thread Daniel Jeong
Add new dual flash driver.
Fixed the previous issues and added device tree support.

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3646.c |  451 
 include/media/lm3646.h |   87 +
 4 files changed, 548 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 4aa9c53..c7f2823 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -629,6 +629,15 @@ config VIDEO_LM3560
  This is a driver for the lm3560 dual flash controllers. It controls
  flash, torch LEDs.
 
+config VIDEO_LM3646
+   tristate "LM3646 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 lm3646 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 4ae..01b6bfc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_VIDEO_S5C73M3)   += s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
 obj-$(CONFIG_VIDEO_LM3560) += lm3560.o
+obj-$(CONFIG_VIDEO_LM3646) += lm3646.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/lm3646.c b/drivers/media/i2c/lm3646.c
new file mode 100644
index 000..388ffe9
--- /dev/null
+++ b/drivers/media/i2c/lm3646.c
@@ -0,0 +1,451 @@
+/*
+ * drivers/media/i2c/lm3646.c
+ * General device driver for TI lm3646, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x01
+#define REG_TORCH_BR   0x05
+#define REG_FLASH_BR   0x05
+#define REG_FLASH_TOUT 0x04
+#define REG_FLAG   0x08
+#define REG_STROBE_SRC 0x06
+#define REG_LED1_FLASH_BR 0x06
+#define REG_LED1_TORCH_BR 0x07
+
+#define MASK_ENABLE0x03
+#define MASK_TORCH_BR  0x70
+#define MASK_FLASH_BR  0x0F
+#define MASK_FLASH_TOUT0x07
+#define MASK_FLAG  0xFF
+#define MASK_STROBE_SRC0x80
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_SHORT_CIRCUIT(1<<1)
+#define FAULT_UVLO (1<<2)
+#define FAULT_IVFM (1<<3)
+#define FAULT_OCP  (1<<4)
+#define FAULT_OVERTEMP (1<<5)
+#define FAULT_NTC_TRIP (1<<6)
+#define FAULT_OVP  (1<<7)
+
+enum led_mode {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/* 
+ * struct lm3646_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 lm3646_flash {
+   struct device *dev;
+   struct lm3646_platform_data *pdata;
+   struct regmap *regmap;
+
+   struct v4l2_ctrl_handler ctrls_led;
+   struct v4l2_subdev subdev_led;
+};
+
+#define to_lm3646_flash(_ctrl) \
+   container_of(_ctrl->handler, struct lm3646_flash, ctrls_led)
+
+/* enable mode control */
+static int lm3646_mode_ctrl(struct lm3646_flash *flash,
+   enum v4l2_flash_led_mode led_mode)
+{
+   int rval = -EINVAL;
+
+   switch (led_mode) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_SHDN);
+   break;
+   case V4L2_FLASH_LED_MODE_TORCH:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_TORCH);
+   break;
+   case V4L2_FLASH_LED_MODE_FLASH:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_FLASH);
+   break;
+   }
+   return rval;
+}
+
+/* V4L2 controls  */
+static int lm3646_get_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct lm3646_flash *flash = to_lm3646_flash(ctrl);
+   int rval = -EINVAL;
+
+   if (ctrl->id == V4L2_CID_FLASH_FAULT) {
+   s3

[RFC v3,2/3] controls.xml : add addtional Flash fault bits

2014-02-14 Thread Daniel Jeong
Add addtional falult bits for FLASH
V4L2_FLASH_FAULT_UNDER_VOLTAGE  : UVLO
V4L2_FLASH_FAULT_INPUT_VOLTAGE  : input voltage is adjusted by IVFM
V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE : NTC Trip point is crossed.

Signed-off-by: Daniel Jeong 
---
 Documentation/DocBook/media/v4l/controls.xml |   16 
 1 file changed, 16 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index a5a3188..8121f7e 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4370,6 +4370,22 @@ interface and may change in the future.
  The flash controller has detected a short or open
  circuit condition on the indicator LED.

+   
+ 
V4L2_FLASH_FAULT_UNDER_VOLTAGE
+ Flash controller voltage to the flash LED
+ has been below the minimum limit specific to the flash
+ controller.
+   
+   
+ 
V4L2_FLASH_FAULT_INPUT_VOLTAGE
+ The flash controller has detected adjustment of input
+ voltage by Input Volage Flash Monitor(IVFM).
+   
+   
+ 
V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE
+ The flash controller has detected that TEMP input has
+ crossed NTC Trip Voltage.
+   
  

  
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v3,1/3] v4l2-controls.h: add addtional Flash fault bits

2014-02-14 Thread Daniel Jeong
Add addtional falult bits for FLASH
V4L2_FLASH_FAULT_UNDER_VOLTAGE  : UVLO
V4L2_FLASH_FAULT_INPUT_VOLTAGE  : input voltage is adjusted by IVFM
V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE : NTC Trip point is crossed.

Signed-off-by: Daniel Jeong 
---
 include/uapi/linux/v4l2-controls.h |3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 2cbe605..1d662f6 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -812,6 +812,9 @@ enum v4l2_flash_strobe_source {
 #define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3)
 #define V4L2_FLASH_FAULT_OVER_CURRENT  (1 << 4)
 #define V4L2_FLASH_FAULT_INDICATOR (1 << 5)
+#define V4L2_FLASH_FAULT_UNDER_VOLTAGE (1 << 6)
+#define V4L2_FLASH_FAULT_INPUT_VOLTAGE (1 << 7)
+#define V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE  (1 << 8)
 
 #define V4L2_CID_FLASH_CHARGE  (V4L2_CID_FLASH_CLASS_BASE + 11)
 #define V4L2_CID_FLASH_READY   (V4L2_CID_FLASH_CLASS_BASE + 12)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFCv2,1/2] v4l2-controls.h: add addtional Flash fault bits

2014-01-28 Thread Daniel Jeong

2014년 01월 28일 18:08, Sakari Ailus 쓴 글:

Hi Daniel,

On Tue, Jan 28, 2014 at 03:55:57PM +0900, Daniel Jeong wrote:

Add additional FLASH Fault bits to dectect faults from chip.
Some Flash drivers support UVLO, IVFM, NTC Trip faults.
UVLO :  Under Voltage Lock Out Threshold crossed
IVFM :  IVFM block reported and/or adjusted LED current Input Voltage Flash 
Monitor trip threshold
NTC  :  NTC Threshold crossed. Many Flash drivers have a pin and the fault bit 
to
serves as a threshold detector for negative temperature coefficient (NTC) 
thermistors.

Signed-off-by: Daniel Jeong 
---
  include/uapi/linux/v4l2-controls.h |3 +++
  1 file changed, 3 insertions(+)

diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 1666aab..01d730c 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -803,6 +803,9 @@ enum v4l2_flash_strobe_source {
  #define V4L2_FLASH_FAULT_SHORT_CIRCUIT(1 << 3)
  #define V4L2_FLASH_FAULT_OVER_CURRENT (1 << 4)
  #define V4L2_FLASH_FAULT_INDICATOR(1 << 5)
+#define V4L2_FLASH_FAULT_UVLO  (1 << 6)
+#define V4L2_FLASH_FAULT_IVFM  (1 << 7)
+#define V4L2_FLASH_FAULT_NTC_TRIP  (1 << 8)

I object adding a new fault which is essentially the same as an existing
fault, V4L2_FLASH_FAULT_OVER_TEMPERATURE.


I hope you consider it again.
Usually, when the die temperature exceeds the specific temperature, ie 120 or 
135 and fixed value,
turn off PFET,NFET, current sources and set TEMP Fault bit.
But in the NTC mode, the comparator is working and detect selected temperature 
through Vtrip value.
It protects shutdown the chip due to high voltage and keep the device operation.
Many flash chip support NTC and TEMP Fault both. For example, LM3554, LM3556, 
LM3559
LM3642, LM3646, LM3560, LM3561, LM3565 etc
Two things should be tell apart.



As the practice has been to use human-readable names for the faults, I'd
also suggest using V4L2_FLASH_FAULT_UNDER_VOLTAGE instead of
V4L2_FLASH_FAULT_UVLO.


I agree with you.



What's the IVFM block and what does it do?


IVFM is Input Voltage Flash Monitor.
If the flash chip has IVFM function the flash current can be adjusted based 
upon the voltage level of input.
As ramping flash current, the input voltage goes down and IVFM block adjust 
current to prevent to shudown due to low voltage
and keep the flash operation. So if the input voltage crossed the IVFM 
Threshold level chip set the fault bit.
Many flash chip, for example LM3556, LM3646, LM3642 , support this fucntion.
I think, V4L2_FLASH_FAULT_INPUT_VOLTAGE_MONITOR is better than 
V4L2_FLASH_FAULT_IVFM.




  #define V4L2_CID_FLASH_CHARGE (V4L2_CID_FLASH_CLASS_BASE + 11)
  #define V4L2_CID_FLASH_READY  (V4L2_CID_FLASH_CLASS_BASE + 12)


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv2,2/2] i2c: add new dual Flash driver,LM3646

2014-01-27 Thread Daniel Jeong
Add new dual flash driver. 
LM3646 is a dual Flash LED Driver, LED1 and LED2, following the datasheet.
But there is no registers to contorl LED2 brightness.
LED2 brightness can be controlled by limiting max brightness.
LED2 brightness  = Total brightness - LED1 brightness
LED2 will be off if LED2 brightness is set equal to or bigger than Total 
brightness.
And the brightness step is very small, 1.46mA for Torch, 11.71mA for Flash.
If the step is changed to mA, maximum brightness cannot be reachable.

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3646.c |  400 
 include/media/lm3646.h |   87 ++
 4 files changed, 497 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 842654d..654df46 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -630,6 +630,15 @@ config VIDEO_LM3560
  This is a driver for the lm3560 dual flash controllers. It controls
  flash, torch LEDs.
 
+config VIDEO_LM3646
+   tristate "LM3646 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 lm3646 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index e03f177..a52cda6 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_VIDEO_S5C73M3)   += s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
 obj-$(CONFIG_VIDEO_LM3560) += lm3560.o
+obj-$(CONFIG_VIDEO_LM3646) += lm3646.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/lm3646.c b/drivers/media/i2c/lm3646.c
new file mode 100644
index 000..4b025f2
--- /dev/null
+++ b/drivers/media/i2c/lm3646.c
@@ -0,0 +1,400 @@
+/*
+ * drivers/media/i2c/lm3646.c
+ * General device driver for TI lm3646, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x01
+#define REG_TORCH_BR   0x05
+#define REG_FLASH_BR   0x05
+#define REG_FLASH_TOUT 0x04
+#define REG_FLAG   0x08
+#define REG_STROBE_SRC 0x06
+#define REG_LED1_FLASH_BR 0x06
+#define REG_LED1_TORCH_BR 0x07
+
+#define MASK_ENABLE0x03
+#define MASK_TORCH_BR  0x70
+#define MASK_FLASH_BR  0x0F
+#define MASK_FLASH_TOUT0x07
+#define MASK_FLAG  0xFF
+#define MASK_STROBE_SRC0x80
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_SHORT_CIRCUIT(1<<1)
+#define FAULT_UVLO (1<<2)
+#define FAULT_IVFM (1<<3)
+#define FAULT_OCP  (1<<4)
+#define FAULT_OVERTEMP (1<<5)
+#define FAULT_NTC_TRIP (1<<6)
+#define FAULT_OVP  (1<<7)
+
+enum led_mode {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/*
+ * struct lm3646_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 lm3646_flash {
+   struct device *dev;
+   struct lm3646_platform_data *pdata;
+   struct regmap *regmap;
+
+   enum v4l2_flash_led_mode led_mode;
+   struct v4l2_ctrl_handler ctrls_led;
+   struct v4l2_subdev subdev_led;
+};
+
+#define to_lm3646_flash(_ctrl) \
+   container_of(_ctrl->handler, struct lm3646_flash, ctrls_led)
+
+/* enable mode control */
+static int lm3646_mode_ctrl(struct lm3646_flash *flash)
+{
+   int rval = -EINVAL;
+
+   switch (flash->led_mode) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_SHDN);
+   break;
+   case V4L2_FLASH_LED_MODE_TORCH:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_TORCH);
+   break;
+   case V4L2_FLASH_LED_MODE_FLASH:
+   rval = reg

[RFCv2,1/2] v4l2-controls.h: add addtional Flash fault bits

2014-01-27 Thread Daniel Jeong
Add additional FLASH Fault bits to dectect faults from chip.
Some Flash drivers support UVLO, IVFM, NTC Trip faults.
UVLO :  Under Voltage Lock Out Threshold crossed
IVFM :  IVFM block reported and/or adjusted LED current Input Voltage Flash 
Monitor trip threshold
NTC  :  NTC Threshold crossed. Many Flash drivers have a pin and the fault bit 
to 
serves as a threshold detector for negative temperature coefficient (NTC) 
thermistors.

Signed-off-by: Daniel Jeong 
---
 include/uapi/linux/v4l2-controls.h |3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 1666aab..01d730c 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -803,6 +803,9 @@ enum v4l2_flash_strobe_source {
 #define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3)
 #define V4L2_FLASH_FAULT_OVER_CURRENT  (1 << 4)
 #define V4L2_FLASH_FAULT_INDICATOR (1 << 5)
+#define V4L2_FLASH_FAULT_UVLO  (1 << 6)
+#define V4L2_FLASH_FAULT_IVFM  (1 << 7)
+#define V4L2_FLASH_FAULT_NTC_TRIP  (1 << 8)
 
 #define V4L2_CID_FLASH_CHARGE  (V4L2_CID_FLASH_CLASS_BASE + 11)
 #define V4L2_CID_FLASH_READY   (V4L2_CID_FLASH_CLASS_BASE + 12)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


media: i2c: add new dual LED Flash driver, lm3646.

2014-01-06 Thread Daniel Jeong
 This patch adds the driver for the LM3646, dual LED Flash driver.
The LM3646 has two 1.5A sync. boost converter with dual white current source.
It is controlled via an I2C compatible interface.
Each flash brightness, torch brightness and enable/disable can be controlled.
UVLO, IVFM and NTC threshhold Faults are added.
Please refer the datasheet http://www.ti.com/lit/ds/snvs962/snvs962.pdf

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3646.c |  410 
 include/media/lm3646.h |   87 
 include/uapi/linux/v4l2-controls.h |3 +
 5 files changed, 510 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 842654d..654df46 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -630,6 +630,15 @@ config VIDEO_LM3560
  This is a driver for the lm3560 dual flash controllers. It controls
  flash, torch LEDs.
 
+config VIDEO_LM3646
+   tristate "LM3646 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 lm3646 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index e03f177..a52cda6 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_VIDEO_S5C73M3)   += s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
 obj-$(CONFIG_VIDEO_LM3560) += lm3560.o
+obj-$(CONFIG_VIDEO_LM3646) += lm3646.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/lm3646.c b/drivers/media/i2c/lm3646.c
new file mode 100644
index 000..f6d8b6d
--- /dev/null
+++ b/drivers/media/i2c/lm3646.c
@@ -0,0 +1,410 @@
+/*
+ * drivers/media/i2c/lm3646.c
+ * General device driver for TI lm3646, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x01
+#define REG_TORCH_BR   0x05
+#define REG_FLASH_BR   0x05
+#define REG_FLASH_TOUT 0x04
+#define REG_FLAG   0x08
+#define REG_STROBE_SRC 0x06
+#define REG_LED1_FLASH_BR 0x06
+#define REG_LED1_TORCH_BR 0x07
+
+#define MASK_ENABLE0x03
+#define MASK_TORCH_BR  0x70
+#define MASK_FLASH_BR  0x0F
+#define MASK_FLASH_TOUT0x07
+#define MASK_FLAG  0xFF
+#define MASK_STROBE_SRC0x80
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_SHORT_CIRCUIT(1<<1)
+#define FAULT_UVLO (1<<2)
+#define FAULT_IVFM (1<<3)
+#define FAULT_OCP  (1<<4)
+#define FAULT_OVERTEMP (1<<5)
+#define FAULT_NTC_TRIP (1<<6)
+#define FAULT_OVP  (1<<7)
+
+enum led_mode {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/* struct lm3646_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 lm3646_flash {
+   struct device *dev;
+   struct lm3646_platform_data *pdata;
+   struct regmap *regmap;
+   struct mutex lock;
+
+   enum v4l2_flash_led_mode led_mode;
+   struct v4l2_ctrl_handler ctrls_led;
+   struct v4l2_subdev subdev_led;
+};
+
+#define to_lm3646_flash(_ctrl) \
+   container_of(_ctrl->handler, struct lm3646_flash, ctrls_led)
+
+/* enable mode control */
+static int lm3646_mode_ctrl(struct lm3646_flash *flash)
+{
+   int rval = -EINVAL;
+
+   switch (flash->led_mode) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_SHDN);
+   break;
+   case V4L2_FLASH_LED_MODE_TORCH:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, MASK_ENABLE, MODE_TORCH);
+   break;
+   case V4L2_FLASH_LED_MODE_FLASH:
+   rval = regmap_update_b

[PATCH V2 -next] [media] media: i2c: lm3560: fix missing unlock on error in lm3560_get_ctrl().

2013-12-05 Thread Daniel Jeong
Sorry I should have checked below things before sending the first patch.
Correct reference of reading values. (rval -> reg_val)
Add the missing unlock before return from function lm3560_get_ctrl()
to avoid deadlock. 
Thank you Dan Carpenter & Sakari.


Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/lm3560.c |   14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c
index 3317a9a..ab5857d 100644
--- a/drivers/media/i2c/lm3560.c
+++ b/drivers/media/i2c/lm3560.c
@@ -172,28 +172,28 @@ static int lm3560_flash_brt_ctrl(struct lm3560_flash 
*flash,
 static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
 {
struct lm3560_flash *flash = to_lm3560_flash(ctrl, led_no);
+   int rval = -EINVAL;
 
mutex_lock(&flash->lock);
 
if (ctrl->id == V4L2_CID_FLASH_FAULT) {
-   int rval;
s32 fault = 0;
unsigned int reg_val;
rval = regmap_read(flash->regmap, REG_FLAG, ®_val);
if (rval < 0)
-   return rval;
-   if (rval & FAULT_SHORT_CIRCUIT)
+   goto out;
+   if (reg_val & FAULT_SHORT_CIRCUIT)
fault |= V4L2_FLASH_FAULT_SHORT_CIRCUIT;
-   if (rval & FAULT_OVERTEMP)
+   if (reg_val & FAULT_OVERTEMP)
fault |= V4L2_FLASH_FAULT_OVER_TEMPERATURE;
-   if (rval & FAULT_TIMEOUT)
+   if (reg_val & FAULT_TIMEOUT)
fault |= V4L2_FLASH_FAULT_TIMEOUT;
ctrl->cur.val = fault;
-   return 0;
}
 
+out:
mutex_unlock(&flash->lock);
-   return -EINVAL;
+   return rval;
 }
 
 static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH -next] [media] media: i2c: lm3560: fix missing unlock error in lm3560_get_ctrl().

2013-11-13 Thread Daniel Jeong
Add the missing unlock before return from function lm3560_get_ctrl()
to avoid deadlock. Thanks to Dan Carpenter.

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/lm3560.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c
index 3317a9a..5d6eef0 100644
--- a/drivers/media/i2c/lm3560.c
+++ b/drivers/media/i2c/lm3560.c
@@ -172,16 +172,16 @@ static int lm3560_flash_brt_ctrl(struct lm3560_flash 
*flash,
 static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
 {
struct lm3560_flash *flash = to_lm3560_flash(ctrl, led_no);
+   int rval = -EINVAL;
 
mutex_lock(&flash->lock);
 
if (ctrl->id == V4L2_CID_FLASH_FAULT) {
-   int rval;
s32 fault = 0;
unsigned int reg_val;
rval = regmap_read(flash->regmap, REG_FLAG, ®_val);
if (rval < 0)
-   return rval;
+   goto out;
if (rval & FAULT_SHORT_CIRCUIT)
fault |= V4L2_FLASH_FAULT_SHORT_CIRCUIT;
if (rval & FAULT_OVERTEMP)
@@ -189,11 +189,11 @@ static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, enum 
lm3560_led_id led_no)
if (rval & FAULT_TIMEOUT)
fault |= V4L2_FLASH_FAULT_TIMEOUT;
ctrl->cur.val = fault;
-   return 0;
}
 
+out:
mutex_unlock(&flash->lock);
-   return -EINVAL;
+   return rval;
 }
 
 static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2] media: i2c: add driver for dual LED Flash, lm3560.

2013-10-16 Thread Daniel Jeong
 Patch v2 deletes unnecessary codes.
 This patch adds the driver for the LM3560, dual LED Flash The
 LM3560 has two 1A constant current driver for high current
 white LEDs. It is controlled via an I2C compatible
 interface(up to 400kHz). Each flash brightness, torch
 brightness and enable/disable can be controlled
 independantly. But flash timeout and operation mode are shared.

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3560.c |  488 
 include/media/lm3560.h |   97 +
 4 files changed, 595 insertions(+)
 create mode 100644 drivers/media/i2c/lm3560.c
 create mode 100644 include/media/lm3560.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index d18be19..75c8a03 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -621,6 +621,15 @@ config VIDEO_AS3645A
  This is a driver for the AS3645A and LM3555 flash controllers. It has
  build in control for flash, torch and indicator LEDs.
 
+config VIDEO_LM3560
+   tristate "LM3560 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 lm3560 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 9f462df..e03f177 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_VIDEO_S5K4ECGX)  += s5k4ecgx.o
 obj-$(CONFIG_VIDEO_S5C73M3)+= s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
+obj-$(CONFIG_VIDEO_LM3560) += lm3560.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/lm3560.c b/drivers/media/i2c/lm3560.c
new file mode 100644
index 000..3317a9a
--- /dev/null
+++ b/drivers/media/i2c/lm3560.c
@@ -0,0 +1,488 @@
+/*
+ * drivers/media/i2c/lm3560.c
+ * General device driver for TI lm3560, FLASH LED Driver
+ *
+ * Copyright (C) 2013 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ * Ldd-Mlp 
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x10
+#define REG_TORCH_BR   0xa0
+#define REG_FLASH_BR   0xb0
+#define REG_FLASH_TOUT 0xc0
+#define REG_FLAG   0xd0
+#define REG_CONFIG10xe0
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_OVERTEMP (1<<1)
+#define FAULT_SHORT_CIRCUIT(1<<2)
+
+enum led_enable {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/* struct lm3560_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 lm3560_flash {
+   struct device *dev;
+   struct lm3560_platform_data *pdata;
+   struct regmap *regmap;
+   struct mutex lock;
+
+   enum v4l2_flash_led_mode led_mode;
+   struct v4l2_ctrl_handler ctrls_led[LM3560_LED_MAX];
+   struct v4l2_subdev subdev_led[LM3560_LED_MAX];
+};
+
+#define to_lm3560_flash(_ctrl, _no)\
+   container_of(_ctrl->handler, struct lm3560_flash, ctrls_led[_no])
+
+/* enable mode control */
+static int lm3560_mode_ctrl(struct lm3560_flash *flash)
+{
+   int rval = -EINVAL;
+
+   switch (flash->led_mode) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, 0x03, MODE_SHDN);
+   break;
+   case V4L2_FLASH_LED_MODE_TORCH:
+   rval = regmap_update_bits(flash->regmap,
+ REG_ENABLE, 0x03, MODE_TORCH);
+   break;
+   case V4L2_FLASH_LED_MODE_FLASH:
+   rval = regmap_update_bits(flash-&

[PATCH] media: i2c: add driver for dual LED Flash, lm3560.

2013-09-11 Thread Daniel Jeong
 This patch includes the driver for the LM3560, dual LED Flash.
 The LM3560 has two 1A constant current drivers for high current
 white LEDs. It is controlled via an I2C compatible interface(up to 400kHz).
 And each flash, torch brightness and enable/disable LED can be controlled
 independantly. But flash timeout and operation mode are shared.

Signed-off-by: Daniel Jeong 
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3560.c |  716 
 include/media/lm3560.h |  103 +++
 4 files changed, 829 insertions(+)
 create mode 100644 drivers/media/i2c/lm3560.c
 create mode 100644 include/media/lm3560.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index d18be19..75c8a03 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -621,6 +621,15 @@ config VIDEO_AS3645A
  This is a driver for the AS3645A and LM3555 flash controllers. It has
  build in control for flash, torch and indicator LEDs.
 
+config VIDEO_LM3560
+   tristate "LM3560 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 lm3560 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 9f462df..e03f177 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_VIDEO_S5K4ECGX)  += s5k4ecgx.o
 obj-$(CONFIG_VIDEO_S5C73M3)+= s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
+obj-$(CONFIG_VIDEO_LM3560) += lm3560.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/lm3560.c b/drivers/media/i2c/lm3560.c
new file mode 100644
index 000..7721e2e
--- /dev/null
+++ b/drivers/media/i2c/lm3560.c
@@ -0,0 +1,716 @@
+/*
+ * drivers/media/i2c/lm3560.c
+ * General device driver for TI LM3560, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2013 Texas Instruments
+ *
+ * Contact: Daniel Jeong 
+ *  LDD-MLP 
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* registers definitions */
+#define REG_ENABLE 0x10
+#define REG_TORCH_BR   0xA0
+#define REG_FLASH_BR   0xB0
+#define REG_FLASH_TOUT 0xC0
+#define REG_FLAG   0xD0
+#define REG_CONFIG10xE0
+
+/* LED1 */
+#define LED1_ENABLE 0x08
+#define LED1_ENABLE_MASK 0x08
+#define FLASH1_BR_DATA(_br) (_br<<0)
+#define FLASH1_BR_MASK 0x0F
+#define TORCH1_BR_DATA(_br) (_br<<0)
+#define TORCH1_BR_MASK 0x07
+
+/* LED2 */
+#define LED2_ENABLE 0x10
+#define LED2_ENABLE_MASK 0x10
+#define FLASH2_BR_DATA(_br) (_br<<4)
+#define FLASH2_BR_MASK 0xF0
+#define TORCH2_BR_DATA(_br) (_br<<3)
+#define TORCH2_BR_MASK 0x38
+
+/* Configuration */
+#define ENABLE_MODE_MASK 0x03
+#define FLASH_TOUT_MASK 0x1F
+#define STROBE_EN_MASK 0x04
+#define STROBE_EN_DATA(_config) (_config<<2)
+#define PEAK_I_MASK 0x60
+
+/* Fault Mask */
+#define FAULT_TIMEOUT (1<<0)
+#define FAULT_OVERTEMP (1<<1)
+#define FAULT_SHORT_CIRCUIT (1<<2)
+
+#define to_lm3560_led_flash(sd, _id)\
+   container_of(sd, struct lm3560_flash, subdev_led##_id)
+
+enum led_enable {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/* struct lm3560_flash
+ *
+ * @pdata: platform data
+ * @regmap: reg. map for i2c
+ * @power_lock: Protects power_count
+ * @power_count: Power reference count
+ * @led_mode: V4L2 LED mode
+ * @fault: falut data
+ * @ctrls_led#: V4L2 contols
+ * @subdev_led#: V4L2 subdev
+ */
+struct lm3560_flash {
+   struct lm3560_platform_data *pdata;
+   struct regmap *regmap;
+   struct mutex power_lock;
+   int power_count;
+
+   enum v4l2_flash_led_mode led_mode;
+   u8 fault;
+   /* LED1 */
+   struct v4l2_ctrl_handler ctrls_led1;
+   struct v4l2_subdev subdev_led1;
+   /* LED2 */