Date: Wed, 29 Jun 2011 02:15:21 GMT From: Jakub Wojciech Klama <jceel@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 195493 for review Message-ID: <201106290215.p5T2FLPY000443@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@195493?ac=10 Change 195493 by jceel@jceel_cyclone on 2011/06/29 02:15:12 First version of USB OHCI host controller driver (broken). Affected files ... .. //depot/projects/soc2011/jceel_lpc/sys/arm/conf/EA3250#4 edit .. //depot/projects/soc2011/jceel_lpc/sys/arm/lpc/files.lpc#3 edit .. //depot/projects/soc2011/jceel_lpc/sys/arm/lpc/lpc_ohci.c#2 edit .. //depot/projects/soc2011/jceel_lpc/sys/boot/fdt/dts/ea3250.dts#3 edit Differences ... ==== //depot/projects/soc2011/jceel_lpc/sys/arm/conf/EA3250#4 (text+ko) ==== @@ -73,6 +73,15 @@ device bpf device lpe +# USB +options USB_DEBUG +device usb +device ohci +device umass +device scbus +device pass +device da + # Flattened Device Tree options FDT options FDT_DTB_STATIC ==== //depot/projects/soc2011/jceel_lpc/sys/arm/lpc/files.lpc#3 (text+ko) ==== @@ -10,5 +10,6 @@ arm/lpc/lpc_timer.c standard arm/lpc/lpc_rtc.c standard arm/lpc/if_lpe.c optional lpe +arm/lpc/lpc_ohci.c optional ohci dev/uart/uart_dev_ns8250.c optional uart kern/kern_clocksource.c standard ==== //depot/projects/soc2011/jceel_lpc/sys/arm/lpc/lpc_ohci.c#2 (text+ko) ==== @@ -27,15 +27,136 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <sys/stdint.h> +#include <sys/stddef.h> +#include <sys/param.h> +#include <sys/queue.h> +#include <sys/types.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/bus.h> +#include <sys/module.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <sys/condvar.h> +#include <sys/sysctl.h> +#include <sys/rman.h> +#include <sys/sx.h> +#include <sys/unistd.h> +#include <sys/callout.h> +#include <sys/malloc.h> +#include <sys/priv.h> + +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include <dev/usb/usb.h> +#include <dev/usb/usbdi.h> + +#include <dev/usb/usb_core.h> +#include <dev/usb/usb_busdma.h> +#include <dev/usb/usb_process.h> +#include <dev/usb/usb_util.h> + +#include <dev/usb/usb_controller.h> +#include <dev/usb/usb_bus.h> +#include <dev/usb/controller/ohci.h> +#include <dev/usb/controller/ohcireg.h> + + + static int lpc_ohci_probe(device_t dev); static int lpc_ohci_attach(device_t dev); +static int lpc_ohci_detach(device_t dev); +static int +lpc_ohci_probe(device_t dev) +{ + if (!ofw_bus_is_compatible(dev, "lpc,usb-ohci")) + return (ENXIO); + + device_set_desc(dev, "LPC32x0 USB OHCI controller"); + return (BUS_PROBE_DEFAULT); +} + +static int +lpc_ohci_attach(device_t dev) +{ + struct ohci_softc *sc = device_get_softc(dev); + int err; + int rid; + + sc->sc_bus.parent = dev; + sc->sc_bus.devices = sc->sc_devices; + sc->sc_bus.devices_max = OHCI_MAX_DEVICES; + + if (usb_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(dev), + &ohci_iterate_hw_softc)) + return (ENOMEM); + + rid = 0; + sc->sc_io_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); + if (!sc->sc_io_res) { + device_printf(dev, "cannot map register space\n"); + goto fail; + } + + sc->sc_io_tag = rman_get_bustag(sc->sc_io_res); + sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res); + sc->sc_io_size = rman_get_size(sc->sc_io_res); + + rid = 0; + sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); + if (sc->sc_irq_res == NULL) { + device_printf(dev, "cannot allocate interrupt\n"); + goto fail; + } + + sc->sc_bus.bdev = device_add_child(dev, "usbus", -1); + if (!(sc->sc_bus.bdev)) + goto fail; + + device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); + strlcpy(sc->sc_vendor, "NXP", sizeof(sc->sc_vendor)); + + err = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, + NULL , (void *)ohci_interrupt, sc, &sc->sc_intr_hdl); + if (err) { + sc->sc_intr_hdl = NULL; + goto fail; + } + + bus_space_write_4(sc->sc_io_tag, sc->sc_io_hdl, + OHCI_CONTROL, 0); + + err = ohci_init(sc); + if (err) + goto fail; + + err = device_probe_and_attach(sc->sc_bus.bdev); + if (err) + goto fail; + + return (0); + +fail: + /* XXX */ + return (ENXIO); +} + +static int +lpc_ohci_detach(device_t dev) +{ + return (0); +} + + static device_method_t lpc_ohci_methods[] = { /* Device interface */ DEVMETHOD(device_probe, lpc_ohci_probe), DEVMETHOD(device_attach, lpc_ohci_attach), DEVMETHOD(device_detach, lpc_ohci_detach), - DEVMETHOD(device_shutdown, lpc_ohci_shutdown), + DEVMETHOD(device_shutdown, bus_generic_shutdown), /* Bus interface */ DEVMETHOD(bus_print_child, bus_generic_print_child), ==== //depot/projects/soc2011/jceel_lpc/sys/boot/fdt/dts/ea3250.dts#3 (text+ko) ==== @@ -173,6 +173,13 @@ #size-cells = <1>; compatible = "simple-bus"; ranges = <0x0 0x30000000 0x10000000>; + + usb@1020000 { + compatible = "lpc,usb-ohci", "usb-ohci"; + reg = <0x1020000 0x20000>; + interrupts = <59>; + interrupt-parent = <&PIC>; + }; lpe@1060000 { compatible = "lpc,ethernet";
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201106290215.p5T2FLPY000443>