Portability cleanup as required by Linus.
[linux-2.6/linux-mips.git] / drivers / char / scan_keyb.c
blob5bc1bdff9b942a95163d20e8958afa3515321ef7
1 /*
2 * $Id: scan_keyb.c,v 1.1 2000/06/10 21:45:30 yaegashi Exp $
3 * Copyright (C) 2000 YAEGASHI Takeshi
4 * Generic scan keyboard driver
5 */
7 #include <linux/spinlock.h>
8 #include <linux/sched.h>
9 #include <linux/interrupt.h>
10 #include <linux/tty.h>
11 #include <linux/mm.h>
12 #include <linux/signal.h>
13 #include <linux/init.h>
14 #include <linux/kbd_ll.h>
15 #include <linux/delay.h>
16 #include <linux/random.h>
17 #include <linux/poll.h>
18 #include <linux/miscdevice.h>
19 #include <linux/malloc.h>
20 #include <linux/kbd_kern.h>
22 struct scan_keyboard {
23 struct scan_keyboard *next;
24 void (*scan)(unsigned char *buffer);
25 const unsigned char *table;
26 unsigned char *s0, *s1;
27 int length;
30 static struct scan_keyboard *keyboards=NULL;
31 static struct tq_struct task_scan_kbd;
33 static void check_kbd(const unsigned char *table,
34 unsigned char *new, unsigned char *old, int length)
36 int need_tasklet_schedule=0;
37 unsigned char xor, bit;
39 while(length-->0) {
40 if((xor=*new^*old)==0) {
41 table+=8;
43 else {
44 for(bit=0x80; bit!=0; bit>>=1) {
45 if(xor&bit) {
46 handle_scancode(*table, !(*new&bit));
47 need_tasklet_schedule=1;
49 table++;
52 new++; old++;
55 if(need_tasklet_schedule)
56 tasklet_schedule(&keyboard_tasklet);
60 static void scan_kbd(void *dummy)
62 struct scan_keyboard *kbd;
64 for(kbd=keyboards; kbd!=NULL; kbd=kbd->next) {
65 if(jiffies&1) {
66 kbd->scan(kbd->s0);
67 check_kbd(kbd->table, kbd->s0, kbd->s1, kbd->length);
69 else {
70 kbd->scan(kbd->s1);
71 check_kbd(kbd->table, kbd->s1, kbd->s0, kbd->length);
75 queue_task(&task_scan_kbd, &tq_timer);
79 int register_scan_keyboard(void (*scan)(unsigned char *buffer),
80 const unsigned char *table,
81 int length)
83 struct scan_keyboard *kbd;
85 if((kbd=kmalloc(sizeof(struct scan_keyboard), GFP_KERNEL))==NULL)
86 goto error_out;
88 kbd->scan=scan;
89 kbd->table=table;
90 kbd->length=length;
92 kbd->s0=kbd->s1=NULL;
93 if((kbd->s0=kmalloc(length, GFP_KERNEL))==NULL)
94 goto error_out;
95 if((kbd->s1=kmalloc(length, GFP_KERNEL))==NULL)
96 goto error_out;
98 kbd->scan(kbd->s0);
99 kbd->scan(kbd->s1);
101 kbd->next=keyboards;
102 keyboards=kbd;
104 return 0;
106 error_mem_free:
107 if(kbd->s0)
108 kfree(kbd->s0);
109 if(kbd->s1)
110 kfree(kbd->s1);
111 kfree(kbd);
113 error_out:
114 return -ENOMEM;
118 void __init scan_kbd_init(void)
121 task_scan_kbd.next=NULL;
122 task_scan_kbd.sync=0;
123 task_scan_kbd.routine=scan_kbd;
124 task_scan_kbd.data=NULL;
125 queue_task(&task_scan_kbd, &tq_timer);
126 printk(KERN_INFO "Generic scan keyboard driver initialized\n");