2 * Copyright (c) 1998, 1999 Martin Husemann <martin@rumolt.teuto.de>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. The name of the author may not be used to endorse or promote products
11 * derived from this software without specific prior written permission
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *---------------------------------------------------------------------------
26 * i4b_itk_ix1.c - ITK ix1 micro passive card driver for isdn4bsd
27 * --------------------------------------------------------------
29 * last edit-date: [Wed Jan 24 09:27:06 2001]
31 * $FreeBSD: src/sys/i4b/layer1/isic/i4b_itk_ix1.c,v 1.5.2.1 2001/08/10 14:08:38 obrien Exp $
33 *---------------------------------------------------------------------------
35 * The ITK ix1 micro ISDN card is an ISA card with one region
36 * of four io ports mapped and a fixed irq all jumpered on the card.
37 * Access to the board is straight forward and simmilar to
38 * the ELSA and DYNALINK cards. If a PCI version of this card
39 * exists all we need is probably a pci-bus attachment, all
40 * this low level routines should work imediately.
43 * - write 0x01 to ITK_CONFIG
45 * - write 0x00 to ITK_CONFIG
47 * To read or write data:
48 * - write address to ITK_ALE port
49 * - read data from or write data to ITK_ISAC_DATA port or ITK_HSCX_DATA port
50 * The two HSCX channel registers are offset by HSCXA (0x00) and HSCXB (0x40).
52 * The probe routine was derived by trial and error from a representative
53 * sample of two cards ;-) The standard way (checking HSCX versions)
54 * was extended by reading a zero from a non existant HSCX register (register
55 * 0xff). Reading the config register gives varying results, so this doesn't
56 * seem to be used as an id register (like the Teles S0/16.3).
58 * If the probe fails for your card use "options ITK_PROBE_DEBUG" to get
59 * additional debug output.
61 *---------------------------------------------------------------------------*/
66 #if NISIC > 0 && defined(ITKIX1)
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/socket.h>
73 #include <net/i4b/include/machine/i4b_ioctl.h>
74 #include <net/i4b/include/machine/i4b_trace.h>
75 #include "../i4b_l1.h"
79 /* Register offsets */
80 #define ITK_ISAC_DATA 0
81 #define ITK_HSCX_DATA 1
85 /* Size of IO range to allocate for this card */
88 /* Register offsets for the two HSCX channels */
93 itkix1_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
95 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
96 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
100 bus_space_write_1(t, h, ITK_ALE, 0);
101 bus_space_read_multi_1(t, h, ITK_ISAC_DATA, buf, size);
103 case ISIC_WHAT_HSCXA:
104 bus_space_write_1(t, h, ITK_ALE, HSCXA);
105 bus_space_read_multi_1(t, h, ITK_HSCX_DATA, buf, size);
107 case ISIC_WHAT_HSCXB:
108 bus_space_write_1(t, h, ITK_ALE, HSCXB);
109 bus_space_read_multi_1(t, h, ITK_HSCX_DATA, buf, size);
115 itkix1_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
117 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
118 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
122 bus_space_write_1(t, h, ITK_ALE, 0);
123 bus_space_write_multi_1(t, h, ITK_ISAC_DATA, (u_int8_t*)buf, size);
125 case ISIC_WHAT_HSCXA:
126 bus_space_write_1(t, h, ITK_ALE, HSCXA);
127 bus_space_write_multi_1(t, h, ITK_HSCX_DATA, (u_int8_t*)buf, size);
129 case ISIC_WHAT_HSCXB:
130 bus_space_write_1(t, h, ITK_ALE, HSCXB);
131 bus_space_write_multi_1(t, h, ITK_HSCX_DATA, (u_int8_t*)buf, size);
137 itkix1_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
139 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
140 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
144 bus_space_write_1(t, h, ITK_ALE, offs);
145 bus_space_write_1(t, h, ITK_ISAC_DATA, data);
147 case ISIC_WHAT_HSCXA:
148 bus_space_write_1(t, h, ITK_ALE, HSCXA+offs);
149 bus_space_write_1(t, h, ITK_HSCX_DATA, data);
151 case ISIC_WHAT_HSCXB:
152 bus_space_write_1(t, h, ITK_ALE, HSCXB+offs);
153 bus_space_write_1(t, h, ITK_HSCX_DATA, data);
159 itkix1_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
161 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
162 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
166 bus_space_write_1(t, h, ITK_ALE, offs);
167 return bus_space_read_1(t, h, ITK_ISAC_DATA);
168 case ISIC_WHAT_HSCXA:
169 bus_space_write_1(t, h, ITK_ALE, HSCXA+offs);
170 return bus_space_read_1(t, h, ITK_HSCX_DATA);
171 case ISIC_WHAT_HSCXB:
172 bus_space_write_1(t, h, ITK_ALE, HSCXB+offs);
173 return bus_space_read_1(t, h, ITK_HSCX_DATA);
182 isic_probe_itkix1(device_t dev)
184 size_t unit = device_get_unit(dev); /* get unit */
185 struct l1_softc *sc = NULL; /* softc */
186 void *ih = NULL; /* dummy */
187 bus_space_tag_t t; /* bus things */
188 bus_space_handle_t h;
189 u_int8_t hd, hv1, hv2, saveale;
192 #if defined(ITK_PROBE_DEBUG)
193 kprintf("Checking unit %u\n", unit);
196 /* check max unit range */
197 if(unit >= ISIC_MAXUNIT)
199 kprintf("isic%d: Error, unit %d >= ISIC_MAXUNIT for ITK IX1!\n",
204 sc = &l1_sc[unit]; /* get pointer to softc */
205 sc->sc_unit = unit; /* set unit */
207 #if defined(ITK_PROBE_DEBUG)
208 kprintf("Allocating io base...");
211 if(!(sc->sc_resources.io_base[0] =
212 bus_alloc_resource(dev, SYS_RES_IOPORT,
213 &sc->sc_resources.io_rid[0],
214 0ul, ~0ul, 1, RF_ACTIVE)))
216 kprintf("isic%d: Could not allocate i/o port for ITK IX1.\n", unit);
220 #if defined(ITK_PROBE_DEBUG)
224 sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
225 t = rman_get_bustag(sc->sc_resources.io_base[0]);
226 h = rman_get_bushandle(sc->sc_resources.io_base[0]);
228 #if defined(ITK_PROBE_DEBUG)
229 kprintf("Allocating irq...");
233 if(!(sc->sc_resources.irq =
234 bus_alloc_resource(dev, SYS_RES_IRQ,
235 &sc->sc_resources.irq_rid,
236 0ul, ~0ul, 1, RF_ACTIVE)))
238 kprintf("isic%d: Could not allocate irq for ITK IX1.\n", unit);
239 bus_release_resource(dev,SYS_RES_IOPORT,
240 sc->sc_resources.io_rid[0],
241 sc->sc_resources.io_base[0]);
245 #if defined(ITK_PROBE_DEBUG)
249 /* get the irq number */
250 sc->sc_irq = rman_get_start(sc->sc_resources.irq);
252 #if defined(ITK_PROBE_DEBUG)
253 kprintf("Setting up access routines...");
256 /* setup access routines */
258 sc->readreg = itkix1_read_reg;
259 sc->writereg = itkix1_write_reg;
260 sc->readfifo = itkix1_read_fifo;
261 sc->writefifo = itkix1_write_fifo;
263 /* setup card type */
264 sc->sc_cardtyp = CARD_TYPEP_ITKIX1;
266 /* setup IOM bus type */
267 sc->sc_bustyp = BUS_TYPE_IOM2;
270 sc->sc_bfifolen = HSCX_FIFO_LEN;
272 #if defined(ITK_PROBE_DEBUG)
276 /* register interupt routine */
278 #if defined(ITK_PROBE_DEBUG)
279 kprintf("Setting up access interrupt...");
282 bus_setup_intr(dev, sc->sc_resources.irq,
283 0, (void(*)(void *))(isicintr),
286 #if defined(ITK_PROBE_DEBUG)
289 kprintf("Doing probe stuff...");
292 /* save old value of this port, we're stomping over it */
293 saveale = bus_space_read_1(t, h, ITK_ALE);
295 /* select invalid register */
296 bus_space_write_1(t, h, ITK_ALE, 0xff);
297 /* get HSCX data for this non existent register */
298 hd = bus_space_read_1(t, h, ITK_HSCX_DATA);
299 /* get HSCX version info */
300 bus_space_write_1(t, h, ITK_ALE, HSCXA + H_VSTR);
301 hv1 = bus_space_read_1(t, h, ITK_HSCX_DATA);
302 bus_space_write_1(t, h, ITK_ALE, HSCXB + H_VSTR);
303 hv2 = bus_space_read_1(t, h, ITK_HSCX_DATA);
305 ret = (hd == 0) && ((hv1 & 0x0f) == 0x05) && ((hv2 & 0x0f) == 0x05);
306 /* succeed if version bits are OK and we got a zero from the
307 * non existent register. we found verison 0x05 and 0x04
310 && (((hv1 & 0x0f) == 0x05) || ((hv1 & 0x0f) == 0x04))
311 && (((hv2 & 0x0f) == 0x05) || ((hv2 & 0x0f) == 0x04));
313 /* retstore save value if we fail (if we succeed the old value
316 bus_space_write_1(t, h, ITK_ALE, saveale);
318 #if defined(ITK_PROBE_DEBUG)
321 kprintf("Doing second probe stuff...");
324 hv1 = HSCX_READ(0, H_VSTR) & 0xf;
325 hv2 = HSCX_READ(1, H_VSTR) & 0xf;
326 /* Read HSCX A/B VSTR. Expected value is 0x05 (V2.1) or 0x04 (V2.0). */
327 if((hv1 != 0x05 && hv1 != 0x04) || (hv2 != 0x05 && hv2 != 0x04))
329 kprintf("isic%d: HSCX VSTR test failed for ITK ix1 micro\n",
331 kprintf("isic%d: HSC0: VSTR: %#x\n",
332 unit, HSCX_READ(0, H_VSTR));
333 kprintf("isic%d: HSC1: VSTR: %#x\n",
334 unit, HSCX_READ(1, H_VSTR));
335 isic_detach_common(dev);
339 #if defined(ITK_PROBE_DEBUG)
343 #if defined(ITK_PROBE_DEBUG)
344 kprintf("\nITK ix1 micro probe: hscx = 0x%02x, v1 = 0x%02x, v2 = 0x%02x, would have %s\n",
345 hd, hv1, hv2, ret ? "succeeded" : "failed");
346 isic_detach_common(dev);
355 isic_detach_common(dev);
365 isic_attach_itkix1(device_t dev)
367 size_t unit = device_get_unit(dev); /* get unit */
368 struct l1_softc *sc = &l1_sc[unit];
369 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
370 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
372 /* setup access routines */
374 sc->readreg = itkix1_read_reg;
375 sc->writereg = itkix1_write_reg;
376 sc->readfifo = itkix1_read_fifo;
377 sc->writefifo = itkix1_write_fifo;
379 /* setup card type */
380 sc->sc_cardtyp = CARD_TYPEP_ITKIX1;
382 /* setup IOM bus type */
383 sc->sc_bustyp = BUS_TYPE_IOM2;
386 sc->sc_bfifolen = HSCX_FIFO_LEN;
388 bus_space_write_1(t, h, ITK_CONFIG, 1);
389 DELAY(SEC_DELAY / 10);
390 bus_space_write_1(t, h, ITK_CONFIG, 0);
391 DELAY(SEC_DELAY / 10);