blob: 58b224498b35ad7d3fc6c2b034780f67921f7f9f [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>
Russell King99730222009-03-25 10:21:35 +000036#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Russell Kinga09e64f2008-08-05 16:14:15 +010039#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#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
Russell King8c6d9d02012-03-01 15:47:10 +000048struct rpckbd_data {
49 int tx_irq;
50 int rx_irq;
51};
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static int rpckbd_write(struct serio *port, unsigned char val)
54{
55 while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
56 cpu_relax();
57
58 iomd_writeb(val, IOMD_KARTTX);
59
60 return 0;
61}
62
David Howells7d12e782006-10-05 14:55:46 +010063static irqreturn_t rpckbd_rx(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 struct serio *port = dev_id;
66 unsigned int byte;
67 int handled = IRQ_NONE;
68
69 while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
70 byte = iomd_readb(IOMD_KARTRX);
71
David Howells7d12e782006-10-05 14:55:46 +010072 serio_interrupt(port, byte, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 handled = IRQ_HANDLED;
74 }
75 return handled;
76}
77
David Howells7d12e782006-10-05 14:55:46 +010078static irqreturn_t rpckbd_tx(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 return IRQ_HANDLED;
81}
82
83static int rpckbd_open(struct serio *port)
84{
Russell King8c6d9d02012-03-01 15:47:10 +000085 struct rpckbd_data *rpckbd = port->port_data;
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 /* Reset the keyboard state machine. */
88 iomd_writeb(0, IOMD_KCTRL);
89 iomd_writeb(8, IOMD_KCTRL);
90 iomd_readb(IOMD_KARTRX);
91
Russell King8c6d9d02012-03-01 15:47:10 +000092 if (request_irq(rpckbd->rx_irq, rpckbd_rx, 0, "rpckbd", port) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
94 return -EBUSY;
95 }
96
Russell King8c6d9d02012-03-01 15:47:10 +000097 if (request_irq(rpckbd->tx_irq, rpckbd_tx, 0, "rpckbd", port) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
Russell King8c6d9d02012-03-01 15:47:10 +000099 free_irq(rpckbd->rx_irq, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return -EBUSY;
101 }
102
103 return 0;
104}
105
106static void rpckbd_close(struct serio *port)
107{
Russell King8c6d9d02012-03-01 15:47:10 +0000108 struct rpckbd_data *rpckbd = port->port_data;
109
110 free_irq(rpckbd->rx_irq, port);
111 free_irq(rpckbd->tx_irq, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
114/*
115 * Allocate and initialize serio structure for subsequent registration
116 * with serio core.
117 */
Russell King3ae5eae2005-11-09 22:32:44 +0000118static int __devinit rpckbd_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Russell King8c6d9d02012-03-01 15:47:10 +0000120 struct rpckbd_data *rpckbd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 struct serio *serio;
Russell King8c6d9d02012-03-01 15:47:10 +0000122 int tx_irq, rx_irq;
123
124 rx_irq = platform_get_irq(dev, 0);
125 if (rx_irq <= 0)
126 return rx_irq < 0 ? rx_irq : -ENXIO;
127
128 tx_irq = platform_get_irq(dev, 1);
129 if (tx_irq <= 0)
130 return tx_irq < 0 ? tx_irq : -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Eric Sesterhennb39787a2006-03-14 00:09:16 -0500132 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
Russell King8c6d9d02012-03-01 15:47:10 +0000133 rpckbd = kzalloc(sizeof(*rpckbd), GFP_KERNEL);
134 if (!serio || !rpckbd) {
135 kfree(rpckbd);
136 kfree(serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return -ENOMEM;
Russell King8c6d9d02012-03-01 15:47:10 +0000138 }
139
140 rpckbd->rx_irq = rx_irq;
141 rpckbd->tx_irq = tx_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 serio->id.type = SERIO_8042;
144 serio->write = rpckbd_write;
145 serio->open = rpckbd_open;
146 serio->close = rpckbd_close;
Russell King3ae5eae2005-11-09 22:32:44 +0000147 serio->dev.parent = &dev->dev;
Russell King8c6d9d02012-03-01 15:47:10 +0000148 serio->port_data = rpckbd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
150 strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
151
Russell King3ae5eae2005-11-09 22:32:44 +0000152 platform_set_drvdata(dev, serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 serio_register_port(serio);
154 return 0;
155}
156
Russell King3ae5eae2005-11-09 22:32:44 +0000157static int __devexit rpckbd_remove(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Russell King3ae5eae2005-11-09 22:32:44 +0000159 struct serio *serio = platform_get_drvdata(dev);
Russell King8c6d9d02012-03-01 15:47:10 +0000160 struct rpckbd_data *rpckbd = serio->port_data;
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 serio_unregister_port(serio);
Russell King8c6d9d02012-03-01 15:47:10 +0000163 kfree(rpckbd);
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 return 0;
166}
167
Russell King3ae5eae2005-11-09 22:32:44 +0000168static struct platform_driver rpckbd_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 .probe = rpckbd_probe,
170 .remove = __devexit_p(rpckbd_remove),
Russell King3ae5eae2005-11-09 22:32:44 +0000171 .driver = {
172 .name = "kart",
Kay Sieversd7b52472008-04-18 00:24:42 -0400173 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +0000174 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175};
JJ Ding24d24692011-11-29 11:08:43 -0800176module_platform_driver(rpckbd_driver);