ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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
51 static int q40kbd_open(struct serio *port)
52 {
53         return 0;
54 }
55 static void q40kbd_close(struct serio *port)
56 {
57 }
58
59 static struct serio q40kbd_port =
60 {
61         .type   = SERIO_8042,
62         .name   = "Q40 kbd port",
63         .phys   = "Q40",
64         .write  = NULL,
65         .open   = q40kbd_open,
66         .close  = q40kbd_close,
67 };
68
69 static irqreturn_t q40kbd_interrupt(int irq, void *dev_id,
70                                     struct pt_regs *regs)
71 {
72         if (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG))
73                 serio_interrupt(&q40kbd_port, master_inb(KEYCODE_REG), 0, regs);
74
75         master_outb(-1, KEYBOARD_UNLOCK_REG);
76         return IRQ_HANDLED;
77 }
78
79 static int __init q40kbd_init(void)
80 {
81         int maxread = 100;
82
83         if (!MACH_IS_Q40)
84                 return -EIO;
85
86         /* allocate the IRQ */
87         request_irq(Q40_IRQ_KEYBOARD, q40kbd_interrupt, 0, "q40kbd", NULL);
88
89         /* flush any pending input */
90         while (maxread-- && (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG)))
91                 master_inb(KEYCODE_REG);
92
93         /* off we go */
94         master_outb(-1,KEYBOARD_UNLOCK_REG);
95         master_outb(1,KEY_IRQ_ENABLE_REG);
96
97         serio_register_port(&q40kbd_port);
98         printk(KERN_INFO "serio: Q40 kbd registered\n");
99
100         return 0;
101 }
102
103 static void __exit q40kbd_exit(void)
104 {
105         master_outb(0,KEY_IRQ_ENABLE_REG);
106         master_outb(-1,KEYBOARD_UNLOCK_REG);
107
108         serio_unregister_port(&q40kbd_port);
109         free_irq(Q40_IRQ_KEYBOARD, NULL);
110 }
111
112 module_init(q40kbd_init);
113 module_exit(q40kbd_exit);