]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/leds/leds-lp55xx-common.c
1fab1d1c45026e464f00f8f00ac7696923e8cbe6
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 static int lp55xx_init_led(struct lp55xx_led
*led
,
67 struct lp55xx_chip
*chip
, int chan
)
72 int lp55xx_write(struct lp55xx_chip
*chip
, u8 reg
, u8 val
)
74 return i2c_smbus_write_byte_data(chip
->cl
, reg
, val
);
76 EXPORT_SYMBOL_GPL(lp55xx_write
);
78 int lp55xx_read(struct lp55xx_chip
*chip
, u8 reg
, u8
*val
)
82 ret
= i2c_smbus_read_byte_data(chip
->cl
, reg
);
89 EXPORT_SYMBOL_GPL(lp55xx_read
);
91 int lp55xx_update_bits(struct lp55xx_chip
*chip
, u8 reg
, u8 mask
, u8 val
)
96 ret
= lp55xx_read(chip
, reg
, &tmp
);
103 return lp55xx_write(chip
, reg
, tmp
);
105 EXPORT_SYMBOL_GPL(lp55xx_update_bits
);
107 int lp55xx_init_device(struct lp55xx_chip
*chip
)
109 struct lp55xx_platform_data
*pdata
;
110 struct lp55xx_device_config
*cfg
;
111 struct device
*dev
= &chip
->cl
->dev
;
122 if (pdata
->setup_resources
) {
123 ret
= pdata
->setup_resources();
125 dev_err(dev
, "setup resoure err: %d\n", ret
);
132 usleep_range(1000, 2000); /* Keep enable down at least 1ms */
134 usleep_range(1000, 2000); /* 500us abs min. */
137 lp55xx_reset_device(chip
);
140 * Exact value is not available. 10 - 20ms
141 * appears to be enough for reset.
143 usleep_range(10000, 20000);
145 ret
= lp55xx_detect_device(chip
);
147 dev_err(dev
, "device detection err: %d\n", ret
);
151 /* chip specific initialization */
152 ret
= lp55xx_post_init_device(chip
);
154 dev_err(dev
, "post init device err: %d\n", ret
);
161 lp55xx_deinit_device(chip
);
165 EXPORT_SYMBOL_GPL(lp55xx_init_device
);
167 void lp55xx_deinit_device(struct lp55xx_chip
*chip
)
169 struct lp55xx_platform_data
*pdata
= chip
->pdata
;
174 if (pdata
->release_resources
)
175 pdata
->release_resources();
177 EXPORT_SYMBOL_GPL(lp55xx_deinit_device
);
179 int lp55xx_register_leds(struct lp55xx_led
*led
, struct lp55xx_chip
*chip
)
181 struct lp55xx_platform_data
*pdata
= chip
->pdata
;
182 struct lp55xx_device_config
*cfg
= chip
->cfg
;
183 int num_channels
= pdata
->num_channels
;
184 struct lp55xx_led
*each
;
189 if (!cfg
->brightness_work_fn
) {
190 dev_err(&chip
->cl
->dev
, "empty brightness configuration\n");
194 for (i
= 0; i
< num_channels
; i
++) {
196 /* do not initialize channels that are not connected */
197 if (pdata
->led_config
[i
].led_current
== 0)
200 led_current
= pdata
->led_config
[i
].led_current
;
202 ret
= lp55xx_init_led(each
, chip
, i
);
206 INIT_WORK(&each
->brightness_work
, cfg
->brightness_work_fn
);
211 /* setting led current at each channel */
212 if (cfg
->set_led_current
)
213 cfg
->set_led_current(each
, led_current
);
219 for (i
= 0; i
< chip
->num_leds
; i
++) {
221 led_classdev_unregister(&each
->cdev
);
222 flush_work(&each
->brightness_work
);
226 EXPORT_SYMBOL_GPL(lp55xx_register_leds
);
228 MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
229 MODULE_DESCRIPTION("LP55xx Common Driver");
230 MODULE_LICENSE("GPL");