aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lp55xx-common.c
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 04:09:56 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-06 18:59:27 -0500
commite3a700d8aae190e09fb06abe0ddd2e172a682508 (patch)
tree3cc952ab61cfb1219f2a43a5e0e738dd2fd7ae10 /drivers/leds/leds-lp55xx-common.c
parent48068d5de16c23c256c085b2cd3ff03bec393900 (diff)
leds-lp55xx: use lp55xx common init function - detect
LP5521/5523 chip detection functions are replaced with lp55xx common function, lp55xx_detect_device(). Chip dependent address and values are configurable in each driver. In init function, chip detection is executed. Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds/leds-lp55xx-common.c')
-rw-r--r--drivers/leds/leds-lp55xx-common.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index bbf2bbf03807..6fede0b96715 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -30,6 +30,29 @@ static void lp55xx_reset_device(struct lp55xx_chip *chip)
30 lp55xx_write(chip, addr, val); 30 lp55xx_write(chip, addr, val);
31} 31}
32 32
33static int lp55xx_detect_device(struct lp55xx_chip *chip)
34{
35 struct lp55xx_device_config *cfg = chip->cfg;
36 u8 addr = cfg->enable.addr;
37 u8 val = cfg->enable.val;
38 int ret;
39
40 ret = lp55xx_write(chip, addr, val);
41 if (ret)
42 return ret;
43
44 usleep_range(1000, 2000);
45
46 ret = lp55xx_read(chip, addr, &val);
47 if (ret)
48 return ret;
49
50 if (val != cfg->enable.val)
51 return -ENODEV;
52
53 return 0;
54}
55
33int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val) 56int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
34{ 57{
35 return i2c_smbus_write_byte_data(chip->cl, reg, val); 58 return i2c_smbus_write_byte_data(chip->cl, reg, val);
@@ -103,6 +126,12 @@ int lp55xx_init_device(struct lp55xx_chip *chip)
103 */ 126 */
104 usleep_range(10000, 20000); 127 usleep_range(10000, 20000);
105 128
129 ret = lp55xx_detect_device(chip);
130 if (ret) {
131 dev_err(dev, "device detection err: %d\n", ret);
132 goto err;
133 }
134
106err: 135err:
107 return ret; 136 return ret;
108} 137}