1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Stowaway keyboard driver for Linux
7 * Copyright (c) 2006 Marek Vasut
9 * Based on Newton keyboard driver for Linux
16 #include <linux/slab.h>
17 #include <linux/module.h>
18 #include <linux/input.h>
19 #include <linux/serio.h>
21 #define DRIVER_DESC "Stowaway keyboard driver"
23 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
24 MODULE_DESCRIPTION(DRIVER_DESC
);
25 MODULE_LICENSE("GPL");
27 #define SKBD_KEY_MASK 0x7f
28 #define SKBD_RELEASE 0x80
30 static unsigned char skbd_keycode
[128] = {
31 KEY_1
, KEY_2
, KEY_3
, KEY_Z
, KEY_4
, KEY_5
, KEY_6
, KEY_7
,
32 0, KEY_Q
, KEY_W
, KEY_E
, KEY_R
, KEY_T
, KEY_Y
, KEY_GRAVE
,
33 KEY_X
, KEY_A
, KEY_S
, KEY_D
, KEY_F
, KEY_G
, KEY_H
, KEY_SPACE
,
34 KEY_CAPSLOCK
, KEY_TAB
, KEY_LEFTCTRL
, 0, 0, 0, 0, 0,
35 0, 0, 0, KEY_LEFTALT
, 0, 0, 0, 0,
36 0, 0, 0, 0, KEY_C
, KEY_V
, KEY_B
, KEY_N
,
37 KEY_MINUS
, KEY_EQUAL
, KEY_BACKSPACE
, KEY_HOME
, KEY_8
, KEY_9
, KEY_0
, KEY_ESC
,
38 KEY_LEFTBRACE
, KEY_RIGHTBRACE
, KEY_BACKSLASH
, KEY_END
, KEY_U
, KEY_I
, KEY_O
, KEY_P
,
39 KEY_APOSTROPHE
, KEY_ENTER
, KEY_PAGEUP
,0, KEY_J
, KEY_K
, KEY_L
, KEY_SEMICOLON
,
40 KEY_SLASH
, KEY_UP
, KEY_PAGEDOWN
, 0,KEY_M
, KEY_COMMA
, KEY_DOT
, KEY_INSERT
,
41 KEY_DELETE
, KEY_LEFT
, KEY_DOWN
, KEY_RIGHT
, 0, 0, 0,
42 KEY_LEFTSHIFT
, KEY_RIGHTSHIFT
, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0,
45 0, KEY_F1
, KEY_F2
, KEY_F3
, KEY_F4
, KEY_F5
, KEY_F6
, KEY_F7
,
46 KEY_F8
, KEY_F9
, KEY_F10
, KEY_F11
, KEY_F12
, 0, 0, 0
50 unsigned char keycode
[128];
51 struct input_dev
*dev
;
56 static irqreturn_t
skbd_interrupt(struct serio
*serio
, unsigned char data
,
59 struct skbd
*skbd
= serio_get_drvdata(serio
);
60 struct input_dev
*dev
= skbd
->dev
;
62 if (skbd
->keycode
[data
& SKBD_KEY_MASK
]) {
63 input_report_key(dev
, skbd
->keycode
[data
& SKBD_KEY_MASK
],
64 !(data
& SKBD_RELEASE
));
71 static int skbd_connect(struct serio
*serio
, struct serio_driver
*drv
)
74 struct input_dev
*input_dev
;
78 skbd
= kzalloc(sizeof(struct skbd
), GFP_KERNEL
);
79 input_dev
= input_allocate_device();
80 if (!skbd
|| !input_dev
)
84 skbd
->dev
= input_dev
;
85 snprintf(skbd
->phys
, sizeof(skbd
->phys
), "%s/input0", serio
->phys
);
86 memcpy(skbd
->keycode
, skbd_keycode
, sizeof(skbd
->keycode
));
88 input_dev
->name
= "Stowaway Keyboard";
89 input_dev
->phys
= skbd
->phys
;
90 input_dev
->id
.bustype
= BUS_RS232
;
91 input_dev
->id
.vendor
= SERIO_STOWAWAY
;
92 input_dev
->id
.product
= 0x0001;
93 input_dev
->id
.version
= 0x0100;
94 input_dev
->dev
.parent
= &serio
->dev
;
96 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
);
97 input_dev
->keycode
= skbd
->keycode
;
98 input_dev
->keycodesize
= sizeof(unsigned char);
99 input_dev
->keycodemax
= ARRAY_SIZE(skbd_keycode
);
100 for (i
= 0; i
< ARRAY_SIZE(skbd_keycode
); i
++)
101 set_bit(skbd_keycode
[i
], input_dev
->keybit
);
102 clear_bit(0, input_dev
->keybit
);
104 serio_set_drvdata(serio
, skbd
);
106 err
= serio_open(serio
, drv
);
110 err
= input_register_device(skbd
->dev
);
116 fail3
: serio_close(serio
);
117 fail2
: serio_set_drvdata(serio
, NULL
);
118 fail1
: input_free_device(input_dev
);
123 static void skbd_disconnect(struct serio
*serio
)
125 struct skbd
*skbd
= serio_get_drvdata(serio
);
128 serio_set_drvdata(serio
, NULL
);
129 input_unregister_device(skbd
->dev
);
133 static const struct serio_device_id skbd_serio_ids
[] = {
136 .proto
= SERIO_STOWAWAY
,
143 MODULE_DEVICE_TABLE(serio
, skbd_serio_ids
);
145 static struct serio_driver skbd_drv
= {
149 .description
= DRIVER_DESC
,
150 .id_table
= skbd_serio_ids
,
151 .interrupt
= skbd_interrupt
,
152 .connect
= skbd_connect
,
153 .disconnect
= skbd_disconnect
,
156 module_serio_driver(skbd_drv
);