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 and clones
37 * =================================================================
38 * last edit-date: [Wed Jan 24 09:27:24 2001]
40 *---------------------------------------------------------------------------*/
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
47 #if defined(TEL_S0_16)
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/socket.h>
54 #include <machine/md_var.h>
55 #include <i4b/include/i4b_ioctl.h>
56 #include <i4b/include/i4b_trace.h>
58 #include <i4b/layer1/i4b_l1.h>
59 #include <i4b/layer1/isic/i4b_isic.h>
60 #include <i4b/layer1/isic/i4b_hscx.h>
62 #define TELES_S016_MEMSIZE 0x1000
64 static u_char intr_no[] = { 1, 1, 0, 2, 4, 6, 1, 1, 1, 0, 8, 10, 12, 1, 1, 14 };
65 static const bus_size_t offset[] = { 0x100, 0x180, 0x1c0 };
67 /*---------------------------------------------------------------------------*
68 * Teles S0/16 write register routine
69 *---------------------------------------------------------------------------*/
71 tels016_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
73 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.mem);
74 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.mem);
81 bus_space_write_1(t, h, offs, data);
84 /*---------------------------------------------------------------------------*
85 * Teles S0/16 read register routine
86 *---------------------------------------------------------------------------*/
88 tels016_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
90 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.mem);
91 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.mem);
98 return bus_space_read_1(t, h, offs);
101 /*---------------------------------------------------------------------------*
102 * Teles S0/16 fifo write routine
103 *---------------------------------------------------------------------------*/
105 tels016_write_fifo(struct l1_softc *sc, int what, void *data, size_t size)
107 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.mem);
108 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.mem);
109 bus_space_write_region_1(t, h, offset[what], data, size);
112 /*---------------------------------------------------------------------------*
113 * Teles S0/16 fifo read routine
114 *---------------------------------------------------------------------------*/
116 tels016_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
118 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.mem);
119 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.mem);
120 bus_space_read_region_1(t, h, offset[what], buf, size);
123 /*---------------------------------------------------------------------------*
124 * isic_probe_s016 - probe for Teles S0/16 and compatibles
125 *---------------------------------------------------------------------------*/
127 isic_probe_s016(device_t dev)
129 size_t unit = device_get_unit(dev); /* get unit */
130 struct l1_softc *sc = 0; /* softc */
131 void *ih = 0; /* dummy */
132 u_int8_t b0,b1,b2; /* for signature */
133 bus_space_tag_t t; /* bus things */
134 bus_space_handle_t h;
136 /* check max unit range */
138 if(unit >= ISIC_MAXUNIT)
140 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Teles S0/16!\n",
145 sc = &l1_sc[unit]; /* get pointer to softc */
146 sc->sc_unit = unit; /* set unit */
148 /* see if an io base was supplied */
150 if(!(sc->sc_resources.io_base[0] =
151 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
152 &sc->sc_resources.io_rid[0],
155 printf("isic%d: Could not allocate i/o port for Teles S0/16.\n", unit);
159 sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
162 * check if the provided io port is valid
173 printf("isic%d: Error, invalid iobase 0x%x specified for Teles S0/16!\n",
175 isic_detach_common(dev);
180 /* allocate memory resource */
182 if(!(sc->sc_resources.mem =
183 bus_alloc_resource(dev, SYS_RES_MEMORY,
184 &sc->sc_resources.mem_rid,
185 0ul, ~0ul, TELES_S016_MEMSIZE,
188 printf("isic%d: Could not allocate memory for Teles S0/16.\n", unit);
189 isic_detach_common(dev);
196 sc->sc_vmem_addr = rman_get_virtual(sc->sc_resources.mem);
199 * check for valid adresses
201 switch(kvtop(sc->sc_vmem_addr))
222 printf("isic%d: Error, invalid memory address 0x%x for Teles S0/16!\n",
223 unit, kvtop(sc->sc_vmem_addr));
224 isic_detach_common(dev);
229 /* setup ISAC access routines */
233 sc->readreg = tels016_read_reg;
234 sc->writereg = tels016_write_reg;
236 sc->readfifo = tels016_read_fifo;
237 sc->writefifo = tels016_write_fifo;
239 /* setup card type */
240 sc->sc_cardtyp = CARD_TYPEP_16;
242 /* setup IOM bus type */
244 sc->sc_bustyp = BUS_TYPE_IOM1;
247 sc->sc_bfifolen = HSCX_FIFO_LEN;
249 /* setup ISAC base addr, though we don't really need it */
251 ISAC_BASE = (caddr_t)((sc->sc_vmem_addr) + 0x100);
253 /* setup HSCX base addr */
255 HSCX_A_BASE = (caddr_t)((sc->sc_vmem_addr) + 0x180);
256 HSCX_B_BASE = (caddr_t)((sc->sc_vmem_addr) + 0x1c0);
258 t = rman_get_bustag(sc->sc_resources.io_base[0]);
259 h = rman_get_bushandle(sc->sc_resources.io_base[0]);
261 /* get signature bytes */
262 b0 = bus_space_read_1(t, h, 0);
263 b1 = bus_space_read_1(t, h, 1);
264 b2 = bus_space_read_1(t, h, 2);
266 /* check signature bytes */
269 printf("isic%d: Error, signature 1 0x%x != 0x51 for Teles S0/16!\n",
271 isic_detach_common(dev);
277 printf("isic%d: Error, signature 2 0x%x != 0x93 for Teles S0/16!\n",
279 isic_detach_common(dev);
283 if((b2 != 0x1e) && (b2 != 0x1f))
285 printf("isic%d: Error, signature 3 0x%x != 0x1e or 0x1f for Teles S0/16!\n",
287 isic_detach_common(dev);
293 if(!(sc->sc_resources.irq =
294 bus_alloc_resource_any(dev, SYS_RES_IRQ,
295 &sc->sc_resources.irq_rid,
298 printf("isic%d: Could not allocate irq for Teles S0/16.\n", unit);
299 isic_detach_common(dev);
303 /* register interrupt routine */
305 if (bus_setup_intr(dev, sc->sc_resources.irq, INTR_TYPE_NET, NULL,
306 (void(*)(void *))(isicintr), sc, &ih) != 0)
308 printf("isic%d: Could not setup irq for Teles S0/16.\n", unit);
309 isic_detach_common(dev);
313 /* get the irq number */
315 sc->sc_irq = rman_get_start(sc->sc_resources.irq);
317 /* check IRQ validity */
319 if((intr_no[sc->sc_irq]) == 1)
321 printf("isic%d: Error, invalid IRQ [%d] specified for Teles S0/16!\n",
323 isic_detach_common(dev);
330 /*---------------------------------------------------------------------------*
331 * isic_attach_s016 - attach Teles S0/16 and compatibles
332 *---------------------------------------------------------------------------*/
334 isic_attach_s016(device_t dev)
336 struct l1_softc *sc = &l1_sc[device_get_unit(dev)];
339 bus_space_tag_t ta = rman_get_bustag(sc->sc_resources.mem);
340 bus_space_handle_t ha = rman_get_bushandle(sc->sc_resources.mem);
341 bus_space_tag_t tb = rman_get_bustag(sc->sc_resources.io_base[0]);
342 bus_space_handle_t hb = rman_get_bushandle(sc->sc_resources.io_base[0]);
344 /* is this right for FreeBSD or off by one ? */
345 irq = intr_no[sc->sc_irq];
349 irq |= ((u_long) sc->sc_vmem_addr) >> 9;
351 DELAY(SEC_DELAY / 10);
352 bus_space_write_1(tb, hb, 4, irq);
354 DELAY(SEC_DELAY / 10);
355 bus_space_write_1(tb, hb, 4, irq | 0x01);
357 DELAY(SEC_DELAY / 5);
359 /* set card bit off */
361 bus_space_write_1(ta, ha, 0x80, 0);
362 DELAY(SEC_DELAY / 5);
364 /* set card bit on */
366 bus_space_write_1(ta, ha, 0x80, 1);
367 DELAY(SEC_DELAY / 5);
372 #endif /* defined(TEL_S0_16) */