aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lp5521.c
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 05:09:32 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-06 18:59:28 -0500
commita96bfa135ddc8045166fc6311ce4d21bfcb8d13d (patch)
tree405bc5264b0b09af0d77db11cdae2923279db188 /drivers/leds/leds-lp5521.c
parenta6e4679a09a0a2bcfa63074272fc9fb2a40f11ad (diff)
leds-lp55xx: provide common LED current setting
LED current is configurable via the sysfs. Max current is a read-only attribute. These attributes code can be shared in lp55xx common driver. Device attributes: 'led_current' and 'max_current' move to lp55xx common driver Replaced functions: show_max_current() => lp55xx_show_max_current() show_current() => lp55xx_show_current() store_current() => lp55xx_store_current() LED setting function: set_led_current() Current registers are device specific, so configurable function is added in each driver. Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds/leds-lp5521.c')
-rw-r--r--drivers/leds/leds-lp5521.c74
1 files changed, 8 insertions, 66 deletions
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index 6efbb7ec0e2d..7133af824b5e 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -134,6 +134,13 @@ static inline void lp5521_wait_enable_done(void)
134 usleep_range(500, 600); 134 usleep_range(500, 600);
135} 135}
136 136
137static void lp5521_set_led_current(struct lp55xx_led *led, u8 led_current)
138{
139 led->led_current = led_current;
140 lp55xx_write(led->chip, LP5521_REG_LED_CURRENT_BASE + led->chan_nr,
141 led_current);
142}
143
137static inline struct lp5521_led *cdev_to_led(struct led_classdev *cdev) 144static inline struct lp5521_led *cdev_to_led(struct led_classdev *cdev)
138{ 145{
139 return container_of(cdev, struct lp5521_led, cdev); 146 return container_of(cdev, struct lp5521_led, cdev);
@@ -229,13 +236,6 @@ static int lp5521_load_program(struct lp5521_engine *eng, const u8 *pattern)
229 return lp5521_write(client, LP5521_REG_OP_MODE, mode); 236 return lp5521_write(client, LP5521_REG_OP_MODE, mode);
230} 237}
231 238
232static int lp5521_set_led_current(struct lp5521_chip *chip, int led, u8 curr)
233{
234 return lp5521_write(chip->client,
235 LP5521_REG_LED_CURRENT_BASE + chip->leds[led].chan_nr,
236 curr);
237}
238
239static int lp5521_post_init_device(struct lp55xx_chip *chip) 239static int lp5521_post_init_device(struct lp55xx_chip *chip)
240{ 240{
241 int ret; 241 int ret;
@@ -462,54 +462,6 @@ store_mode(1)
462store_mode(2) 462store_mode(2)
463store_mode(3) 463store_mode(3)
464 464
465static ssize_t show_max_current(struct device *dev,
466 struct device_attribute *attr,
467 char *buf)
468{
469 struct led_classdev *led_cdev = dev_get_drvdata(dev);
470 struct lp5521_led *led = cdev_to_led(led_cdev);
471
472 return sprintf(buf, "%d\n", led->max_current);
473}
474
475static ssize_t show_current(struct device *dev,
476 struct device_attribute *attr,
477 char *buf)
478{
479 struct led_classdev *led_cdev = dev_get_drvdata(dev);
480 struct lp5521_led *led = cdev_to_led(led_cdev);
481
482 return sprintf(buf, "%d\n", led->led_current);
483}
484
485static ssize_t store_current(struct device *dev,
486 struct device_attribute *attr,
487 const char *buf, size_t len)
488{
489 struct led_classdev *led_cdev = dev_get_drvdata(dev);
490 struct lp5521_led *led = cdev_to_led(led_cdev);
491 struct lp5521_chip *chip = led_to_lp5521(led);
492 ssize_t ret;
493 unsigned long curr;
494
495 if (kstrtoul(buf, 0, &curr))
496 return -EINVAL;
497
498 if (curr > led->max_current)
499 return -EINVAL;
500
501 mutex_lock(&chip->lock);
502 ret = lp5521_set_led_current(chip, led->id, curr);
503 mutex_unlock(&chip->lock);
504
505 if (ret < 0)
506 return ret;
507
508 led->led_current = (u8)curr;
509
510 return len;
511}
512
513static ssize_t lp5521_selftest(struct device *dev, 465static ssize_t lp5521_selftest(struct device *dev,
514 struct device_attribute *attr, 466 struct device_attribute *attr,
515 char *buf) 467 char *buf)
@@ -615,18 +567,7 @@ static ssize_t store_led_pattern(struct device *dev,
615 return len; 567 return len;
616} 568}
617 569
618/* led class device attributes */
619static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, show_current, store_current);
620static DEVICE_ATTR(max_current, S_IRUGO , show_max_current, NULL);
621
622static struct attribute *lp5521_led_attributes[] = {
623 &dev_attr_led_current.attr,
624 &dev_attr_max_current.attr,
625 NULL,
626};
627
628static struct attribute_group lp5521_led_attribute_group = { 570static struct attribute_group lp5521_led_attribute_group = {
629 .attrs = lp5521_led_attributes
630}; 571};
631 572
632/* device attributes */ 573/* device attributes */
@@ -700,6 +641,7 @@ static struct lp55xx_device_config lp5521_cfg = {
700 .max_channel = LP5521_MAX_LEDS, 641 .max_channel = LP5521_MAX_LEDS,
701 .post_init_device = lp5521_post_init_device, 642 .post_init_device = lp5521_post_init_device,
702 .brightness_work_fn = lp5521_led_brightness_work, 643 .brightness_work_fn = lp5521_led_brightness_work,
644 .set_led_current = lp5521_set_led_current,
703}; 645};
704 646
705static int lp5521_probe(struct i2c_client *client, 647static int lp5521_probe(struct i2c_client *client,