#include "opt_atppc.h"
#include <sys/param.h>
__KERNEL_RCSID(0, "$NetBSD: atppc_pioc.c,v 1.7 2023/12/20 06:13:59 thorpej Exp $");
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/bus.h>
#include <machine/intr.h>
#include <arch/acorn32/mainbus/piocvar.h>
#include <dev/ic/atppcreg.h>
#include <dev/ic/atppcvar.h>
#include "locators.h"
static int atppc_pioc_probe(device_t, cfdata_t, void *);
static void atppc_pioc_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(atppc_pioc, sizeof(struct atppc_softc), atppc_pioc_probe,
atppc_pioc_attach, NULL, NULL);
#define IO_LPTSIZE 8
static int
atppc_pioc_probe(device_t parent, cfdata_t cf, void *aux)
{
bus_space_handle_t ioh;
struct pioc_attach_args *pa = aux;
bus_space_tag_t iot = pa->pa_iot;
int addr = pa->pa_iobase + pa->pa_offset;
int rval = 0;
if (pa->pa_name && strcmp(pa->pa_name, "lpt") != 0)
return 0;
if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT) {
aprint_error_dev(parent, "(%s): io port unknown.\n", __func__);
} else if (bus_space_map(iot, addr, IO_LPTSIZE, 0, &ioh) == 0) {
if (atppc_detect_port(iot, ioh) == 0)
rval = 1;
else
aprint_error_dev(parent,
"(%s): unable to write/read I/O port.\n",
__func__);
bus_space_unmap(iot, ioh, IO_LPTSIZE);
} else {
aprint_error_dev(parent, "(%s): attempt to map bus space failed.\n",
__func__);
}
return rval;
}
static void
atppc_pioc_attach(device_t parent, device_t self, void *aux)
{
struct atppc_softc *sc = device_private(self);
struct pioc_attach_args *pa = aux;
bus_addr_t iobase;
sc->sc_dev = self;
sc->sc_iot = pa->pa_iot;
sc->sc_has = 0;
iobase = pa->pa_iobase + pa->pa_offset;
if (bus_space_map(sc->sc_iot, iobase, IO_LPTSIZE, 0,
&sc->sc_ioh) != 0) {
aprint_error(": attempt to map bus space failed, device not "
"properly attached.\n");
sc->sc_dev_ok = ATPPC_NOATTACH;
return;
}
sc->sc_dev_ok = ATPPC_ATTACHED;
if (!(device_cfdata(self)->cf_flags & ATPPC_FLAG_DISABLE_INTR)) {
if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT) {
sc->sc_ieh = intr_claim(pa->pa_irq, IPL_TTY, "atppc",
atppcintr, sc);
sc->sc_has |= ATPPC_HAS_INTR;
} else
ATPPC_DPRINTF(("%s: IRQ not assigned or bad number of "
"IRQs.\n", device_xname(self)));
} else
ATPPC_VPRINTF(("%s: interrupts not configured due to flags.\n",
device_xname(self)));
atppc_sc_attach(sc);
}