treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / input / serio / rpckbd.c
blob37fe6a5711ea0c48b49af979bbb98c544ff4a793
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2000-2001 Vojtech Pavlik
4 * Copyright (c) 2002 Russell King
5 */
7 /*
8 * Acorn RiscPC PS/2 keyboard controller driver for Linux/ARM
9 */
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>
19 #include <linux/io.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");
30 struct rpckbd_data {
31 int tx_irq;
32 int rx_irq;
35 static int rpckbd_write(struct serio *port, unsigned char val)
37 while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
38 cpu_relax();
40 iomd_writeb(val, IOMD_KARTTX);
42 return 0;
45 static irqreturn_t rpckbd_rx(int irq, void *dev_id)
47 struct serio *port = dev_id;
48 unsigned int byte;
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;
57 return handled;
60 static irqreturn_t rpckbd_tx(int irq, void *dev_id)
62 return IRQ_HANDLED;
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");
76 return -EBUSY;
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);
82 return -EBUSY;
85 return 0;
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
98 * with serio core.
100 static int rpckbd_probe(struct platform_device *dev)
102 struct rpckbd_data *rpckbd;
103 struct serio *serio;
104 int tx_irq, rx_irq;
106 rx_irq = platform_get_irq(dev, 0);
107 if (rx_irq <= 0)
108 return rx_irq < 0 ? rx_irq : -ENXIO;
110 tx_irq = platform_get_irq(dev, 1);
111 if (tx_irq <= 0)
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) {
117 kfree(rpckbd);
118 kfree(serio);
119 return -ENOMEM;
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);
136 return 0;
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);
145 kfree(rpckbd);
147 return 0;
150 static struct platform_driver rpckbd_driver = {
151 .probe = rpckbd_probe,
152 .remove = rpckbd_remove,
153 .driver = {
154 .name = "kart",
157 module_platform_driver(rpckbd_driver);