aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lp55xx-common.c
diff options
context:
space:
mode:
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}