aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lp55xx-common.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-lp55xx-common.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-lp55xx-common.c')
-rw-r--r--drivers/leds/leds-lp55xx-common.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 8244d78447f4..6b3d03709f5f 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -25,6 +25,11 @@ static struct lp55xx_led *cdev_to_lp55xx_led(struct led_classdev *cdev)
25 return container_of(cdev, struct lp55xx_led, cdev); 25 return container_of(cdev, struct lp55xx_led, cdev);
26} 26}
27 27
28static struct lp55xx_led *dev_to_lp55xx_led(struct device *dev)
29{
30 return cdev_to_lp55xx_led(dev_get_drvdata(dev));
31}
32
28static void lp55xx_reset_device(struct lp55xx_chip *chip) 33static void lp55xx_reset_device(struct lp55xx_chip *chip)
29{ 34{
30 struct lp55xx_device_config *cfg = chip->cfg; 35 struct lp55xx_device_config *cfg = chip->cfg;
@@ -68,7 +73,55 @@ static int lp55xx_post_init_device(struct lp55xx_chip *chip)
68 return cfg->post_init_device(chip); 73 return cfg->post_init_device(chip);
69} 74}
70 75
76static ssize_t lp55xx_show_current(struct device *dev,
77 struct device_attribute *attr,
78 char *buf)
79{
80 struct lp55xx_led *led = dev_to_lp55xx_led(dev);
81
82 return sprintf(buf, "%d\n", led->led_current);
83}
84
85static ssize_t lp55xx_store_current(struct device *dev,
86 struct device_attribute *attr,
87 const char *buf, size_t len)
88{
89 struct lp55xx_led *led = dev_to_lp55xx_led(dev);
90 struct lp55xx_chip *chip = led->chip;
91 unsigned long curr;
92
93 if (kstrtoul(buf, 0, &curr))
94 return -EINVAL;
95
96 if (curr > led->max_current)
97 return -EINVAL;
98
99 if (!chip->cfg->set_led_current)
100 return len;
101
102 mutex_lock(&chip->lock);
103 chip->cfg->set_led_current(led, (u8)curr);
104 mutex_unlock(&chip->lock);
105
106 return len;
107}
108
109static ssize_t lp55xx_show_max_current(struct device *dev,
110 struct device_attribute *attr,
111 char *buf)
112{
113 struct lp55xx_led *led = dev_to_lp55xx_led(dev);
114
115 return sprintf(buf, "%d\n", led->max_current);
116}
117
118static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, lp55xx_show_current,
119 lp55xx_store_current);
120static DEVICE_ATTR(max_current, S_IRUGO , lp55xx_show_max_current, NULL);
121
71static struct attribute *lp55xx_led_attributes[] = { 122static struct attribute *lp55xx_led_attributes[] = {
123 &dev_attr_led_current.attr,
124 &dev_attr_max_current.attr,
72 NULL, 125 NULL,
73}; 126};
74 127