2 * Copyright (c) 1996 Arne Helme. All rights reserved.
4 * Copyright (c) 1996 Gary Jennejohn. All rights reserved.
6 * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the author nor the names of any co-contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 * 4. Altered versions must be plainly marked as such, and must not be
21 * misrepresented as being the original software and/or documentation.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 *---------------------------------------------------------------------------
37 * isic - I4B Siemens ISDN Chipset Driver for Teles S0/16.3
38 * ========================================================
40 * $FreeBSD: src/sys/i4b/layer1/isic/i4b_tel_s0163.c,v 1.5.2.1 2001/08/10 14:08:38 obrien Exp $
41 * $DragonFly: src/sys/net/i4b/layer1/isic/i4b_tel_s0163.c,v 1.3 2003/08/07 21:17:26 dillon Exp $
43 * last edit-date: [Wed Jan 24 09:27:40 2001]
45 *---------------------------------------------------------------------------*/
50 #if NISIC > 0 && defined(TEL_S0_16_3)
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/socket.h>
57 #include <net/i4b/include/machine/i4b_ioctl.h>
58 #include <net/i4b/include/machine/i4b_trace.h>
60 #include "../i4b_l1.h"
64 static u_char intr_no[] = { 1, 1, 0, 2, 4, 6, 1, 1, 1, 0, 8, 10, 12, 1, 1, 14 };
66 #define ISAC_OFFS 0x400
67 #define HSCXA_OFFS 0xc00
68 #define HSCXB_OFFS 0x800
70 /*---------------------------------------------------------------------------*
71 * Teles S0/16.3 read fifo routine
72 *---------------------------------------------------------------------------*/
74 tels0163_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
76 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
77 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
78 bus_space_read_multi_1(t,h,0x1e,buf,size);
81 /*---------------------------------------------------------------------------*
82 * Teles S0/16.3 write fifo routine
83 *---------------------------------------------------------------------------*/
85 tels0163_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
87 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
88 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
89 bus_space_write_multi_1(t,h,0x1e,buf,size);
92 /*---------------------------------------------------------------------------*
93 * Teles S0/16.3 ISAC put register routine
94 *---------------------------------------------------------------------------*/
96 tels0163_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
98 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
99 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
100 bus_space_write_1(t,h,offs - 0x20,data);
103 /*---------------------------------------------------------------------------*
104 * Teles S0/16.3 ISAC get register routine
105 *---------------------------------------------------------------------------*/
107 tels0163_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
109 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
110 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
111 return bus_space_read_1(t,h,offs - 0x20);
114 /*---------------------------------------------------------------------------*
115 * isic_probe_s0163 - probe routine for Teles S0/16.3
116 *---------------------------------------------------------------------------*/
118 isic_probe_s0163(device_t dev)
120 size_t unit = device_get_unit(dev); /* get unit */
121 struct l1_softc *sc = 0; /* pointer to softc */
122 void *ih = 0; /* dummy */
123 bus_space_tag_t t; /* bus things */
124 bus_space_handle_t h;
125 u_int8_t b0,b1,b2; /* signature */
127 /* check max unit range */
129 if(unit >= ISIC_MAXUNIT)
131 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Teles 16.3!\n",
136 sc = &l1_sc[unit]; /* get pointer to softc */
137 sc->sc_unit = unit; /* set unit */
139 /* see if an io base was supplied */
141 if(!(sc->sc_resources.io_base[0] =
142 bus_alloc_resource(dev, SYS_RES_IOPORT,
143 &sc->sc_resources.io_rid[0],
144 0ul, ~0ul, 1, RF_ACTIVE)))
146 printf("isic%d: Could not get iobase for Teles S0/16.3.\n",
153 sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
154 /* Release the resource - re-allocate later with correct size */
155 bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[0],
156 sc->sc_resources.io_base[0]);
168 printf("isic%d: Error, instead of using iobase 0x%x for your Teles S0/16.3,\n",
170 printf("isic%d: please use 0x%x in the kernel configuration file!\n",
171 unit, sc->sc_port+0xc00);
172 isic_detach_common(dev);
177 printf("isic%d: Error, invalid iobase 0x%x specified for Teles S0/16.3!\n",
179 isic_detach_common(dev);
184 /* set io port resources */
186 sc->sc_resources.io_rid[0] = 0;
187 bus_set_resource(dev, SYS_RES_IOPORT, 0, sc->sc_port, 0x20);
188 sc->sc_resources.io_base[0] =
189 bus_alloc_resource(dev, SYS_RES_IOPORT,
190 &sc->sc_resources.io_rid[0],
191 0ul, ~0ul, 1, RF_ACTIVE);
192 if(!sc->sc_resources.io_base[0])
194 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
196 isic_detach_common(dev);
199 sc->sc_resources.io_rid[1] = 1;
200 bus_set_resource(dev, SYS_RES_IOPORT, 1,
201 sc->sc_port-ISAC_OFFS, 0x20);
202 sc->sc_resources.io_base[1] =
203 bus_alloc_resource(dev, SYS_RES_IOPORT,
204 &sc->sc_resources.io_rid[1],
205 0ul, ~0ul, 1, RF_ACTIVE);
206 if(!sc->sc_resources.io_base[1])
208 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
209 unit, sc->sc_port-ISAC_OFFS);
210 isic_detach_common(dev);
214 sc->sc_resources.io_rid[2] = 2;
215 bus_set_resource(dev, SYS_RES_IOPORT, 2,
216 sc->sc_port-HSCXA_OFFS, 0x20);
217 sc->sc_resources.io_base[2] =
218 bus_alloc_resource(dev, SYS_RES_IOPORT,
219 &sc->sc_resources.io_rid[2],
220 0ul, ~0ul, 1, RF_ACTIVE);
221 if(!sc->sc_resources.io_base[2])
223 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
224 unit, sc->sc_port-HSCXA_OFFS);
225 isic_detach_common(dev);
229 sc->sc_resources.io_rid[3] = 3;
230 bus_set_resource(dev, SYS_RES_IOPORT, 3,
231 sc->sc_port-HSCXB_OFFS, 0x20);
232 sc->sc_resources.io_base[3] =
233 bus_alloc_resource(dev, SYS_RES_IOPORT,
234 &sc->sc_resources.io_rid[3],
235 0ul, ~0ul, 1, RF_ACTIVE);
236 if(!sc->sc_resources.io_base[3])
238 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
239 unit, sc->sc_port-HSCXB_OFFS);
240 isic_detach_common(dev);
244 /* setup access routines */
247 sc->readreg = tels0163_read_reg;
248 sc->writereg = tels0163_write_reg;
250 sc->readfifo = tels0163_read_fifo;
251 sc->writefifo = tels0163_write_fifo;
253 /* setup card type */
255 sc->sc_cardtyp= CARD_TYPEP_16_3;
257 /* setup IOM bus type */
259 sc->sc_bustyp = BUS_TYPE_IOM2;
262 sc->sc_bfifolen = HSCX_FIFO_LEN;
264 t = rman_get_bustag(sc->sc_resources.io_base[0]);
265 h = rman_get_bushandle(sc->sc_resources.io_base[0]);
267 b0 = bus_space_read_1(t, h, 0);
268 b1 = bus_space_read_1(t, h, 1);
269 b2 = bus_space_read_1(t, h, 2);
271 if ( b0 != 0x51 && b0 != 0x10 ) {
272 printf("isic%d: Error, signature 1 0x%x != 0x51 or 0x10 for Teles S0/16.3!\n",
274 isic_detach_common(dev);
279 printf("isic%d: Error, signature 2 0x%x != 0x93 for Teles S0/16.3!\n",
281 isic_detach_common(dev);
284 if (( b2 != 0x1c ) && ( b2 != 0x1f )) {
285 printf("isic%d: Error, signature 3 0x%x != (0x1c || 0x1f) for Teles S0/16.3!\n",
287 isic_detach_common(dev);
292 * Read HSCX A/B VSTR. Expected value for the S0/16.3 card is
293 * 0x05 or 0x04 (for older 16.3's) in the least significant bits.
296 if( (((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) &&
297 ((HSCX_READ(0, H_VSTR) & 0xf) != 0x4)) ||
298 (((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) &&
299 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x4)) )
301 printf("isic%d: HSCX VSTR test failed for Teles S0/16.3\n",
303 printf("isic%d: HSC0: VSTR: %#x\n",
304 unit, HSCX_READ(0, H_VSTR));
305 printf("isic%d: HSC1: VSTR: %#x\n",
306 unit, HSCX_READ(1, H_VSTR));
307 isic_detach_common(dev);
313 if(!(sc->sc_resources.irq =
314 bus_alloc_resource(dev, SYS_RES_IRQ,
315 &sc->sc_resources.irq_rid,
316 0ul, ~0ul, 1, RF_ACTIVE)))
318 printf("isic%d: Could not get IRQ for Teles S0/16.3.\n",unit);
319 isic_detach_common(dev);
323 /* get the irq number */
324 sc->sc_irq = rman_get_start(sc->sc_resources.irq);
337 printf("isic%d: Error, invalid IRQ [%d] specified for Teles S0/16.3!\n",
339 isic_detach_common(dev);
344 /* register interupt routine */
345 bus_setup_intr(dev, sc->sc_resources.irq,
347 (void(*)(void *))(isicintr),
353 /*---------------------------------------------------------------------------*
354 * isic_attach_s0163 - attach Teles S0/16.3 and compatibles
355 *---------------------------------------------------------------------------*/
357 isic_attach_s0163(device_t dev)
359 unsigned int unit = device_get_unit(dev); /* get unit */
360 struct l1_softc *sc = &l1_sc[unit];
361 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
362 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
366 DELAY(SEC_DELAY / 10);
367 bus_space_write_1(t, h, 4, intr_no[sc->sc_irq]);
369 DELAY(SEC_DELAY / 10);
370 bus_space_write_1(t, h, 4, intr_no[sc->sc_irq] | 0x01);
375 #endif /* ISIC > 0 */