patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / input / serio / q40kbd.c
1 /*
2  * $Id: q40kbd.c,v 1.12 2002/02/02 22:26:44 vojtech Exp $
3  *
4  *  Copyright (c) 2000-2001 Vojtech Pavlik
5  *
6  *  Based on the work of:
7  *      Richard Zidlicky <Richard.Zidlicky@stud.informatik.uni-erlangen.de>
8  */
9
10 /*
11  * Q40 PS/2 keyboard controller driver for Linux/m68k
12  */
13
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28  *
29  * Should you need to contact me, the author, you can do so either by
30  * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
31  * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
32  */
33
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/serio.h>
37 #include <linux/interrupt.h>
38
39 #include <asm/bitops.h>
40 #include <asm/io.h>
41 #include <asm/uaccess.h>
42 #include <asm/q40_master.h>
43 #include <asm/irq.h>
44 #include <asm/q40ints.h>
45
46 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
47 MODULE_DESCRIPTION("Q40 PS/2 keyboard controller driver");
48 MODULE_LICENSE("GPL");
49
50 static struct serio q40kbd_port =
51 {
52         .type   = SERIO_8042,
53         .name   = "Q40 kbd port",
54         .phys   = "Q40",
55         .write  = NULL,
56 };
57
58 static irqreturn_t q40kbd_interrupt(int irq, void *dev_id,
59                                     struct pt_regs *regs)
60 {
61         if (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG))
62                 serio_interrupt(&q40kbd_port, master_inb(KEYCODE_REG), 0, regs);
63
64         master_outb(-1, KEYBOARD_UNLOCK_REG);
65         return IRQ_HANDLED;
66 }
67
68 static int __init q40kbd_init(void)
69 {
70         int maxread = 100;
71
72         if (!MACH_IS_Q40)
73                 return -EIO;
74
75         /* allocate the IRQ */
76         request_irq(Q40_IRQ_KEYBOARD, q40kbd_interrupt, 0, "q40kbd", NULL);
77
78         /* flush any pending input */
79         while (maxread-- && (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG)))
80                 master_inb(KEYCODE_REG);
81
82         /* off we go */
83         master_outb(-1,KEYBOARD_UNLOCK_REG);
84         master_outb(1,KEY_IRQ_ENABLE_REG);
85
86         serio_register_port(&q40kbd_port);
87         printk(KERN_INFO "serio: Q40 kbd registered\n");
88
89         return 0;
90 }
91
92 static void __exit q40kbd_exit(void)
93 {
94         master_outb(0,KEY_IRQ_ENABLE_REG);
95         master_outb(-1,KEYBOARD_UNLOCK_REG);
96
97         serio_unregister_port(&q40kbd_port);
98         free_irq(Q40_IRQ_KEYBOARD, NULL);
99 }
100
101 module_init(q40kbd_init);
102 module_exit(q40kbd_exit);