Re: [PATCH 1/1 v1] leds: Add LED driver for lm3554 chip
On Sat, Jul 14, 2012 at 9:30 PM, G.Shark Jeong wrote: > From: "G.Shark Jeong" > > LM3554 : > The LM3554 is a 2 MHz fixed-frequency synchronous boost > converter with 1.2A dual high side led drivers. > Datasheet: www.ti.com > I agree with Shuah here. Could we work out an generic version for this LM355x chip driver? I compared this leds-lm3554.c with leds-lm3556.c and found the most differences are in register definition, but driver flow and mechanism are all most the same. Please think about it and we don't like duplicate code. Thanks, -Bryan > Signed-off-by: G.Shark Jeong > --- > drivers/leds/Kconfig |8 + > drivers/leds/Makefile |1 + > drivers/leds/leds-lm3554.c| 324 > + > include/linux/platform_data/leds-lm3554.h | 66 ++ > 4 files changed, 399 insertions(+), 0 deletions(-) > create mode 100644 drivers/leds/leds-lm3554.c > create mode 100644 include/linux/platform_data/leds-lm3554.h > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > index 12b2b55..ad54bc2 100644 > --- a/drivers/leds/Kconfig > +++ b/drivers/leds/Kconfig > @@ -415,6 +415,14 @@ config LEDS_MAX8997 > This option enables support for on-chip LED drivers on > MAXIM MAX8997 PMIC. > > +config LEDS_LM3554 > + tristate "LED support for LM3554" > + depends on LEDS_CLASS && I2C > + select REGMAP_I2C > + help > + This option enables support for LEDs connected to LM3554. > + LM3554 includes Torch, Flash and Indicator functions. > + > config LEDS_OT200 > tristate "LED support for the Bachmann OT200" > depends on LEDS_CLASS && HAS_IOMEM > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > index f8958cd..19903ed 100644 > --- a/drivers/leds/Makefile > +++ b/drivers/leds/Makefile > @@ -47,6 +47,7 @@ obj-$(CONFIG_LEDS_NETXBIG)+= leds-netxbig.o > obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o > obj-$(CONFIG_LEDS_RENESAS_TPU) += leds-renesas-tpu.o > obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o > +obj-$(CONFIG_LEDS_LM3554) += leds-lm3554.o > > # LED SPI Drivers > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > diff --git a/drivers/leds/leds-lm3554.c b/drivers/leds/leds-lm3554.c > new file mode 100644 > index 000..55461f1 > --- /dev/null > +++ b/drivers/leds/leds-lm3554.c > @@ -0,0 +1,324 @@ > +/* > +* Simple driver for Texas Instruments LM3554 LED Flash driver chip > +* Copyright (C) 2012 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. > +* > +*/ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define REG_TORCH (0xA0) > +#define REG_FLASH (0xB0) > +#define REG_FLASH_TIME (0xC0) > +#define REG_FLAG (0xD0) > +#define REG_CONF1 (0xE0) > +#define REG_CONF2 (0xF0) > +#define REG_GPIO (0x20) > +#define REG_VIN_MON(0x80) > +#define REG_MAXREG_VIN_MON > + > +enum lm3554_mode { > + MODE_SHDN = 0, > + MODE_INDIC, > + MODE_TORCH, > + MODE_FLASH, > + MODE_VOUT, > + MODE_VOUT_INDIC, > + MODE_VOUT_TORCH, > + MODE_VOUT_FLASH, > +}; > + > +struct lm3554_chip_data { > + struct device *dev; > + > + struct led_classdev cdev_flash; > + struct led_classdev cdev_torch; > + struct led_classdev cdev_indicator; > + > + struct lm3554_platform_data *pdata; > + > + struct mutex lock; > + struct regmap *regmap; > + unsigned int last_flag; > +}; > + > +/* chip initialize */ > +static int __devinit lm3554_chip_init(struct lm3554_chip_data *chip) > +{ > + int ret; > + unsigned int reg_val; > + struct lm3554_platform_data *pdata = chip->pdata; > + > + /* input and output pins configuration */ > + reg_val = pdata->pin_strobe | pdata->pin_tx1 > + | pdata->pin_tx2 | pdata->ledi_pin; > + ret = regmap_update_bits(chip->regmap, REG_CONF1, 0xAC, reg_val); > + if (ret < 0) > + goto out; > + > + return ret; > +out: > + dev_err(chip->dev, "%s:i2c access fail to register\n", __func__); > + return ret; > +} > + > +/* chip control */ > +static void lm3554_control(struct lm3554_chip_data *chip, > + u8 brightness, enum lm3554_mode opmode) > +{ > + int ret; > + unsigned int reg_val; > + struct lm3554_platform_data *pdata = chip->pdata; > + > + ret = regmap_read(chip->regmap, REG_FLAG, >last_flag); > + if (ret < 0) > + goto out; > + if (chip->last_flag) > + dev_info(chip->dev, "LM3554 Last
[PATCH 1/1 v1] leds: Add LED driver for lm3554 chip
From: "G.Shark Jeong" LM3554 : The LM3554 is a 2 MHz fixed-frequency synchronous boost converter with 1.2A dual high side led drivers. Datasheet: www.ti.com Signed-off-by: G.Shark Jeong --- drivers/leds/Kconfig |8 + drivers/leds/Makefile |1 + drivers/leds/leds-lm3554.c| 324 + include/linux/platform_data/leds-lm3554.h | 66 ++ 4 files changed, 399 insertions(+), 0 deletions(-) create mode 100644 drivers/leds/leds-lm3554.c create mode 100644 include/linux/platform_data/leds-lm3554.h diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 12b2b55..ad54bc2 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -415,6 +415,14 @@ config LEDS_MAX8997 This option enables support for on-chip LED drivers on MAXIM MAX8997 PMIC. +config LEDS_LM3554 + tristate "LED support for LM3554" + depends on LEDS_CLASS && I2C + select REGMAP_I2C + help + This option enables support for LEDs connected to LM3554. + LM3554 includes Torch, Flash and Indicator functions. + config LEDS_OT200 tristate "LED support for the Bachmann OT200" depends on LEDS_CLASS && HAS_IOMEM diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index f8958cd..19903ed 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_LEDS_NETXBIG)+= leds-netxbig.o obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o obj-$(CONFIG_LEDS_RENESAS_TPU) += leds-renesas-tpu.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o +obj-$(CONFIG_LEDS_LM3554) += leds-lm3554.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-lm3554.c b/drivers/leds/leds-lm3554.c new file mode 100644 index 000..55461f1 --- /dev/null +++ b/drivers/leds/leds-lm3554.c @@ -0,0 +1,324 @@ +/* +* Simple driver for Texas Instruments LM3554 LED Flash driver chip +* Copyright (C) 2012 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. +* +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REG_TORCH (0xA0) +#define REG_FLASH (0xB0) +#define REG_FLASH_TIME (0xC0) +#define REG_FLAG (0xD0) +#define REG_CONF1 (0xE0) +#define REG_CONF2 (0xF0) +#define REG_GPIO (0x20) +#define REG_VIN_MON(0x80) +#define REG_MAXREG_VIN_MON + +enum lm3554_mode { + MODE_SHDN = 0, + MODE_INDIC, + MODE_TORCH, + MODE_FLASH, + MODE_VOUT, + MODE_VOUT_INDIC, + MODE_VOUT_TORCH, + MODE_VOUT_FLASH, +}; + +struct lm3554_chip_data { + struct device *dev; + + struct led_classdev cdev_flash; + struct led_classdev cdev_torch; + struct led_classdev cdev_indicator; + + struct lm3554_platform_data *pdata; + + struct mutex lock; + struct regmap *regmap; + unsigned int last_flag; +}; + +/* chip initialize */ +static int __devinit lm3554_chip_init(struct lm3554_chip_data *chip) +{ + int ret; + unsigned int reg_val; + struct lm3554_platform_data *pdata = chip->pdata; + + /* input and output pins configuration */ + reg_val = pdata->pin_strobe | pdata->pin_tx1 + | pdata->pin_tx2 | pdata->ledi_pin; + ret = regmap_update_bits(chip->regmap, REG_CONF1, 0xAC, reg_val); + if (ret < 0) + goto out; + + return ret; +out: + dev_err(chip->dev, "%s:i2c access fail to register\n", __func__); + return ret; +} + +/* chip control */ +static void lm3554_control(struct lm3554_chip_data *chip, + u8 brightness, enum lm3554_mode opmode) +{ + int ret; + unsigned int reg_val; + struct lm3554_platform_data *pdata = chip->pdata; + + ret = regmap_read(chip->regmap, REG_FLAG, >last_flag); + if (ret < 0) + goto out; + if (chip->last_flag) + dev_info(chip->dev, "LM3554 Last FLAG is 0x%x\n", +chip->last_flag); + /* brightness 0 means shutdown */ + if (!brightness) + opmode = MODE_SHDN; + + switch (opmode) { + case MODE_TORCH: + if (pdata->pin_tx1 == LM3554_TX1_HW_TORCH) { + ret = regmap_update_bits(chip->regmap, +REG_CONF1, 0x80, 0x80); + if (ret < 0) + goto out; + opmode = MODE_SHDN; + } + ret = regmap_update_bits(chip->regmap, +REG_TORCH,
[PATCH 1/1 v1] leds: Add LED driver for lm3554 chip
From: G.Shark Jeong gshark.je...@gmail.com LM3554 : The LM3554 is a 2 MHz fixed-frequency synchronous boost converter with 1.2A dual high side led drivers. Datasheet: www.ti.com Signed-off-by: G.Shark Jeong gshark.je...@gmail.com --- drivers/leds/Kconfig |8 + drivers/leds/Makefile |1 + drivers/leds/leds-lm3554.c| 324 + include/linux/platform_data/leds-lm3554.h | 66 ++ 4 files changed, 399 insertions(+), 0 deletions(-) create mode 100644 drivers/leds/leds-lm3554.c create mode 100644 include/linux/platform_data/leds-lm3554.h diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 12b2b55..ad54bc2 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -415,6 +415,14 @@ config LEDS_MAX8997 This option enables support for on-chip LED drivers on MAXIM MAX8997 PMIC. +config LEDS_LM3554 + tristate LED support for LM3554 + depends on LEDS_CLASS I2C + select REGMAP_I2C + help + This option enables support for LEDs connected to LM3554. + LM3554 includes Torch, Flash and Indicator functions. + config LEDS_OT200 tristate LED support for the Bachmann OT200 depends on LEDS_CLASS HAS_IOMEM diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index f8958cd..19903ed 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_LEDS_NETXBIG)+= leds-netxbig.o obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o obj-$(CONFIG_LEDS_RENESAS_TPU) += leds-renesas-tpu.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o +obj-$(CONFIG_LEDS_LM3554) += leds-lm3554.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-lm3554.c b/drivers/leds/leds-lm3554.c new file mode 100644 index 000..55461f1 --- /dev/null +++ b/drivers/leds/leds-lm3554.c @@ -0,0 +1,324 @@ +/* +* Simple driver for Texas Instruments LM3554 LED Flash driver chip +* Copyright (C) 2012 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. +* +*/ +#include linux/module.h +#include linux/delay.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/platform_data/leds-lm3554.h + +#define REG_TORCH (0xA0) +#define REG_FLASH (0xB0) +#define REG_FLASH_TIME (0xC0) +#define REG_FLAG (0xD0) +#define REG_CONF1 (0xE0) +#define REG_CONF2 (0xF0) +#define REG_GPIO (0x20) +#define REG_VIN_MON(0x80) +#define REG_MAXREG_VIN_MON + +enum lm3554_mode { + MODE_SHDN = 0, + MODE_INDIC, + MODE_TORCH, + MODE_FLASH, + MODE_VOUT, + MODE_VOUT_INDIC, + MODE_VOUT_TORCH, + MODE_VOUT_FLASH, +}; + +struct lm3554_chip_data { + struct device *dev; + + struct led_classdev cdev_flash; + struct led_classdev cdev_torch; + struct led_classdev cdev_indicator; + + struct lm3554_platform_data *pdata; + + struct mutex lock; + struct regmap *regmap; + unsigned int last_flag; +}; + +/* chip initialize */ +static int __devinit lm3554_chip_init(struct lm3554_chip_data *chip) +{ + int ret; + unsigned int reg_val; + struct lm3554_platform_data *pdata = chip-pdata; + + /* input and output pins configuration */ + reg_val = pdata-pin_strobe | pdata-pin_tx1 + | pdata-pin_tx2 | pdata-ledi_pin; + ret = regmap_update_bits(chip-regmap, REG_CONF1, 0xAC, reg_val); + if (ret 0) + goto out; + + return ret; +out: + dev_err(chip-dev, %s:i2c access fail to register\n, __func__); + return ret; +} + +/* chip control */ +static void lm3554_control(struct lm3554_chip_data *chip, + u8 brightness, enum lm3554_mode opmode) +{ + int ret; + unsigned int reg_val; + struct lm3554_platform_data *pdata = chip-pdata; + + ret = regmap_read(chip-regmap, REG_FLAG, chip-last_flag); + if (ret 0) + goto out; + if (chip-last_flag) + dev_info(chip-dev, LM3554 Last FLAG is 0x%x\n, +chip-last_flag); + /* brightness 0 means shutdown */ + if (!brightness) + opmode = MODE_SHDN; + + switch (opmode) { + case MODE_TORCH: + if (pdata-pin_tx1 == LM3554_TX1_HW_TORCH) { + ret = regmap_update_bits(chip-regmap, +REG_CONF1, 0x80, 0x80); + if (ret 0) + goto
Re: [PATCH 1/1 v1] leds: Add LED driver for lm3554 chip
On Sat, Jul 14, 2012 at 9:30 PM, G.Shark Jeong gshark.je...@gmail.com wrote: From: G.Shark Jeong gshark.je...@gmail.com LM3554 : The LM3554 is a 2 MHz fixed-frequency synchronous boost converter with 1.2A dual high side led drivers. Datasheet: www.ti.com I agree with Shuah here. Could we work out an generic version for this LM355x chip driver? I compared this leds-lm3554.c with leds-lm3556.c and found the most differences are in register definition, but driver flow and mechanism are all most the same. Please think about it and we don't like duplicate code. Thanks, -Bryan Signed-off-by: G.Shark Jeong gshark.je...@gmail.com --- drivers/leds/Kconfig |8 + drivers/leds/Makefile |1 + drivers/leds/leds-lm3554.c| 324 + include/linux/platform_data/leds-lm3554.h | 66 ++ 4 files changed, 399 insertions(+), 0 deletions(-) create mode 100644 drivers/leds/leds-lm3554.c create mode 100644 include/linux/platform_data/leds-lm3554.h diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 12b2b55..ad54bc2 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -415,6 +415,14 @@ config LEDS_MAX8997 This option enables support for on-chip LED drivers on MAXIM MAX8997 PMIC. +config LEDS_LM3554 + tristate LED support for LM3554 + depends on LEDS_CLASS I2C + select REGMAP_I2C + help + This option enables support for LEDs connected to LM3554. + LM3554 includes Torch, Flash and Indicator functions. + config LEDS_OT200 tristate LED support for the Bachmann OT200 depends on LEDS_CLASS HAS_IOMEM diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index f8958cd..19903ed 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_LEDS_NETXBIG)+= leds-netxbig.o obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o obj-$(CONFIG_LEDS_RENESAS_TPU) += leds-renesas-tpu.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o +obj-$(CONFIG_LEDS_LM3554) += leds-lm3554.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-lm3554.c b/drivers/leds/leds-lm3554.c new file mode 100644 index 000..55461f1 --- /dev/null +++ b/drivers/leds/leds-lm3554.c @@ -0,0 +1,324 @@ +/* +* Simple driver for Texas Instruments LM3554 LED Flash driver chip +* Copyright (C) 2012 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. +* +*/ +#include linux/module.h +#include linux/delay.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/platform_data/leds-lm3554.h + +#define REG_TORCH (0xA0) +#define REG_FLASH (0xB0) +#define REG_FLASH_TIME (0xC0) +#define REG_FLAG (0xD0) +#define REG_CONF1 (0xE0) +#define REG_CONF2 (0xF0) +#define REG_GPIO (0x20) +#define REG_VIN_MON(0x80) +#define REG_MAXREG_VIN_MON + +enum lm3554_mode { + MODE_SHDN = 0, + MODE_INDIC, + MODE_TORCH, + MODE_FLASH, + MODE_VOUT, + MODE_VOUT_INDIC, + MODE_VOUT_TORCH, + MODE_VOUT_FLASH, +}; + +struct lm3554_chip_data { + struct device *dev; + + struct led_classdev cdev_flash; + struct led_classdev cdev_torch; + struct led_classdev cdev_indicator; + + struct lm3554_platform_data *pdata; + + struct mutex lock; + struct regmap *regmap; + unsigned int last_flag; +}; + +/* chip initialize */ +static int __devinit lm3554_chip_init(struct lm3554_chip_data *chip) +{ + int ret; + unsigned int reg_val; + struct lm3554_platform_data *pdata = chip-pdata; + + /* input and output pins configuration */ + reg_val = pdata-pin_strobe | pdata-pin_tx1 + | pdata-pin_tx2 | pdata-ledi_pin; + ret = regmap_update_bits(chip-regmap, REG_CONF1, 0xAC, reg_val); + if (ret 0) + goto out; + + return ret; +out: + dev_err(chip-dev, %s:i2c access fail to register\n, __func__); + return ret; +} + +/* chip control */ +static void lm3554_control(struct lm3554_chip_data *chip, + u8 brightness, enum lm3554_mode opmode) +{ + int ret; + unsigned int reg_val; + struct lm3554_platform_data *pdata = chip-pdata; + + ret = regmap_read(chip-regmap, REG_FLAG, chip-last_flag); + if (ret 0) + goto out; + if