PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / leds / trigger / ledtrig-timer.c
blob8d09327b5719382da9da6b0f844232c699dacca2
1 /*
2 * LED Kernel Timer Trigger
4 * Copyright 2005-2006 Openedhand Ltd.
6 * Author: Richard Purdie <rpurdie@openedhand.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/device.h>
18 #include <linux/ctype.h>
19 #include <linux/leds.h>
21 static ssize_t led_delay_on_show(struct device *dev,
22 struct device_attribute *attr, char *buf)
24 struct led_classdev *led_cdev = dev_get_drvdata(dev);
26 return sprintf(buf, "%lu\n", led_cdev->blink_delay_on);
29 static ssize_t led_delay_on_store(struct device *dev,
30 struct device_attribute *attr, const char *buf, size_t size)
32 struct led_classdev *led_cdev = dev_get_drvdata(dev);
33 unsigned long state;
34 ssize_t ret = -EINVAL;
36 ret = kstrtoul(buf, 10, &state);
37 if (ret)
38 return ret;
40 led_blink_set(led_cdev, &state, &led_cdev->blink_delay_off);
41 led_cdev->blink_delay_on = state;
43 return size;
46 static ssize_t led_delay_off_show(struct device *dev,
47 struct device_attribute *attr, char *buf)
49 struct led_classdev *led_cdev = dev_get_drvdata(dev);
51 return sprintf(buf, "%lu\n", led_cdev->blink_delay_off);
54 static ssize_t led_delay_off_store(struct device *dev,
55 struct device_attribute *attr, const char *buf, size_t size)
57 struct led_classdev *led_cdev = dev_get_drvdata(dev);
58 unsigned long state;
59 ssize_t ret = -EINVAL;
61 ret = kstrtoul(buf, 10, &state);
62 if (ret)
63 return ret;
65 led_blink_set(led_cdev, &led_cdev->blink_delay_on, &state);
66 led_cdev->blink_delay_off = state;
68 return size;
71 static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);
72 static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
74 static void timer_trig_activate(struct led_classdev *led_cdev)
76 int rc;
78 led_cdev->trigger_data = NULL;
80 rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
81 if (rc)
82 return;
83 rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
84 if (rc)
85 goto err_out_delayon;
87 led_blink_set(led_cdev, &led_cdev->blink_delay_on,
88 &led_cdev->blink_delay_off);
89 led_cdev->activated = true;
91 return;
93 err_out_delayon:
94 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
97 static void timer_trig_deactivate(struct led_classdev *led_cdev)
99 if (led_cdev->activated) {
100 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
101 device_remove_file(led_cdev->dev, &dev_attr_delay_off);
102 led_cdev->activated = false;
105 /* Stop blinking */
106 led_set_brightness(led_cdev, LED_OFF);
109 static struct led_trigger timer_led_trigger = {
110 .name = "timer",
111 .activate = timer_trig_activate,
112 .deactivate = timer_trig_deactivate,
115 static int __init timer_trig_init(void)
117 return led_trigger_register(&timer_led_trigger);
120 static void __exit timer_trig_exit(void)
122 led_trigger_unregister(&timer_led_trigger);
125 module_init(timer_trig_init);
126 module_exit(timer_trig_exit);
128 MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
129 MODULE_DESCRIPTION("Timer LED trigger");
130 MODULE_LICENSE("GPL");