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 $
42 * last edit-date: [Wed Jan 24 09:27:40 2001]
44 *---------------------------------------------------------------------------*/
49 #if NISIC > 0 && defined(TEL_S0_16_3)
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/socket.h>
56 #include <net/i4b/include/machine/i4b_ioctl.h>
57 #include <net/i4b/include/machine/i4b_trace.h>
59 #include "../i4b_l1.h"
63 static u_char intr_no[] = { 1, 1, 0, 2, 4, 6, 1, 1, 1, 0, 8, 10, 12, 1, 1, 14 };
65 #define ISAC_OFFS 0x400
66 #define HSCXA_OFFS 0xc00
67 #define HSCXB_OFFS 0x800
69 /*---------------------------------------------------------------------------*
70 * Teles S0/16.3 read fifo routine
71 *---------------------------------------------------------------------------*/
73 tels0163_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
75 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
76 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
77 bus_space_read_multi_1(t,h,0x1e,buf,size);
80 /*---------------------------------------------------------------------------*
81 * Teles S0/16.3 write fifo routine
82 *---------------------------------------------------------------------------*/
84 tels0163_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
86 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
87 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
88 bus_space_write_multi_1(t,h,0x1e,buf,size);
91 /*---------------------------------------------------------------------------*
92 * Teles S0/16.3 ISAC put register routine
93 *---------------------------------------------------------------------------*/
95 tels0163_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
97 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
98 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
99 bus_space_write_1(t,h,offs - 0x20,data);
102 /*---------------------------------------------------------------------------*
103 * Teles S0/16.3 ISAC get register routine
104 *---------------------------------------------------------------------------*/
106 tels0163_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
108 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
109 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
110 return bus_space_read_1(t,h,offs - 0x20);
113 /*---------------------------------------------------------------------------*
114 * isic_probe_s0163 - probe routine for Teles S0/16.3
115 *---------------------------------------------------------------------------*/
117 isic_probe_s0163(device_t dev)
119 size_t unit = device_get_unit(dev); /* get unit */
120 struct l1_softc *sc = NULL; /* pointer to softc */
121 void *ih = NULL; /* dummy */
122 bus_space_tag_t t; /* bus things */
123 bus_space_handle_t h;
124 u_int8_t b0,b1,b2; /* signature */
126 /* check max unit range */
128 if(unit >= ISIC_MAXUNIT)
130 kprintf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Teles 16.3!\n",
135 sc = &l1_sc[unit]; /* get pointer to softc */
136 sc->sc_unit = unit; /* set unit */
138 /* see if an io base was supplied */
140 if(!(sc->sc_resources.io_base[0] =
141 bus_alloc_resource(dev, SYS_RES_IOPORT,
142 &sc->sc_resources.io_rid[0],
143 0ul, ~0ul, 1, RF_ACTIVE)))
145 kprintf("isic%d: Could not get iobase for Teles S0/16.3.\n",
152 sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
153 /* Release the resource - re-allocate later with correct size */
154 bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[0],
155 sc->sc_resources.io_base[0]);
167 kprintf("isic%d: Error, instead of using iobase 0x%x for your Teles S0/16.3,\n",
169 kprintf("isic%d: please use 0x%x in the kernel configuration file!\n",
170 unit, sc->sc_port+0xc00);
171 isic_detach_common(dev);
176 kprintf("isic%d: Error, invalid iobase 0x%x specified for Teles S0/16.3!\n",
178 isic_detach_common(dev);
183 /* set io port resources */
185 sc->sc_resources.io_rid[0] = 0;
186 bus_set_resource(dev, SYS_RES_IOPORT, 0, sc->sc_port, 0x20, -1);
187 sc->sc_resources.io_base[0] =
188 bus_alloc_resource(dev, SYS_RES_IOPORT,
189 &sc->sc_resources.io_rid[0],
190 0ul, ~0ul, 1, RF_ACTIVE);
191 if(!sc->sc_resources.io_base[0])
193 kprintf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
195 isic_detach_common(dev);
198 sc->sc_resources.io_rid[1] = 1;
199 bus_set_resource(dev, SYS_RES_IOPORT, 1,
200 sc->sc_port-ISAC_OFFS, 0x20, -1);
201 sc->sc_resources.io_base[1] =
202 bus_alloc_resource(dev, SYS_RES_IOPORT,
203 &sc->sc_resources.io_rid[1],
204 0ul, ~0ul, 1, RF_ACTIVE);
205 if(!sc->sc_resources.io_base[1])
207 kprintf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
208 unit, sc->sc_port-ISAC_OFFS);
209 isic_detach_common(dev);
213 sc->sc_resources.io_rid[2] = 2;
214 bus_set_resource(dev, SYS_RES_IOPORT, 2,
215 sc->sc_port-HSCXA_OFFS, 0x20, -1);
216 sc->sc_resources.io_base[2] =
217 bus_alloc_resource(dev, SYS_RES_IOPORT,
218 &sc->sc_resources.io_rid[2],
219 0ul, ~0ul, 1, RF_ACTIVE);
220 if(!sc->sc_resources.io_base[2])
222 kprintf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
223 unit, sc->sc_port-HSCXA_OFFS);
224 isic_detach_common(dev);
228 sc->sc_resources.io_rid[3] = 3;
229 bus_set_resource(dev, SYS_RES_IOPORT, 3,
230 sc->sc_port-HSCXB_OFFS, 0x20, -1);
231 sc->sc_resources.io_base[3] =
232 bus_alloc_resource(dev, SYS_RES_IOPORT,
233 &sc->sc_resources.io_rid[3],
234 0ul, ~0ul, 1, RF_ACTIVE);
235 if(!sc->sc_resources.io_base[3])
237 kprintf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
238 unit, sc->sc_port-HSCXB_OFFS);
239 isic_detach_common(dev);
243 /* setup access routines */
246 sc->readreg = tels0163_read_reg;
247 sc->writereg = tels0163_write_reg;
249 sc->readfifo = tels0163_read_fifo;
250 sc->writefifo = tels0163_write_fifo;
252 /* setup card type */
254 sc->sc_cardtyp= CARD_TYPEP_16_3;
256 /* setup IOM bus type */
258 sc->sc_bustyp = BUS_TYPE_IOM2;
261 sc->sc_bfifolen = HSCX_FIFO_LEN;
263 t = rman_get_bustag(sc->sc_resources.io_base[0]);
264 h = rman_get_bushandle(sc->sc_resources.io_base[0]);
266 b0 = bus_space_read_1(t, h, 0);
267 b1 = bus_space_read_1(t, h, 1);
268 b2 = bus_space_read_1(t, h, 2);
270 if ( b0 != 0x51 && b0 != 0x10 ) {
271 kprintf("isic%d: Error, signature 1 0x%x != 0x51 or 0x10 for Teles S0/16.3!\n",
273 isic_detach_common(dev);
278 kprintf("isic%d: Error, signature 2 0x%x != 0x93 for Teles S0/16.3!\n",
280 isic_detach_common(dev);
283 if (( b2 != 0x1c ) && ( b2 != 0x1f )) {
284 kprintf("isic%d: Error, signature 3 0x%x != (0x1c || 0x1f) for Teles S0/16.3!\n",
286 isic_detach_common(dev);
291 * Read HSCX A/B VSTR. Expected value for the S0/16.3 card is
292 * 0x05 or 0x04 (for older 16.3's) in the least significant bits.
295 if( (((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) &&
296 ((HSCX_READ(0, H_VSTR) & 0xf) != 0x4)) ||
297 (((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) &&
298 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x4)) )
300 kprintf("isic%d: HSCX VSTR test failed for Teles S0/16.3\n",
302 kprintf("isic%d: HSC0: VSTR: %#x\n",
303 unit, HSCX_READ(0, H_VSTR));
304 kprintf("isic%d: HSC1: VSTR: %#x\n",
305 unit, HSCX_READ(1, H_VSTR));
306 isic_detach_common(dev);
312 if(!(sc->sc_resources.irq =
313 bus_alloc_resource(dev, SYS_RES_IRQ,
314 &sc->sc_resources.irq_rid,
315 0ul, ~0ul, 1, RF_ACTIVE)))
317 kprintf("isic%d: Could not get IRQ for Teles S0/16.3.\n",unit);
318 isic_detach_common(dev);
322 /* get the irq number */
323 sc->sc_irq = rman_get_start(sc->sc_resources.irq);
336 kprintf("isic%d: Error, invalid IRQ [%d] specified for Teles S0/16.3!\n",
338 isic_detach_common(dev);
343 /* register interupt routine */
344 bus_setup_intr(dev, sc->sc_resources.irq,
345 0, (void(*)(void *))(isicintr),
351 /*---------------------------------------------------------------------------*
352 * isic_attach_s0163 - attach Teles S0/16.3 and compatibles
353 *---------------------------------------------------------------------------*/
355 isic_attach_s0163(device_t dev)
357 unsigned int unit = device_get_unit(dev); /* get unit */
358 struct l1_softc *sc = &l1_sc[unit];
359 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
360 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
364 DELAY(SEC_DELAY / 10);
365 bus_space_write_1(t, h, 4, intr_no[sc->sc_irq]);
367 DELAY(SEC_DELAY / 10);
368 bus_space_write_1(t, h, 4, intr_no[sc->sc_irq] | 0x01);
373 #endif /* ISIC > 0 */