Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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#include "leds.h"
21
22static ssize_t led_delay_on_show(struct device *dev,
23 struct device_attribute *attr, char *buf)
24{
25 struct led_classdev *led_cdev = dev_get_drvdata(dev);
26
27 return sprintf(buf, "%lu\n", led_cdev->blink_delay_on);
28}
29
30static ssize_t led_delay_on_store(struct device *dev,
31 struct device_attribute *attr, const char *buf, size_t size)
32{
33 struct led_classdev *led_cdev = dev_get_drvdata(dev);
34 int ret = -EINVAL;
35 char *after;
36 unsigned long state = simple_strtoul(buf, &after, 10);
37 size_t count = after - buf;
38
39 if (isspace(*after))
40 count++;
41
42 if (count == size) {
43 led_blink_set(led_cdev, &state, &led_cdev->blink_delay_off);
44 ret = count;
45 }
46
47 return ret;
48}
49
50static ssize_t led_delay_off_show(struct device *dev,
51 struct device_attribute *attr, char *buf)
52{
53 struct led_classdev *led_cdev = dev_get_drvdata(dev);
54
55 return sprintf(buf, "%lu\n", led_cdev->blink_delay_off);
56}
57
58static ssize_t led_delay_off_store(struct device *dev,
59 struct device_attribute *attr, const char *buf, size_t size)
60{
61 struct led_classdev *led_cdev = dev_get_drvdata(dev);
62 int ret = -EINVAL;
63 char *after;
64 unsigned long state = simple_strtoul(buf, &after, 10);
65 size_t count = after - buf;
66
67 if (isspace(*after))
68 count++;
69
70 if (count == size) {
71 led_blink_set(led_cdev, &led_cdev->blink_delay_on, &state);
72 ret = count;
73 }
74
75 return ret;
76}
77
78static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);
79static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
80
81static void timer_trig_activate(struct led_classdev *led_cdev)
82{
83 int rc;
84
85 led_cdev->trigger_data = NULL;
86
87 rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
88 if (rc)
89 return;
90 rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
91 if (rc)
92 goto err_out_delayon;
93
94 led_blink_set(led_cdev, &led_cdev->blink_delay_on,
95 &led_cdev->blink_delay_off);
96
97 led_cdev->trigger_data = (void *)1;
98
99 return;
100
101err_out_delayon:
102 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
103}
104
105static void timer_trig_deactivate(struct led_classdev *led_cdev)
106{
107 if (led_cdev->trigger_data) {
108 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
109 device_remove_file(led_cdev->dev, &dev_attr_delay_off);
110 }
111
112 /* Stop blinking */
113 led_brightness_set(led_cdev, LED_OFF);
114}
115
116static struct led_trigger timer_led_trigger = {
117 .name = "timer",
118 .activate = timer_trig_activate,
119 .deactivate = timer_trig_deactivate,
120};
121
122static int __init timer_trig_init(void)
123{
124 return led_trigger_register(&timer_led_trigger);
125}
126
127static void __exit timer_trig_exit(void)
128{
129 led_trigger_unregister(&timer_led_trigger);
130}
131
132module_init(timer_trig_init);
133module_exit(timer_trig_exit);
134
135MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
136MODULE_DESCRIPTION("Timer LED trigger");
137MODULE_LICENSE("GPL");