1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
38#include <asm/irq.h>
39#include <mach/hardware.h>
40#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");
46MODULE_ALIAS("platform:kart");
47
48static int rpckbd_write(struct serio *port, unsigned char val)
49{
50 while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
51 cpu_relax();
52
53 iomd_writeb(val, IOMD_KARTTX);
54
55 return 0;
56}
57
58static irqreturn_t rpckbd_rx(int irq, void *dev_id)
59{
60 struct serio *port = dev_id;
61 unsigned int byte;
62 int handled = IRQ_NONE;
63
64 while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
65 byte = iomd_readb(IOMD_KARTRX);
66
67 serio_interrupt(port, byte, 0);
68 handled = IRQ_HANDLED;
69 }
70 return handled;
71}
72
73static irqreturn_t rpckbd_tx(int irq, void *dev_id)
74{
75 return IRQ_HANDLED;
76}
77
78static int rpckbd_open(struct serio *port)
79{
80
81 iomd_writeb(0, IOMD_KCTRL);
82 iomd_writeb(8, IOMD_KCTRL);
83 iomd_readb(IOMD_KARTRX);
84
85 if (request_irq(IRQ_KEYBOARDRX, rpckbd_rx, 0, "rpckbd", port) != 0) {
86 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
87 return -EBUSY;
88 }
89
90 if (request_irq(IRQ_KEYBOARDTX, rpckbd_tx, 0, "rpckbd", port) != 0) {
91 printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
92 free_irq(IRQ_KEYBOARDRX, NULL);
93 return -EBUSY;
94 }
95
96 return 0;
97}
98
99static void rpckbd_close(struct serio *port)
100{
101 free_irq(IRQ_KEYBOARDRX, port);
102 free_irq(IRQ_KEYBOARDTX, port);
103}
104
105
106
107
108
109static int __devinit rpckbd_probe(struct platform_device *dev)
110{
111 struct serio *serio;
112
113 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
114 if (!serio)
115 return -ENOMEM;
116
117 serio->id.type = SERIO_8042;
118 serio->write = rpckbd_write;
119 serio->open = rpckbd_open;
120 serio->close = rpckbd_close;
121 serio->dev.parent = &dev->dev;
122 strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
123 strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
124
125 platform_set_drvdata(dev, serio);
126 serio_register_port(serio);
127 return 0;
128}
129
130static int __devexit rpckbd_remove(struct platform_device *dev)
131{
132 struct serio *serio = platform_get_drvdata(dev);
133 serio_unregister_port(serio);
134 return 0;
135}
136
137static struct platform_driver rpckbd_driver = {
138 .probe = rpckbd_probe,
139 .remove = __devexit_p(rpckbd_remove),
140 .driver = {
141 .name = "kart",
142 .owner = THIS_MODULE,
143 },
144};
145
146static int __init rpckbd_init(void)
147{
148 return platform_driver_register(&rpckbd_driver);
149}
150
151static void __exit rpckbd_exit(void)
152{
153 platform_driver_unregister(&rpckbd_driver);
154}
155
156module_init(rpckbd_init);
157module_exit(rpckbd_exit);
158