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 $
21 * $DragonFly: src/sys/dev/serial/si/si_isa.c,v 1.4 2005/05/24 20:59:04 dillon Exp $
24 #include "opt_debug_si.h"
26 #include <sys/param.h>
27 #include <sys/systm.h>
28 #include <sys/kernel.h>
30 #include <machine/bus.h>
32 #include <machine/resource.h>
37 #include <bus/isa/isavar.h>
39 /* Look for a valid board at the given mem addr */
41 si_isa_probe(device_t dev)
46 volatile unsigned char was, *ux;
47 volatile unsigned char *maddr;
51 sc = device_get_softc(dev);
52 unit = device_get_unit(dev);
55 sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
57 0, ~0, SIPROBEALLOC, RF_ACTIVE);
60 paddr = (caddr_t)rman_get_start(sc->sc_mem_res);/* physical */
61 maddr = rman_get_virtual(sc->sc_mem_res); /* in kvm */
63 DPRINT((0, DBG_AUTOBOOT, "si%d: probe at virtual=0x%x physical=0x%x\n",
67 * this is a lie, but it's easier than trying to handle caching
68 * and ram conflicts in the >1M and <16M region.
70 if ((caddr_t)paddr < (caddr_t)0xA0000 ||
71 (caddr_t)paddr >= (caddr_t)0x100000) {
72 printf("si%d: iomem (%p) out of range\n",
77 if (((u_int)paddr & 0x7fff) != 0) {
78 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
79 "si%d: iomem (%x) not on 32k boundary\n", unit, paddr));
83 /* Is there anything out there? (0x17 is just an arbitrary number) */
86 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
87 "si%d: 0x17 check fail at phys 0x%x\n", unit, paddr));
91 * Let's look first for a JET ISA card, since that's pretty easy
93 * All jet hosts are supposed to have this string in the IDROM,
94 * but it's not worth checking on self-IDing busses like PCI.
97 unsigned char *jet_chk_str = "JET HOST BY KEV#";
99 for (i = 0; i < strlen(jet_chk_str); i++)
100 if (jet_chk_str[i] != *(maddr + SIJETIDSTR + 2 * i))
103 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET first check - 0x%x\n",
104 unit, (*(maddr+SIJETIDBASE))));
105 if (*(maddr+SIJETIDBASE) != (SISPLXID&0xff))
107 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET second check - 0x%x\n",
108 unit, (*(maddr+SIJETIDBASE+2))));
109 if (*(maddr+SIJETIDBASE+2) != ((SISPLXID&0xff00)>>8))
111 /* It must be a Jet ISA or RIO card */
112 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL, "si%d: JET id check - 0x%x\n",
113 unit, (*(maddr+SIUNIQID))));
114 if ((*(maddr+SIUNIQID) & 0xf0) != 0x20)
116 /* It must be a Jet ISA SI/XIO card */
117 *(maddr + SIJETCONFIG) = 0;
119 ramsize = SIJET_RAMSIZE;
124 * OK, now to see if whatever responded is really an SI card.
125 * Try for a MK II next (SIHOST2)
127 for (i = SIPLSIG; i < SIPLSIG + 8; i++)
128 if ((*(maddr+i) & 7) != (~(unsigned char)i & 7))
131 /* It must be an SIHOST2 */
132 *(maddr + SIPLRESET) = 0;
133 *(maddr + SIPLIRQCLR) = 0;
134 *(maddr + SIPLIRQSET) = 0x10;
136 ramsize = SIHOST2_RAMSIZE;
141 * Its not a MK II, so try for a MK I (SIHOST)
143 *(maddr+SIRESET) = 0x0; /* reset the card */
144 *(maddr+SIINTCL) = 0x0; /* clear int */
145 *(maddr+SIRAM) = 0x17;
146 if (*(maddr+SIRAM) != (unsigned char)0x17)
148 *(maddr+0x7ff8) = 0x17;
149 if (*(maddr+0x7ff8) != (unsigned char)0x17) {
150 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
151 "si%d: 0x17 check fail at phys 0x%x = 0x%x\n",
152 unit, paddr+0x77f8, *(maddr+0x77f8)));
156 /* It must be an SIHOST (maybe?) - there must be a better way XXX */
158 ramsize = SIHOST_RAMSIZE;
161 DPRINT((0, DBG_AUTOBOOT, "si%d: found type %d card, try memory test\n",
163 /* Try the acid test */
165 for (i = 0; i < ramsize; i++, ux++)
166 *ux = (unsigned char)(i&0xff);
168 for (i = 0; i < ramsize; i++, ux++) {
169 if ((was = *ux) != (unsigned char)(i&0xff)) {
170 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
171 "si%d: match fail at phys 0x%x, was %x should be %x\n",
172 unit, paddr + i, was, i&0xff));
177 /* clear out the RAM */
179 for (i = 0; i < ramsize; i++)
182 for (i = 0; i < ramsize; i++) {
183 if ((was = *ux++) != 0) {
184 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
185 "si%d: clear fail at phys 0x%x, was %x\n",
186 unit, paddr + i, was));
192 * Success, we've found a valid board, now fill in
193 * the adapter structure.
197 switch (isa_get_irq(dev)) {
204 DPRINT((0, DBG_AUTOBOOT|DBG_FAIL,
205 "si%d: bad IRQ value - %d\n",
206 unit, isa_get_irq(dev)));
209 sc->sc_memsize = SIHOST2_MEMSIZE;
212 switch (isa_get_irq(dev)) {
220 sc->sc_memsize = SIHOST_MEMSIZE;
223 switch (isa_get_irq(dev)) {
233 sc->sc_memsize = SIJETISA_MEMSIZE;
235 case SIMCA: /* MCA */
237 printf("si%d: card type %d not supported\n", unit, type);
241 bus_release_resource(dev, SYS_RES_MEMORY,
242 sc->sc_mem_rid, sc->sc_mem_res);
244 return (0); /* success! */
247 if (sc->sc_mem_res) {
248 bus_release_resource(dev, SYS_RES_MEMORY,
249 sc->sc_mem_rid, sc->sc_mem_res);
256 si_isa_attach(device_t dev)
264 sc = device_get_softc(dev);
267 sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
269 0, ~0, 1, RF_ACTIVE);
270 if (!sc->sc_mem_res) {
271 device_printf(dev, "couldn't map memory\n");
274 sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_mem_res);
275 sc->sc_maddr = rman_get_virtual(sc->sc_mem_res);
278 sc->sc_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irq_rid,
279 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
280 if (!sc->sc_irq_res) {
281 device_printf(dev, "couldn't allocate interrupt\n");
284 sc->sc_irq = rman_get_start(sc->sc_irq_res);
285 error = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_TTY,
289 device_printf(dev, "couldn't activate interrupt\n");
293 error = siattach(dev);
296 return (0); /* success */
301 if (sc->sc_irq_res) {
303 bus_teardown_intr(dev, sc->sc_irq_res, ih);
304 bus_release_resource(dev, SYS_RES_IRQ,
305 sc->sc_irq_rid, sc->sc_irq_res);
308 if (sc->sc_mem_res) {
309 bus_release_resource(dev, SYS_RES_MEMORY,
310 sc->sc_mem_rid, sc->sc_mem_res);
316 static device_method_t si_isa_methods[] = {
317 /* Device interface */
318 DEVMETHOD(device_probe, si_isa_probe),
319 DEVMETHOD(device_attach, si_isa_attach),
324 static driver_t si_isa_driver = {
327 sizeof(struct si_softc),
330 DRIVER_MODULE(si, isa, si_isa_driver, si_devclass, 0, 0);