2 * Device driver for Specialix range (SI/XIO) of serial line multiplexors.
4 * Copyright (C) 2000, Peter Wemm <peter@netplex.com.au>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notices, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notices, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18 * NO EVENT SHALL THE AUTHORS BE LIABLE.
20 * $FreeBSD: src/sys/dev/si/si_isa.c,v 1.1 2000/01/24 07:24:01 peter Exp $
23 #include "opt_debug_si.h"
25 #include <sys/param.h>
26 #include <sys/systm.h>
27 #include <sys/kernel.h>
29 #include <machine/bus.h>
31 #include <machine/resource.h>
33 #include <dev/si/sireg.h>
34 #include <dev/si/sivar.h>
36 #include <isa/isavar.h>
38 /* Look for a valid board at the given mem addr */
40 si_isa_probe(device_t dev)
45 volatile unsigned char was, *ux;
46 volatile unsigned char *maddr;
50 sc = device_get_softc(dev);
51 unit = device_get_unit(dev);
54 sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
56 0, ~0, SIPROBEALLOC, RF_ACTIVE);
59 paddr = (caddr_t)rman_get_start(sc->sc_mem_res);/* physical */
60 maddr = rman_get_virtual(sc->sc_mem_res); /* in kvm */
62 DPRINT((0, DBG_AUTOBOOT, "si%d: probe at virtual=0x%x physical=0x%x\n",
66 * this is a lie, but it's easier than trying to handle caching
67 * and ram conflicts in the >1M and <16M region.
69 if ((caddr_t)paddr < (caddr_t)0xA0000 ||
70 (caddr_t)paddr >= (caddr_t)0x100000) {
71 printf("si%d: iomem (%p) out of range\n",
76 if (((u_int)paddr & 0x7fff) != 0) {
77 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
78 "si%d: iomem (%x) not on 32k boundary\n", unit, paddr));
82 /* Is there anything out there? (0x17 is just an arbitrary number) */
85 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
86 "si%d: 0x17 check fail at phys 0x%x\n", unit, paddr));
90 * Let's look first for a JET ISA card, since that's pretty easy
92 * All jet hosts are supposed to have this string in the IDROM,
93 * but it's not worth checking on self-IDing busses like PCI.
96 unsigned char *jet_chk_str = "JET HOST BY KEV#";
98 for (i = 0; i < strlen(jet_chk_str); i++)
99 if (jet_chk_str[i] != *(maddr + SIJETIDSTR + 2 * i))
102 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET first check - 0x%x\n",
103 unit, (*(maddr+SIJETIDBASE))));
104 if (*(maddr+SIJETIDBASE) != (SISPLXID&0xff))
106 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET second check - 0x%x\n",
107 unit, (*(maddr+SIJETIDBASE+2))));
108 if (*(maddr+SIJETIDBASE+2) != ((SISPLXID&0xff00)>>8))
110 /* It must be a Jet ISA or RIO card */
111 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET id check - 0x%x\n",
112 unit, (*(maddr+SIUNIQID))));
113 if ((*(maddr+SIUNIQID) & 0xf0) != 0x20)
115 /* It must be a Jet ISA SI/XIO card */
116 *(maddr + SIJETCONFIG) = 0;
118 ramsize = SIJET_RAMSIZE;
123 * OK, now to see if whatever responded is really an SI card.
124 * Try for a MK II next (SIHOST2)
126 for (i = SIPLSIG; i < SIPLSIG + 8; i++)
127 if ((*(maddr+i) & 7) != (~(unsigned char)i & 7))
130 /* It must be an SIHOST2 */
131 *(maddr + SIPLRESET) = 0;
132 *(maddr + SIPLIRQCLR) = 0;
133 *(maddr + SIPLIRQSET) = 0x10;
135 ramsize = SIHOST2_RAMSIZE;
140 * Its not a MK II, so try for a MK I (SIHOST)
142 *(maddr+SIRESET) = 0x0; /* reset the card */
143 *(maddr+SIINTCL) = 0x0; /* clear int */
144 *(maddr+SIRAM) = 0x17;
145 if (*(maddr+SIRAM) != (unsigned char)0x17)
147 *(maddr+0x7ff8) = 0x17;
148 if (*(maddr+0x7ff8) != (unsigned char)0x17) {
149 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
150 "si%d: 0x17 check fail at phys 0x%x = 0x%x\n",
151 unit, paddr+0x77f8, *(maddr+0x77f8)));
155 /* It must be an SIHOST (maybe?) - there must be a better way XXX */
157 ramsize = SIHOST_RAMSIZE;
160 DPRINT((0, DBG_AUTOBOOT, "si%d: found type %d card, try memory test\n",
162 /* Try the acid test */
164 for (i = 0; i < ramsize; i++, ux++)
165 *ux = (unsigned char)(i&0xff);
167 for (i = 0; i < ramsize; i++, ux++) {
168 if ((was = *ux) != (unsigned char)(i&0xff)) {
169 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
170 "si%d: match fail at phys 0x%x, was %x should be %x\n",
171 unit, paddr + i, was, i&0xff));
176 /* clear out the RAM */
178 for (i = 0; i < ramsize; i++)
181 for (i = 0; i < ramsize; i++) {
182 if ((was = *ux++) != 0) {
183 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
184 "si%d: clear fail at phys 0x%x, was %x\n",
185 unit, paddr + i, was));
191 * Success, we've found a valid board, now fill in
192 * the adapter structure.
196 switch (isa_get_irq(dev)) {
203 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
204 "si%d: bad IRQ value - %d\n",
205 unit, isa_get_irq(dev)));
208 sc->sc_memsize = SIHOST2_MEMSIZE;
211 switch (isa_get_irq(dev)) {
219 sc->sc_memsize = SIHOST_MEMSIZE;
222 switch (isa_get_irq(dev)) {
232 sc->sc_memsize = SIJETISA_MEMSIZE;
234 case SIMCA: /* MCA */
236 printf("si%d: card type %d not supported\n", unit, type);
240 bus_release_resource(dev, SYS_RES_MEMORY,
241 sc->sc_mem_rid, sc->sc_mem_res);
243 return (0); /* success! */
246 if (sc->sc_mem_res) {
247 bus_release_resource(dev, SYS_RES_MEMORY,
248 sc->sc_mem_rid, sc->sc_mem_res);
255 si_isa_attach(device_t dev)
263 sc = device_get_softc(dev);
266 sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
268 0, ~0, 1, RF_ACTIVE);
269 if (!sc->sc_mem_res) {
270 device_printf(dev, "couldn't map memory\n");
273 sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_mem_res);
274 sc->sc_maddr = rman_get_virtual(sc->sc_mem_res);
277 sc->sc_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irq_rid,
278 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
279 if (!sc->sc_irq_res) {
280 device_printf(dev, "couldn't allocate interrupt\n");
283 sc->sc_irq = rman_get_start(sc->sc_irq_res);
284 error = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_TTY,
287 device_printf(dev, "couldn't activate interrupt\n");
291 error = siattach(dev);
294 return (0); /* success */
299 if (sc->sc_irq_res) {
301 bus_teardown_intr(dev, sc->sc_irq_res, ih);
302 bus_release_resource(dev, SYS_RES_IRQ,
303 sc->sc_irq_rid, sc->sc_irq_res);
306 if (sc->sc_mem_res) {
307 bus_release_resource(dev, SYS_RES_MEMORY,
308 sc->sc_mem_rid, sc->sc_mem_res);
314 static device_method_t si_isa_methods[] = {
315 /* Device interface */
316 DEVMETHOD(device_probe, si_isa_probe),
317 DEVMETHOD(device_attach, si_isa_attach),
322 static driver_t si_isa_driver = {
325 sizeof(struct si_softc),
328 DRIVER_MODULE(si, isa, si_isa_driver, si_devclass, 0, 0);