Esempio n. 1
0
static void
at91_udp_clocks_on(void *arg)
{
    struct at91_udp_softc *sc = arg;

    at91_pmc_clock_enable(sc->sc_iclk);
    at91_pmc_clock_enable(sc->sc_fclk);
}
Esempio n. 2
0
static int
ohci_atmelarm_attach(device_t dev)
{
    struct at91_ohci_softc *sc = device_get_softc(dev);
    int err;
    int rid;

    /* initialise some bus fields */
    sc->sc_ohci.sc_bus.parent = dev;
    sc->sc_ohci.sc_bus.devices = sc->sc_ohci.sc_devices;
    sc->sc_ohci.sc_bus.devices_max = OHCI_MAX_DEVICES;

    /* get all DMA memory */
    if (usb_bus_mem_alloc_all(&sc->sc_ohci.sc_bus,
                              USB_GET_DMA_TAG(dev), &ohci_iterate_hw_softc)) {
        return (ENOMEM);
    }
    sc->iclk = at91_pmc_clock_ref("ohci_clk");
    sc->fclk = at91_pmc_clock_ref("uhpck");

    sc->sc_ohci.sc_dev = dev;

    rid = MEM_RID;
    sc->sc_ohci.sc_io_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
                            &rid, RF_ACTIVE);

    if (!(sc->sc_ohci.sc_io_res)) {
        err = ENOMEM;
        goto error;
    }
    sc->sc_ohci.sc_io_tag = rman_get_bustag(sc->sc_ohci.sc_io_res);
    sc->sc_ohci.sc_io_hdl = rman_get_bushandle(sc->sc_ohci.sc_io_res);
    sc->sc_ohci.sc_io_size = rman_get_size(sc->sc_ohci.sc_io_res);

    rid = 0;
    sc->sc_ohci.sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
                             RF_ACTIVE);
    if (!(sc->sc_ohci.sc_irq_res)) {
        goto error;
    }
    sc->sc_ohci.sc_bus.bdev = device_add_child(dev, "usbus", -1);
    if (!(sc->sc_ohci.sc_bus.bdev)) {
        goto error;
    }
    device_set_ivars(sc->sc_ohci.sc_bus.bdev, &sc->sc_ohci.sc_bus);

    strlcpy(sc->sc_ohci.sc_vendor, "Atmel", sizeof(sc->sc_ohci.sc_vendor));

#if (__FreeBSD_version >= 700031)
    err = bus_setup_intr(dev, sc->sc_ohci.sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
                         NULL, (driver_intr_t *)ohci_interrupt, sc, &sc->sc_ohci.sc_intr_hdl);
#else
    err = bus_setup_intr(dev, sc->sc_ohci.sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
                         (driver_intr_t *)ohci_interrupt, sc, &sc->sc_ohci.sc_intr_hdl);
#endif
    if (err) {
        sc->sc_ohci.sc_intr_hdl = NULL;
        goto error;
    }
    /*
     * turn on the clocks from the AT91's point of view.  Keep the unit in reset.
     */
    at91_pmc_clock_enable(sc->iclk);
    at91_pmc_clock_enable(sc->fclk);
    bus_space_write_4(sc->sc_ohci.sc_io_tag, sc->sc_ohci.sc_io_hdl,
                      OHCI_CONTROL, 0);

    err = ohci_init(&sc->sc_ohci);
    if (!err) {
        err = device_probe_and_attach(sc->sc_ohci.sc_bus.bdev);
    }
    if (err) {
        goto error;
    }
    return (0);

error:
    ohci_atmelarm_detach(dev);
    return (ENXIO);
}