blob: 513d37fc1acfc2380a1b6732ec780c4987c1eab6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * $Id: rpckbd.c,v 1.7 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * Copyright (c) 2002 Russell King
6 */
7
8/*
9 * Acorn RiscPC PS/2 keyboard controller driver for Linux/ARM
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 * Should you need to contact me, the author, you can do so either by
28 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
29 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
30 */
31
32#include <linux/module.h>
33#include <linux/interrupt.h>
34#include <linux/init.h>
35#include <linux/serio.h>
36#include <linux/err.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010037#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#include <asm/irq.h>
40#include <asm/hardware.h>
41#include <asm/io.h>
42#include <asm/hardware/iomd.h>
43#include <asm/system.h>
44
45MODULE_AUTHOR("Vojtech Pavlik, Russell King");
46MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
47MODULE_LICENSE("GPL");
48
49static int rpckbd_write(struct serio *port, unsigned char val)
50{
51 while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
52 cpu_relax();
53
54 iomd_writeb(val, IOMD_KARTTX);
55
56 return 0;
57}
58
59static irqreturn_t rpckbd_rx(int irq, void *dev_id, struct pt_regs *regs)
60{
61 struct serio *port = dev_id;
62 unsigned int byte;
63 int handled = IRQ_NONE;
64
65 while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
66 byte = iomd_readb(IOMD_KARTRX);
67
68 serio_interrupt(port, byte, 0, regs);
69 handled = IRQ_HANDLED;
70 }
71 return handled;
72}
73
74static irqreturn_t rpckbd_tx(int irq, void *dev_id, struct pt_regs *regs)
75{
76 return IRQ_HANDLED;
77}
78
79static int rpckbd_open(struct serio *port)
80{
81 /* Reset the keyboard state machine. */
82 iomd_writeb(0, IOMD_KCTRL);
83 iomd_writeb(8, IOMD_KCTRL);
84 iomd_readb(IOMD_KARTRX);
85
86 if (request_irq(IRQ_KEYBOARDRX, rpckbd_rx, 0, "rpckbd", port) != 0) {
87 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
88 return -EBUSY;
89 }
90
91 if (request_irq(IRQ_KEYBOARDTX, rpckbd_tx, 0, "rpckbd", port) != 0) {
92 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
93 free_irq(IRQ_KEYBOARDRX, NULL);
94 return -EBUSY;
95 }
96
97 return 0;
98}
99
100static void rpckbd_close(struct serio *port)
101{
102 free_irq(IRQ_KEYBOARDRX, port);
103 free_irq(IRQ_KEYBOARDTX, port);
104}
105
106/*
107 * Allocate and initialize serio structure for subsequent registration
108 * with serio core.
109 */
Russell King3ae5eae2005-11-09 22:32:44 +0000110static int __devinit rpckbd_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 struct serio *serio;
113
Eric Sesterhennb39787a2006-03-14 00:09:16 -0500114 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 if (!serio)
116 return -ENOMEM;
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 serio->id.type = SERIO_8042;
119 serio->write = rpckbd_write;
120 serio->open = rpckbd_open;
121 serio->close = rpckbd_close;
Russell King3ae5eae2005-11-09 22:32:44 +0000122 serio->dev.parent = &dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
124 strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
125
Russell King3ae5eae2005-11-09 22:32:44 +0000126 platform_set_drvdata(dev, serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 serio_register_port(serio);
128 return 0;
129}
130
Russell King3ae5eae2005-11-09 22:32:44 +0000131static int __devexit rpckbd_remove(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Russell King3ae5eae2005-11-09 22:32:44 +0000133 struct serio *serio = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 serio_unregister_port(serio);
135 return 0;
136}
137
Russell King3ae5eae2005-11-09 22:32:44 +0000138static struct platform_driver rpckbd_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 .probe = rpckbd_probe,
140 .remove = __devexit_p(rpckbd_remove),
Russell King3ae5eae2005-11-09 22:32:44 +0000141 .driver = {
142 .name = "kart",
143 },
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);