aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
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
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')
-rw-r--r--drivers/leds/leds-lp5521.c50
-rw-r--r--drivers/leds/leds-lp5523.c62
-rw-r--r--drivers/leds/leds-lp55xx-common.c66
-rw-r--r--drivers/leds/leds-lp55xx-common.h2
4 files changed, 76 insertions, 104 deletions
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index dc58f4106d09..bda03049fb3c 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -689,55 +689,6 @@ static void lp5521_unregister_sysfs(struct i2c_client *client)
689 &lp5521_led_attribute_group); 689 &lp5521_led_attribute_group);
690} 690}
691 691
692static int lp5521_init_led(struct lp5521_led *led,
693 struct i2c_client *client,
694 int chan, struct lp5521_platform_data *pdata)
695{
696 struct device *dev = &client->dev;
697 char name[32];
698 int res;
699
700 if (chan >= LP5521_MAX_LEDS)
701 return -EINVAL;
702
703 if (pdata->led_config[chan].led_current == 0)
704 return 0;
705
706 led->led_current = pdata->led_config[chan].led_current;
707 led->max_current = pdata->led_config[chan].max_current;
708 led->chan_nr = pdata->led_config[chan].chan_nr;
709
710 if (led->chan_nr >= LP5521_MAX_LEDS) {
711 dev_err(dev, "Use channel numbers between 0 and %d\n",
712 LP5521_MAX_LEDS - 1);
713 return -EINVAL;
714 }
715
716 led->cdev.brightness_set = lp5521_set_brightness;
717 if (pdata->led_config[chan].name) {
718 led->cdev.name = pdata->led_config[chan].name;
719 } else {
720 snprintf(name, sizeof(name), "%s:channel%d",
721 pdata->label ?: client->name, chan);
722 led->cdev.name = name;
723 }
724
725 res = led_classdev_register(dev, &led->cdev);
726 if (res < 0) {
727 dev_err(dev, "couldn't register led on channel %d\n", chan);
728 return res;
729 }
730
731 res = sysfs_create_group(&led->cdev.dev->kobj,
732 &lp5521_led_attribute_group);
733 if (res < 0) {
734 dev_err(dev, "couldn't register current attribute\n");
735 led_classdev_unregister(&led->cdev);
736 return res;
737 }
738 return 0;
739}
740
741static void lp5521_unregister_leds(struct lp5521_chip *chip) 692static void lp5521_unregister_leds(struct lp5521_chip *chip)
742{ 693{
743 int i; 694 int i;
@@ -758,6 +709,7 @@ static struct lp55xx_device_config lp5521_cfg = {
758 .addr = LP5521_REG_ENABLE, 709 .addr = LP5521_REG_ENABLE,
759 .val = LP5521_ENABLE_DEFAULT, 710 .val = LP5521_ENABLE_DEFAULT,
760 }, 711 },
712 .max_channel = LP5521_MAX_LEDS,
761 .post_init_device = lp5521_post_init_device, 713 .post_init_device = lp5521_post_init_device,
762}; 714};
763 715
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
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
diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h
index 219780a2d4eb..70d2bdf54b8e 100644
--- a/drivers/leds/leds-lp55xx-common.h
+++ b/drivers/leds/leds-lp55xx-common.h
@@ -32,6 +32,7 @@ struct lp55xx_reg {
32 * struct lp55xx_device_config 32 * struct lp55xx_device_config
33 * @reset : Chip specific reset command 33 * @reset : Chip specific reset command
34 * @enable : Chip specific enable command 34 * @enable : Chip specific enable command
35 * @max_channel : Maximum number of channels
35 * @post_init_device : Chip specific initialization code 36 * @post_init_device : Chip specific initialization code
36 * @brightness_work_fn : Brightness work function 37 * @brightness_work_fn : Brightness work function
37 * @set_led_current : LED current set function 38 * @set_led_current : LED current set function
@@ -39,6 +40,7 @@ struct lp55xx_reg {
39struct lp55xx_device_config { 40struct lp55xx_device_config {
40 const struct lp55xx_reg reset; 41 const struct lp55xx_reg reset;
41 const struct lp55xx_reg enable; 42 const struct lp55xx_reg enable;
43 const int max_channel;
42 44
43 /* define if the device has specific initialization process */ 45 /* define if the device has specific initialization process */
44 int (*post_init_device) (struct lp55xx_chip *chip); 46 int (*post_init_device) (struct lp55xx_chip *chip);