adb_kbd.c (185724) | adb_kbd.c (186906) |
---|---|
1/*- 2 * Copyright (C) 2008 Nathan Whitehorn 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 8 unchanged lines hidden (view full) --- 17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * | 1/*- 2 * Copyright (C) 2008 Nathan Whitehorn 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 8 unchanged lines hidden (view full) --- 17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * |
25 * $FreeBSD: head/sys/dev/adb/adb_kbd.c 185724 2008-12-06 23:26:02Z nwhitehorn $ | 25 * $FreeBSD: head/sys/dev/adb/adb_kbd.c 186906 2009-01-08 17:47:45Z nwhitehorn $ |
26 */ 27 28#include <sys/cdefs.h> 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/module.h> 32#include <sys/bus.h> 33#include <sys/conf.h> --- 33 unchanged lines hidden (view full) --- 67 struct cv sc_cv; 68 69 int sc_mode; 70 int sc_state; 71 72 int have_led_control; 73 74 uint8_t buffer[8]; | 26 */ 27 28#include <sys/cdefs.h> 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/module.h> 32#include <sys/bus.h> 33#include <sys/conf.h> --- 33 unchanged lines hidden (view full) --- 67 struct cv sc_cv; 68 69 int sc_mode; 70 int sc_state; 71 72 int have_led_control; 73 74 uint8_t buffer[8]; |
75#ifdef AKBD_EMULATE_ATKBD 76 uint8_t at_buffered_char[2]; 77#endif |
|
75 volatile int buffers; 76 77 struct callout sc_repeater; 78 int sc_repeatstart; 79 int sc_repeatcontinue; 80 uint8_t last_press; 81}; 82 --- 17 unchanged lines hidden (view full) --- 100 adb_kbd_methods, 101 sizeof(struct adb_kbd_softc), 102}; 103 104static devclass_t adb_kbd_devclass; 105 106DRIVER_MODULE(akbd, adb, adb_kbd_driver, adb_kbd_devclass, 0, 0); 107 | 78 volatile int buffers; 79 80 struct callout sc_repeater; 81 int sc_repeatstart; 82 int sc_repeatcontinue; 83 uint8_t last_press; 84}; 85 --- 17 unchanged lines hidden (view full) --- 103 adb_kbd_methods, 104 sizeof(struct adb_kbd_softc), 105}; 106 107static devclass_t adb_kbd_devclass; 108 109DRIVER_MODULE(akbd, adb, adb_kbd_driver, adb_kbd_devclass, 0, 0); 110 |
111#ifdef AKBD_EMULATE_ATKBD 112 113#define SCAN_PRESS 0x000 114#define SCAN_RELEASE 0x080 115#define SCAN_PREFIX_E0 0x100 116#define SCAN_PREFIX_E1 0x200 117#define SCAN_PREFIX_CTL 0x400 118#define SCAN_PREFIX_SHIFT 0x800 119#define SCAN_PREFIX (SCAN_PREFIX_E0 | SCAN_PREFIX_E1 | \ 120 SCAN_PREFIX_CTL | SCAN_PREFIX_SHIFT) 121 |
|
108static const uint8_t adb_to_at_scancode_map[128] = { 30, 31, 32, 33, 35, 34, 109 44, 45, 46, 47, 0, 48, 16, 17, 18, 19, 21, 20, 2, 3, 4, 5, 7, 6, 13, 110 10, 8, 12, 9, 11, 27, 24, 22, 26, 23, 25, 28, 38, 36, 40, 37, 39, 43, 111 51, 53, 49, 50, 52, 15, 57, 41, 14, 0, 1, 29, 0, 42, 58, 56, 97, 98, 112 100, 95, 0, 0, 83, 0, 55, 0, 78, 0, 69, 0, 0, 0, 91, 89, 0, 74, 13, 0, 113 0, 82, 79, 80, 81, 75, 76, 77, 71, 0, 72, 73, 0, 0, 0, 63, 64, 65, 61, 114 66, 67, 0, 87, 0, 105, 0, 70, 0, 68, 0, 88, 0, 107, 102, 94, 96, 103, 115 62, 99, 60, 101, 59, 54, 93, 90, 0, 0 }; 116 | 122static const uint8_t adb_to_at_scancode_map[128] = { 30, 31, 32, 33, 35, 34, 123 44, 45, 46, 47, 0, 48, 16, 17, 18, 19, 21, 20, 2, 3, 4, 5, 7, 6, 13, 124 10, 8, 12, 9, 11, 27, 24, 22, 26, 23, 25, 28, 38, 36, 40, 37, 39, 43, 125 51, 53, 49, 50, 52, 15, 57, 41, 14, 0, 1, 29, 0, 42, 58, 56, 97, 98, 126 100, 95, 0, 0, 83, 0, 55, 0, 78, 0, 69, 0, 0, 0, 91, 89, 0, 74, 13, 0, 127 0, 82, 79, 80, 81, 75, 76, 77, 71, 0, 72, 73, 0, 0, 0, 63, 64, 65, 61, 128 66, 67, 0, 87, 0, 105, 0, 70, 0, 68, 0, 88, 0, 107, 102, 94, 96, 103, 129 62, 99, 60, 101, 59, 54, 93, 90, 0, 0 }; 130 |
131static int 132keycode2scancode(int keycode, int shift, int up) 133{ 134 static const int scan[] = { 135 /* KP enter, right ctrl, KP divide */ 136 0x1c , 0x1d , 0x35 , 137 /* print screen */ 138 0x37 | SCAN_PREFIX_SHIFT, 139 /* right alt, home, up, page up, left, right, end */ 140 0x38, 0x47, 0x48, 0x49, 0x4b, 0x4d, 0x4f, 141 /* down, page down, insert, delete */ 142 0x50, 0x51, 0x52, 0x53, 143 /* pause/break (see also below) */ 144 0x46, 145 /* 146 * MS: left window, right window, menu 147 * also Sun: left meta, right meta, compose 148 */ 149 0x5b, 0x5c, 0x5d, 150 /* Sun type 6 USB */ 151 /* help, stop, again, props, undo, front, copy */ 152 0x68, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 153 /* open, paste, find, cut, audiomute, audiolower, audioraise */ 154 0x64, 0x65, 0x66, 0x67, 0x25, 0x1f, 0x1e, 155 /* power */ 156 0x20 157 }; 158 int scancode; 159 160 scancode = keycode; 161 if ((keycode >= 89) && (keycode < 89 + sizeof(scan) / sizeof(scan[0]))) 162 scancode = scan[keycode - 89] | SCAN_PREFIX_E0; 163 /* pause/break */ 164 if ((keycode == 104) && !(shift & CTLS)) 165 scancode = 0x45 | SCAN_PREFIX_E1 | SCAN_PREFIX_CTL; 166 if (shift & SHIFTS) 167 scancode &= ~SCAN_PREFIX_SHIFT; 168 return (scancode | (up ? SCAN_RELEASE : SCAN_PRESS)); 169} 170#endif 171 |
|
117/* keyboard driver declaration */ 118static int akbd_configure(int flags); 119static kbd_probe_t akbd_probe; 120static kbd_init_t akbd_init; 121static kbd_term_t akbd_term; 122static kbd_intr_t akbd_interrupt; 123static kbd_test_if_t akbd_test_if; 124static kbd_enable_t akbd_enable; --- 338 unchanged lines hidden (view full) --- 463 struct adb_kbd_softc *sc; 464 465 if (!KBD_IS_ACTIVE(kbd)) 466 return (FALSE); 467 468 sc = (struct adb_kbd_softc *)(kbd); 469 470 mtx_lock(&sc->sc_mutex); | 172/* keyboard driver declaration */ 173static int akbd_configure(int flags); 174static kbd_probe_t akbd_probe; 175static kbd_init_t akbd_init; 176static kbd_term_t akbd_term; 177static kbd_intr_t akbd_interrupt; 178static kbd_test_if_t akbd_test_if; 179static kbd_enable_t akbd_enable; --- 338 unchanged lines hidden (view full) --- 518 struct adb_kbd_softc *sc; 519 520 if (!KBD_IS_ACTIVE(kbd)) 521 return (FALSE); 522 523 sc = (struct adb_kbd_softc *)(kbd); 524 525 mtx_lock(&sc->sc_mutex); |
526#ifdef AKBD_EMULATE_ATKBD 527 if (sc->at_buffered_char[0]) { 528 mtx_unlock(&sc->sc_mutex); 529 return (TRUE); 530 } 531#endif 532 |
|
471 if (sc->buffers > 0) { 472 mtx_unlock(&sc->sc_mutex); 473 return (TRUE); 474 } 475 mtx_unlock(&sc->sc_mutex); 476 477 return (FALSE); 478} 479 480static u_int 481akbd_read_char(keyboard_t *kbd, int wait) 482{ 483 struct adb_kbd_softc *sc; | 533 if (sc->buffers > 0) { 534 mtx_unlock(&sc->sc_mutex); 535 return (TRUE); 536 } 537 mtx_unlock(&sc->sc_mutex); 538 539 return (FALSE); 540} 541 542static u_int 543akbd_read_char(keyboard_t *kbd, int wait) 544{ 545 struct adb_kbd_softc *sc; |
484 uint8_t adb_code, final_scancode; | 546 uint16_t key; 547 uint8_t adb_code; |
485 int i; 486 487 sc = (struct adb_kbd_softc *)(kbd); 488 489 mtx_lock(&sc->sc_mutex); | 548 int i; 549 550 sc = (struct adb_kbd_softc *)(kbd); 551 552 mtx_lock(&sc->sc_mutex); |
490 if (!sc->buffers && wait) 491 cv_wait(&sc->sc_cv,&sc->sc_mutex); | |
492 | 553 |
493 if (!sc->buffers) { 494 mtx_unlock(&sc->sc_mutex); 495 return (0); | 554#if defined(AKBD_EMULATE_ATKBD) 555 if (sc->sc_mode == K_RAW && sc->at_buffered_char[0]) { 556 key = sc->at_buffered_char[0]; 557 if (key & SCAN_PREFIX) { 558 sc->at_buffered_char[0] = key & ~SCAN_PREFIX; 559 key = (key & SCAN_PREFIX_E0) ? 0xe0 : 0xe1; 560 } else { 561 sc->at_buffered_char[0] = sc->at_buffered_char[1]; 562 sc->at_buffered_char[1] = 0; |
496 } 497 | 563 } 564 |
498 adb_code = sc->buffer[0]; | 565 mtx_unlock(&sc->sc_mutex); |
499 | 566 |
500 for (i = 1; i < sc->buffers; i++) 501 sc->buffer[i-1] = sc->buffer[i]; | 567 return (key); 568 } 569#endif |
502 | 570 |
503 sc->buffers--; 504 mtx_unlock(&sc->sc_mutex); | 571 if (!sc->buffers && wait) 572 cv_wait(&sc->sc_cv,&sc->sc_mutex); |
505 | 573 |
574 if (!sc->buffers) { 575 mtx_unlock(&sc->sc_mutex); 576 return (0); 577 } 578 579 adb_code = sc->buffer[0]; 580 581 for (i = 1; i < sc->buffers; i++) 582 sc->buffer[i-1] = sc->buffer[i]; 583 584 sc->buffers--; 585 |
|
506 #ifdef AKBD_EMULATE_ATKBD | 586 #ifdef AKBD_EMULATE_ATKBD |
507 final_scancode = adb_to_at_scancode_map[adb_code & 0x7f]; 508 final_scancode |= adb_code & 0x80; | 587 key = adb_to_at_scancode_map[adb_code & 0x7f]; 588 if (sc->sc_mode == K_CODE) { 589 /* Add the key-release bit */ 590 key |= adb_code & 0x80; 591 } else if (sc->sc_mode == K_RAW) { 592 /* 593 * In the raw case, we have to emulate the gross 594 * variable-length AT keyboard thing. Since this code 595 * is copied from sunkbd, which is the same code 596 * as ukbd, it might be nice to have this centralized. 597 */ 598 599 key = keycode2scancode(key, 600 0, adb_code & 0x80); 601 602 if (key & SCAN_PREFIX) { 603 if (key & SCAN_PREFIX_CTL) { 604 sc->at_buffered_char[0] = 605 0x1d | (key & SCAN_RELEASE); 606 sc->at_buffered_char[1] = 607 key & ~SCAN_PREFIX; 608 } else if (key & SCAN_PREFIX_SHIFT) { 609 sc->at_buffered_char[0] = 610 0x2a | (key & SCAN_RELEASE); 611 sc->at_buffered_char[1] = 612 key & ~SCAN_PREFIX_SHIFT; 613 } else { 614 sc->at_buffered_char[0] = 615 key & ~SCAN_PREFIX; 616 sc->at_buffered_char[1] = 0; 617 } 618 619 key = (key & SCAN_PREFIX_E0) ? 0xe0 : 0xe1; 620 } 621 } |
509 #else | 622 #else |
510 final_scancode = adb_code; | 623 key = adb_code; |
511 #endif 512 | 624 #endif 625 |
513 return (final_scancode); | 626 mtx_unlock(&sc->sc_mutex); 627 628 return (key); |
514} 515 516static int 517akbd_check_char(keyboard_t *kbd) 518{ 519 if (!KBD_IS_ACTIVE(kbd)) 520 return (FALSE); 521 --- 121 unchanged lines hidden (view full) --- 643 644static int akbd_lock(keyboard_t *kbd, int lock) 645{ 646 return (0); 647} 648 649static void akbd_clear_state(keyboard_t *kbd) 650{ | 629} 630 631static int 632akbd_check_char(keyboard_t *kbd) 633{ 634 if (!KBD_IS_ACTIVE(kbd)) 635 return (FALSE); 636 --- 121 unchanged lines hidden (view full) --- 758 759static int akbd_lock(keyboard_t *kbd, int lock) 760{ 761 return (0); 762} 763 764static void akbd_clear_state(keyboard_t *kbd) 765{ |
766 struct adb_kbd_softc *sc; 767 768 sc = (struct adb_kbd_softc *)(kbd); 769 770 mtx_lock(&sc->sc_mutex); 771 772 sc->buffers = 0; 773 callout_stop(&sc->sc_repeater); 774 775#if defined(AKBD_EMULATE_ATKBD) 776 sc->at_buffered_char[0] = 0; 777 sc->at_buffered_char[1] = 0; 778#endif 779 mtx_unlock(&sc->sc_mutex); |
|
651} 652 653static int akbd_get_state(keyboard_t *kbd, void *buf, size_t len) 654{ 655 return (0); 656} 657 658static int akbd_set_state(keyboard_t *kbd, void *buf, size_t len) --- 30 unchanged lines hidden --- | 780} 781 782static int akbd_get_state(keyboard_t *kbd, void *buf, size_t len) 783{ 784 return (0); 785} 786 787static int akbd_set_state(keyboard_t *kbd, void *buf, size_t len) --- 30 unchanged lines hidden --- |