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 int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
58 return i2c_smbus_write_byte_data(chip->cl, reg, val);
60 EXPORT_SYMBOL_GPL(lp55xx_write);
62 int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val)
66 ret = i2c_smbus_read_byte_data(chip->cl, reg);
73 EXPORT_SYMBOL_GPL(lp55xx_read);
75 int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, u8 mask, u8 val)
80 ret = lp55xx_read(chip, reg, &tmp);
87 return lp55xx_write(chip, reg, tmp);
89 EXPORT_SYMBOL_GPL(lp55xx_update_bits);
91 int lp55xx_init_device(struct lp55xx_chip *chip)
93 struct lp55xx_platform_data *pdata;
94 struct lp55xx_device_config *cfg;
95 struct device *dev = &chip->cl->dev;
106 if (pdata->setup_resources) {
107 ret = pdata->setup_resources();
109 dev_err(dev, "setup resoure err: %d\n", ret);
116 usleep_range(1000, 2000); /* Keep enable down at least 1ms */
118 usleep_range(1000, 2000); /* 500us abs min. */
121 lp55xx_reset_device(chip);
124 * Exact value is not available. 10 - 20ms
125 * appears to be enough for reset.
127 usleep_range(10000, 20000);
129 ret = lp55xx_detect_device(chip);
131 dev_err(dev, "device detection err: %d\n", ret);
138 EXPORT_SYMBOL_GPL(lp55xx_init_device);
140 MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
141 MODULE_DESCRIPTION("LP55xx Common Driver");
142 MODULE_LICENSE("GPL");