#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <machine/bus.h>
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <dev/ic/i8042reg.h>
#include <dev/ic/pckbcvar.h>
int pckbc_isa_match(struct device *, void *, void *);
void pckbc_isa_attach(struct device *, struct device *, void *);
int pckbc_isa_activate(struct device *, int);
const struct cfattach pckbc_isa_ca = {
sizeof(struct pckbc_softc), pckbc_isa_match, pckbc_isa_attach,
NULL, pckbc_isa_activate
};
int
pckbc_isa_match(struct device *parent, void *match, void *aux)
{
struct isa_attach_args *ia = aux;
bus_space_tag_t iot = ia->ia_iot;
bus_space_handle_t ioh_d, ioh_c;
int res;
if ((ia->ia_iobase != IOBASEUNK && ia->ia_iobase != IO_KBD) ||
ia->ia_maddr != MADDRUNK ||
(ia->ia_irq != IRQUNK && ia->ia_irq != 1 ) ||
ia->ia_drq != DRQUNK)
return (0);
if (pckbc_is_console(iot, IO_KBD) == 0) {
if (bus_space_map(iot, IO_KBD + KBDATAP, 1, 0, &ioh_d))
return (0);
if (bus_space_map(iot, IO_KBD + KBCMDP, 1, 0, &ioh_c))
goto fail;
(void) pckbc_poll_data1(iot, ioh_d, ioh_c, PCKBC_KBD_SLOT, 0);
if (pckbc_send_cmd(iot, ioh_c, KBC_SELFTEST) == 0)
goto fail2;
res = pckbc_poll_data1(iot, ioh_d, ioh_c, PCKBC_KBD_SLOT, 0);
if (res != 0x55) {
printf("kbc selftest: %x\n", res);
goto fail2;
}
bus_space_unmap(iot, ioh_c, 1);
bus_space_unmap(iot, ioh_d, 1);
}
ia->ia_iobase = IO_KBD;
ia->ia_iosize = 5;
ia->ia_msize = 0x0;
ia->ipa_nirq = PCKBC_NSLOTS;
ia->ipa_irq[PCKBC_KBD_SLOT].num = 1;
ia->ipa_irq[PCKBC_AUX_SLOT].num = 12;
return (1);
fail2:
bus_space_unmap(iot, ioh_c, 1);
fail:
bus_space_unmap(iot, ioh_d, 1);
return (0);
}
int
pckbc_isa_activate(struct device *self, int act)
{
struct pckbc_softc *sc = (struct pckbc_softc *)self;
int rv = 0;
switch (act) {
case DVACT_SUSPEND:
rv = config_activate_children(self, act);
pckbc_stop(sc);
break;
case DVACT_RESUME:
pckbc_reset(sc);
rv = config_activate_children(self, act);
break;
default:
rv = config_activate_children(self, act);
break;
}
return (rv);
}
void
pckbc_isa_attach(struct device *parent, struct device *self, void *aux)
{
struct pckbc_softc *sc = (struct pckbc_softc *)self;
struct cfdata *cf = self->dv_cfdata;
struct isa_attach_args *ia = aux;
struct pckbc_internal *t;
bus_space_tag_t iot;
bus_space_handle_t ioh_d, ioh_c;
void *rv;
int slot;
iot = ia->ia_iot;
printf("\n");
for (slot = 0; slot < PCKBC_NSLOTS; slot++) {
rv = isa_intr_establish(ia->ia_ic, ia->ipa_irq[slot].num,
IST_EDGE, IPL_TTY, pckbcintr, sc, sc->sc_dv.dv_xname);
if (rv == NULL) {
printf("%s: unable to establish interrupt for irq %d\n",
sc->sc_dv.dv_xname, ia->ipa_irq[slot].num);
}
}
if (pckbc_is_console(iot, IO_KBD)) {
t = &pckbc_consdata;
pckbc_console_attached = 1;
} else {
if (bus_space_map(iot, IO_KBD + KBDATAP, 1, 0, &ioh_d) ||
bus_space_map(iot, IO_KBD + KBCMDP, 1, 0, &ioh_c))
panic("pckbc_attach: couldn't map");
t = malloc(sizeof(*t), M_DEVBUF, M_WAITOK | M_ZERO);
t->t_iot = iot;
t->t_ioh_d = ioh_d;
t->t_ioh_c = ioh_c;
t->t_addr = IO_KBD;
t->t_cmdbyte = KC8_CPU;
}
t->t_sc = sc;
sc->id = t;
pckbc_attach(sc, cf->cf_flags);
}