Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[deliverable/linux.git] / drivers / input / serio / rpckbd.c
1 /*
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>
37 #include <linux/platform_device.h>
38
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
45 MODULE_AUTHOR("Vojtech Pavlik, Russell King");
46 MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
47 MODULE_LICENSE("GPL");
48 MODULE_ALIAS("platform:kart");
49
50 static int rpckbd_write(struct serio *port, unsigned char val)
51 {
52 while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
53 cpu_relax();
54
55 iomd_writeb(val, IOMD_KARTTX);
56
57 return 0;
58 }
59
60 static irqreturn_t rpckbd_rx(int irq, void *dev_id)
61 {
62 struct serio *port = dev_id;
63 unsigned int byte;
64 int handled = IRQ_NONE;
65
66 while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
67 byte = iomd_readb(IOMD_KARTRX);
68
69 serio_interrupt(port, byte, 0);
70 handled = IRQ_HANDLED;
71 }
72 return handled;
73 }
74
75 static irqreturn_t rpckbd_tx(int irq, void *dev_id)
76 {
77 return IRQ_HANDLED;
78 }
79
80 static int rpckbd_open(struct serio *port)
81 {
82 /* Reset the keyboard state machine. */
83 iomd_writeb(0, IOMD_KCTRL);
84 iomd_writeb(8, IOMD_KCTRL);
85 iomd_readb(IOMD_KARTRX);
86
87 if (request_irq(IRQ_KEYBOARDRX, rpckbd_rx, 0, "rpckbd", port) != 0) {
88 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
89 return -EBUSY;
90 }
91
92 if (request_irq(IRQ_KEYBOARDTX, rpckbd_tx, 0, "rpckbd", port) != 0) {
93 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
94 free_irq(IRQ_KEYBOARDRX, NULL);
95 return -EBUSY;
96 }
97
98 return 0;
99 }
100
101 static void rpckbd_close(struct serio *port)
102 {
103 free_irq(IRQ_KEYBOARDRX, port);
104 free_irq(IRQ_KEYBOARDTX, port);
105 }
106
107 /*
108 * Allocate and initialize serio structure for subsequent registration
109 * with serio core.
110 */
111 static int __devinit rpckbd_probe(struct platform_device *dev)
112 {
113 struct serio *serio;
114
115 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
116 if (!serio)
117 return -ENOMEM;
118
119 serio->id.type = SERIO_8042;
120 serio->write = rpckbd_write;
121 serio->open = rpckbd_open;
122 serio->close = rpckbd_close;
123 serio->dev.parent = &dev->dev;
124 strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
125 strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
126
127 platform_set_drvdata(dev, serio);
128 serio_register_port(serio);
129 return 0;
130 }
131
132 static int __devexit rpckbd_remove(struct platform_device *dev)
133 {
134 struct serio *serio = platform_get_drvdata(dev);
135 serio_unregister_port(serio);
136 return 0;
137 }
138
139 static struct platform_driver rpckbd_driver = {
140 .probe = rpckbd_probe,
141 .remove = __devexit_p(rpckbd_remove),
142 .driver = {
143 .name = "kart",
144 .owner = THIS_MODULE,
145 },
146 };
147
148 static int __init rpckbd_init(void)
149 {
150 return platform_driver_register(&rpckbd_driver);
151 }
152
153 static void __exit rpckbd_exit(void)
154 {
155 platform_driver_unregister(&rpckbd_driver);
156 }
157
158 module_init(rpckbd_init);
159 module_exit(rpckbd_exit);
This page took 0.036372 seconds and 5 git commands to generate.