/* * Copyright (c) 2017 Ian Sutton * Copyright (c) 2013 Oleksandr Tymoshenko * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * USB subsystem driver for am335x. Derived from FreeBSD version. */ #include #include #include #include #include #include #include #include #include #define DEVNAME(_s) ((_s)->sc_dev.dv_xname) #define AMUSBSS_DEBUG /* XXX */ #ifdef AMUSBSS_DEBUG int amusbss_debug = 20; #define DPRINTF(n,s) do { if ((n) <= amusbss_debug) printf s; } while (0) #else #define DPRINTF(n,s) do {} #endif #define HREAD4(sc, reg) \ (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg))) #define HWRITE4(sc, reg, val) \ bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val)) #define HSET4(sc, reg, bits) \ HWRITE4((sc), (reg), HREAD4((sc), (reg)) | (bits)) #define HCLR4(sc, reg, bits) \ HWRITE4((sc), (reg), HREAD4((sc), (reg)) & ~(bits)) #define USBSS_REVREG 0x00 #define USBSS_SYSCONFIG 0x10 #define USBSS_SYSCONFIG_SRESET 1 #define USBCTRL_REV 0x00 #define USBCTRL_CTRL 0x14 #define USBCTRL_STAT 0x18 #define USBCTRL_IRQ_STAT0 0x30 #define IRQ_STAT0_RXSHIFT 16 #define IRQ_STAT0_TXSHIFT 0 #define USBCTRL_IRQ_STAT1 0x34 #define IRQ_STAT1_DRVVBUS (1 << 8) #define USBCTRL_INTEN_SET0 0x38 #define USBCTRL_INTEN_SET1 0x3C #define USBCTRL_INTEN_USB_ALL 0x1ff #define USBCTRL_INTEN_USB_SOF (1 << 3) #define USBCTRL_INTEN_CLR0 0x40 #define USBCTRL_INTEN_CLR1 0x44 #define USBCTRL_UTMI 0xE0 #define USBCTRL_UTMI_FSDATAEXT (1 << 1) #define USBCTRL_MODE 0xE8 #define USBCTRL_MODE_IDDIG (1 << 8) #define USBCTRL_MODE_IDDIGMUX (1 << 7) struct amusbss_softc { struct device sc_dev; // struct simplebus_softc sc_sbus; bus_space_tag_t sc_iot; void *sc_ih; bus_dma_tag_t sc_dmat; bus_space_handle_t sc_ioh; bus_size_t sc_ios; bus_space_handle_t sc_ioh_dma_ctl; bus_size_t sc_ios_dma_ctl; bus_space_handle_t sc_ioh_dma_sched; bus_size_t sc_ios_dma_sched; bus_space_handle_t sc_ioh_queue; bus_size_t sc_ios_queue; }; /* XXX figure out what to do instead of this XXX */ extern void simplebus_attach_node(struct device *, int); /* core decl */ int amusbss_match(struct device *, void *, void *); void amusbss_attach(struct device *, struct device *, void *); int amusbss_detach(struct device *, int); void amusbss_reset(struct amusbss_softc *); void amusbss_map_dma(int); /* debug decl */ void amusbss_preg(uint32_t, char *, struct amusbss_softc *); void amusbss_dumpregs(struct amusbss_softc *); /* core/iomux.c defs */ struct cfattach amusbss_ca = { sizeof (struct amusbss_softc), amusbss_match, amusbss_attach, amusbss_detach }; struct cfdriver amusbss_cd = { NULL, "amusbss", DV_DULL }; int amusbss_match(struct device *parent, void *v, void *aux) { struct fdt_attach_args *faa = aux; return OF_is_compatible(faa->fa_node, "ti,am33xx-usb"); } void amusbss_attach(struct device *parent, struct device *self, void *args) { struct amusbss_softc *sc = (struct amusbss_softc *) self; struct fdt_attach_args *faa = args; int i, node; uint32_t rev; sc->sc_iot = faa->fa_iot; if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, faa->fa_reg[0].size, 0, &sc->sc_ioh)) panic("%s: bus_space_map failed!", __func__); sc->sc_ios = faa->fa_reg[0].size; /* Enable device clocks */ prcm_enablemodule(PRCM_USB); /* Reset USB subsystem, USB0 and USB1 */ HWRITE4(sc, USBSS_SYSCONFIG, USBSS_SYSCONFIG_SRESET); delay(100); i = 10; while (HREAD4(sc, USBSS_SYSCONFIG) & USBSS_SYSCONFIG_SRESET) { delay(100); if (i-- == 0) { printf(": reset timeout.\n"); return; } } rev = HREAD4(sc, USBSS_REVREG); printf(": rev %d.%d\n", rev >> 4 &0xf, rev & 0xf); //faa->fa_node = node; //simplebus_attach(parent, &sc->sc_sbus.sc_dev, faa); /* Walk FDT child nodes to attach ammusb devices, map DMA controllers */ for (node = OF_child(faa->fa_node); node > 0; node = OF_peer(node)) { if (OF_is_compatible(node, "ti,am3359-cppi41")) { amusbss_map_dma(node); } else { simplebus_attach_node(parent, node); } } } int amusbss_detach(struct device *self, int flags) { struct amusbss_softc *sc = (struct amusbss_softc *) self; bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios); if (sc->sc_ioh_dma_ctl) bus_space_unmap(sc->sc_iot, sc->sc_ioh_dma_ctl, sc->sc_ios_dma_ctl); if (sc->sc_ioh_dma_sched) bus_space_unmap(sc->sc_iot, sc->sc_ioh_dma_sched, sc->sc_ios_dma_sched); if (sc->sc_ioh_queue) bus_space_unmap(sc->sc_iot, sc->sc_ioh_queue, sc->sc_ios_queue); return 0; } void amusbss_map_dma(int node) { /* XXX TODO */ }