diff options
author | Milo(Woogyom) Kim <milo.kim@ti.com> | 2013-02-05 04:03:08 -0500 |
---|---|---|
committer | Bryan Wu <cooloney@gmail.com> | 2013-02-06 18:59:26 -0500 |
commit | 6a0c9a47963cc72c68713923ead60d1e72e7136c (patch) | |
tree | eafe47fca8ae4674e48ed054d515d66711844fb7 /drivers/leds | |
parent | 945c700746cbfa3375bf88123c2cf6c210f4cc2c (diff) |
leds-lp55xx: use common lp55xx data structure in _probe()
LP5521 and LP5523 data structures have common features.
Use common lp55xx data structures rather than chip specific data.
Legacy code in probe is replaced with this new data structures.
lp55xx_chip : Common data between lp5521_chip and lp5523_chip
lp55xx_led : Common LED structure between lp5521_led and lp5523_led
lp55xx_platform_data : Common platform data between lp5521_platform_data and
lp5523_platform_data
Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r-- | drivers/leds/leds-lp5521.c | 36 | ||||
-rw-r--r-- | drivers/leds/leds-lp5523.c | 36 |
2 files changed, 44 insertions, 28 deletions
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 8ef8f44bf86e..1eab1557a612 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c | |||
@@ -34,6 +34,9 @@ | |||
34 | #include <linux/leds-lp5521.h> | 34 | #include <linux/leds-lp5521.h> |
35 | #include <linux/workqueue.h> | 35 | #include <linux/workqueue.h> |
36 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
37 | #include <linux/platform_data/leds-lp55xx.h> | ||
38 | |||
39 | #include "leds-lp55xx-common.h" | ||
37 | 40 | ||
38 | #define LP5521_PROGRAM_LENGTH 32 /* in bytes */ | 41 | #define LP5521_PROGRAM_LENGTH 32 /* in bytes */ |
39 | 42 | ||
@@ -872,27 +875,32 @@ static void lp5521_unregister_leds(struct lp5521_chip *chip) | |||
872 | static int lp5521_probe(struct i2c_client *client, | 875 | static int lp5521_probe(struct i2c_client *client, |
873 | const struct i2c_device_id *id) | 876 | const struct i2c_device_id *id) |
874 | { | 877 | { |
875 | struct lp5521_chip *old_chip; | 878 | struct lp5521_chip *old_chip = NULL; |
876 | struct lp5521_platform_data *old_pdata; | ||
877 | int ret; | 879 | int ret; |
880 | struct lp55xx_chip *chip; | ||
881 | struct lp55xx_led *led; | ||
882 | struct lp55xx_platform_data *pdata = client->dev.platform_data; | ||
878 | 883 | ||
879 | old_chip = devm_kzalloc(&client->dev, sizeof(*old_chip), GFP_KERNEL); | 884 | if (!pdata) { |
880 | if (!old_chip) | ||
881 | return -ENOMEM; | ||
882 | |||
883 | i2c_set_clientdata(client, old_chip); | ||
884 | old_chip->client = client; | ||
885 | |||
886 | old_pdata = client->dev.platform_data; | ||
887 | |||
888 | if (!old_pdata) { | ||
889 | dev_err(&client->dev, "no platform data\n"); | 885 | dev_err(&client->dev, "no platform data\n"); |
890 | return -EINVAL; | 886 | return -EINVAL; |
891 | } | 887 | } |
892 | 888 | ||
893 | mutex_init(&old_chip->lock); | 889 | chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); |
890 | if (!chip) | ||
891 | return -ENOMEM; | ||
892 | |||
893 | led = devm_kzalloc(&client->dev, | ||
894 | sizeof(*led) * pdata->num_channels, GFP_KERNEL); | ||
895 | if (!led) | ||
896 | return -ENOMEM; | ||
897 | |||
898 | chip->cl = client; | ||
899 | chip->pdata = pdata; | ||
900 | |||
901 | mutex_init(&chip->lock); | ||
894 | 902 | ||
895 | old_chip->pdata = old_pdata; | 903 | i2c_set_clientdata(client, led); |
896 | 904 | ||
897 | ret = lp5521_init_device(old_chip); | 905 | ret = lp5521_init_device(old_chip); |
898 | if (ret) | 906 | if (ret) |
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 49b976271d96..71bda3670ff0 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c | |||
@@ -34,6 +34,9 @@ | |||
34 | #include <linux/leds-lp5523.h> | 34 | #include <linux/leds-lp5523.h> |
35 | #include <linux/workqueue.h> | 35 | #include <linux/workqueue.h> |
36 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
37 | #include <linux/platform_data/leds-lp55xx.h> | ||
38 | |||
39 | #include "leds-lp55xx-common.h" | ||
37 | 40 | ||
38 | #define LP5523_REG_ENABLE 0x00 | 41 | #define LP5523_REG_ENABLE 0x00 |
39 | #define LP5523_REG_OP_MODE 0x01 | 42 | #define LP5523_REG_OP_MODE 0x01 |
@@ -1010,27 +1013,32 @@ static void lp5523_deinit_device(struct lp5523_chip *chip) | |||
1010 | static int lp5523_probe(struct i2c_client *client, | 1013 | static int lp5523_probe(struct i2c_client *client, |
1011 | const struct i2c_device_id *id) | 1014 | const struct i2c_device_id *id) |
1012 | { | 1015 | { |
1013 | struct lp5523_chip *old_chip; | 1016 | struct lp5523_chip *old_chip = NULL; |
1014 | struct lp5523_platform_data *old_pdata; | ||
1015 | int ret, i; | 1017 | int ret, i; |
1018 | struct lp55xx_chip *chip; | ||
1019 | struct lp55xx_led *led; | ||
1020 | struct lp55xx_platform_data *pdata = client->dev.platform_data; | ||
1016 | 1021 | ||
1017 | old_chip = devm_kzalloc(&client->dev, sizeof(*old_chip), GFP_KERNEL); | 1022 | if (!pdata) { |
1018 | if (!old_chip) | ||
1019 | return -ENOMEM; | ||
1020 | |||
1021 | i2c_set_clientdata(client, old_chip); | ||
1022 | old_chip->client = client; | ||
1023 | |||
1024 | old_pdata = client->dev.platform_data; | ||
1025 | |||
1026 | if (!old_pdata) { | ||
1027 | dev_err(&client->dev, "no platform data\n"); | 1023 | dev_err(&client->dev, "no platform data\n"); |
1028 | return -EINVAL; | 1024 | return -EINVAL; |
1029 | } | 1025 | } |
1030 | 1026 | ||
1031 | mutex_init(&old_chip->lock); | 1027 | chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); |
1028 | if (!chip) | ||
1029 | return -ENOMEM; | ||
1030 | |||
1031 | led = devm_kzalloc(&client->dev, | ||
1032 | sizeof(*led) * pdata->num_channels, GFP_KERNEL); | ||
1033 | if (!led) | ||
1034 | return -ENOMEM; | ||
1035 | |||
1036 | chip->cl = client; | ||
1037 | chip->pdata = pdata; | ||
1038 | |||
1039 | mutex_init(&chip->lock); | ||
1032 | 1040 | ||
1033 | old_chip->pdata = old_pdata; | 1041 | i2c_set_clientdata(client, led); |
1034 | 1042 | ||
1035 | ret = lp5523_init_device(old_chip); | 1043 | ret = lp5523_init_device(old_chip); |
1036 | if (ret) | 1044 | if (ret) |