iodi.c revision 199089
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 102 103static int 104iodi_setup_intr(device_t dev, device_t child, 105 struct resource *ires, int flags, driver_filter_t * filt, driver_intr_t * intr, void *arg, 106 void **cookiep) 107{ 108 int level; 109 xlr_reg_t *mmio = xlr_io_mmio(XLR_IO_PIC_OFFSET); 110 xlr_reg_t reg; 111 112 /* FIXME is this the right place to fiddle with PIC? */ 113 if (strcmp(device_get_name(child), "uart") == 0) { 114 /* FIXME uart 1? */ 115 if (rmi_spin_mutex_safe) 116 mtx_lock_spin(&xlr_pic_lock); 117 level = PIC_IRQ_IS_EDGE_TRIGGERED(PIC_IRT_UART_0_INDEX); 118 xlr_write_reg(mmio, PIC_IRT_0_UART_0, 0x01); 119 xlr_write_reg(mmio, PIC_IRT_1_UART_0, ((1 << 31) | (level << 30) | (1 << 6) | (PIC_UART_0_IRQ))); 120 if (rmi_spin_mutex_safe) 121 mtx_unlock_spin(&xlr_pic_lock); 122 cpu_establish_hardintr("uart", NULL, 123 (driver_intr_t *) intr, (void *)arg, PIC_UART_0_IRQ, flags, cookiep); 124 125 } else if (strcmp(device_get_name(child), "rge") == 0) { 126 int irq; 127 /* This is a hack to pass in the irq */ 128 irq = (int)ires->__r_i; 129 if (rmi_spin_mutex_safe) 130 mtx_lock_spin(&xlr_pic_lock); 131 reg = xlr_read_reg(mmio, PIC_IRT_1_BASE + irq - PIC_IRQ_BASE); 132 xlr_write_reg(mmio, PIC_IRT_1_BASE + irq - PIC_IRQ_BASE, reg | (1 << 6) | (1 << 30) | (1 << 31)); 133 if (rmi_spin_mutex_safe) 134 mtx_unlock_spin(&xlr_pic_lock); 135 cpu_establish_hardintr("rge", NULL, (driver_intr_t *) intr, (void *)arg, irq, flags, cookiep); 136 137 } else if (strcmp(device_get_name(child), "ehci") == 0) { 138 if (rmi_spin_mutex_safe) 139 mtx_lock_spin(&xlr_pic_lock); 140 reg = xlr_read_reg(mmio, PIC_IRT_1_BASE + PIC_USB_IRQ - PIC_IRQ_BASE); 141 xlr_write_reg(mmio, PIC_IRT_1_BASE + PIC_USB_IRQ - PIC_IRQ_BASE, reg | (1 << 6) | (1 << 30) | (1 << 31)); 142 if (rmi_spin_mutex_safe) 143 mtx_unlock_spin(&xlr_pic_lock); 144 cpu_establish_hardintr("ehci", NULL, (driver_intr_t *) intr, (void *)arg, PIC_USB_IRQ, flags, cookiep); 145 } 146 /* This causes a panic and looks recursive to me (RRS). 147 BUS_SETUP_INTR(device_get_parent(dev), 148 child, ires, flags, filt, intr, arg, cookiep); 149 */ 150 151 return (0); 152} 153 154/* Strange hook found in mips/include/bus.h */ 155#ifndef MIPS_BUS_SPACE_PCI 156#define MIPS_BUS_SPACE_PCI 10 157#endif 158 159static struct resource * 160iodi_alloc_resource(device_t bus, device_t child, int type, int *rid, 161 u_long start, u_long end, u_long count, u_int flags) 162{ 163 struct resource *res = malloc(sizeof(*res), M_DEVBUF, M_WAITOK); 164 int unit; 165 166#ifdef DEBUG 167 switch (type) { 168 case SYS_RES_IRQ: 169 device_printf(bus, "IRQ resource - for %s %lx-%lx\n", 170 device_get_nameunit(child), start, end); 171 break; 172 173 case SYS_RES_IOPORT: 174 device_printf(bus, "IOPORT resource - for %s %lx-%lx\n", 175 device_get_nameunit(child), start, end); 176 break; 177 178 case SYS_RES_MEMORY: 179 device_printf(bus, "MEMORY resource - for %s %lx-%lx\n", 180 device_get_nameunit(child), start, end); 181 break; 182 } 183#endif 184 185 if (strcmp(device_get_name(child), "uart") == 0) { 186 if ((unit = device_get_unit(child)) == 0) { /* uart 0 */ 187 res->r_bushandle = (xlr_io_base + XLR_IO_UART_0_OFFSET); 188 } else if (unit == 1) { 189 res->r_bushandle = (xlr_io_base + XLR_IO_UART_1_OFFSET); 190 } else 191 printf("%s: Unknown uart unit\n", __FUNCTION__); 192 193 res->r_bustag = uart_bus_space_mem; 194 } else if (strcmp(device_get_name(child), "ehci") == 0) { 195 res->r_bushandle = 0xbef24000; 196 res->r_bustag = (bus_space_tag_t) MIPS_BUS_SPACE_PCI; 197 } else if (strcmp(device_get_name(child), "cfi") == 0) { 198 res->r_bushandle = 0xbc000000; 199 res->r_bustag = 0; 200 } 201 /* res->r_start = *rid; */ 202 return (res); 203} 204 205static int 206iodi_activate_resource(device_t bus, device_t child, int type, int rid, 207 struct resource *r) 208{ 209 return (0); 210} 211 212/* prototypes */ 213static int iodi_probe(device_t); 214static int iodi_attach(device_t); 215static void iodi_identify(driver_t *, device_t); 216 217int 218iodi_probe(device_t dev) 219{ 220 return 0; 221} 222 223void 224iodi_identify(driver_t * driver, device_t parent) 225{ 226 227 BUS_ADD_CHILD(parent, 0, "iodi", 0); 228} 229 230int 231iodi_attach(device_t dev) 232{ 233 device_t tmpd; 234 235 /* 236 * Attach each devices 237 */ 238 device_add_child(dev, "uart", 0); 239 device_add_child(dev, "xlr_i2c", 0); 240 241 if (xlr_board_info.usb) 242 device_add_child(dev, "ehci", 0); 243 244 if (xlr_board_info.cfi) 245 device_add_child(dev, "cfi", 0); 246 247 if (xlr_board_info.gmac_block[0].enabled) { 248 tmpd = device_add_child(dev, "rge", 0); 249 device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]); 250 251 tmpd = device_add_child(dev, "rge", 1); 252 device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]); 253 254 tmpd = device_add_child(dev, "rge", 2); 255 device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]); 256 257 tmpd = device_add_child(dev, "rge", 3); 258 device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]); 259 } 260 if (xlr_board_info.gmac_block[1].enabled) { 261 if (xlr_board_info.gmac_block[1].type == XLR_GMAC) { 262 tmpd = device_add_child(dev, "rge", 4); 263 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 264 265 tmpd = device_add_child(dev, "rge", 5); 266 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 267 268 tmpd = device_add_child(dev, "rge", 6); 269 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 270 271 tmpd = device_add_child(dev, "rge", 7); 272 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 273 } else if (xlr_board_info.gmac_block[1].type == XLR_XGMAC) { 274#if 0 /* XGMAC not yet */ 275 tmpd = device_add_child(dev, "rge", 4); 276 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 277 278 tmpd = device_add_child(dev, "rge", 5); 279 device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]); 280#endif 281 } else 282 device_printf(dev, "Unknown type of gmac 1\n"); 283 } 284 bus_generic_probe(dev); 285 bus_generic_attach(dev); 286 return 0; 287} 288 289static device_method_t iodi_methods[] = { 290 DEVMETHOD(device_probe, iodi_probe), 291 DEVMETHOD(device_attach, iodi_attach), 292 DEVMETHOD(device_identify, iodi_identify), 293 DEVMETHOD(bus_alloc_resource, iodi_alloc_resource), 294 DEVMETHOD(bus_activate_resource, iodi_activate_resource), 295 DEVMETHOD(bus_setup_intr, iodi_setup_intr), 296 {0, 0}, 297}; 298 299static driver_t iodi_driver = { 300 "iodi", 301 iodi_methods, 302 1 /* no softc */ 303}; 304static devclass_t iodi_devclass; 305 306DRIVER_MODULE(iodi, nexus, iodi_driver, iodi_devclass, 0, 0); 307