From eb202621f8c0fb264a35e1b35fc00bdb3114a897 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Thu, 19 Apr 2012 11:46:33 +0800 Subject: led-triggers: rename *trigger to *trig for unified naming scheme No functional change. Signed-off-by: Bryan Wu --- drivers/leds/led-triggers.c | 84 ++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 46b4c766335d..b449ed8d8712 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -99,7 +99,7 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr, EXPORT_SYMBOL_GPL(led_trigger_show); /* Caller must ensure led_cdev->trigger_lock held */ -void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger) +void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) { unsigned long flags; @@ -114,13 +114,13 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger) led_cdev->trigger = NULL; led_brightness_set(led_cdev, LED_OFF); } - if (trigger) { - write_lock_irqsave(&trigger->leddev_list_lock, flags); - list_add_tail(&led_cdev->trig_list, &trigger->led_cdevs); - write_unlock_irqrestore(&trigger->leddev_list_lock, flags); - led_cdev->trigger = trigger; - if (trigger->activate) - trigger->activate(led_cdev); + if (trig) { + write_lock_irqsave(&trig->leddev_list_lock, flags); + list_add_tail(&led_cdev->trig_list, &trig->led_cdevs); + write_unlock_irqrestore(&trig->leddev_list_lock, flags); + led_cdev->trigger = trig; + if (trig->activate) + trig->activate(led_cdev); } } EXPORT_SYMBOL_GPL(led_trigger_set); @@ -153,24 +153,24 @@ EXPORT_SYMBOL_GPL(led_trigger_set_default); /* LED Trigger Interface */ -int led_trigger_register(struct led_trigger *trigger) +int led_trigger_register(struct led_trigger *trig) { struct led_classdev *led_cdev; - struct led_trigger *trig; + struct led_trigger *_trig; - rwlock_init(&trigger->leddev_list_lock); - INIT_LIST_HEAD(&trigger->led_cdevs); + rwlock_init(&trig->leddev_list_lock); + INIT_LIST_HEAD(&trig->led_cdevs); down_write(&triggers_list_lock); /* Make sure the trigger's name isn't already in use */ - list_for_each_entry(trig, &trigger_list, next_trig) { - if (!strcmp(trig->name, trigger->name)) { + list_for_each_entry(_trig, &trigger_list, next_trig) { + if (!strcmp(_trig->name, trig->name)) { up_write(&triggers_list_lock); return -EEXIST; } } /* Add to the list of led triggers */ - list_add_tail(&trigger->next_trig, &trigger_list); + list_add_tail(&trig->next_trig, &trigger_list); up_write(&triggers_list_lock); /* Register with any LEDs that have this as a default trigger */ @@ -178,8 +178,8 @@ int led_trigger_register(struct led_trigger *trigger) list_for_each_entry(led_cdev, &leds_list, node) { down_write(&led_cdev->trigger_lock); if (!led_cdev->trigger && led_cdev->default_trigger && - !strcmp(led_cdev->default_trigger, trigger->name)) - led_trigger_set(led_cdev, trigger); + !strcmp(led_cdev->default_trigger, trig->name)) + led_trigger_set(led_cdev, trig); up_write(&led_cdev->trigger_lock); } up_read(&leds_list_lock); @@ -188,20 +188,20 @@ int led_trigger_register(struct led_trigger *trigger) } EXPORT_SYMBOL_GPL(led_trigger_register); -void led_trigger_unregister(struct led_trigger *trigger) +void led_trigger_unregister(struct led_trigger *trig) { struct led_classdev *led_cdev; /* Remove from the list of led triggers */ down_write(&triggers_list_lock); - list_del(&trigger->next_trig); + list_del(&trig->next_trig); up_write(&triggers_list_lock); /* Remove anyone actively using this trigger */ down_read(&leds_list_lock); list_for_each_entry(led_cdev, &leds_list, node) { down_write(&led_cdev->trigger_lock); - if (led_cdev->trigger == trigger) + if (led_cdev->trigger == trig) led_trigger_set(led_cdev, NULL); up_write(&led_cdev->trigger_lock); } @@ -211,58 +211,58 @@ EXPORT_SYMBOL_GPL(led_trigger_unregister); /* Simple LED Tigger Interface */ -void led_trigger_event(struct led_trigger *trigger, +void led_trigger_event(struct led_trigger *trig, enum led_brightness brightness) { struct list_head *entry; - if (!trigger) + if (!trig) return; - read_lock(&trigger->leddev_list_lock); - list_for_each(entry, &trigger->led_cdevs) { + read_lock(&trig->leddev_list_lock); + list_for_each(entry, &trig->led_cdevs) { struct led_classdev *led_cdev; led_cdev = list_entry(entry, struct led_classdev, trig_list); led_set_brightness(led_cdev, brightness); } - read_unlock(&trigger->leddev_list_lock); + read_unlock(&trig->leddev_list_lock); } EXPORT_SYMBOL_GPL(led_trigger_event); -void led_trigger_blink(struct led_trigger *trigger, +void led_trigger_blink(struct led_trigger *trig, unsigned long *delay_on, unsigned long *delay_off) { struct list_head *entry; - if (!trigger) + if (!trig) return; - read_lock(&trigger->leddev_list_lock); - list_for_each(entry, &trigger->led_cdevs) { + read_lock(&trig->leddev_list_lock); + list_for_each(entry, &trig->led_cdevs) { struct led_classdev *led_cdev; led_cdev = list_entry(entry, struct led_classdev, trig_list); led_blink_set(led_cdev, delay_on, delay_off); } - read_unlock(&trigger->leddev_list_lock); + read_unlock(&trig->leddev_list_lock); } EXPORT_SYMBOL_GPL(led_trigger_blink); void led_trigger_register_simple(const char *name, struct led_trigger **tp) { - struct led_trigger *trigger; + struct led_trigger *trig; int err; - trigger = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); + trig = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); - if (trigger) { - trigger->name = name; - err = led_trigger_register(trigger); + if (trig) { + trig->name = name; + err = led_trigger_register(trig); if (err < 0) { - kfree(trigger); - trigger = NULL; + kfree(trig); + trig = NULL; printk(KERN_WARNING "LED trigger %s failed to register" " (%d)\n", name, err); } @@ -270,15 +270,15 @@ void led_trigger_register_simple(const char *name, struct led_trigger **tp) printk(KERN_WARNING "LED trigger %s failed to register" " (no memory)\n", name); - *tp = trigger; + *tp = trig; } EXPORT_SYMBOL_GPL(led_trigger_register_simple); -void led_trigger_unregister_simple(struct led_trigger *trigger) +void led_trigger_unregister_simple(struct led_trigger *trig) { - if (trigger) - led_trigger_unregister(trigger); - kfree(trigger); + if (trig) + led_trigger_unregister(trig); + kfree(trig); } EXPORT_SYMBOL_GPL(led_trigger_unregister_simple); -- cgit v1.2.1 From 5bb629c504394f4d42c53a25d75ccb02a393f92f Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sun, 27 May 2012 07:19:22 +0800 Subject: leds: add oneshot blink functions Add two new functions, led_blink_set_oneshot and led_trigger_blink_oneshot, to be used by triggers for one-shot blink of led devices. This is implemented extending the existing software-blink code, and uses the same timer and handler function. The behavior of the code is to do a blink-on, blink-off sequence when the function is called, ignoring other calls until the sequence is completed so that the leds keep blinking at constant rate if the functions are called repeatedly. This is meant to be used by drivers which needs to trigger on sporadic event, but doesn't have clear busy/idle trigger points. After the blink sequence the led remains off. This behavior can be inverted setting the "invert" argument, which blink the led off, than on and leave the led on after the sequence. (bryan.wu@canonical.com: rebase to commit 'leds: don't disable blinking when writing the same value to delay_on or delay_off') Signed-off-by: Fabio Baltieri Acked-by: Shuah Khan Signed-off-by: Bryan Wu --- drivers/leds/led-class.c | 19 +++++++++++++++++++ drivers/leds/led-core.c | 45 ++++++++++++++++++++++++++++++++++++++------- drivers/leds/led-triggers.c | 30 ++++++++++++++++++++++++++---- 3 files changed, 83 insertions(+), 11 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index e663e6f413e9..81eb0916b44a 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -86,6 +86,11 @@ static void led_timer_function(unsigned long data) return; } + if (led_cdev->flags & LED_BLINK_ONESHOT_STOP) { + led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP; + return; + } + brightness = led_get_brightness(led_cdev); if (!brightness) { /* Time to switch the LED on. */ @@ -102,6 +107,20 @@ static void led_timer_function(unsigned long data) led_set_brightness(led_cdev, brightness); + /* Return in next iteration if led is in one-shot mode and we are in + * the final blink state so that the led is toggled each delay_on + + * delay_off milliseconds in worst case. + */ + if (led_cdev->flags & LED_BLINK_ONESHOT) { + if (led_cdev->flags & LED_BLINK_INVERT) { + if (brightness) + led_cdev->flags |= LED_BLINK_ONESHOT_STOP; + } else { + if (!brightness) + led_cdev->flags |= LED_BLINK_ONESHOT_STOP; + } + } + mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay)); } diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index d65353d8d3fc..a6f4d910ca08 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -27,7 +27,6 @@ EXPORT_SYMBOL_GPL(leds_list); static void led_stop_software_blink(struct led_classdev *led_cdev) { /* deactivate previous settings */ - del_timer_sync(&led_cdev->blink_timer); led_cdev->blink_delay_on = 0; led_cdev->blink_delay_off = 0; } @@ -61,13 +60,12 @@ static void led_set_software_blink(struct led_classdev *led_cdev, } -void led_blink_set(struct led_classdev *led_cdev, - unsigned long *delay_on, - unsigned long *delay_off) +void led_blink_setup(struct led_classdev *led_cdev, + unsigned long *delay_on, + unsigned long *delay_off) { - del_timer_sync(&led_cdev->blink_timer); - - if (led_cdev->blink_set && + if (!(led_cdev->flags & LED_BLINK_ONESHOT) && + led_cdev->blink_set && !led_cdev->blink_set(led_cdev, delay_on, delay_off)) return; @@ -77,8 +75,41 @@ void led_blink_set(struct led_classdev *led_cdev, led_set_software_blink(led_cdev, *delay_on, *delay_off); } + +void led_blink_set(struct led_classdev *led_cdev, + unsigned long *delay_on, + unsigned long *delay_off) +{ + del_timer_sync(&led_cdev->blink_timer); + + led_cdev->flags &= ~LED_BLINK_ONESHOT; + led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP; + + led_blink_setup(led_cdev, delay_on, delay_off); +} EXPORT_SYMBOL(led_blink_set); +void led_blink_set_oneshot(struct led_classdev *led_cdev, + unsigned long *delay_on, + unsigned long *delay_off, + int invert) +{ + if ((led_cdev->flags & LED_BLINK_ONESHOT) && + timer_pending(&led_cdev->blink_timer)) + return; + + led_cdev->flags |= LED_BLINK_ONESHOT; + led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP; + + if (invert) + led_cdev->flags |= LED_BLINK_INVERT; + else + led_cdev->flags &= ~LED_BLINK_INVERT; + + led_blink_setup(led_cdev, delay_on, delay_off); +} +EXPORT_SYMBOL(led_blink_set_oneshot); + void led_brightness_set(struct led_classdev *led_cdev, enum led_brightness brightness) { diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index b449ed8d8712..fa0b9be019ea 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -230,9 +230,11 @@ void led_trigger_event(struct led_trigger *trig, } EXPORT_SYMBOL_GPL(led_trigger_event); -void led_trigger_blink(struct led_trigger *trig, - unsigned long *delay_on, - unsigned long *delay_off) +void led_trigger_blink_setup(struct led_trigger *trig, + unsigned long *delay_on, + unsigned long *delay_off, + int oneshot, + int invert) { struct list_head *entry; @@ -244,12 +246,32 @@ void led_trigger_blink(struct led_trigger *trig, struct led_classdev *led_cdev; led_cdev = list_entry(entry, struct led_classdev, trig_list); - led_blink_set(led_cdev, delay_on, delay_off); + if (oneshot) + led_blink_set_oneshot(led_cdev, delay_on, delay_off, + invert); + else + led_blink_set(led_cdev, delay_on, delay_off); } read_unlock(&trig->leddev_list_lock); } + +void led_trigger_blink(struct led_trigger *trig, + unsigned long *delay_on, + unsigned long *delay_off) +{ + led_trigger_blink_setup(trig, delay_on, delay_off, 0, 0); +} EXPORT_SYMBOL_GPL(led_trigger_blink); +void led_trigger_blink_oneshot(struct led_trigger *trig, + unsigned long *delay_on, + unsigned long *delay_off, + int invert) +{ + led_trigger_blink_setup(trig, delay_on, delay_off, 1, invert); +} +EXPORT_SYMBOL_GPL(led_trigger_blink_oneshot); + void led_trigger_register_simple(const char *name, struct led_trigger **tp) { struct led_trigger *trig; -- cgit v1.2.1 From 3740e49c668bbe7719f292c24c4c5f152a88b97e Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sun, 27 May 2012 07:19:23 +0800 Subject: ledtrig-ide-disk: use generic one-shot blink api Convert ledtrig-ide-disk code to use the generic API for one-shot LED blinking. This patch changes slightly the behaviour of the trigger, as while the original version kept the LED on under heavy activity, the new one keeps a constant on-off blink at 1 / (2 * BLINK_DELAY) Hz. (bryan.wu@canonical.com: remove 2 useless included header files) Signed-off-by: Fabio Baltieri Signed-off-by: Bryan Wu --- drivers/leds/ledtrig-ide-disk.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/ledtrig-ide-disk.c b/drivers/leds/ledtrig-ide-disk.c index ec099fcbcb00..2cd7c0cf5924 100644 --- a/drivers/leds/ledtrig-ide-disk.c +++ b/drivers/leds/ledtrig-ide-disk.c @@ -12,39 +12,22 @@ */ #include -#include #include #include -#include #include -static void ledtrig_ide_timerfunc(unsigned long data); +#define BLINK_DELAY 30 DEFINE_LED_TRIGGER(ledtrig_ide); -static DEFINE_TIMER(ledtrig_ide_timer, ledtrig_ide_timerfunc, 0, 0); -static int ide_activity; -static int ide_lastactivity; +static unsigned long ide_blink_delay = BLINK_DELAY; void ledtrig_ide_activity(void) { - ide_activity++; - if (!timer_pending(&ledtrig_ide_timer)) - mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10)); + led_trigger_blink_oneshot(ledtrig_ide, + &ide_blink_delay, &ide_blink_delay, 0); } EXPORT_SYMBOL(ledtrig_ide_activity); -static void ledtrig_ide_timerfunc(unsigned long data) -{ - if (ide_lastactivity != ide_activity) { - ide_lastactivity = ide_activity; - /* INT_MAX will set each LED to its maximum brightness */ - led_trigger_event(ledtrig_ide, INT_MAX); - mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10)); - } else { - led_trigger_event(ledtrig_ide, LED_OFF); - } -} - static int __init ledtrig_ide_init(void) { led_trigger_register_simple("ide-disk", &ledtrig_ide); -- cgit v1.2.1 From 437864828d82b9dee50b5741106fbf5fa12b139a Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Thu, 7 Jun 2012 03:12:34 +0800 Subject: leds: fix led_brightness_set when soft-blinking Move led_stop_software_blink() code into led_brightness_set() to ensure software blink timer is stopped and cleared when changing trigger. Also use led_set_brightness() instead of calling led_cdev->brightness_set() directly to keep led_cdev->brightness consistent with current LED status. This ensure proper cleaning when changing triggers, as without this fix a LED may be turned off while leaving it's led_cdev->brightness = 1, leading to an erratic software-blink behaviour. The problem was easy to reproduce by changing the trigger from "timer" to "oneshot". Signed-off-by: Fabio Baltieri Signed-off-by: Bryan Wu --- drivers/leds/led-core.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index a6f4d910ca08..31f1f78ef40b 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -24,13 +24,6 @@ EXPORT_SYMBOL_GPL(leds_list_lock); LIST_HEAD(leds_list); EXPORT_SYMBOL_GPL(leds_list); -static void led_stop_software_blink(struct led_classdev *led_cdev) -{ - /* deactivate previous settings */ - led_cdev->blink_delay_on = 0; - led_cdev->blink_delay_off = 0; -} - static void led_set_software_blink(struct led_classdev *led_cdev, unsigned long delay_on, unsigned long delay_off) @@ -113,7 +106,11 @@ EXPORT_SYMBOL(led_blink_set_oneshot); void led_brightness_set(struct led_classdev *led_cdev, enum led_brightness brightness) { - led_stop_software_blink(led_cdev); - led_cdev->brightness_set(led_cdev, brightness); + /* stop and clear soft-blink timer */ + del_timer_sync(&led_cdev->blink_timer); + led_cdev->blink_delay_on = 0; + led_cdev->blink_delay_off = 0; + + led_set_brightness(led_cdev, brightness); } EXPORT_SYMBOL(led_brightness_set); -- cgit v1.2.1 From 5e417281cde2ef56e9eb1a95d080d6254402e794 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Thu, 7 Jun 2012 06:11:05 +0800 Subject: leds: add oneshot trigger Add oneshot trigger to blink a led with configurale parameters via sysfs. Signed-off-by: Fabio Baltieri Cc: Shuah Khan Signed-off-by: Bryan Wu --- drivers/leds/Kconfig | 14 +++ drivers/leds/Makefile | 1 + drivers/leds/ledtrig-oneshot.c | 204 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 drivers/leds/ledtrig-oneshot.c (limited to 'drivers') diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 12b2b55c519e..54dd1a396fa9 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -443,6 +443,20 @@ config LEDS_TRIGGER_TIMER If unsure, say Y. +config LEDS_TRIGGER_ONESHOT + tristate "LED One-shot Trigger" + depends on LEDS_TRIGGERS + help + This allows LEDs to blink in one-shot pulses with parameters + controlled via sysfs. It's useful to notify the user on + sporadic events, when there are no clear begin and end trap points, + or on dense events, where this blinks the LED at constant rate if + rearmed continuously. + + It also shows how to use the led_blink_set_oneshot() function. + + If unsure, say Y. + config LEDS_TRIGGER_IDE_DISK bool "LED IDE Disk Trigger" depends on IDE_GD_ATA diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index f8958cd6cf6e..9112d518f9d4 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o # LED Triggers obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o +obj-$(CONFIG_LEDS_TRIGGER_ONESHOT) += ledtrig-oneshot.o obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o diff --git a/drivers/leds/ledtrig-oneshot.c b/drivers/leds/ledtrig-oneshot.c new file mode 100644 index 000000000000..5c9edf7f489c --- /dev/null +++ b/drivers/leds/ledtrig-oneshot.c @@ -0,0 +1,204 @@ +/* + * One-shot LED Trigger + * + * Copyright 2012, Fabio Baltieri + * + * Based on ledtrig-timer.c by Richard Purdie + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "leds.h" + +#define DEFAULT_DELAY 100 + +struct oneshot_trig_data { + unsigned int invert; +}; + +static ssize_t led_shot(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct oneshot_trig_data *oneshot_data = led_cdev->trigger_data; + + led_blink_set_oneshot(led_cdev, + &led_cdev->blink_delay_on, &led_cdev->blink_delay_off, + oneshot_data->invert); + + /* content is ignored */ + return size; +} +static ssize_t led_invert_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct oneshot_trig_data *oneshot_data = led_cdev->trigger_data; + + return sprintf(buf, "%u\n", oneshot_data->invert); +} + +static ssize_t led_invert_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct oneshot_trig_data *oneshot_data = led_cdev->trigger_data; + unsigned long state; + int ret; + + ret = kstrtoul(buf, 0, &state); + if (ret) + return ret; + + oneshot_data->invert = !!state; + + if (oneshot_data->invert) + led_set_brightness(led_cdev, LED_FULL); + else + led_set_brightness(led_cdev, LED_OFF); + + return size; +} + +static ssize_t led_delay_on_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + + return sprintf(buf, "%lu\n", led_cdev->blink_delay_on); +} + +static ssize_t led_delay_on_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + unsigned long state; + int ret; + + ret = kstrtoul(buf, 0, &state); + if (ret) + return ret; + + led_cdev->blink_delay_on = state; + + return size; +} +static ssize_t led_delay_off_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + + return sprintf(buf, "%lu\n", led_cdev->blink_delay_off); +} + +static ssize_t led_delay_off_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + unsigned long state; + int ret; + + ret = kstrtoul(buf, 0, &state); + if (ret) + return ret; + + led_cdev->blink_delay_off = state; + + return size; +} + +static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store); +static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store); +static DEVICE_ATTR(invert, 0644, led_invert_show, led_invert_store); +static DEVICE_ATTR(shot, 0200, NULL, led_shot); + +static void oneshot_trig_activate(struct led_classdev *led_cdev) +{ + struct oneshot_trig_data *oneshot_data; + int rc; + + oneshot_data = kzalloc(sizeof(*oneshot_data), GFP_KERNEL); + if (!oneshot_data) + return; + + led_cdev->trigger_data = oneshot_data; + + rc = device_create_file(led_cdev->dev, &dev_attr_delay_on); + if (rc) + goto err_out_trig_data; + rc = device_create_file(led_cdev->dev, &dev_attr_delay_off); + if (rc) + goto err_out_delayon; + rc = device_create_file(led_cdev->dev, &dev_attr_invert); + if (rc) + goto err_out_delayoff; + rc = device_create_file(led_cdev->dev, &dev_attr_shot); + if (rc) + goto err_out_invert; + + led_cdev->blink_delay_on = DEFAULT_DELAY; + led_cdev->blink_delay_off = DEFAULT_DELAY; + + led_cdev->activated = true; + + return; + +err_out_invert: + device_remove_file(led_cdev->dev, &dev_attr_invert); +err_out_delayoff: + device_remove_file(led_cdev->dev, &dev_attr_delay_off); +err_out_delayon: + device_remove_file(led_cdev->dev, &dev_attr_delay_on); +err_out_trig_data: + kfree(led_cdev->trigger_data); +} + +static void oneshot_trig_deactivate(struct led_classdev *led_cdev) +{ + struct oneshot_trig_data *oneshot_data = led_cdev->trigger_data; + + if (led_cdev->activated) { + device_remove_file(led_cdev->dev, &dev_attr_delay_on); + device_remove_file(led_cdev->dev, &dev_attr_delay_off); + device_remove_file(led_cdev->dev, &dev_attr_invert); + device_remove_file(led_cdev->dev, &dev_attr_shot); + kfree(oneshot_data); + led_cdev->activated = false; + } + + /* Stop blinking */ + led_brightness_set(led_cdev, LED_OFF); +} + +static struct led_trigger oneshot_led_trigger = { + .name = "oneshot", + .activate = oneshot_trig_activate, + .deactivate = oneshot_trig_deactivate, +}; + +static int __init oneshot_trig_init(void) +{ + return led_trigger_register(&oneshot_led_trigger); +} + +static void __exit oneshot_trig_exit(void) +{ + led_trigger_unregister(&oneshot_led_trigger); +} + +module_init(oneshot_trig_init); +module_exit(oneshot_trig_exit); + +MODULE_AUTHOR("Fabio Baltieri "); +MODULE_DESCRIPTION("One-shot LED trigger"); +MODULE_LICENSE("GPL"); -- cgit v1.2.1 From 0da3e65ba892b8c63d55fa5ec197b6fae55f75f8 Mon Sep 17 00:00:00 2001 From: Shuah Khan Date: Wed, 13 Jun 2012 10:01:37 +0800 Subject: leds: Rename led_set_brightness() to __led_set_brightness() Rename leds internal interface led_set_brightness() to __led_set_brightness() to reduce confusion between led_set_brightness() and the external interface led_brightness_set(). led_brightness_set() cancels the timer and then calls led_set_brightness(). Signed-off-by: Shuah Khan Signed-off-by: Bryan Wu --- drivers/leds/led-class.c | 6 +++--- drivers/leds/led-core.c | 4 ++-- drivers/leds/led-triggers.c | 2 +- drivers/leds/leds.h | 2 +- drivers/leds/ledtrig-backlight.c | 8 ++++---- drivers/leds/ledtrig-default-on.c | 2 +- drivers/leds/ledtrig-gpio.c | 6 +++--- drivers/leds/ledtrig-heartbeat.c | 2 +- drivers/leds/ledtrig-oneshot.c | 4 ++-- drivers/leds/ledtrig-transient.c | 8 ++++---- 10 files changed, 22 insertions(+), 22 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 81eb0916b44a..cb0a6eb72a2c 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -53,7 +53,7 @@ static ssize_t led_brightness_store(struct device *dev, if (state == LED_OFF) led_trigger_remove(led_cdev); - led_set_brightness(led_cdev, state); + __led_set_brightness(led_cdev, state); return size; } @@ -82,7 +82,7 @@ static void led_timer_function(unsigned long data) unsigned long delay; if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) { - led_set_brightness(led_cdev, LED_OFF); + __led_set_brightness(led_cdev, LED_OFF); return; } @@ -105,7 +105,7 @@ static void led_timer_function(unsigned long data) delay = led_cdev->blink_delay_off; } - led_set_brightness(led_cdev, brightness); + __led_set_brightness(led_cdev, brightness); /* Return in next iteration if led is in one-shot mode and we are in * the final blink state so that the led is toggled each delay_on + diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 31f1f78ef40b..176961b2db6b 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -45,7 +45,7 @@ static void led_set_software_blink(struct led_classdev *led_cdev, /* never off - just set to brightness */ if (!delay_off) { - led_set_brightness(led_cdev, led_cdev->blink_brightness); + __led_set_brightness(led_cdev, led_cdev->blink_brightness); return; } @@ -111,6 +111,6 @@ void led_brightness_set(struct led_classdev *led_cdev, led_cdev->blink_delay_on = 0; led_cdev->blink_delay_off = 0; - led_set_brightness(led_cdev, brightness); + __led_set_brightness(led_cdev, brightness); } EXPORT_SYMBOL(led_brightness_set); diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index fa0b9be019ea..f8b14dd8c2b6 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -224,7 +224,7 @@ void led_trigger_event(struct led_trigger *trig, struct led_classdev *led_cdev; led_cdev = list_entry(entry, struct led_classdev, trig_list); - led_set_brightness(led_cdev, brightness); + __led_set_brightness(led_cdev, brightness); } read_unlock(&trig->leddev_list_lock); } diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h index e77c7f8dcdd4..d02acd496126 100644 --- a/drivers/leds/leds.h +++ b/drivers/leds/leds.h @@ -17,7 +17,7 @@ #include #include -static inline void led_set_brightness(struct led_classdev *led_cdev, +static inline void __led_set_brightness(struct led_classdev *led_cdev, enum led_brightness value) { if (value > led_cdev->max_brightness) diff --git a/drivers/leds/ledtrig-backlight.c b/drivers/leds/ledtrig-backlight.c index e2726867c5d4..b941685f2227 100644 --- a/drivers/leds/ledtrig-backlight.c +++ b/drivers/leds/ledtrig-backlight.c @@ -46,9 +46,9 @@ static int fb_notifier_callback(struct notifier_block *p, if ((n->old_status == UNBLANK) ^ n->invert) { n->brightness = led->brightness; - led_set_brightness(led, LED_OFF); + __led_set_brightness(led, LED_OFF); } else { - led_set_brightness(led, n->brightness); + __led_set_brightness(led, n->brightness); } n->old_status = new_status; @@ -87,9 +87,9 @@ static ssize_t bl_trig_invert_store(struct device *dev, /* After inverting, we need to update the LED. */ if ((n->old_status == BLANK) ^ n->invert) - led_set_brightness(led, LED_OFF); + __led_set_brightness(led, LED_OFF); else - led_set_brightness(led, n->brightness); + __led_set_brightness(led, n->brightness); return num; } diff --git a/drivers/leds/ledtrig-default-on.c b/drivers/leds/ledtrig-default-on.c index a4ef54b9d508..eac1f1b1adac 100644 --- a/drivers/leds/ledtrig-default-on.c +++ b/drivers/leds/ledtrig-default-on.c @@ -19,7 +19,7 @@ static void defon_trig_activate(struct led_classdev *led_cdev) { - led_set_brightness(led_cdev, led_cdev->max_brightness); + __led_set_brightness(led_cdev, led_cdev->max_brightness); } static struct led_trigger defon_led_trigger = { diff --git a/drivers/leds/ledtrig-gpio.c b/drivers/leds/ledtrig-gpio.c index f057c101b896..ba215dc42f98 100644 --- a/drivers/leds/ledtrig-gpio.c +++ b/drivers/leds/ledtrig-gpio.c @@ -54,12 +54,12 @@ static void gpio_trig_work(struct work_struct *work) if (tmp) { if (gpio_data->desired_brightness) - led_set_brightness(gpio_data->led, + __led_set_brightness(gpio_data->led, gpio_data->desired_brightness); else - led_set_brightness(gpio_data->led, LED_FULL); + __led_set_brightness(gpio_data->led, LED_FULL); } else { - led_set_brightness(gpio_data->led, LED_OFF); + __led_set_brightness(gpio_data->led, LED_OFF); } } diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c index a019fbb70880..1edc7463ce83 100644 --- a/drivers/leds/ledtrig-heartbeat.c +++ b/drivers/leds/ledtrig-heartbeat.c @@ -74,7 +74,7 @@ static void led_heartbeat_function(unsigned long data) break; } - led_set_brightness(led_cdev, brightness); + __led_set_brightness(led_cdev, brightness); mod_timer(&heartbeat_data->timer, jiffies + delay); } diff --git a/drivers/leds/ledtrig-oneshot.c b/drivers/leds/ledtrig-oneshot.c index 5c9edf7f489c..5cbab41a8da2 100644 --- a/drivers/leds/ledtrig-oneshot.c +++ b/drivers/leds/ledtrig-oneshot.c @@ -63,9 +63,9 @@ static ssize_t led_invert_store(struct device *dev, oneshot_data->invert = !!state; if (oneshot_data->invert) - led_set_brightness(led_cdev, LED_FULL); + __led_set_brightness(led_cdev, LED_FULL); else - led_set_brightness(led_cdev, LED_OFF); + __led_set_brightness(led_cdev, LED_OFF); return size; } diff --git a/drivers/leds/ledtrig-transient.c b/drivers/leds/ledtrig-transient.c index 83179f435e1e..398f1042c43e 100644 --- a/drivers/leds/ledtrig-transient.c +++ b/drivers/leds/ledtrig-transient.c @@ -41,7 +41,7 @@ static void transient_timer_function(unsigned long data) struct transient_trig_data *transient_data = led_cdev->trigger_data; transient_data->activate = 0; - led_set_brightness(led_cdev, transient_data->restore_state); + __led_set_brightness(led_cdev, transient_data->restore_state); } static ssize_t transient_activate_show(struct device *dev, @@ -72,7 +72,7 @@ static ssize_t transient_activate_store(struct device *dev, if (state == 0 && transient_data->activate == 1) { del_timer(&transient_data->timer); transient_data->activate = state; - led_set_brightness(led_cdev, transient_data->restore_state); + __led_set_brightness(led_cdev, transient_data->restore_state); return size; } @@ -80,7 +80,7 @@ static ssize_t transient_activate_store(struct device *dev, if (state == 1 && transient_data->activate == 0 && transient_data->duration != 0) { transient_data->activate = state; - led_set_brightness(led_cdev, transient_data->state); + __led_set_brightness(led_cdev, transient_data->state); transient_data->restore_state = (transient_data->state == LED_FULL) ? LED_OFF : LED_FULL; mod_timer(&transient_data->timer, @@ -203,7 +203,7 @@ static void transient_trig_deactivate(struct led_classdev *led_cdev) if (led_cdev->activated) { del_timer_sync(&transient_data->timer); - led_set_brightness(led_cdev, transient_data->restore_state); + __led_set_brightness(led_cdev, transient_data->restore_state); device_remove_file(led_cdev->dev, &dev_attr_activate); device_remove_file(led_cdev->dev, &dev_attr_duration); device_remove_file(led_cdev->dev, &dev_attr_state); -- cgit v1.2.1 From 19cd67e2d51225b164560b54b85f943e07deee8a Mon Sep 17 00:00:00 2001 From: Shuah Khan Date: Thu, 14 Jun 2012 04:34:30 +0800 Subject: leds: Rename led_brightness_set() to led_set_brightness() Rename leds external interface led_brightness_set() to led_set_brightness(). This is the second phase of the change to reduce confusion between the leds internal and external interfaces that set brightness. With this change, now the external interface is led_set_brightness(). The first phase renamed the internal interface led_set_brightness() to __led_set_brightness(). There are no changes to the interface implementations. Signed-off-by: Shuah Khan Signed-off-by: Bryan Wu --- drivers/leds/led-class.c | 2 +- drivers/leds/led-core.c | 4 ++-- drivers/leds/led-triggers.c | 2 +- drivers/leds/ledtrig-oneshot.c | 2 +- drivers/leds/ledtrig-timer.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index cb0a6eb72a2c..c599095bc005 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -222,7 +222,7 @@ void led_classdev_unregister(struct led_classdev *led_cdev) #endif /* Stop blinking */ - led_brightness_set(led_cdev, LED_OFF); + led_set_brightness(led_cdev, LED_OFF); device_unregister(led_cdev->dev); diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 176961b2db6b..8a09c5fc2a6d 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -103,7 +103,7 @@ void led_blink_set_oneshot(struct led_classdev *led_cdev, } EXPORT_SYMBOL(led_blink_set_oneshot); -void led_brightness_set(struct led_classdev *led_cdev, +void led_set_brightness(struct led_classdev *led_cdev, enum led_brightness brightness) { /* stop and clear soft-blink timer */ @@ -113,4 +113,4 @@ void led_brightness_set(struct led_classdev *led_cdev, __led_set_brightness(led_cdev, brightness); } -EXPORT_SYMBOL(led_brightness_set); +EXPORT_SYMBOL(led_set_brightness); diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index f8b14dd8c2b6..57721f25d7cd 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -112,7 +112,7 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) if (led_cdev->trigger->deactivate) led_cdev->trigger->deactivate(led_cdev); led_cdev->trigger = NULL; - led_brightness_set(led_cdev, LED_OFF); + led_set_brightness(led_cdev, LED_OFF); } if (trig) { write_lock_irqsave(&trig->leddev_list_lock, flags); diff --git a/drivers/leds/ledtrig-oneshot.c b/drivers/leds/ledtrig-oneshot.c index 5cbab41a8da2..2c029aa5c4f1 100644 --- a/drivers/leds/ledtrig-oneshot.c +++ b/drivers/leds/ledtrig-oneshot.c @@ -177,7 +177,7 @@ static void oneshot_trig_deactivate(struct led_classdev *led_cdev) } /* Stop blinking */ - led_brightness_set(led_cdev, LED_OFF); + led_set_brightness(led_cdev, LED_OFF); } static struct led_trigger oneshot_led_trigger = { diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c index 9010f7abaf2c..f774d0592204 100644 --- a/drivers/leds/ledtrig-timer.c +++ b/drivers/leds/ledtrig-timer.c @@ -104,7 +104,7 @@ static void timer_trig_deactivate(struct led_classdev *led_cdev) } /* Stop blinking */ - led_brightness_set(led_cdev, LED_OFF); + led_set_brightness(led_cdev, LED_OFF); } static struct led_trigger timer_led_trigger = { -- cgit v1.2.1 From a0193cbee0809d65362a0767b2d50306b145b2f5 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Fri, 15 Jun 2012 02:33:35 +0800 Subject: leds: use led_set_brightness in led_trigger_event Fix led_trigger_event() to use led_set_brightness() instead of __led_set_brightness(), so that any pending blink timer is stopped before setting the new brightness value. Without this fix LED status may be overridden by a pending timer. This allows a trigger to use a mix of led_trigger_event(), led_trigger_blink() and led_trigger_blink_oneshot() without races. (applied over: leds: Rename led_brightness_set() to led_set_brightness()) Signed-off-by: Fabio Baltieri Cc: Shuah Khan Signed-off-by: Bryan Wu --- drivers/leds/led-triggers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 57721f25d7cd..de1c59d641a8 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -224,7 +224,7 @@ void led_trigger_event(struct led_trigger *trig, struct led_classdev *led_cdev; led_cdev = list_entry(entry, struct led_classdev, trig_list); - __led_set_brightness(led_cdev, brightness); + led_set_brightness(led_cdev, brightness); } read_unlock(&trig->leddev_list_lock); } -- cgit v1.2.1 From dff67758c1c61c23a3f691675c67f1a3c9c47f7a Mon Sep 17 00:00:00 2001 From: Jesper Dangaard Brouer Date: Fri, 15 Jun 2012 18:13:25 +0800 Subject: leds: correct trivial type in drivers/leds/Kconfig Correct "hadrware" to "hardware", for LEDS_TRIGGER_TRANSIENT. Signed-off-by: Jesper Dangaard Brouer Signed-off-by: Bryan Wu --- drivers/leds/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 54dd1a396fa9..52f1d456f3d2 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -511,7 +511,7 @@ config LEDS_TRIGGER_TRANSIENT depends on LEDS_TRIGGERS help This allows one time activation of a transient state on - GPIO/PWM based hadrware. + GPIO/PWM based hardware. If unsure, say Y. endif # NEW_LEDS -- cgit v1.2.1 From 20c0e6b8787c5289202f688b6be78dff4568c1df Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Fri, 15 Jun 2012 22:15:27 +0800 Subject: leds: fix sparse warnings due to missing static drivers/leds/led-core.c:56:6: sparse: symbol 'led_blink_setup' was not declared. Should it be static? drivers/leds/led-triggers.c:233:6: sparse: symbol 'led_trigger_blink_setup' was not declared. Should it be static? Reported-by: Fengguang Wu Signed-off-by: Bryan Wu --- drivers/leds/led-core.c | 2 +- drivers/leds/led-triggers.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 8a09c5fc2a6d..2ab05af3de31 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -53,7 +53,7 @@ static void led_set_software_blink(struct led_classdev *led_cdev, } -void led_blink_setup(struct led_classdev *led_cdev, +static void led_blink_setup(struct led_classdev *led_cdev, unsigned long *delay_on, unsigned long *delay_off) { diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index de1c59d641a8..6157cbbf4113 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -230,7 +230,7 @@ void led_trigger_event(struct led_trigger *trig, } EXPORT_SYMBOL_GPL(led_trigger_event); -void led_trigger_blink_setup(struct led_trigger *trig, +static void led_trigger_blink_setup(struct led_trigger *trig, unsigned long *delay_on, unsigned long *delay_off, int oneshot, -- cgit v1.2.1 From 1522d02e275332080ec27e268edc29c79c6f5e0c Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Wed, 20 Jun 2012 02:22:39 +0800 Subject: leds: [trivial]Remove unnecesary return the ret is got the status returned by the led_classdev_register, returning ret if the led_classdev_register fails and returning 0 if the led_classdev_register success, can be done by doing just "return ret" at the end. Signed-off-by: Devendra Naga Signed-off-by: Bryan Wu --- drivers/leds/leds-s3c24xx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c index bd0a5ed49c42..e6ee10548265 100644 --- a/drivers/leds/leds-s3c24xx.c +++ b/drivers/leds/leds-s3c24xx.c @@ -106,10 +106,9 @@ static int s3c24xx_led_probe(struct platform_device *dev) if (ret < 0) { dev_err(&dev->dev, "led_classdev_register failed\n"); kfree(led); - return ret; } - return 0; + return ret; } static struct platform_driver s3c24xx_led_driver = { -- cgit v1.2.1 From 32abb4788d3fff69fa242c7850e39ec1418df4f4 Mon Sep 17 00:00:00 2001 From: "G.Shark Jeong" Date: Fri, 22 Jun 2012 08:12:06 +0800 Subject: leds: Add LED driver for lm3556 chip LM3556 : The LM3556 is a 4 MHz fixed-frequency synchronous boost converter plus 1.5A constant current driver for a high-current white LED. Datasheet: www.national.com/ds/LM/LM3556.pdf Tested on OMAP4430 (bryan.wu@canonical.com: use module_i2c_driver() rather than lm3556_init/lm3556_exit for code simplicity; fixed some typo pointed out by Rob Landley) Signed-off-by: G.Shark Jeong Reviewed-by: Axel Lin Reviewed-by: Kim, Milo Acked-by: Rob Landley Signed-off-by: Bryan Wu --- drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-lm3556.c | 512 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 521 insertions(+) create mode 100644 drivers/leds/leds-lm3556.c (limited to 'drivers') diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 52f1d456f3d2..f028f0348e83 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -415,6 +415,14 @@ config LEDS_MAX8997 This option enables support for on-chip LED drivers on MAXIM MAX8997 PMIC. +config LEDS_LM3556 + tristate "LED support for LM3556 Chip" + depends on LEDS_CLASS && I2C + select REGMAP_I2C + help + This option enables support for LEDs connected to LM3556. + LM3556 includes Torch, Flash and Indicator functions. + config LEDS_OT200 tristate "LED support for the Bachmann OT200" depends on LEDS_CLASS && HAS_IOMEM diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 9112d518f9d4..5eebd7bce4be 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o obj-$(CONFIG_LEDS_RENESAS_TPU) += leds-renesas-tpu.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o +obj-$(CONFIG_LEDS_LM3556) += leds-lm3556.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-lm3556.c b/drivers/leds/leds-lm3556.c new file mode 100644 index 000000000000..3062abd9a532 --- /dev/null +++ b/drivers/leds/leds-lm3556.c @@ -0,0 +1,512 @@ +/* + * Simple driver for Texas Instruments LM3556 LED Flash driver chip (Rev0x03) + * Copyright (C) 2012 Texas Instruments + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Please refer Documentation/leds/leds-lm3556.txt file. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REG_FILT_TIME (0x0) +#define REG_IVFM_MODE (0x1) +#define REG_NTC (0x2) +#define REG_INDIC_TIME (0x3) +#define REG_INDIC_BLINK (0x4) +#define REG_INDIC_PERIOD (0x5) +#define REG_TORCH_TIME (0x6) +#define REG_CONF (0x7) +#define REG_FLASH (0x8) +#define REG_I_CTRL (0x9) +#define REG_ENABLE (0xA) +#define REG_FLAG (0xB) +#define REG_MAX (0xB) + +#define IVFM_FILTER_TIME_SHIFT (3) +#define UVLO_EN_SHIFT (7) +#define HYSTERSIS_SHIFT (5) +#define IVM_D_TH_SHIFT (2) +#define IVFM_ADJ_MODE_SHIFT (0) +#define NTC_EVENT_LVL_SHIFT (5) +#define NTC_TRIP_TH_SHIFT (2) +#define NTC_BIAS_I_LVL_SHIFT (0) +#define INDIC_RAMP_UP_TIME_SHIFT (3) +#define INDIC_RAMP_DN_TIME_SHIFT (0) +#define INDIC_N_BLANK_SHIFT (4) +#define INDIC_PULSE_TIME_SHIFT (0) +#define INDIC_N_PERIOD_SHIFT (0) +#define TORCH_RAMP_UP_TIME_SHIFT (3) +#define TORCH_RAMP_DN_TIME_SHIFT (0) +#define STROBE_USUAGE_SHIFT (7) +#define STROBE_PIN_POLARITY_SHIFT (6) +#define TORCH_PIN_POLARITY_SHIFT (5) +#define TX_PIN_POLARITY_SHIFT (4) +#define TX_EVENT_LVL_SHIFT (3) +#define IVFM_EN_SHIFT (2) +#define NTC_MODE_SHIFT (1) +#define INDIC_MODE_SHIFT (0) +#define INDUCTOR_I_LIMIT_SHIFT (6) +#define FLASH_RAMP_TIME_SHIFT (3) +#define FLASH_TOUT_TIME_SHIFT (0) +#define TORCH_I_SHIFT (4) +#define FLASH_I_SHIFT (0) +#define NTC_EN_SHIFT (7) +#define TX_PIN_EN_SHIFT (6) +#define STROBE_PIN_EN_SHIFT (5) +#define TORCH_PIN_EN_SHIFT (4) +#define PRECHG_MODE_EN_SHIFT (3) +#define PASS_MODE_ONLY_EN_SHIFT (2) +#define MODE_BITS_SHIFT (0) + +#define IVFM_FILTER_TIME_MASK (0x3) +#define UVLO_EN_MASK (0x1) +#define HYSTERSIS_MASK (0x3) +#define IVM_D_TH_MASK (0x7) +#define IVFM_ADJ_MODE_MASK (0x3) +#define NTC_EVENT_LVL_MASK (0x1) +#define NTC_TRIP_TH_MASK (0x7) +#define NTC_BIAS_I_LVL_MASK (0x3) +#define INDIC_RAMP_UP_TIME_MASK (0x7) +#define INDIC_RAMP_DN_TIME_MASK (0x7) +#define INDIC_N_BLANK_MASK (0x7) +#define INDIC_PULSE_TIME_MASK (0x7) +#define INDIC_N_PERIOD_MASK (0x7) +#define TORCH_RAMP_UP_TIME_MASK (0x7) +#define TORCH_RAMP_DN_TIME_MASK (0x7) +#define STROBE_USUAGE_MASK (0x1) +#define STROBE_PIN_POLARITY_MASK (0x1) +#define TORCH_PIN_POLARITY_MASK (0x1) +#define TX_PIN_POLARITY_MASK (0x1) +#define TX_EVENT_LVL_MASK (0x1) +#define IVFM_EN_MASK (0x1) +#define NTC_MODE_MASK (0x1) +#define INDIC_MODE_MASK (0x1) +#define INDUCTOR_I_LIMIT_MASK (0x3) +#define FLASH_RAMP_TIME_MASK (0x7) +#define FLASH_TOUT_TIME_MASK (0x7) +#define TORCH_I_MASK (0x7) +#define FLASH_I_MASK (0xF) +#define NTC_EN_MASK (0x1) +#define TX_PIN_EN_MASK (0x1) +#define STROBE_PIN_EN_MASK (0x1) +#define TORCH_PIN_EN_MASK (0x1) +#define PRECHG_MODE_EN_MASK (0x1) +#define PASS_MODE_ONLY_EN_MASK (0x1) +#define MODE_BITS_MASK (0x13) +#define EX_PIN_CONTROL_MASK (0xF1) +#define EX_PIN_ENABLE_MASK (0x70) + +enum lm3556_indic_pulse_time { + PULSE_TIME_0_MS = 0, + PULSE_TIME_32_MS, + PULSE_TIME_64_MS, + PULSE_TIME_92_MS, + PULSE_TIME_128_MS, + PULSE_TIME_160_MS, + PULSE_TIME_196_MS, + PULSE_TIME_224_MS, + PULSE_TIME_256_MS, + PULSE_TIME_288_MS, + PULSE_TIME_320_MS, + PULSE_TIME_352_MS, + PULSE_TIME_384_MS, + PULSE_TIME_416_MS, + PULSE_TIME_448_MS, + PULSE_TIME_480_MS, +}; + +enum lm3556_indic_n_blank { + INDIC_N_BLANK_0 = 0, + INDIC_N_BLANK_1, + INDIC_N_BLANK_2, + INDIC_N_BLANK_3, + INDIC_N_BLANK_4, + INDIC_N_BLANK_5, + INDIC_N_BLANK_6, + INDIC_N_BLANK_7, + INDIC_N_BLANK_8, + INDIC_N_BLANK_9, + INDIC_N_BLANK_10, + INDIC_N_BLANK_11, + INDIC_N_BLANK_12, + INDIC_N_BLANK_13, + INDIC_N_BLANK_14, + INDIC_N_BLANK_15, +}; + +enum lm3556_indic_period { + INDIC_PERIOD_0 = 0, + INDIC_PERIOD_1, + INDIC_PERIOD_2, + INDIC_PERIOD_3, + INDIC_PERIOD_4, + INDIC_PERIOD_5, + INDIC_PERIOD_6, + INDIC_PERIOD_7, +}; + +enum lm3556_mode { + MODES_STASNDBY = 0, + MODES_INDIC, + MODES_TORCH, + MODES_FLASH +}; + +#define INDIC_PATTERN_SIZE 4 + +struct indicator { + u8 blinking; + u8 period_cnt; +}; + +struct lm3556_chip_data { + struct device *dev; + + struct led_classdev cdev_flash; + struct led_classdev cdev_torch; + struct led_classdev cdev_indicator; + + struct lm3556_platform_data *pdata; + struct regmap *regmap; + struct mutex lock; + + unsigned int last_flag; +}; + +/* indicator pattern */ +static struct indicator indicator_pattern[INDIC_PATTERN_SIZE] = { + [0] = {(INDIC_N_BLANK_1 << INDIC_N_BLANK_SHIFT) + | PULSE_TIME_32_MS, INDIC_PERIOD_1}, + [1] = {(INDIC_N_BLANK_15 << INDIC_N_BLANK_SHIFT) + | PULSE_TIME_32_MS, INDIC_PERIOD_2}, + [2] = {(INDIC_N_BLANK_10 << INDIC_N_BLANK_SHIFT) + | PULSE_TIME_32_MS, INDIC_PERIOD_4}, + [3] = {(INDIC_N_BLANK_5 << INDIC_N_BLANK_SHIFT) + | PULSE_TIME_32_MS, INDIC_PERIOD_7}, +}; + +/* chip initialize */ +static int __devinit lm3556_chip_init(struct lm3556_chip_data *chip) +{ + unsigned int reg_val; + int ret; + struct lm3556_platform_data *pdata = chip->pdata; + + /* set config register */ + ret = regmap_read(chip->regmap, REG_CONF, ®_val); + if (ret < 0) { + dev_err(chip->dev, "Failed to read REG_CONF Register\n"); + goto out; + } + + reg_val &= (~EX_PIN_CONTROL_MASK); + reg_val |= ((pdata->torch_pin_polarity & 0x01) + << TORCH_PIN_POLARITY_SHIFT); + reg_val |= ((pdata->strobe_usuage & 0x01) << STROBE_USUAGE_SHIFT); + reg_val |= ((pdata->strobe_pin_polarity & 0x01) + << STROBE_PIN_POLARITY_SHIFT); + reg_val |= ((pdata->tx_pin_polarity & 0x01) << TX_PIN_POLARITY_SHIFT); + reg_val |= ((pdata->indicator_mode & 0x01) << INDIC_MODE_SHIFT); + + ret = regmap_write(chip->regmap, REG_CONF, reg_val); + if (ret < 0) { + dev_err(chip->dev, "Failed to write REG_CONF Regisgter\n"); + goto out; + } + + /* set enable register */ + ret = regmap_read(chip->regmap, REG_ENABLE, ®_val); + if (ret < 0) { + dev_err(chip->dev, "Failed to read REG_ENABLE Register\n"); + goto out; + } + + reg_val &= (~EX_PIN_ENABLE_MASK); + reg_val |= ((pdata->torch_pin_en & 0x01) << TORCH_PIN_EN_SHIFT); + reg_val |= ((pdata->strobe_pin_en & 0x01) << STROBE_PIN_EN_SHIFT); + reg_val |= ((pdata->tx_pin_en & 0x01) << TX_PIN_EN_SHIFT); + + ret = regmap_write(chip->regmap, REG_ENABLE, reg_val); + if (ret < 0) { + dev_err(chip->dev, "Failed to write REG_ENABLE Regisgter\n"); + goto out; + } + +out: + return ret; +} + +/* chip control */ +static int lm3556_control(struct lm3556_chip_data *chip, + u8 brightness, enum lm3556_mode opmode) +{ + int ret; + struct lm3556_platform_data *pdata = chip->pdata; + + ret = regmap_read(chip->regmap, REG_FLAG, &chip->last_flag); + if (ret < 0) { + dev_err(chip->dev, "Failed to read REG_FLAG Register\n"); + goto out; + } + + if (chip->last_flag) + dev_info(chip->dev, "Last FLAG is 0x%x\n", chip->last_flag); + + /* brightness 0 means off-state */ + if (!brightness) + opmode = MODES_STASNDBY; + + switch (opmode) { + case MODES_TORCH: + ret = regmap_update_bits(chip->regmap, REG_I_CTRL, + TORCH_I_MASK << TORCH_I_SHIFT, + (brightness - 1) << TORCH_I_SHIFT); + + if (pdata->torch_pin_en) + opmode |= (TORCH_PIN_EN_MASK << TORCH_PIN_EN_SHIFT); + break; + + case MODES_FLASH: + ret = regmap_update_bits(chip->regmap, REG_I_CTRL, + FLASH_I_MASK << FLASH_I_SHIFT, + (brightness - 1) << FLASH_I_SHIFT); + break; + + case MODES_INDIC: + ret = regmap_update_bits(chip->regmap, REG_I_CTRL, + TORCH_I_MASK << TORCH_I_SHIFT, + (brightness - 1) << TORCH_I_SHIFT); + break; + + case MODES_STASNDBY: + if (pdata->torch_pin_en) + opmode |= (TORCH_PIN_EN_MASK << TORCH_PIN_EN_SHIFT); + break; + + default: + return ret; + } + if (ret < 0) { + dev_err(chip->dev, "Failed to write REG_I_CTRL Register\n"); + goto out; + } + ret = regmap_update_bits(chip->regmap, REG_ENABLE, + MODE_BITS_MASK << MODE_BITS_SHIFT, + opmode << MODE_BITS_SHIFT); + +out: + return ret; +} + +/* torch */ +static void lm3556_torch_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct lm3556_chip_data *chip = + container_of(cdev, struct lm3556_chip_data, cdev_torch); + + mutex_lock(&chip->lock); + lm3556_control(chip, brightness, MODES_TORCH); + mutex_unlock(&chip->lock); +} + +/* flash */ +static void lm3556_strobe_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct lm3556_chip_data *chip = + container_of(cdev, struct lm3556_chip_data, cdev_flash); + + mutex_lock(&chip->lock); + lm3556_control(chip, brightness, MODES_FLASH); + mutex_unlock(&chip->lock); +} + +/* indicator */ +static void lm3556_indicator_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct lm3556_chip_data *chip = + container_of(cdev, struct lm3556_chip_data, cdev_indicator); + + mutex_lock(&chip->lock); + lm3556_control(chip, brightness, MODES_INDIC); + mutex_unlock(&chip->lock); +} + +/* indicator pattern */ +static ssize_t lm3556_indicator_pattern_store(struct device *dev, + struct device_attribute *devAttr, + const char *buf, size_t size) +{ + ssize_t ret; + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct lm3556_chip_data *chip = + container_of(led_cdev, struct lm3556_chip_data, cdev_indicator); + unsigned int state; + + ret = kstrtouint(buf, 10, &state); + if (ret) + goto out; + if (state > INDIC_PATTERN_SIZE - 1) + state = INDIC_PATTERN_SIZE - 1; + + ret = regmap_write(chip->regmap, REG_INDIC_BLINK, + indicator_pattern[state].blinking); + if (ret < 0) { + dev_err(chip->dev, "Failed to write REG_ENABLE Regisgter\n"); + goto out; + } + + ret = regmap_write(chip->regmap, REG_INDIC_PERIOD, + indicator_pattern[state].period_cnt); + if (ret < 0) { + dev_err(chip->dev, "Failed to write REG_ENABLE Regisgter\n"); + goto out; + } + + return size; +out: + dev_err(chip->dev, "Indicator pattern doesn't saved\n"); + return size; +} + +static DEVICE_ATTR(pattern, 0666, NULL, lm3556_indicator_pattern_store); + +static const struct regmap_config lm3556_regmap = { + .reg_bits = 8, + .val_bits = 8, + .max_register = REG_MAX, +}; + +/* module initialize */ +static int __devinit lm3556_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct lm3556_platform_data *pdata = client->dev.platform_data; + struct lm3556_chip_data *chip; + + int err; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_err(&client->dev, "i2c functionality check fail.\n"); + return -EOPNOTSUPP; + } + + if (pdata == NULL) { + dev_err(&client->dev, "Needs Platform Data.\n"); + return -ENODATA; + } + + chip = + devm_kzalloc(&client->dev, sizeof(struct lm3556_chip_data), + GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->dev = &client->dev; + chip->pdata = pdata; + + chip->regmap = devm_regmap_init_i2c(client, &lm3556_regmap); + if (IS_ERR(chip->regmap)) { + err = PTR_ERR(chip->regmap); + dev_err(&client->dev, "Failed to allocate register map: %d\n", + err); + return err; + } + + mutex_init(&chip->lock); + i2c_set_clientdata(client, chip); + + err = lm3556_chip_init(chip); + if (err < 0) + goto err_out; + + /* flash */ + chip->cdev_flash.name = "flash"; + chip->cdev_flash.max_brightness = 16; + chip->cdev_flash.brightness_set = lm3556_strobe_brightness_set; + err = led_classdev_register((struct device *) + &client->dev, &chip->cdev_flash); + if (err < 0) + goto err_out; + /* torch */ + chip->cdev_torch.name = "torch"; + chip->cdev_torch.max_brightness = 8; + chip->cdev_torch.brightness_set = lm3556_torch_brightness_set; + err = led_classdev_register((struct device *) + &client->dev, &chip->cdev_torch); + if (err < 0) + goto err_create_torch_file; + /* indicator */ + chip->cdev_indicator.name = "indicator"; + chip->cdev_indicator.max_brightness = 8; + chip->cdev_indicator.brightness_set = lm3556_indicator_brightness_set; + err = led_classdev_register((struct device *) + &client->dev, &chip->cdev_indicator); + if (err < 0) + goto err_create_indicator_file; + + err = device_create_file(chip->cdev_indicator.dev, &dev_attr_pattern); + if (err < 0) + goto err_create_pattern_file; + + dev_info(&client->dev, "LM3556 is initialized\n"); + return 0; + +err_create_pattern_file: + led_classdev_unregister(&chip->cdev_indicator); +err_create_indicator_file: + led_classdev_unregister(&chip->cdev_torch); +err_create_torch_file: + led_classdev_unregister(&chip->cdev_flash); +err_out: + return err; +} + +static int __devexit lm3556_remove(struct i2c_client *client) +{ + struct lm3556_chip_data *chip = i2c_get_clientdata(client); + + device_remove_file(chip->cdev_indicator.dev, &dev_attr_pattern); + led_classdev_unregister(&chip->cdev_indicator); + led_classdev_unregister(&chip->cdev_torch); + led_classdev_unregister(&chip->cdev_flash); + regmap_write(chip->regmap, REG_ENABLE, 0); + return 0; +} + +static const struct i2c_device_id lm3556_id[] = { + {LM3556_NAME, 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, lm3556_id); + +static struct i2c_driver lm3556_i2c_driver = { + .driver = { + .name = LM3556_NAME, + .owner = THIS_MODULE, + .pm = NULL, + }, + .probe = lm3556_probe, + .remove = __devexit_p(lm3556_remove), + .id_table = lm3556_id, +}; + +module_i2c_driver(lm3556_i2c_driver); + +MODULE_DESCRIPTION("Texas Instruments Flash Lighting driver for LM3556"); +MODULE_AUTHOR("Daniel Jeong "); +MODULE_AUTHOR("G.Shark Jeong "); +MODULE_LICENSE("GPL v2"); -- cgit v1.2.1 From 5391dd0a9d084633e20e6583cfed233581c452f9 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 27 Jun 2012 17:10:56 +0800 Subject: leds-lp5523: BUG() in error handling in probe() Inside the error handling in lp5523_init_led(), there is a place that calls to led_classdev_unregister(). When we unregister the LED drivers, it tries to set the brightness to OFF. In this driver setting the brightness is done through a work queue and the work queue hasn't been initialized yet. The result is that we trigger a WARN_ON() in the __queue_work(). The fix is to move the INIT_WORK() in front of the call to lp5523_init_led(). Matt Renzelmann found this using a bug finding tool. Reported-by: Matt Renzelmann Signed-off-by: Dan Carpenter Signed-off-by: Bryan Wu --- drivers/leds/leds-lp5523.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 857a3e15f2dd..e8a271232cd0 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -943,6 +943,9 @@ static int __devinit lp5523_probe(struct i2c_client *client, if (pdata->led_config[i].led_current == 0) continue; + INIT_WORK(&chip->leds[led].brightness_work, + lp5523_led_brightness_work); + ret = lp5523_init_led(&chip->leds[led], &client->dev, i, pdata); if (ret) { dev_err(&client->dev, "error initializing leds\n"); @@ -956,9 +959,6 @@ static int __devinit lp5523_probe(struct i2c_client *client, LP5523_REG_LED_CURRENT_BASE + chip->leds[led].chan_nr, chip->leds[led].led_current); - INIT_WORK(&(chip->leds[led].brightness_work), - lp5523_led_brightness_work); - led++; } -- cgit v1.2.1 From b523cfe61b097a45f4e919e8c3b6da239962b3e9 Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Mon, 2 Jul 2012 18:15:43 +0800 Subject: leds-88pm860x: use devm_kzalloc function Using devm_kzalloc will remove all the error checks and the frees are automatically done at the driver unload side. Signed-off-by: Devendra Naga Signed-off-by: Bryan Wu --- drivers/leds/leds-88pm860x.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c index 5b61aaf7ac0f..61897cfeeda6 100644 --- a/drivers/leds/leds-88pm860x.c +++ b/drivers/leds/leds-88pm860x.c @@ -209,7 +209,7 @@ static int pm860x_led_probe(struct platform_device *pdev) return -EINVAL; } - data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL); + data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_led), GFP_KERNEL); if (data == NULL) return -ENOMEM; strncpy(data->name, res->name, MFD_NAME_SIZE - 1); @@ -220,7 +220,6 @@ static int pm860x_led_probe(struct platform_device *pdev) data->port = pdata->flags; if (data->port < 0) { dev_err(&pdev->dev, "check device failed\n"); - kfree(data); return -EINVAL; } @@ -233,13 +232,10 @@ static int pm860x_led_probe(struct platform_device *pdev) ret = led_classdev_register(chip->dev, &data->cdev); if (ret < 0) { dev_err(&pdev->dev, "Failed to register LED: %d\n", ret); - goto out; + return ret; } pm860x_led_set(&data->cdev, 0); return 0; -out: - kfree(data); - return ret; } static int pm860x_led_remove(struct platform_device *pdev) @@ -247,7 +243,6 @@ static int pm860x_led_remove(struct platform_device *pdev) struct pm860x_led *data = platform_get_drvdata(pdev); led_classdev_unregister(&data->cdev); - kfree(data); return 0; } -- cgit v1.2.1 From 317dfb148d606a92e7d2748ab77f3d8f9749cc8a Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Mon, 2 Jul 2012 16:40:20 +0800 Subject: leds-mc13783: set platform data to NULL at mc13783_led_remove the platform_set_drvdata (pdev, NULL) to be set at the remove of the driver, as we have set the platform data to led at probe. Signed-off-by: Devendra Naga Signed-off-by: Bryan Wu --- drivers/leds/leds-mc13783.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c index 4cc6a2e3df34..6515c11dbe6b 100644 --- a/drivers/leds/leds-mc13783.c +++ b/drivers/leds/leds-mc13783.c @@ -372,6 +372,7 @@ static int __devexit mc13783_led_remove(struct platform_device *pdev) mc13xxx_unlock(dev); + platform_set_drvdata(pdev, NULL); kfree(led); return 0; } -- cgit v1.2.1 From 7e97b58133b7cddf3be80660300bb2c77c514c6f Mon Sep 17 00:00:00 2001 From: Sylwester Nawrocki Date: Sat, 30 Jun 2012 20:30:25 +0800 Subject: leds: Convert S3C24XX LED driver to devm_kzalloc() Use the device managed resource API for simplifying the error/driver remove paths. Cc: Ben Dooks Signed-off-by: Sylwester Nawrocki Signed-off-by: Bryan Wu --- drivers/leds/leds-s3c24xx.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c index e6ee10548265..b816ccb9adf4 100644 --- a/drivers/leds/leds-s3c24xx.c +++ b/drivers/leds/leds-s3c24xx.c @@ -63,7 +63,6 @@ static int s3c24xx_led_remove(struct platform_device *dev) struct s3c24xx_gpio_led *led = pdev_to_gpio(dev); led_classdev_unregister(&led->cdev); - kfree(led); return 0; } @@ -74,7 +73,8 @@ static int s3c24xx_led_probe(struct platform_device *dev) struct s3c24xx_gpio_led *led; int ret; - led = kzalloc(sizeof(struct s3c24xx_gpio_led), GFP_KERNEL); + led = devm_kzalloc(&dev->dev, sizeof(struct s3c24xx_gpio_led), + GFP_KERNEL); if (led == NULL) { dev_err(&dev->dev, "No memory for device\n"); return -ENOMEM; @@ -103,10 +103,8 @@ static int s3c24xx_led_probe(struct platform_device *dev) /* register our new led device */ ret = led_classdev_register(&dev->dev, &led->cdev); - if (ret < 0) { + if (ret < 0) dev_err(&dev->dev, "led_classdev_register failed\n"); - kfree(led); - } return ret; } -- cgit v1.2.1 From 7d84f66f22cb511b7cb7602b2a9dab20c8906da7 Mon Sep 17 00:00:00 2001 From: Sylwester Nawrocki Date: Sat, 30 Jun 2012 20:30:26 +0800 Subject: leds: Convert S3C24XX LED driver to gpiolib API The s3c2410_gpio* calls are obsolete and have been scheduled for removal since several kernel releases. Remove them and use common gpiolib API instead. This patch also adds gpio_request/gpio_free call for API corectness. It is a prerequisite for removal of the S3C24XX SoC specific arch/arm/plat-samsung/include/gpio-fns.h header. Tested on Micro2440-SDK. Cc: Ben Dooks Signed-off-by: Sylwester Nawrocki Signed-off-by: Bryan Wu --- drivers/leds/leds-s3c24xx.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c index b816ccb9adf4..e1206407616d 100644 --- a/drivers/leds/leds-s3c24xx.c +++ b/drivers/leds/leds-s3c24xx.c @@ -45,17 +45,19 @@ static void s3c24xx_led_set(struct led_classdev *led_cdev, { struct s3c24xx_gpio_led *led = to_gpio(led_cdev); struct s3c24xx_led_platdata *pd = led->pdata; + int state = (value ? 1 : 0) ^ (pd->flags & S3C24XX_LEDF_ACTLOW); /* there will be a short delay between setting the output and * going from output to input when using tristate. */ - s3c2410_gpio_setpin(pd->gpio, (value ? 1 : 0) ^ - (pd->flags & S3C24XX_LEDF_ACTLOW)); - - if (pd->flags & S3C24XX_LEDF_TRISTATE) - s3c2410_gpio_cfgpin(pd->gpio, - value ? S3C2410_GPIO_OUTPUT : S3C2410_GPIO_INPUT); + gpio_set_value(pd->gpio, state); + if (pd->flags & S3C24XX_LEDF_TRISTATE) { + if (value) + gpio_direction_output(pd->gpio, state); + else + gpio_direction_input(pd->gpio); + } } static int s3c24xx_led_remove(struct platform_device *dev) @@ -63,6 +65,7 @@ static int s3c24xx_led_remove(struct platform_device *dev) struct s3c24xx_gpio_led *led = pdev_to_gpio(dev); led_classdev_unregister(&led->cdev); + gpio_free(led->pdata->gpio); return 0; } @@ -89,16 +92,19 @@ static int s3c24xx_led_probe(struct platform_device *dev) led->pdata = pdata; + ret = gpio_request(pdata->gpio, "S3C24XX_LED"); + if (ret < 0) + return ret; + /* no point in having a pull-up if we are always driving */ - if (pdata->flags & S3C24XX_LEDF_TRISTATE) { - s3c2410_gpio_setpin(pdata->gpio, 0); - s3c2410_gpio_cfgpin(pdata->gpio, S3C2410_GPIO_INPUT); - } else { - s3c2410_gpio_pullup(pdata->gpio, 0); - s3c2410_gpio_setpin(pdata->gpio, 0); - s3c2410_gpio_cfgpin(pdata->gpio, S3C2410_GPIO_OUTPUT); - } + s3c_gpio_setpull(pdata->gpio, S3C_GPIO_PULL_NONE); + + if (pdata->flags & S3C24XX_LEDF_TRISTATE) + gpio_direction_input(pdata->gpio); + else + gpio_direction_output(pdata->gpio, + pdata->flags & S3C24XX_LEDF_ACTLOW ? 1 : 0); /* register our new led device */ -- cgit v1.2.1 From 2e9117672db9a9fa4339eb6c58cb76018e6b579e Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Tue, 3 Jul 2012 16:03:38 +0800 Subject: leds: convert tca6507 driver to module_i2c_driver() Signed-off-by: Peter Meerwald Cc: NeilBrown Signed-off-by: Bryan Wu --- drivers/leds/leds-tca6507.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c index 6c1c14f31635..f74a45a49f47 100644 --- a/drivers/leds/leds-tca6507.c +++ b/drivers/leds/leds-tca6507.c @@ -758,18 +758,7 @@ static struct i2c_driver tca6507_driver = { .id_table = tca6507_id, }; -static int __init tca6507_leds_init(void) -{ - return i2c_add_driver(&tca6507_driver); -} - -static void __exit tca6507_leds_exit(void) -{ - i2c_del_driver(&tca6507_driver); -} - -module_init(tca6507_leds_init); -module_exit(tca6507_leds_exit); +module_i2c_driver(tca6507_driver); MODULE_AUTHOR("NeilBrown "); MODULE_DESCRIPTION("TCA6507 LED/GPO driver"); -- cgit v1.2.1 From 7fafefb86e4d48464b79c125b37b9d472ba253ab Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 3 Jul 2012 19:47:51 +0800 Subject: leds: Use module_platform_driver() in leds-max8997.c file module_platform_driver() makes the code simpler. Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu --- drivers/leds/leds-max8997.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c index f4c0e37fad1e..86abfe24ad28 100644 --- a/drivers/leds/leds-max8997.c +++ b/drivers/leds/leds-max8997.c @@ -354,17 +354,7 @@ static struct platform_driver max8997_led_driver = { .remove = __devexit_p(max8997_led_remove), }; -static int __init max8997_led_init(void) -{ - return platform_driver_register(&max8997_led_driver); -} -module_init(max8997_led_init); - -static void __exit max8997_led_exit(void) -{ - platform_driver_unregister(&max8997_led_driver); -} -module_exit(max8997_led_exit); +module_platform_driver(max8997_led_driver); MODULE_AUTHOR("Donggeun Kim "); MODULE_DESCRIPTION("MAX8997 LED driver"); -- cgit v1.2.1 From 0b7da746cc5fdbdb7b52bf6faa9bb06bb0dd7869 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 3 Jul 2012 19:47:53 +0800 Subject: leds: Use devm_kzalloc in leds-pwm.c file devm_kzalloc() makes cleanup simpler. Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu --- drivers/leds/leds-pwm.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index 3ed92f34bd44..f2e44c719437 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -57,7 +57,8 @@ static int led_pwm_probe(struct platform_device *pdev) if (!pdata) return -EBUSY; - leds_data = kzalloc(sizeof(struct led_pwm_data) * pdata->num_leds, + leds_data = devm_kzalloc(&pdev->dev, + sizeof(struct led_pwm_data) * pdata->num_leds, GFP_KERNEL); if (!leds_data) return -ENOMEM; @@ -103,8 +104,6 @@ err: } } - kfree(leds_data); - return ret; } @@ -121,8 +120,6 @@ static int __devexit led_pwm_remove(struct platform_device *pdev) pwm_free(leds_data[i].pwm); } - kfree(leds_data); - return 0; } -- cgit v1.2.1 From d41589658ed1607303e702805c51030d6ecfc471 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 3 Jul 2012 19:47:54 +0800 Subject: leds: Use devm_kzalloc in leds-regulator.c file devm_kzalloc() makes cleanup simpler. Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu --- drivers/leds/leds-regulator.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-regulator.c b/drivers/leds/leds-regulator.c index df7e963bddd3..25d382d60fa9 100644 --- a/drivers/leds/leds-regulator.c +++ b/drivers/leds/leds-regulator.c @@ -158,7 +158,7 @@ static int __devinit regulator_led_probe(struct platform_device *pdev) return PTR_ERR(vcc); } - led = kzalloc(sizeof(*led), GFP_KERNEL); + led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); if (led == NULL) { ret = -ENOMEM; goto err_vcc; @@ -169,7 +169,7 @@ static int __devinit regulator_led_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Invalid default brightness %d\n", pdata->brightness); ret = -EINVAL; - goto err_led; + goto err_vcc; } led->value = pdata->brightness; @@ -190,7 +190,7 @@ static int __devinit regulator_led_probe(struct platform_device *pdev) ret = led_classdev_register(&pdev->dev, &led->cdev); if (ret < 0) { cancel_work_sync(&led->work); - goto err_led; + goto err_vcc; } /* to expose the default value to userspace */ @@ -201,8 +201,6 @@ static int __devinit regulator_led_probe(struct platform_device *pdev) return 0; -err_led: - kfree(led); err_vcc: regulator_put(vcc); return ret; @@ -216,7 +214,6 @@ static int __devexit regulator_led_remove(struct platform_device *pdev) cancel_work_sync(&led->work); regulator_led_disable(led); regulator_put(led->vcc); - kfree(led); return 0; } -- cgit v1.2.1 From 7f13bbf799f28d5c718a2f18c42f0c6ab56f501b Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Wed, 4 Jul 2012 11:21:36 +0800 Subject: leds: Use devm_kzalloc in leds-max8997.c file devm_kzalloc() makes code cleanup simpler. Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu --- drivers/leds/leds-max8997.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c index 86abfe24ad28..bf86d5483f43 100644 --- a/drivers/leds/leds-max8997.c +++ b/drivers/leds/leds-max8997.c @@ -276,11 +276,9 @@ static int __devinit max8997_led_probe(struct platform_device *pdev) return -ENODEV; } - led = kzalloc(sizeof(*led), GFP_KERNEL); - if (led == NULL) { - ret = -ENOMEM; - goto err_mem; - } + led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); + if (led == NULL) + return -ENOMEM; led->id = pdev->id; snprintf(name, sizeof(name), "max8997-led%d", pdev->id); @@ -315,23 +313,17 @@ static int __devinit max8997_led_probe(struct platform_device *pdev) ret = led_classdev_register(&pdev->dev, &led->cdev); if (ret < 0) - goto err_led; + return ret; ret = device_create_file(led->cdev.dev, &dev_attr_mode); if (ret != 0) { dev_err(&pdev->dev, "failed to create file: %d\n", ret); - goto err_file; + led_classdev_unregister(&led->cdev); + return ret; } return 0; - -err_file: - led_classdev_unregister(&led->cdev); -err_led: - kfree(led); -err_mem: - return ret; } static int __devexit max8997_led_remove(struct platform_device *pdev) @@ -340,7 +332,6 @@ static int __devexit max8997_led_remove(struct platform_device *pdev) device_remove_file(led->cdev.dev, &dev_attr_mode); led_classdev_unregister(&led->cdev); - kfree(led); return 0; } -- cgit v1.2.1 From 198b8611315f793a8f674c3ca3324028e19634aa Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Wed, 4 Jul 2012 11:35:44 +0800 Subject: leds: Use devm_kzalloc in leds-gpio.c file devm_kzalloc() makes cleanup simpler. Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu --- drivers/leds/leds-gpio.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index f4c470a3bc8d..c032b2180340 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -178,7 +178,8 @@ static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_dev if (!count) return NULL; - priv = kzalloc(sizeof_gpio_leds_priv(count), GFP_KERNEL); + priv = devm_kzalloc(&pdev->dev, sizeof_gpio_leds_priv(count), + GFP_KERNEL); if (!priv) return NULL; @@ -215,7 +216,6 @@ static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_dev err: for (count = priv->num_leds - 2; count >= 0; count--) delete_gpio_led(&priv->leds[count]); - kfree(priv); return NULL; } @@ -239,8 +239,9 @@ static int __devinit gpio_led_probe(struct platform_device *pdev) int i, ret = 0; if (pdata && pdata->num_leds) { - priv = kzalloc(sizeof_gpio_leds_priv(pdata->num_leds), - GFP_KERNEL); + priv = devm_kzalloc(&pdev->dev, + sizeof_gpio_leds_priv(pdata->num_leds), + GFP_KERNEL); if (!priv) return -ENOMEM; @@ -253,7 +254,6 @@ static int __devinit gpio_led_probe(struct platform_device *pdev) /* On failure: unwind the led creations */ for (i = i - 1; i >= 0; i--) delete_gpio_led(&priv->leds[i]); - kfree(priv); return ret; } } @@ -277,7 +277,6 @@ static int __devexit gpio_led_remove(struct platform_device *pdev) delete_gpio_led(&priv->leds[i]); dev_set_drvdata(&pdev->dev, NULL); - kfree(priv); return 0; } -- cgit v1.2.1 From 8095c385aacf54724ee571d65df987330da9fbd9 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Tue, 3 Jul 2012 12:42:55 +0800 Subject: leds: convert Big Networks LED driver to devm_kzalloc() Cc: Simon Guinot Signed-off-by: Bryan Wu --- drivers/leds/leds-netxbig.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c index 73973fdbd8be..e37618e363cf 100644 --- a/drivers/leds/leds-netxbig.c +++ b/drivers/leds/leds-netxbig.c @@ -362,14 +362,14 @@ static int __devinit netxbig_led_probe(struct platform_device *pdev) if (!pdata) return -EINVAL; - leds_data = kzalloc(sizeof(struct netxbig_led_data) * pdata->num_leds, - GFP_KERNEL); + leds_data = devm_kzalloc(&pdev->dev, + sizeof(struct netxbig_led_data) * pdata->num_leds, GFP_KERNEL); if (!leds_data) return -ENOMEM; ret = gpio_ext_init(pdata->gpio_ext); if (ret < 0) - goto err_free_data; + return ret; for (i = 0; i < pdata->num_leds; i++) { ret = create_netxbig_led(pdev, &leds_data[i], &pdata->leds[i]); @@ -386,9 +386,6 @@ err_free_leds: delete_netxbig_led(&leds_data[i]); gpio_ext_free(pdata->gpio_ext); -err_free_data: - kfree(leds_data); - return ret; } @@ -404,7 +401,6 @@ static int __devexit netxbig_led_remove(struct platform_device *pdev) delete_netxbig_led(&leds_data[i]); gpio_ext_free(pdata->gpio_ext); - kfree(leds_data); return 0; } -- cgit v1.2.1 From 60a0aadbf8f0858dcc8307afb3ec3c79ecad7c0a Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Tue, 3 Jul 2012 12:47:16 +0800 Subject: leds: convert HTC ASIC3 LED driver to devm_kzalloc() and cleanup error exit path Cc: Paul Parsons Signed-off-by: Bryan Wu --- drivers/leds/leds-asic3.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-asic3.c b/drivers/leds/leds-asic3.c index 525a92492837..5de74ff90dcf 100644 --- a/drivers/leds/leds-asic3.c +++ b/drivers/leds/leds-asic3.c @@ -99,12 +99,13 @@ static int __devinit asic3_led_probe(struct platform_device *pdev) ret = mfd_cell_enable(pdev); if (ret < 0) - goto ret0; + return ret; - led->cdev = kzalloc(sizeof(struct led_classdev), GFP_KERNEL); + led->cdev = devm_kzalloc(&pdev->dev, sizeof(struct led_classdev), + GFP_KERNEL); if (!led->cdev) { ret = -ENOMEM; - goto ret1; + goto out; } led->cdev->name = led->name; @@ -115,15 +116,12 @@ static int __devinit asic3_led_probe(struct platform_device *pdev) ret = led_classdev_register(&pdev->dev, led->cdev); if (ret < 0) - goto ret2; + goto out; return 0; -ret2: - kfree(led->cdev); -ret1: +out: (void) mfd_cell_disable(pdev); -ret0: return ret; } @@ -133,8 +131,6 @@ static int __devexit asic3_led_remove(struct platform_device *pdev) led_classdev_unregister(led->cdev); - kfree(led->cdev); - return mfd_cell_disable(pdev); } -- cgit v1.2.1 From 4aad381f0d1de9cca7509d77f1d504f2785870e8 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Tue, 3 Jul 2012 13:01:37 +0800 Subject: leds: convert Atmel PWM LED driver to devm_kzalloc() Signed-off-by: Bryan Wu --- drivers/leds/leds-atmel-pwm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-atmel-pwm.c b/drivers/leds/leds-atmel-pwm.c index 64ad702a2ecc..45430632faab 100644 --- a/drivers/leds/leds-atmel-pwm.c +++ b/drivers/leds/leds-atmel-pwm.c @@ -46,7 +46,8 @@ static int __devinit pwmled_probe(struct platform_device *pdev) if (!pdata || pdata->num_leds < 1) return -ENODEV; - leds = kcalloc(pdata->num_leds, sizeof(*leds), GFP_KERNEL); + leds = devm_kzalloc(&pdev->dev, pdata->num_leds * sizeof(*leds), + GFP_KERNEL); if (!leds) return -ENOMEM; @@ -108,7 +109,6 @@ err: pwm_channel_free(&leds[i].pwmc); } } - kfree(leds); return status; } @@ -129,7 +129,6 @@ static int __exit pwmled_remove(struct platform_device *pdev) pwm_channel_free(&led->pwmc); } - kfree(leds); platform_set_drvdata(pdev, NULL); return 0; } -- cgit v1.2.1 From 9813d74fa55fba7a974d66d452d1d699ee15073b Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Tue, 3 Jul 2012 13:04:32 +0800 Subject: leds: convert LP3944 LED driver to devm_kzalloc() Cc: Antonio Ospite Signed-off-by: Bryan Wu --- drivers/leds/leds-lp3944.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-lp3944.c b/drivers/leds/leds-lp3944.c index b8f9f0a5d431..c298f7d9f535 100644 --- a/drivers/leds/leds-lp3944.c +++ b/drivers/leds/leds-lp3944.c @@ -393,7 +393,8 @@ static int __devinit lp3944_probe(struct i2c_client *client, return -ENODEV; } - data = kzalloc(sizeof(struct lp3944_data), GFP_KERNEL); + data = devm_kzalloc(&client->dev, sizeof(struct lp3944_data), + GFP_KERNEL); if (!data) return -ENOMEM; @@ -403,10 +404,8 @@ static int __devinit lp3944_probe(struct i2c_client *client, mutex_init(&data->lock); err = lp3944_configure(client, data, lp3944_pdata); - if (err < 0) { - kfree(data); + if (err < 0) return err; - } dev_info(&client->dev, "lp3944 enabled\n"); return 0; @@ -431,8 +430,6 @@ static int __devexit lp3944_remove(struct i2c_client *client) break; } - kfree(data); - return 0; } -- cgit v1.2.1 From bad1c898e8b70c644c6542f79802326cc7b11c77 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Tue, 3 Jul 2012 13:07:53 +0800 Subject: leds: convert DA9030/DA9034 LED driver to devm_kzalloc() and cleanup error exit path Cc: Eric Miao Signed-off-by: Bryan Wu --- drivers/leds/leds-da903x.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-da903x.c b/drivers/leds/leds-da903x.c index d9cd73ebd6c4..cc77c9d92615 100644 --- a/drivers/leds/leds-da903x.c +++ b/drivers/leds/leds-da903x.c @@ -108,7 +108,7 @@ static int __devinit da903x_led_probe(struct platform_device *pdev) return -EINVAL; } - led = kzalloc(sizeof(struct da903x_led), GFP_KERNEL); + led = devm_kzalloc(&pdev->dev, sizeof(struct da903x_led), GFP_KERNEL); if (led == NULL) { dev_err(&pdev->dev, "failed to alloc memory for LED%d\n", id); return -ENOMEM; @@ -129,15 +129,11 @@ static int __devinit da903x_led_probe(struct platform_device *pdev) ret = led_classdev_register(led->master, &led->cdev); if (ret) { dev_err(&pdev->dev, "failed to register LED %d\n", id); - goto err; + return ret; } platform_set_drvdata(pdev, led); return 0; - -err: - kfree(led); - return ret; } static int __devexit da903x_led_remove(struct platform_device *pdev) @@ -145,7 +141,6 @@ static int __devexit da903x_led_remove(struct platform_device *pdev) struct da903x_led *led = platform_get_drvdata(pdev); led_classdev_unregister(&led->cdev); - kfree(led); return 0; } -- cgit v1.2.1 From e430dc003f023f3f5244418aa26cc64e78ab8b6e Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 11:16:09 +0800 Subject: leds: convert LP5521 LED driver to devm_kzalloc() and cleanup error exit path Signed-off-by: Bryan Wu --- drivers/leds/leds-lp5521.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 23815624f35e..2064aefedc07 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -744,7 +744,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, int ret, i, led; u8 buf; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; @@ -755,8 +755,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, if (!pdata) { dev_err(&client->dev, "no platform data\n"); - ret = -EINVAL; - goto fail1; + return -EINVAL; } mutex_init(&chip->lock); @@ -766,7 +765,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, if (pdata->setup_resources) { ret = pdata->setup_resources(); if (ret < 0) - goto fail1; + return ret; } if (pdata->enable) { @@ -807,7 +806,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, ret = lp5521_configure(client); if (ret < 0) { dev_err(&client->dev, "error configuring chip\n"); - goto fail2; + goto fail1; } /* Initialize leds */ @@ -822,7 +821,7 @@ static int __devinit lp5521_probe(struct i2c_client *client, ret = lp5521_init_led(&chip->leds[led], client, i, pdata); if (ret) { dev_err(&client->dev, "error initializing leds\n"); - goto fail3; + goto fail2; } chip->num_leds++; @@ -840,21 +839,19 @@ static int __devinit lp5521_probe(struct i2c_client *client, ret = lp5521_register_sysfs(client); if (ret) { dev_err(&client->dev, "registering sysfs failed\n"); - goto fail3; + goto fail2; } return ret; -fail3: +fail2: for (i = 0; i < chip->num_leds; i++) { led_classdev_unregister(&chip->leds[i].cdev); cancel_work_sync(&chip->leds[i].brightness_work); } -fail2: +fail1: if (pdata->enable) pdata->enable(0); if (pdata->release_resources) pdata->release_resources(); -fail1: - kfree(chip); return ret; } @@ -875,7 +872,6 @@ static int __devexit lp5521_remove(struct i2c_client *client) chip->pdata->enable(0); if (chip->pdata->release_resources) chip->pdata->release_resources(); - kfree(chip); return 0; } -- cgit v1.2.1 From ac63ff50ad37369b838e1416665ff8ca7e9c9b1b Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 11:35:03 +0800 Subject: leds: convert BD2802 RGB LED driver to devm_kzalloc() and cleanup error exit path Cc: Kim Kyuwon Signed-off-by: Bryan Wu --- drivers/leds/leds-bd2802.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-bd2802.c b/drivers/leds/leds-bd2802.c index 591cbdf5a046..89ca6a2a19d1 100644 --- a/drivers/leds/leds-bd2802.c +++ b/drivers/leds/leds-bd2802.c @@ -677,7 +677,7 @@ static int __devinit bd2802_probe(struct i2c_client *client, struct bd2802_led_platform_data *pdata; int ret, i; - led = kzalloc(sizeof(struct bd2802_led), GFP_KERNEL); + led = devm_kzalloc(&client->dev, sizeof(struct bd2802_led), GFP_KERNEL); if (!led) { dev_err(&client->dev, "failed to allocate driver data\n"); return -ENOMEM; @@ -697,7 +697,7 @@ static int __devinit bd2802_probe(struct i2c_client *client, ret = bd2802_write_byte(client, BD2802_REG_CLKSETUP, 0x00); if (ret < 0) { dev_err(&client->dev, "failed to detect device\n"); - goto failed_free; + return ret; } else dev_info(&client->dev, "return 0x%02x\n", ret); @@ -729,9 +729,6 @@ static int __devinit bd2802_probe(struct i2c_client *client, failed_unregister_dev_file: for (i--; i >= 0; i--) device_remove_file(&led->client->dev, bd2802_attributes[i]); -failed_free: - kfree(led); - return ret; } @@ -746,7 +743,6 @@ static int __exit bd2802_remove(struct i2c_client *client) bd2802_disable_adv_conf(led); for (i = 0; i < ARRAY_SIZE(bd2802_attributes); i++) device_remove_file(&led->client->dev, bd2802_attributes[i]); - kfree(led); return 0; } -- cgit v1.2.1 From 983ce8840c9cbafefd568f6973e531d77119a977 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 11:40:10 +0800 Subject: leds: convert PCA9633 LED driver to devm_kzalloc() Cc: Peter Meerwald Signed-off-by: Bryan Wu --- drivers/leds/leds-pca9633.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-pca9633.c b/drivers/leds/leds-pca9633.c index d8926fd031aa..edcd706c5631 100644 --- a/drivers/leds/leds-pca9633.c +++ b/drivers/leds/leds-pca9633.c @@ -108,7 +108,7 @@ static int __devinit pca9633_probe(struct i2c_client *client, } } - pca9633 = kcalloc(4, sizeof(*pca9633), GFP_KERNEL); + pca9633 = devm_kzalloc(&client->dev, 4 * sizeof(*pca9633), GFP_KERNEL); if (!pca9633) return -ENOMEM; @@ -156,8 +156,6 @@ exit: cancel_work_sync(&pca9633[i].work); } - kfree(pca9633); - return err; } @@ -171,8 +169,6 @@ static int __devexit pca9633_remove(struct i2c_client *client) cancel_work_sync(&pca9633[i].work); } - kfree(pca9633); - return 0; } -- cgit v1.2.1 From 94ca4bccac0f4cc521148134895498826a63aa2a Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 11:44:18 +0800 Subject: leds: convert LP5523 LED driver to devm_kzalloc() and cleanup error exit path Cc: Mathias Nyman Signed-off-by: Bryan Wu --- drivers/leds/leds-lp5523.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index e8a271232cd0..fbc12acada95 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -877,7 +877,7 @@ static int __devinit lp5523_probe(struct i2c_client *client, struct lp5523_platform_data *pdata; int ret, i, led; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; @@ -888,8 +888,7 @@ static int __devinit lp5523_probe(struct i2c_client *client, if (!pdata) { dev_err(&client->dev, "no platform data\n"); - ret = -EINVAL; - goto fail1; + return -EINVAL; } mutex_init(&chip->lock); @@ -899,7 +898,7 @@ static int __devinit lp5523_probe(struct i2c_client *client, if (pdata->setup_resources) { ret = pdata->setup_resources(); if (ret < 0) - goto fail1; + return ret; } if (pdata->enable) { @@ -916,7 +915,7 @@ static int __devinit lp5523_probe(struct i2c_client *client, */ ret = lp5523_detect(client); if (ret) - goto fail2; + goto fail1; dev_info(&client->dev, "LP5523 Programmable led chip found\n"); @@ -925,13 +924,13 @@ static int __devinit lp5523_probe(struct i2c_client *client, ret = lp5523_init_engine(&chip->engines[i], i + 1); if (ret) { dev_err(&client->dev, "error initializing engine\n"); - goto fail2; + goto fail1; } } ret = lp5523_configure(client); if (ret < 0) { dev_err(&client->dev, "error configuring chip\n"); - goto fail2; + goto fail1; } /* Initialize leds */ @@ -949,7 +948,7 @@ static int __devinit lp5523_probe(struct i2c_client *client, ret = lp5523_init_led(&chip->leds[led], &client->dev, i, pdata); if (ret) { dev_err(&client->dev, "error initializing leds\n"); - goto fail3; + goto fail2; } chip->num_leds++; @@ -965,21 +964,19 @@ static int __devinit lp5523_probe(struct i2c_client *client, ret = lp5523_register_sysfs(client); if (ret) { dev_err(&client->dev, "registering sysfs failed\n"); - goto fail3; + goto fail2; } return ret; -fail3: +fail2: for (i = 0; i < chip->num_leds; i++) { led_classdev_unregister(&chip->leds[i].cdev); cancel_work_sync(&chip->leds[i].brightness_work); } -fail2: +fail1: if (pdata->enable) pdata->enable(0); if (pdata->release_resources) pdata->release_resources(); -fail1: - kfree(chip); return ret; } @@ -999,7 +996,6 @@ static int lp5523_remove(struct i2c_client *client) chip->pdata->enable(0); if (chip->pdata->release_resources) chip->pdata->release_resources(); - kfree(chip); return 0; } -- cgit v1.2.1 From bfe4c0419397ffe33ed7accf1729a95737e7ee9e Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 11:48:57 +0800 Subject: leds: convert Renesas TPU LED driver to devm_kzalloc() and cleanup error exit path Cc: Magnus Damm Signed-off-by: Bryan Wu --- drivers/leds/leds-renesas-tpu.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-renesas-tpu.c b/drivers/leds/leds-renesas-tpu.c index 32fe337d5c68..9ee12c28059a 100644 --- a/drivers/leds/leds-renesas-tpu.c +++ b/drivers/leds/leds-renesas-tpu.c @@ -243,31 +243,30 @@ static int __devinit r_tpu_probe(struct platform_device *pdev) struct led_renesas_tpu_config *cfg = pdev->dev.platform_data; struct r_tpu_priv *p; struct resource *res; - int ret = -ENXIO; + int ret; if (!cfg) { dev_err(&pdev->dev, "missing platform data\n"); goto err0; } - p = kzalloc(sizeof(*p), GFP_KERNEL); + p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); if (p == NULL) { dev_err(&pdev->dev, "failed to allocate driver data\n"); - ret = -ENOMEM; - goto err0; + return -ENOMEM; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "failed to get I/O memory\n"); - goto err1; + return -ENXIO; } /* map memory, let mapbase point to our channel */ p->mapbase = ioremap_nocache(res->start, resource_size(res)); if (p->mapbase == NULL) { dev_err(&pdev->dev, "failed to remap I/O memory\n"); - goto err1; + return -ENXIO; } /* get hold of clock */ @@ -275,7 +274,7 @@ static int __devinit r_tpu_probe(struct platform_device *pdev) if (IS_ERR(p->clk)) { dev_err(&pdev->dev, "cannot get clock\n"); ret = PTR_ERR(p->clk); - goto err2; + goto err0; } p->pdev = pdev; @@ -294,7 +293,7 @@ static int __devinit r_tpu_probe(struct platform_device *pdev) p->ldev.flags |= LED_CORE_SUSPENDRESUME; ret = led_classdev_register(&pdev->dev, &p->ldev); if (ret < 0) - goto err3; + goto err1; /* max_brightness may be updated by the LED core code */ p->min_rate = p->ldev.max_brightness * p->refresh_rate; @@ -302,14 +301,11 @@ static int __devinit r_tpu_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); return 0; - err3: + err1: r_tpu_set_pin(p, R_TPU_PIN_UNUSED, LED_OFF); clk_put(p->clk); - err2: - iounmap(p->mapbase); - err1: - kfree(p); err0: + iounmap(p->mapbase); return ret; } @@ -327,7 +323,6 @@ static int __devexit r_tpu_remove(struct platform_device *pdev) clk_put(p->clk); iounmap(p->mapbase); - kfree(p); return 0; } -- cgit v1.2.1 From 0a8d9d4a61d8c7d6ea00835c814a678ba488b8aa Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 11:51:51 +0800 Subject: leds: convert LT3593 LED driver to devm_kzalloc() Cc: Daniel Mack Signed-off-by: Bryan Wu --- drivers/leds/leds-lt3593.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-lt3593.c b/drivers/leds/leds-lt3593.c index e311a96c4469..09a732217f6d 100644 --- a/drivers/leds/leds-lt3593.c +++ b/drivers/leds/leds-lt3593.c @@ -149,8 +149,9 @@ static int __devinit lt3593_led_probe(struct platform_device *pdev) if (!pdata) return -EBUSY; - leds_data = kzalloc(sizeof(struct lt3593_led_data) * pdata->num_leds, - GFP_KERNEL); + leds_data = devm_kzalloc(&pdev->dev, + sizeof(struct lt3593_led_data) * pdata->num_leds, + GFP_KERNEL); if (!leds_data) return -ENOMEM; @@ -169,8 +170,6 @@ err: for (i = i - 1; i >= 0; i--) delete_lt3593_led(&leds_data[i]); - kfree(leds_data); - return ret; } @@ -185,8 +184,6 @@ static int __devexit lt3593_led_remove(struct platform_device *pdev) for (i = 0; i < pdata->num_leds; i++) delete_lt3593_led(&leds_data[i]); - kfree(leds_data); - return 0; } -- cgit v1.2.1 From 0f4630c90b2c00dfb005d239d8926ec310fd560a Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 11:59:19 +0800 Subject: leds: convert PCA9532 LED driver to devm_kzalloc() Cc: Riku Voipio Signed-off-by: Bryan Wu --- drivers/leds/leds-pca9532.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c index ceccab44b5b8..cee8a5b483ac 100644 --- a/drivers/leds/leds-pca9532.c +++ b/drivers/leds/leds-pca9532.c @@ -449,7 +449,6 @@ static int pca9532_probe(struct i2c_client *client, { struct pca9532_data *data = i2c_get_clientdata(client); struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data; - int err; if (!pca9532_pdata) return -EIO; @@ -458,7 +457,7 @@ static int pca9532_probe(struct i2c_client *client, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; - data = kzalloc(sizeof(*data), GFP_KERNEL); + data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; @@ -469,11 +468,7 @@ static int pca9532_probe(struct i2c_client *client, data->client = client; mutex_init(&data->update_lock); - err = pca9532_configure(client, data, pca9532_pdata); - if (err) - kfree(data); - - return err; + return pca9532_configure(client, data, pca9532_pdata); } static int pca9532_remove(struct i2c_client *client) @@ -485,7 +480,6 @@ static int pca9532_remove(struct i2c_client *client) if (err) return err; - kfree(data); return 0; } -- cgit v1.2.1 From 234699a8f3228754fa4c0dfe90170c8a043fedab Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 12:04:48 +0800 Subject: leds: convert Sun Fire LED driver to devm_kzalloc() and cleanup error exit path Cc: David S. Miller Signed-off-by: Bryan Wu --- drivers/leds/leds-sunfire.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-sunfire.c b/drivers/leds/leds-sunfire.c index 1757396b20b3..134d9a4b34f1 100644 --- a/drivers/leds/leds-sunfire.c +++ b/drivers/leds/leds-sunfire.c @@ -132,15 +132,13 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev, if (pdev->num_resources != 1) { printk(KERN_ERR PFX "Wrong number of resources %d, should be 1\n", pdev->num_resources); - err = -EINVAL; - goto out; + return -EINVAL; } - p = kzalloc(sizeof(*p), GFP_KERNEL); + p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); if (!p) { printk(KERN_ERR PFX "Could not allocate struct sunfire_drvdata\n"); - err = -ENOMEM; - goto out; + return -ENOMEM; } for (i = 0; i < NUM_LEDS_PER_BOARD; i++) { @@ -156,20 +154,15 @@ static int __devinit sunfire_led_generic_probe(struct platform_device *pdev, if (err) { printk(KERN_ERR PFX "Could not register %s LED\n", lp->name); - goto out_unregister_led_cdevs; + for (i--; i >= 0; i--) + led_classdev_unregister(&p->leds[i].led_cdev); + return err; } } dev_set_drvdata(&pdev->dev, p); return 0; - -out_unregister_led_cdevs: - for (i--; i >= 0; i--) - led_classdev_unregister(&p->leds[i].led_cdev); - kfree(p); -out: - return err; } static int __devexit sunfire_led_generic_remove(struct platform_device *pdev) @@ -180,8 +173,6 @@ static int __devexit sunfire_led_generic_remove(struct platform_device *pdev) for (i = 0; i < NUM_LEDS_PER_BOARD; i++) led_classdev_unregister(&p->leds[i].led_cdev); - kfree(p); - return 0; } -- cgit v1.2.1 From 73759f6ab3620d605a5ce07d5316df1abb7edf18 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 12:09:05 +0800 Subject: leds: convert PCA955x LED driver to devm_kzalloc() and cleanup error exit path Cc: Nate Case Signed-off-by: Bryan Wu --- drivers/leds/leds-pca955x.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c index 5f462dbf0dbb..aef3cf0432fe 100644 --- a/drivers/leds/leds-pca955x.c +++ b/drivers/leds/leds-pca955x.c @@ -293,15 +293,14 @@ static int __devinit pca955x_probe(struct i2c_client *client, } } - pca955x = kzalloc(sizeof(*pca955x), GFP_KERNEL); + pca955x = devm_kzalloc(&client->dev, sizeof(*pca955x), GFP_KERNEL); if (!pca955x) return -ENOMEM; - pca955x->leds = kzalloc(sizeof(*pca955x_led) * chip->bits, GFP_KERNEL); - if (!pca955x->leds) { - err = -ENOMEM; - goto exit_nomem; - } + pca955x->leds = devm_kzalloc(&client->dev, + sizeof(*pca955x_led) * chip->bits, GFP_KERNEL); + if (!pca955x->leds) + return -ENOMEM; i2c_set_clientdata(client, pca955x); @@ -361,10 +360,6 @@ exit: cancel_work_sync(&pca955x->leds[i].work); } - kfree(pca955x->leds); -exit_nomem: - kfree(pca955x); - return err; } @@ -378,9 +373,6 @@ static int __devexit pca955x_remove(struct i2c_client *client) cancel_work_sync(&pca955x->leds[i].work); } - kfree(pca955x->leds); - kfree(pca955x); - return 0; } -- cgit v1.2.1 From bcbf01624f8e551d2c3c13a2b0c394fb270fd774 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 12:11:40 +0800 Subject: leds: convert ADP5520 LED driver to devm_kzalloc() and cleanup error exit path Cc: Michael Hennerich Signed-off-by: Bryan Wu --- drivers/leds/leds-adp5520.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-adp5520.c b/drivers/leds/leds-adp5520.c index b1400db3f839..aa56a867693a 100644 --- a/drivers/leds/leds-adp5520.c +++ b/drivers/leds/leds-adp5520.c @@ -119,7 +119,8 @@ static int __devinit adp5520_led_probe(struct platform_device *pdev) return -EFAULT; } - led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL); + led = devm_kzalloc(&pdev->dev, sizeof(*led) * pdata->num_leds, + GFP_KERNEL); if (led == NULL) { dev_err(&pdev->dev, "failed to alloc memory\n"); return -ENOMEM; @@ -129,7 +130,7 @@ static int __devinit adp5520_led_probe(struct platform_device *pdev) if (ret) { dev_err(&pdev->dev, "failed to write\n"); - goto err_free; + return ret; } for (i = 0; i < pdata->num_leds; ++i) { @@ -179,8 +180,6 @@ err: } } -err_free: - kfree(led); return ret; } @@ -200,7 +199,6 @@ static int __devexit adp5520_led_remove(struct platform_device *pdev) cancel_work_sync(&led[i].work); } - kfree(led); return 0; } -- cgit v1.2.1 From a44cdd2c1a527a08069d9635a9e8e1a2e9473e98 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 12:18:35 +0800 Subject: leds: convert Freescale MC13783 LED driver to devm_kzalloc() and cleanup error exit path Cc: Philippe Retornaz Signed-off-by: Bryan Wu --- drivers/leds/leds-mc13783.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c index 6515c11dbe6b..2a5d43400677 100644 --- a/drivers/leds/leds-mc13783.c +++ b/drivers/leds/leds-mc13783.c @@ -280,7 +280,8 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev) return -EINVAL; } - led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL); + led = devm_kzalloc(&pdev->dev, pdata->num_leds * sizeof(*led), + GFP_KERNEL); if (led == NULL) { dev_err(&pdev->dev, "failed to alloc memory\n"); return -ENOMEM; @@ -289,7 +290,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev) ret = mc13783_leds_prepare(pdev); if (ret) { dev_err(&pdev->dev, "unable to init led driver\n"); - goto err_free; + return ret; } for (i = 0; i < pdata->num_leds; i++) { @@ -344,8 +345,6 @@ err_register: cancel_work_sync(&led[i].work); } -err_free: - kfree(led); return ret; } @@ -373,7 +372,6 @@ static int __devexit mc13783_led_remove(struct platform_device *pdev) mc13xxx_unlock(dev); platform_set_drvdata(pdev, NULL); - kfree(led); return 0; } -- cgit v1.2.1 From 6770fc60c4fb3fac9578013103012b7cd0355e44 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 12:20:41 +0800 Subject: leds: convert TCA6507 LED driver to devm_kzalloc() Cc: Neil Brown Signed-off-by: Bryan Wu --- drivers/leds/leds-tca6507.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c index f74a45a49f47..dabcf7ae8d0f 100644 --- a/drivers/leds/leds-tca6507.c +++ b/drivers/leds/leds-tca6507.c @@ -687,7 +687,7 @@ static int __devinit tca6507_probe(struct i2c_client *client, NUM_LEDS); return -ENODEV; } - tca = kzalloc(sizeof(*tca), GFP_KERNEL); + tca = devm_kzalloc(&client->dev, sizeof(*tca), GFP_KERNEL); if (!tca) return -ENOMEM; @@ -727,7 +727,6 @@ exit: if (tca->leds[i].led_cdev.name) led_classdev_unregister(&tca->leds[i].led_cdev); } - kfree(tca); return err; } @@ -743,7 +742,6 @@ static int __devexit tca6507_remove(struct i2c_client *client) } tca6507_remove_gpio(tca); cancel_work_sync(&tca->work); - kfree(tca); return 0; } -- cgit v1.2.1 From 0b873f3d507b43f7381fb6c377d0034ed6696d46 Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 12:24:40 +0800 Subject: leds: convert LM3530 LED driver to devm_kzalloc() and cleanup error exit path Cc: Shreshtha Kumar SAHU Acked-by: Linus Walleij Signed-off-by: Bryan Wu --- drivers/leds/leds-lm3530.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-lm3530.c b/drivers/leds/leds-lm3530.c index 84ba6de8039c..23637bdb275d 100644 --- a/drivers/leds/leds-lm3530.c +++ b/drivers/leds/leds-lm3530.c @@ -386,28 +386,24 @@ static int __devinit lm3530_probe(struct i2c_client *client, if (pdata == NULL) { dev_err(&client->dev, "platform data required\n"); - err = -ENODEV; - goto err_out; + return -ENODEV; } /* BL mode */ if (pdata->mode > LM3530_BL_MODE_PWM) { dev_err(&client->dev, "Illegal Mode request\n"); - err = -EINVAL; - goto err_out; + return -EINVAL; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_err(&client->dev, "I2C_FUNC_I2C not supported\n"); - err = -EIO; - goto err_out; + return -EIO; } - drvdata = kzalloc(sizeof(struct lm3530_data), GFP_KERNEL); - if (drvdata == NULL) { - err = -ENOMEM; - goto err_out; - } + drvdata = devm_kzalloc(&client->dev, sizeof(struct lm3530_data), + GFP_KERNEL); + if (drvdata == NULL) + return -ENOMEM; drvdata->mode = pdata->mode; drvdata->client = client; @@ -425,7 +421,7 @@ static int __devinit lm3530_probe(struct i2c_client *client, dev_err(&client->dev, "regulator get failed\n"); err = PTR_ERR(drvdata->regulator); drvdata->regulator = NULL; - goto err_regulator_get; + return err; } if (drvdata->pdata->brt_val) { @@ -458,9 +454,6 @@ err_create_file: err_class_register: err_reg_init: regulator_put(drvdata->regulator); -err_regulator_get: - kfree(drvdata); -err_out: return err; } @@ -474,7 +467,6 @@ static int __devexit lm3530_remove(struct i2c_client *client) regulator_disable(drvdata->regulator); regulator_put(drvdata->regulator); led_classdev_unregister(&drvdata->led_dev); - kfree(drvdata); return 0; } -- cgit v1.2.1 From e58603122ee05f9bcfa07a33492d986dd5841a9c Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 12:27:40 +0800 Subject: leds: convert DAC124S085 LED driver to devm_kzalloc() Cc: Guennadi Liakhovetski Signed-off-by: Bryan Wu --- drivers/leds/leds-dac124s085.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-dac124s085.c b/drivers/leds/leds-dac124s085.c index d56c14269ff0..1f9d8e62d37e 100644 --- a/drivers/leds/leds-dac124s085.c +++ b/drivers/leds/leds-dac124s085.c @@ -69,7 +69,7 @@ static int dac124s085_probe(struct spi_device *spi) struct dac124s085_led *led; int i, ret; - dac = kzalloc(sizeof(*dac), GFP_KERNEL); + dac = devm_kzalloc(&spi->dev, sizeof(*dac), GFP_KERNEL); if (!dac) return -ENOMEM; @@ -102,7 +102,6 @@ eledcr: led_classdev_unregister(&dac->leds[i].ldev); spi_set_drvdata(spi, NULL); - kfree(dac); return ret; } @@ -117,7 +116,6 @@ static int dac124s085_remove(struct spi_device *spi) } spi_set_drvdata(spi, NULL); - kfree(dac); return 0; } -- cgit v1.2.1 From a209f7669870c461932515eba147b961692de37f Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Wed, 4 Jul 2012 12:30:50 +0800 Subject: leds: convert Network Space v2 LED driver to devm_kzalloc() and cleanup error exit path Cc: Simon Guinot Signed-off-by: Bryan Wu --- drivers/leds/leds-ns2.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c index 01cf89ec6944..10528dafb043 100644 --- a/drivers/leds/leds-ns2.c +++ b/drivers/leds/leds-ns2.c @@ -273,29 +273,23 @@ static int __devinit ns2_led_probe(struct platform_device *pdev) if (!pdata) return -EINVAL; - leds_data = kzalloc(sizeof(struct ns2_led_data) * + leds_data = devm_kzalloc(&pdev->dev, sizeof(struct ns2_led_data) * pdata->num_leds, GFP_KERNEL); if (!leds_data) return -ENOMEM; for (i = 0; i < pdata->num_leds; i++) { ret = create_ns2_led(pdev, &leds_data[i], &pdata->leds[i]); - if (ret < 0) - goto err; - + if (ret < 0) { + for (i = i - 1; i >= 0; i--) + delete_ns2_led(&leds_data[i]); + return ret; + } } platform_set_drvdata(pdev, leds_data); return 0; - -err: - for (i = i - 1; i >= 0; i--) - delete_ns2_led(&leds_data[i]); - - kfree(leds_data); - - return ret; } static int __devexit ns2_led_remove(struct platform_device *pdev) @@ -309,7 +303,6 @@ static int __devexit ns2_led_remove(struct platform_device *pdev) for (i = 0; i < pdata->num_leds; i++) delete_ns2_led(&leds_data[i]); - kfree(leds_data); platform_set_drvdata(pdev, NULL); return 0; -- cgit v1.2.1 From 5ecf6e40bbb8649b8418c8038a2af1faefbc56e4 Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Wed, 11 Jul 2012 17:50:32 +0800 Subject: leds/leds-s3c24xx: use devm_gpio_request why? because if the led_classdev_register fails we wont do gpio free because using devm_ functions, there is no need for error paths Signed-off-by: Devendra Naga Signed-off-by: Bryan Wu --- drivers/leds/leds-s3c24xx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c index e1206407616d..942f0ea18178 100644 --- a/drivers/leds/leds-s3c24xx.c +++ b/drivers/leds/leds-s3c24xx.c @@ -65,7 +65,6 @@ static int s3c24xx_led_remove(struct platform_device *dev) struct s3c24xx_gpio_led *led = pdev_to_gpio(dev); led_classdev_unregister(&led->cdev); - gpio_free(led->pdata->gpio); return 0; } @@ -92,7 +91,7 @@ static int s3c24xx_led_probe(struct platform_device *dev) led->pdata = pdata; - ret = gpio_request(pdata->gpio, "S3C24XX_LED"); + ret = devm_gpio_request(&dev->dev, pdata->gpio, "S3C24XX_LED"); if (ret < 0) return ret; -- cgit v1.2.1 From eb18618b8018bffad6e62f1bc40e4e0c7ee2fa19 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 24 Jul 2012 14:29:47 +0800 Subject: leds: max8997: Simplify max8997_led_set_mode implementation It is not necessary to call max8997_update_reg() twice just for updating MAX8997_REG_LEN_CNTL register. With proper val and mask arguments to max8997_update_reg() call, this can be done in one max8997_update_reg() call. And then we can remove max8997_led_clear_mode() function. Signed-off-by: Axel Lin Signed-off-by: Bryan Wu --- drivers/leds/leds-max8997.c | 60 ++++++++++----------------------------------- 1 file changed, 13 insertions(+), 47 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c index bf86d5483f43..569e36de37df 100644 --- a/drivers/leds/leds-max8997.c +++ b/drivers/leds/leds-max8997.c @@ -49,71 +49,37 @@ struct max8997_led { struct mutex mutex; }; -static void max8997_led_clear_mode(struct max8997_led *led, - enum max8997_led_mode mode) -{ - struct i2c_client *client = led->iodev->i2c; - u8 val = 0, mask = 0; - int ret; - - switch (mode) { - case MAX8997_FLASH_MODE: - mask = led->id ? - MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK; - break; - case MAX8997_MOVIE_MODE: - mask = led->id ? - MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK; - break; - case MAX8997_FLASH_PIN_CONTROL_MODE: - mask = led->id ? - MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK; - break; - case MAX8997_MOVIE_PIN_CONTROL_MODE: - mask = led->id ? - MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK; - break; - default: - break; - } - - if (mask) { - ret = max8997_update_reg(client, - MAX8997_REG_LEN_CNTL, val, mask); - if (ret) - dev_err(led->iodev->dev, - "failed to update register(%d)\n", ret); - } -} - static void max8997_led_set_mode(struct max8997_led *led, enum max8997_led_mode mode) { int ret; struct i2c_client *client = led->iodev->i2c; - u8 mask = 0; - - /* First, clear the previous mode */ - max8997_led_clear_mode(led, led->led_mode); + u8 mask = 0, val; switch (mode) { case MAX8997_FLASH_MODE: - mask = led->id ? + mask = MAX8997_LED1_FLASH_MASK | MAX8997_LED0_FLASH_MASK; + val = led->id ? MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK; led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS; break; case MAX8997_MOVIE_MODE: - mask = led->id ? + mask = MAX8997_LED1_MOVIE_MASK | MAX8997_LED0_MOVIE_MASK; + val = led->id ? MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK; led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS; break; case MAX8997_FLASH_PIN_CONTROL_MODE: - mask = led->id ? + mask = MAX8997_LED1_FLASH_PIN_MASK | + MAX8997_LED0_FLASH_PIN_MASK; + val = led->id ? MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK; led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS; break; case MAX8997_MOVIE_PIN_CONTROL_MODE: - mask = led->id ? + mask = MAX8997_LED1_MOVIE_PIN_MASK | + MAX8997_LED0_MOVIE_PIN_MASK; + val = led->id ? MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK; led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS; break; @@ -123,8 +89,8 @@ static void max8997_led_set_mode(struct max8997_led *led, } if (mask) { - ret = max8997_update_reg(client, - MAX8997_REG_LEN_CNTL, mask, mask); + ret = max8997_update_reg(client, MAX8997_REG_LEN_CNTL, val, + mask); if (ret) dev_err(led->iodev->dev, "failed to update register(%d)\n", ret); -- cgit v1.2.1 From b54cf35a7f656c61dd695509e8cf8cc7e1dc3e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= Date: Fri, 20 Jul 2012 16:49:06 +0800 Subject: LEDS: add BlinkM RGB LED driver, documentation and update MAINTAINERS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add driver for BlinkM device to drivers/leds/. Add entry to MAINTAINERS file. Add documentation in Documentation/leds/. A BlinkM is a RGB LED controlled through I2C. This driver implements an interface to the LED framework and another sysfs group to access the internal options of the BlinkM. rev6: Use module_i2c_driver(). rev5: Removed own workqueue in favor of events wq. rev4: Fixed comments by Bryan Wu. rev3: Fixed issues found by Jonathan Neuschäfer. (bryan.wu@canonical.com: remove 2 trailing whitespace) Signed-off-by: Jan-Simon Möller Signed-off-by: Bryan Wu --- drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-blinkm.c | 812 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 821 insertions(+) create mode 100644 drivers/leds/leds-blinkm.c (limited to 'drivers') diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index f028f0348e83..f0aaf415316d 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -430,6 +430,14 @@ config LEDS_OT200 This option enables support for the LEDs on the Bachmann OT200. Say Y to enable LEDs on the Bachmann OT200. +config LEDS_BLINKM + tristate "LED support for the BlinkM I2C RGB LED" + depends on LEDS_CLASS + depends on I2C + help + This option enables support for the BlinkM RGB LED connected + through I2C. Say Y to enable support for the BlinkM LED. + config LEDS_TRIGGERS bool "LED Trigger support" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 5eebd7bce4be..d94d18f8a4be 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -48,6 +48,7 @@ obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o obj-$(CONFIG_LEDS_RENESAS_TPU) += leds-renesas-tpu.o obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o obj-$(CONFIG_LEDS_LM3556) += leds-lm3556.o +obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c new file mode 100644 index 000000000000..5a9df43e5302 --- /dev/null +++ b/drivers/leds/leds-blinkm.c @@ -0,0 +1,812 @@ +/* + * leds-blinkm.c + * (c) Jan-Simon Möller (dl9pf@gmx.de) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Addresses to scan - BlinkM is on 0x09 by default*/ +static const unsigned short normal_i2c[] = { 0x09, I2C_CLIENT_END }; + +static int blinkm_transfer_hw(struct i2c_client *client, int cmd); +static int blinkm_test_run(struct i2c_client *client); + +struct blinkm_led { + struct i2c_client *i2c_client; + struct led_classdev led_cdev; + int id; + atomic_t active; +}; + +struct blinkm_work { + struct blinkm_led *blinkm_led; + struct work_struct work; +}; + +#define cdev_to_blmled(c) container_of(c, struct blinkm_led, led_cdev) +#define work_to_blmwork(c) container_of(c, struct blinkm_work, work) + +struct blinkm_data { + struct i2c_client *i2c_client; + struct mutex update_lock; + /* used for led class interface */ + struct blinkm_led blinkm_leds[3]; + /* used for "blinkm" sysfs interface */ + u8 red; /* color red */ + u8 green; /* color green */ + u8 blue; /* color blue */ + /* next values to use for transfer */ + u8 next_red; /* color red */ + u8 next_green; /* color green */ + u8 next_blue; /* color blue */ + /* internal use */ + u8 args[7]; /* set of args for transmission */ + u8 i2c_addr; /* i2c addr */ + u8 fw_ver; /* firmware version */ + /* used, but not from userspace */ + u8 hue; /* HSB hue */ + u8 saturation; /* HSB saturation */ + u8 brightness; /* HSB brightness */ + u8 next_hue; /* HSB hue */ + u8 next_saturation; /* HSB saturation */ + u8 next_brightness; /* HSB brightness */ + /* currently unused / todo */ + u8 fade_speed; /* fade speed 1 - 255 */ + s8 time_adjust; /* time adjust -128 - 127 */ + u8 fade:1; /* fade on = 1, off = 0 */ + u8 rand:1; /* rand fade mode on = 1 */ + u8 script_id; /* script ID */ + u8 script_repeats; /* repeats of script */ + u8 script_startline; /* line to start */ +}; + +/* Colors */ +#define RED 0 +#define GREEN 1 +#define BLUE 2 + +/* mapping command names to cmd chars - see datasheet */ +#define BLM_GO_RGB 0 +#define BLM_FADE_RGB 1 +#define BLM_FADE_HSB 2 +#define BLM_FADE_RAND_RGB 3 +#define BLM_FADE_RAND_HSB 4 +#define BLM_PLAY_SCRIPT 5 +#define BLM_STOP_SCRIPT 6 +#define BLM_SET_FADE_SPEED 7 +#define BLM_SET_TIME_ADJ 8 +#define BLM_GET_CUR_RGB 9 +#define BLM_WRITE_SCRIPT_LINE 10 +#define BLM_READ_SCRIPT_LINE 11 +#define BLM_SET_SCRIPT_LR 12 /* Length & Repeats */ +#define BLM_SET_ADDR 13 +#define BLM_GET_ADDR 14 +#define BLM_GET_FW_VER 15 +#define BLM_SET_STARTUP_PARAM 16 + +/* BlinkM Commands + * as extracted out of the datasheet: + * + * cmdchar = command (ascii) + * cmdbyte = command in hex + * nr_args = number of arguments (to send) + * nr_ret = number of return values (to read) + * dir = direction (0 = read, 1 = write, 2 = both) + * + */ +static const struct { + char cmdchar; + u8 cmdbyte; + u8 nr_args; + u8 nr_ret; + u8 dir:2; +} blinkm_cmds[17] = { + /* cmdchar, cmdbyte, nr_args, nr_ret, dir */ + { 'n', 0x6e, 3, 0, 1}, + { 'c', 0x63, 3, 0, 1}, + { 'h', 0x68, 3, 0, 1}, + { 'C', 0x43, 3, 0, 1}, + { 'H', 0x48, 3, 0, 1}, + { 'p', 0x70, 3, 0, 1}, + { 'o', 0x6f, 0, 0, 1}, + { 'f', 0x66, 1, 0, 1}, + { 't', 0x74, 1, 0, 1}, + { 'g', 0x67, 0, 3, 0}, + { 'W', 0x57, 7, 0, 1}, + { 'R', 0x52, 2, 5, 2}, + { 'L', 0x4c, 3, 0, 1}, + { 'A', 0x41, 4, 0, 1}, + { 'a', 0x61, 0, 1, 0}, + { 'Z', 0x5a, 0, 1, 0}, + { 'B', 0x42, 5, 0, 1}, +}; + +static ssize_t show_color_common(struct device *dev, char *buf, int color) +{ + struct i2c_client *client; + struct blinkm_data *data; + int ret; + + client = to_i2c_client(dev); + data = i2c_get_clientdata(client); + + ret = blinkm_transfer_hw(client, BLM_GET_CUR_RGB); + if (ret < 0) + return ret; + switch (color) { + case RED: + return scnprintf(buf, PAGE_SIZE, "%02X\n", data->red); + break; + case GREEN: + return scnprintf(buf, PAGE_SIZE, "%02X\n", data->green); + break; + case BLUE: + return scnprintf(buf, PAGE_SIZE, "%02X\n", data->blue); + break; + default: + return -EINVAL; + } + return -EINVAL; +} + +static int store_color_common(struct device *dev, const char *buf, int color) +{ + struct i2c_client *client; + struct blinkm_data *data; + int ret; + u8 value; + + client = to_i2c_client(dev); + data = i2c_get_clientdata(client); + + ret = kstrtou8(buf, 10, &value); + if (ret < 0) { + dev_err(dev, "BlinkM: value too large!\n"); + return ret; + } + + switch (color) { + case RED: + data->next_red = value; + break; + case GREEN: + data->next_green = value; + break; + case BLUE: + data->next_blue = value; + break; + default: + return -EINVAL; + } + + dev_dbg(dev, "next_red = %d, next_green = %d, next_blue = %d\n", + data->next_red, data->next_green, data->next_blue); + + /* if mode ... */ + ret = blinkm_transfer_hw(client, BLM_GO_RGB); + if (ret < 0) { + dev_err(dev, "BlinkM: can't set RGB\n"); + return ret; + } + return 0; +} + +static ssize_t show_red(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return show_color_common(dev, buf, RED); +} + +static ssize_t store_red(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + + ret = store_color_common(dev, buf, RED); + if (ret < 0) + return ret; + return count; +} + +static DEVICE_ATTR(red, S_IRUGO | S_IWUSR, show_red, store_red); + +static ssize_t show_green(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return show_color_common(dev, buf, GREEN); +} + +static ssize_t store_green(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + + int ret; + + ret = store_color_common(dev, buf, GREEN); + if (ret < 0) + return ret; + return count; +} + +static DEVICE_ATTR(green, S_IRUGO | S_IWUSR, show_green, store_green); + +static ssize_t show_blue(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return show_color_common(dev, buf, BLUE); +} + +static ssize_t store_blue(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + + ret = store_color_common(dev, buf, BLUE); + if (ret < 0) + return ret; + return count; +} + +static DEVICE_ATTR(blue, S_IRUGO | S_IWUSR, show_blue, store_blue); + +static ssize_t show_test(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return scnprintf(buf, PAGE_SIZE, + "#Write into test to start test sequence!#\n"); +} + +static ssize_t store_test(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + + struct i2c_client *client; + int ret; + client = to_i2c_client(dev); + + /*test */ + ret = blinkm_test_run(client); + if (ret < 0) + return ret; + + return count; +} + +static DEVICE_ATTR(test, S_IRUGO | S_IWUSR, show_test, store_test); + +/* TODO: HSB, fade, timeadj, script ... */ + +static struct attribute *blinkm_attrs[] = { + &dev_attr_red.attr, + &dev_attr_green.attr, + &dev_attr_blue.attr, + &dev_attr_test.attr, + NULL, +}; + +static struct attribute_group blinkm_group = { + .name = "blinkm", + .attrs = blinkm_attrs, +}; + +static int blinkm_write(struct i2c_client *client, int cmd, u8 *arg) +{ + int result; + int i; + int arglen = blinkm_cmds[cmd].nr_args; + /* write out cmd to blinkm - always / default step */ + result = i2c_smbus_write_byte(client, blinkm_cmds[cmd].cmdbyte); + if (result < 0) + return result; + /* no args to write out */ + if (arglen == 0) + return 0; + + for (i = 0; i < arglen; i++) { + /* repeat for arglen */ + result = i2c_smbus_write_byte(client, arg[i]); + if (result < 0) + return result; + } + return 0; +} + +static int blinkm_read(struct i2c_client *client, int cmd, u8 *arg) +{ + int result; + int i; + int retlen = blinkm_cmds[cmd].nr_ret; + for (i = 0; i < retlen; i++) { + /* repeat for retlen */ + result = i2c_smbus_read_byte(client); + if (result < 0) + return result; + arg[i] = result; + } + + return 0; +} + +static int blinkm_transfer_hw(struct i2c_client *client, int cmd) +{ + /* the protocol is simple but non-standard: + * e.g. cmd 'g' (= 0x67) for "get device address" + * - which defaults to 0x09 - would be the sequence: + * a) write 0x67 to the device (byte write) + * b) read the value (0x09) back right after (byte read) + * + * Watch out for "unfinished" sequences (i.e. not enough reads + * or writes after a command. It will make the blinkM misbehave. + * Sequence is key here. + */ + + /* args / return are in private data struct */ + struct blinkm_data *data = i2c_get_clientdata(client); + + /* We start hardware transfers which are not to be + * mixed with other commands. Aquire a lock now. */ + if (mutex_lock_interruptible(&data->update_lock) < 0) + return -EAGAIN; + + /* switch cmd - usually write before reads */ + switch (cmd) { + case BLM_FADE_RAND_RGB: + case BLM_GO_RGB: + case BLM_FADE_RGB: + data->args[0] = data->next_red; + data->args[1] = data->next_green; + data->args[2] = data->next_blue; + blinkm_write(client, cmd, data->args); + data->red = data->args[0]; + data->green = data->args[1]; + data->blue = data->args[2]; + break; + case BLM_FADE_HSB: + case BLM_FADE_RAND_HSB: + data->args[0] = data->next_hue; + data->args[1] = data->next_saturation; + data->args[2] = data->next_brightness; + blinkm_write(client, cmd, data->args); + data->hue = data->next_hue; + data->saturation = data->next_saturation; + data->brightness = data->next_brightness; + break; + case BLM_PLAY_SCRIPT: + data->args[0] = data->script_id; + data->args[1] = data->script_repeats; + data->args[2] = data->script_startline; + blinkm_write(client, cmd, data->args); + break; + case BLM_STOP_SCRIPT: + blinkm_write(client, cmd, NULL); + break; + case BLM_GET_CUR_RGB: + data->args[0] = data->red; + data->args[1] = data->green; + data->args[2] = data->blue; + blinkm_write(client, cmd, NULL); + blinkm_read(client, cmd, data->args); + data->red = data->args[0]; + data->green = data->args[1]; + data->blue = data->args[2]; + break; + case BLM_GET_ADDR: + data->args[0] = data->i2c_addr; + blinkm_write(client, cmd, NULL); + blinkm_read(client, cmd, data->args); + data->i2c_addr = data->args[0]; + break; + case BLM_SET_TIME_ADJ: + case BLM_SET_FADE_SPEED: + case BLM_READ_SCRIPT_LINE: + case BLM_WRITE_SCRIPT_LINE: + case BLM_SET_SCRIPT_LR: + case BLM_SET_ADDR: + case BLM_GET_FW_VER: + case BLM_SET_STARTUP_PARAM: + dev_err(&client->dev, + "BlinkM: cmd %d not implemented yet.\n", cmd); + break; + default: + dev_err(&client->dev, "BlinkM: unknown command %d\n", cmd); + mutex_unlock(&data->update_lock); + return -EINVAL; + } /* end switch(cmd) */ + + /* transfers done, unlock */ + mutex_unlock(&data->update_lock); + return 0; +} + +static void led_work(struct work_struct *work) +{ + int ret; + struct blinkm_led *led; + struct blinkm_data *data ; + struct blinkm_work *blm_work = work_to_blmwork(work); + + led = blm_work->blinkm_led; + data = i2c_get_clientdata(led->i2c_client); + ret = blinkm_transfer_hw(led->i2c_client, BLM_GO_RGB); + atomic_dec(&led->active); + dev_dbg(&led->i2c_client->dev, + "# DONE # next_red = %d, next_green = %d," + " next_blue = %d, active = %d\n", + data->next_red, data->next_green, + data->next_blue, atomic_read(&led->active)); + kfree(blm_work); +} + +static int blinkm_led_common_set(struct led_classdev *led_cdev, + enum led_brightness value, int color) +{ + /* led_brightness is 0, 127 or 255 - we just use it here as-is */ + struct blinkm_led *led = cdev_to_blmled(led_cdev); + struct blinkm_data *data = i2c_get_clientdata(led->i2c_client); + struct blinkm_work *bl_work = kzalloc(sizeof(struct blinkm_work), + GFP_ATOMIC); + + switch (color) { + case RED: + /* bail out if there's no change */ + if (data->next_red == (u8) value) + return 0; + /* we assume a quite fast sequence here ([off]->on->off) + * think of network led trigger - we cannot blink that fast, so + * in case we already have a off->on->off transition queued up, + * we refuse to queue up more. + * Revisit: fast-changing brightness. */ + if (atomic_read(&led->active) > 1) + return 0; + data->next_red = (u8) value; + break; + case GREEN: + /* bail out if there's no change */ + if (data->next_green == (u8) value) + return 0; + /* we assume a quite fast sequence here ([off]->on->off) + * Revisit: fast-changing brightness. */ + if (atomic_read(&led->active) > 1) + return 0; + data->next_green = (u8) value; + break; + case BLUE: + /* bail out if there's no change */ + if (data->next_blue == (u8) value) + return 0; + /* we assume a quite fast sequence here ([off]->on->off) + * Revisit: fast-changing brightness. */ + if (atomic_read(&led->active) > 1) + return 0; + data->next_blue = (u8) value; + break; + + default: + dev_err(&led->i2c_client->dev, "BlinkM: unknown color.\n"); + return -EINVAL; + } + + atomic_inc(&led->active); + dev_dbg(&led->i2c_client->dev, + "#TO_SCHED# next_red = %d, next_green = %d," + " next_blue = %d, active = %d\n", + data->next_red, data->next_green, + data->next_blue, atomic_read(&led->active)); + + /* a fresh work _item_ for each change */ + bl_work->blinkm_led = led; + INIT_WORK(&bl_work->work, led_work); + /* queue work in own queue for easy sync on exit*/ + schedule_work(&bl_work->work); + + return 0; +} + +static void blinkm_led_red_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + blinkm_led_common_set(led_cdev, value, RED); +} + +static void blinkm_led_green_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + blinkm_led_common_set(led_cdev, value, GREEN); +} + +static void blinkm_led_blue_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + blinkm_led_common_set(led_cdev, value, BLUE); +} + +static void blinkm_init_hw(struct i2c_client *client) +{ + int ret; + ret = blinkm_transfer_hw(client, BLM_STOP_SCRIPT); + ret = blinkm_transfer_hw(client, BLM_GO_RGB); +} + +static int blinkm_test_run(struct i2c_client *client) +{ + int ret; + struct blinkm_data *data = i2c_get_clientdata(client); + + data->next_red = 0x01; + data->next_green = 0x05; + data->next_blue = 0x10; + ret = blinkm_transfer_hw(client, BLM_GO_RGB); + if (ret < 0) + return ret; + msleep(2000); + + data->next_red = 0x25; + data->next_green = 0x10; + data->next_blue = 0x31; + ret = blinkm_transfer_hw(client, BLM_FADE_RGB); + if (ret < 0) + return ret; + msleep(2000); + + data->next_hue = 0x50; + data->next_saturation = 0x10; + data->next_brightness = 0x20; + ret = blinkm_transfer_hw(client, BLM_FADE_HSB); + if (ret < 0) + return ret; + msleep(2000); + + return 0; +} + +/* Return 0 if detection is successful, -ENODEV otherwise */ +static int blinkm_detect(struct i2c_client *client, struct i2c_board_info *info) +{ + struct i2c_adapter *adapter = client->adapter; + int ret; + int count = 99; + u8 tmpargs[7]; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA + | I2C_FUNC_SMBUS_WORD_DATA + | I2C_FUNC_SMBUS_WRITE_BYTE)) + return -ENODEV; + + /* Now, we do the remaining detection. Simple for now. */ + /* We might need more guards to protect other i2c slaves */ + + /* make sure the blinkM is balanced (read/writes) */ + while (count > 0) { + ret = blinkm_write(client, BLM_GET_ADDR, NULL); + usleep_range(5000, 10000); + ret = blinkm_read(client, BLM_GET_ADDR, tmpargs); + usleep_range(5000, 10000); + if (tmpargs[0] == 0x09) + count = 0; + count--; + } + + /* Step 1: Read BlinkM address back - cmd_char 'a' */ + ret = blinkm_write(client, BLM_GET_ADDR, NULL); + if (ret < 0) + return -ENODEV; + usleep_range(20000, 30000); /* allow a small delay */ + ret = blinkm_read(client, BLM_GET_ADDR, tmpargs); + if (ret < 0) + return -ENODEV; + + if (tmpargs[0] != 0x09) { + dev_err(&client->dev, "enodev DEV ADDR = 0x%02X\n", tmpargs[0]); + return -ENODEV; + } + + strlcpy(info->type, "blinkm", I2C_NAME_SIZE); + return 0; +} + +static int __devinit blinkm_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct blinkm_data *data; + struct blinkm_led *led[3]; + int err, i; + char blinkm_led_name[28]; + + data = devm_kzalloc(&client->dev, + sizeof(struct blinkm_data), GFP_KERNEL); + if (!data) { + err = -ENOMEM; + goto exit; + } + + data->i2c_addr = 0x09; + data->i2c_addr = 0x08; + /* i2c addr - use fake addr of 0x08 initially (real is 0x09) */ + data->fw_ver = 0xfe; + /* firmware version - use fake until we read real value + * (currently broken - BlinkM confused!) */ + data->script_id = 0x01; + data->i2c_client = client; + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + + /* Register sysfs hooks */ + err = sysfs_create_group(&client->dev.kobj, &blinkm_group); + if (err < 0) { + dev_err(&client->dev, "couldn't register sysfs group\n"); + goto exit; + } + + for (i = 0; i < 3; i++) { + /* RED = 0, GREEN = 1, BLUE = 2 */ + led[i] = &data->blinkm_leds[i]; + led[i]->i2c_client = client; + led[i]->id = i; + led[i]->led_cdev.max_brightness = 255; + led[i]->led_cdev.flags = LED_CORE_SUSPENDRESUME; + atomic_set(&led[i]->active, 0); + switch (i) { + case RED: + snprintf(blinkm_led_name, sizeof(blinkm_led_name), + "blinkm-%d-%d-red", + client->adapter->nr, + client->addr); + led[i]->led_cdev.name = blinkm_led_name; + led[i]->led_cdev.brightness_set = blinkm_led_red_set; + err = led_classdev_register(&client->dev, + &led[i]->led_cdev); + if (err < 0) { + dev_err(&client->dev, + "couldn't register LED %s\n", + led[i]->led_cdev.name); + goto failred; + } + break; + case GREEN: + snprintf(blinkm_led_name, sizeof(blinkm_led_name), + "blinkm-%d-%d-green", + client->adapter->nr, + client->addr); + led[i]->led_cdev.name = blinkm_led_name; + led[i]->led_cdev.brightness_set = blinkm_led_green_set; + err = led_classdev_register(&client->dev, + &led[i]->led_cdev); + if (err < 0) { + dev_err(&client->dev, + "couldn't register LED %s\n", + led[i]->led_cdev.name); + goto failgreen; + } + break; + case BLUE: + snprintf(blinkm_led_name, sizeof(blinkm_led_name), + "blinkm-%d-%d-blue", + client->adapter->nr, + client->addr); + led[i]->led_cdev.name = blinkm_led_name; + led[i]->led_cdev.brightness_set = blinkm_led_blue_set; + err = led_classdev_register(&client->dev, + &led[i]->led_cdev); + if (err < 0) { + dev_err(&client->dev, + "couldn't register LED %s\n", + led[i]->led_cdev.name); + goto failblue; + } + break; + } /* end switch */ + } /* end for */ + + /* Initialize the blinkm */ + blinkm_init_hw(client); + + return 0; + +failblue: + led_classdev_unregister(&led[GREEN]->led_cdev); + +failgreen: + led_classdev_unregister(&led[RED]->led_cdev); + +failred: + sysfs_remove_group(&client->dev.kobj, &blinkm_group); +exit: + return err; +} + +static int __devexit blinkm_remove(struct i2c_client *client) +{ + struct blinkm_data *data = i2c_get_clientdata(client); + int ret = 0; + int i; + + /* make sure no workqueue entries are pending */ + for (i = 0; i < 3; i++) { + flush_scheduled_work(); + led_classdev_unregister(&data->blinkm_leds[i].led_cdev); + } + + /* reset rgb */ + data->next_red = 0x00; + data->next_green = 0x00; + data->next_blue = 0x00; + ret = blinkm_transfer_hw(client, BLM_FADE_RGB); + if (ret < 0) + dev_err(&client->dev, "Failure in blinkm_remove ignored. Continuing.\n"); + + /* reset hsb */ + data->next_hue = 0x00; + data->next_saturation = 0x00; + data->next_brightness = 0x00; + ret = blinkm_transfer_hw(client, BLM_FADE_HSB); + if (ret < 0) + dev_err(&client->dev, "Failure in blinkm_remove ignored. Continuing.\n"); + + /* red fade to off */ + data->next_red = 0xff; + ret = blinkm_transfer_hw(client, BLM_GO_RGB); + if (ret < 0) + dev_err(&client->dev, "Failure in blinkm_remove ignored. Continuing.\n"); + + /* off */ + data->next_red = 0x00; + ret = blinkm_transfer_hw(client, BLM_FADE_RGB); + if (ret < 0) + dev_err(&client->dev, "Failure in blinkm_remove ignored. Continuing.\n"); + + sysfs_remove_group(&client->dev.kobj, &blinkm_group); + return 0; +} + +static const struct i2c_device_id blinkm_id[] = { + {"blinkm", 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, blinkm_id); + + /* This is the driver that will be inserted */ +static struct i2c_driver blinkm_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "blinkm", + }, + .probe = blinkm_probe, + .remove = __devexit_p(blinkm_remove), + .id_table = blinkm_id, + .detect = blinkm_detect, + .address_list = normal_i2c, +}; + +module_i2c_driver(blinkm_driver); + +MODULE_AUTHOR("Jan-Simon Moeller "); +MODULE_DESCRIPTION("BlinkM RGB LED driver"); +MODULE_LICENSE("GPL"); + -- cgit v1.2.1 From eb80411b54fde031e9a8b368ff7b32c774ecfc5c Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Fri, 20 Jul 2012 16:43:59 +0800 Subject: leds: add new lp8788 led driver TI LP8788 PMU has the current sink as the keyboard led driver. The brightness is controlled by the i2c commands. Configurable parameters can be defined in the platform side. Patch v2. (a) use workqueue on changing the brightness (b) use mutex_lock/unlock when the brightness is set and the led block of lp8788 device is enabled (c) remove err_dev on _probe() : just return as returned value if any errors (d) replace module_init/exit() with module_platform_driver() (e) add led configuration structure and loading them by default if platform data is null Signed-off-by: Milo(Woogyom) Kim Acked-by: Mark Brown Signed-off-by: Bryan Wu --- drivers/leds/Kconfig | 7 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-lp8788.c | 192 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 drivers/leds/leds-lp8788.c (limited to 'drivers') diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index f0aaf415316d..c96bbaadeebd 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -200,6 +200,13 @@ config LEDS_LP5523 Driver provides direct control via LED class and interface for programming the engines. +config LEDS_LP8788 + tristate "LED support for the TI LP8788 PMIC" + depends on LEDS_CLASS + depends on MFD_LP8788 + help + This option enables support for the Keyboard LEDs on the LP8788 PMIC. + config LEDS_CLEVO_MAIL tristate "Mail LED on Clevo notebook" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index d94d18f8a4be..a4429a9217bc 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o +obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o diff --git a/drivers/leds/leds-lp8788.c b/drivers/leds/leds-lp8788.c new file mode 100644 index 000000000000..574b49f79093 --- /dev/null +++ b/drivers/leds/leds-lp8788.c @@ -0,0 +1,192 @@ +/* + * TI LP8788 MFD - keyled driver + * + * Copyright 2012 Texas Instruments + * + * Author: Milo(Woogyom) Kim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_BRIGHTNESS LP8788_ISINK_MAX_PWM +#define DEFAULT_LED_NAME "keyboard-backlight" + +struct lp8788_led { + struct lp8788 *lp; + struct mutex lock; + struct work_struct work; + struct led_classdev led_dev; + enum lp8788_isink_number isink_num; + enum led_brightness brightness; + int on; +}; + +struct lp8788_led_config { + enum lp8788_isink_scale scale; + enum lp8788_isink_number num; + int iout; +}; + +static struct lp8788_led_config default_led_config = { + .scale = LP8788_ISINK_SCALE_100mA, + .num = LP8788_ISINK_3, + .iout = 0, +}; + +static int lp8788_led_init_device(struct lp8788_led *led, + struct lp8788_led_platform_data *pdata) +{ + struct lp8788_led_config *cfg = &default_led_config; + u8 addr, mask, val; + int ret; + + if (pdata) { + cfg->scale = pdata->scale; + cfg->num = pdata->num; + cfg->iout = pdata->iout_code; + } + + led->isink_num = cfg->num; + + /* scale configuration */ + addr = LP8788_ISINK_CTRL; + mask = 1 << (cfg->num + LP8788_ISINK_SCALE_OFFSET); + val = cfg->scale << cfg->num; + ret = lp8788_update_bits(led->lp, addr, mask, val); + if (ret) + return ret; + + /* current configuration */ + addr = lp8788_iout_addr[cfg->num]; + mask = lp8788_iout_mask[cfg->num]; + val = cfg->iout; + + return lp8788_update_bits(led->lp, addr, mask, val); +} + +static void lp8788_led_enable(struct lp8788_led *led, + enum lp8788_isink_number num, int on) +{ + u8 mask = 1 << num; + u8 val = on << num; + + if (lp8788_update_bits(led->lp, LP8788_ISINK_CTRL, mask, val)) + return; + + led->on = on; +} + +static void lp8788_led_work(struct work_struct *work) +{ + struct lp8788_led *led = container_of(work, struct lp8788_led, work); + enum lp8788_isink_number num = led->isink_num; + int enable; + u8 val = led->brightness; + + mutex_lock(&led->lock); + + switch (num) { + case LP8788_ISINK_1: + case LP8788_ISINK_2: + case LP8788_ISINK_3: + lp8788_write_byte(led->lp, lp8788_pwm_addr[num], val); + break; + default: + return; + } + + enable = (val > 0) ? 1 : 0; + if (enable != led->on) + lp8788_led_enable(led, num, enable); + + mutex_unlock(&led->lock); +} + +static void lp8788_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brt_val) +{ + struct lp8788_led *led = + container_of(led_cdev, struct lp8788_led, led_dev); + + led->brightness = brt_val; + schedule_work(&led->work); +} + +static __devinit int lp8788_led_probe(struct platform_device *pdev) +{ + struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); + struct lp8788_led_platform_data *led_pdata; + struct lp8788_led *led; + int ret; + + led = devm_kzalloc(lp->dev, sizeof(struct lp8788_led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + led->lp = lp; + led->led_dev.max_brightness = MAX_BRIGHTNESS; + led->led_dev.brightness_set = lp8788_brightness_set; + + led_pdata = lp->pdata ? lp->pdata->led_pdata : NULL; + + if (!led_pdata || !led_pdata->name) + led->led_dev.name = DEFAULT_LED_NAME; + else + led->led_dev.name = led_pdata->name; + + mutex_init(&led->lock); + INIT_WORK(&led->work, lp8788_led_work); + + platform_set_drvdata(pdev, led); + + ret = lp8788_led_init_device(led, led_pdata); + if (ret) { + dev_err(lp->dev, "led init device err: %d\n", ret); + return ret; + } + + ret = led_classdev_register(lp->dev, &led->led_dev); + if (ret) { + dev_err(lp->dev, "led register err: %d\n", ret); + return ret; + } + + return 0; +} + +static int __devexit lp8788_led_remove(struct platform_device *pdev) +{ + struct lp8788_led *led = platform_get_drvdata(pdev); + + led_classdev_unregister(&led->led_dev); + flush_work_sync(&led->work); + + return 0; +} + +static struct platform_driver lp8788_led_driver = { + .probe = lp8788_led_probe, + .remove = __devexit_p(lp8788_led_remove), + .driver = { + .name = LP8788_DEV_KEYLED, + .owner = THIS_MODULE, + }, +}; +module_platform_driver(lp8788_led_driver); + +MODULE_DESCRIPTION("Texas Instruments LP8788 Keyboard LED Driver"); +MODULE_AUTHOR("Milo Kim"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:lp8788-keyled"); -- cgit v1.2.1 From 4d8729a139782d4facc98b7bd7d87c7d10c128b0 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 26 Jul 2012 15:59:51 +0800 Subject: LEDS: memory leak in blinkm_led_common_set() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This can return without freeing the bl_work struct. Also there was no check for allocation failure. Signed-off-by: Dan Carpenter Acked-by: Jan-Simon Möller Signed-off-by: Bryan Wu --- drivers/leds/leds-blinkm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c index 5a9df43e5302..ae6ad6331f23 100644 --- a/drivers/leds/leds-blinkm.c +++ b/drivers/leds/leds-blinkm.c @@ -468,8 +468,7 @@ static int blinkm_led_common_set(struct led_classdev *led_cdev, /* led_brightness is 0, 127 or 255 - we just use it here as-is */ struct blinkm_led *led = cdev_to_blmled(led_cdev); struct blinkm_data *data = i2c_get_clientdata(led->i2c_client); - struct blinkm_work *bl_work = kzalloc(sizeof(struct blinkm_work), - GFP_ATOMIC); + struct blinkm_work *bl_work; switch (color) { case RED: @@ -511,6 +510,10 @@ static int blinkm_led_common_set(struct led_classdev *led_cdev, return -EINVAL; } + bl_work = kzalloc(sizeof(*bl_work), GFP_ATOMIC); + if (!bl_work) + return -ENOMEM; + atomic_inc(&led->active); dev_dbg(&led->i2c_client->dev, "#TO_SCHED# next_red = %d, next_green = %d," -- cgit v1.2.1 From 18d4a06f9bb013737b9c21921b15033afb0198d9 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 26 Jul 2012 16:00:25 +0800 Subject: LEDS: propagate error codes in blinkm_detect() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the error codes from the lower levels instead of -ENODEV. Signed-off-by: Dan Carpenter Acked-by: Jan-Simon Möller Signed-off-by: Bryan Wu --- drivers/leds/leds-blinkm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c index ae6ad6331f23..f7c3d7f1ec52 100644 --- a/drivers/leds/leds-blinkm.c +++ b/drivers/leds/leds-blinkm.c @@ -617,11 +617,11 @@ static int blinkm_detect(struct i2c_client *client, struct i2c_board_info *info) /* Step 1: Read BlinkM address back - cmd_char 'a' */ ret = blinkm_write(client, BLM_GET_ADDR, NULL); if (ret < 0) - return -ENODEV; + return ret; usleep_range(20000, 30000); /* allow a small delay */ ret = blinkm_read(client, BLM_GET_ADDR, tmpargs); if (ret < 0) - return -ENODEV; + return ret; if (tmpargs[0] != 0x09) { dev_err(&client->dev, "enodev DEV ADDR = 0x%02X\n", tmpargs[0]); -- cgit v1.2.1 From d45bb11616c94c76c6e40960a120c0687b708a2e Mon Sep 17 00:00:00 2001 From: Devendra Naga Date: Fri, 27 Jul 2012 02:00:31 +0800 Subject: leds-lp8788: forgotten unlock at lp8788_led_work at default case of switch we return with out unlocking the mutex. Signed-off-by: Devendra Naga Signed-off-by: Bryan Wu --- drivers/leds/leds-lp8788.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/leds/leds-lp8788.c b/drivers/leds/leds-lp8788.c index 574b49f79093..53bd136f1ef0 100644 --- a/drivers/leds/leds-lp8788.c +++ b/drivers/leds/leds-lp8788.c @@ -104,6 +104,7 @@ static void lp8788_led_work(struct work_struct *work) lp8788_write_byte(led->lp, lp8788_pwm_addr[num], val); break; default: + mutex_unlock(&led->lock); return; } -- cgit v1.2.1