Automatic merge of rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/driver...
[linux-2.6/verdex.git] / drivers / char / scan_keyb.c
blob2b5bb4f5754dc8828389bfef2b298335fc418ac1
1 /*
2 * $Id: scan_keyb.c,v 1.2 2000/07/04 06:24:42 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/slab.h>
20 #include <linux/kbd_kern.h>
21 #include <linux/timer.h>
23 #define SCANHZ (HZ/20)
25 struct scan_keyboard {
26 struct scan_keyboard *next;
27 int (*scan)(unsigned char *buffer);
28 const unsigned char *table;
29 unsigned char *s0, *s1;
30 int length;
33 static int scan_jiffies=0;
34 static struct scan_keyboard *keyboards=NULL;
35 struct timer_list scan_timer;
37 static void check_kbd(const unsigned char *table,
38 unsigned char *new, unsigned char *old, int length)
40 int need_tasklet_schedule=0;
41 unsigned int xor, bit;
43 while(length-->0) {
44 if((xor=*new^*old)==0) {
45 table+=8;
47 else {
48 for(bit=0x01; bit<0x100; bit<<=1) {
49 if(xor&bit) {
50 handle_scancode(*table, !(*new&bit));
51 need_tasklet_schedule=1;
52 #if 0
53 printk("0x%x %s\n", *table, (*new&bit)?"released":"pressed");
54 #endif
56 table++;
59 new++; old++;
62 if(need_tasklet_schedule)
63 tasklet_schedule(&keyboard_tasklet);
67 static void scan_kbd(unsigned long dummy)
69 struct scan_keyboard *kbd;
71 scan_jiffies++;
73 for(kbd=keyboards; kbd!=NULL; kbd=kbd->next) {
74 if(scan_jiffies&1) {
75 if(!kbd->scan(kbd->s0))
76 check_kbd(kbd->table,
77 kbd->s0, kbd->s1, kbd->length);
78 else
79 memcpy(kbd->s0, kbd->s1, kbd->length);
81 else {
82 if(!kbd->scan(kbd->s1))
83 check_kbd(kbd->table,
84 kbd->s1, kbd->s0, kbd->length);
85 else
86 memcpy(kbd->s1, kbd->s0, kbd->length);
91 init_timer(&scan_timer);
92 scan_timer.expires = jiffies + SCANHZ;
93 scan_timer.data = 0;
94 scan_timer.function = scan_kbd;
95 add_timer(&scan_timer);
99 int register_scan_keyboard(int (*scan)(unsigned char *buffer),
100 const unsigned char *table,
101 int length)
103 struct scan_keyboard *kbd;
105 kbd = kmalloc(sizeof(struct scan_keyboard), GFP_KERNEL);
106 if (kbd == NULL)
107 goto error_out;
109 kbd->scan=scan;
110 kbd->table=table;
111 kbd->length=length;
113 kbd->s0 = kmalloc(length, GFP_KERNEL);
114 if (kbd->s0 == NULL)
115 goto error_free_kbd;
117 kbd->s1 = kmalloc(length, GFP_KERNEL);
118 if (kbd->s1 == NULL)
119 goto error_free_s0;
121 memset(kbd->s0, -1, kbd->length);
122 memset(kbd->s1, -1, kbd->length);
124 kbd->next=keyboards;
125 keyboards=kbd;
127 return 0;
129 error_free_s0:
130 kfree(kbd->s0);
132 error_free_kbd:
133 kfree(kbd);
135 error_out:
136 return -ENOMEM;
140 void __init scan_kbd_init(void)
142 init_timer(&scan_timer);
143 scan_timer.expires = jiffies + SCANHZ;
144 scan_timer.data = 0;
145 scan_timer.function = scan_kbd;
146 add_timer(&scan_timer);
148 printk(KERN_INFO "Generic scan keyboard driver initialized\n");