]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/input/serio/rpckbd.c
x86/msr-index: Cleanup bit defines
[mirror_ubuntu-bionic-kernel.git] / drivers / input / serio / rpckbd.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * 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>
1da177e4
LT
32#include <linux/serio.h>
33#include <linux/err.h>
d052d1be 34#include <linux/platform_device.h>
99730225 35#include <linux/io.h>
5a0e3ad6 36#include <linux/slab.h>
1da177e4 37
a09e64fb 38#include <mach/hardware.h>
1da177e4 39#include <asm/hardware/iomd.h>
1da177e4
LT
40
41MODULE_AUTHOR("Vojtech Pavlik, Russell King");
42MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
43MODULE_LICENSE("GPL");
d7b5247b 44MODULE_ALIAS("platform:kart");
1da177e4 45
8c6d9d0a
RK
46struct rpckbd_data {
47 int tx_irq;
48 int rx_irq;
49};
50
1da177e4
LT
51static 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
7d12e780 61static irqreturn_t rpckbd_rx(int irq, void *dev_id)
1da177e4
LT
62{
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
7d12e780 70 serio_interrupt(port, byte, 0);
1da177e4
LT
71 handled = IRQ_HANDLED;
72 }
73 return handled;
74}
75
7d12e780 76static irqreturn_t rpckbd_tx(int irq, void *dev_id)
1da177e4
LT
77{
78 return IRQ_HANDLED;
79}
80
81static int rpckbd_open(struct serio *port)
82{
8c6d9d0a
RK
83 struct rpckbd_data *rpckbd = port->port_data;
84
1da177e4
LT
85 /* Reset the keyboard state machine. */
86 iomd_writeb(0, IOMD_KCTRL);
87 iomd_writeb(8, IOMD_KCTRL);
88 iomd_readb(IOMD_KARTRX);
89
8c6d9d0a 90 if (request_irq(rpckbd->rx_irq, rpckbd_rx, 0, "rpckbd", port) != 0) {
1da177e4
LT
91 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
92 return -EBUSY;
93 }
94
8c6d9d0a 95 if (request_irq(rpckbd->tx_irq, rpckbd_tx, 0, "rpckbd", port) != 0) {
1da177e4 96 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
8c6d9d0a 97 free_irq(rpckbd->rx_irq, port);
1da177e4
LT
98 return -EBUSY;
99 }
100
101 return 0;
102}
103
104static void rpckbd_close(struct serio *port)
105{
8c6d9d0a
RK
106 struct rpckbd_data *rpckbd = port->port_data;
107
108 free_irq(rpckbd->rx_irq, port);
109 free_irq(rpckbd->tx_irq, port);
1da177e4
LT
110}
111
112/*
113 * Allocate and initialize serio structure for subsequent registration
114 * with serio core.
115 */
5298cc4c 116static int rpckbd_probe(struct platform_device *dev)
1da177e4 117{
8c6d9d0a 118 struct rpckbd_data *rpckbd;
1da177e4 119 struct serio *serio;
8c6d9d0a
RK
120 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;
1da177e4 129
b39787a9 130 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
8c6d9d0a
RK
131 rpckbd = kzalloc(sizeof(*rpckbd), GFP_KERNEL);
132 if (!serio || !rpckbd) {
133 kfree(rpckbd);
134 kfree(serio);
1da177e4 135 return -ENOMEM;
8c6d9d0a
RK
136 }
137
138 rpckbd->rx_irq = rx_irq;
139 rpckbd->tx_irq = tx_irq;
1da177e4 140
1da177e4
LT
141 serio->id.type = SERIO_8042;
142 serio->write = rpckbd_write;
143 serio->open = rpckbd_open;
144 serio->close = rpckbd_close;
3ae5eaec 145 serio->dev.parent = &dev->dev;
8c6d9d0a 146 serio->port_data = rpckbd;
1da177e4
LT
147 strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
148 strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
149
3ae5eaec 150 platform_set_drvdata(dev, serio);
1da177e4
LT
151 serio_register_port(serio);
152 return 0;
153}
154
e2619cf7 155static int rpckbd_remove(struct platform_device *dev)
1da177e4 156{
3ae5eaec 157 struct serio *serio = platform_get_drvdata(dev);
8c6d9d0a
RK
158 struct rpckbd_data *rpckbd = serio->port_data;
159
1da177e4 160 serio_unregister_port(serio);
8c6d9d0a
RK
161 kfree(rpckbd);
162
1da177e4
LT
163 return 0;
164}
165
3ae5eaec 166static struct platform_driver rpckbd_driver = {
1da177e4 167 .probe = rpckbd_probe,
1cb0aa88 168 .remove = rpckbd_remove,
3ae5eaec
RK
169 .driver = {
170 .name = "kart",
171 },
1da177e4 172};
24d2469a 173module_platform_driver(rpckbd_driver);