blob: 8cf96473690274b716ee1171cd0c849f3bbf77f2 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/serio.h>
33#include <linux/err.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010034#include <linux/platform_device.h>
Russell King99730222009-03-25 10:21:35 +000035#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Russell Kinga09e64f2008-08-05 16:14:15 +010038#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/hardware/iomd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41MODULE_AUTHOR("Vojtech Pavlik, Russell King");
42MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
43MODULE_LICENSE("GPL");
Kay Sieversd7b52472008-04-18 00:24:42 -040044MODULE_ALIAS("platform:kart");
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Russell King8c6d9d02012-03-01 15:47:10 +000046struct rpckbd_data {
47 int tx_irq;
48 int rx_irq;
49};
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static int rpckbd_write(struct serio *port, unsigned char val)
52{
53 while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
54 cpu_relax();
55
56 iomd_writeb(val, IOMD_KARTTX);
57
58 return 0;
59}
60
David Howells7d12e782006-10-05 14:55:46 +010061static irqreturn_t rpckbd_rx(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
63 struct serio *port = dev_id;
64 unsigned int byte;
65 int handled = IRQ_NONE;
66
67 while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
68 byte = iomd_readb(IOMD_KARTRX);
69
David Howells7d12e782006-10-05 14:55:46 +010070 serio_interrupt(port, byte, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 handled = IRQ_HANDLED;
72 }
73 return handled;
74}
75
David Howells7d12e782006-10-05 14:55:46 +010076static irqreturn_t rpckbd_tx(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 return IRQ_HANDLED;
79}
80
81static int rpckbd_open(struct serio *port)
82{
Russell King8c6d9d02012-03-01 15:47:10 +000083 struct rpckbd_data *rpckbd = port->port_data;
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 /* Reset the keyboard state machine. */
86 iomd_writeb(0, IOMD_KCTRL);
87 iomd_writeb(8, IOMD_KCTRL);
88 iomd_readb(IOMD_KARTRX);
89
Russell King8c6d9d02012-03-01 15:47:10 +000090 if (request_irq(rpckbd->rx_irq, rpckbd_rx, 0, "rpckbd", port) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
92 return -EBUSY;
93 }
94
Russell King8c6d9d02012-03-01 15:47:10 +000095 if (request_irq(rpckbd->tx_irq, rpckbd_tx, 0, "rpckbd", port) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
Russell King8c6d9d02012-03-01 15:47:10 +000097 free_irq(rpckbd->rx_irq, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return -EBUSY;
99 }
100
101 return 0;
102}
103
104static void rpckbd_close(struct serio *port)
105{
Russell King8c6d9d02012-03-01 15:47:10 +0000106 struct rpckbd_data *rpckbd = port->port_data;
107
108 free_irq(rpckbd->rx_irq, port);
109 free_irq(rpckbd->tx_irq, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
112/*
113 * Allocate and initialize serio structure for subsequent registration
114 * with serio core.
115 */
Bill Pemberton5298cc42012-11-23 21:38:25 -0800116static int rpckbd_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
Russell King8c6d9d02012-03-01 15:47:10 +0000118 struct rpckbd_data *rpckbd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 struct serio *serio;
Russell King8c6d9d02012-03-01 15:47:10 +0000120 int tx_irq, rx_irq;
121
122 rx_irq = platform_get_irq(dev, 0);
123 if (rx_irq <= 0)
124 return rx_irq < 0 ? rx_irq : -ENXIO;
125
126 tx_irq = platform_get_irq(dev, 1);
127 if (tx_irq <= 0)
128 return tx_irq < 0 ? tx_irq : -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Eric Sesterhennb39787a2006-03-14 00:09:16 -0500130 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
Russell King8c6d9d02012-03-01 15:47:10 +0000131 rpckbd = kzalloc(sizeof(*rpckbd), GFP_KERNEL);
132 if (!serio || !rpckbd) {
133 kfree(rpckbd);
134 kfree(serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 return -ENOMEM;
Russell King8c6d9d02012-03-01 15:47:10 +0000136 }
137
138 rpckbd->rx_irq = rx_irq;
139 rpckbd->tx_irq = tx_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 serio->id.type = SERIO_8042;
142 serio->write = rpckbd_write;
143 serio->open = rpckbd_open;
144 serio->close = rpckbd_close;
Russell King3ae5eae2005-11-09 22:32:44 +0000145 serio->dev.parent = &dev->dev;
Russell King8c6d9d02012-03-01 15:47:10 +0000146 serio->port_data = rpckbd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
148 strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
149
Russell King3ae5eae2005-11-09 22:32:44 +0000150 platform_set_drvdata(dev, serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 serio_register_port(serio);
152 return 0;
153}
154
Bill Pembertone2619cf2012-11-23 21:50:47 -0800155static int rpckbd_remove(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Russell King3ae5eae2005-11-09 22:32:44 +0000157 struct serio *serio = platform_get_drvdata(dev);
Russell King8c6d9d02012-03-01 15:47:10 +0000158 struct rpckbd_data *rpckbd = serio->port_data;
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 serio_unregister_port(serio);
Russell King8c6d9d02012-03-01 15:47:10 +0000161 kfree(rpckbd);
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return 0;
164}
165
Russell King3ae5eae2005-11-09 22:32:44 +0000166static struct platform_driver rpckbd_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 .probe = rpckbd_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -0800168 .remove = rpckbd_remove,
Russell King3ae5eae2005-11-09 22:32:44 +0000169 .driver = {
170 .name = "kart",
171 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
JJ Ding24d24692011-11-29 11:08:43 -0800173module_platform_driver(rpckbd_driver);