Commit 2dbfca5a authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds

Pull LED subsystem update from Bryan Wu:
 "We got some cleanup and driver for LP8860 as well as some patches for
  LED Flash Class"

* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds:
  leds: lp8860: Fix module dependency
  leds: lp8860: Introduce TI lp8860 4 channel LED driver
  leds: Add support for setting brightness in a synchronous way
  leds: implement sysfs interface locking mechanism
  leds: syscon: handle multiple syscon instances
  leds: delete copy/paste mistake
  leds: regulator: Convert to devm_regulator_get_exclusive
parents dab363f9 2969bb18
* Texas Instruments - lp8860 4-Channel LED Driver
The LP8860-Q1 is an high-efficiency LED
driver with boost controller. It has 4 high-precision
current sinks that can be controlled by a PWM input
signal, a SPI/I2C master, or both.
Required properties:
- compatible:
"ti,lp8860"
- reg - I2C slave address
- label - Used for naming LEDs
Optional properties:
- enable-gpio - gpio pin to enable/disable the device.
- supply - "vled" - LED supply
Example:
leds: leds@6 {
compatible = "ti,lp8860";
reg = <0x2d>;
label = "display_cluster";
enable-gpio = <&gpio1 28 GPIO_ACTIVE_HIGH>;
vled-supply = <&vbatt>;
}
For more product information please see the link below:
http://www.ti.com/product/lp8860-q1
...@@ -250,6 +250,17 @@ config LEDS_LP8788 ...@@ -250,6 +250,17 @@ config LEDS_LP8788
help help
This option enables support for the Keyboard LEDs on the LP8788 PMIC. This option enables support for the Keyboard LEDs on the LP8788 PMIC.
config LEDS_LP8860
tristate "LED support for the TI LP8860 4 channel LED driver"
depends on LEDS_CLASS && I2C
select REGMAP_I2C
help
If you say yes here you get support for the TI LP8860 4 channel
LED driver.
This option enables support for the display cluster LEDs
on the LP8860 4 channel LED driver using the I2C communication
bus.
config LEDS_CLEVO_MAIL config LEDS_CLEVO_MAIL
tristate "Mail LED on Clevo notebook" tristate "Mail LED on Clevo notebook"
depends on LEDS_CLASS depends on LEDS_CLASS
......
...@@ -28,6 +28,7 @@ obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o ...@@ -28,6 +28,7 @@ obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o
obj-$(CONFIG_LEDS_LP5562) += leds-lp5562.o obj-$(CONFIG_LEDS_LP5562) += leds-lp5562.o
obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o obj-$(CONFIG_LEDS_LP8501) += leds-lp8501.o
obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o obj-$(CONFIG_LEDS_LP8788) += leds-lp8788.o
obj-$(CONFIG_LEDS_LP8860) += leds-lp8860.o
obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o
obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o
......
...@@ -40,17 +40,27 @@ static ssize_t brightness_store(struct device *dev, ...@@ -40,17 +40,27 @@ static ssize_t brightness_store(struct device *dev,
{ {
struct led_classdev *led_cdev = dev_get_drvdata(dev); struct led_classdev *led_cdev = dev_get_drvdata(dev);
unsigned long state; unsigned long state;
ssize_t ret = -EINVAL; ssize_t ret;
mutex_lock(&led_cdev->led_access);
if (led_sysfs_is_disabled(led_cdev)) {
ret = -EBUSY;
goto unlock;
}
ret = kstrtoul(buf, 10, &state); ret = kstrtoul(buf, 10, &state);
if (ret) if (ret)
return ret; goto unlock;
if (state == LED_OFF) if (state == LED_OFF)
led_trigger_remove(led_cdev); led_trigger_remove(led_cdev);
__led_set_brightness(led_cdev, state); led_set_brightness(led_cdev, state);
return size; ret = size;
unlock:
mutex_unlock(&led_cdev->led_access);
return ret;
} }
static DEVICE_ATTR_RW(brightness); static DEVICE_ATTR_RW(brightness);
...@@ -99,7 +109,7 @@ static void led_timer_function(unsigned long data) ...@@ -99,7 +109,7 @@ static void led_timer_function(unsigned long data)
unsigned long delay; unsigned long delay;
if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) { if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) {
__led_set_brightness(led_cdev, LED_OFF); led_set_brightness_async(led_cdev, LED_OFF);
return; return;
} }
...@@ -122,7 +132,7 @@ static void led_timer_function(unsigned long data) ...@@ -122,7 +132,7 @@ static void led_timer_function(unsigned long data)
delay = led_cdev->blink_delay_off; delay = led_cdev->blink_delay_off;
} }
__led_set_brightness(led_cdev, brightness); led_set_brightness_async(led_cdev, brightness);
/* Return in next iteration if led is in one-shot mode and we are in /* 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 + * the final blink state so that the led is toggled each delay_on +
...@@ -148,7 +158,7 @@ static void set_brightness_delayed(struct work_struct *ws) ...@@ -148,7 +158,7 @@ static void set_brightness_delayed(struct work_struct *ws)
led_stop_software_blink(led_cdev); led_stop_software_blink(led_cdev);
__led_set_brightness(led_cdev, led_cdev->delayed_set_value); led_set_brightness_async(led_cdev, led_cdev->delayed_set_value);
} }
/** /**
...@@ -214,6 +224,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) ...@@ -214,6 +224,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
#ifdef CONFIG_LEDS_TRIGGERS #ifdef CONFIG_LEDS_TRIGGERS
init_rwsem(&led_cdev->trigger_lock); init_rwsem(&led_cdev->trigger_lock);
#endif #endif
mutex_init(&led_cdev->led_access);
/* add to the list of leds */ /* add to the list of leds */
down_write(&leds_list_lock); down_write(&leds_list_lock);
list_add_tail(&led_cdev->node, &leds_list); list_add_tail(&led_cdev->node, &leds_list);
...@@ -222,6 +233,8 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) ...@@ -222,6 +233,8 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
if (!led_cdev->max_brightness) if (!led_cdev->max_brightness)
led_cdev->max_brightness = LED_FULL; led_cdev->max_brightness = LED_FULL;
led_cdev->flags |= SET_BRIGHTNESS_ASYNC;
led_update_brightness(led_cdev); led_update_brightness(led_cdev);
INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed); INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed);
...@@ -267,6 +280,8 @@ void led_classdev_unregister(struct led_classdev *led_cdev) ...@@ -267,6 +280,8 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
down_write(&leds_list_lock); down_write(&leds_list_lock);
list_del(&led_cdev->node); list_del(&led_cdev->node);
up_write(&leds_list_lock); up_write(&leds_list_lock);
mutex_destroy(&led_cdev->led_access);
} }
EXPORT_SYMBOL_GPL(led_classdev_unregister); EXPORT_SYMBOL_GPL(led_classdev_unregister);
......
...@@ -42,13 +42,13 @@ static void led_set_software_blink(struct led_classdev *led_cdev, ...@@ -42,13 +42,13 @@ static void led_set_software_blink(struct led_classdev *led_cdev,
/* never on - just set to off */ /* never on - just set to off */
if (!delay_on) { if (!delay_on) {
__led_set_brightness(led_cdev, LED_OFF); led_set_brightness_async(led_cdev, LED_OFF);
return; return;
} }
/* never off - just set to brightness */ /* never off - just set to brightness */
if (!delay_off) { if (!delay_off) {
__led_set_brightness(led_cdev, led_cdev->blink_brightness); led_set_brightness_async(led_cdev, led_cdev->blink_brightness);
return; return;
} }
...@@ -117,6 +117,8 @@ EXPORT_SYMBOL_GPL(led_stop_software_blink); ...@@ -117,6 +117,8 @@ EXPORT_SYMBOL_GPL(led_stop_software_blink);
void led_set_brightness(struct led_classdev *led_cdev, void led_set_brightness(struct led_classdev *led_cdev,
enum led_brightness brightness) enum led_brightness brightness)
{ {
int ret = 0;
/* delay brightness setting if need to stop soft-blink timer */ /* delay brightness setting if need to stop soft-blink timer */
if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) { if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) {
led_cdev->delayed_set_value = brightness; led_cdev->delayed_set_value = brightness;
...@@ -124,7 +126,17 @@ void led_set_brightness(struct led_classdev *led_cdev, ...@@ -124,7 +126,17 @@ void led_set_brightness(struct led_classdev *led_cdev,
return; return;
} }
__led_set_brightness(led_cdev, brightness); if (led_cdev->flags & SET_BRIGHTNESS_ASYNC) {
led_set_brightness_async(led_cdev, brightness);
return;
} else if (led_cdev->flags & SET_BRIGHTNESS_SYNC)
ret = led_set_brightness_sync(led_cdev, brightness);
else
ret = -EINVAL;
if (ret < 0)
dev_dbg(led_cdev->dev, "Setting LED brightness failed (%d)\n",
ret);
} }
EXPORT_SYMBOL(led_set_brightness); EXPORT_SYMBOL(led_set_brightness);
...@@ -143,3 +155,21 @@ int led_update_brightness(struct led_classdev *led_cdev) ...@@ -143,3 +155,21 @@ int led_update_brightness(struct led_classdev *led_cdev)
return ret; return ret;
} }
EXPORT_SYMBOL(led_update_brightness); EXPORT_SYMBOL(led_update_brightness);
/* Caller must ensure led_cdev->led_access held */
void led_sysfs_disable(struct led_classdev *led_cdev)
{
lockdep_assert_held(&led_cdev->led_access);
led_cdev->flags |= LED_SYSFS_DISABLE;
}
EXPORT_SYMBOL_GPL(led_sysfs_disable);
/* Caller must ensure led_cdev->led_access held */
void led_sysfs_enable(struct led_classdev *led_cdev)
{
lockdep_assert_held(&led_cdev->led_access);
led_cdev->flags &= ~LED_SYSFS_DISABLE;
}
EXPORT_SYMBOL_GPL(led_sysfs_enable);
...@@ -37,6 +37,14 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, ...@@ -37,6 +37,14 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
char trigger_name[TRIG_NAME_MAX]; char trigger_name[TRIG_NAME_MAX];
struct led_trigger *trig; struct led_trigger *trig;
size_t len; size_t len;
int ret = count;
mutex_lock(&led_cdev->led_access);
if (led_sysfs_is_disabled(led_cdev)) {
ret = -EBUSY;
goto unlock;
}
trigger_name[sizeof(trigger_name) - 1] = '\0'; trigger_name[sizeof(trigger_name) - 1] = '\0';
strncpy(trigger_name, buf, sizeof(trigger_name) - 1); strncpy(trigger_name, buf, sizeof(trigger_name) - 1);
...@@ -47,7 +55,7 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, ...@@ -47,7 +55,7 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
if (!strcmp(trigger_name, "none")) { if (!strcmp(trigger_name, "none")) {
led_trigger_remove(led_cdev); led_trigger_remove(led_cdev);
return count; goto unlock;
} }
down_read(&triggers_list_lock); down_read(&triggers_list_lock);
...@@ -58,12 +66,14 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, ...@@ -58,12 +66,14 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
up_write(&led_cdev->trigger_lock); up_write(&led_cdev->trigger_lock);
up_read(&triggers_list_lock); up_read(&triggers_list_lock);
return count; goto unlock;
} }
} }
up_read(&triggers_list_lock); up_read(&triggers_list_lock);
return -EINVAL; unlock:
mutex_unlock(&led_cdev->led_access);
return ret;
} }
EXPORT_SYMBOL_GPL(led_trigger_store); EXPORT_SYMBOL_GPL(led_trigger_store);
......
This diff is collapsed.
...@@ -153,24 +153,21 @@ static int regulator_led_probe(struct platform_device *pdev) ...@@ -153,24 +153,21 @@ static int regulator_led_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
vcc = regulator_get_exclusive(&pdev->dev, "vled"); vcc = devm_regulator_get_exclusive(&pdev->dev, "vled");
if (IS_ERR(vcc)) { if (IS_ERR(vcc)) {
dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name); dev_err(&pdev->dev, "Cannot get vcc for %s\n", pdata->name);
return PTR_ERR(vcc); return PTR_ERR(vcc);
} }
led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
if (led == NULL) { if (led == NULL)
ret = -ENOMEM; return -ENOMEM;
goto err_vcc;
}
led->cdev.max_brightness = led_regulator_get_max_brightness(vcc); led->cdev.max_brightness = led_regulator_get_max_brightness(vcc);
if (pdata->brightness > led->cdev.max_brightness) { if (pdata->brightness > led->cdev.max_brightness) {
dev_err(&pdev->dev, "Invalid default brightness %d\n", dev_err(&pdev->dev, "Invalid default brightness %d\n",
pdata->brightness); pdata->brightness);
ret = -EINVAL; return -EINVAL;
goto err_vcc;
} }
led->value = pdata->brightness; led->value = pdata->brightness;
...@@ -191,7 +188,7 @@ static int regulator_led_probe(struct platform_device *pdev) ...@@ -191,7 +188,7 @@ static int regulator_led_probe(struct platform_device *pdev)
ret = led_classdev_register(&pdev->dev, &led->cdev); ret = led_classdev_register(&pdev->dev, &led->cdev);
if (ret < 0) { if (ret < 0) {
cancel_work_sync(&led->work); cancel_work_sync(&led->work);
goto err_vcc; return ret;
} }
/* to expose the default value to userspace */ /* to expose the default value to userspace */
...@@ -201,10 +198,6 @@ static int regulator_led_probe(struct platform_device *pdev) ...@@ -201,10 +198,6 @@ static int regulator_led_probe(struct platform_device *pdev)
regulator_led_set_value(led); regulator_led_set_value(led);
return 0; return 0;
err_vcc:
regulator_put(vcc);
return ret;
} }
static int regulator_led_remove(struct platform_device *pdev) static int regulator_led_remove(struct platform_device *pdev)
...@@ -214,7 +207,6 @@ static int regulator_led_remove(struct platform_device *pdev) ...@@ -214,7 +207,6 @@ static int regulator_led_remove(struct platform_device *pdev)
led_classdev_unregister(&led->cdev); led_classdev_unregister(&led->cdev);
cancel_work_sync(&led->work); cancel_work_sync(&led->work);
regulator_led_disable(led); regulator_led_disable(led);
regulator_put(led->vcc);
return 0; return 0;
} }
......
...@@ -18,10 +18,6 @@ ...@@ -18,10 +18,6 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
*
* This driver provides system reboot functionality for APM X-Gene SoC.
* For system shutdown, this is board specify. If a board designer
* implements GPIO shutdown, use the gpio-poweroff.c driver.
*/ */
#include <linux/io.h> #include <linux/io.h>
#include <linux/of_device.h> #include <linux/of_device.h>
...@@ -70,39 +66,13 @@ static void syscon_led_set(struct led_classdev *led_cdev, ...@@ -70,39 +66,13 @@ static void syscon_led_set(struct led_classdev *led_cdev,
dev_err(sled->cdev.dev, "error updating LED status\n"); dev_err(sled->cdev.dev, "error updating LED status\n");
} }
static const struct of_device_id syscon_match[] = { static int __init syscon_leds_spawn(struct device_node *np,
{ .compatible = "syscon", }, struct device *dev,
{}, struct regmap *map)
};
static int __init syscon_leds_init(void)
{ {
const struct of_device_id *devid;
struct device_node *np;
struct device_node *child; struct device_node *child;
struct regmap *map;
struct platform_device *pdev;
struct device *dev;
int ret; int ret;
np = of_find_matching_node_and_match(NULL, syscon_match,
&devid);
if (!np)
return -ENODEV;
map = syscon_node_to_regmap(np);
if (IS_ERR(map))
return PTR_ERR(map);
/*
* If the map is there, the device should be there, we allocate
* memory on the syscon device's behalf here.
*/
pdev = of_find_device_by_node(np);
if (!pdev)
return -ENODEV;
dev = &pdev->dev;
for_each_available_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
struct syscon_led *sled; struct syscon_led *sled;
const char *state; const char *state;
...@@ -150,7 +120,6 @@ static int __init syscon_leds_init(void) ...@@ -150,7 +120,6 @@ static int __init syscon_leds_init(void)
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
} }
sled->cdev.brightness_set = syscon_led_set; sled->cdev.brightness_set = syscon_led_set;
...@@ -160,6 +129,38 @@ static int __init syscon_leds_init(void) ...@@ -160,6 +129,38 @@ static int __init syscon_leds_init(void)
dev_info(dev, "registered LED %s\n", sled->cdev.name); dev_info(dev, "registered LED %s\n", sled->cdev.name);
} }
return 0;
}
static int __init syscon_leds_init(void)
{
struct device_node *np;
for_each_of_allnodes(np) {
struct platform_device *pdev;
struct regmap *map;
int ret;
if (!of_device_is_compatible(np, "syscon"))
continue;
map = syscon_node_to_regmap(np);
if (IS_ERR(map)) {
pr_err("error getting regmap for syscon LEDs\n");
continue;
}
/*
* If the map is there, the device should be there, we allocate
* memory on the syscon device's behalf here.
*/
pdev = of_find_device_by_node(np);
if (!pdev)
return -ENODEV;
ret = syscon_leds_spawn(np, &pdev->dev, map);
if (ret)
dev_err(&pdev->dev, "could not spawn syscon LEDs\n");
}
return 0; return 0;
} }
......
...@@ -17,16 +17,28 @@ ...@@ -17,16 +17,28 @@
#include <linux/rwsem.h> #include <linux/rwsem.h>
#include <linux/leds.h> #include <linux/leds.h>
static inline void __led_set_brightness(struct led_classdev *led_cdev, static inline void led_set_brightness_async(struct led_classdev *led_cdev,
enum led_brightness value) enum led_brightness value)
{ {
if (value > led_cdev->max_brightness) led_cdev->brightness = min(value, led_cdev->max_brightness);
value = led_cdev->max_brightness;
led_cdev->brightness = value;
if (!(led_cdev->flags & LED_SUSPENDED)) if (!(led_cdev->flags & LED_SUSPENDED))
led_cdev->brightness_set(led_cdev, value); led_cdev->brightness_set(led_cdev, value);
} }
static inline int led_set_brightness_sync(struct led_classdev *led_cdev,
enum led_brightness value)
{
int ret = 0;
led_cdev->brightness = min(value, led_cdev->max_brightness);
if (!(led_cdev->flags & LED_SUSPENDED))
ret = led_cdev->brightness_set_sync(led_cdev,
led_cdev->brightness);
return ret;
}
static inline int led_get_brightness(struct led_classdev *led_cdev) static inline int led_get_brightness(struct led_classdev *led_cdev)
{ {
return led_cdev->brightness; return led_cdev->brightness;
......
...@@ -51,9 +51,9 @@ static int fb_notifier_callback(struct notifier_block *p, ...@@ -51,9 +51,9 @@ static int fb_notifier_callback(struct notifier_block *p,
if ((n->old_status == UNBLANK) ^ n->invert) { if ((n->old_status == UNBLANK) ^ n->invert) {
n->brightness = led->brightness; n->brightness = led->brightness;
__led_set_brightness(led, LED_OFF); led_set_brightness_async(led, LED_OFF);
} else { } else {
__led_set_brightness(led, n->brightness); led_set_brightness_async(led, n->brightness);
} }
n->old_status = new_status; n->old_status = new_status;
...@@ -89,9 +89,9 @@ static ssize_t bl_trig_invert_store(struct device *dev, ...@@ -89,9 +89,9 @@ static ssize_t bl_trig_invert_store(struct device *dev,
/* After inverting, we need to update the LED. */ /* After inverting, we need to update the LED. */
if ((n->old_status == BLANK) ^ n->invert) if ((n->old_status == BLANK) ^ n->invert)
__led_set_brightness(led, LED_OFF); led_set_brightness_async(led, LED_OFF);
else else
__led_set_brightness(led, n->brightness); led_set_brightness_async(led, n->brightness);
return num; return num;
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
static void defon_trig_activate(struct led_classdev *led_cdev) static void defon_trig_activate(struct led_classdev *led_cdev)
{ {
__led_set_brightness(led_cdev, led_cdev->max_brightness); led_set_brightness_async(led_cdev, led_cdev->max_brightness);
} }
static struct led_trigger defon_led_trigger = { static struct led_trigger defon_led_trigger = {
......
...@@ -54,12 +54,12 @@ static void gpio_trig_work(struct work_struct *work) ...@@ -54,12 +54,12 @@ static void gpio_trig_work(struct work_struct *work)
if (tmp) { if (tmp) {
if (gpio_data->desired_brightness) if (gpio_data->desired_brightness)
__led_set_brightness(gpio_data->led, led_set_brightness_async(gpio_data->led,
gpio_data->desired_brightness); gpio_data->desired_brightness);
else else
__led_set_brightness(gpio_data->led, LED_FULL); led_set_brightness_async(gpio_data->led, LED_FULL);
} else { } else {
__led_set_brightness(gpio_data->led, LED_OFF); led_set_brightness_async(gpio_data->led, LED_OFF);
} }
} }
......
...@@ -74,7 +74,7 @@ static void led_heartbeat_function(unsigned long data) ...@@ -74,7 +74,7 @@ static void led_heartbeat_function(unsigned long data)
break; break;
} }
__led_set_brightness(led_cdev, brightness); led_set_brightness_async(led_cdev, brightness);
mod_timer(&heartbeat_data->timer, jiffies + delay); mod_timer(&heartbeat_data->timer, jiffies + delay);
} }
......
...@@ -63,9 +63,9 @@ static ssize_t led_invert_store(struct device *dev, ...@@ -63,9 +63,9 @@ static ssize_t led_invert_store(struct device *dev,
oneshot_data->invert = !!state; oneshot_data->invert = !!state;
if (oneshot_data->invert) if (oneshot_data->invert)
__led_set_brightness(led_cdev, LED_FULL); led_set_brightness_async(led_cdev, LED_FULL);
else else
__led_set_brightness(led_cdev, LED_OFF); led_set_brightness_async(led_cdev, LED_OFF);
return size; return size;
} }
......
...@@ -41,7 +41,7 @@ static void transient_timer_function(unsigned long data) ...@@ -41,7 +41,7 @@ static void transient_timer_function(unsigned long data)
struct transient_trig_data *transient_data = led_cdev->trigger_data; struct transient_trig_data *transient_data = led_cdev->trigger_data;
transient_data->activate = 0; transient_data->activate = 0;
__led_set_brightness(led_cdev, transient_data->restore_state); led_set_brightness_async(led_cdev, transient_data->restore_state);
} }
static ssize_t transient_activate_show(struct device *dev, static ssize_t transient_activate_show(struct device *dev,
...@@ -72,7 +72,8 @@ static ssize_t transient_activate_store(struct device *dev, ...@@ -72,7 +72,8 @@ static ssize_t transient_activate_store(struct device *dev,
if (state == 0 && transient_data->activate == 1) { if (state == 0 && transient_data->activate == 1) {
del_timer(&transient_data->timer); del_timer(&transient_data->timer);
transient_data->activate = state; transient_data->activate = state;
__led_set_brightness(led_cdev, transient_data->restore_state); led_set_brightness_async(led_cdev,
transient_data->restore_state);
return size; return size;
} }
...@@ -80,7 +81,7 @@ static ssize_t transient_activate_store(struct device *dev, ...@@ -80,7 +81,7 @@ static ssize_t transient_activate_store(struct device *dev,
if (state == 1 && transient_data->activate == 0 && if (state == 1 && transient_data->activate == 0 &&
transient_data->duration != 0) { transient_data->duration != 0) {
transient_data->activate = state; transient_data->activate = state;
__led_set_brightness(led_cdev, transient_data->state); led_set_brightness_async(led_cdev, transient_data->state);
transient_data->restore_state = transient_data->restore_state =
(transient_data->state == LED_FULL) ? LED_OFF : LED_FULL; (transient_data->state == LED_FULL) ? LED_OFF : LED_FULL;
mod_timer(&transient_data->timer, mod_timer(&transient_data->timer,
...@@ -203,7 +204,8 @@ static void transient_trig_deactivate(struct led_classdev *led_cdev) ...@@ -203,7 +204,8 @@ static void transient_trig_deactivate(struct led_classdev *led_cdev)
if (led_cdev->activated) { if (led_cdev->activated) {
del_timer_sync(&transient_data->timer); del_timer_sync(&transient_data->timer);
__led_set_brightness(led_cdev, transient_data->restore_state); led_set_brightness_async(led_cdev,
transient_data->restore_state);
device_remove_file(led_cdev->dev, &dev_attr_activate); 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_duration);
device_remove_file(led_cdev->dev, &dev_attr_state); device_remove_file(led_cdev->dev, &dev_attr_state);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#define __LINUX_LEDS_H_INCLUDED #define __LINUX_LEDS_H_INCLUDED
#include <linux/list.h> #include <linux/list.h>
#include <linux/mutex.h>
#include <linux/rwsem.h> #include <linux/rwsem.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/timer.h> #include <linux/timer.h>
...@@ -42,11 +43,20 @@ struct led_classdev { ...@@ -42,11 +43,20 @@ struct led_classdev {
#define LED_BLINK_ONESHOT (1 << 17) #define LED_BLINK_ONESHOT (1 << 17)
#define LED_BLINK_ONESHOT_STOP (1 << 18) #define LED_BLINK_ONESHOT_STOP (1 << 18)
#define LED_BLINK_INVERT (1 << 19) #define LED_BLINK_INVERT (1 << 19)
#define LED_SYSFS_DISABLE (1 << 20)
#define SET_BRIGHTNESS_ASYNC (1 << 21)
#define SET_BRIGHTNESS_SYNC (1 << 22)
/* Set LED brightness level */ /* Set LED brightness level */
/* Must not sleep, use a workqueue if needed */ /* Must not sleep, use a workqueue if needed */
void (*brightness_set)(struct led_classdev *led_cdev, void (*brightness_set)(struct led_classdev *led_cdev,
enum led_brightness brightness); enum led_brightness brightness);
/*
* Set LED brightness level immediately - it can block the caller for
* the time required for accessing a LED device register.
*/
int (*brightness_set_sync)(struct led_classdev *led_cdev,
enum led_brightness brightness);
/* Get LED brightness level */ /* Get LED brightness level */
enum led_brightness (*brightness_get)(struct led_classdev *led_cdev); enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
...@@ -85,6 +95,9 @@ struct led_classdev { ...@@ -85,6 +95,9 @@ struct led_classdev {
/* true if activated - deactivate routine uses it to do cleanup */ /* true if activated - deactivate routine uses it to do cleanup */
bool activated; bool activated;
#endif #endif
/* Ensures consistent access to the LED Flash Class device */
struct mutex led_access;
}; };
extern int led_classdev_register(struct device *parent, extern int led_classdev_register(struct device *parent,
...@@ -151,6 +164,33 @@ extern void led_set_brightness(struct led_classdev *led_cdev, ...@@ -151,6 +164,33 @@ extern void led_set_brightness(struct led_classdev *led_cdev,
*/ */
extern int led_update_brightness(struct led_classdev *led_cdev); extern int led_update_brightness(struct led_classdev *led_cdev);
/**
* led_sysfs_disable - disable LED sysfs interface
* @led_cdev: the LED to set
*
* Disable the led_cdev's sysfs interface.
*/
extern void led_sysfs_disable(struct led_classdev *led_cdev);
/**
* led_sysfs_enable - enable LED sysfs interface
* @led_cdev: the LED to set
*
* Enable the led_cdev's sysfs interface.
*/
extern void led_sysfs_enable(struct led_classdev *led_cdev);
/**
* led_sysfs_is_disabled - check if LED sysfs interface is disabled
* @led_cdev: the LED to query
*
* Returns: true if the led_cdev's sysfs interface is disabled.
*/
static inline bool led_sysfs_is_disabled(struct led_classdev *led_cdev)
{
return led_cdev->flags & LED_SYSFS_DISABLE;
}
/* /*
* LED Triggers * LED Triggers
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment