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 withough 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 $
32 * $DragonFly: src/sys/net/i4b/layer1/isic/i4b_itk_ix1.c,v 1.3 2003/08/07 21:17:26 dillon Exp $
34 *---------------------------------------------------------------------------
36 * The ITK ix1 micro ISDN card is an ISA card with one region
37 * of four io ports mapped and a fixed irq all jumpered on the card.
38 * Access to the board is straight forward and simmilar to
39 * the ELSA and DYNALINK cards. If a PCI version of this card
40 * exists all we need is probably a pci-bus attachment, all
41 * this low level routines should work imediately.
44 * - write 0x01 to ITK_CONFIG
46 * - write 0x00 to ITK_CONFIG
48 * To read or write data:
49 * - write address to ITK_ALE port
50 * - read data from or write data to ITK_ISAC_DATA port or ITK_HSCX_DATA port
51 * The two HSCX channel registers are offset by HSCXA (0x00) and HSCXB (0x40).
53 * The probe routine was derived by trial and error from a representative
54 * sample of two cards ;-) The standard way (checking HSCX versions)
55 * was extended by reading a zero from a non existant HSCX register (register
56 * 0xff). Reading the config register gives varying results, so this doesn't
57 * seem to be used as an id register (like the Teles S0/16.3).
59 * If the probe fails for your card use "options ITK_PROBE_DEBUG" to get
60 * additional debug output.
62 *---------------------------------------------------------------------------*/
67 #if NISIC > 0 && defined(ITKIX1)
69 #include <sys/param.h>
70 #include <sys/systm.h>
71 #include <sys/socket.h>
74 #include <net/i4b/include/machine/i4b_ioctl.h>
75 #include <net/i4b/include/machine/i4b_trace.h>
76 #include "../i4b_l1.h"
80 /* Register offsets */
81 #define ITK_ISAC_DATA 0
82 #define ITK_HSCX_DATA 1
86 /* Size of IO range to allocate for this card */
89 /* Register offsets for the two HSCX channels */
94 itkix1_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
96 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
97 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
101 bus_space_write_1(t, h, ITK_ALE, 0);
102 bus_space_read_multi_1(t, h, ITK_ISAC_DATA, buf, size);
104 case ISIC_WHAT_HSCXA:
105 bus_space_write_1(t, h, ITK_ALE, HSCXA);
106 bus_space_read_multi_1(t, h, ITK_HSCX_DATA, buf, size);
108 case ISIC_WHAT_HSCXB:
109 bus_space_write_1(t, h, ITK_ALE, HSCXB);
110 bus_space_read_multi_1(t, h, ITK_HSCX_DATA, buf, size);
116 itkix1_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
118 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
119 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
123 bus_space_write_1(t, h, ITK_ALE, 0);
124 bus_space_write_multi_1(t, h, ITK_ISAC_DATA, (u_int8_t*)buf, size);
126 case ISIC_WHAT_HSCXA:
127 bus_space_write_1(t, h, ITK_ALE, HSCXA);
128 bus_space_write_multi_1(t, h, ITK_HSCX_DATA, (u_int8_t*)buf, size);
130 case ISIC_WHAT_HSCXB:
131 bus_space_write_1(t, h, ITK_ALE, HSCXB);
132 bus_space_write_multi_1(t, h, ITK_HSCX_DATA, (u_int8_t*)buf, size);
138 itkix1_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
140 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
141 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
145 bus_space_write_1(t, h, ITK_ALE, offs);
146 bus_space_write_1(t, h, ITK_ISAC_DATA, data);
148 case ISIC_WHAT_HSCXA:
149 bus_space_write_1(t, h, ITK_ALE, HSCXA+offs);
150 bus_space_write_1(t, h, ITK_HSCX_DATA, data);
152 case ISIC_WHAT_HSCXB:
153 bus_space_write_1(t, h, ITK_ALE, HSCXB+offs);
154 bus_space_write_1(t, h, ITK_HSCX_DATA, data);
160 itkix1_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
162 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
163 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
167 bus_space_write_1(t, h, ITK_ALE, offs);
168 return bus_space_read_1(t, h, ITK_ISAC_DATA);
169 case ISIC_WHAT_HSCXA:
170 bus_space_write_1(t, h, ITK_ALE, HSCXA+offs);
171 return bus_space_read_1(t, h, ITK_HSCX_DATA);
172 case ISIC_WHAT_HSCXB:
173 bus_space_write_1(t, h, ITK_ALE, HSCXB+offs);
174 return bus_space_read_1(t, h, ITK_HSCX_DATA);
183 isic_probe_itkix1(device_t dev)
185 size_t unit = device_get_unit(dev); /* get unit */
186 struct l1_softc *sc = 0; /* softc */
187 void *ih = 0; /* dummy */
188 bus_space_tag_t t; /* bus things */
189 bus_space_handle_t h;
190 u_int8_t hd, hv1, hv2, saveale;
193 #if defined(ITK_PROBE_DEBUG)
194 printf("Checking unit %u\n", unit);
197 /* check max unit range */
198 if(unit >= ISIC_MAXUNIT)
200 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for ITK IX1!\n",
205 sc = &l1_sc[unit]; /* get pointer to softc */
206 sc->sc_unit = unit; /* set unit */
208 #if defined(ITK_PROBE_DEBUG)
209 printf("Allocating io base...");
212 if(!(sc->sc_resources.io_base[0] =
213 bus_alloc_resource(dev, SYS_RES_IOPORT,
214 &sc->sc_resources.io_rid[0],
215 0ul, ~0ul, 1, RF_ACTIVE)))
217 printf("isic%d: Could not allocate i/o port for ITK IX1.\n", unit);
221 #if defined(ITK_PROBE_DEBUG)
225 sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
226 t = rman_get_bustag(sc->sc_resources.io_base[0]);
227 h = rman_get_bushandle(sc->sc_resources.io_base[0]);
229 #if defined(ITK_PROBE_DEBUG)
230 printf("Allocating irq...");
234 if(!(sc->sc_resources.irq =
235 bus_alloc_resource(dev, SYS_RES_IRQ,
236 &sc->sc_resources.irq_rid,
237 0ul, ~0ul, 1, RF_ACTIVE)))
239 printf("isic%d: Could not allocate irq for ITK IX1.\n", unit);
240 bus_release_resource(dev,SYS_RES_IOPORT,
241 sc->sc_resources.io_rid[0],
242 sc->sc_resources.io_base[0]);
246 #if defined(ITK_PROBE_DEBUG)
250 /* get the irq number */
251 sc->sc_irq = rman_get_start(sc->sc_resources.irq);
253 #if defined(ITK_PROBE_DEBUG)
254 printf("Setting up access routines...");
257 /* setup access routines */
259 sc->readreg = itkix1_read_reg;
260 sc->writereg = itkix1_write_reg;
261 sc->readfifo = itkix1_read_fifo;
262 sc->writefifo = itkix1_write_fifo;
264 /* setup card type */
265 sc->sc_cardtyp = CARD_TYPEP_ITKIX1;
267 /* setup IOM bus type */
268 sc->sc_bustyp = BUS_TYPE_IOM2;
271 sc->sc_bfifolen = HSCX_FIFO_LEN;
273 #if defined(ITK_PROBE_DEBUG)
277 /* register interupt routine */
279 #if defined(ITK_PROBE_DEBUG)
280 printf("Setting up access interupt...");
283 bus_setup_intr(dev, sc->sc_resources.irq,
285 (void(*)(void *))(isicintr),
288 #if defined(ITK_PROBE_DEBUG)
291 printf("Doing probe stuff...");
294 /* save old value of this port, we're stomping over it */
295 saveale = bus_space_read_1(t, h, ITK_ALE);
297 /* select invalid register */
298 bus_space_write_1(t, h, ITK_ALE, 0xff);
299 /* get HSCX data for this non existent register */
300 hd = bus_space_read_1(t, h, ITK_HSCX_DATA);
301 /* get HSCX version info */
302 bus_space_write_1(t, h, ITK_ALE, HSCXA + H_VSTR);
303 hv1 = bus_space_read_1(t, h, ITK_HSCX_DATA);
304 bus_space_write_1(t, h, ITK_ALE, HSCXB + H_VSTR);
305 hv2 = bus_space_read_1(t, h, ITK_HSCX_DATA);
307 ret = (hd == 0) && ((hv1 & 0x0f) == 0x05) && ((hv2 & 0x0f) == 0x05);
308 /* succeed if version bits are OK and we got a zero from the
309 * non existent register. we found verison 0x05 and 0x04
312 && (((hv1 & 0x0f) == 0x05) || ((hv1 & 0x0f) == 0x04))
313 && (((hv2 & 0x0f) == 0x05) || ((hv2 & 0x0f) == 0x04));
315 /* retstore save value if we fail (if we succeed the old value
318 bus_space_write_1(t, h, ITK_ALE, saveale);
320 #if defined(ITK_PROBE_DEBUG)
323 printf("Doing second probe stuff...");
326 hv1 = HSCX_READ(0, H_VSTR) & 0xf;
327 hv2 = HSCX_READ(1, H_VSTR) & 0xf;
328 /* Read HSCX A/B VSTR. Expected value is 0x05 (V2.1) or 0x04 (V2.0). */
329 if((hv1 != 0x05 && hv1 != 0x04) || (hv2 != 0x05 && hv2 != 0x04))
331 printf("isic%d: HSCX VSTR test failed for ITK ix1 micro\n",
333 printf("isic%d: HSC0: VSTR: %#x\n",
334 unit, HSCX_READ(0, H_VSTR));
335 printf("isic%d: HSC1: VSTR: %#x\n",
336 unit, HSCX_READ(1, H_VSTR));
337 isic_detach_common(dev);
341 #if defined(ITK_PROBE_DEBUG)
345 #if defined(ITK_PROBE_DEBUG)
346 printf("\nITK ix1 micro probe: hscx = 0x%02x, v1 = 0x%02x, v2 = 0x%02x, would have %s\n",
347 hd, hv1, hv2, ret ? "succeeded" : "failed");
348 isic_detach_common(dev);
357 isic_detach_common(dev);
367 isic_attach_itkix1(device_t dev)
369 size_t unit = device_get_unit(dev); /* get unit */
370 struct l1_softc *sc = &l1_sc[unit];
371 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
372 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
374 /* setup access routines */
376 sc->readreg = itkix1_read_reg;
377 sc->writereg = itkix1_write_reg;
378 sc->readfifo = itkix1_read_fifo;
379 sc->writefifo = itkix1_write_fifo;
381 /* setup card type */
382 sc->sc_cardtyp = CARD_TYPEP_ITKIX1;
384 /* setup IOM bus type */
385 sc->sc_bustyp = BUS_TYPE_IOM2;
388 sc->sc_bfifolen = HSCX_FIFO_LEN;
390 bus_space_write_1(t, h, ITK_CONFIG, 1);
391 DELAY(SEC_DELAY / 10);
392 bus_space_write_1(t, h, ITK_CONFIG, 0);
393 DELAY(SEC_DELAY / 10);