iommu/msm: Add iommu_group support
[linux/fpc-iii.git] / arch / sparc / kernel / led.c
blobe278bf52963b58e834ca21015ac59c2a84fe6ec0
1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/init.h>
4 #include <linux/proc_fs.h>
5 #include <linux/seq_file.h>
6 #include <linux/slab.h>
7 #include <linux/string.h>
8 #include <linux/jiffies.h>
9 #include <linux/timer.h>
10 #include <linux/uaccess.h>
11 #include <linux/sched/loadavg.h>
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_proc_show(struct seq_file *m, void *v)
53 if (get_auxio() & AUXIO_LED)
54 seq_puts(m, "on\n");
55 else
56 seq_puts(m, "off\n");
57 return 0;
60 static int led_proc_open(struct inode *inode, struct file *file)
62 return single_open(file, led_proc_show, NULL);
65 static ssize_t led_proc_write(struct file *file, const char __user *buffer,
66 size_t count, loff_t *ppos)
68 char *buf = NULL;
70 if (count > LED_MAX_LENGTH)
71 count = LED_MAX_LENGTH;
73 buf = memdup_user_nul(buffer, count);
74 if (IS_ERR(buf))
75 return PTR_ERR(buf);
77 /* work around \n when echo'ing into proc */
78 if (buf[count - 1] == '\n')
79 buf[count - 1] = '\0';
81 /* before we change anything we want to stop any running timers,
82 * otherwise calls such as on will have no persistent effect
84 del_timer_sync(&led_blink_timer);
86 if (!strcmp(buf, "on")) {
87 auxio_set_led(AUXIO_LED_ON);
88 } else if (!strcmp(buf, "toggle")) {
89 led_toggle();
90 } else if ((*buf > '0') && (*buf <= '9')) {
91 led_blink(simple_strtoul(buf, NULL, 10));
92 } else if (!strcmp(buf, "load")) {
93 led_blink(0);
94 } else {
95 auxio_set_led(AUXIO_LED_OFF);
98 kfree(buf);
100 return count;
103 static const struct file_operations led_proc_fops = {
104 .owner = THIS_MODULE,
105 .open = led_proc_open,
106 .read = seq_read,
107 .llseek = seq_lseek,
108 .release = single_release,
109 .write = led_proc_write,
112 static struct proc_dir_entry *led;
114 #define LED_VERSION "0.1"
116 static int __init led_init(void)
118 init_timer(&led_blink_timer);
119 led_blink_timer.function = led_blink;
121 led = proc_create("led", 0, NULL, &led_proc_fops);
122 if (!led)
123 return -ENOMEM;
125 printk(KERN_INFO
126 "led: version %s, Lars Kotthoff <metalhead@metalhead.ws>\n",
127 LED_VERSION);
129 return 0;
132 static void __exit led_exit(void)
134 remove_proc_entry("led", NULL);
135 del_timer_sync(&led_blink_timer);
138 module_init(led_init);
139 module_exit(led_exit);
141 MODULE_AUTHOR("Lars Kotthoff <metalhead@metalhead.ws>");
142 MODULE_DESCRIPTION("Provides control of the front LED on SPARC systems.");
143 MODULE_LICENSE("GPL");
144 MODULE_VERSION(LED_VERSION);