aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 04:01:23 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-06 18:59:26 -0500
commitc93d08fa75020835741c7b1d0523ff854e8acde1 (patch)
tree8cbc5dc9100ea73a9204bc84c6fdb90fc578e671 /drivers/leds
parentf6c64c6fc8d793b414446f1a655a37b7bfce68e3 (diff)
leds-lp55xx: add new common driver for lp5521/5523
This patch supports basic common driver code for LP5521, LP5523/55231 devices. ( Driver Structure Data ) lp55xx_led and lp55xx_chip In lp55xx common driver, two different data structure is used. o lp55xx_led control multi output LED channels such as led current, channel index. o lp55xx_chip general chip control such like the I2C and platform data. For example, LP5521 has maximum 3 LED channels. LP5523/55231 has 9 output channels. lp55xx_chip for LP5521 ... lp55xx_led #1 lp55xx_led #2 lp55xx_led #3 lp55xx_chip for LP5523 ... lp55xx_led #1 lp55xx_led #2 . . lp55xx_led #9 ( Platform Data ) LP5521 and LP5523/55231 have own specific platform data. However, this data can be handled with just one platform data structure. The lp55xx platform data is declared in the header. This structure is derived from leds-lp5521.h and leds-lp5523.h Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/Kconfig9
-rw-r--r--drivers/leds/Makefile1
-rw-r--r--drivers/leds/leds-lp55xx-common.c59
-rw-r--r--drivers/leds/leds-lp55xx-common.h61
4 files changed, 130 insertions, 0 deletions
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index b58bc8a14b9c..3d7822b3498f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -193,9 +193,17 @@ config LEDS_LP3944
193 To compile this driver as a module, choose M here: the 193 To compile this driver as a module, choose M here: the
194 module will be called leds-lp3944. 194 module will be called leds-lp3944.
195 195
196config LEDS_LP55XX_COMMON
197 tristate "Common Driver for TI/National LP5521 and LP5523/55231"
198 depends on LEDS_LP5521 || LEDS_LP5523
199 help
200 This option supports common operations for LP5521 and LP5523/55231
201 devices.
202
196config LEDS_LP5521 203config LEDS_LP5521
197 tristate "LED Support for N.S. LP5521 LED driver chip" 204 tristate "LED Support for N.S. LP5521 LED driver chip"
198 depends on LEDS_CLASS && I2C 205 depends on LEDS_CLASS && I2C
206 select LEDS_LP55XX_COMMON
199 help 207 help
200 If you say yes here you get support for the National Semiconductor 208 If you say yes here you get support for the National Semiconductor
201 LP5521 LED driver. It is 3 channel chip with programmable engines. 209 LP5521 LED driver. It is 3 channel chip with programmable engines.
@@ -205,6 +213,7 @@ config LEDS_LP5521
205config LEDS_LP5523 213config LEDS_LP5523
206 tristate "LED Support for TI/National LP5523/55231 LED driver chip" 214 tristate "LED Support for TI/National LP5523/55231 LED driver chip"
207 depends on LEDS_CLASS && I2C 215 depends on LEDS_CLASS && I2C
216 select LEDS_LP55XX_COMMON
208 help 217 help
209 If you say yes here you get support for TI/National Semiconductor 218 If you say yes here you get support for TI/National Semiconductor
210 LP5523/55231 LED driver. 219 LP5523/55231 LED driver.
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3fb9641b6194..215e7e3b6173 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_LEDS_PCA9532) += leds-pca9532.o
23obj-$(CONFIG_LEDS_GPIO_REGISTER) += leds-gpio-register.o 23obj-$(CONFIG_LEDS_GPIO_REGISTER) += leds-gpio-register.o
24obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o 24obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
25obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o 25obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o
26obj-$(CONFIG_LEDS_LP55XX_COMMON) += leds-lp55xx-common.o
26obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o 27obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o
27obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o 28obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o
28obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o 29obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
new file mode 100644
index 000000000000..1c716ecfa817
--- /dev/null
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -0,0 +1,59 @@
1/*
2 * LP5521/LP5523/LP55231 Common Driver
3 *
4 * Copyright 2012 Texas Instruments
5 *
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Derived from leds-lp5521.c, leds-lp5523.c
13 */
14
15#include <linux/i2c.h>
16#include <linux/leds.h>
17#include <linux/module.h>
18#include <linux/platform_data/leds-lp55xx.h>
19
20#include "leds-lp55xx-common.h"
21
22int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
23{
24 return i2c_smbus_write_byte_data(chip->cl, reg, val);
25}
26EXPORT_SYMBOL_GPL(lp55xx_write);
27
28int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val)
29{
30 s32 ret;
31
32 ret = i2c_smbus_read_byte_data(chip->cl, reg);
33 if (ret < 0)
34 return ret;
35
36 *val = ret;
37 return 0;
38}
39EXPORT_SYMBOL_GPL(lp55xx_read);
40
41int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, u8 mask, u8 val)
42{
43 int ret;
44 u8 tmp;
45
46 ret = lp55xx_read(chip, reg, &tmp);
47 if (ret)
48 return ret;
49
50 tmp &= ~mask;
51 tmp |= val & mask;
52
53 return lp55xx_write(chip, reg, tmp);
54}
55EXPORT_SYMBOL_GPL(lp55xx_update_bits);
56
57MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
58MODULE_DESCRIPTION("LP55xx Common Driver");
59MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h
new file mode 100644
index 000000000000..369cb9c91f17
--- /dev/null
+++ b/drivers/leds/leds-lp55xx-common.h
@@ -0,0 +1,61 @@
1/*
2 * LP55XX Common Driver Header
3 *
4 * Copyright (C) 2012 Texas Instruments
5 *
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * Derived from leds-lp5521.c, leds-lp5523.c
13 */
14
15#ifndef _LEDS_LP55XX_COMMON_H
16#define _LEDS_LP55XX_COMMON_H
17
18struct lp55xx_led;
19struct lp55xx_chip;
20
21/*
22 * struct lp55xx_chip
23 * @cl : I2C communication for access registers
24 * @pdata : Platform specific data
25 * @lock : Lock for user-space interface
26 * @num_leds : Number of registered LEDs
27 */
28struct lp55xx_chip {
29 struct i2c_client *cl;
30 struct lp55xx_platform_data *pdata;
31 struct mutex lock; /* lock for user-space interface */
32 int num_leds;
33};
34
35/*
36 * struct lp55xx_led
37 * @chan_nr : Channel number
38 * @cdev : LED class device
39 * @led_current : Current setting at each led channel
40 * @max_current : Maximun current at each led channel
41 * @brightness_work : Workqueue for brightness control
42 * @brightness : Brightness value
43 * @chip : The lp55xx chip data
44 */
45struct lp55xx_led {
46 int chan_nr;
47 struct led_classdev cdev;
48 u8 led_current;
49 u8 max_current;
50 struct work_struct brightness_work;
51 u8 brightness;
52 struct lp55xx_chip *chip;
53};
54
55/* register access */
56extern int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val);
57extern int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val);
58extern int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg,
59 u8 mask, u8 val);
60
61#endif /* _LEDS_LP55XX_COMMON_H */