From: Milo(Woogyom) Kim Date: Tue, 5 Feb 2013 09:03:08 +0000 (+0900) Subject: leds-lp55xx: use common lp55xx data structure in _probe() X-Git-Tag: v3.9-rc1~79^2~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6a0c9a47963cc72c68713923ead60d1e72e7136c;p=profile%2Fivi%2Fkernel-x86-ivi.git 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 Signed-off-by: Bryan Wu --- diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 8ef8f44b..1eab155 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -34,6 +34,9 @@ #include #include #include +#include + +#include "leds-lp55xx-common.h" #define LP5521_PROGRAM_LENGTH 32 /* in bytes */ @@ -872,27 +875,32 @@ static void lp5521_unregister_leds(struct lp5521_chip *chip) static int lp5521_probe(struct i2c_client *client, const struct i2c_device_id *id) { - struct lp5521_chip *old_chip; - struct lp5521_platform_data *old_pdata; + struct lp5521_chip *old_chip = NULL; int ret; + struct lp55xx_chip *chip; + struct lp55xx_led *led; + struct lp55xx_platform_data *pdata = client->dev.platform_data; - old_chip = devm_kzalloc(&client->dev, sizeof(*old_chip), GFP_KERNEL); - if (!old_chip) - return -ENOMEM; - - i2c_set_clientdata(client, old_chip); - old_chip->client = client; - - old_pdata = client->dev.platform_data; - - if (!old_pdata) { + if (!pdata) { dev_err(&client->dev, "no platform data\n"); return -EINVAL; } - mutex_init(&old_chip->lock); + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + led = devm_kzalloc(&client->dev, + sizeof(*led) * pdata->num_channels, GFP_KERNEL); + if (!led) + return -ENOMEM; + + chip->cl = client; + chip->pdata = pdata; + + mutex_init(&chip->lock); - old_chip->pdata = old_pdata; + i2c_set_clientdata(client, led); ret = lp5521_init_device(old_chip); if (ret) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 49b9762..71bda36 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -34,6 +34,9 @@ #include #include #include +#include + +#include "leds-lp55xx-common.h" #define LP5523_REG_ENABLE 0x00 #define LP5523_REG_OP_MODE 0x01 @@ -1010,27 +1013,32 @@ static void lp5523_deinit_device(struct lp5523_chip *chip) static int lp5523_probe(struct i2c_client *client, const struct i2c_device_id *id) { - struct lp5523_chip *old_chip; - struct lp5523_platform_data *old_pdata; + struct lp5523_chip *old_chip = NULL; int ret, i; + struct lp55xx_chip *chip; + struct lp55xx_led *led; + struct lp55xx_platform_data *pdata = client->dev.platform_data; - old_chip = devm_kzalloc(&client->dev, sizeof(*old_chip), GFP_KERNEL); - if (!old_chip) - return -ENOMEM; - - i2c_set_clientdata(client, old_chip); - old_chip->client = client; - - old_pdata = client->dev.platform_data; - - if (!old_pdata) { + if (!pdata) { dev_err(&client->dev, "no platform data\n"); return -EINVAL; } - mutex_init(&old_chip->lock); + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + led = devm_kzalloc(&client->dev, + sizeof(*led) * pdata->num_channels, GFP_KERNEL); + if (!led) + return -ENOMEM; + + chip->cl = client; + chip->pdata = pdata; + + mutex_init(&chip->lock); - old_chip->pdata = old_pdata; + i2c_set_clientdata(client, led); ret = lp5523_init_device(old_chip); if (ret)