#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/proc.h>
#include <sys/queue.h>
#include <machine/bus.h>
#include <dev/pci/pcivar.h>
#include <loongson/dev/voyagerreg.h>
#include <loongson/dev/voyagervar.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdivar.h>
#include <dev/usb/usb_mem.h>
#include <dev/usb/ohcireg.h>
#include <dev/usb/ohcivar.h>
extern int gdium_revision;
int ohci_voyager_match(struct device *, void *, void *);
void ohci_voyager_attach(struct device *, struct device *, void *);
void ohci_voyager_attach_deferred(struct device *);
struct ohci_voyager_softc {
struct ohci_softc sc;
void *sc_ih;
};
const struct cfattach ohci_voyager_ca = {
sizeof(struct ohci_voyager_softc),
ohci_voyager_match, ohci_voyager_attach, NULL, ohci_activate
};
int
ohci_voyager_match(struct device *parent, void *vcf, void *aux)
{
struct voyager_attach_args *vaa = (struct voyager_attach_args *)aux;
struct cfdata *cf = (struct cfdata *)vcf;
return gdium_revision == 0 &&
strcmp(vaa->vaa_name, cf->cf_driver->cd_name) == 0;
}
void
ohci_voyager_attach(struct device *parent, struct device *self, void *aux)
{
struct ohci_voyager_softc *sc = (struct ohci_voyager_softc *)self;
struct voyager_attach_args *vaa = (struct voyager_attach_args *)aux;
struct pci_attach_args *pa = vaa->vaa_pa;
int s;
const char *vendor;
char *devname = sc->sc.sc_bus.bdev.dv_xname;
sc->sc.sc_size = VOYAGER_OHCI_SIZE;
sc->sc.iot = vaa->vaa_mmiot;
if (bus_space_subregion(vaa->vaa_mmiot, vaa->vaa_mmioh,
VOYAGER_OHCI_BASE, VOYAGER_OHCI_SIZE, &sc->sc.ioh) != 0) {
printf(": can't map mem space\n");
return;
}
sc->sc.sc_intre = bus_space_read_4(sc->sc.iot, sc->sc.ioh,
OHCI_INTERRUPT_ENABLE);
bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE,
OHCI_MIE);
sc->sc.sc_bus.dmatag = pa->pa_dmat;
bus_space_barrier(sc->sc.iot, sc->sc.ioh, 0, sc->sc.sc_size,
BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE);
bus_space_write_4(sc->sc.iot, sc->sc.ioh,
OHCI_INTERRUPT_DISABLE, OHCI_MIE);
s = splusb();
sc->sc_ih = voyager_intr_establish(parent, VOYAGER_INTR_USB_HOST,
IPL_USB, ohci_intr, sc, devname);
if (sc->sc_ih == NULL) {
printf(": couldn't establish interrupt\n");
splx(s);
return;
}
printf(": %s, ", voyager_intr_string(sc->sc_ih));
vendor = pci_findvendor(pa->pa_id);
sc->sc.sc_id_vendor = PCI_VENDOR(pa->pa_id);
if (vendor)
strlcpy(sc->sc.sc_vendor, vendor, sizeof (sc->sc.sc_vendor));
else
snprintf(sc->sc.sc_vendor, sizeof (sc->sc.sc_vendor),
"vendor 0x%04x", PCI_VENDOR(pa->pa_id));
if (ohci_checkrev(&sc->sc) != USBD_NORMAL_COMPLETION ||
ohci_handover(&sc->sc) != USBD_NORMAL_COMPLETION) {
splx(s);
return;
}
sc->sc.sc_bus.dying = 1;
config_defer(self, ohci_voyager_attach_deferred);
splx(s);
}
void
ohci_voyager_attach_deferred(struct device *self)
{
struct ohci_voyager_softc *sc = (struct ohci_voyager_softc *)self;
usbd_status r;
int s;
s = splusb();
sc->sc.sc_bus.dying = 0;
r = ohci_init(&sc->sc);
if (r != USBD_NORMAL_COMPLETION) {
printf("%s: init failed, error=%d\n",
sc->sc.sc_bus.bdev.dv_xname, r);
bus_space_unmap(sc->sc.iot, sc->sc.ioh, sc->sc.sc_size);
splx(s);
return;
}
splx(s);
config_found(self, &sc->sc.sc_bus, usbctlprint);
}