blob: 71bda3670ff0c34286314f1d3b8ae5dd2186d37f [file] [log] [blame]
Samu Onkalo0efba162010-11-11 14:05:22 -08001/*
2 * lp5523.c - LP5523 LED Driver
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/i2c.h>
26#include <linux/mutex.h>
27#include <linux/gpio.h>
28#include <linux/interrupt.h>
29#include <linux/delay.h>
30#include <linux/ctype.h>
31#include <linux/spinlock.h>
32#include <linux/wait.h>
33#include <linux/leds.h>
34#include <linux/leds-lp5523.h>
35#include <linux/workqueue.h>
36#include <linux/slab.h>
Milo(Woogyom) Kim6a0c9a42013-02-05 18:03:08 +090037#include <linux/platform_data/leds-lp55xx.h>
38
39#include "leds-lp55xx-common.h"
Samu Onkalo0efba162010-11-11 14:05:22 -080040
41#define LP5523_REG_ENABLE 0x00
42#define LP5523_REG_OP_MODE 0x01
43#define LP5523_REG_RATIOMETRIC_MSB 0x02
44#define LP5523_REG_RATIOMETRIC_LSB 0x03
45#define LP5523_REG_ENABLE_LEDS_MSB 0x04
46#define LP5523_REG_ENABLE_LEDS_LSB 0x05
47#define LP5523_REG_LED_CNTRL_BASE 0x06
48#define LP5523_REG_LED_PWM_BASE 0x16
49#define LP5523_REG_LED_CURRENT_BASE 0x26
50#define LP5523_REG_CONFIG 0x36
51#define LP5523_REG_CHANNEL1_PC 0x37
52#define LP5523_REG_CHANNEL2_PC 0x38
53#define LP5523_REG_CHANNEL3_PC 0x39
54#define LP5523_REG_STATUS 0x3a
55#define LP5523_REG_GPO 0x3b
56#define LP5523_REG_VARIABLE 0x3c
57#define LP5523_REG_RESET 0x3d
58#define LP5523_REG_TEMP_CTRL 0x3e
59#define LP5523_REG_TEMP_READ 0x3f
60#define LP5523_REG_TEMP_WRITE 0x40
61#define LP5523_REG_LED_TEST_CTRL 0x41
62#define LP5523_REG_LED_TEST_ADC 0x42
63#define LP5523_REG_ENG1_VARIABLE 0x45
64#define LP5523_REG_ENG2_VARIABLE 0x46
65#define LP5523_REG_ENG3_VARIABLE 0x47
66#define LP5523_REG_MASTER_FADER1 0x48
67#define LP5523_REG_MASTER_FADER2 0x49
68#define LP5523_REG_MASTER_FADER3 0x4a
69#define LP5523_REG_CH1_PROG_START 0x4c
70#define LP5523_REG_CH2_PROG_START 0x4d
71#define LP5523_REG_CH3_PROG_START 0x4e
72#define LP5523_REG_PROG_PAGE_SEL 0x4f
73#define LP5523_REG_PROG_MEM 0x50
74
75#define LP5523_CMD_LOAD 0x15 /* 00010101 */
76#define LP5523_CMD_RUN 0x2a /* 00101010 */
77#define LP5523_CMD_DISABLED 0x00 /* 00000000 */
78
79#define LP5523_ENABLE 0x40
80#define LP5523_AUTO_INC 0x40
81#define LP5523_PWR_SAVE 0x20
82#define LP5523_PWM_PWR_SAVE 0x04
83#define LP5523_CP_1 0x08
84#define LP5523_CP_1_5 0x10
85#define LP5523_CP_AUTO 0x18
86#define LP5523_INT_CLK 0x01
87#define LP5523_AUTO_CLK 0x02
88#define LP5523_EN_LEDTEST 0x80
89#define LP5523_LEDTEST_DONE 0x80
90
91#define LP5523_DEFAULT_CURRENT 50 /* microAmps */
92#define LP5523_PROGRAM_LENGTH 32 /* in bytes */
93#define LP5523_PROGRAM_PAGES 6
94#define LP5523_ADC_SHORTCIRC_LIM 80
95
96#define LP5523_LEDS 9
97#define LP5523_ENGINES 3
98
99#define LP5523_ENG_MASK_BASE 0x30 /* 00110000 */
100
101#define LP5523_ENG_STATUS_MASK 0x07 /* 00000111 */
102
103#define LP5523_IRQ_FLAGS IRQF_TRIGGER_FALLING
104
105#define LP5523_EXT_CLK_USED 0x08
106
107#define LED_ACTIVE(mux, led) (!!(mux & (0x0001 << led)))
108#define SHIFT_MASK(id) (((id) - 1) * 2)
109
Kim, Milo27d77042012-09-04 15:06:18 +0800110enum lp5523_chip_id {
111 LP5523,
112 LP55231,
113};
114
Samu Onkalo0efba162010-11-11 14:05:22 -0800115struct lp5523_engine {
Samu Onkalo0efba162010-11-11 14:05:22 -0800116 int id;
117 u8 mode;
118 u8 prog_page;
119 u8 mux_page;
120 u16 led_mux;
121 u8 engine_mask;
122};
123
124struct lp5523_led {
125 int id;
126 u8 chan_nr;
127 u8 led_current;
128 u8 max_current;
129 struct led_classdev cdev;
130 struct work_struct brightness_work;
131 u8 brightness;
132};
133
134struct lp5523_chip {
135 struct mutex lock; /* Serialize control */
136 struct i2c_client *client;
137 struct lp5523_engine engines[LP5523_ENGINES];
138 struct lp5523_led leds[LP5523_LEDS];
139 struct lp5523_platform_data *pdata;
140 u8 num_channels;
141 u8 num_leds;
142};
143
Samu Onkalo87dbf622010-11-24 12:57:03 -0800144static inline struct lp5523_led *cdev_to_led(struct led_classdev *cdev)
145{
146 return container_of(cdev, struct lp5523_led, cdev);
147}
Samu Onkalo0efba162010-11-11 14:05:22 -0800148
Samu Onkalo87dbf622010-11-24 12:57:03 -0800149static inline struct lp5523_chip *engine_to_lp5523(struct lp5523_engine *engine)
Samu Onkalo0efba162010-11-11 14:05:22 -0800150{
151 return container_of(engine, struct lp5523_chip,
152 engines[engine->id - 1]);
153}
154
Samu Onkalo87dbf622010-11-24 12:57:03 -0800155static inline struct lp5523_chip *led_to_lp5523(struct lp5523_led *led)
Samu Onkalo0efba162010-11-11 14:05:22 -0800156{
157 return container_of(led, struct lp5523_chip,
158 leds[led->id]);
159}
160
Kim, Milo6f6365f2012-08-21 17:03:58 +0800161static void lp5523_set_mode(struct lp5523_engine *engine, u8 mode);
Samu Onkalo0efba162010-11-11 14:05:22 -0800162static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode);
Andrew Mortond06cb462012-03-23 15:02:10 -0700163static int lp5523_load_program(struct lp5523_engine *engine, const u8 *pattern);
Samu Onkalo0efba162010-11-11 14:05:22 -0800164
165static void lp5523_led_brightness_work(struct work_struct *work);
166
167static int lp5523_write(struct i2c_client *client, u8 reg, u8 value)
168{
169 return i2c_smbus_write_byte_data(client, reg, value);
170}
171
172static int lp5523_read(struct i2c_client *client, u8 reg, u8 *buf)
173{
174 s32 ret = i2c_smbus_read_byte_data(client, reg);
175
176 if (ret < 0)
Sachin Kamat5ebab742012-11-20 01:59:01 -0800177 return ret;
Samu Onkalo0efba162010-11-11 14:05:22 -0800178
179 *buf = ret;
180 return 0;
181}
182
183static int lp5523_detect(struct i2c_client *client)
184{
185 int ret;
186 u8 buf;
187
Kim, Milo469eba02012-08-21 17:04:02 +0800188 ret = lp5523_write(client, LP5523_REG_ENABLE, LP5523_ENABLE);
Samu Onkalo0efba162010-11-11 14:05:22 -0800189 if (ret)
190 return ret;
191 ret = lp5523_read(client, LP5523_REG_ENABLE, &buf);
192 if (ret)
193 return ret;
194 if (buf == 0x40)
195 return 0;
196 else
197 return -ENODEV;
198}
199
200static int lp5523_configure(struct i2c_client *client)
201{
202 struct lp5523_chip *chip = i2c_get_clientdata(client);
203 int ret = 0;
204 u8 status;
205
206 /* one pattern per engine setting led mux start and stop addresses */
Andrew Mortond06cb462012-03-23 15:02:10 -0700207 static const u8 pattern[][LP5523_PROGRAM_LENGTH] = {
Samu Onkalo0efba162010-11-11 14:05:22 -0800208 { 0x9c, 0x30, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0},
209 { 0x9c, 0x40, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0},
210 { 0x9c, 0x50, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0},
211 };
212
Samu Onkalo0efba162010-11-11 14:05:22 -0800213 ret |= lp5523_write(client, LP5523_REG_ENABLE, LP5523_ENABLE);
Samu Onkalo2e4840e2010-11-24 12:57:04 -0800214 /* Chip startup time is 500 us, 1 - 2 ms gives some margin */
215 usleep_range(1000, 2000);
Samu Onkalo0efba162010-11-11 14:05:22 -0800216
217 ret |= lp5523_write(client, LP5523_REG_CONFIG,
218 LP5523_AUTO_INC | LP5523_PWR_SAVE |
219 LP5523_CP_AUTO | LP5523_AUTO_CLK |
220 LP5523_PWM_PWR_SAVE);
221
222 /* turn on all leds */
223 ret |= lp5523_write(client, LP5523_REG_ENABLE_LEDS_MSB, 0x01);
224 ret |= lp5523_write(client, LP5523_REG_ENABLE_LEDS_LSB, 0xff);
225
226 /* hardcode 32 bytes of memory for each engine from program memory */
227 ret |= lp5523_write(client, LP5523_REG_CH1_PROG_START, 0x00);
228 ret |= lp5523_write(client, LP5523_REG_CH2_PROG_START, 0x10);
229 ret |= lp5523_write(client, LP5523_REG_CH3_PROG_START, 0x20);
230
231 /* write led mux address space for each channel */
232 ret |= lp5523_load_program(&chip->engines[0], pattern[0]);
233 ret |= lp5523_load_program(&chip->engines[1], pattern[1]);
234 ret |= lp5523_load_program(&chip->engines[2], pattern[2]);
235
236 if (ret) {
237 dev_err(&client->dev, "could not load mux programs\n");
238 return -1;
239 }
240
241 /* set all engines exec state and mode to run 00101010 */
242 ret |= lp5523_write(client, LP5523_REG_ENABLE,
243 (LP5523_CMD_RUN | LP5523_ENABLE));
244
245 ret |= lp5523_write(client, LP5523_REG_OP_MODE, LP5523_CMD_RUN);
246
247 if (ret) {
248 dev_err(&client->dev, "could not start mux programs\n");
249 return -1;
250 }
251
Samu Onkalo2e4840e2010-11-24 12:57:04 -0800252 /* Let the programs run for couple of ms and check the engine status */
253 usleep_range(3000, 6000);
Jingoo Han1b21ec52012-10-28 18:45:11 -0700254 ret = lp5523_read(client, LP5523_REG_STATUS, &status);
255 if (ret < 0)
256 return ret;
257
Samu Onkalo0efba162010-11-11 14:05:22 -0800258 status &= LP5523_ENG_STATUS_MASK;
259
260 if (status == LP5523_ENG_STATUS_MASK) {
261 dev_dbg(&client->dev, "all engines configured\n");
262 } else {
263 dev_info(&client->dev, "status == %x\n", status);
264 dev_err(&client->dev, "cound not configure LED engine\n");
265 return -1;
266 }
267
268 dev_info(&client->dev, "disabling engines\n");
269
270 ret |= lp5523_write(client, LP5523_REG_OP_MODE, LP5523_CMD_DISABLED);
271
272 return ret;
273}
274
275static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode)
276{
277 struct lp5523_chip *chip = engine_to_lp5523(engine);
278 struct i2c_client *client = chip->client;
279 int ret;
280 u8 engine_state;
281
282 ret = lp5523_read(client, LP5523_REG_OP_MODE, &engine_state);
283 if (ret)
284 goto fail;
285
286 engine_state &= ~(engine->engine_mask);
287
288 /* set mode only for this engine */
289 mode &= engine->engine_mask;
290
291 engine_state |= mode;
292
293 ret |= lp5523_write(client, LP5523_REG_OP_MODE, engine_state);
294fail:
295 return ret;
296}
297
298static int lp5523_load_mux(struct lp5523_engine *engine, u16 mux)
299{
300 struct lp5523_chip *chip = engine_to_lp5523(engine);
301 struct i2c_client *client = chip->client;
302 int ret = 0;
303
304 ret |= lp5523_set_engine_mode(engine, LP5523_CMD_LOAD);
305
306 ret |= lp5523_write(client, LP5523_REG_PROG_PAGE_SEL, engine->mux_page);
307 ret |= lp5523_write(client, LP5523_REG_PROG_MEM,
308 (u8)(mux >> 8));
309 ret |= lp5523_write(client, LP5523_REG_PROG_MEM + 1, (u8)(mux));
310 engine->led_mux = mux;
311
312 return ret;
313}
314
Andrew Mortond06cb462012-03-23 15:02:10 -0700315static int lp5523_load_program(struct lp5523_engine *engine, const u8 *pattern)
Samu Onkalo0efba162010-11-11 14:05:22 -0800316{
317 struct lp5523_chip *chip = engine_to_lp5523(engine);
318 struct i2c_client *client = chip->client;
319
320 int ret = 0;
321
322 ret |= lp5523_set_engine_mode(engine, LP5523_CMD_LOAD);
323
324 ret |= lp5523_write(client, LP5523_REG_PROG_PAGE_SEL,
325 engine->prog_page);
326 ret |= i2c_smbus_write_i2c_block_data(client, LP5523_REG_PROG_MEM,
327 LP5523_PROGRAM_LENGTH, pattern);
328
329 return ret;
330}
331
332static int lp5523_run_program(struct lp5523_engine *engine)
333{
334 struct lp5523_chip *chip = engine_to_lp5523(engine);
335 struct i2c_client *client = chip->client;
336 int ret;
337
338 ret = lp5523_write(client, LP5523_REG_ENABLE,
339 LP5523_CMD_RUN | LP5523_ENABLE);
340 if (ret)
341 goto fail;
342
343 ret = lp5523_set_engine_mode(engine, LP5523_CMD_RUN);
344fail:
345 return ret;
346}
347
348static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len)
349{
350 int i;
351 u16 tmp_mux = 0;
Kim, Milo469eba02012-08-21 17:04:02 +0800352
353 len = min_t(int, len, LP5523_LEDS);
Samu Onkalo0efba162010-11-11 14:05:22 -0800354 for (i = 0; i < len; i++) {
355 switch (buf[i]) {
356 case '1':
357 tmp_mux |= (1 << i);
358 break;
359 case '0':
360 break;
361 case '\n':
362 i = len;
363 break;
364 default:
365 return -1;
366 }
367 }
368 *mux = tmp_mux;
369
370 return 0;
371}
372
373static void lp5523_mux_to_array(u16 led_mux, char *array)
374{
375 int i, pos = 0;
376 for (i = 0; i < LP5523_LEDS; i++)
377 pos += sprintf(array + pos, "%x", LED_ACTIVE(led_mux, i));
378
379 array[pos] = '\0';
380}
381
382/*--------------------------------------------------------------*/
383/* Sysfs interface */
384/*--------------------------------------------------------------*/
385
386static ssize_t show_engine_leds(struct device *dev,
387 struct device_attribute *attr,
388 char *buf, int nr)
389{
390 struct i2c_client *client = to_i2c_client(dev);
391 struct lp5523_chip *chip = i2c_get_clientdata(client);
392 char mux[LP5523_LEDS + 1];
393
394 lp5523_mux_to_array(chip->engines[nr - 1].led_mux, mux);
395
396 return sprintf(buf, "%s\n", mux);
397}
398
399#define show_leds(nr) \
400static ssize_t show_engine##nr##_leds(struct device *dev, \
401 struct device_attribute *attr, \
402 char *buf) \
403{ \
404 return show_engine_leds(dev, attr, buf, nr); \
405}
406show_leds(1)
407show_leds(2)
408show_leds(3)
409
410static ssize_t store_engine_leds(struct device *dev,
411 struct device_attribute *attr,
412 const char *buf, size_t len, int nr)
413{
414 struct i2c_client *client = to_i2c_client(dev);
415 struct lp5523_chip *chip = i2c_get_clientdata(client);
416 u16 mux = 0;
Samu Onkalofbac0812011-01-12 16:59:18 -0800417 ssize_t ret;
Samu Onkalo0efba162010-11-11 14:05:22 -0800418
419 if (lp5523_mux_parse(buf, &mux, len))
420 return -EINVAL;
421
Samu Onkalofbac0812011-01-12 16:59:18 -0800422 mutex_lock(&chip->lock);
423 ret = -EINVAL;
424 if (chip->engines[nr - 1].mode != LP5523_CMD_LOAD)
425 goto leave;
Samu Onkalo0efba162010-11-11 14:05:22 -0800426
Samu Onkalofbac0812011-01-12 16:59:18 -0800427 if (lp5523_load_mux(&chip->engines[nr - 1], mux))
428 goto leave;
429
430 ret = len;
431leave:
432 mutex_unlock(&chip->lock);
433 return ret;
Samu Onkalo0efba162010-11-11 14:05:22 -0800434}
435
436#define store_leds(nr) \
437static ssize_t store_engine##nr##_leds(struct device *dev, \
438 struct device_attribute *attr, \
439 const char *buf, size_t len) \
440{ \
441 return store_engine_leds(dev, attr, buf, len, nr); \
442}
443store_leds(1)
444store_leds(2)
445store_leds(3)
446
447static ssize_t lp5523_selftest(struct device *dev,
448 struct device_attribute *attr,
449 char *buf)
450{
451 struct i2c_client *client = to_i2c_client(dev);
452 struct lp5523_chip *chip = i2c_get_clientdata(client);
453 int i, ret, pos = 0;
454 int led = 0;
455 u8 status, adc, vdd;
456
457 mutex_lock(&chip->lock);
458
459 ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status);
460 if (ret < 0)
461 goto fail;
462
463 /* Check that ext clock is really in use if requested */
464 if ((chip->pdata) && (chip->pdata->clock_mode == LP5523_CLOCK_EXT))
465 if ((status & LP5523_EXT_CLK_USED) == 0)
466 goto fail;
467
468 /* Measure VDD (i.e. VBAT) first (channel 16 corresponds to VDD) */
469 lp5523_write(chip->client, LP5523_REG_LED_TEST_CTRL,
470 LP5523_EN_LEDTEST | 16);
Samu Onkalo2e4840e2010-11-24 12:57:04 -0800471 usleep_range(3000, 6000); /* ADC conversion time is typically 2.7 ms */
Samu Onkalo0efba162010-11-11 14:05:22 -0800472 ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status);
Jingoo Han1b21ec52012-10-28 18:45:11 -0700473 if (ret < 0)
474 goto fail;
475
Samu Onkalo0efba162010-11-11 14:05:22 -0800476 if (!(status & LP5523_LEDTEST_DONE))
Samu Onkalo2e4840e2010-11-24 12:57:04 -0800477 usleep_range(3000, 6000); /* Was not ready. Wait little bit */
Samu Onkalo0efba162010-11-11 14:05:22 -0800478
Jingoo Han1b21ec52012-10-28 18:45:11 -0700479 ret = lp5523_read(chip->client, LP5523_REG_LED_TEST_ADC, &vdd);
480 if (ret < 0)
481 goto fail;
482
Samu Onkalo0efba162010-11-11 14:05:22 -0800483 vdd--; /* There may be some fluctuation in measurement */
484
485 for (i = 0; i < LP5523_LEDS; i++) {
486 /* Skip non-existing channels */
487 if (chip->pdata->led_config[i].led_current == 0)
488 continue;
489
490 /* Set default current */
491 lp5523_write(chip->client,
492 LP5523_REG_LED_CURRENT_BASE + i,
493 chip->pdata->led_config[i].led_current);
494
495 lp5523_write(chip->client, LP5523_REG_LED_PWM_BASE + i, 0xff);
Samu Onkalo2e4840e2010-11-24 12:57:04 -0800496 /* let current stabilize 2 - 4ms before measurements start */
497 usleep_range(2000, 4000);
Samu Onkalo0efba162010-11-11 14:05:22 -0800498 lp5523_write(chip->client,
499 LP5523_REG_LED_TEST_CTRL,
500 LP5523_EN_LEDTEST | i);
Samu Onkalo2e4840e2010-11-24 12:57:04 -0800501 /* ADC conversion time is 2.7 ms typically */
502 usleep_range(3000, 6000);
Samu Onkalo0efba162010-11-11 14:05:22 -0800503 ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status);
Jingoo Han1b21ec52012-10-28 18:45:11 -0700504 if (ret < 0)
505 goto fail;
506
Samu Onkalo0efba162010-11-11 14:05:22 -0800507 if (!(status & LP5523_LEDTEST_DONE))
Samu Onkalo2e4840e2010-11-24 12:57:04 -0800508 usleep_range(3000, 6000);/* Was not ready. Wait. */
Jingoo Han1b21ec52012-10-28 18:45:11 -0700509 ret = lp5523_read(chip->client, LP5523_REG_LED_TEST_ADC, &adc);
510 if (ret < 0)
511 goto fail;
Samu Onkalo0efba162010-11-11 14:05:22 -0800512
513 if (adc >= vdd || adc < LP5523_ADC_SHORTCIRC_LIM)
514 pos += sprintf(buf + pos, "LED %d FAIL\n", i);
515
516 lp5523_write(chip->client, LP5523_REG_LED_PWM_BASE + i, 0x00);
517
518 /* Restore current */
519 lp5523_write(chip->client,
520 LP5523_REG_LED_CURRENT_BASE + i,
521 chip->leds[led].led_current);
522 led++;
523 }
524 if (pos == 0)
525 pos = sprintf(buf, "OK\n");
526 goto release_lock;
527fail:
528 pos = sprintf(buf, "FAIL\n");
529
530release_lock:
531 mutex_unlock(&chip->lock);
532
533 return pos;
534}
535
536static void lp5523_set_brightness(struct led_classdev *cdev,
537 enum led_brightness brightness)
538{
539 struct lp5523_led *led = cdev_to_led(cdev);
540
541 led->brightness = (u8)brightness;
542
543 schedule_work(&led->brightness_work);
544}
545
546static void lp5523_led_brightness_work(struct work_struct *work)
547{
548 struct lp5523_led *led = container_of(work,
549 struct lp5523_led,
550 brightness_work);
551 struct lp5523_chip *chip = led_to_lp5523(led);
552 struct i2c_client *client = chip->client;
553
554 mutex_lock(&chip->lock);
555
556 lp5523_write(client, LP5523_REG_LED_PWM_BASE + led->chan_nr,
557 led->brightness);
558
559 mutex_unlock(&chip->lock);
560}
561
562static int lp5523_do_store_load(struct lp5523_engine *engine,
563 const char *buf, size_t len)
564{
565 struct lp5523_chip *chip = engine_to_lp5523(engine);
566 struct i2c_client *client = chip->client;
567 int ret, nrchars, offset = 0, i = 0;
568 char c[3];
569 unsigned cmd;
570 u8 pattern[LP5523_PROGRAM_LENGTH] = {0};
571
Kim, Milo469eba02012-08-21 17:04:02 +0800572 if (engine->mode != LP5523_CMD_LOAD)
573 return -EINVAL;
574
Samu Onkalo0efba162010-11-11 14:05:22 -0800575 while ((offset < len - 1) && (i < LP5523_PROGRAM_LENGTH)) {
576 /* separate sscanfs because length is working only for %s */
577 ret = sscanf(buf + offset, "%2s%n ", c, &nrchars);
578 ret = sscanf(c, "%2x", &cmd);
579 if (ret != 1)
580 goto fail;
581 pattern[i] = (u8)cmd;
582
583 offset += nrchars;
584 i++;
585 }
586
587 /* Each instruction is 16bit long. Check that length is even */
588 if (i % 2)
589 goto fail;
590
591 mutex_lock(&chip->lock);
Kim, Milo469eba02012-08-21 17:04:02 +0800592 ret = lp5523_load_program(engine, pattern);
Samu Onkalo0efba162010-11-11 14:05:22 -0800593 mutex_unlock(&chip->lock);
594
595 if (ret) {
596 dev_err(&client->dev, "failed loading pattern\n");
597 return ret;
598 }
599
600 return len;
601fail:
602 dev_err(&client->dev, "wrong pattern format\n");
603 return -EINVAL;
604}
605
606static ssize_t store_engine_load(struct device *dev,
607 struct device_attribute *attr,
608 const char *buf, size_t len, int nr)
609{
610 struct i2c_client *client = to_i2c_client(dev);
611 struct lp5523_chip *chip = i2c_get_clientdata(client);
612 return lp5523_do_store_load(&chip->engines[nr - 1], buf, len);
613}
614
615#define store_load(nr) \
616static ssize_t store_engine##nr##_load(struct device *dev, \
617 struct device_attribute *attr, \
618 const char *buf, size_t len) \
619{ \
620 return store_engine_load(dev, attr, buf, len, nr); \
621}
622store_load(1)
623store_load(2)
624store_load(3)
625
626static ssize_t show_engine_mode(struct device *dev,
627 struct device_attribute *attr,
628 char *buf, int nr)
629{
630 struct i2c_client *client = to_i2c_client(dev);
631 struct lp5523_chip *chip = i2c_get_clientdata(client);
632 switch (chip->engines[nr - 1].mode) {
633 case LP5523_CMD_RUN:
634 return sprintf(buf, "run\n");
635 case LP5523_CMD_LOAD:
636 return sprintf(buf, "load\n");
637 case LP5523_CMD_DISABLED:
638 return sprintf(buf, "disabled\n");
639 default:
640 return sprintf(buf, "disabled\n");
641 }
642}
643
644#define show_mode(nr) \
645static ssize_t show_engine##nr##_mode(struct device *dev, \
646 struct device_attribute *attr, \
647 char *buf) \
648{ \
649 return show_engine_mode(dev, attr, buf, nr); \
650}
651show_mode(1)
652show_mode(2)
653show_mode(3)
654
655static ssize_t store_engine_mode(struct device *dev,
656 struct device_attribute *attr,
657 const char *buf, size_t len, int nr)
658{
659 struct i2c_client *client = to_i2c_client(dev);
660 struct lp5523_chip *chip = i2c_get_clientdata(client);
661 struct lp5523_engine *engine = &chip->engines[nr - 1];
662 mutex_lock(&chip->lock);
663
664 if (!strncmp(buf, "run", 3))
665 lp5523_set_mode(engine, LP5523_CMD_RUN);
666 else if (!strncmp(buf, "load", 4))
667 lp5523_set_mode(engine, LP5523_CMD_LOAD);
668 else if (!strncmp(buf, "disabled", 8))
669 lp5523_set_mode(engine, LP5523_CMD_DISABLED);
670
671 mutex_unlock(&chip->lock);
672 return len;
673}
674
675#define store_mode(nr) \
676static ssize_t store_engine##nr##_mode(struct device *dev, \
677 struct device_attribute *attr, \
678 const char *buf, size_t len) \
679{ \
680 return store_engine_mode(dev, attr, buf, len, nr); \
681}
682store_mode(1)
683store_mode(2)
684store_mode(3)
685
686static ssize_t show_max_current(struct device *dev,
687 struct device_attribute *attr,
688 char *buf)
689{
690 struct led_classdev *led_cdev = dev_get_drvdata(dev);
691 struct lp5523_led *led = cdev_to_led(led_cdev);
692
693 return sprintf(buf, "%d\n", led->max_current);
694}
695
696static ssize_t show_current(struct device *dev,
697 struct device_attribute *attr,
698 char *buf)
699{
700 struct led_classdev *led_cdev = dev_get_drvdata(dev);
701 struct lp5523_led *led = cdev_to_led(led_cdev);
702
703 return sprintf(buf, "%d\n", led->led_current);
704}
705
706static ssize_t store_current(struct device *dev,
707 struct device_attribute *attr,
708 const char *buf, size_t len)
709{
710 struct led_classdev *led_cdev = dev_get_drvdata(dev);
711 struct lp5523_led *led = cdev_to_led(led_cdev);
712 struct lp5523_chip *chip = led_to_lp5523(led);
713 ssize_t ret;
714 unsigned long curr;
715
Jingoo Haneef4aa62012-11-18 20:51:47 -0800716 if (kstrtoul(buf, 0, &curr))
Samu Onkalo0efba162010-11-11 14:05:22 -0800717 return -EINVAL;
718
719 if (curr > led->max_current)
720 return -EINVAL;
721
722 mutex_lock(&chip->lock);
723 ret = lp5523_write(chip->client,
724 LP5523_REG_LED_CURRENT_BASE + led->chan_nr,
725 (u8)curr);
726 mutex_unlock(&chip->lock);
727
728 if (ret < 0)
729 return ret;
730
731 led->led_current = (u8)curr;
732
733 return len;
734}
735
736/* led class device attributes */
Vasiliy Kulikovccd75102011-03-22 16:30:20 -0700737static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, show_current, store_current);
Samu Onkalo0efba162010-11-11 14:05:22 -0800738static DEVICE_ATTR(max_current, S_IRUGO , show_max_current, NULL);
739
740static struct attribute *lp5523_led_attributes[] = {
741 &dev_attr_led_current.attr,
742 &dev_attr_max_current.attr,
743 NULL,
744};
745
746static struct attribute_group lp5523_led_attribute_group = {
747 .attrs = lp5523_led_attributes
748};
749
750/* device attributes */
Vasiliy Kulikovccd75102011-03-22 16:30:20 -0700751static DEVICE_ATTR(engine1_mode, S_IRUGO | S_IWUSR,
Samu Onkalo0efba162010-11-11 14:05:22 -0800752 show_engine1_mode, store_engine1_mode);
Vasiliy Kulikovccd75102011-03-22 16:30:20 -0700753static DEVICE_ATTR(engine2_mode, S_IRUGO | S_IWUSR,
Samu Onkalo0efba162010-11-11 14:05:22 -0800754 show_engine2_mode, store_engine2_mode);
Vasiliy Kulikovccd75102011-03-22 16:30:20 -0700755static DEVICE_ATTR(engine3_mode, S_IRUGO | S_IWUSR,
Samu Onkalo0efba162010-11-11 14:05:22 -0800756 show_engine3_mode, store_engine3_mode);
Vasiliy Kulikovccd75102011-03-22 16:30:20 -0700757static DEVICE_ATTR(engine1_leds, S_IRUGO | S_IWUSR,
Samu Onkalo0efba162010-11-11 14:05:22 -0800758 show_engine1_leds, store_engine1_leds);
Vasiliy Kulikovccd75102011-03-22 16:30:20 -0700759static DEVICE_ATTR(engine2_leds, S_IRUGO | S_IWUSR,
Samu Onkalo0efba162010-11-11 14:05:22 -0800760 show_engine2_leds, store_engine2_leds);
Vasiliy Kulikovccd75102011-03-22 16:30:20 -0700761static DEVICE_ATTR(engine3_leds, S_IRUGO | S_IWUSR,
Samu Onkalo0efba162010-11-11 14:05:22 -0800762 show_engine3_leds, store_engine3_leds);
Vasiliy Kulikovccd75102011-03-22 16:30:20 -0700763static DEVICE_ATTR(engine1_load, S_IWUSR, NULL, store_engine1_load);
764static DEVICE_ATTR(engine2_load, S_IWUSR, NULL, store_engine2_load);
765static DEVICE_ATTR(engine3_load, S_IWUSR, NULL, store_engine3_load);
Samu Onkalo0efba162010-11-11 14:05:22 -0800766static DEVICE_ATTR(selftest, S_IRUGO, lp5523_selftest, NULL);
767
768static struct attribute *lp5523_attributes[] = {
769 &dev_attr_engine1_mode.attr,
770 &dev_attr_engine2_mode.attr,
771 &dev_attr_engine3_mode.attr,
772 &dev_attr_selftest.attr,
Samu Onkalo0efba162010-11-11 14:05:22 -0800773 &dev_attr_engine1_load.attr,
774 &dev_attr_engine1_leds.attr,
Samu Onkalo0efba162010-11-11 14:05:22 -0800775 &dev_attr_engine2_load.attr,
776 &dev_attr_engine2_leds.attr,
Samu Onkalo0efba162010-11-11 14:05:22 -0800777 &dev_attr_engine3_load.attr,
778 &dev_attr_engine3_leds.attr,
Kim, Milof1625842012-09-12 20:16:03 +0800779 NULL,
Samu Onkalo0efba162010-11-11 14:05:22 -0800780};
781
782static const struct attribute_group lp5523_group = {
783 .attrs = lp5523_attributes,
784};
785
Samu Onkalo0efba162010-11-11 14:05:22 -0800786static int lp5523_register_sysfs(struct i2c_client *client)
787{
788 struct device *dev = &client->dev;
789 int ret;
790
791 ret = sysfs_create_group(&dev->kobj, &lp5523_group);
792 if (ret < 0)
793 return ret;
794
795 return 0;
796}
797
798static void lp5523_unregister_sysfs(struct i2c_client *client)
799{
800 struct lp5523_chip *chip = i2c_get_clientdata(client);
801 struct device *dev = &client->dev;
802 int i;
803
804 sysfs_remove_group(&dev->kobj, &lp5523_group);
805
Samu Onkalo0efba162010-11-11 14:05:22 -0800806 for (i = 0; i < chip->num_leds; i++)
807 sysfs_remove_group(&chip->leds[i].cdev.dev->kobj,
808 &lp5523_led_attribute_group);
809}
810
811/*--------------------------------------------------------------*/
812/* Set chip operating mode */
813/*--------------------------------------------------------------*/
Kim, Milo6f6365f2012-08-21 17:03:58 +0800814static void lp5523_set_mode(struct lp5523_engine *engine, u8 mode)
Samu Onkalo0efba162010-11-11 14:05:22 -0800815{
Samu Onkalo0efba162010-11-11 14:05:22 -0800816 /* if in that mode already do nothing, except for run */
817 if (mode == engine->mode && mode != LP5523_CMD_RUN)
Kim, Milo6f6365f2012-08-21 17:03:58 +0800818 return;
Samu Onkalo0efba162010-11-11 14:05:22 -0800819
Kim, Milo6f6365f2012-08-21 17:03:58 +0800820 switch (mode) {
821 case LP5523_CMD_RUN:
822 lp5523_run_program(engine);
823 break;
824 case LP5523_CMD_LOAD:
Samu Onkalo0efba162010-11-11 14:05:22 -0800825 lp5523_set_engine_mode(engine, LP5523_CMD_DISABLED);
826 lp5523_set_engine_mode(engine, LP5523_CMD_LOAD);
Kim, Milo6f6365f2012-08-21 17:03:58 +0800827 break;
828 case LP5523_CMD_DISABLED:
Samu Onkalo0efba162010-11-11 14:05:22 -0800829 lp5523_set_engine_mode(engine, LP5523_CMD_DISABLED);
Kim, Milo6f6365f2012-08-21 17:03:58 +0800830 break;
831 default:
832 return;
Samu Onkalo0efba162010-11-11 14:05:22 -0800833 }
834
Samu Onkalo0efba162010-11-11 14:05:22 -0800835 engine->mode = mode;
Samu Onkalo0efba162010-11-11 14:05:22 -0800836}
837
838/*--------------------------------------------------------------*/
839/* Probe, Attach, Remove */
840/*--------------------------------------------------------------*/
841static int __init lp5523_init_engine(struct lp5523_engine *engine, int id)
842{
843 if (id < 1 || id > LP5523_ENGINES)
844 return -1;
845 engine->id = id;
846 engine->engine_mask = LP5523_ENG_MASK_BASE >> SHIFT_MASK(id);
847 engine->prog_page = id - 1;
848 engine->mux_page = id + 2;
Samu Onkalo0efba162010-11-11 14:05:22 -0800849
850 return 0;
851}
852
Bill Pemberton98ea1ea2012-11-19 13:23:02 -0500853static int lp5523_init_led(struct lp5523_led *led, struct device *dev,
Kim, Milo56a1e9a2012-09-04 15:06:26 +0800854 int chan, struct lp5523_platform_data *pdata,
855 const char *chip_name)
Samu Onkalo0efba162010-11-11 14:05:22 -0800856{
857 char name[32];
858 int res;
859
860 if (chan >= LP5523_LEDS)
861 return -EINVAL;
862
863 if (pdata->led_config[chan].led_current) {
864 led->led_current = pdata->led_config[chan].led_current;
865 led->max_current = pdata->led_config[chan].max_current;
866 led->chan_nr = pdata->led_config[chan].chan_nr;
867
868 if (led->chan_nr >= LP5523_LEDS) {
869 dev_err(dev, "Use channel numbers between 0 and %d\n",
870 LP5523_LEDS - 1);
871 return -EINVAL;
872 }
873
Kim, Milo94b43b62012-08-22 15:32:29 +0800874 if (pdata->led_config[chan].name) {
875 led->cdev.name = pdata->led_config[chan].name;
876 } else {
877 snprintf(name, sizeof(name), "%s:channel%d",
Kim, Milo56a1e9a2012-09-04 15:06:26 +0800878 pdata->label ? : chip_name, chan);
Kim, Milo94b43b62012-08-22 15:32:29 +0800879 led->cdev.name = name;
880 }
Samu Onkalo0efba162010-11-11 14:05:22 -0800881
Samu Onkalo0efba162010-11-11 14:05:22 -0800882 led->cdev.brightness_set = lp5523_set_brightness;
883 res = led_classdev_register(dev, &led->cdev);
884 if (res < 0) {
885 dev_err(dev, "couldn't register led on channel %d\n",
886 chan);
887 return res;
888 }
889 res = sysfs_create_group(&led->cdev.dev->kobj,
890 &lp5523_led_attribute_group);
891 if (res < 0) {
892 dev_err(dev, "couldn't register current attribute\n");
893 led_classdev_unregister(&led->cdev);
894 return res;
895 }
896 } else {
897 led->led_current = 0;
898 }
899 return 0;
900}
901
Milo(Woogyom) Kimf6524802013-02-05 17:53:40 +0900902static int lp5523_register_leds(struct lp5523_chip *chip, const char *name)
903{
904 struct lp5523_platform_data *pdata = chip->pdata;
905 struct i2c_client *client = chip->client;
906 int i;
907 int led;
908 int ret;
909
910 /* Initialize leds */
911 chip->num_channels = pdata->num_channels;
912 chip->num_leds = 0;
913 led = 0;
914 for (i = 0; i < pdata->num_channels; i++) {
915 /* Do not initialize channels that are not connected */
916 if (pdata->led_config[i].led_current == 0)
917 continue;
918
919 INIT_WORK(&chip->leds[led].brightness_work,
920 lp5523_led_brightness_work);
921
922 ret = lp5523_init_led(&chip->leds[led], &client->dev, i, pdata,
923 name);
924 if (ret) {
925 dev_err(&client->dev, "error initializing leds\n");
926 return ret;
927 }
928 chip->num_leds++;
929
930 chip->leds[led].id = led;
931 /* Set LED current */
932 lp5523_write(client,
933 LP5523_REG_LED_CURRENT_BASE + chip->leds[led].chan_nr,
934 chip->leds[led].led_current);
935
936 led++;
937 }
938
939 return 0;
940}
941
Milo(Woogyom) Kim1904f832013-02-05 17:56:23 +0900942static void lp5523_unregister_leds(struct lp5523_chip *chip)
943{
944 int i;
945
946 for (i = 0; i < chip->num_leds; i++) {
947 led_classdev_unregister(&chip->leds[i].cdev);
948 flush_work(&chip->leds[i].brightness_work);
949 }
950}
951
Milo(Woogyom) Kim86eb7742013-02-05 17:57:02 +0900952static void lp5523_reset_device(struct lp5523_chip *chip)
953{
954 struct i2c_client *client = chip->client;
955
956 lp5523_write(client, LP5523_REG_RESET, 0xff);
957}
958
Milo(Woogyom) Kimf6c64c62013-02-05 17:58:01 +0900959static void lp5523_deinit_device(struct lp5523_chip *chip);
Milo(Woogyom) Kim944f7b12013-02-05 17:49:46 +0900960static int lp5523_init_device(struct lp5523_chip *chip)
961{
962 struct lp5523_platform_data *pdata = chip->pdata;
963 struct i2c_client *client = chip->client;
964 int ret;
965
966 if (pdata->setup_resources) {
967 ret = pdata->setup_resources();
968 if (ret < 0)
969 return ret;
970 }
971
972 if (pdata->enable) {
973 pdata->enable(0);
974 usleep_range(1000, 2000); /* Keep enable down at least 1ms */
975 pdata->enable(1);
976 usleep_range(1000, 2000); /* 500us abs min. */
977 }
978
Milo(Woogyom) Kim86eb7742013-02-05 17:57:02 +0900979 lp5523_reset_device(chip);
980
Milo(Woogyom) Kim944f7b12013-02-05 17:49:46 +0900981 usleep_range(10000, 20000); /*
982 * Exact value is not available. 10 - 20ms
983 * appears to be enough for reset.
984 */
Milo(Woogyom) Kimf6c64c62013-02-05 17:58:01 +0900985 ret = lp5523_detect(client);
986 if (ret)
987 goto err;
988
989 ret = lp5523_configure(client);
990 if (ret < 0) {
991 dev_err(&client->dev, "error configuring chip\n");
992 goto err_config;
993 }
994
995 return 0;
996
997err_config:
998 lp5523_deinit_device(chip);
999err:
1000 return ret;
Milo(Woogyom) Kim944f7b12013-02-05 17:49:46 +09001001}
1002
Milo(Woogyom) Kim1a991482013-02-05 17:50:36 +09001003static void lp5523_deinit_device(struct lp5523_chip *chip)
1004{
1005 struct lp5523_platform_data *pdata = chip->pdata;
1006
1007 if (pdata->enable)
1008 pdata->enable(0);
1009 if (pdata->release_resources)
1010 pdata->release_resources();
1011}
1012
Bill Pemberton98ea1ea2012-11-19 13:23:02 -05001013static int lp5523_probe(struct i2c_client *client,
Samu Onkalo0efba162010-11-11 14:05:22 -08001014 const struct i2c_device_id *id)
1015{
Milo(Woogyom) Kim6a0c9a42013-02-05 18:03:08 +09001016 struct lp5523_chip *old_chip = NULL;
Milo(Woogyom) Kimf6524802013-02-05 17:53:40 +09001017 int ret, i;
Milo(Woogyom) Kim6a0c9a42013-02-05 18:03:08 +09001018 struct lp55xx_chip *chip;
1019 struct lp55xx_led *led;
1020 struct lp55xx_platform_data *pdata = client->dev.platform_data;
Samu Onkalo0efba162010-11-11 14:05:22 -08001021
Milo(Woogyom) Kim6a0c9a42013-02-05 18:03:08 +09001022 if (!pdata) {
Samu Onkalo0efba162010-11-11 14:05:22 -08001023 dev_err(&client->dev, "no platform data\n");
Bryan Wu94ca4bc2012-07-04 11:44:18 +08001024 return -EINVAL;
Samu Onkalo0efba162010-11-11 14:05:22 -08001025 }
1026
Milo(Woogyom) Kim6a0c9a42013-02-05 18:03:08 +09001027 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
1028 if (!chip)
1029 return -ENOMEM;
Samu Onkalo0efba162010-11-11 14:05:22 -08001030
Milo(Woogyom) Kim6a0c9a42013-02-05 18:03:08 +09001031 led = devm_kzalloc(&client->dev,
1032 sizeof(*led) * pdata->num_channels, GFP_KERNEL);
1033 if (!led)
1034 return -ENOMEM;
1035
1036 chip->cl = client;
1037 chip->pdata = pdata;
1038
1039 mutex_init(&chip->lock);
1040
1041 i2c_set_clientdata(client, led);
Samu Onkalo0efba162010-11-11 14:05:22 -08001042
Milo(Woogyom) Kim945c7002013-02-05 18:02:26 +09001043 ret = lp5523_init_device(old_chip);
Samu Onkalo0efba162010-11-11 14:05:22 -08001044 if (ret)
Milo(Woogyom) Kimf6c64c62013-02-05 17:58:01 +09001045 goto err_init;
Samu Onkalo0efba162010-11-11 14:05:22 -08001046
Kim, Milo56a1e9a2012-09-04 15:06:26 +08001047 dev_info(&client->dev, "%s Programmable led chip found\n", id->name);
Samu Onkalo0efba162010-11-11 14:05:22 -08001048
1049 /* Initialize engines */
Milo(Woogyom) Kim945c7002013-02-05 18:02:26 +09001050 for (i = 0; i < ARRAY_SIZE(old_chip->engines); i++) {
1051 ret = lp5523_init_engine(&old_chip->engines[i], i + 1);
Samu Onkalo0efba162010-11-11 14:05:22 -08001052 if (ret) {
1053 dev_err(&client->dev, "error initializing engine\n");
Bryan Wu94ca4bc2012-07-04 11:44:18 +08001054 goto fail1;
Samu Onkalo0efba162010-11-11 14:05:22 -08001055 }
1056 }
Samu Onkalo0efba162010-11-11 14:05:22 -08001057
Milo(Woogyom) Kim945c7002013-02-05 18:02:26 +09001058 ret = lp5523_register_leds(old_chip, id->name);
Milo(Woogyom) Kimf6524802013-02-05 17:53:40 +09001059 if (ret)
1060 goto fail2;
Samu Onkalo0efba162010-11-11 14:05:22 -08001061
1062 ret = lp5523_register_sysfs(client);
1063 if (ret) {
1064 dev_err(&client->dev, "registering sysfs failed\n");
Bryan Wu94ca4bc2012-07-04 11:44:18 +08001065 goto fail2;
Samu Onkalo0efba162010-11-11 14:05:22 -08001066 }
1067 return ret;
Bryan Wu94ca4bc2012-07-04 11:44:18 +08001068fail2:
Milo(Woogyom) Kim945c7002013-02-05 18:02:26 +09001069 lp5523_unregister_leds(old_chip);
Bryan Wu94ca4bc2012-07-04 11:44:18 +08001070fail1:
Milo(Woogyom) Kim945c7002013-02-05 18:02:26 +09001071 lp5523_deinit_device(old_chip);
Milo(Woogyom) Kimf6c64c62013-02-05 17:58:01 +09001072err_init:
Samu Onkalo0efba162010-11-11 14:05:22 -08001073 return ret;
1074}
1075
1076static int lp5523_remove(struct i2c_client *client)
1077{
Milo(Woogyom) Kim945c7002013-02-05 18:02:26 +09001078 struct lp5523_chip *old_chip = i2c_get_clientdata(client);
Samu Onkalo0efba162010-11-11 14:05:22 -08001079
Kim, Milo23301b72012-09-12 20:16:00 +08001080 /* Disable engine mode */
1081 lp5523_write(client, LP5523_REG_OP_MODE, LP5523_CMD_DISABLED);
1082
Samu Onkalo0efba162010-11-11 14:05:22 -08001083 lp5523_unregister_sysfs(client);
1084
Milo(Woogyom) Kim945c7002013-02-05 18:02:26 +09001085 lp5523_unregister_leds(old_chip);
Samu Onkalo0efba162010-11-11 14:05:22 -08001086
Milo(Woogyom) Kim945c7002013-02-05 18:02:26 +09001087 lp5523_deinit_device(old_chip);
Samu Onkalo0efba162010-11-11 14:05:22 -08001088 return 0;
1089}
1090
1091static const struct i2c_device_id lp5523_id[] = {
Kim, Milo27d77042012-09-04 15:06:18 +08001092 { "lp5523", LP5523 },
1093 { "lp55231", LP55231 },
Samu Onkalo0efba162010-11-11 14:05:22 -08001094 { }
1095};
1096
1097MODULE_DEVICE_TABLE(i2c, lp5523_id);
1098
1099static struct i2c_driver lp5523_driver = {
1100 .driver = {
Kim, Milo27d77042012-09-04 15:06:18 +08001101 .name = "lp5523x",
Samu Onkalo0efba162010-11-11 14:05:22 -08001102 },
1103 .probe = lp5523_probe,
1104 .remove = lp5523_remove,
1105 .id_table = lp5523_id,
1106};
1107
Axel Lin09a0d182012-01-10 15:09:27 -08001108module_i2c_driver(lp5523_driver);
Samu Onkalo0efba162010-11-11 14:05:22 -08001109
1110MODULE_AUTHOR("Mathias Nyman <mathias.nyman@nokia.com>");
1111MODULE_DESCRIPTION("LP5523 LED engine");
1112MODULE_LICENSE("GPL");