1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2000-2001 Vojtech Pavlik
4 * Copyright (c) 2002 Russell King
8 * Acorn RiscPC PS/2 keyboard controller driver for Linux/ARM
11 #include <linux/module.h>
12 #include <linux/interrupt.h>
13 #include <linux/serio.h>
14 #include <linux/err.h>
15 #include <linux/platform_device.h>
17 #include <linux/slab.h>
19 #include <mach/hardware.h>
20 #include <asm/hardware/iomd.h>
22 MODULE_AUTHOR("Vojtech Pavlik, Russell King");
23 MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
24 MODULE_LICENSE("GPL");
25 MODULE_ALIAS("platform:kart");
32 static int rpckbd_write(struct serio
*port
, unsigned char val
)
34 while (!(iomd_readb(IOMD_KCTRL
) & (1 << 7)))
37 iomd_writeb(val
, IOMD_KARTTX
);
42 static irqreturn_t
rpckbd_rx(int irq
, void *dev_id
)
44 struct serio
*port
= dev_id
;
46 int handled
= IRQ_NONE
;
48 while (iomd_readb(IOMD_KCTRL
) & (1 << 5)) {
49 byte
= iomd_readb(IOMD_KARTRX
);
51 serio_interrupt(port
, byte
, 0);
52 handled
= IRQ_HANDLED
;
57 static irqreturn_t
rpckbd_tx(int irq
, void *dev_id
)
62 static int rpckbd_open(struct serio
*port
)
64 struct rpckbd_data
*rpckbd
= port
->port_data
;
66 /* Reset the keyboard state machine. */
67 iomd_writeb(0, IOMD_KCTRL
);
68 iomd_writeb(8, IOMD_KCTRL
);
69 iomd_readb(IOMD_KARTRX
);
71 if (request_irq(rpckbd
->rx_irq
, rpckbd_rx
, 0, "rpckbd", port
) != 0) {
72 printk(KERN_ERR
"rpckbd.c: Could not allocate keyboard receive IRQ\n");
76 if (request_irq(rpckbd
->tx_irq
, rpckbd_tx
, 0, "rpckbd", port
) != 0) {
77 printk(KERN_ERR
"rpckbd.c: Could not allocate keyboard transmit IRQ\n");
78 free_irq(rpckbd
->rx_irq
, port
);
85 static void rpckbd_close(struct serio
*port
)
87 struct rpckbd_data
*rpckbd
= port
->port_data
;
89 free_irq(rpckbd
->rx_irq
, port
);
90 free_irq(rpckbd
->tx_irq
, port
);
94 * Allocate and initialize serio structure for subsequent registration
97 static int rpckbd_probe(struct platform_device
*dev
)
99 struct rpckbd_data
*rpckbd
;
103 rx_irq
= platform_get_irq(dev
, 0);
107 tx_irq
= platform_get_irq(dev
, 1);
111 serio
= kzalloc(sizeof(*serio
), GFP_KERNEL
);
112 rpckbd
= kzalloc(sizeof(*rpckbd
), GFP_KERNEL
);
113 if (!serio
|| !rpckbd
) {
119 rpckbd
->rx_irq
= rx_irq
;
120 rpckbd
->tx_irq
= tx_irq
;
122 serio
->id
.type
= SERIO_8042
;
123 serio
->write
= rpckbd_write
;
124 serio
->open
= rpckbd_open
;
125 serio
->close
= rpckbd_close
;
126 serio
->dev
.parent
= &dev
->dev
;
127 serio
->port_data
= rpckbd
;
128 strscpy(serio
->name
, "RiscPC PS/2 kbd port", sizeof(serio
->name
));
129 strscpy(serio
->phys
, "rpckbd/serio0", sizeof(serio
->phys
));
131 platform_set_drvdata(dev
, serio
);
132 serio_register_port(serio
);
136 static void rpckbd_remove(struct platform_device
*dev
)
138 struct serio
*serio
= platform_get_drvdata(dev
);
139 struct rpckbd_data
*rpckbd
= serio
->port_data
;
141 serio_unregister_port(serio
);
145 static struct platform_driver rpckbd_driver
= {
146 .probe
= rpckbd_probe
,
147 .remove
= rpckbd_remove
,
152 module_platform_driver(rpckbd_driver
);