Lines Matching +full:wait +full:- +full:delay

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1996-1999
5 * Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp)
66 #define availq(q) ((q)->head != (q)->tail)
68 #define emptyq(q) ((q)->tail = (q)->head = (q)->qcount = 0)
70 #define emptyq(q) ((q)->tail = (q)->head = 0)
73 #define read_data(k) (bus_space_read_1((k)->iot, (k)->ioh0, 0))
74 #define read_status(k) (bus_space_read_1((k)->iot, (k)->ioh1, 0))
76 (bus_space_write_1((k)->iot, (k)->ioh0, 0, (d)))
78 (bus_space_write_1((k)->iot, (k)->ioh1, 0, (d)))
84 * low-level console. As the low-level console accesses the keyboard
125 * all chromebooks while omitting non-Google systems from System76 and
246 * on the fact that reading from non-existing in/out port returns in atkbdc_configure()
271 if (sc->ioh0 == 0) { /* XXX */ in atkbdc_setup()
272 sc->command_byte = -1; in atkbdc_setup()
273 sc->command_mask = 0; in atkbdc_setup()
274 sc->lock = FALSE; in atkbdc_setup()
275 sc->kbd.head = sc->kbd.tail = 0; in atkbdc_setup()
276 sc->aux.head = sc->aux.tail = 0; in atkbdc_setup()
277 sc->aux_mux_enabled = FALSE; in atkbdc_setup()
279 sc->kbd.call_count = 0; in atkbdc_setup()
280 sc->kbd.qcount = sc->kbd.max_qcount = 0; in atkbdc_setup()
281 sc->aux.call_count = 0; in atkbdc_setup()
282 sc->aux.qcount = sc->aux.max_qcount = 0; in atkbdc_setup()
285 sc->iot = tag; in atkbdc_setup()
286 sc->ioh0 = h0; in atkbdc_setup()
287 sc->ioh1 = h1; in atkbdc_setup()
305 DELAY(1000); in atkbdc_setup()
308 read_delay = tscval[1] - tscval[0]; in atkbdc_setup()
309 read_delay /= (tscval[2] - tscval[1]) / 1000; in atkbdc_setup()
310 sc->retry = 100000 / ((KBDD_DELAYTIME * 2) + read_delay); in atkbdc_setup()
312 sc->retry = 5000; in atkbdc_setup()
314 sc->quirks = atkbdc_getquirks(); in atkbdc_setup()
327 if ((atkbdc_softc[unit]->port0 != NULL) in atkbdc_open()
328 || (atkbdc_softc[unit]->ioh0 != 0)) /* XXX */ in atkbdc_open()
377 prevlock = p->lock; in kbdc_lock()
378 p->lock = lock; in kbdc_lock()
387 return (availq(&p->kbd) || availq(&p->aux) in kbdc_data_ready()
396 if (nextq(q->tail) != q->head) { in addq()
397 q->q[q->tail] = c; in addq()
398 q->tail = nextq(q->tail); in addq()
400 ++q->call_count; in addq()
401 ++q->qcount; in addq()
402 if (q->qcount > q->max_qcount) in addq()
403 q->max_qcount = q->qcount; in addq()
415 if (q->tail != q->head) { in removeq()
416 c = q->q[q->head]; in removeq()
417 q->head = nextq(q->head); in removeq()
419 --q->qcount; in removeq()
423 return -1; in removeq()
436 retry = kbdc->retry; in wait_while_controller_busy()
440 DELAY(KBDD_DELAYTIME); in wait_while_controller_busy()
441 addq(&kbdc->kbd, read_data(kbdc)); in wait_while_controller_busy()
443 DELAY(KBDD_DELAYTIME); in wait_while_controller_busy()
444 addq(&kbdc->aux, read_data(kbdc)); in wait_while_controller_busy()
446 DELAY(KBDC_DELAYTIME); in wait_while_controller_busy()
447 if (--retry < 0) in wait_while_controller_busy()
454 * wait for any data; whether it's from the controller,
464 retry = kbdc->retry * 2; in wait_for_data()
467 DELAY(KBDC_DELAYTIME); in wait_for_data()
468 if (--retry < 0) in wait_for_data()
471 DELAY(KBDD_DELAYTIME); in wait_for_data()
475 /* wait for data from the keyboard */
483 retry = kbdc->retry * 2; in wait_for_kbd_data()
488 DELAY(KBDD_DELAYTIME); in wait_for_kbd_data()
489 addq(&kbdc->aux, read_data(kbdc)); in wait_for_kbd_data()
491 DELAY(KBDC_DELAYTIME); in wait_for_kbd_data()
492 if (--retry < 0) in wait_for_kbd_data()
495 DELAY(KBDD_DELAYTIME); in wait_for_kbd_data()
500 * wait for an ACK(FAh), RESEND(FEh), or RESET_FAIL(FCh) from the keyboard.
511 retry = kbdc->retry * 2; in wait_for_kbd_ack()
513 while (retry-- > 0) { in wait_for_kbd_ack()
515 DELAY(KBDD_DELAYTIME); in wait_for_kbd_ack()
521 addq(&kbdc->kbd, b); in wait_for_kbd_ack()
523 addq(&kbdc->aux, b); in wait_for_kbd_ack()
526 DELAY(KBDC_DELAYTIME); in wait_for_kbd_ack()
528 return -1; in wait_for_kbd_ack()
531 /* wait for data from the aux device */
539 retry = kbdc->retry * 2; in wait_for_aux_data()
544 DELAY(KBDD_DELAYTIME); in wait_for_aux_data()
545 addq(&kbdc->kbd, read_data(kbdc)); in wait_for_aux_data()
547 DELAY(KBDC_DELAYTIME); in wait_for_aux_data()
548 if (--retry < 0) in wait_for_aux_data()
551 DELAY(KBDD_DELAYTIME); in wait_for_aux_data()
556 * wait for an ACK(FAh), RESEND(FEh), or RESET_FAIL(FCh) from the aux device.
567 retry = kbdc->retry * 2; in wait_for_aux_ack()
569 while (retry-- > 0) { in wait_for_aux_ack()
571 DELAY(KBDD_DELAYTIME); in wait_for_aux_ack()
577 addq(&kbdc->aux, b); in wait_for_aux_ack()
579 addq(&kbdc->kbd, b); in wait_for_aux_ack()
582 DELAY(KBDC_DELAYTIME); in wait_for_aux_ack()
584 return -1; in wait_for_aux_ack()
624 KBDC_WRITE_TO_AUX_MUX + p->aux_mux_port : KBDC_WRITE_TO_AUX; in write_aux_command()
631 /* send a command to the keyboard and wait for ACK */
636 int res = -1; in send_kbd_command()
638 while (retry-- > 0) { in send_kbd_command()
648 /* send a command to the auxiliary device and wait for ACK */
653 int res = -1; in send_aux_command()
655 while (retry-- > 0) { in send_aux_command()
667 emptyq(&p->aux); in send_aux_command()
675 /* send a command and a data to the keyboard, wait for ACKs */
680 int res = -1; in send_kbd_command_and_data()
682 for (retry = KBD_MAXRETRY; retry > 0; --retry) { in send_kbd_command_and_data()
694 for (retry = KBD_MAXRETRY, res = -1; retry > 0; --retry) { in send_kbd_command_and_data()
704 /* send a command and a data to the auxiliary device, wait for ACKs */
709 int res = -1; in send_aux_command_and_data()
711 for (retry = KBD_MAXRETRY; retry > 0; --retry) { in send_aux_command_and_data()
714 emptyq(&p->aux); in send_aux_command_and_data()
724 for (retry = KBD_MAXRETRY, res = -1; retry > 0; --retry) { in send_aux_command_and_data()
741 if (availq(&p->kbd)) in read_controller_data()
742 return removeq(&p->kbd); in read_controller_data()
743 if (availq(&p->aux)) in read_controller_data()
744 return removeq(&p->aux); in read_controller_data()
746 return -1; /* timeout */ in read_controller_data()
763 p->kbd.call_count, p->kbd.max_qcount, in read_kbd_data()
764 p->aux.call_count, p->aux.max_qcount); in read_kbd_data()
768 if (availq(&p->kbd)) in read_kbd_data()
769 return removeq(&p->kbd); in read_kbd_data()
771 return -1; /* timeout */ in read_kbd_data()
788 p->kbd.call_count, p->kbd.max_qcount, in read_kbd_data_no_wait()
789 p->aux.call_count, p->aux.max_qcount); in read_kbd_data_no_wait()
793 if (availq(&p->kbd)) in read_kbd_data_no_wait()
794 return removeq(&p->kbd); in read_kbd_data_no_wait()
797 DELAY(KBDD_DELAYTIME); in read_kbd_data_no_wait()
798 addq(&p->aux, read_data(p)); in read_kbd_data_no_wait()
802 DELAY(KBDD_DELAYTIME); in read_kbd_data_no_wait()
805 return -1; /* no data */ in read_kbd_data_no_wait()
812 if (availq(&p->aux)) in read_aux_data()
813 return removeq(&p->aux); in read_aux_data()
815 return -1; /* timeout */ in read_aux_data()
827 if (availq(&p->aux)) in read_aux_data_no_wait()
828 return removeq(&p->aux); in read_aux_data_no_wait()
831 DELAY(KBDD_DELAYTIME); in read_aux_data_no_wait()
832 addq(&p->kbd, read_data(p)); in read_aux_data_no_wait()
836 DELAY(KBDD_DELAYTIME); in read_aux_data_no_wait()
839 return -1; /* no data */ in read_aux_data_no_wait()
844 empty_kbd_buffer(KBDC p, int wait) in empty_kbd_buffer() argument
855 for (t = wait; t > 0; ) { in empty_kbd_buffer()
857 DELAY(KBDD_DELAYTIME); in empty_kbd_buffer()
860 addq(&p->aux, b); in empty_kbd_buffer()
867 t = wait; in empty_kbd_buffer()
869 t -= delta; in empty_kbd_buffer()
871 DELAY(delta*1000); in empty_kbd_buffer()
878 emptyq(&p->kbd); in empty_kbd_buffer()
883 empty_aux_buffer(KBDC p, int wait) in empty_aux_buffer() argument
894 for (t = wait; t > 0; ) { in empty_aux_buffer()
896 DELAY(KBDD_DELAYTIME); in empty_aux_buffer()
899 addq(&p->kbd, b); in empty_aux_buffer()
906 t = wait; in empty_aux_buffer()
908 t -= delta; in empty_aux_buffer()
910 DELAY(delta*1000); in empty_aux_buffer()
917 emptyq(&p->aux); in empty_aux_buffer()
922 empty_both_buffers(KBDC p, int wait) in empty_both_buffers() argument
933 for (t = wait; t > 0; ) { in empty_both_buffers()
935 DELAY(KBDD_DELAYTIME); in empty_both_buffers()
943 t = wait; in empty_both_buffers()
945 t -= delta; in empty_both_buffers()
951 * avoid this hang -- the keyboard attach will fail later on. in empty_both_buffers()
957 DELAY(delta*1000); in empty_both_buffers()
964 emptyq(&p->kbd); in empty_both_buffers()
965 emptyq(&p->aux); in empty_both_buffers()
980 while (retry-- > 0) { in reset_kbd()
984 emptyq(&p->kbd); in reset_kbd()
994 while (again-- > 0) { in reset_kbd()
995 /* wait awhile, well, in fact we must wait quite loooooooooooong */ in reset_kbd()
996 DELAY(KBD_RESETDELAY*1000); in reset_kbd()
998 if (c != -1) /* wait again if the controller is not ready */ in reset_kbd()
1018 while (retry-- > 0) { in reset_aux_dev()
1022 emptyq(&p->aux); in reset_aux_dev()
1023 /* NOTE: Compaq Armada laptops require extra delay here. XXX */ in reset_aux_dev()
1024 for (again = KBD_MAXWAIT; again > 0; --again) { in reset_aux_dev()
1025 DELAY(KBD_RESETDELAY*1000); in reset_aux_dev()
1027 if (c != -1) in reset_aux_dev()
1038 for (again = KBD_MAXWAIT; again > 0; --again) { in reset_aux_dev()
1039 /* wait awhile, well, quite looooooooooooong */ in reset_aux_dev()
1040 DELAY(KBD_RESETDELAY*1000); in reset_aux_dev()
1042 if (c != -1) /* wait again if the controller is not ready */ in reset_aux_dev()
1066 while (retry-- > 0) { in test_controller()
1074 emptyq(&p->kbd); in test_controller()
1075 while (again-- > 0) { in test_controller()
1076 /* wait awhile */ in test_controller()
1077 DELAY(KBD_RESETDELAY*1000); in test_controller()
1079 if (c != -1) /* wait again if the controller is not ready */ in test_controller()
1092 int c = -1; in test_kbd_port()
1094 while (retry-- > 0) { in test_kbd_port()
1102 emptyq(&p->kbd); in test_kbd_port()
1103 while (again-- > 0) { in test_kbd_port()
1105 if (c != -1) /* try again if the controller is not ready */ in test_kbd_port()
1118 int c = -1; in test_aux_port()
1120 while (retry-- > 0) { in test_aux_port()
1128 emptyq(&p->kbd); in test_aux_port()
1129 while (again-- > 0) { in test_aux_port()
1131 if (c != -1) /* try again if the controller is not ready */ in test_aux_port()
1142 return p->command_mask; in kbdc_get_device_mask()
1148 p->command_mask = in kbdc_set_device_mask()
1149 mask & (((p->quirks & KBDC_QUIRK_KEEP_ACTIVATED) in kbdc_set_device_mask()
1156 if (p->command_byte != -1) in get_controller_command_byte()
1157 return p->command_byte; in get_controller_command_byte()
1159 return -1; in get_controller_command_byte()
1160 emptyq(&p->kbd); in get_controller_command_byte()
1161 p->command_byte = read_controller_data(p); in get_controller_command_byte()
1162 return p->command_byte; in get_controller_command_byte()
1168 if (get_controller_command_byte(p) == -1) in set_controller_command_byte()
1171 command = (p->command_byte & ~mask) | (command & mask); in set_controller_command_byte()
1180 p->command_byte = command; in set_controller_command_byte()
1202 return (-1); in set_aux_mux_state()
1207 return (-1); in set_aux_mux_state()
1213 return (-1); in set_aux_mux_state()
1228 p->aux_mux_port = port; in set_active_aux_mux_port()
1241 p->aux_mux_enabled = TRUE; in enable_aux_mux()
1252 p->aux_mux_enabled = FALSE; in disable_aux_mux()
1261 return (p->aux_mux_enabled); in aux_mux_is_enabled()