Deleted Added
sdiff udiff text old ( 161969 ) new ( 207354 )
full compact
1/*-
2 * Copyright (c) 1996-1999
3 * Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 17 unchanged lines hidden (view full) ---

26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * from kbdio.c,v 1.13 1998/09/25 11:55:46 yokota Exp
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/dev/atkbdc/atkbdc.c 161969 2006-09-04 00:19:31Z dwhite $");
35
36#include "opt_kbd.h"
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/bus.h>
41#include <sys/malloc.h>
42#include <sys/syslog.h>
43#include <machine/bus.h>
44#include <machine/resource.h>
45#include <sys/rman.h>
46
47#include <dev/atkbdc/atkbdcreg.h>
48
49#ifdef __sparc64__
50#include <dev/ofw/openfirm.h>
51#include <machine/bus_private.h>
52#include <machine/ofw_machdep.h>
53#else
54#include <isa/isareg.h>

--- 93 unchanged lines hidden (view full) ---

148
149/* the backdoor to the keyboard controller! XXX */
150int
151atkbdc_configure(void)
152{
153 bus_space_tag_t tag;
154 bus_space_handle_t h0;
155 bus_space_handle_t h1;
156#if defined(__i386__)
157 volatile int i;
158 register_t flags;
159#endif
160#ifdef __sparc64__
161 char name[32];
162 phandle_t chosen, node;
163 ihandle_t stdin;
164 bus_addr_t port0;

--- 52 unchanged lines hidden (view full) ---

217 bus_space_map(tag, port0, IO_KBDSIZE, 0, &h0);
218 bus_space_map(tag, port1, IO_KBDSIZE, 0, &h1);
219#else
220 h0 = (bus_space_handle_t)port0;
221 h1 = (bus_space_handle_t)port1;
222#endif
223#endif
224
225#if defined(__i386__)
226 /*
227 * Check if we really have AT keyboard controller. Poll status
228 * register until we get "all clear" indication. If no such
229 * indication comes, it probably means that there is no AT
230 * keyboard controller present. Give up in such case. Check relies
231 * on the fact that reading from non-existing in/out port returns
232 * 0xff on i386. May or may not be true on other platforms.
233 */

--- 9 unchanged lines hidden (view full) ---

243
244 return atkbdc_setup(atkbdc_softc[0], tag, h0, h1);
245}
246
247static int
248atkbdc_setup(atkbdc_softc_t *sc, bus_space_tag_t tag, bus_space_handle_t h0,
249 bus_space_handle_t h1)
250{
251 if (sc->ioh0 == 0) { /* XXX */
252 sc->command_byte = -1;
253 sc->command_mask = 0;
254 sc->lock = FALSE;
255 sc->kbd.head = sc->kbd.tail = 0;
256 sc->aux.head = sc->aux.tail = 0;
257#if KBDIO_DEBUG >= 2
258 sc->kbd.call_count = 0;
259 sc->kbd.qcount = sc->kbd.max_qcount = 0;
260 sc->aux.call_count = 0;
261 sc->aux.qcount = sc->aux.max_qcount = 0;
262#endif
263 }
264 sc->iot = tag;
265 sc->ioh0 = h0;
266 sc->ioh1 = h1;
267 return 0;
268}
269
270/* open a keyboard controller */
271KBDC
272atkbdc_open(int unit)
273{
274 if (unit <= 0)

--- 100 unchanged lines hidden (view full) ---

375}
376
377/*
378 * device I/O routines
379 */
380static int
381wait_while_controller_busy(struct atkbdc_softc *kbdc)
382{
383 /* CPU will stay inside the loop for 100msec at most */
384 int retry = 5000;
385 int f;
386
387 while ((f = read_status(kbdc)) & KBDS_INPUT_BUFFER_FULL) {
388 if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL) {
389 DELAY(KBDD_DELAYTIME);
390 addq(&kbdc->kbd, read_data(kbdc));
391 } else if ((f & KBDS_BUFFER_FULL) == KBDS_AUX_BUFFER_FULL) {
392 DELAY(KBDD_DELAYTIME);
393 addq(&kbdc->aux, read_data(kbdc));
394 }

--- 6 unchanged lines hidden (view full) ---

401
402/*
403 * wait for any data; whether it's from the controller,
404 * the keyboard, or the aux device.
405 */
406static int
407wait_for_data(struct atkbdc_softc *kbdc)
408{
409 /* CPU will stay inside the loop for 200msec at most */
410 int retry = 10000;
411 int f;
412
413 while ((f = read_status(kbdc) & KBDS_ANY_BUFFER_FULL) == 0) {
414 DELAY(KBDC_DELAYTIME);
415 if (--retry < 0)
416 return 0;
417 }
418 DELAY(KBDD_DELAYTIME);
419 return f;
420}
421
422/* wait for data from the keyboard */
423static int
424wait_for_kbd_data(struct atkbdc_softc *kbdc)
425{
426 /* CPU will stay inside the loop for 200msec at most */
427 int retry = 10000;
428 int f;
429
430 while ((f = read_status(kbdc) & KBDS_BUFFER_FULL)
431 != KBDS_KBD_BUFFER_FULL) {
432 if (f == KBDS_AUX_BUFFER_FULL) {
433 DELAY(KBDD_DELAYTIME);
434 addq(&kbdc->aux, read_data(kbdc));
435 }
436 DELAY(KBDC_DELAYTIME);
437 if (--retry < 0)

--- 5 unchanged lines hidden (view full) ---

443
444/*
445 * wait for an ACK(FAh), RESEND(FEh), or RESET_FAIL(FCh) from the keyboard.
446 * queue anything else.
447 */
448static int
449wait_for_kbd_ack(struct atkbdc_softc *kbdc)
450{
451 /* CPU will stay inside the loop for 200msec at most */
452 int retry = 10000;
453 int f;
454 int b;
455
456 while (retry-- > 0) {
457 if ((f = read_status(kbdc)) & KBDS_ANY_BUFFER_FULL) {
458 DELAY(KBDD_DELAYTIME);
459 b = read_data(kbdc);
460 if ((f & KBDS_BUFFER_FULL) == KBDS_KBD_BUFFER_FULL) {
461 if ((b == KBD_ACK) || (b == KBD_RESEND)
462 || (b == KBD_RESET_FAIL))
463 return b;

--- 6 unchanged lines hidden (view full) ---

470 }
471 return -1;
472}
473
474/* wait for data from the aux device */
475static int
476wait_for_aux_data(struct atkbdc_softc *kbdc)
477{
478 /* CPU will stay inside the loop for 200msec at most */
479 int retry = 10000;
480 int f;
481
482 while ((f = read_status(kbdc) & KBDS_BUFFER_FULL)
483 != KBDS_AUX_BUFFER_FULL) {
484 if (f == KBDS_KBD_BUFFER_FULL) {
485 DELAY(KBDD_DELAYTIME);
486 addq(&kbdc->kbd, read_data(kbdc));
487 }
488 DELAY(KBDC_DELAYTIME);
489 if (--retry < 0)

--- 5 unchanged lines hidden (view full) ---

495
496/*
497 * wait for an ACK(FAh), RESEND(FEh), or RESET_FAIL(FCh) from the aux device.
498 * queue anything else.
499 */
500static int
501wait_for_aux_ack(struct atkbdc_softc *kbdc)
502{
503 /* CPU will stay inside the loop for 200msec at most */
504 int retry = 10000;
505 int f;
506 int b;
507
508 while (retry-- > 0) {
509 if ((f = read_status(kbdc)) & KBDS_ANY_BUFFER_FULL) {
510 DELAY(KBDD_DELAYTIME);
511 b = read_data(kbdc);
512 if ((f & KBDS_BUFFER_FULL) == KBDS_AUX_BUFFER_FULL) {
513 if ((b == PSM_ACK) || (b == PSM_RESEND)
514 || (b == PSM_RESET_FAIL))
515 return b;

--- 605 unchanged lines hidden ---