Index: head/sys/mips/rt305x/files.rt305x =================================================================== --- head/sys/mips/rt305x/files.rt305x (revision 292702) +++ head/sys/mips/rt305x/files.rt305x (revision 292703) @@ -1,14 +1,19 @@ # $FreeBSD$ # RT305X on-board devices mips/rt305x/rt305x_machdep.c standard mips/rt305x/obio.c standard mips/rt305x/rt305x_sysctl.c standard mips/rt305x/rt305x_ic.c standard mips/rt305x/rt305x_gpio.c optional gpio mips/rt305x/uart_bus_rt305x.c optional uart mips/rt305x/uart_cpu_rt305x.c optional uart mips/rt305x/uart_dev_rt305x.c optional uart +mips/rt305x/rt305x_dotg.c optional dwcotg +mips/rt305x/rt305x_ehci.c optional ehci +mips/rt305x/rt305x_ohci.c optional ohci +mips/rt305x/rt305x_spi.c optional spibus +mips/rt305x/rt305x_pci.c optional pci mips/mips/intr_machdep.c standard mips/mips/tick.c standard dev/rt/if_rt.c optional rt Index: head/sys/mips/rt305x/obio.c =================================================================== --- head/sys/mips/rt305x/obio.c (revision 292702) +++ head/sys/mips/rt305x/obio.c (revision 292703) @@ -1,627 +1,636 @@ /* $NetBSD: obio.c,v 1.11 2003/07/15 00:25:05 lukem Exp $ */ /*- * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. * All rights reserved. * * Written by Jason R. Thorpe for Wasabi Systems, Inc. * * 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 WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC * 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 __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include /* MIPS HW interrupts of IRQ/FIQ respectively */ #define RT305X_INTR 0 #define RT305X_FAST_INTR 1 /* Interrupt levels */ #define INTR_IRQ 0 #define INTR_FIQ 1 int irq_priorities[NIRQS] = { INTR_IRQ, /* SYSCTL */ INTR_FIQ, /* TIMER0 */ INTR_FIQ, /* WDTIMER */ INTR_IRQ, /* Illegal Access */ INTR_IRQ, /* PCM */ INTR_IRQ, /* UART */ INTR_IRQ, /* GPIO */ INTR_FIQ, /* GDMA */ INTR_IRQ, /* NAND */ INTR_IRQ, /* Perfomance Counter */ INTR_IRQ, /* I2S */ INTR_IRQ, /* unknown */ INTR_IRQ, /* UARTLITE */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* EtherNet Switch */ INTR_FIQ, /* OTG */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ INTR_IRQ, /* unknown */ }; #define REG_READ(o) *((volatile uint32_t *)MIPS_PHYS_TO_KSEG1(INTCTL_BASE + (o))) #define REG_WRITE(o,v) (REG_READ(o)) = (v) static int obio_activate_resource(device_t, device_t, int, int, struct resource *); static device_t obio_add_child(device_t, u_int, const char *, int); static struct resource * obio_alloc_resource(device_t, device_t, int, int *, u_long, u_long, u_long, u_int); static int obio_attach(device_t); static int obio_deactivate_resource(device_t, device_t, int, int, struct resource *); static struct resource_list * obio_get_resource_list(device_t, device_t); static void obio_add_res_child(device_t, const char *, int, long, int, int); static void obio_hinted_child(device_t, const char *, int); static int obio_intr(void *); static int obio_probe(device_t); static int obio_release_resource(device_t, device_t, int, int, struct resource *); static int obio_setup_intr(device_t, device_t, struct resource *, int, driver_filter_t *, driver_intr_t *, void *, void **); static int obio_teardown_intr(device_t, device_t, struct resource *, void *); static void obio_mask_irq(void *source) { int irq; uint32_t irqmask; irq = (int)source; irqmask = 1 << irq; /* disable IRQ */ rt305x_ic_set(IC_INT_DIS, irqmask); } static void obio_unmask_irq(void *source) { int irq; uint32_t irqmask; irq = (int)source; irqmask = 1 << irq; /* enable IRQ */ rt305x_ic_set(IC_INT_ENA, irqmask); } static int obio_probe(device_t dev) { return (BUS_PROBE_NOWILDCARD); } static int obio_attach(device_t dev) { struct obio_softc *sc = device_get_softc(dev); int rid; sc->oba_mem_rman.rm_type = RMAN_ARRAY; sc->oba_mem_rman.rm_descr = "OBIO memory"; if (rman_init(&sc->oba_mem_rman) != 0 || rman_manage_region(&sc->oba_mem_rman, OBIO_MEM_START, OBIO_MEM_END) != 0) panic("obio_attach: failed to set up I/O rman"); sc->oba_irq_rman.rm_type = RMAN_ARRAY; sc->oba_irq_rman.rm_descr = "OBIO IRQ"; if (rman_init(&sc->oba_irq_rman) != 0 || rman_manage_region(&sc->oba_irq_rman, 0, NIRQS-1) != 0) panic("obio_attach: failed to set up IRQ rman"); /* Hook up our interrupt handler. */ if ((sc->sc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, RT305X_INTR, RT305X_INTR, 1, RF_SHAREABLE | RF_ACTIVE)) == NULL) { device_printf(dev, "unable to allocate IRQ resource\n"); return (ENXIO); } if ((bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC, obio_intr, NULL, sc, &sc->sc_ih))) { device_printf(dev, "WARNING: unable to register interrupt handler\n"); return (ENXIO); } /* Hook up our FAST interrupt handler. */ if ((sc->sc_fast_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, RT305X_FAST_INTR, RT305X_FAST_INTR, 1, RF_SHAREABLE | RF_ACTIVE)) == NULL) { device_printf(dev, "unable to allocate IRQ resource\n"); return (ENXIO); } if ((bus_setup_intr(dev, sc->sc_fast_irq, INTR_TYPE_MISC, obio_intr, NULL, sc, &sc->sc_fast_ih))) { device_printf(dev, "WARNING: unable to register interrupt handler\n"); return (ENXIO); } /* disable all interrupts */ rt305x_ic_set(IC_INT_DIS, IC_INT_MASK|IC_LINE_GLOBAL); bus_generic_probe(dev); obio_add_res_child(dev, "rt305x_sysctl", 0, SYSCTL_BASE, (SYSCTL_END - SYSCTL_BASE + 1), IC_SYSCTL); obio_add_res_child(dev, "rt305x_ic", 0, INTCTL_BASE, (INTCTL_END - INTCTL_BASE + 1), -1); #ifdef notyet obio_add_res_child(dev, "timer",0, TIMER_BASE, (TIMER_END - TIMER_BASE + 1), IC_TIMER0); obio_add_res_child(dev, "rt305x_memc", 0, MEMCTRL_BASE, (MEMCTRL_END - MEMCTRL_BASE + 1), -1); obio_add_res_child(dev, "pcm", 0, PCM_BASE, (PCM_END - PCM_BASE + 1), IC_PCM); +#endif obio_add_res_child(dev, "uart", 0, UART_BASE, (UART_END - UART_BASE + 1), IC_UART); -#endif obio_add_res_child(dev, "gpio", 0, PIO_BASE, (PIO_END - PIO_BASE + 1), IC_PIO); #ifdef notyet obio_add_res_child(dev, "rt305x_dma", 0, GDMA_BASE, (GDMA_END - GDMA_BASE + 1), IC_DMA); obio_add_res_child(dev, "rt305x_nandc", 0, NANDFC_BASE, (NANDFC_END - NANDFC_BASE + 1), IC_NAND); obio_add_res_child(dev, "i2c", 0, I2C_BASE, (I2C_END - I2C_BASE + 1), -1); obio_add_res_child(dev, "i2s", 0, I2S_BASE, (I2S_END - I2S_BASE + 1), IC_I2S); +#endif obio_add_res_child(dev, "spi", 0, SPI_BASE, (SPI_END - SPI_BASE + 1), -1); -#endif obio_add_res_child(dev, "uart", 1, UARTLITE_BASE, (UARTLITE_END - UARTLITE_BASE + 1), IC_UARTLITE); +#if !defined(RT5350) && !defined(MT7620) obio_add_res_child(dev, "cfi", 0, FLASH_BASE, (FLASH_END - FLASH_BASE + 1), -1); - obio_add_res_child(dev, "dotg", 0, + obio_add_res_child(dev, "dwcotg", 0, USB_OTG_BASE, (USB_OTG_END - USB_OTG_BASE + 1), IC_OTG); +#else + obio_add_res_child(dev, "ehci", 0, + USB_OTG_BASE, (USB_OTG_END - USB_OTG_BASE + 1), + IC_OTG); + obio_add_res_child(dev, "ohci", 0, + USB_OHCI_BASE, (USB_OHCI_END - USB_OHCI_BASE + 1), + IC_OTG); +#endif obio_add_res_child(dev, "switch", 0, ETHSW_BASE, (ETHSW_END - ETHSW_BASE + 1), IC_ETHSW); bus_enumerate_hinted_children(dev); bus_generic_attach(dev); /* enable IC */ rt305x_ic_set(IC_INT_ENA, IC_LINE_GLOBAL); return (0); } static struct resource * obio_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { struct obio_softc *sc = device_get_softc(bus); struct obio_ivar *ivar = device_get_ivars(child); struct resource *rv; struct resource_list_entry *rle; struct rman *rm; int isdefault, needactivate, passthrough; isdefault = (start == 0UL && end == ~0UL && count == 1); needactivate = flags & RF_ACTIVE; passthrough = (device_get_parent(child) != bus); rle = NULL; if (passthrough) return (BUS_ALLOC_RESOURCE(device_get_parent(bus), child, type, rid, start, end, count, flags)); /* * If this is an allocation of the "default" range for a given RID, * and we know what the resources for this device are (ie. they aren't * maintained by a child bus), then work out the start/end values. */ if (isdefault) { rle = resource_list_find(&ivar->resources, type, *rid); if (rle == NULL) return (NULL); if (rle->res != NULL) { panic("%s: resource entry is busy", __func__); } start = rle->start; end = rle->end; count = rle->count; } switch (type) { case SYS_RES_IRQ: rm = &sc->oba_irq_rman; break; case SYS_RES_MEMORY: rm = &sc->oba_mem_rman; break; default: printf("%s: unknown resource type %d\n", __func__, type); return (0); } rv = rman_reserve_resource(rm, start, end, count, flags, child); if (rv == 0) { printf("%s: could not reserve resource\n", __func__); return (0); } rman_set_rid(rv, *rid); if (needactivate) { if (bus_activate_resource(child, type, *rid, rv)) { printf("%s: could not activate resource\n", __func__); rman_release_resource(rv); return (0); } } return (rv); } static int obio_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { /* * If this is a memory resource, track the direct mapping * in the uncached MIPS KSEG1 segment. */ if (type == SYS_RES_MEMORY) { void *vaddr; vaddr = (void *)MIPS_PHYS_TO_KSEG1((intptr_t)rman_get_start(r)); rman_set_virtual(r, vaddr); rman_set_bustag(r, mips_bus_space_generic); rman_set_bushandle(r, (bus_space_handle_t)vaddr); } return (rman_activate_resource(r)); } static int obio_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { return (rman_deactivate_resource(r)); } static int obio_release_resource(device_t dev, device_t child, int type, int rid, struct resource *r) { struct resource_list *rl; struct resource_list_entry *rle; rl = obio_get_resource_list(dev, child); if (rl == NULL) return (EINVAL); rle = resource_list_find(rl, type, rid); if (rle == NULL) return (EINVAL); rman_release_resource(r); rle->res = NULL; return (0); } static int obio_setup_intr(device_t dev, device_t child, struct resource *ires, int flags, driver_filter_t *filt, driver_intr_t *handler, void *arg, void **cookiep) { struct obio_softc *sc = device_get_softc(dev); struct intr_event *event; int irq, error, priority; uint32_t irqmask; irq = rman_get_start(ires); if (irq >= NIRQS) panic("%s: bad irq %d", __func__, irq); event = sc->sc_eventstab[irq]; if (event == NULL) { error = intr_event_create(&event, (void *)irq, 0, irq, obio_mask_irq, obio_unmask_irq, NULL, NULL, "obio intr%d:", irq); sc->sc_eventstab[irq] = event; } else panic("obio: Can't share IRQs"); intr_event_add_handler(event, device_get_nameunit(child), filt, handler, arg, intr_priority(flags), flags, cookiep); irqmask = 1 << irq; priority = irq_priorities[irq]; if (priority == INTR_FIQ) rt305x_ic_set(IC_INTTYPE, rt305x_ic_get(IC_INTTYPE) | irqmask); else rt305x_ic_set(IC_INTTYPE, rt305x_ic_get(IC_INTTYPE) & ~irqmask); /* enable */ obio_unmask_irq((void*)irq); return (0); } static int obio_teardown_intr(device_t dev, device_t child, struct resource *ires, void *cookie) { struct obio_softc *sc = device_get_softc(dev); int irq, result, priority; uint32_t irqmask; irq = rman_get_start(ires); if (irq >= NIRQS) panic("%s: bad irq %d", __func__, irq); if (sc->sc_eventstab[irq] == NULL) panic("Trying to teardown unoccupied IRQ"); irqmask = (1 << irq); priority = irq_priorities[irq]; if (priority == INTR_FIQ) rt305x_ic_set(IC_INTTYPE, rt305x_ic_get(IC_INTTYPE) & ~irqmask); else rt305x_ic_set(IC_INTTYPE, rt305x_ic_get(IC_INTTYPE) | irqmask); /* disable */ obio_mask_irq((void*)irq); result = intr_event_remove_handler(cookie); if (!result) { sc->sc_eventstab[irq] = NULL; } return (result); } static int obio_intr(void *arg) { struct obio_softc *sc = arg; struct intr_event *event; uint32_t irqstat; int irq; irqstat = rt305x_ic_get(IC_IRQ0STAT); irqstat |= rt305x_ic_get(IC_IRQ1STAT); irq = 0; while (irqstat != 0) { if ((irqstat & 1) == 1) { event = sc->sc_eventstab[irq]; if (!event || TAILQ_EMPTY(&event->ie_handlers)) continue; /* TODO: pass frame as an argument*/ /* TODO: log stray interrupt */ intr_event_handle(event, NULL); } irq++; irqstat >>= 1; } return (FILTER_HANDLED); } static void obio_add_res_child(device_t bus, const char *dname, int dunit, long maddr, int msize, int irq) { device_t child; int result; child = BUS_ADD_CHILD(bus, 0, dname, dunit); result = bus_set_resource(child, SYS_RES_MEMORY, 0, maddr, msize); if (result != 0) device_printf(bus, "warning: bus_set_resource() failed\n"); if (irq != -1) { result = bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1); if (result != 0) device_printf(bus, "warning: bus_set_resource() failed\n"); } } static void obio_hinted_child(device_t bus, const char *dname, int dunit) { long maddr; int msize; int irq; /* * Set hard-wired resources for hinted child using * specific RIDs. */ resource_long_value(dname, dunit, "maddr", &maddr); resource_int_value(dname, dunit, "msize", &msize); if (resource_int_value(dname, dunit, "irq", &irq) == 0) irq = -1; obio_add_res_child(bus, dname, dunit, maddr, msize, irq); } static device_t obio_add_child(device_t bus, u_int order, const char *name, int unit) { device_t child; struct obio_ivar *ivar; ivar = malloc(sizeof(struct obio_ivar), M_DEVBUF, M_WAITOK | M_ZERO); if (ivar == NULL) { printf("Failed to allocate ivar\n"); return (0); } resource_list_init(&ivar->resources); child = device_add_child_ordered(bus, order, name, unit); if (child == NULL) { printf("Can't add child %s%d ordered\n", name, unit); return (0); } device_set_ivars(child, ivar); return (child); } /* * Helper routine for bus_generic_rl_get_resource/bus_generic_rl_set_resource * Provides pointer to resource_list for these routines */ static struct resource_list * obio_get_resource_list(device_t dev, device_t child) { struct obio_ivar *ivar; ivar = device_get_ivars(child); return (&(ivar->resources)); } static int obio_print_all_resources(device_t dev) { struct obio_ivar *ivar = device_get_ivars(dev); struct resource_list *rl = &ivar->resources; int retval = 0; if (STAILQ_FIRST(rl)) retval += printf(" at"); retval += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx"); retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld"); return (retval); } static int obio_print_child(device_t bus, device_t child) { int retval = 0; retval += bus_print_child_header(bus, child); retval += obio_print_all_resources(child); if (device_get_flags(child)) retval += printf(" flags %#x", device_get_flags(child)); retval += printf(" on %s\n", device_get_nameunit(bus)); return (retval); } static device_method_t obio_methods[] = { DEVMETHOD(bus_activate_resource, obio_activate_resource), DEVMETHOD(bus_add_child, obio_add_child), DEVMETHOD(bus_alloc_resource, obio_alloc_resource), DEVMETHOD(bus_deactivate_resource, obio_deactivate_resource), DEVMETHOD(bus_get_resource_list, obio_get_resource_list), DEVMETHOD(bus_hinted_child, obio_hinted_child), DEVMETHOD(bus_print_child, obio_print_child), DEVMETHOD(bus_release_resource, obio_release_resource), DEVMETHOD(bus_setup_intr, obio_setup_intr), DEVMETHOD(bus_teardown_intr, obio_teardown_intr), DEVMETHOD(device_attach, obio_attach), DEVMETHOD(device_probe, obio_probe), DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource), {0, 0}, }; static driver_t obio_driver = { "obio", obio_methods, sizeof(struct obio_softc), }; static devclass_t obio_devclass; DRIVER_MODULE(obio, nexus, obio_driver, obio_devclass, 0, 0); Index: head/sys/mips/rt305x/rt305x_dotg.c =================================================================== --- head/sys/mips/rt305x/rt305x_dotg.c (revision 292702) +++ head/sys/mips/rt305x/rt305x_dotg.c (revision 292703) @@ -1,231 +1,237 @@ #include __FBSDID("$FreeBSD$"); /*- + * Copyright (c) 2015 Stanislav Galabov. All rights reserved. * Copyright (c) 2010,2011 Aleksandr Rybalko. All rights reserved. * Copyright (c) 2007-2008 Hans Petter Selasky. All rights reserved. * * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include +#include #include #include #define MEM_RID 0 static device_probe_t dotg_obio_probe; static device_attach_t dotg_obio_attach; static device_detach_t dotg_obio_detach; -struct dotg_obio_softc { - struct dotg_softc sc_dci; /* must be first */ -}; - static int dotg_obio_probe(device_t dev) { device_set_desc(dev, "DWC like USB OTG controller"); return (0); } static int dotg_obio_attach(device_t dev) { - struct dotg_obio_softc *sc = device_get_softc(dev); - int err; + struct dwc_otg_softc *sc = device_get_softc(dev); + uint32_t tmp; + int err, rid; /* setup controller interface softc */ /* initialise some bus fields */ - sc->sc_dci.sc_dev = dev; - sc->sc_dci.sc_bus.parent = dev; - sc->sc_dci.sc_bus.devices = sc->sc_dci.sc_devices; - sc->sc_dci.sc_bus.devices_max = DOTG_MAX_DEVICES; - sc->sc_dci.sc_bus.dma_bits = 32; + sc->sc_mode = DWC_MODE_HOST; + sc->sc_bus.parent = dev; + sc->sc_bus.devices = sc->sc_devices; + sc->sc_bus.devices_max = DWC_OTG_MAX_DEVICES; + sc->sc_bus.dma_bits = 32; /* get all DMA memory */ - if (usb_bus_mem_alloc_all(&sc->sc_dci.sc_bus, + if (usb_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(dev), NULL)) { printf("No mem\n"); return (ENOMEM); } - sc->sc_dci.sc_mem_rid = 0; - sc->sc_dci.sc_mem_res = - bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_dci.sc_irq_rid, - RF_ACTIVE); - if (!(sc->sc_dci.sc_mem_res)) { + rid = 0; + sc->sc_io_res = + bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); + if (!(sc->sc_io_res)) { printf("Can`t alloc MEM\n"); goto error; } - sc->sc_dci.sc_bst = rman_get_bustag(sc->sc_dci.sc_mem_res); - sc->sc_dci.sc_bsh = rman_get_bushandle(sc->sc_dci.sc_mem_res); + 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); - sc->sc_dci.sc_irq_rid = 0; - sc->sc_dci.sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, - &sc->sc_dci.sc_irq_rid, RF_SHAREABLE| RF_ACTIVE); - if (!(sc->sc_dci.sc_irq_res)) { + rid = 0; + sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, + &rid, RF_ACTIVE); + if (!(sc->sc_irq_res)) { printf("Can`t alloc IRQ\n"); goto error; } - sc->sc_dci.sc_bus.bdev = device_add_child(dev, "usbus", -1); - if (!(sc->sc_dci.sc_bus.bdev)) { + sc->sc_bus.bdev = device_add_child(dev, "usbus", -1); + if (!(sc->sc_bus.bdev)) { printf("Can`t add usbus\n"); goto error; } - device_set_ivars(sc->sc_dci.sc_bus.bdev, &sc->sc_dci.sc_bus); + device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); #if (__FreeBSD_version >= 700031) - err = bus_setup_intr(dev, sc->sc_dci.sc_irq_res, - INTR_TYPE_BIO | INTR_MPSAFE, NULL, (driver_intr_t *)dotg_interrupt, - sc, &sc->sc_dci.sc_intr_hdl); + err = bus_setup_intr(dev, sc->sc_irq_res, + INTR_TYPE_TTY | INTR_MPSAFE, dwc_otg_filter_interrupt, + dwc_otg_interrupt, sc, &sc->sc_intr_hdl); #else - err = bus_setup_intr(dev, sc->sc_dci.sc_irq_res, - INTR_TYPE_BIO | INTR_MPSAFE, (driver_intr_t *)dotg_interrupt, - sc, &sc->sc_dci.sc_intr_hdl); + #error error + err = bus_setup_intr(dev, sc->sc_irq_res, + INTR_TYPE_BIO | INTR_MPSAFE,(driver_intr_t*)dwc_otg_interrupt, + sc, &sc->sc_intr_hdl); #endif if (err) { - sc->sc_dci.sc_intr_hdl = NULL; + sc->sc_intr_hdl = NULL; printf("Can`t set IRQ handle\n"); goto error; } /* Run clock for OTG core */ rt305x_sysctl_set(SYSCTL_CLKCFG1, rt305x_sysctl_get(SYSCTL_CLKCFG1) | SYSCTL_CLKCFG1_OTG_CLK_EN); - rt305x_sysctl_set(SYSCTL_RSTCTRL, SYSCTL_RSTCTRL_OTG); + tmp = rt305x_sysctl_get(SYSCTL_RSTCTRL); + rt305x_sysctl_set(SYSCTL_RSTCTRL, tmp | SYSCTL_RSTCTRL_OTG); DELAY(100); + /* + * Docs say that RSTCTRL bits for RT305x are W1C, so there should + * be no need for the below, but who really knows? + */ +// rt305x_sysctl_set(SYSCTL_RSTCTRL, tmp & ~SYSCTL_RSTCTRL_OTG); +// DELAY(100); - err = dotg_init(&sc->sc_dci); + err = dwc_otg_init(sc); if (err) printf("dotg_init fail\n"); if (!err) { - err = device_probe_and_attach(sc->sc_dci.sc_bus.bdev); - if (err) printf("device_probe_and_attach fail\n"); + err = device_probe_and_attach(sc->sc_bus.bdev); + if (err) printf("device_probe_and_attach fail %d\n", err); } if (err) { goto error; } return (0); error: dotg_obio_detach(dev); return (ENXIO); } static int dotg_obio_detach(device_t dev) { - struct dotg_obio_softc *sc = device_get_softc(dev); + struct dwc_otg_softc *sc = device_get_softc(dev); device_t bdev; int err; - if (sc->sc_dci.sc_bus.bdev) { - bdev = sc->sc_dci.sc_bus.bdev; + if (sc->sc_bus.bdev) { + bdev = sc->sc_bus.bdev; device_detach(bdev); device_delete_child(dev, bdev); } /* during module unload there are lots of children leftover */ device_delete_children(dev); - if (sc->sc_dci.sc_irq_res && sc->sc_dci.sc_intr_hdl) { + if (sc->sc_irq_res && sc->sc_intr_hdl) { /* * only call dotg_obio_uninit() after dotg_obio_init() */ - dotg_uninit(&sc->sc_dci); + dwc_otg_uninit(sc); /* Stop OTG clock */ rt305x_sysctl_set(SYSCTL_CLKCFG1, rt305x_sysctl_get(SYSCTL_CLKCFG1) & ~SYSCTL_CLKCFG1_OTG_CLK_EN); - err = bus_teardown_intr(dev, sc->sc_dci.sc_irq_res, - sc->sc_dci.sc_intr_hdl); - sc->sc_dci.sc_intr_hdl = NULL; + err = bus_teardown_intr(dev, sc->sc_irq_res, + sc->sc_intr_hdl); + sc->sc_intr_hdl = NULL; } - if (sc->sc_dci.sc_irq_res) { + if (sc->sc_irq_res) { bus_release_resource(dev, SYS_RES_IRQ, 0, - sc->sc_dci.sc_irq_res); - sc->sc_dci.sc_irq_res = NULL; + sc->sc_irq_res); + sc->sc_irq_res = NULL; } - if (sc->sc_dci.sc_mem_res) { + if (sc->sc_io_res) { bus_release_resource(dev, SYS_RES_MEMORY, 0, - sc->sc_dci.sc_mem_res); - sc->sc_dci.sc_mem_res = NULL; + sc->sc_io_res); + sc->sc_io_res = NULL; } - usb_bus_mem_free_all(&sc->sc_dci.sc_bus, NULL); + usb_bus_mem_free_all(&sc->sc_bus, NULL); return (0); } static device_method_t dotg_obio_methods[] = { /* Device interface */ DEVMETHOD(device_probe, dotg_obio_probe), DEVMETHOD(device_attach, dotg_obio_attach), DEVMETHOD(device_detach, dotg_obio_detach), DEVMETHOD(device_suspend, bus_generic_suspend), DEVMETHOD(device_resume, bus_generic_resume), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD_END }; static driver_t dotg_obio_driver = { - .name = "dotg", + .name = "dwcotg", .methods = dotg_obio_methods, - .size = sizeof(struct dotg_obio_softc), + .size = sizeof(struct dwc_otg_softc), }; static devclass_t dotg_obio_devclass; -DRIVER_MODULE(dotg, obio, dotg_obio_driver, dotg_obio_devclass, 0, 0); +DRIVER_MODULE(dwcotg, obio, dotg_obio_driver, dotg_obio_devclass, 0, 0); Index: head/sys/mips/rt305x/rt305x_machdep.c =================================================================== --- head/sys/mips/rt305x/rt305x_machdep.c (revision 292702) +++ head/sys/mips/rt305x/rt305x_machdep.c (revision 292703) @@ -1,191 +1,207 @@ /*- * Copyright (C) 2010-2011 by Aleksandr Rybalko. All rights reserved. * Copyright (C) 2007 by Oleksandr Tymoshenko. All rights reserved. * * 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 ``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 HIS RELATIVES 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 MIND, 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 __FBSDID("$FreeBSD$"); #include "opt_ddb.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include extern int *edata; extern int *end; static char boot1_env[0x1000]; void platform_cpu_init() { /* Nothing special */ } static void mips_init(void) { int i; + char *memsize; printf("entry: mips_init()\n"); + if ((memsize = kern_getenv("memsize")) != NULL) + realmem = btoc(strtol(memsize, NULL, 0) << 20); + else + realmem = btoc(32 << 20); + + bootverbose = 1; - realmem = btoc(32 << 20); for (i = 0; i < 10; i++) { phys_avail[i] = 0; } /* phys_avail regions are in bytes */ dump_avail[0] = phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end); dump_avail[1] = phys_avail[1] = ctob(realmem); physmem = realmem; init_param1(); init_param2(physmem); mips_cpu_init(); pmap_bootstrap(); mips_proc0_init(); mutex_init(); kdb_init(); #ifdef KDB if (boothowto & RB_KDB) kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); #endif } void platform_reset(void) { +#if !defined(MT7620) && !defined(RT5350) __asm __volatile("li $25, 0xbf000000"); __asm __volatile("j $25"); +#else + rt305x_sysctl_set(SYSCTL_RSTCTRL, 1); + while (1); +#endif } void platform_start(__register_t a0 __unused, __register_t a1 __unused, __register_t a2 __unused, __register_t a3 __unused) { vm_offset_t kernend; uint64_t platform_counter_freq = PLATFORM_COUNTER_FREQ; int i; int argc = a0; char **argv = (char **)MIPS_PHYS_TO_KSEG0(a1); char **envp = (char **)MIPS_PHYS_TO_KSEG0(a2); /* clear the BSS and SBSS segments */ kernend = (vm_offset_t)&end; memset(&edata, 0, kernend - (vm_offset_t)(&edata)); mips_postboot_fixup(); /* Initialize pcpu stuff */ mips_pcpu0_init(); + mips_timer_early_init(platform_counter_freq / 2); + /* initialize console so that we have printf */ boothowto |= (RB_SERIAL | RB_MULTIPLE); /* Use multiple consoles */ boothowto |= (RB_VERBOSE); cninit(); init_static_kenv(boot1_env, sizeof(boot1_env)); printf("U-Boot args (from %d args):\n", argc - 1); if (argc == 1) printf("\tNone\n"); for (i = 1; i < argc; i++) { char *n = "argv ", *arg; if (i > 99) break; if (argv[i]) { arg = (char *)(intptr_t)MIPS_PHYS_TO_KSEG0(argv[i]); printf("\targv[%d] = %s\n", i, arg); sprintf(n, "argv%d", i); kern_setenv(n, arg); } } printf("Environment:\n"); - for (i = 0; envp[i] ; i++) { + for (i = 0; envp[i] && MIPS_IS_VALID_PTR(envp[i]); i++) { char *n, *arg; arg = (char *)(intptr_t)MIPS_PHYS_TO_KSEG0(envp[i]); + if (! MIPS_IS_VALID_PTR(arg)) + continue; printf("\t%s\n", arg); n = strsep(&arg, "="); if (arg == NULL) kern_setenv(n, "1"); else kern_setenv(n, arg); } mips_init(); mips_timer_init_params(platform_counter_freq, 2); } Index: head/sys/mips/rt305x/rt305x_sysctl.c =================================================================== --- head/sys/mips/rt305x/rt305x_sysctl.c (revision 292702) +++ head/sys/mips/rt305x/rt305x_sysctl.c (revision 292703) @@ -1,240 +1,242 @@ /*- * Copyright (c) 2010 Aleksandr Rybalko. * All rights reserved. * * 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 __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include static int rt305x_sysctl_probe(device_t); static int rt305x_sysctl_attach(device_t); static int rt305x_sysctl_detach(device_t); static struct rt305x_sysctl_softc *rt305x_sysctl_softc = NULL; static void rt305x_sysctl_dump_config(device_t dev) { uint32_t val; #define DUMPREG(r) \ val = rt305x_sysctl_get(r); printf(" " #r "=%#08x\n", val) val = rt305x_sysctl_get(SYSCTL_CHIPID0_3); printf("\tChip ID: \"%c%c%c%c", (val >> 0 ) & 0xff, (val >> 8 ) & 0xff, (val >> 16) & 0xff, (val >> 24) & 0xff); val = rt305x_sysctl_get(SYSCTL_CHIPID4_7); printf("%c%c%c%c\"\n", (val >> 0 ) & 0xff, (val >> 8 ) & 0xff, (val >> 16) & 0xff, (val >> 24) & 0xff); DUMPREG(SYSCTL_SYSCFG); +#if !defined(RT5350) && !defined(MT7620) if ( val & SYSCTL_SYSCFG_INIC_EE_SDRAM) printf("\tGet SDRAM config from EEPROM\n"); if ( val & SYSCTL_SYSCFG_INIC_8MB_SDRAM) printf("\tBootstrap flag is set\n"); printf("\tGE0 mode %u\n", ((val & SYSCTL_SYSCFG_GE0_MODE_MASK) >> SYSCTL_SYSCFG_GE0_MODE_SHIFT)); if ( val & SYSCTL_SYSCFG_BOOT_ADDR_1F00) printf("\tBoot from 0x1f000000\n"); if ( val & SYSCTL_SYSCFG_BYPASS_PLL) printf("\tBypass PLL\n"); if ( val & SYSCTL_SYSCFG_BIG_ENDIAN) printf("\tBig Endian\n"); if ( val & SYSCTL_SYSCFG_CPU_CLK_SEL_384MHZ) printf("\tClock is 384MHz\n"); printf("\tBoot from %u\n", ((val & SYSCTL_SYSCFG_BOOT_FROM_MASK) >> SYSCTL_SYSCFG_BOOT_FROM_SHIFT)); printf("\tBootstrap test code %u\n", ((val & SYSCTL_SYSCFG_TEST_CODE_MASK) >> SYSCTL_SYSCFG_TEST_CODE_SHIFT)); printf("\tSRAM_CS mode %u\n", ((val & SYSCTL_SYSCFG_SRAM_CS_MODE_MASK) >> SYSCTL_SYSCFG_SRAM_CS_MODE_SHIFT)); printf("\t%umA SDRAM_CLK driving\n", (val & SYSCTL_SYSCFG_SDRAM_CLK_DRV)?12:8); DUMPREG(SYSCTL_CLKCFG0); printf("\tSDRAM_CLK_SKEW %uns\n", (val >> 30) & 0x03); DUMPREG(SYSCTL_CLKCFG1); if ( val & SYSCTL_CLKCFG1_PBUS_DIV_CLK_BY2) printf("\tPbus clock is 1/2 of System clock\n"); if ( val & SYSCTL_CLKCFG1_OTG_CLK_EN) printf("\tUSB OTG clock is enabled\n"); if ( val & SYSCTL_CLKCFG1_I2S_CLK_EN) printf("\tI2S clock is enabled\n"); printf("\tI2S clock is %s\n", (val & SYSCTL_CLKCFG1_I2S_CLK_SEL_EXT)? "external":"internal 15.625MHz"); printf("\tI2S clock divider %u\n", ((val & SYSCTL_CLKCFG1_I2S_CLK_DIV_MASK) >> SYSCTL_CLKCFG1_I2S_CLK_DIV_SHIFT)); if ( val & SYSCTL_CLKCFG1_PCM_CLK_EN) printf("\tPCM clock is enabled\n"); printf("\tPCM clock is %s\n", (val & SYSCTL_CLKCFG1_PCM_CLK_SEL_EXT)? "external":"internal 15.625MHz"); printf("\tPCM clock divider %u\n", ((val & SYSCTL_CLKCFG1_PCM_CLK_DIV_MASK) >> SYSCTL_CLKCFG1_PCM_CLK_DIV_SHIFT)); DUMPREG(SYSCTL_GPIOMODE); +#endif #undef DUMPREG return; } static int rt305x_sysctl_probe(device_t dev) { device_set_desc(dev, "RT305X System Control driver"); return (0); } static int rt305x_sysctl_attach(device_t dev) { struct rt305x_sysctl_softc *sc = device_get_softc(dev); int error = 0; KASSERT((device_get_unit(dev) == 0), ("rt305x_sysctl: Only one sysctl module supported")); if (rt305x_sysctl_softc != NULL) return (ENXIO); rt305x_sysctl_softc = sc; /* Map control/status registers. */ sc->mem_rid = 0; sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid, RF_ACTIVE); if (sc->mem_res == NULL) { device_printf(dev, "couldn't map memory\n"); error = ENXIO; rt305x_sysctl_detach(dev); return(error); } #ifdef notyet sc->irq_rid = 0; if ((sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) { device_printf(dev, "unable to allocate IRQ resource\n"); return (ENXIO); } if ((bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC, rt305x_sysctl_intr, NULL, sc, &sc->sysctl_ih))) { device_printf(dev, "WARNING: unable to register interrupt handler\n"); return (ENXIO); } #endif rt305x_sysctl_dump_config(dev); return (bus_generic_attach(dev)); } static int rt305x_sysctl_detach(device_t dev) { struct rt305x_sysctl_softc *sc = device_get_softc(dev); bus_generic_detach(dev); if (sc->mem_res) bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res); #ifdef notyet if (sc->irq_res) bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res); #endif return(0); } #ifdef notyet static int rt305x_sysctl_intr(void *arg) { return (FILTER_HANDLED); } #endif uint32_t rt305x_sysctl_get(uint32_t reg) { struct rt305x_sysctl_softc *sc = rt305x_sysctl_softc; return (bus_read_4(sc->mem_res, reg)); } void rt305x_sysctl_set(uint32_t reg, uint32_t val) { struct rt305x_sysctl_softc *sc = rt305x_sysctl_softc; bus_write_4(sc->mem_res, reg, val); return; } static device_method_t rt305x_sysctl_methods[] = { DEVMETHOD(device_probe, rt305x_sysctl_probe), DEVMETHOD(device_attach, rt305x_sysctl_attach), DEVMETHOD(device_detach, rt305x_sysctl_detach), {0, 0}, }; static driver_t rt305x_sysctl_driver = { "rt305x_sysctl", rt305x_sysctl_methods, sizeof(struct rt305x_sysctl_softc), }; static devclass_t rt305x_sysctl_devclass; DRIVER_MODULE(rt305x_sysctl, obio, rt305x_sysctl_driver, rt305x_sysctl_devclass, 0, 0); Index: head/sys/mips/rt305x/uart_bus_rt305x.c =================================================================== --- head/sys/mips/rt305x/uart_bus_rt305x.c (revision 292702) +++ head/sys/mips/rt305x/uart_bus_rt305x.c (revision 292703) @@ -1,102 +1,94 @@ /*- * Copyright (c) 2007 Bruce M. Simpson. * All rights reserved. * * 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 * $Id$ */ /* * Skeleton of this file was based on respective code for ARM * code written by Olivier Houchard. */ /* * XXXMIPS: This file is hacked from arm/... . XXXMIPS here means this file is * experimental and was written for MIPS32 port. */ #include "opt_uart.h" #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "uart_if.h" static int uart_rt305x_probe(device_t dev); extern struct uart_class uart_rt305x_uart_class; static device_method_t uart_rt305x_methods[] = { /* Device interface */ DEVMETHOD(device_probe, uart_rt305x_probe), DEVMETHOD(device_attach, uart_bus_attach), DEVMETHOD(device_detach, uart_bus_detach), { 0, 0 } }; static driver_t uart_rt305x_driver = { uart_driver_name, uart_rt305x_methods, sizeof(struct uart_softc), }; -extern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs; - static int uart_rt305x_probe(device_t dev) { struct uart_softc *sc; sc = device_get_softc(dev); - sc->sc_sysdev = SLIST_FIRST(&uart_sysdevs); sc->sc_class = &uart_rt305x_uart_class; - bcopy(&sc->sc_sysdev->bas, &sc->sc_bas, sizeof(sc->sc_bas)); - sc->sc_sysdev->bas.regshft = 2; - sc->sc_sysdev->bas.bst = mips_bus_space_generic; - sc->sc_sysdev->bas.bsh = - MIPS_PHYS_TO_KSEG1(device_get_unit(dev)?UARTLITE_BASE:UART_BASE); sc->sc_bas.regshft = 2; sc->sc_bas.bst = mips_bus_space_generic; sc->sc_bas.bsh = MIPS_PHYS_TO_KSEG1(device_get_unit(dev)?UARTLITE_BASE:UART_BASE); return (uart_bus_probe(dev, 2, SYSTEM_CLOCK, 0, 0)); } DRIVER_MODULE(uart, obio, uart_rt305x_driver, uart_devclass, 0, 0); Index: head/sys/mips/rt305x/uart_cpu_rt305x.c =================================================================== --- head/sys/mips/rt305x/uart_cpu_rt305x.c (revision 292702) +++ head/sys/mips/rt305x/uart_cpu_rt305x.c (revision 292703) @@ -1,82 +1,86 @@ /*- * Copyright (c) 2006 Wojciech A. Koszek * All rights reserved. * * 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. * * $Id$ */ /* * Skeleton of this file was based on respective code for ARM * code written by Olivier Houchard. */ /* * XXXMIPS: This file is hacked from arm/... . XXXMIPS here means this file is * experimental and was written for MIPS32 port. */ #include "opt_uart.h" #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include extern struct uart_class uart_rt305x_uart_class; bus_space_tag_t uart_bus_space_io; bus_space_tag_t uart_bus_space_mem; int uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) { return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0); } int uart_cpu_getdev(int devtype, struct uart_devinfo *di) { di->ops = uart_getops(&uart_rt305x_uart_class); di->bas.chan = 0; di->bas.bst = mips_bus_space_generic; di->bas.regshft = 2; di->bas.rclk = SYSTEM_CLOCK; di->baudrate = 115200; di->databits = 8; di->stopbits = 1; di->parity = UART_PARITY_NONE; uart_bus_space_io = NULL; uart_bus_space_mem = mips_bus_space_generic; +#ifdef RT305X_USE_UART + di->bas.bsh = MIPS_PHYS_TO_KSEG1(UART_BASE); +#else di->bas.bsh = MIPS_PHYS_TO_KSEG1(UARTLITE_BASE); +#endif return (0); }