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>
22 static ssize_t
led_delay_on_show(struct device
*dev
,
23 struct device_attribute
*attr
, char *buf
)
25 struct led_classdev
*led_cdev
= dev_get_drvdata(dev
);
27 return sprintf(buf
, "%lu\n", led_cdev
->blink_delay_on
);
30 static ssize_t
led_delay_on_store(struct device
*dev
,
31 struct device_attribute
*attr
, const char *buf
, size_t size
)
33 struct led_classdev
*led_cdev
= dev_get_drvdata(dev
);
36 unsigned long state
= simple_strtoul(buf
, &after
, 10);
37 size_t count
= after
- buf
;
43 led_blink_set(led_cdev
, &state
, &led_cdev
->blink_delay_off
);
44 led_cdev
->blink_delay_on
= state
;
51 static ssize_t
led_delay_off_show(struct device
*dev
,
52 struct device_attribute
*attr
, char *buf
)
54 struct led_classdev
*led_cdev
= dev_get_drvdata(dev
);
56 return sprintf(buf
, "%lu\n", led_cdev
->blink_delay_off
);
59 static ssize_t
led_delay_off_store(struct device
*dev
,
60 struct device_attribute
*attr
, const char *buf
, size_t size
)
62 struct led_classdev
*led_cdev
= dev_get_drvdata(dev
);
65 unsigned long state
= simple_strtoul(buf
, &after
, 10);
66 size_t count
= after
- buf
;
72 led_blink_set(led_cdev
, &led_cdev
->blink_delay_on
, &state
);
73 led_cdev
->blink_delay_off
= state
;
80 static DEVICE_ATTR(delay_on
, 0644, led_delay_on_show
, led_delay_on_store
);
81 static DEVICE_ATTR(delay_off
, 0644, led_delay_off_show
, led_delay_off_store
);
83 static void timer_trig_activate(struct led_classdev
*led_cdev
)
87 led_cdev
->trigger_data
= NULL
;
89 rc
= device_create_file(led_cdev
->dev
, &dev_attr_delay_on
);
92 rc
= device_create_file(led_cdev
->dev
, &dev_attr_delay_off
);
96 led_blink_set(led_cdev
, &led_cdev
->blink_delay_on
,
97 &led_cdev
->blink_delay_off
);
99 led_cdev
->trigger_data
= (void *)1;
104 device_remove_file(led_cdev
->dev
, &dev_attr_delay_on
);
107 static void timer_trig_deactivate(struct led_classdev
*led_cdev
)
109 if (led_cdev
->trigger_data
) {
110 device_remove_file(led_cdev
->dev
, &dev_attr_delay_on
);
111 device_remove_file(led_cdev
->dev
, &dev_attr_delay_off
);
115 led_brightness_set(led_cdev
, LED_OFF
);
118 static struct led_trigger timer_led_trigger
= {
120 .activate
= timer_trig_activate
,
121 .deactivate
= timer_trig_deactivate
,
124 static int __init
timer_trig_init(void)
126 return led_trigger_register(&timer_led_trigger
);
129 static void __exit
timer_trig_exit(void)
131 led_trigger_unregister(&timer_led_trigger
);
134 module_init(timer_trig_init
);
135 module_exit(timer_trig_exit
);
137 MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
138 MODULE_DESCRIPTION("Timer LED trigger");
139 MODULE_LICENSE("GPL");