]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/input/serio/rpckbd.c
ARM: riscpc: pass IRQ resources into keyboard driver
[karo-tx-linux.git] / drivers / input / serio / rpckbd.c
1 /*
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>
32 #include <linux/init.h>
33 #include <linux/serio.h>
34 #include <linux/err.h>
35 #include <linux/platform_device.h>
36 #include <linux/io.h>
37 #include <linux/slab.h>
38
39 #include <mach/hardware.h>
40 #include <asm/hardware/iomd.h>
41 #include <asm/system.h>
42
43 MODULE_AUTHOR("Vojtech Pavlik, Russell King");
44 MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
45 MODULE_LICENSE("GPL");
46 MODULE_ALIAS("platform:kart");
47
48 struct rpckbd_data {
49         int tx_irq;
50         int rx_irq;
51 };
52
53 static 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
63 static irqreturn_t rpckbd_rx(int irq, void *dev_id)
64 {
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
72                 serio_interrupt(port, byte, 0);
73                 handled = IRQ_HANDLED;
74         }
75         return handled;
76 }
77
78 static irqreturn_t rpckbd_tx(int irq, void *dev_id)
79 {
80         return IRQ_HANDLED;
81 }
82
83 static int rpckbd_open(struct serio *port)
84 {
85         struct rpckbd_data *rpckbd = port->port_data;
86
87         /* Reset the keyboard state machine. */
88         iomd_writeb(0, IOMD_KCTRL);
89         iomd_writeb(8, IOMD_KCTRL);
90         iomd_readb(IOMD_KARTRX);
91
92         if (request_irq(rpckbd->rx_irq, rpckbd_rx, 0, "rpckbd", port) != 0) {
93                 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
94                 return -EBUSY;
95         }
96
97         if (request_irq(rpckbd->tx_irq, rpckbd_tx, 0, "rpckbd", port) != 0) {
98                 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
99                 free_irq(rpckbd->rx_irq, port);
100                 return -EBUSY;
101         }
102
103         return 0;
104 }
105
106 static void rpckbd_close(struct serio *port)
107 {
108         struct rpckbd_data *rpckbd = port->port_data;
109
110         free_irq(rpckbd->rx_irq, port);
111         free_irq(rpckbd->tx_irq, port);
112 }
113
114 /*
115  * Allocate and initialize serio structure for subsequent registration
116  * with serio core.
117  */
118 static int __devinit rpckbd_probe(struct platform_device *dev)
119 {
120         struct rpckbd_data *rpckbd;
121         struct serio *serio;
122         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;
131
132         serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
133         rpckbd = kzalloc(sizeof(*rpckbd), GFP_KERNEL);
134         if (!serio || !rpckbd) {
135                 kfree(rpckbd);
136                 kfree(serio);
137                 return -ENOMEM;
138         }
139
140         rpckbd->rx_irq = rx_irq;
141         rpckbd->tx_irq = tx_irq;
142
143         serio->id.type          = SERIO_8042;
144         serio->write            = rpckbd_write;
145         serio->open             = rpckbd_open;
146         serio->close            = rpckbd_close;
147         serio->dev.parent       = &dev->dev;
148         serio->port_data        = rpckbd;
149         strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
150         strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
151
152         platform_set_drvdata(dev, serio);
153         serio_register_port(serio);
154         return 0;
155 }
156
157 static int __devexit rpckbd_remove(struct platform_device *dev)
158 {
159         struct serio *serio = platform_get_drvdata(dev);
160         struct rpckbd_data *rpckbd = serio->port_data;
161
162         serio_unregister_port(serio);
163         kfree(rpckbd);
164
165         return 0;
166 }
167
168 static struct platform_driver rpckbd_driver = {
169         .probe          = rpckbd_probe,
170         .remove         = __devexit_p(rpckbd_remove),
171         .driver         = {
172                 .name   = "kart",
173                 .owner  = THIS_MODULE,
174         },
175 };
176 module_platform_driver(rpckbd_driver);