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:07:34 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-06 18:59:28 -0500
commit0e2023463a3c9412728cb2c36c79aca0bb731cc8 (patch)
treed88e84842ab9b3fcca01e56da349f7c94e61ae0a /drivers/leds/leds-lp55xx-common.c
parent9e9b3db1b2f725bacaf1b7e8708a0c78265bde97 (diff)
leds-lp55xx: use lp55xx_init_led() common function
lp5521_init_led() and lp5523_init_led() are replaced with one common function, lp55xx_init_led(). Max channels is configurable, so it's used in lp55xx_init_led(). 'LP5523_LEDS' are changed to 'LP5523_MAX_LEDS'. lp55xx_set_brightness, lp55xx_led_attributes: skeleton Will be filled in next patches. 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.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 1fab1d1c4502..75ab1c3c03ed 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -63,9 +63,75 @@ static int lp55xx_post_init_device(struct lp55xx_chip *chip)
63 return cfg->post_init_device(chip); 63 return cfg->post_init_device(chip);
64} 64}
65 65
66static struct attribute *lp55xx_led_attributes[] = {
67 NULL,
68};
69
70static struct attribute_group lp55xx_led_attr_group = {
71 .attrs = lp55xx_led_attributes
72};
73
74static void lp55xx_set_brightness(struct led_classdev *cdev,
75 enum led_brightness brightness)
76{
77}
78
66static int lp55xx_init_led(struct lp55xx_led *led, 79static int lp55xx_init_led(struct lp55xx_led *led,
67 struct lp55xx_chip *chip, int chan) 80 struct lp55xx_chip *chip, int chan)
68{ 81{
82 struct lp55xx_platform_data *pdata = chip->pdata;
83 struct lp55xx_device_config *cfg = chip->cfg;
84 struct device *dev = &chip->cl->dev;
85 char name[32];
86 int ret;
87 int max_channel = cfg->max_channel;
88
89 if (chan >= max_channel) {
90 dev_err(dev, "invalid channel: %d / %d\n", chan, max_channel);
91 return -EINVAL;
92 }
93
94 if (pdata->led_config[chan].led_current == 0)
95 return 0;
96
97 led->led_current = pdata->led_config[chan].led_current;
98 led->max_current = pdata->led_config[chan].max_current;
99 led->chan_nr = pdata->led_config[chan].chan_nr;
100
101 if (led->chan_nr >= max_channel) {
102 dev_err(dev, "Use channel numbers between 0 and %d\n",
103 max_channel - 1);
104 return -EINVAL;
105 }
106
107 led->cdev.brightness_set = lp55xx_set_brightness;
108
109 if (pdata->led_config[chan].name) {
110 led->cdev.name = pdata->led_config[chan].name;
111 } else {
112 snprintf(name, sizeof(name), "%s:channel%d",
113 pdata->label ? : chip->cl->name, chan);
114 led->cdev.name = name;
115 }
116
117 /*
118 * register led class device for each channel and
119 * add device attributes
120 */
121
122 ret = led_classdev_register(dev, &led->cdev);
123 if (ret) {
124 dev_err(dev, "led register err: %d\n", ret);
125 return ret;
126 }
127
128 ret = sysfs_create_group(&led->cdev.dev->kobj, &lp55xx_led_attr_group);
129 if (ret) {
130 dev_err(dev, "led sysfs err: %d\n", ret);
131 led_classdev_unregister(&led->cdev);
132 return ret;
133 }
134
69 return 0; 135 return 0;
70} 136}
71 137