コード例 #1
0
ファイル: pckbc.c プロジェクト: ajinkya93/OpenBSD
void
pckbc_attach(struct pckbc_softc *sc, int flags)
{
	struct pckbc_internal *t;
	bus_space_tag_t iot;
	bus_space_handle_t ioh_d, ioh_c;
	int haskbd = 0, res;
	u_char cmdbits = 0;

	t = sc->id;
	iot = t->t_iot;
	ioh_d = t->t_ioh_d;
	ioh_c = t->t_ioh_c;

	if (pckbc_console == 0) {
		timeout_set(&t->t_cleanup, pckbc_cleanup, t);
		timeout_set(&t->t_poll, pckbc_poll, t);
	}

	/* flush */
	(void) pckbc_poll_data1(iot, ioh_d, ioh_c, PCKBC_KBD_SLOT, 0);

	/* set initial cmd byte */
	if (!pckbc_put8042cmd(t)) {
#if defined(__i386__) || defined(__amd64__)
		if (!ISSET(flags, PCKBCF_FORCE_KEYBOARD_PRESENT)) {
			pckbc_release_console();
			return;
		}
#endif
		printf("kbc: cmd word write error\n");
		return;
	}

/*
 * XXX Don't check the keyboard port. There are broken keyboard controllers
 * which don't pass the test but work normally otherwise.
 */
#if 0
	/*
	 * check kbd port ok
	 */
	if (!pckbc_send_cmd(iot, ioh_c, KBC_KBDTEST))
		return;
	res = pckbc_poll_data1(iot, ioh_d, ioh_c, PCKBC_KBD_SLOT, 0);

	/*
	 * Normally, we should get a "0" here.
	 * But there are keyboard controllers behaving differently.
	 */
	if (res == 0 || res == 0xfa || res == 0x01 || res == 0xab) {
#ifdef PCKBCDEBUG
		if (res != 0)
			printf("kbc: returned %x on kbd slot test\n", res);
#endif
		if (pckbc_attach_slot(sc, PCKBC_KBD_SLOT, 0)) {
			cmdbits |= KC8_KENABLE;
			haskbd = 1;
		}
	} else {
		printf("kbc: kbd port test: %x\n", res);
		return;
	}
#else
	if (pckbc_attach_slot(sc, PCKBC_KBD_SLOT, 0)) {
		cmdbits |= KC8_KENABLE;
		haskbd = 1;
	}
#endif /* 0 */

	/*
	 * Check aux port ok.
	 * Avoid KBC_AUXTEST because it hangs some older controllers
	 * (eg UMC880?).
	 */
	if (!pckbc_send_cmd(iot, ioh_c, KBC_AUXECHO)) {
		printf("kbc: aux echo error 1\n");
		goto nomouse;
	}
	if (!pckbc_wait_output(iot, ioh_c)) {
		printf("kbc: aux echo error 2\n");
		goto nomouse;
	}
	bus_space_write_1(iot, ioh_d, 0, 0x5a);	/* a random value */
	res = pckbc_poll_data1(iot, ioh_d, ioh_c, PCKBC_AUX_SLOT, 1);

	if (ISSET(t->t_flags, PCKBC_NEED_AUXWRITE)) {
		/*
		 * The following code is necessary to find the aux port on the
		 * oqo-1 machine, among others.  However if confuses old
		 * (non-ps/2) keyboard controllers (at least UMC880x again).
		 */
		if (res == -1) {
			/* Read of aux echo timed out, try again */
			if (!pckbc_send_cmd(iot, ioh_c, KBC_AUXWRITE))
				goto nomouse;
			if (!pckbc_wait_output(iot, ioh_c))
				goto nomouse;
			bus_space_write_1(iot, ioh_d, 0, 0x5a);
			res = pckbc_poll_data1(iot, ioh_d, ioh_c,
			    PCKBC_AUX_SLOT, 1);
			DPRINTF("kbc: aux echo: %x\n", res);
		}
	}

	if (res != -1) {
		/*
		 * In most cases, the 0x5a gets echoed.
		 * Some old controllers (Gateway 2000 circa 1993)
		 * return 0xfe here.
		 * We are satisfied if there is anything in the
		 * aux output buffer.
		 */
		DPRINTF("kbc: aux echo: %x\n", res);
		t->t_haveaux = 1;
		if (pckbc_attach_slot(sc, PCKBC_AUX_SLOT, 0))
			cmdbits |= KC8_MENABLE;
	}
#ifdef PCKBCDEBUG
	else
		printf("kbc: aux echo test failed\n");
#endif

#if defined(__i386__) || defined(__amd64__)
	if (haskbd == 0 && !ISSET(flags, PCKBCF_FORCE_KEYBOARD_PRESENT)) {
		if (t->t_haveaux) {
			if (pckbc_attach_slot(sc, PCKBC_KBD_SLOT, 1))
				cmdbits |= KC8_KENABLE;
		} else {
			pckbc_release_console();
		}
	}
#endif

nomouse:
	/* enable needed interrupts */
	t->t_cmdbyte |= cmdbits;
	if (!pckbc_put8042cmd(t))
		printf("kbc: cmd word write error\n");
}
コード例 #2
0
ファイル: pckbc.c プロジェクト: eyberg/rumpkernel-netbsd-src
void
pckbc_attach(struct pckbc_softc *sc)
{
	struct pckbc_internal *t;
	bus_space_tag_t iot;
	bus_space_handle_t ioh_d, ioh_c;
	int res;
	u_char cmdbits = 0;

	t = sc->id;
	iot = t->t_iot;
	ioh_d = t->t_ioh_d;
	ioh_c = t->t_ioh_c;

	t->t_pt = pckbport_attach(t, &pckbc_ops);
	if (t->t_pt == NULL) {
		aprint_error(": attach failed\n");
		return;
	}

	/* flush */
	(void) pckbc_poll_data1(t, PCKBC_KBD_SLOT);

	/* set initial cmd byte */
	if (!pckbc_put8042cmd(t)) {
		printf("pckbc: cmd word write error\n");
		return;
	}

/*
 * XXX Don't check the keyboard port. There are broken keyboard controllers
 * which don't pass the test but work normally otherwise.
 */
#if 0
	/*
	 * check kbd port ok
	 */
	if (!pckbc_send_cmd(iot, ioh_c, KBC_KBDTEST))
		return;
	res = pckbc_poll_data1(t, PCKBC_KBD_SLOT, 0);

	/*
	 * Normally, we should get a "0" here.
	 * But there are keyboard controllers behaving differently.
	 */
	if (res == 0 || res == 0xfa || res == 0x01 || res == 0xab) {
#ifdef PCKBCDEBUG
		if (res != 0)
			printf("pckbc: returned %x on kbd slot test\n", res);
#endif
		if (pckbc_attach_slot(sc, PCKBC_KBD_SLOT))
			cmdbits |= KC8_KENABLE;
	} else {
		printf("pckbc: kbd port test: %x\n", res);
		return;
	}
#else
	if (pckbc_attach_slot(sc, PCKBC_KBD_SLOT))
		cmdbits |= KC8_KENABLE;
#endif /* 0 */

	/*
	 * Check aux port ok.
	 * Avoid KBC_AUXTEST because it hangs some older controllers
	 *  (eg UMC880?).
	 */
	if (!pckbc_send_cmd(iot, ioh_c, KBC_AUXECHO)) {
		printf("pckbc: aux echo error 1\n");
		goto nomouse;
	}
	if (!pckbc_wait_output(iot, ioh_c)) {
		printf("pckbc: aux echo error 2\n");
		goto nomouse;
	}
	t->t_haveaux = 1;
	bus_space_write_1(iot, ioh_d, 0, 0x5a); /* a random value */
	res = pckbc_poll_data1(t, PCKBC_AUX_SLOT);

	/*
	 * The following is needed to find the aux port on the Tadpole
	 * SPARCle.
	 */
	if (res == -1 && ISSET(t->t_flags, PCKBC_NEED_AUXWRITE)) {
		/* Read of aux echo timed out, try again */
		if (!pckbc_send_cmd(iot, ioh_c, KBC_AUXWRITE))
			goto nomouse;
		if (!pckbc_wait_output(iot, ioh_c))
			goto nomouse;
		bus_space_write_1(iot, ioh_d, 0, 0x5a);
		res = pckbc_poll_data1(t, PCKBC_AUX_SLOT);
	}
	if (res != -1) {
		/*
		 * In most cases, the 0x5a gets echoed.
		 * Some older controllers (Gateway 2000 circa 1993)
		 * return 0xfe here.
		 * We are satisfied if there is anything in the
		 * aux output buffer.
		 */
		if (pckbc_attach_slot(sc, PCKBC_AUX_SLOT))
			cmdbits |= KC8_MENABLE;
	} else {

#ifdef PCKBCDEBUG
		printf("pckbc: aux echo test failed\n");
#endif
		t->t_haveaux = 0;
	}

nomouse:
	/* enable needed interrupts */
	t->t_cmdbyte |= cmdbits;
	if (!pckbc_put8042cmd(t))
		printf("pckbc: cmd word write error\n");
}