2003-06-12 07:34:12 +04:00
|
|
|
/* $NetBSD: pckbc.c,v 1.26 2003/06/12 03:34:12 uwe Exp $ */
|
1998-03-22 18:25:15 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1998
|
|
|
|
* Matthias Drochner. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project
|
|
|
|
* by Matthias Drochner.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-06-12 07:34:12 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: pckbc.c,v 1.26 2003/06/12 03:34:12 uwe Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
1998-03-22 18:25:15 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1998-03-22 18:25:15 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/ic/i8042reg.h>
|
1999-12-04 01:48:22 +03:00
|
|
|
#include <dev/ic/pckbcvar.h>
|
|
|
|
|
2000-06-06 02:20:54 +04:00
|
|
|
#include "rnd.h"
|
1999-12-04 01:48:22 +03:00
|
|
|
#include "locators.h"
|
1998-03-22 18:25:15 +03:00
|
|
|
|
2001-12-18 18:50:23 +03:00
|
|
|
#ifdef __HAVE_NWSCONS /* XXX: this port uses sys/dev/pckbc */
|
2001-12-15 16:23:20 +03:00
|
|
|
#include "pckbd.h"
|
2001-12-18 18:50:23 +03:00
|
|
|
#else /* ie: only md drivers attach to pckbc */
|
|
|
|
#define NPCKBD 0
|
|
|
|
#endif
|
1998-03-22 18:25:15 +03:00
|
|
|
#if (NPCKBD > 0)
|
|
|
|
#include <dev/pckbc/pckbdvar.h>
|
|
|
|
#endif
|
2000-06-06 02:20:54 +04:00
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
1998-03-22 18:25:15 +03:00
|
|
|
|
|
|
|
/* descriptor for one device command */
|
|
|
|
struct pckbc_devcmd {
|
|
|
|
TAILQ_ENTRY(pckbc_devcmd) next;
|
|
|
|
int flags;
|
|
|
|
#define KBC_CMDFLAG_SYNC 1 /* give descriptor back to caller */
|
|
|
|
#define KBC_CMDFLAG_SLOW 2
|
|
|
|
u_char cmd[4];
|
|
|
|
int cmdlen, cmdidx, retries;
|
|
|
|
u_char response[4];
|
|
|
|
int status, responselen, responseidx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* data per slave device */
|
|
|
|
struct pckbc_slotdata {
|
2001-07-31 17:15:28 +04:00
|
|
|
int polling; /* don't process data in interrupt handler */
|
|
|
|
int poll_data; /* data read from inr handler if polling */
|
|
|
|
int poll_stat; /* status read from inr handler if polling */
|
1998-03-22 18:25:15 +03:00
|
|
|
TAILQ_HEAD(, pckbc_devcmd) cmdqueue; /* active commands */
|
1998-07-24 07:29:29 +04:00
|
|
|
TAILQ_HEAD(, pckbc_devcmd) freequeue; /* free commands */
|
1998-03-22 18:25:15 +03:00
|
|
|
#define NCMD 5
|
1998-07-24 07:29:29 +04:00
|
|
|
struct pckbc_devcmd cmds[NCMD];
|
2000-06-06 02:20:54 +04:00
|
|
|
#if NRND > 0
|
|
|
|
rndsource_element_t rnd_source;
|
|
|
|
#endif
|
1998-03-22 18:25:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define CMD_IN_QUEUE(q) (TAILQ_FIRST(&(q)->cmdqueue) != NULL)
|
|
|
|
|
|
|
|
void pckbc_init_slotdata __P((struct pckbc_slotdata *));
|
|
|
|
int pckbc_attach_slot __P((struct pckbc_softc *, pckbc_slot_t));
|
|
|
|
int pckbc_submatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
int pckbcprint __P((void *, const char *));
|
|
|
|
|
1999-12-04 01:48:22 +03:00
|
|
|
struct pckbc_internal pckbc_consdata;
|
|
|
|
int pckbc_console_attached;
|
1998-03-22 18:25:15 +03:00
|
|
|
|
1999-12-04 01:48:22 +03:00
|
|
|
static int pckbc_console;
|
1998-03-22 18:25:15 +03:00
|
|
|
static struct pckbc_slotdata pckbc_cons_slotdata;
|
|
|
|
|
|
|
|
static int pckbc_wait_output __P((bus_space_tag_t, bus_space_handle_t));
|
|
|
|
|
|
|
|
static int pckbc_get8042cmd __P((struct pckbc_internal *));
|
|
|
|
static int pckbc_put8042cmd __P((struct pckbc_internal *));
|
|
|
|
static int pckbc_send_devcmd __P((struct pckbc_internal *, pckbc_slot_t,
|
|
|
|
u_char));
|
|
|
|
static void pckbc_poll_cmd1 __P((struct pckbc_internal *, pckbc_slot_t,
|
|
|
|
struct pckbc_devcmd *));
|
|
|
|
|
|
|
|
void pckbc_cleanqueue __P((struct pckbc_slotdata *));
|
|
|
|
void pckbc_cleanup __P((void *));
|
|
|
|
int pckbc_cmdresponse __P((struct pckbc_internal *, pckbc_slot_t, u_char));
|
|
|
|
void pckbc_start __P((struct pckbc_internal *, pckbc_slot_t));
|
|
|
|
|
2001-06-17 20:15:41 +04:00
|
|
|
const char * const pckbc_slot_names[] = { "kbd", "aux" };
|
1999-12-03 22:02:49 +03:00
|
|
|
|
1998-03-22 18:25:15 +03:00
|
|
|
#define KBC_DEVCMD_ACK 0xfa
|
|
|
|
#define KBC_DEVCMD_RESEND 0xfe
|
|
|
|
|
|
|
|
#define KBD_DELAY DELAY(8)
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
pckbc_wait_output(iot, ioh_c)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh_c;
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = 100000; i; i--)
|
|
|
|
if (!(bus_space_read_1(iot, ioh_c, 0) & KBS_IBF)) {
|
|
|
|
KBD_DELAY;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-12-04 01:48:22 +03:00
|
|
|
int
|
1998-03-22 18:25:15 +03:00
|
|
|
pckbc_send_cmd(iot, ioh_c, val)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh_c;
|
|
|
|
u_char val;
|
|
|
|
{
|
|
|
|
if (!pckbc_wait_output(iot, ioh_c))
|
|
|
|
return (0);
|
|
|
|
bus_space_write_1(iot, ioh_c, 0, val);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2001-07-31 17:15:28 +04:00
|
|
|
/*
|
|
|
|
* Note: the spl games here are to deal with some strange PC kbd controllers
|
|
|
|
* in some system configurations.
|
|
|
|
* This is not canonical way to handle polling input.
|
|
|
|
*/
|
1999-12-04 01:48:22 +03:00
|
|
|
int
|
2001-07-24 01:03:19 +04:00
|
|
|
pckbc_poll_data1(pt, slot, checkaux)
|
|
|
|
pckbc_tag_t pt;
|
1998-03-22 18:25:15 +03:00
|
|
|
pckbc_slot_t slot;
|
|
|
|
int checkaux;
|
|
|
|
{
|
2001-07-24 01:03:19 +04:00
|
|
|
struct pckbc_internal *t = pt;
|
2001-07-31 17:15:28 +04:00
|
|
|
struct pckbc_slotdata *q = t->t_slotdata[slot];
|
2002-11-02 00:39:31 +03:00
|
|
|
int s;
|
2001-07-24 01:03:19 +04:00
|
|
|
u_char stat, c;
|
2002-11-02 00:39:31 +03:00
|
|
|
int i = 100000; /* if 1 port read takes 1us (?), this polls for 100ms */
|
1998-03-22 18:25:15 +03:00
|
|
|
|
2001-07-31 17:15:28 +04:00
|
|
|
s = splhigh();
|
|
|
|
|
|
|
|
if (q && q->polling && q->poll_data != -1 && q->poll_stat != -1) {
|
|
|
|
stat = q->poll_stat;
|
|
|
|
c = q->poll_data;
|
|
|
|
q->poll_data = -1;
|
|
|
|
q->poll_stat = -1;
|
|
|
|
goto process;
|
|
|
|
}
|
|
|
|
|
2002-11-02 00:39:31 +03:00
|
|
|
for (; i; i--) {
|
2001-07-24 01:03:19 +04:00
|
|
|
stat = bus_space_read_1(t->t_iot, t->t_ioh_c, 0);
|
1998-03-22 18:25:15 +03:00
|
|
|
if (stat & KBS_DIB) {
|
|
|
|
KBD_DELAY;
|
2001-07-24 01:03:19 +04:00
|
|
|
c = bus_space_read_1(t->t_iot, t->t_ioh_d, 0);
|
|
|
|
|
2001-07-31 17:15:28 +04:00
|
|
|
process:
|
1998-03-22 18:25:15 +03:00
|
|
|
if (checkaux && (stat & 0x20)) { /* aux data */
|
|
|
|
if (slot != PCKBC_AUX_SLOT) {
|
1998-04-07 19:57:48 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
printf("lost aux 0x%x\n", c);
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (slot == PCKBC_AUX_SLOT) {
|
1998-04-07 19:57:48 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
printf("lost kbd 0x%x\n", c);
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2001-07-31 17:15:28 +04:00
|
|
|
splx(s);
|
1998-03-22 18:25:15 +03:00
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
}
|
2001-07-31 17:15:28 +04:00
|
|
|
|
|
|
|
splx(s);
|
1998-03-22 18:25:15 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current command byte.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
pckbc_get8042cmd(t)
|
|
|
|
struct pckbc_internal *t;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = t->t_iot;
|
|
|
|
bus_space_handle_t ioh_c = t->t_ioh_c;
|
|
|
|
int data;
|
|
|
|
|
|
|
|
if (!pckbc_send_cmd(iot, ioh_c, K_RDCMDBYTE))
|
|
|
|
return (0);
|
2001-07-24 01:03:19 +04:00
|
|
|
data = pckbc_poll_data1(t, PCKBC_KBD_SLOT, t->t_haveaux);
|
1998-03-22 18:25:15 +03:00
|
|
|
if (data == -1)
|
|
|
|
return (0);
|
|
|
|
t->t_cmdbyte = data;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass command byte to keyboard controller (8042).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
pckbc_put8042cmd(t)
|
|
|
|
struct pckbc_internal *t;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = t->t_iot;
|
|
|
|
bus_space_handle_t ioh_d = t->t_ioh_d;
|
|
|
|
bus_space_handle_t ioh_c = t->t_ioh_c;
|
|
|
|
|
|
|
|
if (!pckbc_send_cmd(iot, ioh_c, K_LDCMDBYTE))
|
|
|
|
return (0);
|
|
|
|
if (!pckbc_wait_output(iot, ioh_c))
|
|
|
|
return (0);
|
|
|
|
bus_space_write_1(iot, ioh_d, 0, t->t_cmdbyte);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pckbc_send_devcmd(t, slot, val)
|
|
|
|
struct pckbc_internal *t;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
u_char val;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = t->t_iot;
|
|
|
|
bus_space_handle_t ioh_d = t->t_ioh_d;
|
|
|
|
bus_space_handle_t ioh_c = t->t_ioh_c;
|
|
|
|
|
|
|
|
if (slot == PCKBC_AUX_SLOT) {
|
|
|
|
if (!pckbc_send_cmd(iot, ioh_c, KBC_AUXWRITE))
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (!pckbc_wait_output(iot, ioh_c))
|
|
|
|
return (0);
|
|
|
|
bus_space_write_1(iot, ioh_d, 0, val);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1999-12-04 01:48:22 +03:00
|
|
|
int
|
|
|
|
pckbc_is_console(iot, addr)
|
1998-03-22 18:25:15 +03:00
|
|
|
bus_space_tag_t iot;
|
1999-12-04 01:48:22 +03:00
|
|
|
bus_addr_t addr;
|
1998-03-22 18:25:15 +03:00
|
|
|
{
|
|
|
|
if (pckbc_console && !pckbc_console_attached &&
|
1999-12-04 01:48:22 +03:00
|
|
|
pckbc_consdata.t_iot == iot &&
|
|
|
|
pckbc_consdata.t_addr == addr)
|
1998-03-22 18:25:15 +03:00
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-04-07 19:57:48 +04:00
|
|
|
pckbc_submatch(parent, cf, aux)
|
1998-03-22 18:25:15 +03:00
|
|
|
struct device *parent;
|
1998-04-07 19:57:48 +04:00
|
|
|
struct cfdata *cf;
|
1998-03-22 18:25:15 +03:00
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pckbc_attach_args *pa = aux;
|
|
|
|
|
|
|
|
if (cf->cf_loc[PCKBCCF_SLOT] != PCKBCCF_SLOT_DEFAULT &&
|
|
|
|
cf->cf_loc[PCKBCCF_SLOT] != pa->pa_slot)
|
|
|
|
return (0);
|
2002-09-27 07:17:40 +04:00
|
|
|
return (config_match(parent, cf, aux));
|
1998-03-22 18:25:15 +03:00
|
|
|
}
|
|
|
|
|
1999-02-28 17:26:38 +03:00
|
|
|
int
|
|
|
|
pckbc_attach_slot(sc, slot)
|
1998-03-22 18:25:15 +03:00
|
|
|
struct pckbc_softc *sc;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
{
|
|
|
|
struct pckbc_internal *t = sc->id;
|
|
|
|
struct pckbc_attach_args pa;
|
2001-12-06 23:00:58 +03:00
|
|
|
void *sdata;
|
1998-03-22 18:25:15 +03:00
|
|
|
int found;
|
2001-12-06 22:52:56 +03:00
|
|
|
int alloced = 0;
|
1998-03-22 18:25:15 +03:00
|
|
|
|
|
|
|
pa.pa_tag = t;
|
|
|
|
pa.pa_slot = slot;
|
|
|
|
|
2001-12-06 22:52:56 +03:00
|
|
|
if (t->t_slotdata[slot] == NULL) {
|
2001-12-06 23:00:58 +03:00
|
|
|
sdata = malloc(sizeof(struct pckbc_slotdata),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (sdata == NULL) {
|
|
|
|
printf("%s: no memory\n", sc->sc_dv.dv_xname);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
t->t_slotdata[slot] = sdata;
|
1998-03-22 18:25:15 +03:00
|
|
|
pckbc_init_slotdata(t->t_slotdata[slot]);
|
2001-12-06 22:52:56 +03:00
|
|
|
alloced++;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = (config_found_sm((struct device *)sc, &pa,
|
|
|
|
pckbcprint, pckbc_submatch) != NULL);
|
|
|
|
|
|
|
|
if (!found && alloced) {
|
|
|
|
free(t->t_slotdata[slot], M_DEVBUF);
|
|
|
|
t->t_slotdata[slot] = NULL;
|
1998-03-22 18:25:15 +03:00
|
|
|
}
|
2001-12-06 22:52:56 +03:00
|
|
|
|
2000-06-06 02:20:54 +04:00
|
|
|
#if NRND > 0
|
2000-06-06 20:21:22 +04:00
|
|
|
if (found && (t->t_slotdata[slot] != NULL))
|
2001-12-06 22:52:56 +03:00
|
|
|
rnd_attach_source(&t->t_slotdata[slot]->rnd_source,
|
|
|
|
sc->subname[slot], RND_TYPE_TTY, 0);
|
2000-06-06 02:20:54 +04:00
|
|
|
#endif
|
1998-03-22 18:25:15 +03:00
|
|
|
return (found);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-12-04 01:48:22 +03:00
|
|
|
pckbc_attach(sc)
|
|
|
|
struct pckbc_softc *sc;
|
1998-03-22 18:25:15 +03:00
|
|
|
{
|
|
|
|
struct pckbc_internal *t;
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh_d, ioh_c;
|
|
|
|
int res;
|
|
|
|
u_char cmdbits = 0;
|
|
|
|
|
1999-12-04 01:48:22 +03:00
|
|
|
t = sc->id;
|
|
|
|
iot = t->t_iot;
|
|
|
|
ioh_d = t->t_ioh_d;
|
|
|
|
ioh_c = t->t_ioh_c;
|
1998-03-22 18:25:15 +03:00
|
|
|
|
|
|
|
/* flush */
|
2001-07-24 01:03:19 +04:00
|
|
|
(void) pckbc_poll_data1(t, PCKBC_KBD_SLOT, 0);
|
1998-03-22 18:25:15 +03:00
|
|
|
|
1998-05-03 15:54:38 +04:00
|
|
|
/* set initial cmd byte */
|
1998-03-22 18:25:15 +03:00
|
|
|
if (!pckbc_put8042cmd(t)) {
|
|
|
|
printf("kbc: cmd word write error\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-03-05 13:40:54 +03:00
|
|
|
/*
|
|
|
|
* XXX Don't check the keyboard port. There are broken keyboard controllers
|
|
|
|
* which don't pass the test but work normally otherwise.
|
|
|
|
*/
|
|
|
|
#if 0
|
1998-03-22 18:25:15 +03:00
|
|
|
/*
|
|
|
|
* check kbd port ok
|
|
|
|
*/
|
|
|
|
if (!pckbc_send_cmd(iot, ioh_c, KBC_KBDTEST))
|
|
|
|
return;
|
2001-07-24 01:03:19 +04:00
|
|
|
res = pckbc_poll_data1(t, PCKBC_KBD_SLOT, 0);
|
1998-03-22 18:25:15 +03:00
|
|
|
|
1999-02-28 17:26:38 +03:00
|
|
|
/*
|
|
|
|
* Normally, we should get a "0" here.
|
|
|
|
* But there are keyboard controllers behaving differently.
|
|
|
|
*/
|
1999-03-05 13:40:54 +03:00
|
|
|
if (res == 0 || res == 0xfa || res == 0x01 || res == 0xab) {
|
1998-12-14 16:54:25 +03:00
|
|
|
#ifdef PCKBCDEBUG
|
1999-02-28 17:26:38 +03:00
|
|
|
if (res != 0)
|
|
|
|
printf("kbc: returned %x on kbd slot test\n", res);
|
1998-12-14 16:54:25 +03:00
|
|
|
#endif
|
1998-03-22 18:25:15 +03:00
|
|
|
if (pckbc_attach_slot(sc, PCKBC_KBD_SLOT))
|
|
|
|
cmdbits |= KC8_KENABLE;
|
|
|
|
} else {
|
|
|
|
printf("kbc: kbd port test: %x\n", res);
|
|
|
|
return;
|
|
|
|
}
|
1999-03-05 13:40:54 +03:00
|
|
|
#else
|
|
|
|
if (pckbc_attach_slot(sc, PCKBC_KBD_SLOT))
|
|
|
|
cmdbits |= KC8_KENABLE;
|
|
|
|
#endif /* 0 */
|
1998-03-22 18:25:15 +03:00
|
|
|
|
|
|
|
/*
|
2001-04-09 19:45:50 +04:00
|
|
|
* Check aux port ok.
|
|
|
|
* Avoid KBC_AUXTEST because it hangs some older controllers
|
|
|
|
* (eg UMC880?).
|
1998-03-22 18:25:15 +03:00
|
|
|
*/
|
2001-04-09 19:45:50 +04:00
|
|
|
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 */
|
2001-07-24 01:03:19 +04:00
|
|
|
res = pckbc_poll_data1(t, PCKBC_AUX_SLOT, 1);
|
2001-05-17 14:48:39 +04:00
|
|
|
if (res != -1) {
|
2001-05-16 02:01:07 +04:00
|
|
|
/*
|
2001-05-17 14:48:39 +04:00
|
|
|
* 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.
|
2001-05-16 02:01:07 +04:00
|
|
|
*/
|
2001-05-17 14:48:39 +04:00
|
|
|
t->t_haveaux = 1;
|
2001-05-16 02:01:07 +04:00
|
|
|
if (pckbc_attach_slot(sc, PCKBC_AUX_SLOT))
|
|
|
|
cmdbits |= KC8_MENABLE;
|
|
|
|
}
|
2001-05-17 14:48:39 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
|
|
|
else
|
|
|
|
printf("kbc: aux echo test failed\n");
|
|
|
|
#endif
|
1998-03-22 18:25:15 +03:00
|
|
|
|
2001-04-09 19:45:50 +04:00
|
|
|
nomouse:
|
1998-03-22 18:25:15 +03:00
|
|
|
/* enable needed interrupts */
|
|
|
|
t->t_cmdbyte |= cmdbits;
|
|
|
|
if (!pckbc_put8042cmd(t))
|
|
|
|
printf("kbc: cmd word write error\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pckbcprint(aux, pnp)
|
|
|
|
void *aux;
|
|
|
|
const char *pnp;
|
|
|
|
{
|
|
|
|
struct pckbc_attach_args *pa = aux;
|
|
|
|
|
|
|
|
if (!pnp)
|
2003-01-01 03:16:46 +03:00
|
|
|
aprint_normal(" (%s slot)", pckbc_slot_names[pa->pa_slot]);
|
1998-03-22 18:25:15 +03:00
|
|
|
return (QUIET);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pckbc_init_slotdata(q)
|
|
|
|
struct pckbc_slotdata *q;
|
|
|
|
{
|
1998-07-24 07:29:29 +04:00
|
|
|
int i;
|
1998-03-22 18:25:15 +03:00
|
|
|
TAILQ_INIT(&q->cmdqueue);
|
1998-07-24 07:29:29 +04:00
|
|
|
TAILQ_INIT(&q->freequeue);
|
|
|
|
|
2001-04-09 19:45:50 +04:00
|
|
|
for (i = 0; i < NCMD; i++) {
|
1998-07-24 07:29:29 +04:00
|
|
|
TAILQ_INSERT_TAIL(&q->freequeue, &(q->cmds[i]), next);
|
|
|
|
}
|
1998-03-22 18:25:15 +03:00
|
|
|
q->polling = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pckbc_flush(self, slot)
|
|
|
|
pckbc_tag_t self;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
{
|
|
|
|
struct pckbc_internal *t = self;
|
|
|
|
|
2001-07-24 01:03:19 +04:00
|
|
|
(void) pckbc_poll_data1(t, slot, t->t_haveaux);
|
1998-03-22 18:25:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pckbc_poll_data(self, slot)
|
|
|
|
pckbc_tag_t self;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
{
|
|
|
|
struct pckbc_internal *t = self;
|
|
|
|
struct pckbc_slotdata *q = t->t_slotdata[slot];
|
|
|
|
int c;
|
|
|
|
|
2001-07-24 01:03:19 +04:00
|
|
|
c = pckbc_poll_data1(t, slot, t->t_haveaux);
|
1998-03-22 18:25:15 +03:00
|
|
|
if (c != -1 && q && CMD_IN_QUEUE(q)) {
|
|
|
|
/* we jumped into a running command - try to
|
|
|
|
deliver the response */
|
|
|
|
if (pckbc_cmdresponse(t, slot, c))
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* switch scancode translation on / off
|
|
|
|
* return nonzero on success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
pckbc_xt_translation(self, slot, on)
|
|
|
|
pckbc_tag_t self;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
int on;
|
|
|
|
{
|
|
|
|
struct pckbc_internal *t = self;
|
|
|
|
int ison;
|
|
|
|
|
|
|
|
if (slot != PCKBC_KBD_SLOT) {
|
|
|
|
/* translation only for kbd slot */
|
|
|
|
if (on)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ison = t->t_cmdbyte & KC8_TRANS;
|
|
|
|
if ((on && ison) || (!on && !ison))
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
t->t_cmdbyte ^= KC8_TRANS;
|
|
|
|
if (!pckbc_put8042cmd(t))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* read back to be sure */
|
|
|
|
if (!pckbc_get8042cmd(t))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
ison = t->t_cmdbyte & KC8_TRANS;
|
|
|
|
if ((on && ison) || (!on && !ison))
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-06-17 20:15:41 +04:00
|
|
|
static const struct pckbc_portcmd {
|
1998-03-22 18:25:15 +03:00
|
|
|
u_char cmd_en, cmd_dis;
|
|
|
|
} pckbc_portcmd[2] = {
|
|
|
|
{
|
|
|
|
KBC_KBDENABLE, KBC_KBDDISABLE,
|
|
|
|
}, {
|
|
|
|
KBC_AUXENABLE, KBC_AUXDISABLE,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
pckbc_slot_enable(self, slot, on)
|
|
|
|
pckbc_tag_t self;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
int on;
|
|
|
|
{
|
|
|
|
struct pckbc_internal *t = (struct pckbc_internal *)self;
|
2001-06-17 20:15:41 +04:00
|
|
|
const struct pckbc_portcmd *cmd;
|
1998-03-22 18:25:15 +03:00
|
|
|
|
|
|
|
cmd = &pckbc_portcmd[slot];
|
|
|
|
|
|
|
|
if (!pckbc_send_cmd(t->t_iot, t->t_ioh_c,
|
|
|
|
on ? cmd->cmd_en : cmd->cmd_dis))
|
|
|
|
printf("pckbc_slot_enable(%d) failed\n", on);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pckbc_set_poll(self, slot, on)
|
|
|
|
pckbc_tag_t self;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
int on;
|
|
|
|
{
|
|
|
|
struct pckbc_internal *t = (struct pckbc_internal *)self;
|
|
|
|
|
|
|
|
t->t_slotdata[slot]->polling = on;
|
|
|
|
|
2001-07-31 17:15:28 +04:00
|
|
|
if (on) {
|
|
|
|
t->t_slotdata[slot]->poll_data = -1;
|
|
|
|
t->t_slotdata[slot]->poll_stat = -1;
|
|
|
|
} else {
|
1998-03-22 18:25:15 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If disabling polling on a device that's been configured,
|
|
|
|
* make sure there are no bytes left in the FIFO, holding up
|
|
|
|
* the interrupt line. Otherwise we won't get any further
|
|
|
|
* interrupts.
|
|
|
|
*/
|
|
|
|
if (t->t_sc) {
|
|
|
|
s = spltty();
|
|
|
|
pckbcintr(t->t_sc);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass command to device, poll for ACK and data.
|
|
|
|
* to be called at spltty()
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pckbc_poll_cmd1(t, slot, cmd)
|
|
|
|
struct pckbc_internal *t;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
struct pckbc_devcmd *cmd;
|
|
|
|
{
|
|
|
|
int i, c = 0;
|
|
|
|
|
|
|
|
while (cmd->cmdidx < cmd->cmdlen) {
|
|
|
|
if (!pckbc_send_devcmd(t, slot, cmd->cmd[cmd->cmdidx])) {
|
|
|
|
printf("pckbc_cmd: send error\n");
|
|
|
|
cmd->status = EIO;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 10; i; i--) { /* 1s ??? */
|
2001-07-24 01:03:19 +04:00
|
|
|
c = pckbc_poll_data1(t, slot, t->t_haveaux);
|
1998-03-22 18:25:15 +03:00
|
|
|
if (c != -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == KBC_DEVCMD_ACK) {
|
|
|
|
cmd->cmdidx++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c == KBC_DEVCMD_RESEND) {
|
1998-04-07 19:57:48 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
|
|
|
printf("pckbc_cmd: RESEND\n");
|
1998-03-22 18:25:15 +03:00
|
|
|
#endif
|
|
|
|
if (cmd->retries++ < 5)
|
|
|
|
continue;
|
|
|
|
else {
|
1998-05-03 14:02:11 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
printf("pckbc: cmd failed\n");
|
1998-04-07 19:57:48 +04:00
|
|
|
#endif
|
1998-03-22 18:25:15 +03:00
|
|
|
cmd->status = EIO;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c == -1) {
|
1998-05-03 14:02:11 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
printf("pckbc_cmd: timeout\n");
|
|
|
|
#endif
|
|
|
|
cmd->status = EIO;
|
|
|
|
return;
|
|
|
|
}
|
1998-04-07 19:57:48 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
printf("pckbc_cmd: lost 0x%x\n", c);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
while (cmd->responseidx < cmd->responselen) {
|
|
|
|
if (cmd->flags & KBC_CMDFLAG_SLOW)
|
|
|
|
i = 100; /* 10s ??? */
|
|
|
|
else
|
|
|
|
i = 10; /* 1s ??? */
|
|
|
|
while (i--) {
|
2001-07-24 01:03:19 +04:00
|
|
|
c = pckbc_poll_data1(t, slot, t->t_haveaux);
|
1998-03-22 18:25:15 +03:00
|
|
|
if (c != -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c == -1) {
|
1998-05-03 14:02:11 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
printf("pckbc_cmd: no data\n");
|
|
|
|
#endif
|
|
|
|
cmd->status = ETIMEDOUT;
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
cmd->response[cmd->responseidx++] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for use in autoconfiguration */
|
|
|
|
int
|
|
|
|
pckbc_poll_cmd(self, slot, cmd, len, responselen, respbuf, slow)
|
|
|
|
pckbc_tag_t self;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
u_char *cmd;
|
|
|
|
int len, responselen;
|
|
|
|
u_char *respbuf;
|
|
|
|
int slow;
|
|
|
|
{
|
|
|
|
struct pckbc_internal *t = self;
|
|
|
|
struct pckbc_devcmd nc;
|
|
|
|
|
|
|
|
if ((len > 4) || (responselen > 4))
|
|
|
|
return (EINVAL);
|
|
|
|
|
2001-07-07 20:13:44 +04:00
|
|
|
memset(&nc, 0, sizeof(nc));
|
2001-07-07 19:53:13 +04:00
|
|
|
memcpy(nc.cmd, cmd, len);
|
1998-03-22 18:25:15 +03:00
|
|
|
nc.cmdlen = len;
|
|
|
|
nc.responselen = responselen;
|
|
|
|
nc.flags = (slow ? KBC_CMDFLAG_SLOW : 0);
|
|
|
|
|
|
|
|
pckbc_poll_cmd1(t, slot, &nc);
|
|
|
|
|
|
|
|
if (nc.status == 0 && respbuf)
|
2001-07-07 19:53:13 +04:00
|
|
|
memcpy(respbuf, nc.response, responselen);
|
1998-03-22 18:25:15 +03:00
|
|
|
|
|
|
|
return (nc.status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up a command queue, throw away everything.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pckbc_cleanqueue(q)
|
|
|
|
struct pckbc_slotdata *q;
|
|
|
|
{
|
|
|
|
struct pckbc_devcmd *cmd;
|
1998-04-07 19:57:48 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
int i;
|
1998-04-07 19:57:48 +04:00
|
|
|
#endif
|
1998-03-22 18:25:15 +03:00
|
|
|
|
|
|
|
while ((cmd = TAILQ_FIRST(&q->cmdqueue))) {
|
|
|
|
TAILQ_REMOVE(&q->cmdqueue, cmd, next);
|
1998-04-07 19:57:48 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
printf("pckbc_cleanqueue: removing");
|
|
|
|
for (i = 0; i < cmd->cmdlen; i++)
|
|
|
|
printf(" %02x", cmd->cmd[i]);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
1998-07-24 07:29:29 +04:00
|
|
|
TAILQ_INSERT_TAIL(&q->freequeue, cmd, next);
|
1998-03-22 18:25:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timeout error handler: clean queues and data port.
|
|
|
|
* XXX could be less invasive.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pckbc_cleanup(self)
|
|
|
|
void *self;
|
|
|
|
{
|
|
|
|
struct pckbc_internal *t = self;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
printf("pckbc: command timeout\n");
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
if (t->t_slotdata[PCKBC_KBD_SLOT])
|
|
|
|
pckbc_cleanqueue(t->t_slotdata[PCKBC_KBD_SLOT]);
|
|
|
|
if (t->t_slotdata[PCKBC_AUX_SLOT])
|
|
|
|
pckbc_cleanqueue(t->t_slotdata[PCKBC_AUX_SLOT]);
|
|
|
|
|
|
|
|
while (bus_space_read_1(t->t_iot, t->t_ioh_c, 0) & KBS_DIB) {
|
|
|
|
KBD_DELAY;
|
|
|
|
(void) bus_space_read_1(t->t_iot, t->t_ioh_d, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset KBC? */
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass command to device during normal operation.
|
|
|
|
* to be called at spltty()
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pckbc_start(t, slot)
|
|
|
|
struct pckbc_internal *t;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
{
|
|
|
|
struct pckbc_slotdata *q = t->t_slotdata[slot];
|
|
|
|
struct pckbc_devcmd *cmd = TAILQ_FIRST(&q->cmdqueue);
|
|
|
|
|
|
|
|
if (q->polling) {
|
|
|
|
do {
|
|
|
|
pckbc_poll_cmd1(t, slot, cmd);
|
|
|
|
if (cmd->status)
|
|
|
|
printf("pckbc_start: command error\n");
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&q->cmdqueue, cmd, next);
|
|
|
|
if (cmd->flags & KBC_CMDFLAG_SYNC)
|
|
|
|
wakeup(cmd);
|
|
|
|
else {
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&t->t_cleanup);
|
1998-07-24 07:29:29 +04:00
|
|
|
TAILQ_INSERT_TAIL(&q->freequeue, cmd, next);
|
1998-03-22 18:25:15 +03:00
|
|
|
}
|
|
|
|
cmd = TAILQ_FIRST(&q->cmdqueue);
|
|
|
|
} while (cmd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pckbc_send_devcmd(t, slot, cmd->cmd[cmd->cmdidx])) {
|
|
|
|
printf("pckbc_start: send error\n");
|
|
|
|
/* XXX what now? */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle command responses coming in asynchonously,
|
|
|
|
* return nonzero if valid response.
|
|
|
|
* to be called at spltty()
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
pckbc_cmdresponse(t, slot, data)
|
|
|
|
struct pckbc_internal *t;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
u_char data;
|
|
|
|
{
|
|
|
|
struct pckbc_slotdata *q = t->t_slotdata[slot];
|
|
|
|
struct pckbc_devcmd *cmd = TAILQ_FIRST(&q->cmdqueue);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (!cmd)
|
|
|
|
panic("pckbc_cmdresponse: no active command");
|
|
|
|
#endif
|
|
|
|
if (cmd->cmdidx < cmd->cmdlen) {
|
|
|
|
if (data != KBC_DEVCMD_ACK && data != KBC_DEVCMD_RESEND)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (data == KBC_DEVCMD_RESEND) {
|
|
|
|
if (cmd->retries++ < 5) {
|
|
|
|
/* try again last command */
|
|
|
|
goto restart;
|
|
|
|
} else {
|
2003-06-10 11:46:29 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
printf("pckbc: cmd failed\n");
|
2003-06-10 11:46:29 +04:00
|
|
|
#endif
|
1998-03-22 18:25:15 +03:00
|
|
|
cmd->status = EIO;
|
|
|
|
/* dequeue */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (++cmd->cmdidx < cmd->cmdlen)
|
|
|
|
goto restart;
|
|
|
|
if (cmd->responselen)
|
|
|
|
return (1);
|
|
|
|
/* else dequeue */
|
|
|
|
}
|
|
|
|
} else if (cmd->responseidx < cmd->responselen) {
|
|
|
|
cmd->response[cmd->responseidx++] = data;
|
|
|
|
if (cmd->responseidx < cmd->responselen)
|
|
|
|
return (1);
|
|
|
|
/* else dequeue */
|
|
|
|
} else
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* dequeue: */
|
|
|
|
TAILQ_REMOVE(&q->cmdqueue, cmd, next);
|
|
|
|
if (cmd->flags & KBC_CMDFLAG_SYNC)
|
|
|
|
wakeup(cmd);
|
|
|
|
else {
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&t->t_cleanup);
|
1998-07-24 07:29:29 +04:00
|
|
|
TAILQ_INSERT_TAIL(&q->freequeue, cmd, next);
|
1998-03-22 18:25:15 +03:00
|
|
|
}
|
|
|
|
if (!CMD_IN_QUEUE(q))
|
|
|
|
return (1);
|
|
|
|
restart:
|
|
|
|
pckbc_start(t, slot);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put command into the device's command queue, return zero or errno.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
pckbc_enqueue_cmd(self, slot, cmd, len, responselen, sync, respbuf)
|
|
|
|
pckbc_tag_t self;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
u_char *cmd;
|
|
|
|
int len, responselen, sync;
|
|
|
|
u_char *respbuf;
|
|
|
|
{
|
|
|
|
struct pckbc_internal *t = self;
|
|
|
|
struct pckbc_slotdata *q = t->t_slotdata[slot];
|
|
|
|
struct pckbc_devcmd *nc;
|
|
|
|
int s, isactive, res = 0;
|
|
|
|
|
|
|
|
if ((len > 4) || (responselen > 4))
|
|
|
|
return (EINVAL);
|
|
|
|
s = spltty();
|
1998-07-24 07:29:29 +04:00
|
|
|
nc = TAILQ_FIRST(&q->freequeue);
|
|
|
|
if (nc) {
|
|
|
|
TAILQ_REMOVE(&q->freequeue, nc, next);
|
|
|
|
}
|
1998-03-22 18:25:15 +03:00
|
|
|
splx(s);
|
|
|
|
if (!nc)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
2001-07-07 20:13:44 +04:00
|
|
|
memset(nc, 0, sizeof(*nc));
|
2001-07-07 19:53:13 +04:00
|
|
|
memcpy(nc->cmd, cmd, len);
|
1998-03-22 18:25:15 +03:00
|
|
|
nc->cmdlen = len;
|
|
|
|
nc->responselen = responselen;
|
|
|
|
nc->flags = (sync ? KBC_CMDFLAG_SYNC : 0);
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
if (q->polling && sync) {
|
|
|
|
/*
|
|
|
|
* XXX We should poll until the queue is empty.
|
|
|
|
* But we don't come here normally, so make
|
|
|
|
* it simple and throw away everything.
|
|
|
|
*/
|
|
|
|
pckbc_cleanqueue(q);
|
|
|
|
}
|
|
|
|
|
|
|
|
isactive = CMD_IN_QUEUE(q);
|
|
|
|
TAILQ_INSERT_TAIL(&q->cmdqueue, nc, next);
|
|
|
|
if (!isactive)
|
|
|
|
pckbc_start(t, slot);
|
|
|
|
|
|
|
|
if (q->polling)
|
|
|
|
res = (sync ? nc->status : 0);
|
|
|
|
else if (sync) {
|
|
|
|
if ((res = tsleep(nc, 0, "kbccmd", 1*hz))) {
|
|
|
|
TAILQ_REMOVE(&q->cmdqueue, nc, next);
|
|
|
|
pckbc_cleanup(t);
|
|
|
|
} else
|
|
|
|
res = nc->status;
|
|
|
|
} else
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&t->t_cleanup, hz, pckbc_cleanup, t);
|
1998-03-22 18:25:15 +03:00
|
|
|
|
|
|
|
if (sync) {
|
|
|
|
if (respbuf)
|
2001-07-07 19:53:13 +04:00
|
|
|
memcpy(respbuf, nc->response, responselen);
|
1998-07-24 07:29:29 +04:00
|
|
|
TAILQ_INSERT_TAIL(&q->freequeue, nc, next);
|
1998-03-22 18:25:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-06-06 02:20:54 +04:00
|
|
|
pckbc_set_inputhandler(self, slot, func, arg, name)
|
1998-03-22 18:25:15 +03:00
|
|
|
pckbc_tag_t self;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
pckbc_inputfcn func;
|
|
|
|
void *arg;
|
2000-06-06 02:20:54 +04:00
|
|
|
char *name;
|
1998-03-22 18:25:15 +03:00
|
|
|
{
|
|
|
|
struct pckbc_internal *t = (struct pckbc_internal *)self;
|
|
|
|
struct pckbc_softc *sc = t->t_sc;
|
|
|
|
|
1999-12-04 01:48:22 +03:00
|
|
|
if (slot >= PCKBC_NSLOTS)
|
1998-03-22 18:25:15 +03:00
|
|
|
panic("pckbc_set_inputhandler: bad slot %d", slot);
|
|
|
|
|
1999-12-04 01:48:22 +03:00
|
|
|
(*sc->intr_establish)(sc, slot);
|
1998-11-17 01:35:18 +03:00
|
|
|
|
1998-03-22 18:25:15 +03:00
|
|
|
sc->inputhandler[slot] = func;
|
|
|
|
sc->inputarg[slot] = arg;
|
2000-06-06 02:20:54 +04:00
|
|
|
sc->subname[slot] = name;
|
1998-03-22 18:25:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pckbcintr(vsc)
|
|
|
|
void *vsc;
|
|
|
|
{
|
|
|
|
struct pckbc_softc *sc = (struct pckbc_softc *)vsc;
|
|
|
|
struct pckbc_internal *t = sc->id;
|
|
|
|
u_char stat;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
struct pckbc_slotdata *q;
|
|
|
|
int served = 0, data;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
stat = bus_space_read_1(t->t_iot, t->t_ioh_c, 0);
|
|
|
|
if (!(stat & KBS_DIB))
|
|
|
|
break;
|
|
|
|
|
|
|
|
served = 1;
|
|
|
|
|
|
|
|
slot = (t->t_haveaux && (stat & 0x20)) ?
|
|
|
|
PCKBC_AUX_SLOT : PCKBC_KBD_SLOT;
|
|
|
|
q = t->t_slotdata[slot];
|
|
|
|
|
|
|
|
if (!q) {
|
|
|
|
/* XXX do something for live insertion? */
|
|
|
|
printf("pckbcintr: no dev for slot %d\n", slot);
|
|
|
|
KBD_DELAY;
|
|
|
|
(void) bus_space_read_1(t->t_iot, t->t_ioh_d, 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
KBD_DELAY;
|
|
|
|
data = bus_space_read_1(t->t_iot, t->t_ioh_d, 0);
|
|
|
|
|
2000-06-06 02:20:54 +04:00
|
|
|
#if NRND > 0
|
|
|
|
rnd_add_uint32(&q->rnd_source, (stat<<8)|data);
|
|
|
|
#endif
|
2001-07-31 17:15:28 +04:00
|
|
|
|
|
|
|
if (q->polling) {
|
|
|
|
q->poll_data = data;
|
|
|
|
q->poll_stat = stat;
|
|
|
|
break; /* pckbc_poll_data() will get it */
|
|
|
|
}
|
|
|
|
|
1998-03-22 18:25:15 +03:00
|
|
|
if (CMD_IN_QUEUE(q) && pckbc_cmdresponse(t, slot, data))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sc->inputhandler[slot])
|
|
|
|
(*sc->inputhandler[slot])(sc->inputarg[slot], data);
|
1998-04-07 19:57:48 +04:00
|
|
|
#ifdef PCKBCDEBUG
|
1998-03-22 18:25:15 +03:00
|
|
|
else
|
|
|
|
printf("pckbcintr: slot %d lost %d\n", slot, data);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return (served);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-06-09 08:58:32 +04:00
|
|
|
pckbc_cnattach(iot, addr, cmd_offset, slot)
|
1998-03-22 18:25:15 +03:00
|
|
|
bus_space_tag_t iot;
|
1999-12-04 01:48:22 +03:00
|
|
|
bus_addr_t addr;
|
2000-06-09 08:58:32 +04:00
|
|
|
bus_size_t cmd_offset;
|
1998-03-22 18:25:15 +03:00
|
|
|
pckbc_slot_t slot;
|
|
|
|
{
|
1998-04-18 13:42:20 +04:00
|
|
|
bus_space_handle_t ioh_d, ioh_c;
|
2003-06-12 07:34:12 +04:00
|
|
|
#ifdef PCKBC_CNATTACH_SELFTEST
|
|
|
|
int reply;
|
|
|
|
#endif
|
1998-04-18 13:42:20 +04:00
|
|
|
int res = 0;
|
1998-03-22 18:25:15 +03:00
|
|
|
|
1999-12-04 01:48:22 +03:00
|
|
|
if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d))
|
1998-03-22 18:25:15 +03:00
|
|
|
return (ENXIO);
|
2000-06-09 08:58:32 +04:00
|
|
|
if (bus_space_map(iot, addr + cmd_offset, 1, 0, &ioh_c)) {
|
1998-04-18 13:42:20 +04:00
|
|
|
bus_space_unmap(iot, ioh_d, 1);
|
1998-03-22 18:25:15 +03:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2001-07-24 01:03:19 +04:00
|
|
|
memset(&pckbc_consdata, 0, sizeof(pckbc_consdata));
|
1998-04-18 13:42:20 +04:00
|
|
|
pckbc_consdata.t_iot = iot;
|
|
|
|
pckbc_consdata.t_ioh_d = ioh_d;
|
|
|
|
pckbc_consdata.t_ioh_c = ioh_c;
|
1999-12-04 01:48:22 +03:00
|
|
|
pckbc_consdata.t_addr = addr;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_init(&pckbc_consdata.t_cleanup);
|
1998-04-18 13:42:20 +04:00
|
|
|
|
|
|
|
/* flush */
|
2001-07-24 01:03:19 +04:00
|
|
|
(void) pckbc_poll_data1(&pckbc_consdata, PCKBC_KBD_SLOT, 0);
|
1998-04-18 13:42:20 +04:00
|
|
|
|
2003-06-12 07:34:12 +04:00
|
|
|
#ifdef PCKBC_CNATTACH_SELFTEST
|
|
|
|
/*
|
|
|
|
* In some machines (e.g. netwinder) pckbc refuses to talk at
|
|
|
|
* all until we request a self-test.
|
|
|
|
*/
|
|
|
|
if (!pckbc_send_cmd(iot, ioh_c, KBC_SELFTEST)) {
|
|
|
|
printf("kbc: unable to request selftest\n");
|
|
|
|
res = EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
reply = pckbc_poll_data1(&pckbc_consdata, PCKBC_KBD_SLOT, 0);
|
|
|
|
if (reply != 0x55) {
|
|
|
|
printf("kbc: selftest returned 0x%02x\n", reply);
|
|
|
|
res = EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#endif /* PCKBC_CNATTACH_SELFTEST */
|
1998-04-18 13:42:20 +04:00
|
|
|
|
|
|
|
/* init cmd byte, enable ports */
|
|
|
|
pckbc_consdata.t_cmdbyte = KC8_CPU;
|
|
|
|
if (!pckbc_put8042cmd(&pckbc_consdata)) {
|
|
|
|
printf("kbc: cmd word write error\n");
|
|
|
|
res = EIO;
|
2003-06-12 07:34:12 +04:00
|
|
|
goto out;
|
1998-04-18 13:42:20 +04:00
|
|
|
}
|
|
|
|
|
1998-03-22 18:25:15 +03:00
|
|
|
#if (NPCKBD > 0)
|
2003-06-12 07:34:12 +04:00
|
|
|
res = pckbd_cnattach(&pckbc_consdata, slot);
|
1998-04-28 23:13:24 +04:00
|
|
|
#else
|
2003-06-12 07:34:12 +04:00
|
|
|
/*
|
|
|
|
* XXX This should be replaced with the `notyet' case
|
|
|
|
* XXX when all of the old PC-style console drivers
|
|
|
|
* XXX have gone away. When that happens, all of
|
|
|
|
* XXX the pckbc_machdep_cnattach() should be purged,
|
|
|
|
* XXX as well.
|
|
|
|
*/
|
2001-12-18 18:50:23 +03:00
|
|
|
#ifdef notyet
|
2003-06-12 07:34:12 +04:00
|
|
|
res = ENXIO;
|
2001-12-18 18:50:23 +03:00
|
|
|
#else
|
2003-06-12 07:34:12 +04:00
|
|
|
res = pckbc_machdep_cnattach(&pckbc_consdata, slot);
|
1998-03-22 18:25:15 +03:00
|
|
|
#endif
|
1998-04-28 23:13:24 +04:00
|
|
|
#endif /* NPCKBD > 0 */
|
1998-04-18 13:42:20 +04:00
|
|
|
|
2003-06-12 07:34:12 +04:00
|
|
|
out:
|
1998-03-22 18:25:15 +03:00
|
|
|
if (res) {
|
|
|
|
bus_space_unmap(iot, pckbc_consdata.t_ioh_d, 1);
|
|
|
|
bus_space_unmap(iot, pckbc_consdata.t_ioh_c, 1);
|
|
|
|
} else {
|
|
|
|
pckbc_consdata.t_slotdata[slot] = &pckbc_cons_slotdata;
|
|
|
|
pckbc_init_slotdata(&pckbc_cons_slotdata);
|
|
|
|
pckbc_console = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|