7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
11 #include <linux/time.h>
15 #include <linux/string.h>
16 #include <linux/errno.h>
19 #include <asm/uaccess.h>
26 static void button_sequence_finished (
unsigned long parameters);
28 static int button_press_count;
30 static DEFINE_TIMER(button_timer, button_sequence_finished, 0, 0);
32 static char button_output_buffer[32];
34 static int bdelay = BUTTON_DELAY;
35 static struct button_callback button_callback_list[32];
36 static int callback_count;
37 static int reboot_count = NUM_PRESSES_REBOOT;
59 if (callback_count == 32) {
66 for (; (button_callback_list [lp].callback); lp++);
67 button_callback_list [lp].callback =
callback;
68 button_callback_list [lp].count =
count;
91 if ((button_callback_list [lp].
callback) == callback) {
92 button_callback_list [lp].callback =
NULL;
93 button_callback_list [lp].count = 0;
110 static void button_consume_callbacks (
int bpcount)
113 for (; lp <= 31; lp++) {
114 if ((button_callback_list [lp].
count) == bpcount) {
115 if (button_callback_list [lp].
callback) {
116 button_callback_list[lp].callback();
130 static void button_sequence_finished (
unsigned long parameters)
132 #ifdef CONFIG_NWBUTTON_REBOOT
133 if (button_press_count == reboot_count)
136 button_consume_callbacks (button_press_count);
137 bcount =
sprintf (button_output_buffer,
"%d\n", button_press_count);
138 button_press_count = 0;
152 button_press_count++;
153 mod_timer(&button_timer, jiffies + bdelay);
168 static int button_read (
struct file *filp,
char __user *
buffer,
169 size_t count, loff_t *ppos)
194 static struct miscdevice button_misc_device = {
209 static int __init nwbutton_init(
void)
214 printk (
KERN_INFO "NetWinder Button Driver Version %s (C) Alex Holden "
219 "%d.\n", BUTTON_MINOR);
233 static void __exit nwbutton_exit (
void)