aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lp5523.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-lp5523.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-lp5523.c')
-rw-r--r--drivers/leds/leds-lp5523.c62
1 files changed, 7 insertions, 55 deletions
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index 41ac502ff82f..ca2f8134909f 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -94,7 +94,7 @@
94#define LP5523_PROGRAM_PAGES 6 94#define LP5523_PROGRAM_PAGES 6
95#define LP5523_ADC_SHORTCIRC_LIM 80 95#define LP5523_ADC_SHORTCIRC_LIM 80
96 96
97#define LP5523_LEDS 9 97#define LP5523_MAX_LEDS 9
98#define LP5523_ENGINES 3 98#define LP5523_ENGINES 3
99 99
100#define LP5523_ENG_MASK_BASE 0x30 /* 00110000 */ 100#define LP5523_ENG_MASK_BASE 0x30 /* 00110000 */
@@ -136,7 +136,7 @@ struct lp5523_chip {
136 struct mutex lock; /* Serialize control */ 136 struct mutex lock; /* Serialize control */
137 struct i2c_client *client; 137 struct i2c_client *client;
138 struct lp5523_engine engines[LP5523_ENGINES]; 138 struct lp5523_engine engines[LP5523_ENGINES];
139 struct lp5523_led leds[LP5523_LEDS]; 139 struct lp5523_led leds[LP5523_MAX_LEDS];
140 struct lp5523_platform_data *pdata; 140 struct lp5523_platform_data *pdata;
141 u8 num_channels; 141 u8 num_channels;
142 u8 num_leds; 142 u8 num_leds;
@@ -285,7 +285,7 @@ static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len)
285 int i; 285 int i;
286 u16 tmp_mux = 0; 286 u16 tmp_mux = 0;
287 287
288 len = min_t(int, len, LP5523_LEDS); 288 len = min_t(int, len, LP5523_MAX_LEDS);
289 for (i = 0; i < len; i++) { 289 for (i = 0; i < len; i++) {
290 switch (buf[i]) { 290 switch (buf[i]) {
291 case '1': 291 case '1':
@@ -308,7 +308,7 @@ static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len)
308static void lp5523_mux_to_array(u16 led_mux, char *array) 308static void lp5523_mux_to_array(u16 led_mux, char *array)
309{ 309{
310 int i, pos = 0; 310 int i, pos = 0;
311 for (i = 0; i < LP5523_LEDS; i++) 311 for (i = 0; i < LP5523_MAX_LEDS; i++)
312 pos += sprintf(array + pos, "%x", LED_ACTIVE(led_mux, i)); 312 pos += sprintf(array + pos, "%x", LED_ACTIVE(led_mux, i));
313 313
314 array[pos] = '\0'; 314 array[pos] = '\0';
@@ -324,7 +324,7 @@ static ssize_t show_engine_leds(struct device *dev,
324{ 324{
325 struct i2c_client *client = to_i2c_client(dev); 325 struct i2c_client *client = to_i2c_client(dev);
326 struct lp5523_chip *chip = i2c_get_clientdata(client); 326 struct lp5523_chip *chip = i2c_get_clientdata(client);
327 char mux[LP5523_LEDS + 1]; 327 char mux[LP5523_MAX_LEDS + 1];
328 328
329 lp5523_mux_to_array(chip->engines[nr - 1].led_mux, mux); 329 lp5523_mux_to_array(chip->engines[nr - 1].led_mux, mux);
330 330
@@ -417,7 +417,7 @@ static ssize_t lp5523_selftest(struct device *dev,
417 417
418 vdd--; /* There may be some fluctuation in measurement */ 418 vdd--; /* There may be some fluctuation in measurement */
419 419
420 for (i = 0; i < LP5523_LEDS; i++) { 420 for (i = 0; i < LP5523_MAX_LEDS; i++) {
421 /* Skip non-existing channels */ 421 /* Skip non-existing channels */
422 if (chip->pdata->led_config[i].led_current == 0) 422 if (chip->pdata->led_config[i].led_current == 0)
423 continue; 423 continue;
@@ -773,55 +773,6 @@ static void lp5523_set_mode(struct lp5523_engine *engine, u8 mode)
773/*--------------------------------------------------------------*/ 773/*--------------------------------------------------------------*/
774/* Probe, Attach, Remove */ 774/* Probe, Attach, Remove */
775/*--------------------------------------------------------------*/ 775/*--------------------------------------------------------------*/
776static int lp5523_init_led(struct lp5523_led *led, struct device *dev,
777 int chan, struct lp5523_platform_data *pdata,
778 const char *chip_name)
779{
780 char name[32];
781 int res;
782
783 if (chan >= LP5523_LEDS)
784 return -EINVAL;
785
786 if (pdata->led_config[chan].led_current) {
787 led->led_current = pdata->led_config[chan].led_current;
788 led->max_current = pdata->led_config[chan].max_current;
789 led->chan_nr = pdata->led_config[chan].chan_nr;
790
791 if (led->chan_nr >= LP5523_LEDS) {
792 dev_err(dev, "Use channel numbers between 0 and %d\n",
793 LP5523_LEDS - 1);
794 return -EINVAL;
795 }
796
797 if (pdata->led_config[chan].name) {
798 led->cdev.name = pdata->led_config[chan].name;
799 } else {
800 snprintf(name, sizeof(name), "%s:channel%d",
801 pdata->label ? : chip_name, chan);
802 led->cdev.name = name;
803 }
804
805 led->cdev.brightness_set = lp5523_set_brightness;
806 res = led_classdev_register(dev, &led->cdev);
807 if (res < 0) {
808 dev_err(dev, "couldn't register led on channel %d\n",
809 chan);
810 return res;
811 }
812 res = sysfs_create_group(&led->cdev.dev->kobj,
813 &lp5523_led_attribute_group);
814 if (res < 0) {
815 dev_err(dev, "couldn't register current attribute\n");
816 led_classdev_unregister(&led->cdev);
817 return res;
818 }
819 } else {
820 led->led_current = 0;
821 }
822 return 0;
823}
824
825static void lp5523_unregister_leds(struct lp5523_chip *chip) 776static void lp5523_unregister_leds(struct lp5523_chip *chip)
826{ 777{
827 int i; 778 int i;
@@ -842,6 +793,7 @@ static struct lp55xx_device_config lp5523_cfg = {
842 .addr = LP5523_REG_ENABLE, 793 .addr = LP5523_REG_ENABLE,
843 .val = LP5523_ENABLE, 794 .val = LP5523_ENABLE,
844 }, 795 },
796 .max_channel = LP5523_MAX_LEDS,
845 .post_init_device = lp5523_post_init_device, 797 .post_init_device = lp5523_post_init_device,
846}; 798};
847 799