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
7 #include <linux/spinlock.h>
8 #include <linux/sched.h>
9 #include <linux/interrupt.h>
10 #include <linux/tty.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;
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;
44 if((xor=*new^*old)==0) {
48 for(bit=0x01; bit<0x100; bit<<=1) {
50 handle_scancode(*table, !(*new&bit));
51 need_tasklet_schedule=1;
53 printk("0x%x %s\n", *table, (*new&bit)?"released":"pressed");
62 if(need_tasklet_schedule)
63 tasklet_schedule(&keyboard_tasklet);
67 static void scan_kbd(unsigned long dummy)
69 struct scan_keyboard *kbd;
73 for(kbd=keyboards; kbd!=NULL; kbd=kbd->next) {
75 if(!kbd->scan(kbd->s0))
77 kbd->s0, kbd->s1, kbd->length);
79 memcpy(kbd->s0, kbd->s1, kbd->length);
82 if(!kbd->scan(kbd->s1))
84 kbd->s1, kbd->s0, kbd->length);
86 memcpy(kbd->s1, kbd->s0, kbd->length);
91 init_timer(&scan_timer);
92 scan_timer.expires = jiffies + SCANHZ;
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,
103 struct scan_keyboard *kbd;
105 kbd = kmalloc(sizeof(struct scan_keyboard), GFP_KERNEL);
113 kbd->s0 = kmalloc(length, GFP_KERNEL);
117 kbd->s1 = kmalloc(length, GFP_KERNEL);
121 memset(kbd->s0, -1, kbd->length);
122 memset(kbd->s1, -1, kbd->length);
140 void __init scan_kbd_init(void)
142 init_timer(&scan_timer);
143 scan_timer.expires = jiffies + SCANHZ;
145 scan_timer.function = scan_kbd;
146 add_timer(&scan_timer);
148 printk(KERN_INFO "Generic scan keyboard driver initialized\n");