iodi.c revision 198625
1/*- 2 * Copyright (c) 2003-2009 RMI Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of RMI Corporation, nor the names of its contributors, 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * RMI_BSD */ 30 31#define __RMAN_RESOURCE_VISIBLE 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/bus.h> 35#include <sys/kernel.h> 36#include <sys/lock.h> 37#include <sys/mutex.h> 38#include <sys/reboot.h> 39#include <sys/types.h> 40#include <sys/malloc.h> 41#include <sys/bus.h> 42#include <sys/interrupt.h> 43#include <sys/module.h> 44 45#include <machine/cpu.h> 46#include <machine/bus.h> 47#include <machine/bus.h> 48#include <machine/intr_machdep.h> 49#include <mips/rmi/iomap.h> 50#include <mips/rmi/pic.h> 51#include <mips/rmi/shared_structs.h> 52#include <mips/rmi/board.h> 53#include <sys/rman.h> 54 55 56#include <machine/param.h> 57#include <machine/intr_machdep.h> 58#include <machine/clock.h> /* for DELAY */ 59#include <machine/bus.h> 60#include <machine/resource.h> 61#include <mips/rmi/interrupt.h> 62#include <mips/rmi/msgring.h> 63#include <mips/rmi/iomap.h> 64#include <mips/rmi/debug.h> 65#include <mips/rmi/pic.h> 66#include <mips/rmi/xlrconfig.h> 67#include <mips/rmi/shared_structs.h> 68#include <mips/rmi/board.h> 69 70#include <dev/rmi/xlr/atx_cpld.h> 71#include <dev/rmi/xlr/xgmac_mdio.h> 72 73extern void iodi_activateirqs(void); 74 75extern bus_space_tag_t uart_bus_space_mem; 76 77static struct resource * 78iodi_alloc_resource(device_t, device_t, int, int *, 79 u_long, u_long, u_long, u_int); 80 81static int 82iodi_activate_resource(device_t, device_t, int, int, 83 struct resource *); 84static int 85iodi_setup_intr(device_t, device_t, struct resource *, int, 86 driver_filter_t *, driver_intr_t *, void *, void **); 87 88struct iodi_softc *iodi_softc; /* There can be only one. */ 89 90/* 91static void pic_usb_ack(void *arg) 92{ 93 xlr_reg_t *mmio = xlr_io_mmio(XLR_IO_PIC_OFFSET); 94 int irq = PIC_USB_IRQ ; 95 96 mtx_lock_spin(&xlr_pic_lock); 97 xlr_write_reg(mmio, PIC_INT_ACK, (1 << (irq - PIC_IRQ_BASE))); 98 mtx_unlock_spin(&xlr_pic_lock); 99} 100*/ 101 102static int 103iodi_setup_intr(device_t dev, device_t child, 104 struct resource *ires, int flags, driver_filter_t * filt, driver_intr_t * intr, void *arg, 105 void **cookiep) 106{ 107 int level; 108 xlr_reg_t *mmio = xlr_io_mmio(XLR_IO_PIC_OFFSET); 109 xlr_reg_t reg; 110 111 /* FIXME is this the right place to fiddle with PIC? */ 112 if (strcmp(device_get_name(child), "uart") == 0) { 113 /* FIXME uart 1? */ 114 mtx_lock_spin(&xlr_pic_lock); 115 level = PIC_IRQ_IS_EDGE_TRIGGERED(PIC_IRT_UART_0_INDEX); 116 xlr_write_reg(mmio, PIC_IRT_0_UART_0, 0x01); 117 xlr_write_reg(mmio, PIC_IRT_1_UART_0, ((1 << 31) | (level << 30) | (1 << 6) | (PIC_UART_0_IRQ))); 118 mtx_unlock_spin(&xlr_pic_lock); 119 cpu_establish_hardintr("uart", NULL, 120 (driver_intr_t *) intr, (void *)arg, PIC_UART_0_IRQ, flags, cookiep); 121 122 } else if (strcmp(device_get_name(child), "rge") == 0) { 123 int irq; 124 125 irq = rman_get_rid(ires); 126 mtx_lock_spin(&xlr_pic_lock); 127 reg = xlr_read_reg(mmio, PIC_IRT_1_BASE + irq - PIC_IRQ_BASE); 128 xlr_write_reg(mmio, PIC_IRT_1_BASE + irq - PIC_IRQ_BASE, reg | (1 << 6) | (1 << 30) | (1 << 31)); 129 mtx_unlock_spin(&xlr_pic_lock); 130 cpu_establish_hardintr("rge", NULL, (driver_intr_t *) intr, (void *)arg, irq, flags, cookiep); 131 132 } else if (strcmp(device_get_name(child), "ehci") == 0) { 133 mtx_lock_spin(&xlr_pic_lock); 134 reg = xlr_read_reg(mmio, PIC_IRT_1_BASE + PIC_USB_IRQ - PIC_IRQ_BASE); 135 xlr_write_reg(mmio, PIC_IRT_1_BASE + PIC_USB_IRQ - PIC_IRQ_BASE, reg | (1 << 6) | (1 << 30) | (1 << 31)); 136 mtx_unlock_spin(&xlr_pic_lock); 137 cpu_establish_hardintr("ehci", NULL, (driver_intr_t *) intr, (void *)arg, PIC_USB_IRQ, flags, cookiep); 138 } 139 BUS_SETUP_INTR(device_get_parent(dev), 140 child, ires, flags, filt, intr, arg, cookiep); 141 142 143 return (0); 144} 145 146/* Strange hook found in mips/include/bus.h */ 147#ifndef MIPS_BUS_SPACE_PCI 148#define MIPS_BUS_SPACE_PCI 10 149#endif 150 151static struct resource * 152iodi_alloc_resource(device_t bus, device_t child, int type, int *rid, 153 u_long start, u_long end, u_long count, u_int flags) 154{ 155 struct resource *res = malloc(sizeof(*res), M_DEVBUF, M_WAITOK); 156 int unit; 157 158#ifdef DEBUG 159 switch (type) { 160 case SYS_RES_IRQ: 161 device_printf(bus, "IRQ resource - for %s %lx-%lx\n", 162 device_get_nameunit(child), start, end); 163 break; 164 165 case SYS_RES_IOPORT: 166 device_printf(bus, "IOPORT resource - for %s %lx-%lx\n", 167 device_get_nameunit(child), start, end); 168 break; 169 170 case SYS_RES_MEMORY: 171 device_printf(bus, "MEMORY resource - for %s %lx-%lx\n", 172 device_get_nameunit(child), start, end); 173 break; 174 } 175#endif 176 177 if (strcmp(device_get_name(child), "uart") == 0) { 178 if ((unit = device_get_unit(child)) == 0) { /* uart 0 */ 179 res->r_bushandle = (xlr_io_base + XLR_IO_UART_0_OFFSET); 180 } else if (unit == 1) { 181 res->r_bushandle = (xlr_io_base + XLR_IO_UART_1_OFFSET); 182 } else 183 printf("%s: Unknown uart unit\n", __FUNCTION__); 184 185 res->r_bustag = uart_bus_space_mem; 186 } else if (strcmp(device_get_name(child), "ehci") == 0) { 187 res->r_bushandle = 0xbef24000; 188 res->r_bustag = (bus_space_tag_t) MIPS_BUS_SPACE_PCI; 189 } else if (strcmp(device_get_name(child), "cfi") == 0) { 190 res->r_bushandle = 0xbc000000; 191 res->r_bustag = 0; 192 } 193 /* res->r_start = *rid; */ 194 return (res); 195} 196 197static int 198iodi_activate_resource(device_t bus, device_t child, int type, int rid, 199 struct resource *r) 200{ 201 return (0); 202} 203 204/* prototypes */ 205static int iodi_probe(device_t); 206static int iodi_attach(device_t); 207static void iodi_identify(driver_t *, device_t); 208 209int 210iodi_probe(device_t dev) 211{ 212 return 0; 213} 214 215void 216iodi_identify(driver_t * driver, device_t parent) 217{ 218 219 BUS_ADD_CHILD(parent, 0, "iodi", 0); 220} 221 222int 223iodi_attach(device_t dev) 224{ 225 device_t tmpd; 226 227 /* 228 * Attach each devices 229 */ 230 device_add_child(dev, "uart", 0); 231 device_add_child(dev, "xlr_i2c", 0); 232 233 if (xlr_board_info.usb) 234 device_add_child(dev, "ehci", 0); 235 236 if (xlr_board_info.cfi) 237 device_add_child(dev, "cfi", 0); 238 239 if (xlr_board_info.gmac_block[0].enabled) { 240 tmpd = device_add_child(dev, "rge", 0); 241 device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]); 242 243 tmpd = device_add_child(dev, "rge", 1); 244 device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]); 245 246 tmpd = device_add_child(dev, "rge", 2); 247 device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]); 248 249 tmpd = device_add_child(dev, "rge", 3); 250 device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]); 251 } 252 if (xlr_board_info.gmac_block[1].enabled) { 253 if (xlr_board_info.gmac_block[1].type == XLR_GMAC) { 254 tmpd = device_add_child(dev, "rge", 4); 255 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 256 257 tmpd = device_add_child(dev, "rge", 5); 258 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 259 260 tmpd = device_add_child(dev, "rge", 6); 261 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 262 263 tmpd = device_add_child(dev, "rge", 7); 264 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 265 } else if (xlr_board_info.gmac_block[1].type == XLR_XGMAC) { 266#if 0 /* XGMAC not yet */ 267 tmpd = device_add_child(dev, "rge", 4); 268 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 269 270 tmpd = device_add_child(dev, "rge", 5); 271 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 272#endif 273 } else 274 device_printf(dev, "Unknown type of gmac 1\n"); 275 } 276 bus_generic_probe(dev); 277 bus_generic_attach(dev); 278 return 0; 279} 280 281static device_method_t iodi_methods[] = { 282 DEVMETHOD(device_probe, iodi_probe), 283 DEVMETHOD(device_attach, iodi_attach), 284 DEVMETHOD(device_identify, iodi_identify), 285 DEVMETHOD(bus_alloc_resource, iodi_alloc_resource), 286 DEVMETHOD(bus_activate_resource, iodi_activate_resource), 287 DEVMETHOD(bus_setup_intr, iodi_setup_intr), 288 {0, 0}, 289}; 290 291static driver_t iodi_driver = { 292 "iodi", 293 iodi_methods, 294 1 /* no softc */ 295}; 296static devclass_t iodi_devclass; 297 298DRIVER_MODULE(iodi, nexus, iodi_driver, iodi_devclass, 0, 0); 299