2 * Copyright (c) 2000-2001 Vojtech Pavlik
3 * Copyright (c) 2002 Russell King
7 * Acorn RiscPC PS/2 keyboard controller driver for Linux/ARM
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Should you need to contact me, the author, you can do so either by
26 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
27 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
30 #include <linux/module.h>
31 #include <linux/interrupt.h>
32 #include <linux/init.h>
33 #include <linux/serio.h>
34 #include <linux/err.h>
35 #include <linux/platform_device.h>
38 #include <mach/hardware.h>
40 #include <asm/hardware/iomd.h>
41 #include <asm/system.h>
43 MODULE_AUTHOR("Vojtech Pavlik, Russell King");
44 MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
45 MODULE_LICENSE("GPL");
46 MODULE_ALIAS("platform:kart");
48 static int rpckbd_write(struct serio *port, unsigned char val)
50 while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
53 iomd_writeb(val, IOMD_KARTTX);
58 static irqreturn_t rpckbd_rx(int irq, void *dev_id)
60 struct serio *port = dev_id;
62 int handled = IRQ_NONE;
64 while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
65 byte = iomd_readb(IOMD_KARTRX);
67 serio_interrupt(port, byte, 0);
68 handled = IRQ_HANDLED;
73 static irqreturn_t rpckbd_tx(int irq, void *dev_id)
78 static int rpckbd_open(struct serio *port)
80 /* Reset the keyboard state machine. */
81 iomd_writeb(0, IOMD_KCTRL);
82 iomd_writeb(8, IOMD_KCTRL);
83 iomd_readb(IOMD_KARTRX);
85 if (request_irq(IRQ_KEYBOARDRX, rpckbd_rx, 0, "rpckbd", port) != 0) {
86 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
90 if (request_irq(IRQ_KEYBOARDTX, rpckbd_tx, 0, "rpckbd", port) != 0) {
91 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
92 free_irq(IRQ_KEYBOARDRX, NULL);
99 static void rpckbd_close(struct serio *port)
101 free_irq(IRQ_KEYBOARDRX, port);
102 free_irq(IRQ_KEYBOARDTX, port);
106 * Allocate and initialize serio structure for subsequent registration
109 static int __devinit rpckbd_probe(struct platform_device *dev)
113 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
117 serio->id.type = SERIO_8042;
118 serio->write = rpckbd_write;
119 serio->open = rpckbd_open;
120 serio->close = rpckbd_close;
121 serio->dev.parent = &dev->dev;
122 strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
123 strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
125 platform_set_drvdata(dev, serio);
126 serio_register_port(serio);
130 static int __devexit rpckbd_remove(struct platform_device *dev)
132 struct serio *serio = platform_get_drvdata(dev);
133 serio_unregister_port(serio);
137 static struct platform_driver rpckbd_driver = {
138 .probe = rpckbd_probe,
139 .remove = __devexit_p(rpckbd_remove),
142 .owner = THIS_MODULE,
146 static int __init rpckbd_init(void)
148 return platform_driver_register(&rpckbd_driver);
151 static void __exit rpckbd_exit(void)
153 platform_driver_unregister(&rpckbd_driver);
156 module_init(rpckbd_init);
157 module_exit(rpckbd_exit);