2 * Copyright (c) 1996 Andrew Gordon. All rights reserved.
4 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the author nor the names of any co-contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 * 4. Altered versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software and/or documentation.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 *---------------------------------------------------------------------------
35 * i4b_avm_a1.c - AVM A1/Fritz passive card driver for isdn4bsd
36 * ------------------------------------------------------------
38 * $Id: i4b_avm_a1.c,v 1.2 1999/12/13 21:25:26 hm Exp $
42 * last edit-date: [Mon Dec 13 21:58:36 1999]
44 *---------------------------------------------------------------------------*/
49 #if NISIC > 0 && defined(AVM_A1)
51 #include <sys/param.h>
52 #include <sys/ioccom.h>
53 #include <sys/kernel.h>
54 #include <sys/systm.h>
56 #include <sys/socket.h>
60 #include <machine/clock.h>
62 #include <machine/i4b_debug.h>
63 #include <machine/i4b_ioctl.h>
65 #include <i4b/include/i4b_global.h>
67 #include <i4b/layer1/i4b_l1.h>
68 #include <i4b/layer1/i4b_isac.h>
69 #include <i4b/layer1/i4b_hscx.h>
71 /*---------------------------------------------------------------------------*
72 * AVM A1 and AVM Fritz! Card special registers
73 *---------------------------------------------------------------------------*/
75 #define AVM_CONF_REG 0x1800 /* base offset for config register */
76 #define AVM_CONF_IRQ 0x1801 /* base offset for IRQ register */
77 /* config register write */
78 #define AVM_CONF_WR_RESET 0x01 /* 1 = RESET ISAC and HSCX */
79 #define AVM_CONF_WR_CCL 0x02 /* 1 = clear counter low nibble */
80 #define AVM_CONF_WR_CCH 0x04 /* 1 = clear counter high nibble */
81 #define AVM_CONF_WR_IRQEN 0x08 /* 1 = enable IRQ */
82 #define AVM_CONF_WR_TEST 0x10 /* test bit */
83 /* config register read */
84 #define AVM_CONF_RD_IIRQ 0x01 /* 0 = ISAC IRQ active */
85 #define AVM_CONF_RD_HIRQ 0x02 /* 0 = HSCX IRQ active */
86 #define AVM_CONF_RD_CIRQ 0x04 /* 0 = counter IRQ active */
87 #define AVM_CONF_RD_ZER1 0x08 /* unused, always read 0 */
88 #define AVM_CONF_RD_TEST 0x10 /* test bit read back */
89 #define AVM_CONF_RD_ZER2 0x20 /* unused, always read 0 */
91 #define AVM_ISAC_R_OFFS (0x1400-0x20)
92 #define AVM_HSCXA_R_OFFS (0x400-0x20)
93 #define AVM_HSCXB_R_OFFS (0xc00-0x20)
94 #define AVM_ISAC_F_OFFS (0x1400-0x20-0x3e0)
95 #define AVM_HSCXA_F_OFFS (0x400-0x20-0x3e0)
96 #define AVM_HSCXB_F_OFFS (0xc00-0x20-0x3e0)
98 /*---------------------------------------------------------------------------*
99 * AVM read fifo routine
100 *---------------------------------------------------------------------------*/
102 avma1_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
104 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+4]);
105 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+4]);
106 bus_space_read_multi_1(t, h, 0, buf, size);
109 /*---------------------------------------------------------------------------*
110 * AVM write fifo routine
111 *---------------------------------------------------------------------------*/
113 avma1_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
115 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+4]);
116 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+4]);
117 bus_space_write_multi_1(t, h, 0, (u_int8_t*)buf, size);
120 /*---------------------------------------------------------------------------*
121 * AVM write register routine
122 *---------------------------------------------------------------------------*/
124 avma1_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
126 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
127 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
128 bus_space_write_1(t, h, offs, data);
131 /*---------------------------------------------------------------------------*
132 * AVM read register routine
133 *---------------------------------------------------------------------------*/
135 avma1_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
137 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
138 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
139 return bus_space_read_1(t, h, offs);
142 /*---------------------------------------------------------------------------*
143 * allocate an io port
144 *---------------------------------------------------------------------------*/
146 isic_alloc_port(device_t dev, int rid, u_int base, u_int len)
148 size_t unit = device_get_unit(dev);
149 struct l1_softc *sc = &l1_sc[unit];
151 sc->sc_resources.io_rid[rid] = rid;
153 bus_set_resource(dev, SYS_RES_IOPORT, rid, base, len);
155 if(!(sc->sc_resources.io_base[rid] =
156 bus_alloc_resource(dev, SYS_RES_IOPORT,
157 &sc->sc_resources.io_rid[rid],
158 0ul, ~0ul, 1, RF_ACTIVE)))
160 printf("isic%d: Error, failed to reserve io #%d!\n", unit, rid);
161 isic_detach_common(dev);
167 /*---------------------------------------------------------------------------*
168 * isic_probe_avma1 - probe for AVM A1 and compatibles
169 *---------------------------------------------------------------------------*/
171 isic_probe_avma1(device_t dev)
173 size_t unit = device_get_unit(dev); /* get unit */
174 struct l1_softc *sc = 0; /* pointer to softc */
175 void *ih = 0; /* dummy */
176 bus_space_tag_t t; /* bus things */
177 bus_space_handle_t h;
181 /* check max unit range */
183 if(unit >= ISIC_MAXUNIT)
185 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for AVM A1/Fritz!\n",
190 sc = &l1_sc[unit]; /* get pointer to softc */
191 sc->sc_unit = unit; /* set unit */
192 sc->sc_flags = FLAG_AVM_A1; /* set flags */
194 /* see if an io base was supplied */
196 if(!(sc->sc_resources.io_base[0] =
197 bus_alloc_resource(dev, SYS_RES_IOPORT,
198 &sc->sc_resources.io_rid[0],
199 0ul, ~0ul, 1, RF_ACTIVE)))
201 printf("isic%d: Could not get iobase for AVM A1/Fritz!\n",
208 sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
210 /* release io base */
212 bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[0],
213 sc->sc_resources.io_base[0]);
224 printf("isic%d: Error, invalid iobase 0x%x specified for AVM A1/Fritz!\n",
230 if(isic_alloc_port(dev, 0, sc->sc_port+AVM_CONF_REG, 0x20))
233 if(isic_alloc_port(dev, 1, sc->sc_port+AVM_ISAC_R_OFFS, 0x20))
236 if(isic_alloc_port(dev, 2, sc->sc_port+AVM_HSCXA_R_OFFS, 0x20))
239 if(isic_alloc_port(dev, 3, sc->sc_port+AVM_HSCXB_R_OFFS, 0x20))
242 if(isic_alloc_port(dev, 4, sc->sc_port+AVM_ISAC_F_OFFS, 0x20))
245 if(isic_alloc_port(dev, 5, sc->sc_port+AVM_HSCXA_F_OFFS, 0x20))
248 if(isic_alloc_port(dev, 6, sc->sc_port+AVM_HSCXB_F_OFFS, 0x20))
253 if(!(sc->sc_resources.irq =
254 bus_alloc_resource(dev, SYS_RES_IRQ,
255 &sc->sc_resources.irq_rid,
256 0ul, ~0ul, 1, RF_ACTIVE)))
258 printf("isic%d: Could not get an irq for AVM A1/Fritz!\n",unit);
259 isic_detach_common(dev);
263 /* get the irq number */
264 sc->sc_irq = rman_get_start(sc->sc_resources.irq);
266 /* register interupt routine */
267 bus_setup_intr(dev, sc->sc_resources.irq, INTR_TYPE_NET,
268 (void(*)(void *))(isicintr),
271 /* check IRQ validity */
290 printf("isic%d: Error, invalid IRQ [%d] specified for AVM A1/Fritz!\n",
292 isic_detach_common(dev);
298 sc->readreg = avma1_read_reg;
299 sc->writereg = avma1_write_reg;
301 sc->readfifo = avma1_read_fifo;
302 sc->writefifo = avma1_write_fifo;
304 /* setup card type */
306 sc->sc_cardtyp = CARD_TYPEP_AVMA1;
308 /* setup IOM bus type */
310 sc->sc_bustyp = BUS_TYPE_IOM2;
313 sc->sc_bfifolen = HSCX_FIFO_LEN;
316 * Read HSCX A/B VSTR.
317 * Expected value for AVM A1 is 0x04 or 0x05 and for the
318 * AVM Fritz!Card is 0x05 in the least significant bits.
321 if( (((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) &&
322 ((HSCX_READ(0, H_VSTR) & 0xf) != 0x4)) ||
323 (((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) &&
324 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x4)) )
326 printf("isic%d: HSCX VSTR test failed for AVM A1/Fritz\n",
328 printf("isic%d: HSC0: VSTR: %#x\n",
329 unit, HSCX_READ(0, H_VSTR));
330 printf("isic%d: HSC1: VSTR: %#x\n",
331 unit, HSCX_READ(1, H_VSTR));
335 /* AVM A1 or Fritz! control register bits: */
337 /* 0x01 hscx irq* RESET */
338 /* 0x02 isac irq* clear counter1 */
339 /* 0x04 counter irq* clear counter2 */
340 /* 0x08 always 0 irq enable */
341 /* 0x10 read test bit set test bit */
342 /* 0x20 always 0 unused */
345 * XXX the following test may be destructive, to prevent the
346 * worst case, we save the byte first, and in case the test
347 * fails, we write back the saved byte .....
350 t = rman_get_bustag(sc->sc_resources.io_base[0]);
351 h = rman_get_bushandle(sc->sc_resources.io_base[0]);
353 savebyte = bus_space_read_1(t, h, 0);
355 /* write low to test bit */
357 bus_space_write_1(t, h, 0, 0x00);
359 /* test bit and next higher and lower bit must be 0 */
361 if((byte = bus_space_read_1(t, h, 0) & 0x38) != 0x00)
363 printf("isic%d: Error, probe-1 failed, 0x%02x should be 0x00 for AVM A1/Fritz!\n",
365 bus_space_write_1(t, h, 0, savebyte);
369 /* write high to test bit */
371 bus_space_write_1(t, h, 0, 0x10);
373 /* test bit must be high, next higher and lower bit must be 0 */
375 if((byte = bus_space_read_1(t, h, 0) & 0x38) != 0x10)
377 printf("isic%d: Error, probe-2 failed, 0x%02x should be 0x10 for AVM A1/Fritz!\n",
379 bus_space_write_1(t, h, 0, savebyte);
385 /*---------------------------------------------------------------------------*
386 * isic_attach_avma1 - attach AVM A1 and compatibles
387 *---------------------------------------------------------------------------*/
389 isic_attach_avma1(device_t dev)
391 size_t unit = device_get_unit(dev);
392 struct l1_softc *sc = &l1_sc[unit];
393 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
394 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
396 /* reset ISAC/HSCX */
398 bus_space_write_1(t, h, 0, 0x00);
399 DELAY(SEC_DELAY / 10);
401 bus_space_write_1(t, h, 0, AVM_CONF_WR_RESET);
402 DELAY(SEC_DELAY / 10);
404 bus_space_write_1(t, h, 0, 0x00);
405 DELAY(SEC_DELAY / 10);
409 bus_space_write_1(t, h, 1, sc->sc_irq);
410 DELAY(SEC_DELAY / 10);
412 /* enable IRQ, disable counter IRQ */
414 bus_space_write_1(t, h, 0, AVM_CONF_WR_IRQEN |
415 AVM_CONF_WR_CCH | AVM_CONF_WR_CCL);
416 DELAY(SEC_DELAY / 10);
421 #endif /* NISIC > 0 && defined(AVM_A1) */