treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / input / keyboard / xtkbd.c
blob280796df679a300376e2eeb734e51ea1d292dd4c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 1999-2001 Vojtech Pavlik
4 */
6 /*
7 * XT keyboard driver for Linux
8 */
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/input.h>
16 #include <linux/serio.h>
18 #define DRIVER_DESC "XT keyboard driver"
20 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
21 MODULE_DESCRIPTION(DRIVER_DESC);
22 MODULE_LICENSE("GPL");
24 #define XTKBD_EMUL0 0xe0
25 #define XTKBD_EMUL1 0xe1
26 #define XTKBD_KEY 0x7f
27 #define XTKBD_RELEASE 0x80
29 static unsigned char xtkbd_keycode[256] = {
30 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
31 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
33 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
34 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
35 80, 81, 82, 83, 0, 0, 0, 87, 88, 0, 0, 0, 0, 0, 0, 0,
36 0, 0, 0, 0, 0, 87, 88, 0, 0, 0, 0,110,111,103,108,105,
37 106
40 struct xtkbd {
41 unsigned char keycode[256];
42 struct input_dev *dev;
43 struct serio *serio;
44 char phys[32];
47 static irqreturn_t xtkbd_interrupt(struct serio *serio,
48 unsigned char data, unsigned int flags)
50 struct xtkbd *xtkbd = serio_get_drvdata(serio);
52 switch (data) {
53 case XTKBD_EMUL0:
54 case XTKBD_EMUL1:
55 break;
56 default:
58 if (xtkbd->keycode[data & XTKBD_KEY]) {
59 input_report_key(xtkbd->dev, xtkbd->keycode[data & XTKBD_KEY], !(data & XTKBD_RELEASE));
60 input_sync(xtkbd->dev);
61 } else {
62 printk(KERN_WARNING "xtkbd.c: Unknown key (scancode %#x) %s.\n",
63 data & XTKBD_KEY, data & XTKBD_RELEASE ? "released" : "pressed");
66 return IRQ_HANDLED;
69 static int xtkbd_connect(struct serio *serio, struct serio_driver *drv)
71 struct xtkbd *xtkbd;
72 struct input_dev *input_dev;
73 int err = -ENOMEM;
74 int i;
76 xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL);
77 input_dev = input_allocate_device();
78 if (!xtkbd || !input_dev)
79 goto fail1;
81 xtkbd->serio = serio;
82 xtkbd->dev = input_dev;
83 snprintf(xtkbd->phys, sizeof(xtkbd->phys), "%s/input0", serio->phys);
84 memcpy(xtkbd->keycode, xtkbd_keycode, sizeof(xtkbd->keycode));
86 input_dev->name = "XT Keyboard";
87 input_dev->phys = xtkbd->phys;
88 input_dev->id.bustype = BUS_XTKBD;
89 input_dev->id.vendor = 0x0001;
90 input_dev->id.product = 0x0001;
91 input_dev->id.version = 0x0100;
92 input_dev->dev.parent = &serio->dev;
94 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
95 input_dev->keycode = xtkbd->keycode;
96 input_dev->keycodesize = sizeof(unsigned char);
97 input_dev->keycodemax = ARRAY_SIZE(xtkbd_keycode);
99 for (i = 0; i < 255; i++)
100 set_bit(xtkbd->keycode[i], input_dev->keybit);
101 clear_bit(0, input_dev->keybit);
103 serio_set_drvdata(serio, xtkbd);
105 err = serio_open(serio, drv);
106 if (err)
107 goto fail2;
109 err = input_register_device(xtkbd->dev);
110 if (err)
111 goto fail3;
113 return 0;
115 fail3: serio_close(serio);
116 fail2: serio_set_drvdata(serio, NULL);
117 fail1: input_free_device(input_dev);
118 kfree(xtkbd);
119 return err;
122 static void xtkbd_disconnect(struct serio *serio)
124 struct xtkbd *xtkbd = serio_get_drvdata(serio);
126 serio_close(serio);
127 serio_set_drvdata(serio, NULL);
128 input_unregister_device(xtkbd->dev);
129 kfree(xtkbd);
132 static const struct serio_device_id xtkbd_serio_ids[] = {
134 .type = SERIO_XT,
135 .proto = SERIO_ANY,
136 .id = SERIO_ANY,
137 .extra = SERIO_ANY,
139 { 0 }
142 MODULE_DEVICE_TABLE(serio, xtkbd_serio_ids);
144 static struct serio_driver xtkbd_drv = {
145 .driver = {
146 .name = "xtkbd",
148 .description = DRIVER_DESC,
149 .id_table = xtkbd_serio_ids,
150 .interrupt = xtkbd_interrupt,
151 .connect = xtkbd_connect,
152 .disconnect = xtkbd_disconnect,
155 module_serio_driver(xtkbd_drv);