summaryrefslogtreecommitdiff
path: root/drivers/leds/leds-lp5521.c
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 17:53:40 +0900
committerBryan Wu <cooloney@gmail.com>2013-02-06 15:59:26 -0800
commitf652480802b636f86e194f9680347676b655d856 (patch)
tree37b1673e85657841c7864e12bb807cc31647f6d0 /drivers/leds/leds-lp5521.c
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>
Diffstat (limited to 'drivers/leds/leds-lp5521.c')
-rw-r--r--drivers/leds/leds-lp5521.c69
1 files changed, 42 insertions, 27 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,
return 0;
}
+static int lp5521_register_leds(struct lp5521_chip *chip)
+{
+ struct lp5521_platform_data *pdata = chip->pdata;
+ struct i2c_client *client = chip->client;
+ int i;
+ int led;
+ int ret;
+
+ /* Initialize leds */
+ chip->num_channels = pdata->num_channels;
+ chip->num_leds = 0;
+ led = 0;
+ for (i = 0; i < pdata->num_channels; i++) {
+ /* Do not initialize channels that are not connected */
+ if (pdata->led_config[i].led_current == 0)
+ continue;
+
+ ret = lp5521_init_led(&chip->leds[led], client, i, pdata);
+ if (ret) {
+ dev_err(&client->dev, "error initializing leds\n");
+ return ret;
+ }
+ chip->num_leds++;
+
+ chip->leds[led].id = led;
+ /* Set initial LED current */
+ lp5521_set_led_current(chip, led,
+ chip->leds[led].led_current);
+
+ INIT_WORK(&(chip->leds[led].brightness_work),
+ lp5521_led_brightness_work);
+
+ led++;
+ }
+
+ return 0;
+}
+
static int lp5521_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct lp5521_chip *chip;
struct lp5521_platform_data *pdata;
- int ret, i, led;
+ int ret, i;
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
@@ -836,32 +874,9 @@ static int lp5521_probe(struct i2c_client *client,
goto fail1;
}
- /* Initialize leds */
- chip->num_channels = pdata->num_channels;
- chip->num_leds = 0;
- led = 0;
- for (i = 0; i < pdata->num_channels; i++) {
- /* Do not initialize channels that are not connected */
- if (pdata->led_config[i].led_current == 0)
- continue;
-
- ret = lp5521_init_led(&chip->leds[led], client, i, pdata);
- if (ret) {
- dev_err(&client->dev, "error initializing leds\n");
- goto fail2;
- }
- chip->num_leds++;
-
- chip->leds[led].id = led;
- /* Set initial LED current */
- lp5521_set_led_current(chip, led,
- chip->leds[led].led_current);
-
- INIT_WORK(&(chip->leds[led].brightness_work),
- lp5521_led_brightness_work);
-
- led++;
- }
+ ret = lp5521_register_leds(chip);
+ if (ret)
+ goto fail2;
ret = lp5521_register_sysfs(client);
if (ret) {