/* * 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. */ #include #include #include #include #include #include #include #include #include #include #define DEVNAME(_s) ((_s)->sc_dev.dv_xname) #define AMMUSB_DEBUG /* XXX */ #ifdef AMMUSB_DEBUG int ammusb_debug = 20; #define DPRINTF(n,s) do { if ((n) <= ammusb_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)) struct ammusb_softc { struct device sc_dev; bus_space_tag_t sc_iot; bus_space_handle_t sc_ioh; void *sc_ih; }; /* core decl */ int ammusb_match(struct device *, void *, void *); void ammusb_attach(struct device *, struct device *, void *); int ammusb_detach(struct device *, int); int ammusb_intr(void *); void ammusb_reset(struct ammusb_softc *); /* debug decl */ void ammusb_preg(uint32_t, char *, struct ammusb_softc *); void ammusb_dumpregs(struct ammusb_softc *); /* core/iomux.c def */ struct cfattach ammusb_ca = { sizeof (struct ammusb_softc), ammusb_match, ammusb_attach, ammusb_detach }; struct cfdriver ammusb_cd = { NULL, "ammusb", DV_DULL }; int ammusb_match(struct device *parent, void *v, void *aux) { struct fdt_attach_args *faa = aux; return OF_is_compatible(faa->fa_node, "ti,musb-am33xx"); } void ammusb_attach(struct device *parent, struct device *self, void *args) { struct ammusb_softc *sc = (struct ammusb_softc *) self; struct fdt_attach_args *faa = args; 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__); rev = HREAD4(sc, 0x0); printf(": rev %d.%d\n", rev >> 4 &0xf, rev & 0xf); // printf("%s: phys: 0x%08llx, size: %08llx\n", DEVNAME(sc), faa->fa_reg[0].addr, // faa->fa_reg[0].size); } int ammusb_detach(struct device *self, int flags) { return 0; /* XXX */ } int ammusb_intr(void * arg) { return 0; /* XXX */ }