Lines Matching defs:atkbd
192 * The atkbd control structure
195 struct atkbd {
236 static void (*atkbd_platform_fixup)(struct atkbd *, const void *data);
238 static unsigned int (*atkbd_platform_scancode_fixup)(struct atkbd *, unsigned int);
241 ssize_t (*handler)(struct atkbd *, char *));
243 ssize_t (*handler)(struct atkbd *, const char *, size_t));
245 static ssize_t atkbd_show_##_name(struct atkbd *, char *); \
246 static ssize_t atkbd_set_##_name(struct atkbd *, const char *, size_t); \
268 static ssize_t atkbd_show_##_name(struct atkbd *, char *); \
322 static void atkbd_calculate_xl_bit(struct atkbd *atkbd, unsigned char code)
329 __clear_bit(i, &atkbd->xl_bit);
331 __set_bit(i, &atkbd->xl_bit);
341 static unsigned int atkbd_compat_scancode(struct atkbd *atkbd, unsigned int code)
343 if (atkbd->set == 3) {
344 if (atkbd->emul == 1)
348 if (atkbd->emul == 1)
363 struct atkbd *atkbd = serio_get_drvdata(serio);
364 struct input_dev *dev = atkbd->dev;
373 if ((flags & (SERIO_FRAME | SERIO_PARITY)) && (~flags & SERIO_TIMEOUT) && !atkbd->resend && atkbd->write) {
376 atkbd->resend = true;
381 atkbd->resend = false;
384 if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_ACK))
385 if (ps2_handle_ack(&atkbd->ps2dev, data))
388 if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_CMD))
389 if (ps2_handle_response(&atkbd->ps2dev, data))
392 if (!atkbd->enabled)
398 code = atkbd_platform_scancode_fixup(atkbd, code);
400 if (atkbd->translated) {
402 if (atkbd->emul || atkbd_need_xlate(atkbd->xl_bit, code)) {
403 atkbd->release = code >> 7;
407 if (!atkbd->emul)
408 atkbd_calculate_xl_bit(atkbd, data);
413 atkbd->enabled = false;
414 serio_reconnect(atkbd->ps2dev.serio);
417 atkbd->emul = 1;
420 atkbd->emul = 2;
423 atkbd->release = true;
434 atkbd->err_count++;
440 code = atkbd_compat_scancode(atkbd, code);
442 if (atkbd->emul && --atkbd->emul)
445 keycode = atkbd->keycode[code];
456 atkbd->release ? "released" : "pressed",
457 atkbd->translated ? "translated" : "raw",
458 atkbd->set, code, serio->phys);
477 click = !atkbd->release;
486 if (atkbd->release) {
488 atkbd->last = 0;
489 } else if (!atkbd->softrepeat && test_bit(keycode, dev->key)) {
490 value = time_before(jiffies, atkbd->time) && atkbd->last == code ? 1 : 2;
493 atkbd->last = code;
494 atkbd->time = jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]) / 2;
500 if (value && test_bit(code, atkbd->force_release_mask)) {
506 if (atkbd->scroll) {
510 atkbd->release ? -scroll : scroll);
515 atkbd->release = false;
520 static int atkbd_set_repeat_rate(struct atkbd *atkbd)
528 struct input_dev *dev = atkbd->dev;
541 return ps2_command(&atkbd->ps2dev, ¶m, ATKBD_CMD_SETREP);
544 static int atkbd_set_leds(struct atkbd *atkbd)
546 struct input_dev *dev = atkbd->dev;
552 if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS))
555 if (atkbd->extra) {
562 if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS))
577 struct atkbd *atkbd = container_of(work, struct atkbd, event_work.work);
579 mutex_lock(&atkbd->mutex);
581 if (!atkbd->enabled) {
588 schedule_delayed_work(&atkbd->event_work,
591 if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask))
592 atkbd_set_leds(atkbd);
594 if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask))
595 atkbd_set_repeat_rate(atkbd);
598 mutex_unlock(&atkbd->mutex);
605 static void atkbd_schedule_event_work(struct atkbd *atkbd, int event_bit)
609 if (time_after(jiffies, atkbd->event_jiffies + delay))
612 atkbd->event_jiffies = jiffies;
613 set_bit(event_bit, &atkbd->event_mask);
615 schedule_delayed_work(&atkbd->event_work, delay);
627 struct atkbd *atkbd = input_get_drvdata(dev);
629 if (!atkbd->write)
635 atkbd_schedule_event_work(atkbd, ATKBD_LED_EVENT_BIT);
639 if (!atkbd->softrepeat)
640 atkbd_schedule_event_work(atkbd, ATKBD_REP_EVENT_BIT);
653 static inline void atkbd_enable(struct atkbd *atkbd)
655 serio_pause_rx(atkbd->ps2dev.serio);
656 atkbd->enabled = true;
657 serio_continue_rx(atkbd->ps2dev.serio);
665 static inline void atkbd_disable(struct atkbd *atkbd)
667 serio_pause_rx(atkbd->ps2dev.serio);
668 atkbd->enabled = false;
669 serio_continue_rx(atkbd->ps2dev.serio);
676 static int atkbd_probe(struct atkbd *atkbd)
678 struct ps2dev *ps2dev = &atkbd->ps2dev;
711 atkbd->id = 0xabba;
718 atkbd->id = (param[0] << 8) | param[1];
720 if (atkbd->id == 0xaca1 && atkbd->translated) {
736 static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra)
738 struct ps2dev *ps2dev = &atkbd->ps2dev;
741 atkbd->extra = false;
748 if (atkbd->translated)
751 if (atkbd->id == 0xaca1) {
760 atkbd->extra = true;
769 atkbd->id = param[0] << 8 | param[1];
792 static int atkbd_reset_state(struct atkbd *atkbd)
794 struct ps2dev *ps2dev = &atkbd->ps2dev;
816 static int atkbd_activate(struct atkbd *atkbd)
818 struct ps2dev *ps2dev = &atkbd->ps2dev;
841 struct atkbd *atkbd = serio_get_drvdata(serio);
843 atkbd_disable(atkbd);
844 ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);
854 struct atkbd *atkbd = serio_get_drvdata(serio);
858 atkbd_disable(atkbd);
860 input_unregister_device(atkbd->dev);
864 * Note that since atkbd->enabled is false event work will keep
868 cancel_delayed_work_sync(&atkbd->event_work);
872 kfree(atkbd);
878 static void atkbd_apply_forced_release_keylist(struct atkbd* atkbd,
884 if (atkbd->set == 2)
886 __set_bit(keys[i], atkbd->force_release_mask);
945 static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd,
948 if (atkbd->translated && atkbd->emul == 1 &&
950 atkbd->emul = 0;
962 static void atkbd_set_keycode_table(struct atkbd *atkbd)
967 memset(atkbd->keycode, 0, sizeof(atkbd->keycode));
968 bitmap_zero(atkbd->force_release_mask, ATKBD_KEYMAP_SIZE);
970 if (atkbd->translated) {
973 atkbd->keycode[i] = atkbd_set2_keycode[scancode];
974 atkbd->keycode[i | 0x80] = atkbd_set2_keycode[scancode | 0x80];
975 if (atkbd->scroll)
978 atkbd->keycode[i | 0x80] = atkbd_scroll_keys[j].keycode;
980 } else if (atkbd->set == 3) {
981 memcpy(atkbd->keycode, atkbd_set3_keycode, sizeof(atkbd->keycode));
983 memcpy(atkbd->keycode, atkbd_set2_keycode, sizeof(atkbd->keycode));
985 if (atkbd->scroll)
988 atkbd->keycode[scancode] = atkbd_scroll_keys[i].keycode;
996 scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANGEUL);
997 atkbd->keycode[scancode] = KEY_HANGEUL;
998 __set_bit(scancode, atkbd->force_release_mask);
1000 scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANJA);
1001 atkbd->keycode[scancode] = KEY_HANJA;
1002 __set_bit(scancode, atkbd->force_release_mask);
1008 atkbd_platform_fixup(atkbd, atkbd_platform_fixup_data);
1015 static void atkbd_set_device_attrs(struct atkbd *atkbd)
1017 struct input_dev *input_dev = atkbd->dev;
1020 if (atkbd->extra)
1021 snprintf(atkbd->name, sizeof(atkbd->name),
1024 snprintf(atkbd->name, sizeof(atkbd->name),
1026 atkbd->translated ? "Translated" : "Raw", atkbd->set);
1028 snprintf(atkbd->phys, sizeof(atkbd->phys),
1029 "%s/input0", atkbd->ps2dev.serio->phys);
1031 input_dev->name = atkbd->name;
1032 input_dev->phys = atkbd->phys;
1035 input_dev->id.product = atkbd->translated ? 1 : atkbd->set;
1036 input_dev->id.version = atkbd->id;
1038 input_dev->dev.parent = &atkbd->ps2dev.serio->dev;
1040 input_set_drvdata(input_dev, atkbd);
1045 if (atkbd->write) {
1051 if (atkbd->extra)
1056 if (!atkbd->softrepeat) {
1061 input_dev->mscbit[0] = atkbd->softraw ? BIT_MASK(MSC_SCAN) :
1064 if (atkbd->scroll) {
1071 input_dev->keycode = atkbd->keycode;
1076 if (atkbd->keycode[i] != KEY_RESERVED &&
1077 atkbd->keycode[i] != ATKBD_KEY_NULL &&
1078 atkbd->keycode[i] < ATKBD_SPECIAL) {
1079 __set_bit(atkbd->keycode[i], input_dev->keybit);
1093 struct atkbd *atkbd;
1097 atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL);
1099 if (!atkbd || !dev)
1102 atkbd->dev = dev;
1103 ps2_init(&atkbd->ps2dev, serio);
1104 INIT_DELAYED_WORK(&atkbd->event_work, atkbd_event_work);
1105 mutex_init(&atkbd->mutex);
1110 atkbd->translated = true;
1115 atkbd->write = true;
1119 atkbd->softraw = atkbd_softraw;
1120 atkbd->softrepeat = atkbd_softrepeat;
1121 atkbd->scroll = atkbd_scroll;
1123 if (atkbd->softrepeat)
1124 atkbd->softraw = true;
1126 serio_set_drvdata(serio, atkbd);
1132 if (atkbd->write) {
1134 if (atkbd_probe(atkbd)) {
1139 atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra);
1140 atkbd_reset_state(atkbd);
1141 atkbd_activate(atkbd);
1144 atkbd->set = 2;
1145 atkbd->id = 0xab00;
1148 atkbd_set_keycode_table(atkbd);
1149 atkbd_set_device_attrs(atkbd);
1155 atkbd_enable(atkbd);
1157 err = input_register_device(atkbd->dev);
1167 kfree(atkbd);
1178 struct atkbd *atkbd = serio_get_drvdata(serio);
1182 if (!atkbd || !drv) {
1188 mutex_lock(&atkbd->mutex);
1190 atkbd_disable(atkbd);
1192 if (atkbd->write) {
1193 if (atkbd_probe(atkbd))
1196 if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra))
1199 atkbd_activate(atkbd);
1208 atkbd_set_leds(atkbd);
1209 if (!atkbd->softrepeat)
1210 atkbd_set_repeat_rate(atkbd);
1214 atkbd_enable(atkbd);
1218 mutex_unlock(&atkbd->mutex);
1248 .name = "atkbd",
1260 ssize_t (*handler)(struct atkbd *, char *))
1263 struct atkbd *atkbd = serio_get_drvdata(serio);
1265 return handler(atkbd, buf);
1269 ssize_t (*handler)(struct atkbd *, const char *, size_t))
1272 struct atkbd *atkbd = serio_get_drvdata(serio);
1275 retval = mutex_lock_interruptible(&atkbd->mutex);
1279 atkbd_disable(atkbd);
1280 retval = handler(atkbd, buf, count);
1281 atkbd_enable(atkbd);
1283 mutex_unlock(&atkbd->mutex);
1288 static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
1290 return sprintf(buf, "%d\n", atkbd->extra ? 1 : 0);
1293 static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
1301 if (!atkbd->write)
1307 if (atkbd->extra != value) {
1313 old_dev = atkbd->dev;
1314 old_extra = atkbd->extra;
1315 old_set = atkbd->set;
1321 atkbd->dev = new_dev;
1322 atkbd->set = atkbd_select_set(atkbd, atkbd->set, value);
1323 atkbd_reset_state(atkbd);
1324 atkbd_activate(atkbd);
1325 atkbd_set_keycode_table(atkbd);
1326 atkbd_set_device_attrs(atkbd);
1328 err = input_register_device(atkbd->dev);
1332 atkbd->dev = old_dev;
1333 atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
1334 atkbd_set_keycode_table(atkbd);
1335 atkbd_set_device_attrs(atkbd);
1345 static ssize_t atkbd_show_force_release(struct atkbd *atkbd, char *buf)
1348 atkbd->force_release_mask, ATKBD_KEYMAP_SIZE);
1356 static ssize_t atkbd_set_force_release(struct atkbd *atkbd,
1367 memcpy(atkbd->force_release_mask, new_mask, sizeof(atkbd->force_release_mask));
1372 static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
1374 return sprintf(buf, "%d\n", atkbd->scroll ? 1 : 0);
1377 static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
1387 if (atkbd->scroll != value) {
1388 old_dev = atkbd->dev;
1389 old_scroll = atkbd->scroll;
1395 atkbd->dev = new_dev;
1396 atkbd->scroll = value;
1397 atkbd_set_keycode_table(atkbd);
1398 atkbd_set_device_attrs(atkbd);
1400 err = input_register_device(atkbd->dev);
1404 atkbd->scroll = old_scroll;
1405 atkbd->dev = old_dev;
1406 atkbd_set_keycode_table(atkbd);
1407 atkbd_set_device_attrs(atkbd);
1416 static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
1418 return sprintf(buf, "%d\n", atkbd->set);
1421 static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1429 if (!atkbd->write)
1435 if (atkbd->set != value) {
1436 old_dev = atkbd->dev;
1437 old_extra = atkbd->extra;
1438 old_set = atkbd->set;
1444 atkbd->dev = new_dev;
1445 atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra);
1446 atkbd_reset_state(atkbd);
1447 atkbd_activate(atkbd);
1448 atkbd_set_keycode_table(atkbd);
1449 atkbd_set_device_attrs(atkbd);
1451 err = input_register_device(atkbd->dev);
1455 atkbd->dev = old_dev;
1456 atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
1457 atkbd_set_keycode_table(atkbd);
1458 atkbd_set_device_attrs(atkbd);
1467 static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
1469 return sprintf(buf, "%d\n", atkbd->softrepeat ? 1 : 0);
1472 static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
1479 if (!atkbd->write)
1485 if (atkbd->softrepeat != value) {
1486 old_dev = atkbd->dev;
1487 old_softrepeat = atkbd->softrepeat;
1488 old_softraw = atkbd->softraw;
1494 atkbd->dev = new_dev;
1495 atkbd->softrepeat = value;
1496 if (atkbd->softrepeat)
1497 atkbd->softraw = true;
1498 atkbd_set_device_attrs(atkbd);
1500 err = input_register_device(atkbd->dev);
1504 atkbd->dev = old_dev;
1505 atkbd->softrepeat = old_softrepeat;
1506 atkbd->softraw = old_softraw;
1507 atkbd_set_device_attrs(atkbd);
1517 static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
1519 return sprintf(buf, "%d\n", atkbd->softraw ? 1 : 0);
1522 static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
1532 if (atkbd->softraw != value) {
1533 old_dev = atkbd->dev;
1534 old_softraw = atkbd->softraw;
1540 atkbd->dev = new_dev;
1541 atkbd->softraw = value;
1542 atkbd_set_device_attrs(atkbd);
1544 err = input_register_device(atkbd->dev);
1548 atkbd->dev = old_dev;
1549 atkbd->softraw = old_softraw;
1550 atkbd_set_device_attrs(atkbd);
1559 static ssize_t atkbd_show_err_count(struct atkbd *atkbd, char *buf)
1561 return sprintf(buf, "%lu\n", atkbd->err_count);