]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/leds/leds-lp55xx-common.c
leds-lp55xx: use lp55xx common init function - platform data
[karo-tx-linux.git] / drivers / leds / leds-lp55xx-common.c
1 /*
2  * LP5521/LP5523/LP55231 Common Driver
3  *
4  * Copyright 2012 Texas Instruments
5  *
6  * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
7  *
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.
11  *
12  * Derived from leds-lp5521.c, leds-lp5523.c
13  */
14
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>
20
21 #include "leds-lp55xx-common.h"
22
23 int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
24 {
25         return i2c_smbus_write_byte_data(chip->cl, reg, val);
26 }
27 EXPORT_SYMBOL_GPL(lp55xx_write);
28
29 int lp55xx_read(struct lp55xx_chip *chip, u8 reg, u8 *val)
30 {
31         s32 ret;
32
33         ret = i2c_smbus_read_byte_data(chip->cl, reg);
34         if (ret < 0)
35                 return ret;
36
37         *val = ret;
38         return 0;
39 }
40 EXPORT_SYMBOL_GPL(lp55xx_read);
41
42 int lp55xx_update_bits(struct lp55xx_chip *chip, u8 reg, u8 mask, u8 val)
43 {
44         int ret;
45         u8 tmp;
46
47         ret = lp55xx_read(chip, reg, &tmp);
48         if (ret)
49                 return ret;
50
51         tmp &= ~mask;
52         tmp |= val & mask;
53
54         return lp55xx_write(chip, reg, tmp);
55 }
56 EXPORT_SYMBOL_GPL(lp55xx_update_bits);
57
58 int lp55xx_init_device(struct lp55xx_chip *chip)
59 {
60         struct lp55xx_platform_data *pdata;
61         struct device *dev = &chip->cl->dev;
62         int ret = 0;
63
64         WARN_ON(!chip);
65
66         pdata = chip->pdata;
67
68         if (!pdata)
69                 return -EINVAL;
70
71         if (pdata->setup_resources) {
72                 ret = pdata->setup_resources();
73                 if (ret < 0) {
74                         dev_err(dev, "setup resoure err: %d\n", ret);
75                         goto err;
76                 }
77         }
78
79         if (pdata->enable) {
80                 pdata->enable(0);
81                 usleep_range(1000, 2000); /* Keep enable down at least 1ms */
82                 pdata->enable(1);
83                 usleep_range(1000, 2000); /* 500us abs min. */
84         }
85
86 err:
87         return ret;
88 }
89 EXPORT_SYMBOL_GPL(lp55xx_init_device);
90
91 MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
92 MODULE_DESCRIPTION("LP55xx Common Driver");
93 MODULE_LICENSE("GPL");