2 * Copyright (c) 1996 Arne Helme. All rights reserved.
3 * Copyright (c) 1996 Gary Jennejohn. All rights reserved.
4 * Copyright (c) 1997, 2001 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
34 /*---------------------------------------------------------------------------
36 * isic - I4B Siemens ISDN Chipset Driver for Teles S0/16.3
37 * ========================================================
38 * last edit-date: [Wed Jan 24 09:27:40 2001]
40 *---------------------------------------------------------------------------*/
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
47 #if defined(TEL_S0_16_3)
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/socket.h>
54 #include <i4b/include/i4b_ioctl.h>
55 #include <i4b/include/i4b_trace.h>
57 #include <i4b/layer1/i4b_l1.h>
58 #include <i4b/layer1/isic/i4b_isic.h>
59 #include <i4b/layer1/isic/i4b_hscx.h>
61 static u_char intr_no[] = { 1, 1, 0, 2, 4, 6, 1, 1, 1, 0, 8, 10, 12, 1, 1, 14 };
63 #define ISAC_OFFS 0x400
64 #define HSCXA_OFFS 0xc00
65 #define HSCXB_OFFS 0x800
67 /*---------------------------------------------------------------------------*
68 * Teles S0/16.3 read fifo routine
69 *---------------------------------------------------------------------------*/
71 tels0163_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
73 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
74 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
75 bus_space_read_multi_1(t,h,0x1e,buf,size);
78 /*---------------------------------------------------------------------------*
79 * Teles S0/16.3 write fifo routine
80 *---------------------------------------------------------------------------*/
82 tels0163_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
84 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
85 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
86 bus_space_write_multi_1(t,h,0x1e,buf,size);
89 /*---------------------------------------------------------------------------*
90 * Teles S0/16.3 ISAC put register routine
91 *---------------------------------------------------------------------------*/
93 tels0163_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
95 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
96 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
97 bus_space_write_1(t,h,offs - 0x20,data);
100 /*---------------------------------------------------------------------------*
101 * Teles S0/16.3 ISAC get register routine
102 *---------------------------------------------------------------------------*/
104 tels0163_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
106 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
107 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
108 return bus_space_read_1(t,h,offs - 0x20);
111 /*---------------------------------------------------------------------------*
112 * isic_probe_s0163 - probe routine for Teles S0/16.3
113 *---------------------------------------------------------------------------*/
115 isic_probe_s0163(device_t dev)
117 size_t unit = device_get_unit(dev); /* get unit */
118 struct l1_softc *sc = 0; /* pointer to softc */
119 void *ih = 0; /* dummy */
120 bus_space_tag_t t; /* bus things */
121 bus_space_handle_t h;
122 u_int8_t b0,b1,b2; /* signature */
124 /* check max unit range */
126 if(unit >= ISIC_MAXUNIT)
128 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Teles 16.3!\n",
133 sc = &l1_sc[unit]; /* get pointer to softc */
134 sc->sc_unit = unit; /* set unit */
136 /* see if an io base was supplied */
138 if(!(sc->sc_resources.io_base[0] =
139 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
140 &sc->sc_resources.io_rid[0],
143 printf("isic%d: Could not get iobase for Teles S0/16.3.\n",
150 sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
151 /* Release the resource - re-allocate later with correct size */
152 bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[0],
153 sc->sc_resources.io_base[0]);
165 printf("isic%d: Error, instead of using iobase 0x%x for your Teles S0/16.3,\n",
167 printf("isic%d: please use 0x%x in the kernel configuration file!\n",
168 unit, sc->sc_port+0xc00);
169 isic_detach_common(dev);
174 printf("isic%d: Error, invalid iobase 0x%x specified for Teles S0/16.3!\n",
176 isic_detach_common(dev);
181 /* set io port resources */
183 sc->sc_resources.io_rid[0] = 0;
184 bus_set_resource(dev, SYS_RES_IOPORT, 0, sc->sc_port, 0x20);
185 sc->sc_resources.io_base[0] =
186 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
187 &sc->sc_resources.io_rid[0],
189 if(!sc->sc_resources.io_base[0])
191 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
193 isic_detach_common(dev);
196 sc->sc_resources.io_rid[1] = 1;
197 bus_set_resource(dev, SYS_RES_IOPORT, 1,
198 sc->sc_port-ISAC_OFFS, 0x20);
199 sc->sc_resources.io_base[1] =
200 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
201 &sc->sc_resources.io_rid[1],
203 if(!sc->sc_resources.io_base[1])
205 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
206 unit, sc->sc_port-ISAC_OFFS);
207 isic_detach_common(dev);
211 sc->sc_resources.io_rid[2] = 2;
212 bus_set_resource(dev, SYS_RES_IOPORT, 2,
213 sc->sc_port-HSCXA_OFFS, 0x20);
214 sc->sc_resources.io_base[2] =
215 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
216 &sc->sc_resources.io_rid[2],
218 if(!sc->sc_resources.io_base[2])
220 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
221 unit, sc->sc_port-HSCXA_OFFS);
222 isic_detach_common(dev);
226 sc->sc_resources.io_rid[3] = 3;
227 bus_set_resource(dev, SYS_RES_IOPORT, 3,
228 sc->sc_port-HSCXB_OFFS, 0x20);
229 sc->sc_resources.io_base[3] =
230 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
231 &sc->sc_resources.io_rid[3],
233 if(!sc->sc_resources.io_base[3])
235 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
236 unit, sc->sc_port-HSCXB_OFFS);
237 isic_detach_common(dev);
241 /* setup access routines */
244 sc->readreg = tels0163_read_reg;
245 sc->writereg = tels0163_write_reg;
247 sc->readfifo = tels0163_read_fifo;
248 sc->writefifo = tels0163_write_fifo;
250 /* setup card type */
252 sc->sc_cardtyp= CARD_TYPEP_16_3;
254 /* setup IOM bus type */
256 sc->sc_bustyp = BUS_TYPE_IOM2;
259 sc->sc_bfifolen = HSCX_FIFO_LEN;
261 t = rman_get_bustag(sc->sc_resources.io_base[0]);
262 h = rman_get_bushandle(sc->sc_resources.io_base[0]);
264 b0 = bus_space_read_1(t, h, 0);
265 b1 = bus_space_read_1(t, h, 1);
266 b2 = bus_space_read_1(t, h, 2);
268 if ( b0 != 0x51 && b0 != 0x10 ) {
269 printf("isic%d: Error, signature 1 0x%x != 0x51 or 0x10 for Teles S0/16.3!\n",
271 isic_detach_common(dev);
276 printf("isic%d: Error, signature 2 0x%x != 0x93 for Teles S0/16.3!\n",
278 isic_detach_common(dev);
281 if (( b2 != 0x1c ) && ( b2 != 0x1f )) {
282 printf("isic%d: Error, signature 3 0x%x != (0x1c || 0x1f) for Teles S0/16.3!\n",
284 isic_detach_common(dev);
289 * Read HSCX A/B VSTR. Expected value for the S0/16.3 card is
290 * 0x05 or 0x04 (for older 16.3's) in the least significant bits.
293 if( (((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) &&
294 ((HSCX_READ(0, H_VSTR) & 0xf) != 0x4)) ||
295 (((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) &&
296 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x4)) )
298 printf("isic%d: HSCX VSTR test failed for Teles S0/16.3\n",
300 printf("isic%d: HSC0: VSTR: %#x\n",
301 unit, HSCX_READ(0, H_VSTR));
302 printf("isic%d: HSC1: VSTR: %#x\n",
303 unit, HSCX_READ(1, H_VSTR));
304 isic_detach_common(dev);
310 if(!(sc->sc_resources.irq =
311 bus_alloc_resource_any(dev, SYS_RES_IRQ,
312 &sc->sc_resources.irq_rid,
315 printf("isic%d: Could not get IRQ for Teles S0/16.3.\n",unit);
316 isic_detach_common(dev);
320 /* get the irq number */
321 sc->sc_irq = rman_get_start(sc->sc_resources.irq);
334 printf("isic%d: Error, invalid IRQ [%d] specified for Teles S0/16.3!\n",
336 isic_detach_common(dev);
341 /* register interrupt routine */
342 if (bus_setup_intr(dev, sc->sc_resources.irq, INTR_TYPE_NET, NULL,
343 (void(*)(void *))(isicintr), sc, &ih) != 0)
345 printf("isic%d: Could not setup IRQ for Teles S0/16.3.\n",unit);
346 isic_detach_common(dev);
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 /* defined(TEL_S0_16_3) */