blob: 7f36edd34f8bcad063a595e23707ca894c9d7029 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (c) 2000-2001 Vojtech Pavlik
3 * Copyright (c) 2002 Russell King
4 */
5
6/*
7 * Acorn RiscPC PS/2 keyboard controller driver for Linux/ARM
8 */
9
10/*
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.
15 *
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.
20 *
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
24 *
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
28 */
29
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>
Russell Kingd052d1b2005-10-29 19:07:23 +010035#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010038#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/io.h>
40#include <asm/hardware/iomd.h>
41#include <asm/system.h>
42
43MODULE_AUTHOR("Vojtech Pavlik, Russell King");
44MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
45MODULE_LICENSE("GPL");
Kay Sieversd7b52472008-04-18 00:24:42 -040046MODULE_ALIAS("platform:kart");
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48static int rpckbd_write(struct serio *port, unsigned char val)
49{
50 while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
51 cpu_relax();
52
53 iomd_writeb(val, IOMD_KARTTX);
54
55 return 0;
56}
57
David Howells7d12e782006-10-05 14:55:46 +010058static irqreturn_t rpckbd_rx(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 struct serio *port = dev_id;
61 unsigned int byte;
62 int handled = IRQ_NONE;
63
64 while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
65 byte = iomd_readb(IOMD_KARTRX);
66
David Howells7d12e782006-10-05 14:55:46 +010067 serio_interrupt(port, byte, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 handled = IRQ_HANDLED;
69 }
70 return handled;
71}
72
David Howells7d12e782006-10-05 14:55:46 +010073static irqreturn_t rpckbd_tx(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 return IRQ_HANDLED;
76}
77
78static int rpckbd_open(struct serio *port)
79{
80 /* Reset the keyboard state machine. */
81 iomd_writeb(0, IOMD_KCTRL);
82 iomd_writeb(8, IOMD_KCTRL);
83 iomd_readb(IOMD_KARTRX);
84
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");
87 return -EBUSY;
88 }
89
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);
93 return -EBUSY;
94 }
95
96 return 0;
97}
98
99static void rpckbd_close(struct serio *port)
100{
101 free_irq(IRQ_KEYBOARDRX, port);
102 free_irq(IRQ_KEYBOARDTX, port);
103}
104
105/*
106 * Allocate and initialize serio structure for subsequent registration
107 * with serio core.
108 */
Russell King3ae5eae2005-11-09 22:32:44 +0000109static int __devinit rpckbd_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 struct serio *serio;
112
Eric Sesterhennb39787a2006-03-14 00:09:16 -0500113 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 if (!serio)
115 return -ENOMEM;
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 serio->id.type = SERIO_8042;
118 serio->write = rpckbd_write;
119 serio->open = rpckbd_open;
120 serio->close = rpckbd_close;
Russell King3ae5eae2005-11-09 22:32:44 +0000121 serio->dev.parent = &dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
123 strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
124
Russell King3ae5eae2005-11-09 22:32:44 +0000125 platform_set_drvdata(dev, serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 serio_register_port(serio);
127 return 0;
128}
129
Russell King3ae5eae2005-11-09 22:32:44 +0000130static int __devexit rpckbd_remove(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Russell King3ae5eae2005-11-09 22:32:44 +0000132 struct serio *serio = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 serio_unregister_port(serio);
134 return 0;
135}
136
Russell King3ae5eae2005-11-09 22:32:44 +0000137static struct platform_driver rpckbd_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .probe = rpckbd_probe,
139 .remove = __devexit_p(rpckbd_remove),
Russell King3ae5eae2005-11-09 22:32:44 +0000140 .driver = {
141 .name = "kart",
Kay Sieversd7b52472008-04-18 00:24:42 -0400142 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +0000143 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144};
145
146static int __init rpckbd_init(void)
147{
Russell King3ae5eae2005-11-09 22:32:44 +0000148 return platform_driver_register(&rpckbd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
151static void __exit rpckbd_exit(void)
152{
Russell King3ae5eae2005-11-09 22:32:44 +0000153 platform_driver_unregister(&rpckbd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154}
155
156module_init(rpckbd_init);
157module_exit(rpckbd_exit);