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
14 #include <linux/module.h>
15 #include <linux/interrupt.h>
16 #include <linux/serio.h>
17 #include <linux/err.h>
18 #include <linux/platform_device.h>
20 #include <linux/slab.h>
22 #include <mach/hardware.h>
23 #include <asm/hardware/iomd.h>
25 MODULE_AUTHOR("Vojtech Pavlik, Russell King");
26 MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
27 MODULE_LICENSE("GPL");
28 MODULE_ALIAS("platform:kart");
35 static int rpckbd_write(struct serio
*port
, unsigned char val
)
37 while (!(iomd_readb(IOMD_KCTRL
) & (1 << 7)))
40 iomd_writeb(val
, IOMD_KARTTX
);
45 static irqreturn_t
rpckbd_rx(int irq
, void *dev_id
)
47 struct serio
*port
= dev_id
;
49 int handled
= IRQ_NONE
;
51 while (iomd_readb(IOMD_KCTRL
) & (1 << 5)) {
52 byte
= iomd_readb(IOMD_KARTRX
);
54 serio_interrupt(port
, byte
, 0);
55 handled
= IRQ_HANDLED
;
60 static irqreturn_t
rpckbd_tx(int irq
, void *dev_id
)
65 static int rpckbd_open(struct serio
*port
)
67 struct rpckbd_data
*rpckbd
= port
->port_data
;
69 /* Reset the keyboard state machine. */
70 iomd_writeb(0, IOMD_KCTRL
);
71 iomd_writeb(8, IOMD_KCTRL
);
72 iomd_readb(IOMD_KARTRX
);
74 if (request_irq(rpckbd
->rx_irq
, rpckbd_rx
, 0, "rpckbd", port
) != 0) {
75 printk(KERN_ERR
"rpckbd.c: Could not allocate keyboard receive IRQ\n");
79 if (request_irq(rpckbd
->tx_irq
, rpckbd_tx
, 0, "rpckbd", port
) != 0) {
80 printk(KERN_ERR
"rpckbd.c: Could not allocate keyboard transmit IRQ\n");
81 free_irq(rpckbd
->rx_irq
, port
);
88 static void rpckbd_close(struct serio
*port
)
90 struct rpckbd_data
*rpckbd
= port
->port_data
;
92 free_irq(rpckbd
->rx_irq
, port
);
93 free_irq(rpckbd
->tx_irq
, port
);
97 * Allocate and initialize serio structure for subsequent registration
100 static int rpckbd_probe(struct platform_device
*dev
)
102 struct rpckbd_data
*rpckbd
;
106 rx_irq
= platform_get_irq(dev
, 0);
108 return rx_irq
< 0 ? rx_irq
: -ENXIO
;
110 tx_irq
= platform_get_irq(dev
, 1);
112 return tx_irq
< 0 ? tx_irq
: -ENXIO
;
114 serio
= kzalloc(sizeof(struct serio
), GFP_KERNEL
);
115 rpckbd
= kzalloc(sizeof(*rpckbd
), GFP_KERNEL
);
116 if (!serio
|| !rpckbd
) {
122 rpckbd
->rx_irq
= rx_irq
;
123 rpckbd
->tx_irq
= tx_irq
;
125 serio
->id
.type
= SERIO_8042
;
126 serio
->write
= rpckbd_write
;
127 serio
->open
= rpckbd_open
;
128 serio
->close
= rpckbd_close
;
129 serio
->dev
.parent
= &dev
->dev
;
130 serio
->port_data
= rpckbd
;
131 strlcpy(serio
->name
, "RiscPC PS/2 kbd port", sizeof(serio
->name
));
132 strlcpy(serio
->phys
, "rpckbd/serio0", sizeof(serio
->phys
));
134 platform_set_drvdata(dev
, serio
);
135 serio_register_port(serio
);
139 static int rpckbd_remove(struct platform_device
*dev
)
141 struct serio
*serio
= platform_get_drvdata(dev
);
142 struct rpckbd_data
*rpckbd
= serio
->port_data
;
144 serio_unregister_port(serio
);
150 static struct platform_driver rpckbd_driver
= {
151 .probe
= rpckbd_probe
,
152 .remove
= rpckbd_remove
,
157 module_platform_driver(rpckbd_driver
);