diff options
-rw-r--r-- | drivers/leds/leds-lp5521.c | 102 | ||||
-rw-r--r-- | drivers/leds/leds-lp5523.c | 47 |
2 files changed, 84 insertions, 65 deletions
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index cb8a5220200b..24f439f78bd8 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c | |||
@@ -687,6 +687,59 @@ static void lp5521_unregister_sysfs(struct i2c_client *client) | |||
687 | &lp5521_led_attribute_group); | 687 | &lp5521_led_attribute_group); |
688 | } | 688 | } |
689 | 689 | ||
690 | static int lp5521_init_device(struct lp5521_chip *chip) | ||
691 | { | ||
692 | struct lp5521_platform_data *pdata = chip->pdata; | ||
693 | struct i2c_client *client = chip->client; | ||
694 | int ret; | ||
695 | u8 buf; | ||
696 | |||
697 | if (pdata->setup_resources) { | ||
698 | ret = pdata->setup_resources(); | ||
699 | if (ret < 0) | ||
700 | return ret; | ||
701 | } | ||
702 | |||
703 | if (pdata->enable) { | ||
704 | pdata->enable(0); | ||
705 | usleep_range(1000, 2000); /* Keep enable down at least 1ms */ | ||
706 | pdata->enable(1); | ||
707 | usleep_range(1000, 2000); /* 500us abs min. */ | ||
708 | } | ||
709 | |||
710 | lp5521_write(client, LP5521_REG_RESET, 0xff); | ||
711 | usleep_range(10000, 20000); /* | ||
712 | * Exact value is not available. 10 - 20ms | ||
713 | * appears to be enough for reset. | ||
714 | */ | ||
715 | |||
716 | /* | ||
717 | * Make sure that the chip is reset by reading back the r channel | ||
718 | * current reg. This is dummy read is required on some platforms - | ||
719 | * otherwise further access to the R G B channels in the | ||
720 | * LP5521_REG_ENABLE register will not have any effect - strange! | ||
721 | */ | ||
722 | ret = lp5521_read(client, LP5521_REG_R_CURRENT, &buf); | ||
723 | if (ret) { | ||
724 | dev_err(&client->dev, "error in resetting chip\n"); | ||
725 | return ret; | ||
726 | } | ||
727 | if (buf != LP5521_REG_R_CURR_DEFAULT) { | ||
728 | dev_err(&client->dev, | ||
729 | "unexpected data in register (expected 0x%x got 0x%x)\n", | ||
730 | LP5521_REG_R_CURR_DEFAULT, buf); | ||
731 | ret = -EINVAL; | ||
732 | return ret; | ||
733 | } | ||
734 | usleep_range(10000, 20000); | ||
735 | |||
736 | ret = lp5521_detect(client); | ||
737 | if (ret) | ||
738 | dev_err(&client->dev, "Chip not found\n"); | ||
739 | |||
740 | return ret; | ||
741 | } | ||
742 | |||
690 | static int lp5521_init_led(struct lp5521_led *led, | 743 | static int lp5521_init_led(struct lp5521_led *led, |
691 | struct i2c_client *client, | 744 | struct i2c_client *client, |
692 | int chan, struct lp5521_platform_data *pdata) | 745 | int chan, struct lp5521_platform_data *pdata) |
@@ -742,7 +795,6 @@ static int lp5521_probe(struct i2c_client *client, | |||
742 | struct lp5521_chip *chip; | 795 | struct lp5521_chip *chip; |
743 | struct lp5521_platform_data *pdata; | 796 | struct lp5521_platform_data *pdata; |
744 | int ret, i, led; | 797 | int ret, i, led; |
745 | u8 buf; | ||
746 | 798 | ||
747 | chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); | 799 | chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); |
748 | if (!chip) | 800 | if (!chip) |
@@ -762,51 +814,9 @@ static int lp5521_probe(struct i2c_client *client, | |||
762 | 814 | ||
763 | chip->pdata = pdata; | 815 | chip->pdata = pdata; |
764 | 816 | ||
765 | if (pdata->setup_resources) { | 817 | ret = lp5521_init_device(chip); |
766 | ret = pdata->setup_resources(); | 818 | if (ret) |
767 | if (ret < 0) | 819 | goto fail1; |
768 | return ret; | ||
769 | } | ||
770 | |||
771 | if (pdata->enable) { | ||
772 | pdata->enable(0); | ||
773 | usleep_range(1000, 2000); /* Keep enable down at least 1ms */ | ||
774 | pdata->enable(1); | ||
775 | usleep_range(1000, 2000); /* 500us abs min. */ | ||
776 | } | ||
777 | |||
778 | lp5521_write(client, LP5521_REG_RESET, 0xff); | ||
779 | usleep_range(10000, 20000); /* | ||
780 | * Exact value is not available. 10 - 20ms | ||
781 | * appears to be enough for reset. | ||
782 | */ | ||
783 | |||
784 | /* | ||
785 | * Make sure that the chip is reset by reading back the r channel | ||
786 | * current reg. This is dummy read is required on some platforms - | ||
787 | * otherwise further access to the R G B channels in the | ||
788 | * LP5521_REG_ENABLE register will not have any effect - strange! | ||
789 | */ | ||
790 | ret = lp5521_read(client, LP5521_REG_R_CURRENT, &buf); | ||
791 | if (ret) { | ||
792 | dev_err(&client->dev, "error in resetting chip\n"); | ||
793 | goto fail2; | ||
794 | } | ||
795 | if (buf != LP5521_REG_R_CURR_DEFAULT) { | ||
796 | dev_err(&client->dev, | ||
797 | "unexpected data in register (expected 0x%x got 0x%x)\n", | ||
798 | LP5521_REG_R_CURR_DEFAULT, buf); | ||
799 | ret = -EINVAL; | ||
800 | goto fail2; | ||
801 | } | ||
802 | usleep_range(10000, 20000); | ||
803 | |||
804 | ret = lp5521_detect(client); | ||
805 | |||
806 | if (ret) { | ||
807 | dev_err(&client->dev, "Chip not found\n"); | ||
808 | goto fail2; | ||
809 | } | ||
810 | 820 | ||
811 | dev_info(&client->dev, "%s programmable led chip found\n", id->name); | 821 | dev_info(&client->dev, "%s programmable led chip found\n", id->name); |
812 | 822 | ||
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 7f5be8948cde..491ea725bb0b 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c | |||
@@ -896,6 +896,33 @@ static int lp5523_init_led(struct lp5523_led *led, struct device *dev, | |||
896 | return 0; | 896 | return 0; |
897 | } | 897 | } |
898 | 898 | ||
899 | static int lp5523_init_device(struct lp5523_chip *chip) | ||
900 | { | ||
901 | struct lp5523_platform_data *pdata = chip->pdata; | ||
902 | struct i2c_client *client = chip->client; | ||
903 | int ret; | ||
904 | |||
905 | if (pdata->setup_resources) { | ||
906 | ret = pdata->setup_resources(); | ||
907 | if (ret < 0) | ||
908 | return ret; | ||
909 | } | ||
910 | |||
911 | if (pdata->enable) { | ||
912 | pdata->enable(0); | ||
913 | usleep_range(1000, 2000); /* Keep enable down at least 1ms */ | ||
914 | pdata->enable(1); | ||
915 | usleep_range(1000, 2000); /* 500us abs min. */ | ||
916 | } | ||
917 | |||
918 | lp5523_write(client, LP5523_REG_RESET, 0xff); | ||
919 | usleep_range(10000, 20000); /* | ||
920 | * Exact value is not available. 10 - 20ms | ||
921 | * appears to be enough for reset. | ||
922 | */ | ||
923 | return lp5523_detect(client); | ||
924 | } | ||
925 | |||
899 | static int lp5523_probe(struct i2c_client *client, | 926 | static int lp5523_probe(struct i2c_client *client, |
900 | const struct i2c_device_id *id) | 927 | const struct i2c_device_id *id) |
901 | { | 928 | { |
@@ -921,25 +948,7 @@ static int lp5523_probe(struct i2c_client *client, | |||
921 | 948 | ||
922 | chip->pdata = pdata; | 949 | chip->pdata = pdata; |
923 | 950 | ||
924 | if (pdata->setup_resources) { | 951 | ret = lp5523_init_device(chip); |
925 | ret = pdata->setup_resources(); | ||
926 | if (ret < 0) | ||
927 | return ret; | ||
928 | } | ||
929 | |||
930 | if (pdata->enable) { | ||
931 | pdata->enable(0); | ||
932 | usleep_range(1000, 2000); /* Keep enable down at least 1ms */ | ||
933 | pdata->enable(1); | ||
934 | usleep_range(1000, 2000); /* 500us abs min. */ | ||
935 | } | ||
936 | |||
937 | lp5523_write(client, LP5523_REG_RESET, 0xff); | ||
938 | usleep_range(10000, 20000); /* | ||
939 | * Exact value is not available. 10 - 20ms | ||
940 | * appears to be enough for reset. | ||
941 | */ | ||
942 | ret = lp5523_detect(client); | ||
943 | if (ret) | 952 | if (ret) |
944 | goto fail1; | 953 | goto fail1; |
945 | 954 | ||