1 /*
2 * Copyright (c) 1997 Andrew Gordon. All rights reserved.
3 *
4 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
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.
20 *
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
31 * SUCH DAMAGE.
32 *
33 *---------------------------------------------------------------------------
34 *
35 * isic - I4B Siemens ISDN Chipset Driver for Teles S0 PnP
36 * =======================================================
37 *
38 * EXPERIMENTAL !!!
39 * ================
40 *
41 * $Id: isic_isapnp_tel_s0P.c,v 1.4 2002/03/24 20:35:53 martin Exp $
42 *
43 * last edit-date: [Fri Jan 5 11:38:29 2001]
44 *
45 *---------------------------------------------------------------------------*/
46
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: isic_isapnp_tel_s0P.c,v 1.4 2002/03/24 20:35:53 martin Exp $");
49
50 #include "opt_isicpnp.h"
51 #ifdef ISICPNP_TEL_S0_16_3_P
52
53 #include <sys/param.h>
54 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
55 #include <sys/ioccom.h>
56 #else
57 #include <sys/ioctl.h>
58 #endif
59 #include <sys/kernel.h>
60 #include <sys/systm.h>
61 #include <sys/mbuf.h>
62
63 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
64 #include <sys/callout.h>
65 #endif
66
67 #ifdef __FreeBSD__
68 #include <machine/clock.h>
69 #include <i386/isa/isa_device.h>
70 #else
71 #include <machine/bus.h>
72 #include <sys/device.h>
73 #endif
74
75 #include <sys/socket.h>
76 #include <net/if.h>
77
78 #ifdef __FreeBSD__
79 #include <machine/i4b_debug.h>
80 #include <machine/i4b_ioctl.h>
81 #else
82 #include <netisdn/i4b_global.h>
83 #include <netisdn/i4b_debug.h>
84 #include <netisdn/i4b_ioctl.h>
85 #include <netisdn/i4b_l2.h>
86 #include <netisdn/i4b_l1l2.h>
87 #endif
88
89 #include <dev/ic/isic_l1.h>
90 #include <dev/ic/isac.h>
91 #include <dev/ic/hscx.h>
92
93 #include <netisdn/i4b_global.h>
94 #include <netisdn/i4b_l1l2.h>
95 #include <netisdn/i4b_mbuf.h>
96
97 #ifndef __FreeBSD__
98 static u_int8_t tels0163P_read_reg __P((struct isic_softc *sc, int what, bus_size_t offs));
99 static void tels0163P_write_reg __P((struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data));
100 static void tels0163P_read_fifo __P((struct isic_softc *sc, int what, void *buf, size_t size));
101 static void tels0163P_write_fifo __P((struct isic_softc *sc, int what, const void *data, size_t size));
102 void isic_attach_s0163P __P((struct isic_softc *sc));
103 #endif
104
105
106 /*---------------------------------------------------------------------------*
107 * Teles S0/16.3 PnP read fifo routine
108 *---------------------------------------------------------------------------*/
109 #ifdef __FreeBSD__
110
111 static void
112 tels0163P_read_fifo(void *buf, const void *base, size_t len)
113 {
114 insb((int)base + 0x3e, (u_char *)buf, (u_int)len);
115 }
116
117 #else
118
119 static void
120 tels0163P_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size)
121 {
122 bus_space_tag_t t = sc->sc_maps[what+1].t;
123 bus_space_handle_t h = sc->sc_maps[what+1].h;
124 bus_size_t o = sc->sc_maps[what+1].offset;
125 bus_space_read_multi_1(t, h, o + 0x3e, buf, size);
126 }
127
128 #endif
129
130 /*---------------------------------------------------------------------------*
131 * Teles S0/16.3 PnP write fifo routine
132 *---------------------------------------------------------------------------*/
133 #ifdef __FreeBSD__
134
135 static void
136 tels0163P_write_fifo(void *base, const void *buf, size_t len)
137 {
138 outsb((int)base + 0x3e, (u_char *)buf, (u_int)len);
139 }
140
141 #else
142
143 static void
144 tels0163P_write_fifo(struct isic_softc *sc, int what, const void *buf, size_t size)
145 {
146 bus_space_tag_t t = sc->sc_maps[what+1].t;
147 bus_space_handle_t h = sc->sc_maps[what+1].h;
148 bus_size_t o = sc->sc_maps[what+1].offset;
149 bus_space_write_multi_1(t, h, o + 0x3e, (u_int8_t*)buf, size);
150 }
151 #endif
152
153 /*---------------------------------------------------------------------------*
154 * Teles S0/16.3 PnP write register routine
155 *---------------------------------------------------------------------------*/
156 #ifdef __FreeBSD__
157
158 static void
159 tels0163P_write_reg(u_char *base, u_int offset, u_int v)
160 {
161 outb((int)base + offset, (u_char)v);
162 }
163
164 #else
165
166 static void
167 tels0163P_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data)
168 {
169 bus_space_tag_t t = sc->sc_maps[what+1].t;
170 bus_space_handle_t h = sc->sc_maps[what+1].h;
171 bus_size_t o = sc->sc_maps[what+1].offset;
172 bus_space_write_1(t, h, o + offs, data);
173 }
174 #endif
175
176 /*---------------------------------------------------------------------------*
177 * Teles S0/16.3 PnP read register routine
178 *---------------------------------------------------------------------------*/
179 #ifdef __FreeBSD__
180
181 static u_char
182 tels0163P_read_reg(u_char *base, u_int offset)
183 {
184 return (inb((int)base + offset));
185 }
186
187 #else
188
189 static u_int8_t
190 tels0163P_read_reg(struct isic_softc *sc, int what, bus_size_t offs)
191 {
192 bus_space_tag_t t = sc->sc_maps[what+1].t;
193 bus_space_handle_t h = sc->sc_maps[what+1].h;
194 bus_size_t o = sc->sc_maps[what+1].offset;
195 return bus_space_read_1(t, h, o + offs);
196 }
197 #endif
198
199 /*---------------------------------------------------------------------------*
200 * isic_probe_s0163P - probe for Teles S0/16.3 PnP and compatibles
201 *---------------------------------------------------------------------------*/
202 #ifdef __FreeBSD__
203 int
204 isic_probe_s0163P(struct isa_device *dev, unsigned int iobase2)
205 {
206 struct isic_softc *sc = &l1_sc[dev->id_unit];
207
208 /* check max unit range */
209
210 if(dev->id_unit >= ISIC_MAXUNIT)
211 {
212 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Teles S0/16.3 PnP!\n",
213 dev->id_unit, dev->id_unit);
214 return(0);
215 }
216 sc->sc_unit = dev->id_unit;
217
218 /* check IRQ validity */
219
220 switch(ffs(dev->id_irq) - 1)
221 {
222 case 3:
223 case 5:
224 case 7:
225 case 10:
226 case 11:
227 case 12:
228 break;
229
230 default:
231 printf("isic%d: Error, invalid IRQ [%d] specified for Teles S0/16.3 PnP!\n",
232 dev->id_unit, ffs(dev->id_irq)-1);
233 return(0);
234 break;
235 }
236 sc->sc_irq = dev->id_irq;
237
238 /* check if memory addr specified */
239
240 if(dev->id_maddr)
241 {
242 printf("isic%d: Error, mem addr 0x%lx specified for Teles S0/16.3 PnP!\n",
243 dev->id_unit, (u_long)dev->id_maddr);
244 return(0);
245 }
246 dev->id_msize = 0;
247
248 /* check if we got an iobase */
249
250 switch(dev->id_iobase)
251 {
252 case 0x580:
253 case 0x500:
254 case 0x680:
255 break;
256
257 default:
258 printf("isic%d: Error, invalid iobase 0x%x specified for Teles S0/16.3 PnP!\n",
259 dev->id_unit, dev->id_iobase);
260 return(0);
261 break;
262 }
263 sc->sc_port = dev->id_iobase;
264
265 /* setup access routines */
266
267 sc->clearirq = NULL;
268 sc->readreg = tels0163P_read_reg;
269 sc->writereg = tels0163P_write_reg;
270
271 sc->readfifo = tels0163P_read_fifo;
272 sc->writefifo = tels0163P_write_fifo;
273
274 /* setup card type */
275
276 sc->sc_cardtyp = CARD_TYPEP_163P;
277
278 /* setup IOM bus type */
279
280 sc->sc_bustyp = BUS_TYPE_IOM2;
281
282 sc->sc_ipac = 0;
283 sc->sc_bfifolen = HSCX_FIFO_LEN;
284
285 /* setup ISAC and HSCX base addr */
286
287 switch(dev->id_iobase)
288 {
289 case 0x580:
290 ISAC_BASE = (caddr_t) 0x580 - 0x20;
291 HSCX_A_BASE = (caddr_t) 0x180 - 0x20;
292 HSCX_B_BASE = (caddr_t) 0x180;
293 break;
294
295 case 0x500:
296 ISAC_BASE = (caddr_t) 0x500 - 0x20;
297 HSCX_A_BASE = (caddr_t) 0x100 - 0x20;
298 HSCX_B_BASE = (caddr_t) 0x100;
299 break;
300
301 case 0x680:
302 ISAC_BASE = (caddr_t) 0x680 - 0x20;
303 HSCX_A_BASE = (caddr_t) 0x280 - 0x20;
304 HSCX_B_BASE = (caddr_t) 0x280;
305 break;
306 }
307
308 /*
309 * Read HSCX A/B VSTR. Expected value for the S0/16.3 PnP card is
310 * 0x05 in the least significant bits.
311 */
312
313 if( ((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) ||
314 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) )
315 {
316 printf("isic%d: HSCX VSTR test failed for Teles S0/16.3 PnP\n",
317 dev->id_unit);
318 printf("isic%d: HSC0: VSTR: %#x\n",
319 dev->id_unit, HSCX_READ(0, H_VSTR));
320 printf("isic%d: HSC1: VSTR: %#x\n",
321 dev->id_unit, HSCX_READ(1, H_VSTR));
322 return (0);
323 }
324
325 return (1);
326 }
327 #endif
328
329 /*---------------------------------------------------------------------------*
330 * isic_attach_s0163P - attach Teles S0/16.3 PnP and compatibles
331 *---------------------------------------------------------------------------*/
332 #ifdef __FreeBSD__
333 int
334 isic_attach_s0163P(struct isa_device *dev, unsigned int iobase2)
335 {
336 outb((dev->id_iobase) + 0x1c, 0);
337 DELAY(SEC_DELAY / 10);
338 outb((dev->id_iobase) + 0x1c, 1);
339 DELAY(SEC_DELAY / 10);
340 return(1);
341 }
342
343 #else
344
345 void
346 isic_attach_s0163P(struct isic_softc *sc)
347 {
348 /* init card */
349 bus_space_tag_t t = sc->sc_maps[0].t;
350 bus_space_handle_t h = sc->sc_maps[0].h;
351 bus_space_write_1(t, h, 0x1c, 0);
352 DELAY(SEC_DELAY / 10);
353 bus_space_write_1(t, h, 0x1c, 1);
354 DELAY(SEC_DELAY / 10);
355
356 /* setup access routines */
357
358 sc->clearirq = NULL;
359 sc->readreg = tels0163P_read_reg;
360 sc->writereg = tels0163P_write_reg;
361
362 sc->readfifo = tels0163P_read_fifo;
363 sc->writefifo = tels0163P_write_fifo;
364
365 /* setup card type */
366
367 sc->sc_cardtyp = CARD_TYPEP_163P;
368
369 /* setup IOM bus type */
370
371 sc->sc_bustyp = BUS_TYPE_IOM2;
372
373 sc->sc_ipac = 0;
374 sc->sc_bfifolen = HSCX_FIFO_LEN;
375 }
376 #endif
377
378 #endif /* ISICPNP_TEL_S0_16_3_P */
379
Cache object: 54f16e31c090210f21fec4bfa3d77977
|