summaryrefslogtreecommitdiff
path: root/drivers/leds/leds-lp55xx-common.c
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 19:06:27 +0900
committerBryan Wu <cooloney@gmail.com>2013-02-06 15:59:28 -0800
commit9e9b3db1b2f725bacaf1b7e8708a0c78265bde97 (patch)
tree498353c79883feb33c7ea93dda7742eb7c1b7dcc /drivers/leds/leds-lp55xx-common.c
parent6ce6176263393dd80b9a537c1e1462b8529f240b (diff)
leds-lp55xx: use lp55xx common led registration function
LED class devices are registered in lp5521_register_leds() and lp5523_register_leds(). Two separate functions are merged into consolidated lp55xx function, lp55xx_register_leds(). Error handling fix: Unregistering LEDS are handled in lp55xx_register_leds() when LED registration failure occurs. So each driver error handler is changed to 'err_register_leds' Chip dependency: 'brightness_work_fn' and 'set_led_current' To make the structure abstract, both functions are configured in each driver. Those functions should be done by each driver because register control is chip-dependant work. lp55xx_init_led: skeleton Will be filled in next patch Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds/leds-lp55xx-common.c')
-rw-r--r--drivers/leds/leds-lp55xx-common.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index bcabf2cb949a..1fab1d1c4502 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -63,6 +63,12 @@ static int lp55xx_post_init_device(struct lp55xx_chip *chip)
return cfg->post_init_device(chip);
}
+static int lp55xx_init_led(struct lp55xx_led *led,
+ struct lp55xx_chip *chip, int chan)
+{
+ return 0;
+}
+
int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
{
return i2c_smbus_write_byte_data(chip->cl, reg, val);
@@ -170,6 +176,55 @@ void lp55xx_deinit_device(struct lp55xx_chip *chip)
}
EXPORT_SYMBOL_GPL(lp55xx_deinit_device);
+int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip)
+{
+ struct lp55xx_platform_data *pdata = chip->pdata;
+ struct lp55xx_device_config *cfg = chip->cfg;
+ int num_channels = pdata->num_channels;
+ struct lp55xx_led *each;
+ u8 led_current;
+ int ret;
+ int i;
+
+ if (!cfg->brightness_work_fn) {
+ dev_err(&chip->cl->dev, "empty brightness configuration\n");
+ return -EINVAL;
+ }
+
+ for (i = 0; i < num_channels; i++) {
+
+ /* do not initialize channels that are not connected */
+ if (pdata->led_config[i].led_current == 0)
+ continue;
+
+ led_current = pdata->led_config[i].led_current;
+ each = led + i;
+ ret = lp55xx_init_led(each, chip, i);
+ if (ret)
+ goto err_init_led;
+
+ INIT_WORK(&each->brightness_work, cfg->brightness_work_fn);
+
+ chip->num_leds++;
+ each->chip = chip;
+
+ /* setting led current at each channel */
+ if (cfg->set_led_current)
+ cfg->set_led_current(each, led_current);
+ }
+
+ return 0;
+
+err_init_led:
+ for (i = 0; i < chip->num_leds; i++) {
+ each = led + i;
+ led_classdev_unregister(&each->cdev);
+ flush_work(&each->brightness_work);
+ }
+ return ret;
+}
+EXPORT_SYMBOL_GPL(lp55xx_register_leds);
+
MODULE_AUTHOR("Milo Kim <milo.kim@ti.com>");
MODULE_DESCRIPTION("LP55xx Common Driver");
MODULE_LICENSE("GPL");