diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-06 15:41:42 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-06 15:41:42 -0700 |
commit | 2b69703fea185bb0ae1af78ca2da41af677b9dff (patch) | |
tree | 26b13044a0a20bed5525638d193e776f31f70af2 /drivers/leds/trigger/ledtrig-timer.c | |
parent | 30c67e93c526639aaac90fa873800104b7c16d16 (diff) | |
parent | df92d5ff5e70999274f53884cc2c40ae620a109a (diff) | |
download | linux-2b69703fea185bb0ae1af78ca2da41af677b9dff.tar.gz linux-2b69703fea185bb0ae1af78ca2da41af677b9dff.tar.bz2 linux-2b69703fea185bb0ae1af78ca2da41af677b9dff.zip |
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds
Pull LED subsystem updates from Bryan Wu:
- move LED trigger drivers into a new directory
- lp55xx common driver updates
- other led drivers updates and bug fixing
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds:
leds: leds-asic3: switch to using SIMPLE_DEV_PM_OPS
leds: leds-bd2802: add CONFIG_PM_SLEEP to suspend/resume functions
leds: lp55xx: configure the clock detection
leds: lp55xx: use common clock framework when external clock is used
leds: leds-ns2: fix oops at module removal
leds: leds-pwm: Defer led_pwm_set() if PWM can sleep
leds: lp55xx: fix the sysfs read operation
leds: lm355x, lm3642: support camera LED triggers for flash and torch
leds: add camera LED triggers
leds: trigger: use inline functions instead of macros
leds: tca6507: Use of_match_ptr() macro
leds: wm8350: Complain if we fail to reenable DCDC
leds: renesas: set gpio_request_one() flags param correctly
leds: leds-ns2: set devm_gpio_request_one() flags param correctly
leds: leds-lt3593: set devm_gpio_request_one() flags param correctly
leds: leds-bd2802: remove erroneous __exit annotation
leds: atmel-pwm: remove erroneous __exit annotation
leds: move LED trigger drivers into new subdirectory
leds: add new LP5562 LED driver
Diffstat (limited to 'drivers/leds/trigger/ledtrig-timer.c')
-rw-r--r-- | drivers/leds/trigger/ledtrig-timer.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/drivers/leds/trigger/ledtrig-timer.c b/drivers/leds/trigger/ledtrig-timer.c new file mode 100644 index 000000000000..8d09327b5719 --- /dev/null +++ b/drivers/leds/trigger/ledtrig-timer.c @@ -0,0 +1,130 @@ +/* + * LED Kernel Timer Trigger + * + * Copyright 2005-2006 Openedhand Ltd. + * + * Author: Richard Purdie <rpurdie@openedhand.com> + * + * 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 <linux/module.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/device.h> +#include <linux/ctype.h> +#include <linux/leds.h> + +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; + ssize_t ret = -EINVAL; + + ret = kstrtoul(buf, 10, &state); + if (ret) + return ret; + + led_blink_set(led_cdev, &state, &led_cdev->blink_delay_off); + 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; + ssize_t ret = -EINVAL; + + ret = kstrtoul(buf, 10, &state); + if (ret) + return ret; + + led_blink_set(led_cdev, &led_cdev->blink_delay_on, &state); + 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 void timer_trig_activate(struct led_classdev *led_cdev) +{ + int rc; + + led_cdev->trigger_data = NULL; + + rc = device_create_file(led_cdev->dev, &dev_attr_delay_on); + if (rc) + return; + rc = device_create_file(led_cdev->dev, &dev_attr_delay_off); + if (rc) + goto err_out_delayon; + + led_blink_set(led_cdev, &led_cdev->blink_delay_on, + &led_cdev->blink_delay_off); + led_cdev->activated = true; + + return; + +err_out_delayon: + device_remove_file(led_cdev->dev, &dev_attr_delay_on); +} + +static void timer_trig_deactivate(struct led_classdev *led_cdev) +{ + if (led_cdev->activated) { + device_remove_file(led_cdev->dev, &dev_attr_delay_on); + device_remove_file(led_cdev->dev, &dev_attr_delay_off); + led_cdev->activated = false; + } + + /* Stop blinking */ + led_set_brightness(led_cdev, LED_OFF); +} + +static struct led_trigger timer_led_trigger = { + .name = "timer", + .activate = timer_trig_activate, + .deactivate = timer_trig_deactivate, +}; + +static int __init timer_trig_init(void) +{ + return led_trigger_register(&timer_led_trigger); +} + +static void __exit timer_trig_exit(void) +{ + led_trigger_unregister(&timer_led_trigger); +} + +module_init(timer_trig_init); +module_exit(timer_trig_exit); + +MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>"); +MODULE_DESCRIPTION("Timer LED trigger"); +MODULE_LICENSE("GPL"); |