Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / sparc / kernel / led.c
blob94a120a4e1050f670b8eb0d15ce9d05e1d1d0106
1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/init.h>
4 #include <linux/proc_fs.h>
5 #include <linux/string.h>
6 <<<<<<< HEAD:arch/sparc/kernel/led.c
7 =======
8 #include <linux/jiffies.h>
9 #include <linux/timer.h>
10 #include <linux/uaccess.h>
11 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sparc/kernel/led.c
13 #include <asm/auxio.h>
15 #define LED_MAX_LENGTH 8 /* maximum chars written to proc file */
17 static inline void led_toggle(void)
19 unsigned char val = get_auxio();
20 unsigned char on, off;
22 if (val & AUXIO_LED) {
23 on = 0;
24 off = AUXIO_LED;
25 } else {
26 on = AUXIO_LED;
27 off = 0;
30 set_auxio(on, off);
33 static struct timer_list led_blink_timer;
35 static void led_blink(unsigned long timeout)
37 led_toggle();
39 /* reschedule */
40 if (!timeout) { /* blink according to load */
41 led_blink_timer.expires = jiffies +
42 ((1 + (avenrun[0] >> FSHIFT)) * HZ);
43 led_blink_timer.data = 0;
44 } else { /* blink at user specified interval */
45 led_blink_timer.expires = jiffies + (timeout * HZ);
46 led_blink_timer.data = timeout;
48 add_timer(&led_blink_timer);
51 static int led_read_proc(char *buf, char **start, off_t offset, int count,
52 int *eof, void *data)
54 int len = 0;
56 if (get_auxio() & AUXIO_LED)
57 len = sprintf(buf, "on\n");
58 else
59 len = sprintf(buf, "off\n");
61 return len;
64 static int led_write_proc(struct file *file, const char __user *buffer,
65 unsigned long count, void *data)
67 char *buf = NULL;
69 if (count > LED_MAX_LENGTH)
70 count = LED_MAX_LENGTH;
72 buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL);
73 if (!buf)
74 return -ENOMEM;
76 if (copy_from_user(buf, buffer, count)) {
77 kfree(buf);
78 return -EFAULT;
81 buf[count] = '\0';
83 /* work around \n when echo'ing into proc */
84 if (buf[count - 1] == '\n')
85 buf[count - 1] = '\0';
87 /* before we change anything we want to stop any running timers,
88 * otherwise calls such as on will have no persistent effect
90 del_timer_sync(&led_blink_timer);
92 if (!strcmp(buf, "on")) {
93 auxio_set_led(AUXIO_LED_ON);
94 } else if (!strcmp(buf, "toggle")) {
95 led_toggle();
96 } else if ((*buf > '0') && (*buf <= '9')) {
97 led_blink(simple_strtoul(buf, NULL, 10));
98 } else if (!strcmp(buf, "load")) {
99 led_blink(0);
100 } else {
101 auxio_set_led(AUXIO_LED_OFF);
104 kfree(buf);
106 return count;
109 static struct proc_dir_entry *led;
111 #define LED_VERSION "0.1"
113 static int __init led_init(void)
115 init_timer(&led_blink_timer);
116 led_blink_timer.function = led_blink;
118 led = create_proc_entry("led", 0, NULL);
119 if (!led)
120 return -ENOMEM;
122 led->read_proc = led_read_proc; /* reader function */
123 led->write_proc = led_write_proc; /* writer function */
124 led->owner = THIS_MODULE;
126 printk(KERN_INFO
127 "led: version %s, Lars Kotthoff <metalhead@metalhead.ws>\n",
128 LED_VERSION);
130 return 0;
133 static void __exit led_exit(void)
135 remove_proc_entry("led", NULL);
136 del_timer_sync(&led_blink_timer);
139 module_init(led_init);
140 module_exit(led_exit);
142 MODULE_AUTHOR("Lars Kotthoff <metalhead@metalhead.ws>");
143 MODULE_DESCRIPTION("Provides control of the front LED on SPARC systems.");
144 MODULE_LICENSE("GPL");
145 MODULE_VERSION(LED_VERSION);