30 #include <linux/sched.h>
31 #include <linux/slab.h>
32 #include <linux/module.h>
35 #include <linux/input.h>
36 #include <linux/serio.h>
39 #define DRIVER_DESC "Sun keyboard driver"
45 static unsigned char sunkbd_keycode[128] = {
46 0,128,114,129,115, 59, 60, 68, 61, 87, 62, 88, 63,100, 64,112,
47 65, 66, 67, 56,103,119, 99, 70,105,130,131,108,106, 1, 2, 3,
48 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 41, 14,110,113, 98, 55,
49 116,132, 83,133,102, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
50 26, 27,111,127, 71, 72, 73, 74,134,135,107, 0, 29, 30, 31, 32,
51 33, 34, 35, 36, 37, 38, 39, 40, 43, 28, 96, 75, 76, 77, 82,136,
52 104,137, 69, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,101,
53 79, 80, 81, 0, 0, 0,138, 58,125, 57,126,109, 86, 78
56 #define SUNKBD_CMD_RESET 0x1
57 #define SUNKBD_CMD_BELLON 0x2
58 #define SUNKBD_CMD_BELLOFF 0x3
59 #define SUNKBD_CMD_CLICK 0xa
60 #define SUNKBD_CMD_NOCLICK 0xb
61 #define SUNKBD_CMD_SETLED 0xe
62 #define SUNKBD_CMD_LAYOUT 0xf
64 #define SUNKBD_RET_RESET 0xff
65 #define SUNKBD_RET_ALLUP 0x7f
66 #define SUNKBD_RET_LAYOUT 0xfe
68 #define SUNKBD_LAYOUT_5_MASK 0x20
69 #define SUNKBD_RELEASE 0x80
70 #define SUNKBD_KEY 0x7f
78 struct input_dev *
dev;
100 if (sunkbd->
reset <= -1) {
110 if (sunkbd->
layout == -1) {
135 input_report_key(sunkbd->
dev,
136 sunkbd->
keycode[data & SUNKBD_KEY],
138 input_sync(sunkbd->
dev);
141 "sunkbd.c: Unknown key (scancode %#x) %s.\n",
154 static int sunkbd_event(
struct input_dev *
dev,
157 struct sunkbd *sunkbd = input_get_drvdata(dev);
164 serio_write(sunkbd->
serio,
195 static int sunkbd_initialize(
struct sunkbd *sunkbd)
200 if (sunkbd->
reset < 0)
205 if (sunkbd->
type == 4) {
231 serio_write(sunkbd->
serio,
236 serio_write(sunkbd->
serio,
238 serio_write(sunkbd->
serio,
242 static void sunkbd_enable(
struct sunkbd *sunkbd,
bool enable)
244 serio_pause_rx(sunkbd->
serio);
246 serio_continue_rx(sunkbd->
serio);
254 static int sunkbd_connect(
struct serio *serio,
struct serio_driver *drv)
256 struct sunkbd *sunkbd;
257 struct input_dev *input_dev;
261 sunkbd = kzalloc(
sizeof(
struct sunkbd),
GFP_KERNEL);
262 input_dev = input_allocate_device();
263 if (!sunkbd || !input_dev)
266 sunkbd->
serio = serio;
267 sunkbd->
dev = input_dev;
272 serio_set_drvdata(serio, sunkbd);
278 if (sunkbd_initialize(sunkbd) < 0) {
284 "Sun Type %d keyboard", sunkbd->
type);
287 input_dev->name = sunkbd->
name;
288 input_dev->phys = sunkbd->
phys;
291 input_dev->id.product = sunkbd->
type;
292 input_dev->id.version = 0x0100;
293 input_dev->dev.parent = &serio->
dev;
295 input_set_drvdata(input_dev, sunkbd);
297 input_dev->event = sunkbd_event;
305 input_dev->keycode = sunkbd->
keycode;
306 input_dev->keycodesize =
sizeof(
unsigned char);
307 input_dev->keycodemax =
ARRAY_SIZE(sunkbd_keycode);
308 for (i = 0; i <
ARRAY_SIZE(sunkbd_keycode); i++)
312 sunkbd_enable(sunkbd,
true);
314 err = input_register_device(sunkbd->
dev);
320 fail4: sunkbd_enable(sunkbd,
false);
322 fail2: serio_set_drvdata(serio,
NULL);
323 fail1: input_free_device(input_dev);
332 static void sunkbd_disconnect(
struct serio *serio)
334 struct sunkbd *sunkbd = serio_get_drvdata(serio);
336 sunkbd_enable(sunkbd,
false);
337 input_unregister_device(sunkbd->
dev);
339 serio_set_drvdata(serio,
NULL);
366 .id_table = sunkbd_serio_ids,
367 .interrupt = sunkbd_interrupt,
368 .connect = sunkbd_connect,
369 .disconnect = sunkbd_disconnect,