aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/trigger/ledtrig-timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/leds/trigger/ledtrig-timer.c')
-rw-r--r--drivers/leds/trigger/ledtrig-timer.c130
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 @@
1/*
2 * LED Kernel Timer Trigger
3 *
4 * Copyright 2005-2006 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
7 *
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.
11 *
12 */
13
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>
20
21static ssize_t led_delay_on_show(struct device *dev,
22 struct device_attribute *attr, char *buf)
23{
24 struct led_classdev *led_cdev = dev_get_drvdata(dev);
25
26 return sprintf(buf, "%lu\n", led_cdev->blink_delay_on);
27}
28
29static ssize_t led_delay_on_store(struct device *dev,
30 struct device_attribute *attr, const char *buf, size_t size)
31{
32 struct led_classdev *led_cdev = dev_get_drvdata(dev);
33 unsigned long state;
34 ssize_t ret = -EINVAL;
35
36 ret = kstrtoul(buf, 10, &state);
37 if (ret)
38 return ret;
39
40 led_blink_set(led_cdev, &state, &led_cdev->blink_delay_off);
41 led_cdev->blink_delay_on = state;
42
43 return size;
44}
45
46static ssize_t led_delay_off_show(struct device *dev,
47 struct device_attribute *attr, char *buf)
48{
49 struct led_classdev *led_cdev = dev_get_drvdata(dev);
50
51 return sprintf(buf, "%lu\n", led_cdev->blink_delay_off);
52}
53
54static ssize_t led_delay_off_store(struct device *dev,
55 struct device_attribute *attr, const char *buf, size_t size)
56{
57 struct led_classdev *led_cdev = dev_get_drvdata(dev);
58 unsigned long state;
59 ssize_t ret = -EINVAL;
60
61 ret = kstrtoul(buf, 10, &state);
62 if (ret)
63 return ret;
64
65 led_blink_set(led_cdev, &led_cdev->blink_delay_on, &state);
66 led_cdev->blink_delay_off = state;
67
68 return size;
69}
70
71static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);
72static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
73
74static void timer_trig_activate(struct led_classdev *led_cdev)
75{
76 int rc;
77
78 led_cdev->trigger_data = NULL;
79
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;
86
87 led_blink_set(led_cdev, &led_cdev->blink_delay_on,
88 &led_cdev->blink_delay_off);
89 led_cdev->activated = true;
90
91 return;
92
93err_out_delayon:
94 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
95}
96
97static void timer_trig_deactivate(struct led_classdev *led_cdev)
98{
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;
103 }
104
105 /* Stop blinking */
106 led_set_brightness(led_cdev, LED_OFF);
107}
108
109static struct led_trigger timer_led_trigger = {
110 .name = "timer",
111 .activate = timer_trig_activate,
112 .deactivate = timer_trig_deactivate,
113};
114
115static int __init timer_trig_init(void)
116{
117 return led_trigger_register(&timer_led_trigger);
118}
119
120static void __exit timer_trig_exit(void)
121{
122 led_trigger_unregister(&timer_led_trigger);
123}
124
125module_init(timer_trig_init);
126module_exit(timer_trig_exit);
127
128MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
129MODULE_DESCRIPTION("Timer LED trigger");
130MODULE_LICENSE("GPL");