2003-08-24 18:03:45 +00:00
|
|
|
/*-
|
2000-01-24 07:24:02 +00:00
|
|
|
* Device driver for Specialix range (SI/XIO) of serial line multiplexors.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000, Peter Wemm <peter@netplex.com.au>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* notices, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notices, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY ``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 AUTHORS BE LIABLE.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 18:03:45 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-01-24 07:24:02 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2000-01-24 07:24:02 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
|
|
|
#include <dev/si/sireg.h>
|
|
|
|
#include <dev/si/sivar.h>
|
|
|
|
|
2005-11-08 04:11:50 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
2003-08-22 07:08:17 +00:00
|
|
|
#include <dev/pci/pcivar.h>
|
2000-01-24 07:24:02 +00:00
|
|
|
|
2000-01-24 08:11:10 +00:00
|
|
|
static int
|
2000-01-24 07:24:02 +00:00
|
|
|
si_pci_probe(device_t dev)
|
|
|
|
{
|
2000-01-24 08:11:10 +00:00
|
|
|
const char *desc = NULL;
|
|
|
|
|
2000-01-24 07:24:02 +00:00
|
|
|
switch (pci_get_devid(dev)) {
|
|
|
|
case 0x400011cb:
|
2000-01-24 08:11:10 +00:00
|
|
|
desc = "Specialix SI/XIO PCI host card";
|
2000-01-24 07:24:02 +00:00
|
|
|
break;
|
|
|
|
case 0x200011cb:
|
|
|
|
if (pci_read_config(dev, SIJETSSIDREG, 4) == 0x020011cb)
|
2000-01-24 08:11:10 +00:00
|
|
|
desc = "Specialix SX PCI host card";
|
2000-01-24 07:24:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-01-24 08:11:10 +00:00
|
|
|
if (desc) {
|
|
|
|
device_set_desc(dev, desc);
|
2005-03-01 08:58:06 +00:00
|
|
|
return BUS_PROBE_DEFAULT;
|
2000-01-24 08:11:10 +00:00
|
|
|
}
|
|
|
|
return ENXIO;
|
2000-01-24 07:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
si_pci_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct si_softc *sc;
|
|
|
|
void *ih;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
ih = NULL;
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
switch (pci_get_devid(dev)) {
|
|
|
|
case 0x400011cb:
|
|
|
|
sc->sc_type = SIPCI;
|
|
|
|
sc->sc_mem_rid = SIPCIBADR;
|
|
|
|
break;
|
|
|
|
case 0x200011cb:
|
|
|
|
sc->sc_type = SIJETPCI;
|
|
|
|
sc->sc_mem_rid = SIJETBADR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
|
|
|
&sc->sc_mem_rid,
|
|
|
|
RF_ACTIVE);
|
2000-01-24 07:24:02 +00:00
|
|
|
if (!sc->sc_mem_res) {
|
|
|
|
device_printf(dev, "couldn't map memory\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_mem_res);
|
|
|
|
sc->sc_maddr = rman_get_virtual(sc->sc_mem_res);
|
|
|
|
|
|
|
|
sc->sc_irq_rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
|
|
|
|
&sc->sc_irq_rid,
|
|
|
|
RF_ACTIVE | RF_SHAREABLE);
|
2000-01-24 07:24:02 +00:00
|
|
|
if (!sc->sc_irq_res) {
|
|
|
|
device_printf(dev, "couldn't map interrupt\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
sc->sc_irq = rman_get_start(sc->sc_irq_res);
|
|
|
|
error = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_TTY,
|
2007-02-23 19:34:52 +00:00
|
|
|
NULL, si_intr, sc, &ih);
|
2000-01-24 07:24:02 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "could not activate interrupt\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2007-12-01 20:39:47 +00:00
|
|
|
if (pci_get_devid(dev) == 0x200011cb) {
|
|
|
|
int rid;
|
|
|
|
struct resource *plx_res;
|
|
|
|
uint32_t *addr;
|
|
|
|
uint32_t oldvalue;
|
|
|
|
|
|
|
|
/* Perform a PLX control register fixup */
|
|
|
|
rid = PCIR_BAR(0);
|
|
|
|
plx_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
|
|
|
|
RF_ACTIVE);
|
|
|
|
if (plx_res == NULL) {
|
|
|
|
device_printf(dev, "couldn't map plx registers\n");
|
|
|
|
} else {
|
|
|
|
addr = rman_get_virtual(plx_res);
|
|
|
|
oldvalue = addr[0x50 / 4];
|
|
|
|
if (oldvalue != 0x18260000) {
|
|
|
|
device_printf(dev, "PLX register 0x50: 0x%08x changed to 0x%08x\n", oldvalue, 0x18260000);
|
|
|
|
addr[0x50 / 4] = 0x18260000;
|
|
|
|
}
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, rid, plx_res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-24 07:24:02 +00:00
|
|
|
error = siattach(dev);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
|
|
|
return (0); /* success */
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (error == 0)
|
|
|
|
error = ENXIO;
|
|
|
|
if (sc->sc_irq_res) {
|
|
|
|
if (ih)
|
|
|
|
bus_teardown_intr(dev, sc->sc_irq_res, ih);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ,
|
|
|
|
sc->sc_irq_rid, sc->sc_irq_res);
|
|
|
|
sc->sc_irq_res = 0;
|
|
|
|
}
|
|
|
|
if (sc->sc_mem_res) {
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
sc->sc_mem_rid, sc->sc_mem_res);
|
|
|
|
sc->sc_mem_res = 0;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t si_pci_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, si_pci_probe),
|
|
|
|
DEVMETHOD(device_attach, si_pci_attach),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t si_pci_driver = {
|
|
|
|
"si",
|
|
|
|
si_pci_methods,
|
|
|
|
sizeof(struct si_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(si, pci, si_pci_driver, si_devclass, 0, 0);
|