#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lpt_ofisa.c,v 1.19 2021/01/27 03:10:21 thorpej Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <sys/tty.h>
#include <sys/intr.h>
#include <sys/bus.h>
#include <dev/ofw/openfirm.h>
#include <dev/isa/isavar.h>
#include <dev/ofisa/ofisavar.h>
#include <dev/ic/lptreg.h>
#include <dev/ic/lptvar.h>
struct lpt_ofisa_softc {
struct lpt_softc sc_lpt;
void *sc_ih;
};
int lpt_ofisa_probe(device_t, cfdata_t , void *);
void lpt_ofisa_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(lpt_ofisa, sizeof(struct lpt_ofisa_softc),
lpt_ofisa_probe, lpt_ofisa_attach, NULL, NULL);
static const struct device_compatible_entry compat_data[] = {
{ .compat = "pnpPNP,401" },
DEVICE_COMPAT_EOL
};
int
lpt_ofisa_probe(device_t parent, cfdata_t cf, void *aux)
{
struct ofisa_attach_args *aa = aux;
int rv;
rv = of_compatible_match(aa->oba.oba_phandle, compat_data) ? 5 : 0;
#ifdef _LPT_OFISA_MD_MATCH
if (!rv)
rv = lpt_ofisa_md_match(parent, cf, aux);
#endif
return (rv);
}
void
lpt_ofisa_attach(device_t parent, device_t self, void *aux)
{
struct lpt_ofisa_softc *osc = device_private(self);
struct lpt_softc *sc = &osc->sc_lpt;
struct ofisa_attach_args *aa = aux;
struct ofisa_reg_desc reg;
struct ofisa_intr_desc intr;
int n;
sc->sc_dev = self;
n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1);
#ifdef _LPT_OFISA_MD_REG_FIXUP
n = lpt_ofisa_md_reg_fixup(parent, self, aux, ®, 1, n);
#endif
if (n != 1) {
aprint_error(": error getting register data\n");
return;
}
if (reg.len != 4 && reg.len != 8) {
aprint_error(": weird register size (%lu, expected 4 or 8)\n",
(unsigned long)reg.len);
return;
}
n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
#ifdef _LPT_OFISA_MD_INTR_FIXUP
n = lpt_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
#endif
if (n != 1) {
aprint_error(": error getting interrupt data\n");
return;
}
sc->sc_iot = (reg.type == OFISA_REG_TYPE_IO) ? aa->iot : aa->memt;
if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) {
aprint_error(": can't map register space\n");
return;
}
osc->sc_ih = isa_intr_establish(aa->ic, intr.irq, intr.share,
IPL_TTY, lptintr, sc);
aprint_normal("\n");
lpt_attach_subr(sc);
#if 0
printf("%s: registers: ", device_xname(sc->sc_dev));
ofisa_reg_print(®, 1);
printf("\n");
printf("%s: interrupts: ", device_xname(sc->sc_dev));
ofisa_intr_print(&intr, 1);
printf("\n");
#endif
}