aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 03:53:40 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-06 18:59:26 -0500
commitf652480802b636f86e194f9680347676b655d856 (patch)
tree37b1673e85657841c7864e12bb807cc31647f6d0
parent1a9914855d2868112257dbc5771ddc6ebc9b2cab (diff)
leds-lp55xx: clean up init leds in lp5521/5523
To make LED initialization code simple, new function, _register_leds() is added at each driver. This patch is a preceding step for lp55xx common driver architecture. Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
-rw-r--r--drivers/leds/leds-lp5521.c69
-rw-r--r--drivers/leds/leds-lp5523.c73
2 files changed, 86 insertions, 56 deletions
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index fd963fe0a944..f4cd0fe67fef 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -799,12 +799,50 @@ static int lp5521_init_led(struct lp5521_led *led,
799 return 0; 799 return 0;
800} 800}
801 801
802static int lp5521_register_leds(struct lp5521_chip *chip)
803{
804 struct lp5521_platform_data *pdata = chip->pdata;
805 struct i2c_client *client = chip->client;
806 int i;
807 int led;
808 int ret;
809
810 /* Initialize leds */
811 chip->num_channels = pdata->num_channels;
812 chip->num_leds = 0;
813 led = 0;
814 for (i = 0; i < pdata->num_channels; i++) {
815 /* Do not initialize channels that are not connected */
816 if (pdata->led_config[i].led_current == 0)
817 continue;
818
819 ret = lp5521_init_led(&chip->leds[led], client, i, pdata);
820 if (ret) {
821 dev_err(&client->dev, "error initializing leds\n");
822 return ret;
823 }
824 chip->num_leds++;
825
826 chip->leds[led].id = led;
827 /* Set initial LED current */
828 lp5521_set_led_current(chip, led,
829 chip->leds[led].led_current);
830
831 INIT_WORK(&(chip->leds[led].brightness_work),
832 lp5521_led_brightness_work);
833
834 led++;
835 }
836
837 return 0;
838}
839
802static int lp5521_probe(struct i2c_client *client, 840static int lp5521_probe(struct i2c_client *client,
803 const struct i2c_device_id *id) 841 const struct i2c_device_id *id)
804{ 842{
805 struct lp5521_chip *chip; 843 struct lp5521_chip *chip;
806 struct lp5521_platform_data *pdata; 844 struct lp5521_platform_data *pdata;
807 int ret, i, led; 845 int ret, i;
808 846
809 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 847 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
810 if (!chip) 848 if (!chip)
@@ -836,32 +874,9 @@ static int lp5521_probe(struct i2c_client *client,
836 goto fail1; 874 goto fail1;
837 } 875 }
838 876
839 /* Initialize leds */ 877 ret = lp5521_register_leds(chip);
840 chip->num_channels = pdata->num_channels; 878 if (ret)
841 chip->num_leds = 0; 879 goto fail2;
842 led = 0;
843 for (i = 0; i < pdata->num_channels; i++) {
844 /* Do not initialize channels that are not connected */
845 if (pdata->led_config[i].led_current == 0)
846 continue;
847
848 ret = lp5521_init_led(&chip->leds[led], client, i, pdata);
849 if (ret) {
850 dev_err(&client->dev, "error initializing leds\n");
851 goto fail2;
852 }
853 chip->num_leds++;
854
855 chip->leds[led].id = led;
856 /* Set initial LED current */
857 lp5521_set_led_current(chip, led,
858 chip->leds[led].led_current);
859
860 INIT_WORK(&(chip->leds[led].brightness_work),
861 lp5521_led_brightness_work);
862
863 led++;
864 }
865 880
866 ret = lp5521_register_sysfs(client); 881 ret = lp5521_register_sysfs(client);
867 if (ret) { 882 if (ret) {
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index ddb482aebe14..f5e893289816 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -896,6 +896,46 @@ static int lp5523_init_led(struct lp5523_led *led, struct device *dev,
896 return 0; 896 return 0;
897} 897}
898 898
899static int lp5523_register_leds(struct lp5523_chip *chip, const char *name)
900{
901 struct lp5523_platform_data *pdata = chip->pdata;
902 struct i2c_client *client = chip->client;
903 int i;
904 int led;
905 int ret;
906
907 /* Initialize leds */
908 chip->num_channels = pdata->num_channels;
909 chip->num_leds = 0;
910 led = 0;
911 for (i = 0; i < pdata->num_channels; i++) {
912 /* Do not initialize channels that are not connected */
913 if (pdata->led_config[i].led_current == 0)
914 continue;
915
916 INIT_WORK(&chip->leds[led].brightness_work,
917 lp5523_led_brightness_work);
918
919 ret = lp5523_init_led(&chip->leds[led], &client->dev, i, pdata,
920 name);
921 if (ret) {
922 dev_err(&client->dev, "error initializing leds\n");
923 return ret;
924 }
925 chip->num_leds++;
926
927 chip->leds[led].id = led;
928 /* Set LED current */
929 lp5523_write(client,
930 LP5523_REG_LED_CURRENT_BASE + chip->leds[led].chan_nr,
931 chip->leds[led].led_current);
932
933 led++;
934 }
935
936 return 0;
937}
938
899static int lp5523_init_device(struct lp5523_chip *chip) 939static int lp5523_init_device(struct lp5523_chip *chip)
900{ 940{
901 struct lp5523_platform_data *pdata = chip->pdata; 941 struct lp5523_platform_data *pdata = chip->pdata;
@@ -938,7 +978,7 @@ static int lp5523_probe(struct i2c_client *client,
938{ 978{
939 struct lp5523_chip *chip; 979 struct lp5523_chip *chip;
940 struct lp5523_platform_data *pdata; 980 struct lp5523_platform_data *pdata;
941 int ret, i, led; 981 int ret, i;
942 982
943 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 983 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
944 if (!chip) 984 if (!chip)
@@ -978,34 +1018,9 @@ static int lp5523_probe(struct i2c_client *client,
978 goto fail1; 1018 goto fail1;
979 } 1019 }
980 1020
981 /* Initialize leds */ 1021 ret = lp5523_register_leds(chip, id->name);
982 chip->num_channels = pdata->num_channels; 1022 if (ret)
983 chip->num_leds = 0; 1023 goto fail2;
984 led = 0;
985 for (i = 0; i < pdata->num_channels; i++) {
986 /* Do not initialize channels that are not connected */
987 if (pdata->led_config[i].led_current == 0)
988 continue;
989
990 INIT_WORK(&chip->leds[led].brightness_work,
991 lp5523_led_brightness_work);
992
993 ret = lp5523_init_led(&chip->leds[led], &client->dev, i, pdata,
994 id->name);
995 if (ret) {
996 dev_err(&client->dev, "error initializing leds\n");
997 goto fail2;
998 }
999 chip->num_leds++;
1000
1001 chip->leds[led].id = led;
1002 /* Set LED current */
1003 lp5523_write(client,
1004 LP5523_REG_LED_CURRENT_BASE + chip->leds[led].chan_nr,
1005 chip->leds[led].led_current);
1006
1007 led++;
1008 }
1009 1024
1010 ret = lp5523_register_sysfs(client); 1025 ret = lp5523_register_sysfs(client);
1011 if (ret) { 1026 if (ret) {