summaryrefslogtreecommitdiff
path: root/drivers/leds/leds-lp55xx-common.c
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 18:09:56 +0900
committerBryan Wu <cooloney@gmail.com>2013-02-06 15:59:27 -0800
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 bbf2bbf0380..6fede0b9671 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)
lp55xx_write(chip, addr, val);
}
+static int lp55xx_detect_device(struct lp55xx_chip *chip)
+{
+ struct lp55xx_device_config *cfg = chip->cfg;
+ u8 addr = cfg->enable.addr;
+ u8 val = cfg->enable.val;
+ int ret;
+
+ ret = lp55xx_write(chip, addr, val);
+ if (ret)
+ return ret;
+
+ usleep_range(1000, 2000);
+
+ ret = lp55xx_read(chip, addr, &val);
+ if (ret)
+ return ret;
+
+ if (val != cfg->enable.val)
+ return -ENODEV;
+
+ return 0;
+}
+
int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
{
return i2c_smbus_write_byte_data(chip->cl, reg, val);
@@ -103,6 +126,12 @@ int lp55xx_init_device(struct lp55xx_chip *chip)
*/
usleep_range(10000, 20000);
+ ret = lp55xx_detect_device(chip);
+ if (ret) {
+ dev_err(dev, "device detection err: %d\n", ret);
+ goto err;
+ }
+
err:
return ret;
}