65 #include <linux/slab.h>
66 #include <linux/module.h>
69 #include <linux/input.h>
70 #include <linux/serio.h>
73 #define DRIVER_DESC "LK keyboard driver"
87 static int bell_volume = 100;
91 static int keyclick_volume = 100;
93 MODULE_PARM_DESC(keyclick_volume,
"Keyclick volume (in %), default is 100%");
95 static int ctrlclick_volume = 100;
97 MODULE_PARM_DESC(ctrlclick_volume,
"Ctrlclick volume (in %), default is 100%");
99 static int lk201_compose_is_alt;
102 "If set non-zero, LK201' Compose key will act as an Alt key");
108 #define DBG(x...) printk(x)
110 #define DBG(x...) do {} while (0)
114 #define LK_LED_WAIT 0x81
115 #define LK_LED_COMPOSE 0x82
116 #define LK_LED_SHIFTLOCK 0x84
117 #define LK_LED_SCROLLLOCK 0x88
118 #define LK_CMD_LED_ON 0x13
119 #define LK_CMD_LED_OFF 0x11
122 #define LK_MODE_DOWN 0x80
123 #define LK_MODE_AUTODOWN 0x82
124 #define LK_MODE_UPDOWN 0x86
125 #define LK_CMD_SET_MODE(mode, div) ((mode) | ((div) << 3))
128 #define LK_CMD_ENABLE_KEYCLICK 0x1b
129 #define LK_CMD_DISABLE_KEYCLICK 0x99
130 #define LK_CMD_DISABLE_BELL 0xa1
131 #define LK_CMD_SOUND_BELL 0xa7
132 #define LK_CMD_ENABLE_BELL 0x23
133 #define LK_CMD_DISABLE_CTRCLICK 0xb9
134 #define LK_CMD_ENABLE_CTRCLICK 0xbb
135 #define LK_CMD_SET_DEFAULTS 0xd3
136 #define LK_CMD_POWERCYCLE_RESET 0xfd
137 #define LK_CMD_ENABLE_LK401 0xe9
138 #define LK_CMD_REQUEST_ID 0xab
141 #define LK_STUCK_KEY 0x3d
142 #define LK_SELFTEST_FAILED 0x3e
143 #define LK_ALL_KEYS_UP 0xb3
144 #define LK_METRONOME 0xb4
145 #define LK_OUTPUT_ERROR 0xb5
146 #define LK_INPUT_ERROR 0xb6
147 #define LK_KBD_LOCKED 0xb7
148 #define LK_KBD_TEST_MODE_ACK 0xb8
149 #define LK_PREFIX_KEY_DOWN 0xb9
150 #define LK_MODE_CHANGE_ACK 0xba
151 #define LK_RESPONSE_RESERVED 0xbb
153 #define LK_NUM_KEYCODES 256
154 #define LK_NUM_IGNORE_BYTES 6
267 #define CHECK_LED(LK, VAR_ON, VAR_OFF, LED, BITS) do { \
268 if (test_bit(LED, (LK)->dev->led)) \
300 #define RESPONSE(x) { .value = (x), .name = #x, }
315 static unsigned char *response_name(
unsigned char value)
320 if (lk_response[i].value == value)
321 return lk_response[
i].name;
330 static unsigned char volume_to_hw(
int volume_percent)
332 unsigned char ret = 0;
334 if (volume_percent < 0)
336 if (volume_percent > 100)
337 volume_percent = 100;
339 if (volume_percent >= 0)
341 if (volume_percent >= 13)
343 if (volume_percent >= 25)
345 if (volume_percent >= 38)
347 if (volume_percent >= 50)
349 if (volume_percent >= 63)
351 if (volume_percent >= 75)
353 if (volume_percent >= 88)
361 static void lkkbd_detection_done(
struct lkkbd *lk)
377 if (lk201_compose_is_alt)
388 "lkkbd: keyboard on %s is unknown, please report to "
415 "lkkbd: Selftest failed on keyboard at %s, "
416 "keyboard may not work properly\n", lk->
phys);
421 "lkkbd: Unknown error %02x on keyboard at %s\n",
431 "Scancode of stuck key is 0x%02x, keycode is 0x%04x\n",
442 struct lkkbd *lk = serio_get_drvdata(serio);
443 struct input_dev *input_dev = lk->
dev;
454 lkkbd_detection_done(lk);
461 for (i = 0; i <
ARRAY_SIZE(lkkbd_keycode); i++)
462 input_report_key(input_dev, lk->
keycode[i], 0);
463 input_sync(input_dev);
467 DBG(
KERN_INFO "Got 0x01, scheduling re-initialization\n");
481 DBG(
KERN_INFO "Got %s and don't know how to handle...\n",
482 response_name(data));
488 input_report_key(input_dev, keycode,
489 !
test_bit(keycode, input_dev->key));
490 input_sync(input_dev);
493 "%s: Unknown key with scancode 0x%02x on %s.\n",
494 __FILE__, data, lk->
name);
501 static void lkkbd_toggle_leds(
struct lkkbd *lk)
503 struct serio *serio = lk->
serio;
504 unsigned char leds_on = 0;
505 unsigned char leds_off = 0;
513 serio_write(serio, leds_on);
517 serio_write(serio, leds_off);
521 static void lkkbd_toggle_keyclick(
struct lkkbd *lk,
bool on)
523 struct serio *serio = lk->
serio;
526 DBG(
"%s: Activating key clicks\n", __func__);
532 DBG(
"%s: Deactivating key clicks\n", __func__);
542 static int lkkbd_event(
struct input_dev *
dev,
543 unsigned int type,
unsigned int code,
int value)
545 struct lkkbd *lk = input_get_drvdata(dev);
549 lkkbd_toggle_leds(lk);
555 lkkbd_toggle_keyclick(lk, value);
569 __func__, type, code, value);
591 lkkbd_toggle_leds(lk);
601 for (division = 1; division <= 14; division++)
602 serio_write(lk->
serio,
620 static int lkkbd_connect(
struct serio *serio,
struct serio_driver *drv)
623 struct input_dev *input_dev;
628 input_dev = input_allocate_device();
629 if (!lk || !input_dev) {
645 input_dev->name = lk->
name;
646 input_dev->phys = lk->
phys;
649 input_dev->id.product = 0;
650 input_dev->id.version = 0x0100;
651 input_dev->dev.parent = &serio->
dev;
652 input_dev->event = lkkbd_event;
654 input_set_drvdata(input_dev, lk);
667 input_dev->keycode = lk->
keycode;
668 input_dev->keycodesize =
sizeof(lk->
keycode[0]);
675 serio_set_drvdata(serio, lk);
681 err = input_register_device(lk->
dev);
690 fail2: serio_set_drvdata(serio,
NULL);
691 fail1: input_free_device(input_dev);
699 static void lkkbd_disconnect(
struct serio *serio)
701 struct lkkbd *lk = serio_get_drvdata(serio);
703 input_get_device(lk->
dev);
704 input_unregister_device(lk->
dev);
706 serio_set_drvdata(serio,
NULL);
707 input_put_device(lk->
dev);
728 .id_table = lkkbd_serio_ids,
729 .connect = lkkbd_connect,
730 .disconnect = lkkbd_disconnect,
731 .interrupt = lkkbd_interrupt,