43 #include <linux/module.h>
45 #include <linux/string.h>
46 #include <linux/ctype.h>
49 #include <linux/i2c.h>
51 #include <linux/slab.h>
54 #define PCA955X_LS_LED_ON 0x0
55 #define PCA955X_LS_LED_OFF 0x1
56 #define PCA955X_LS_BLINK0 0x2
57 #define PCA955X_LS_BLINK1 0x3
121 static inline int pca95xx_num_input_regs(
int bits)
123 return (bits + 7) / 8;
127 static inline int pca95xx_num_led_regs(
int bits)
129 return (bits + 3) / 4;
136 static inline u8 pca955x_ledsel(
u8 oldval,
int led_num,
int state)
138 return (oldval & (~(0x3 << (led_num << 1)))) |
139 ((state & 0x3) << (led_num << 1));
151 pca95xx_num_input_regs(pca955x->
chipdef->bits) + 2*n,
162 static void pca955x_write_pwm(
struct i2c_client *client,
int n,
u8 val)
164 struct pca955x *pca955x = i2c_get_clientdata(client);
167 pca95xx_num_input_regs(pca955x->
chipdef->bits) + 1 + 2*n,
175 static void pca955x_write_ls(
struct i2c_client *client,
int n,
u8 val)
177 struct pca955x *pca955x = i2c_get_clientdata(client);
180 pca95xx_num_input_regs(pca955x->
chipdef->bits) + 4 + n,
188 static u8 pca955x_read_ls(
struct i2c_client *client,
int n)
190 struct pca955x *pca955x = i2c_get_clientdata(client);
193 pca95xx_num_input_regs(pca955x->
chipdef->bits) + 4 + n);
199 struct pca955x *pca955x;
204 pca955x_led =
container_of(work,
struct pca955x_led, work);
205 pca955x = pca955x_led->
pca955x;
207 chip_ls = pca955x_led->
led_num / 4;
208 ls_led = pca955x_led->
led_num % 4;
212 ls = pca955x_read_ls(pca955x->
client, chip_ls);
232 pca955x_write_pwm(pca955x->
client, 1,
238 pca955x_write_ls(pca955x->
client, chip_ls, ls);
247 pca955x =
container_of(led_cdev,
struct pca955x_led, led_cdev);
261 struct pca955x *pca955x;
262 struct pca955x_led *pca955x_led;
268 chip = &pca955x_chipdefs[
id->driver_data];
270 pdata = client->
dev.platform_data;
275 dev_err(&client->
dev,
"invalid slave address %02x\n",
281 "slave address 0x%02x\n",
289 dev_err(&client->
dev,
"board info claims %d LEDs"
290 " on a %d-bit chip\n",
305 i2c_set_clientdata(client, pca955x);
311 for (i = 0; i < chip->
bits; i++) {
312 pca955x_led = &pca955x->
leds[
i];
314 pca955x_led->
pca955x = pca955x;
318 if (pdata->
leds[i].name)
320 sizeof(pca955x_led->
name),
"pca955x:%s",
321 pdata->
leds[i].name);
322 if (pdata->
leds[i].default_trigger)
323 pca955x_led->
led_cdev.default_trigger =
324 pdata->
leds[
i].default_trigger;
331 pca955x_led->
led_cdev.brightness_set = pca955x_led_set;
342 for (i = 0; i < pca95xx_num_led_regs(chip->
bits); i++)
343 pca955x_write_ls(client, i, 0x55);
346 pca955x_write_pwm(client, 0, 255-
LED_HALF);
349 pca955x_write_pwm(client, 1, 0);
352 pca955x_write_psc(client, 0, 0);
353 pca955x_write_psc(client, 1, 0);
368 struct pca955x *pca955x = i2c_get_clientdata(client);
371 for (i = 0; i < pca955x->
chipdef->bits; i++) {
381 .name =
"leds-pca955x",
384 .probe = pca955x_probe,
386 .id_table = pca955x_id,