Lines Matching refs:kb8042

122 static void kb8042_init(struct kb8042 *kb8042, boolean_t from_resume);
124 static void kb8042_wait_poweron(struct kb8042 *kb8042);
125 static void kb8042_send_to_keyboard(struct kb8042 *, int, boolean_t);
127 static void kb8042_setled(struct kb8042 *, int led_state, boolean_t polled);
133 static void kb8042_get_initial_leds(struct kb8042 *, int *, int *);
134 static boolean_t kb8042_autorepeat_detect(struct kb8042 *kb8042, int key_pos,
136 static void kb8042_type4_cmd(struct kb8042 *kb8042, int cmd);
137 static void kb8042_ioctlmsg(struct kb8042 *kb8042, queue_t *, mblk_t *);
139 static void kb8042_process_key(struct kb8042 *, kbtrans_key_t, enum keystate);
142 static void kb8042_cleanup(struct kb8042 *kb8042);
179 struct kb8042 Kdws = {0};
265 kb8042_is_input_avail(struct kb8042 *kb8042, int timeout_usec, boolean_t polled) in kb8042_is_input_avail() argument
273 if (ddi_get8(kb8042->handle, kb8042->addr + port) != 0) in kb8042_is_input_avail()
283 kb8042_clear_input_buffer(struct kb8042 *kb8042, boolean_t polled) in kb8042_clear_input_buffer() argument
288 while (kb8042_is_input_avail(kb8042, MIN_DELAY_USECS, polled)) { in kb8042_clear_input_buffer()
289 (void) ddi_get8(kb8042->handle, kb8042->addr + port); in kb8042_clear_input_buffer()
297 kb8042_send_and_expect(struct kb8042 *kb8042, uint8_t send, uint8_t expect, in kb8042_send_and_expect() argument
304 ddi_put8(kb8042->handle, in kb8042_send_and_expect()
305 kb8042->addr + I8042_POLL_OUTPUT_DATA, send); in kb8042_send_and_expect()
307 if (kb8042_is_input_avail(kb8042, timeout, B_TRUE)) { in kb8042_send_and_expect()
309 datab = ddi_get8(kb8042->handle, in kb8042_send_and_expect()
310 kb8042->addr + I8042_POLL_INPUT_DATA); in kb8042_send_and_expect()
342 kb8042_read_scanset(struct kb8042 *kb8042) in kb8042_read_scanset() argument
348 kb8042_clear_input_buffer(kb8042, B_TRUE); in kb8042_read_scanset()
354 if (kb8042_send_and_expect(kb8042, KB_SET_SCAN, KB_ACK, MAX_WAIT_USECS, in kb8042_read_scanset()
363 if (kb8042_send_and_expect(kb8042, 0, KB_ACK, MAX_WAIT_USECS, &err, in kb8042_read_scanset()
373 while (kb8042_is_input_avail(kb8042, MAX_WAIT_USECS, B_TRUE) && in kb8042_read_scanset()
374 (scanset = ddi_get8(kb8042->handle, in kb8042_read_scanset()
375 kb8042->addr + I8042_POLL_INPUT_DATA)) == KB_ACK) in kb8042_read_scanset()
406 struct kb8042 *kb8042 = &Kdws; in kb8042_attach() local
415 leds = kb8042->leds.commanded; in kb8042_attach()
416 kb8042->w_init = 0; in kb8042_attach()
417 kb8042_init(kb8042, B_TRUE); in kb8042_attach()
418 kb8042_setled(kb8042, leds, B_FALSE); in kb8042_attach()
419 mutex_enter(&kb8042->w_hw_mutex); in kb8042_attach()
420 kb8042->suspended = B_FALSE; in kb8042_attach()
421 if (kb8042->w_qp != NULL) { in kb8042_attach()
422 enableok(WR(kb8042->w_qp)); in kb8042_attach()
423 qenable(WR(kb8042->w_qp)); in kb8042_attach()
425 cv_broadcast(&kb8042->suspend_cv); in kb8042_attach()
426 mutex_exit(&kb8042->w_hw_mutex); in kb8042_attach()
439 kb8042->debugger.mod1 = 58; /* Left Ctrl */ in kb8042_attach()
440 kb8042->debugger.mod2 = 60; /* Left Alt */ in kb8042_attach()
441 kb8042->debugger.trigger = 33; /* D */ in kb8042_attach()
442 kb8042->debugger.mod1_down = B_FALSE; in kb8042_attach()
443 kb8042->debugger.mod2_down = B_FALSE; in kb8042_attach()
444 kb8042->debugger.enabled = B_FALSE; in kb8042_attach()
447 kb8042->init_state = KB8042_UNINITIALIZED; in kb8042_attach()
449 kb8042->polled_synthetic_release_pending = B_FALSE; in kb8042_attach()
456 kb8042->init_state |= KB8042_MINOR_NODE_CREATED; in kb8042_attach()
458 rc = ddi_regs_map_setup(devi, 0, (caddr_t *)&kb8042->addr, in kb8042_attach()
459 (offset_t)0, (offset_t)0, &attr, &kb8042->handle); in kb8042_attach()
467 kb8042->init_state |= KB8042_REGS_MAPPED; in kb8042_attach()
469 if (ddi_get_iblock_cookie(devi, 0, &kb8042->w_iblock) != in kb8042_attach()
475 mutex_init(&kb8042->w_hw_mutex, NULL, MUTEX_DRIVER, kb8042->w_iblock); in kb8042_attach()
476 cv_init(&kb8042->ops_cv, NULL, CV_DRIVER, NULL); in kb8042_attach()
477 cv_init(&kb8042->suspend_cv, NULL, CV_DRIVER, NULL); in kb8042_attach()
478 cv_init(&kb8042->cmd_cv, NULL, CV_DRIVER, NULL); in kb8042_attach()
479 kb8042->init_state |= KB8042_HW_MUTEX_INITTED; in kb8042_attach()
481 kb8042_init(kb8042, B_FALSE); in kb8042_attach()
485 scanset = kb8042_read_scanset(kb8042); in kb8042_attach()
510 if (KeyboardConvertScan_init(kb8042, scanset) != DDI_SUCCESS) { in kb8042_attach()
521 &kb8042->w_iblock, (ddi_idevice_cookie_t *)NULL, in kb8042_attach()
522 kb8042_intr, (caddr_t)kb8042) != DDI_SUCCESS) { in kb8042_attach()
527 kb8042->init_state |= KB8042_INTR_ADDED; in kb8042_attach()
539 kb8042_cleanup(kb8042); in kb8042_attach()
546 struct kb8042 *kb8042 = &Kdws; in kb8042_detach() local
550 mutex_enter(&kb8042->w_hw_mutex); in kb8042_detach()
551 ASSERT(kb8042->ops >= 0); in kb8042_detach()
552 while (kb8042->ops > 0) in kb8042_detach()
553 cv_wait(&kb8042->ops_cv, &kb8042->w_hw_mutex); in kb8042_detach()
554 kb8042->suspended = B_TRUE; in kb8042_detach()
555 mutex_exit(&kb8042->w_hw_mutex); in kb8042_detach()
560 if (kb8042->w_qp != NULL) in kb8042_detach()
565 kb8042_cleanup(kb8042); in kb8042_detach()
605 kb8042_cleanup(struct kb8042 *kb8042) in kb8042_cleanup() argument
609 if (kb8042->init_state & KB8042_INTR_ADDED) in kb8042_cleanup()
610 ddi_remove_intr(kb8042_dip, 0, kb8042->w_iblock); in kb8042_cleanup()
612 if (kb8042->init_state & KB8042_HW_MUTEX_INITTED) { in kb8042_cleanup()
613 cv_destroy(&kb8042->cmd_cv); in kb8042_cleanup()
614 cv_destroy(&kb8042->suspend_cv); in kb8042_cleanup()
615 cv_destroy(&kb8042->ops_cv); in kb8042_cleanup()
616 mutex_destroy(&kb8042->w_hw_mutex); in kb8042_cleanup()
619 if (kb8042->init_state & KB8042_REGS_MAPPED) in kb8042_cleanup()
620 ddi_regs_map_free(&kb8042->handle); in kb8042_cleanup()
622 if (kb8042->init_state & KB8042_MINOR_NODE_CREATED) in kb8042_cleanup()
625 kb8042->init_state = KB8042_UNINITIALIZED; in kb8042_cleanup()
630 kb8042_init(struct kb8042 *kb8042, boolean_t from_resume) in kb8042_init() argument
632 if (kb8042->w_init) in kb8042_init()
636 kb8042->w_kblayout = 0; /* Default to US */ in kb8042_init()
637 kb8042->w_qp = (queue_t *)NULL; in kb8042_init()
638 kb8042->simulated_kbd_type = KB_PC; in kb8042_init()
639 kb8042->leds.commanded = -1; /* Unknown initial state */ in kb8042_init()
640 kb8042->leds.desired = -1; /* Unknown initial state */ in kb8042_init()
643 kb8042_wait_poweron(kb8042); in kb8042_init()
645 kb8042->kb_old_key_pos = 0; in kb8042_init()
652 (void) ddi_get8(kb8042->handle, kb8042->addr + I8042_LOCK); in kb8042_init()
654 kb8042_send_to_keyboard(kb8042, KB_ENABLE, B_TRUE); in kb8042_init()
655 (void) ddi_get8(kb8042->handle, kb8042->addr + I8042_UNLOCK); in kb8042_init()
657 kb8042->w_init++; in kb8042_init()
666 struct kb8042 *kb8042; in kb8042_open() local
671 kb8042 = &Kdws; in kb8042_open()
673 mutex_enter(&kb8042->w_hw_mutex); in kb8042_open()
675 kb8042->w_dev = *devp; in kb8042_open()
676 mutex_exit(&kb8042->w_hw_mutex); in kb8042_open()
681 mutex_exit(&kb8042->w_hw_mutex); in kb8042_open()
685 while (kb8042->suspended) { in kb8042_open()
686 if (cv_wait_sig(&kb8042->suspend_cv, &kb8042->w_hw_mutex) == in kb8042_open()
688 mutex_exit(&kb8042->w_hw_mutex); in kb8042_open()
693 kb8042->w_dev = *devp; in kb8042_open()
694 qp->q_ptr = (caddr_t)kb8042; in kb8042_open()
696 if (!kb8042->w_qp) in kb8042_open()
697 kb8042->w_qp = qp; in kb8042_open()
699 ASSERT(kb8042->ops >= 0); in kb8042_open()
700 kb8042->ops++; in kb8042_open()
701 mutex_exit(&kb8042->w_hw_mutex); in kb8042_open()
703 kb8042_get_initial_leds(kb8042, &initial_leds, &initial_led_mask); in kb8042_open()
705 (struct kbtrans_hardware *)kb8042, &kb8042_callbacks, in kb8042_open()
706 &kb8042->hw_kbtrans, in kb8042_open()
711 kbtrans_streams_set_keyboard(kb8042->hw_kbtrans, KB_PC, &keyindex_pc); in kb8042_open()
713 kb8042->polledio.cons_polledio_version = CONSPOLLEDIO_V1; in kb8042_open()
714 kb8042->polledio.cons_polledio_argument = in kb8042_open()
715 (cons_polledio_arg_t)kb8042; in kb8042_open()
716 kb8042->polledio.cons_polledio_putchar = NULL; in kb8042_open()
717 kb8042->polledio.cons_polledio_getchar = in kb8042_open()
719 kb8042->polledio.cons_polledio_ischar = in kb8042_open()
721 kb8042->polledio.cons_polledio_enter = NULL; in kb8042_open()
722 kb8042->polledio.cons_polledio_exit = NULL; in kb8042_open()
723 kb8042->polledio.cons_polledio_setled = in kb8042_open()
725 kb8042->polledio.cons_polledio_keycheck = in kb8042_open()
731 kbtrans_streams_enable(kb8042->hw_kbtrans); in kb8042_open()
734 mutex_enter(&kb8042->w_hw_mutex); in kb8042_open()
735 ASSERT(kb8042->ops > 0); in kb8042_open()
736 kb8042->ops--; in kb8042_open()
737 if (kb8042->ops == 0) in kb8042_open()
738 cv_broadcast(&kb8042->ops_cv); in kb8042_open()
739 mutex_exit(&kb8042->w_hw_mutex); in kb8042_open()
748 struct kb8042 *kb8042; in kb8042_close() local
753 kb8042 = (struct kb8042 *)qp->q_ptr; in kb8042_close()
755 mutex_enter(&kb8042->w_hw_mutex); in kb8042_close()
756 while (kb8042->suspended) { in kb8042_close()
757 if (cv_wait_sig(&kb8042->suspend_cv, &kb8042->w_hw_mutex) == in kb8042_close()
759 mutex_exit(&kb8042->w_hw_mutex); in kb8042_close()
764 ASSERT(kb8042->ops >= 0); in kb8042_close()
765 kb8042->ops++; in kb8042_close()
766 mutex_exit(&kb8042->w_hw_mutex); in kb8042_close()
768 (void) kbtrans_streams_fini(kb8042->hw_kbtrans); in kb8042_close()
770 kb8042->w_qp = (queue_t *)NULL; in kb8042_close()
773 mutex_enter(&kb8042->w_hw_mutex); in kb8042_close()
774 ASSERT(kb8042->ops > 0); in kb8042_close()
775 kb8042->ops--; in kb8042_close()
776 if (kb8042->ops == 0) in kb8042_close()
777 cv_broadcast(&kb8042->ops_cv); in kb8042_close()
778 mutex_exit(&kb8042->w_hw_mutex); in kb8042_close()
786 struct kb8042 *kb8042; local
791 kb8042 = (struct kb8042 *)qp->q_ptr;
793 mutex_enter(&kb8042->w_hw_mutex);
794 suspended = kb8042->suspended;
795 ASSERT(kb8042->ops >= 0);
797 kb8042->ops++;
798 mutex_exit(&kb8042->w_hw_mutex);
810 switch (kbtrans_streams_message(kb8042->hw_kbtrans, mp)) {
818 kb8042_ioctlmsg(kb8042, qp, mp);
844 mutex_enter(&kb8042->w_hw_mutex);
846 ASSERT(kb8042->ops > 0);
847 kb8042->ops--;
848 if (kb8042->ops == 0)
849 cv_broadcast(&kb8042->ops_cv);
851 mutex_exit(&kb8042->w_hw_mutex);
857 kb8042_ioctlmsg(struct kb8042 *kb8042, queue_t *qp, mblk_t *mp) argument
883 &kb8042->polledio;
899 kb8042->debugger.enabled = *(intptr_t *)mp->b_cont->b_rptr;
917 kb8042->simulated_kbd_type = tmp;
922 if (kb8042->w_kblayout == -1) {
932 if (kb8042->simulated_kbd_type == KB_USB)
935 *(int *)datap->b_wptr = kb8042->w_kblayout;
953 kb8042->w_kblayout = *(intptr_t *)mp->b_cont->b_rptr;
964 kb8042_type4_cmd(kb8042, *(int *)mp->b_cont->b_rptr);
1009 struct kb8042 *kb8042, argument
1022 mutex_enter(&kb8042->w_hw_mutex);
1023 kb8042->acked = 1;
1024 cv_signal(&kb8042->cmd_cv);
1025 mutex_exit(&kb8042->w_hw_mutex);
1028 mutex_enter(&kb8042->w_hw_mutex);
1029 kb8042->need_retry = 1;
1030 cv_signal(&kb8042->cmd_cv);
1031 mutex_exit(&kb8042->w_hw_mutex);
1035 if (!kb8042->w_init) /* can't do anything anyway */
1038 legit = KeyboardConvertScan(kb8042, scancode, &key_pos, &state,
1050 if (key_pos == kb8042->debugger.mod1) {
1051 kb8042->debugger.mod1_down = (state == KEY_PRESSED);
1053 if (key_pos == kb8042->debugger.mod2) {
1054 kb8042->debugger.mod2_down = (state == KEY_PRESSED);
1056 if (kb8042->debugger.enabled &&
1057 key_pos == kb8042->debugger.trigger &&
1058 kb8042->debugger.mod1_down &&
1059 kb8042->debugger.mod2_down) {
1063 kb8042->debugger.mod1_down = B_FALSE;
1064 kb8042->debugger.mod2_down = B_FALSE;
1075 if (kb8042->w_qp == NULL) {
1085 if (kb8042_autorepeat_detect(kb8042, key_pos, state)) {
1090 kb8042_process_key(kb8042, key_pos, state);
1098 (void) kb8042_autorepeat_detect(kb8042, key_pos, KEY_RELEASED);
1099 kb8042_process_key(kb8042, key_pos, state);
1105 kb8042_process_key(struct kb8042 *kb8042, kbtrans_key_t key_pos, argument
1111 if (kb8042->simulated_kbd_type == KB_PC) {
1112 kbtrans_streams_key(kb8042->hw_kbtrans, key_pos, state);
1113 } else if (kb8042->simulated_kbd_type == KB_USB) {
1116 kbtrans_streams_key(kb8042->hw_kbtrans, key, state);
1129 struct kb8042 *kb8042 = (struct kb8042 *)arg; local
1133 if (kb8042->init_state == KB8042_UNINITIALIZED)
1139 while (ddi_get8(kb8042->handle, kb8042->addr + I8042_INT_INPUT_AVAIL)
1143 scancode = ddi_get8(kb8042->handle,
1144 kb8042->addr + I8042_INT_INPUT_DATA);
1146 kb8042_received_byte(kb8042, scancode);
1176 struct kb8042 *kb8042 = (struct kb8042 *)hw; local
1181 if (kb8042->polled_synthetic_release_pending) {
1182 *key = kb8042->polled_synthetic_release_key;
1184 kb8042->polled_synthetic_release_pending = B_FALSE;
1185 (void) kb8042_autorepeat_detect(kb8042, *key, *state);
1190 if (ddi_get8(kb8042->handle,
1191 kb8042->addr + I8042_POLL_INPUT_AVAIL) == 0) {
1195 scancode = ddi_get8(kb8042->handle,
1196 kb8042->addr + I8042_POLL_INPUT_DATA);
1198 legit = KeyboardConvertScan(kb8042, scancode, key, state,
1209 (void) kb8042_autorepeat_detect(kb8042, *key, *state);
1219 kb8042->polled_synthetic_release_pending = B_TRUE;
1220 kb8042->polled_synthetic_release_key = *key;
1223 if (kb8042->simulated_kbd_type == KB_USB) {
1231 kb8042_setled(struct kb8042 *kb8042, int led_state, boolean_t polled) argument
1233 kb8042->leds.desired = led_state;
1236 mutex_enter(&kb8042->w_hw_mutex);
1238 if (kb8042->leds.desired != kb8042->leds.commanded) {
1239 kb8042_send_to_keyboard(kb8042, KB_SET_LED, polled);
1243 mutex_exit(&kb8042->w_hw_mutex);
1249 struct kb8042 *kb8042 = (struct kb8042 *)hw; local
1250 kb8042_setled(kb8042, led_state, B_TRUE);
1256 struct kb8042 *kb8042 = (struct kb8042 *)hw; local
1257 kb8042_setled(kb8042, led_state, B_FALSE);
1262 kb8042_send_and_wait(struct kb8042 *kb8042, uint8_t u8, boolean_t polled) argument
1264 uint8_t *outp = kb8042->addr +
1266 uint8_t *inavp = kb8042->addr +
1268 uint8_t *inp = kb8042->addr +
1277 kb8042->acked = 0;
1278 kb8042->need_retry = 0;
1282 ddi_put8(kb8042->handle, outp, u8);
1284 while (!kb8042->acked && !kb8042->need_retry && !timedout) {
1287 if (ddi_get8(kb8042->handle, inavp)) {
1288 b = ddi_get8(kb8042->handle, inp);
1291 kb8042->acked = 1;
1294 kb8042->need_retry = 1;
1314 if (!kb8042->acked) {
1330 if (cv_timedwait(&kb8042->cmd_cv,
1331 &kb8042->w_hw_mutex, expire) == -1 &&
1332 !kb8042->acked && !kb8042->need_retry) {
1338 } while ((kb8042->need_retry || timedout) &&
1341 return (kb8042->acked);
1349 kb8042_send_to_keyboard(struct kb8042 *kb8042, int byte, boolean_t polled) argument
1362 (void) ddi_get8(kb8042->handle, kb8042->addr +
1366 if (kb8042_send_and_wait(kb8042, KB_SET_LED, polled)) {
1371 (void) kb8042_send_and_wait(kb8042,
1372 kb8042_xlate_leds(kb8042->leds.desired), polled);
1376 (void) ddi_get8(kb8042->handle, kb8042->addr +
1379 kb8042->leds.commanded = kb8042->leds.desired;
1384 (void) ddi_get8(kb8042->handle, kb8042->addr +
1388 (void) kb8042_send_and_wait(kb8042, KB_ENABLE, polled);
1391 (void) ddi_get8(kb8042->handle, kb8042->addr +
1398 ddi_put8(kb8042->handle,
1399 kb8042->addr + I8042_POLL_OUTPUT_DATA, byte);
1401 ddi_put8(kb8042->handle,
1402 kb8042->addr + I8042_INT_OUTPUT_DATA, byte);
1417 kb8042_wait_poweron(struct kb8042 *kb8042) argument
1424 ready = ddi_get8(kb8042->handle,
1425 kb8042->addr + I8042_INT_INPUT_AVAIL);
1437 (void) ddi_get8(kb8042->handle,
1438 kb8042->addr + I8042_INT_INPUT_DATA);
1462 struct kb8042 *kb8042, argument
1488 struct kb8042 *kb8042, argument
1493 if (kb8042->kb_old_key_pos == key_pos)
1494 kb8042->kb_old_key_pos = 0;
1496 if (kb8042->kb_old_key_pos == key_pos) {
1499 kb8042->kb_old_key_pos = key_pos;
1506 kb8042_type4_cmd(struct kb8042 *kb8042, int cmd) argument
1525 struct kb8042 *kb8042; local
1527 kb8042 = (struct kb8042 *)arg;
1529 return (kbtrans_getchar(kb8042->hw_kbtrans));
1538 struct kb8042 *kb8042; local
1540 kb8042 = (struct kb8042 *)arg;
1542 return (kbtrans_ischar(kb8042->hw_kbtrans));