2009-10-15 21:14:42 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003-2009 RMI Corporation
|
|
|
|
* 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.
|
|
|
|
* 3. Neither the name of RMI Corporation, nor the names of its contributors,
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2010-01-11 04:49:44 +00:00
|
|
|
* RMI_BSD
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2009-10-15 21:14:42 +00:00
|
|
|
|
|
|
|
#define __RMAN_RESOURCE_VISIBLE
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/reboot.h>
|
2010-08-30 13:05:21 +00:00
|
|
|
#include <sys/rman.h>
|
2009-10-15 21:14:42 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/interrupt.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus.h>
|
2009-10-29 15:55:25 +00:00
|
|
|
#include <machine/param.h>
|
|
|
|
#include <machine/intr_machdep.h>
|
|
|
|
#include <machine/clock.h> /* for DELAY */
|
|
|
|
#include <machine/resource.h>
|
2010-08-30 13:05:21 +00:00
|
|
|
|
|
|
|
#include <mips/rmi/board.h>
|
|
|
|
#include <mips/rmi/pic.h>
|
2009-10-29 15:55:25 +00:00
|
|
|
#include <mips/rmi/interrupt.h>
|
|
|
|
#include <mips/rmi/msgring.h>
|
|
|
|
#include <mips/rmi/iomap.h>
|
2010-08-30 13:05:21 +00:00
|
|
|
#include <mips/rmi/rmi_mips_exts.h>
|
2009-10-29 15:55:25 +00:00
|
|
|
|
2010-01-11 04:49:44 +00:00
|
|
|
#include <mips/rmi/dev/xlr/atx_cpld.h>
|
|
|
|
#include <mips/rmi/dev/xlr/xgmac_mdio.h>
|
2009-10-29 15:55:25 +00:00
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
extern bus_space_tag_t uart_bus_space_mem;
|
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
static struct resource *
|
|
|
|
iodi_alloc_resource(device_t, device_t, int, int *,
|
|
|
|
u_long, u_long, u_long, u_int);
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2009-11-09 16:43:02 +00:00
|
|
|
static int
|
2009-10-29 21:14:10 +00:00
|
|
|
iodi_activate_resource(device_t, device_t, int, int,
|
|
|
|
struct resource *);
|
2009-11-09 16:43:02 +00:00
|
|
|
static int
|
2009-10-29 21:14:10 +00:00
|
|
|
iodi_setup_intr(device_t, device_t, struct resource *, int,
|
|
|
|
driver_filter_t *, driver_intr_t *, void *, void **);
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
struct iodi_softc *iodi_softc; /* There can be only one. */
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-08-28 07:58:10 +00:00
|
|
|
/*
|
|
|
|
* We will manage the Flash/PCMCIA devices in IODI for now.
|
|
|
|
* The NOR flash, Compact flash etc. which can be connected on
|
|
|
|
* various chip selects on the peripheral IO, should have a
|
|
|
|
* separate bus later.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
bridge_pcmcia_ack(int irq)
|
|
|
|
{
|
|
|
|
xlr_reg_t *mmio = xlr_io_mmio(XLR_IO_FLASH_OFFSET);
|
|
|
|
|
|
|
|
xlr_write_reg(mmio, 0x60, 0xffffffff);
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
static int
|
|
|
|
iodi_setup_intr(device_t dev, device_t child,
|
2010-09-01 17:35:31 +00:00
|
|
|
struct resource *ires, int flags, driver_filter_t *filt,
|
2010-08-25 11:49:48 +00:00
|
|
|
driver_intr_t *intr, void *arg, void **cookiep)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
2010-08-28 19:02:51 +00:00
|
|
|
const char *name = device_get_name(child);
|
2009-10-29 21:14:10 +00:00
|
|
|
|
2010-08-28 19:02:51 +00:00
|
|
|
if (strcmp(name, "uart") == 0) {
|
2009-10-29 21:14:10 +00:00
|
|
|
/* FIXME uart 1? */
|
2010-08-25 11:49:48 +00:00
|
|
|
cpu_establish_hardintr("uart", filt, intr, arg,
|
|
|
|
PIC_UART_0_IRQ, flags, cookiep);
|
2010-09-06 06:18:49 +00:00
|
|
|
pic_setup_intr(PIC_IRT_UART_0_INDEX, PIC_UART_0_IRQ, 0x1, 1);
|
2010-08-28 19:02:51 +00:00
|
|
|
} else if (strcmp(name, "rge") == 0 || strcmp(name, "nlge") == 0) {
|
2009-10-29 21:14:10 +00:00
|
|
|
int irq;
|
2009-11-09 16:43:02 +00:00
|
|
|
|
2009-11-09 16:42:08 +00:00
|
|
|
/* This is a hack to pass in the irq */
|
2010-07-08 15:05:23 +00:00
|
|
|
irq = (intptr_t)ires->__r_i;
|
2010-08-25 11:49:48 +00:00
|
|
|
cpu_establish_hardintr("rge", filt, intr, arg, irq, flags,
|
|
|
|
cookiep);
|
2010-09-06 06:18:49 +00:00
|
|
|
pic_setup_intr(irq - PIC_IRQ_BASE, irq, 0x1, 1);
|
2010-08-28 19:02:51 +00:00
|
|
|
} else if (strcmp(name, "ehci") == 0) {
|
2010-08-25 11:49:48 +00:00
|
|
|
cpu_establish_hardintr("ehci", filt, intr, arg, PIC_USB_IRQ, flags,
|
|
|
|
cookiep);
|
2010-09-06 06:18:49 +00:00
|
|
|
pic_setup_intr(PIC_USB_IRQ - PIC_IRQ_BASE, PIC_USB_IRQ, 0x1, 1);
|
2010-08-28 19:02:51 +00:00
|
|
|
} else if (strcmp(name, "ata") == 0) {
|
2010-08-28 07:58:10 +00:00
|
|
|
xlr_establish_intr("ata", filt, intr, arg, PIC_PCMCIA_IRQ, flags,
|
|
|
|
cookiep, bridge_pcmcia_ack);
|
2010-09-06 06:18:49 +00:00
|
|
|
pic_setup_intr(PIC_PCMCIA_IRQ - PIC_IRQ_BASE, PIC_PCMCIA_IRQ, 0x1, 1);
|
2009-10-29 21:14:10 +00:00
|
|
|
}
|
|
|
|
return (0);
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct resource *
|
|
|
|
iodi_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
2009-10-29 21:14:10 +00:00
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
|
|
|
struct resource *res = malloc(sizeof(*res), M_DEVBUF, M_WAITOK);
|
2010-09-01 17:35:31 +00:00
|
|
|
const char *name = device_get_name(child);
|
2009-10-15 21:14:42 +00:00
|
|
|
int unit;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
switch (type) {
|
|
|
|
case SYS_RES_IRQ:
|
|
|
|
device_printf(bus, "IRQ resource - for %s %lx-%lx\n",
|
2009-10-29 21:14:10 +00:00
|
|
|
device_get_nameunit(child), start, end);
|
|
|
|
break;
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
case SYS_RES_IOPORT:
|
2009-10-15 21:14:42 +00:00
|
|
|
device_printf(bus, "IOPORT resource - for %s %lx-%lx\n",
|
2009-10-29 21:14:10 +00:00
|
|
|
device_get_nameunit(child), start, end);
|
|
|
|
break;
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
case SYS_RES_MEMORY:
|
2009-10-15 21:14:42 +00:00
|
|
|
device_printf(bus, "MEMORY resource - for %s %lx-%lx\n",
|
2009-10-29 21:14:10 +00:00
|
|
|
device_get_nameunit(child), start, end);
|
|
|
|
break;
|
|
|
|
}
|
2009-10-15 21:14:42 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-01 17:35:31 +00:00
|
|
|
if (strcmp(name, "uart") == 0) {
|
2009-10-29 21:14:10 +00:00
|
|
|
if ((unit = device_get_unit(child)) == 0) { /* uart 0 */
|
2009-10-15 21:14:42 +00:00
|
|
|
res->r_bushandle = (xlr_io_base + XLR_IO_UART_0_OFFSET);
|
2009-10-29 21:14:10 +00:00
|
|
|
} else if (unit == 1) {
|
2009-10-15 21:14:42 +00:00
|
|
|
res->r_bushandle = (xlr_io_base + XLR_IO_UART_1_OFFSET);
|
2009-10-29 21:14:10 +00:00
|
|
|
} else
|
2009-10-15 21:14:42 +00:00
|
|
|
printf("%s: Unknown uart unit\n", __FUNCTION__);
|
|
|
|
|
|
|
|
res->r_bustag = uart_bus_space_mem;
|
2010-09-01 17:35:31 +00:00
|
|
|
} else if (strcmp(name, "ehci") == 0) {
|
2010-07-08 15:05:23 +00:00
|
|
|
res->r_bushandle = MIPS_PHYS_TO_KSEG1(0x1ef24000);
|
2010-03-02 12:11:00 +00:00
|
|
|
res->r_bustag = rmi_pci_bus_space;
|
2010-09-01 17:35:31 +00:00
|
|
|
} else if (strcmp(name, "cfi") == 0) {
|
2010-07-08 15:05:23 +00:00
|
|
|
res->r_bushandle = MIPS_PHYS_TO_KSEG1(0x1c000000);
|
2009-10-15 21:14:42 +00:00
|
|
|
res->r_bustag = 0;
|
2010-09-01 17:35:31 +00:00
|
|
|
} else if (strcmp(name, "ata") == 0) {
|
2010-08-28 07:58:10 +00:00
|
|
|
res->r_bushandle = MIPS_PHYS_TO_KSEG1(0x1d000000);
|
|
|
|
res->r_bustag = rmi_pci_bus_space; /* byte swapping (not really PCI) */
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
2009-10-29 21:14:10 +00:00
|
|
|
/* res->r_start = *rid; */
|
2009-10-15 21:14:42 +00:00
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
iodi_activate_resource(device_t bus, device_t child, int type, int rid,
|
2009-10-29 21:14:10 +00:00
|
|
|
struct resource *r)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
2009-10-29 21:14:10 +00:00
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
/* prototypes */
|
2009-10-29 21:14:10 +00:00
|
|
|
static int iodi_probe(device_t);
|
|
|
|
static int iodi_attach(device_t);
|
2010-08-28 19:02:51 +00:00
|
|
|
static int iodi_detach(device_t);
|
2009-10-29 21:14:10 +00:00
|
|
|
static void iodi_identify(driver_t *, device_t);
|
2009-10-15 21:14:42 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
iodi_probe(device_t dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-29 21:14:10 +00:00
|
|
|
iodi_identify(driver_t * driver, device_t parent)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
2009-10-29 21:14:10 +00:00
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
BUS_ADD_CHILD(parent, 0, "iodi", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
iodi_attach(device_t dev)
|
|
|
|
{
|
|
|
|
device_t tmpd;
|
2010-08-28 19:02:51 +00:00
|
|
|
int i;
|
2009-10-29 21:14:10 +00:00
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
/*
|
2009-10-29 21:14:10 +00:00
|
|
|
* Attach each devices
|
2009-10-15 21:14:42 +00:00
|
|
|
*/
|
|
|
|
device_add_child(dev, "uart", 0);
|
|
|
|
device_add_child(dev, "xlr_i2c", 0);
|
2010-12-12 06:00:26 +00:00
|
|
|
device_add_child(dev, "xlr_i2c", 1);
|
2010-05-16 19:43:48 +00:00
|
|
|
device_add_child(dev, "pcib", 0);
|
2010-09-16 20:23:22 +00:00
|
|
|
device_add_child(dev, "rmisec", -1);
|
2009-10-29 21:14:10 +00:00
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
if (xlr_board_info.usb)
|
|
|
|
device_add_child(dev, "ehci", 0);
|
2009-10-29 21:14:10 +00:00
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
if (xlr_board_info.cfi)
|
|
|
|
device_add_child(dev, "cfi", 0);
|
|
|
|
|
2010-08-28 07:58:10 +00:00
|
|
|
if (xlr_board_info.ata)
|
|
|
|
device_add_child(dev, "ata", 0);
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
if (xlr_board_info.gmac_block[0].enabled) {
|
|
|
|
tmpd = device_add_child(dev, "rge", 0);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]);
|
|
|
|
|
|
|
|
tmpd = device_add_child(dev, "rge", 1);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]);
|
|
|
|
|
|
|
|
tmpd = device_add_child(dev, "rge", 2);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]);
|
|
|
|
|
|
|
|
tmpd = device_add_child(dev, "rge", 3);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[0]);
|
|
|
|
}
|
|
|
|
if (xlr_board_info.gmac_block[1].enabled) {
|
|
|
|
if (xlr_board_info.gmac_block[1].type == XLR_GMAC) {
|
|
|
|
tmpd = device_add_child(dev, "rge", 4);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]);
|
|
|
|
|
|
|
|
tmpd = device_add_child(dev, "rge", 5);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]);
|
|
|
|
|
2010-02-20 17:24:33 +00:00
|
|
|
if (xlr_board_info.gmac_block[1].enabled & 0x4) {
|
|
|
|
tmpd = device_add_child(dev, "rge", 6);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xlr_board_info.gmac_block[1].enabled & 0x8) {
|
|
|
|
tmpd = device_add_child(dev, "rge", 7);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]);
|
|
|
|
}
|
2009-10-15 21:14:42 +00:00
|
|
|
} else if (xlr_board_info.gmac_block[1].type == XLR_XGMAC) {
|
2009-10-29 21:14:10 +00:00
|
|
|
#if 0 /* XGMAC not yet */
|
2009-10-15 21:14:42 +00:00
|
|
|
tmpd = device_add_child(dev, "rge", 4);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]);
|
|
|
|
|
|
|
|
tmpd = device_add_child(dev, "rge", 5);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[1]);
|
|
|
|
#endif
|
2010-08-28 19:02:51 +00:00
|
|
|
} else
|
|
|
|
device_printf(dev, "Unknown type of gmac 1\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is to add the new GMAC driver. The above adds the old driver,
|
|
|
|
which has been retained for now as the new driver is stabilized.
|
|
|
|
The new driver is enabled with "option nlge". Make sure that only
|
|
|
|
one of rge or nlge is enabled in the conf file. */
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
if (xlr_board_info.gmac_block[i].enabled == 0)
|
|
|
|
continue;
|
|
|
|
tmpd = device_add_child(dev, "nlna", i);
|
|
|
|
device_set_ivars(tmpd, &xlr_board_info.gmac_block[i]);
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
|
|
|
bus_generic_probe(dev);
|
|
|
|
bus_generic_attach(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-28 19:02:51 +00:00
|
|
|
int
|
|
|
|
iodi_detach(device_t dev)
|
|
|
|
{
|
|
|
|
device_t nlna_dev;
|
|
|
|
int error, i, ret;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
ret = 0;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
nlna_dev = device_find_child(dev, "nlna", i);
|
|
|
|
if (nlna_dev != NULL)
|
|
|
|
error = bus_generic_detach(nlna_dev);
|
|
|
|
if (error)
|
|
|
|
ret = error;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
static device_method_t iodi_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, iodi_probe),
|
|
|
|
DEVMETHOD(device_attach, iodi_attach),
|
2010-08-28 19:02:51 +00:00
|
|
|
DEVMETHOD(device_detach, iodi_detach),
|
2009-10-15 21:14:42 +00:00
|
|
|
DEVMETHOD(device_identify, iodi_identify),
|
|
|
|
DEVMETHOD(bus_alloc_resource, iodi_alloc_resource),
|
|
|
|
DEVMETHOD(bus_activate_resource, iodi_activate_resource),
|
2010-09-13 11:47:35 +00:00
|
|
|
DEVMETHOD(bus_add_child, bus_generic_add_child),
|
2009-10-15 21:14:42 +00:00
|
|
|
DEVMETHOD(bus_setup_intr, iodi_setup_intr),
|
|
|
|
{0, 0},
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t iodi_driver = {
|
|
|
|
"iodi",
|
|
|
|
iodi_methods,
|
2009-10-29 21:14:10 +00:00
|
|
|
1 /* no softc */
|
2009-10-15 21:14:42 +00:00
|
|
|
};
|
|
|
|
static devclass_t iodi_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(iodi, nexus, iodi_driver, iodi_devclass, 0, 0);
|