2 * LP5521/LP5523/LP55231 Common Driver
4 * Copyright 2012 Texas Instruments
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
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.
12 * Derived from leds-lp5521.c, leds-lp5523.c
15 #include <linux/delay.h>
16 #include <linux/i2c.h>
17 #include <linux/leds.h>
18 #include <linux/module.h>
19 #include <linux/platform_data/leds-lp55xx.h>
21 #include "leds-lp55xx-common.h"
23 static void lp55xx_reset_device(struct lp55xx_chip *chip)
25 struct lp55xx_device_config *cfg = chip->cfg;
26 u8 addr = cfg->reset.addr;
27 u8 val = cfg->reset.val;
29 /* no error checking here because no ACK from the device after reset */
30 lp55xx_write(chip, addr, val);
33 static int lp55xx_detect_device(struct lp55xx_chip *chip)
35 struct lp55xx_device_config *cfg = chip->cfg;
36 u8 addr = cfg->enable.addr;
37 u8 val = cfg->enable.val;
40 ret = lp55xx_write(chip, addr, val);
44 usleep_range(1000, 2000);
46 ret = lp55xx_read(chip, addr, &val);
50 if (val != cfg->enable.val)
56 static int lp55xx_post_init_device(struct lp55xx_chip *chip)
58 struct lp55xx_device_config *cfg = chip->cfg;
60 if (!cfg->post_init_device)
63 return cfg->post_init_device(chip);
66 int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
68 return i2c_smbus_write_byte_data(chip->cl, reg, val);
70 EXPORT_SYMBOL_GPL(lp55xx_write);
72 int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val)
76 ret = i2c_smbus_read_byte_data(chip->cl, reg);
83 EXPORT_SYMBOL_GPL(lp55xx_read);
85 int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, u8 mask, u8 val)
90 ret = lp55xx_read(chip, reg, &tmp);
97 return lp55xx_write(chip, reg, tmp);
99 EXPORT_SYMBOL_GPL(lp55xx_update_bits);
101 int lp55xx_init_device(struct lp55xx_chip *chip)
103 struct lp55xx_platform_data *pdata;
104 struct lp55xx_device_config *cfg;
105 struct device *dev = &chip->cl->dev;
116 if (pdata->setup_resources) {
117 ret = pdata->setup_resources();
119 dev_err(dev, "setup resoure err: %d\n", ret);
126 usleep_range(1000, 2000); /* Keep enable down at least 1ms */
128 usleep_range(1000, 2000); /* 500us abs min. */
131 lp55xx_reset_device(chip);
134 * Exact value is not available. 10 - 20ms
135 * appears to be enough for reset.
137 usleep_range(10000, 20000);
139 ret = lp55xx_detect_device(chip);
141 dev_err(dev, "device detection err: %d\n", ret);
145 /* chip specific initialization */
146 ret = lp55xx_post_init_device(chip);
148 dev_err(dev, "post init device err: %d\n", ret);
157 if (pdata->release_resources)
158 pdata->release_resources();
162 EXPORT_SYMBOL_GPL(lp55xx_init_device);
164 MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
165 MODULE_DESCRIPTION("LP55xx Common Driver");
166 MODULE_LICENSE("GPL");