1 /*
2 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 *
25 *---------------------------------------------------------------------------
26 *
27 * isic - I4B Siemens ISDN Chipset Driver for Creatix PnP cards
28 * ============================================================
29 *
30 * $Id: isic_isapnp_ctx_s0P.c,v 1.4 2002/03/24 20:35:50 martin Exp $
31 *
32 * last edit-date: [Fri Jan 5 11:38:29 2001]
33 *
34 *---------------------------------------------------------------------------*/
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: isic_isapnp_ctx_s0P.c,v 1.4 2002/03/24 20:35:50 martin Exp $");
38
39 #include "opt_isicpnp.h"
40 #if ISICPNP_CRTX_S0_P
41
42 #include <sys/param.h>
43
44 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
45 #include <sys/ioccom.h>
46 #else
47 #include <sys/ioctl.h>
48 #endif
49
50 #include <sys/kernel.h>
51 #include <sys/systm.h>
52 #include <sys/mbuf.h>
53
54 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
55 #include <sys/callout.h>
56 #endif
57
58 #ifdef __FreeBSD__
59 #include <machine/clock.h>
60 #include <i386/isa/isa_device.h>
61 #else
62 #include <machine/bus.h>
63 #include <sys/device.h>
64 #endif
65
66 #include <sys/socket.h>
67 #include <net/if.h>
68
69 #ifdef __FreeBSD__
70 #include <machine/i4b_debug.h>
71 #include <machine/i4b_ioctl.h>
72 #else
73 #include <netisdn/i4b_debug.h>
74 #include <netisdn/i4b_ioctl.h>
75 #endif
76
77 #include <netisdn/i4b_global.h>
78 #include <netisdn/i4b_l2.h>
79 #include <netisdn/i4b_l1l2.h>
80
81 #include <dev/ic/isic_l1.h>
82 #include <dev/ic/isac.h>
83 #include <dev/ic/hscx.h>
84
85 #include <netisdn/i4b_l1l2.h>
86 #include <netisdn/i4b_mbuf.h>
87
88 #ifndef __FreeBSD__
89 static u_int8_t ctxs0P_read_reg __P((struct isic_softc *sc, int what, bus_size_t offs));
90 static void ctxs0P_write_reg __P((struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data));
91 static void ctxs0P_read_fifo __P((struct isic_softc *sc, int what, void *buf, size_t size));
92 static void ctxs0P_write_fifo __P((struct isic_softc *sc, int what, const void *data, size_t size));
93 void isic_attach_Cs0P(struct isic_softc *sc);
94 #endif
95
96 #ifdef __FreeBSD__
97 #include <i386/isa/pnp.h>
98 extern void isicintr ( int unit );
99 #endif
100
101 /*---------------------------------------------------------------------------*
102 * Creatix ISDN-S0 P&P ISAC get fifo routine
103 *---------------------------------------------------------------------------*/
104 #ifdef __FreeBSD__
105
106 static void
107 ctxs0P_read_fifo(void *buf, const void *base, size_t len)
108 {
109 insb((int)base + 0x3e, (u_char *)buf, (u_int)len);
110 }
111
112 #else
113
114 static void
115 ctxs0P_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size)
116 {
117 bus_space_tag_t t = sc->sc_maps[what+1].t;
118 bus_space_handle_t h = sc->sc_maps[what+1].h;
119 bus_size_t o = sc->sc_maps[what+1].offset;
120 bus_space_read_multi_1(t, h, o + 0x3e, buf, size);
121 }
122
123 #endif
124
125 /*---------------------------------------------------------------------------*
126 * Creatix ISDN-S0 P&P ISAC put fifo routine
127 *---------------------------------------------------------------------------*/
128 #ifdef __FreeBSD__
129
130 static void
131 ctxs0P_write_fifo(void *base, const void *buf, size_t len)
132 {
133 outsb((int)base + 0x3e, (u_char *)buf, (u_int)len);
134 }
135
136 #else
137
138 static void
139 ctxs0P_write_fifo(struct isic_softc *sc, int what, const void *buf, size_t size)
140 {
141 bus_space_tag_t t = sc->sc_maps[what+1].t;
142 bus_space_handle_t h = sc->sc_maps[what+1].h;
143 bus_size_t o = sc->sc_maps[what+1].offset;
144 bus_space_write_multi_1(t, h, o + 0x3e, (u_int8_t*)buf, size);
145 }
146 #endif
147
148 /*---------------------------------------------------------------------------*
149 * Creatix ISDN-S0 P&P ISAC put register routine
150 *---------------------------------------------------------------------------*/
151 #ifdef __FreeBSD__
152
153 static void
154 ctxs0P_write_reg(u_char *base, u_int offset, u_int v)
155 {
156 outb((int)base + offset, (u_char)v);
157 }
158
159 #else
160
161 static void
162 ctxs0P_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data)
163 {
164 bus_space_tag_t t = sc->sc_maps[what+1].t;
165 bus_space_handle_t h = sc->sc_maps[what+1].h;
166 bus_size_t o = sc->sc_maps[what+1].offset;
167 bus_space_write_1(t, h, o + offs, data);
168 }
169 #endif
170
171 /*---------------------------------------------------------------------------*
172 * Creatix ISDN-S0 P&P ISAC get register routine
173 *---------------------------------------------------------------------------*/
174 #ifdef __FreeBSD__
175
176 static u_char
177 ctxs0P_read_reg(u_char *base, u_int offset)
178 {
179 return (inb((int)base + offset));
180 }
181
182 #else
183
184 static u_int8_t
185 ctxs0P_read_reg(struct isic_softc *sc, int what, bus_size_t offs)
186 {
187 bus_space_tag_t t = sc->sc_maps[what+1].t;
188 bus_space_handle_t h = sc->sc_maps[what+1].h;
189 bus_size_t o = sc->sc_maps[what+1].offset;
190 return bus_space_read_1(t, h, o + offs);
191 }
192
193 #endif
194
195 #ifdef __FreeBSD__
196
197 /*---------------------------------------------------------------------------*
198 * isic_probe_Cs0P - probe for Creatix ISDN-S0 P&P and compatibles
199 *---------------------------------------------------------------------------*/
200 int
201 isic_probe_Cs0P(struct isa_device *dev, unsigned int iobase2)
202 {
203 struct isic_softc *sc = &l1_sc[dev->id_unit];
204
205 /* check max unit range */
206
207 if(dev->id_unit >= ISIC_MAXUNIT)
208 {
209 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Creatix ISDN-S0 P&P!\n",
210 dev->id_unit, dev->id_unit);
211 return(0);
212 }
213 sc->sc_unit = dev->id_unit;
214
215 /* check IRQ validity */
216
217 switch(ffs(dev->id_irq) - 1)
218 {
219 case 3:
220 case 5:
221 case 7:
222 case 10:
223 case 11:
224 case 12:
225 break;
226
227 default:
228 printf("isic%d: Error, invalid IRQ [%d] specified for Creatix ISDN-S0 P&P!\n",
229 dev->id_unit, ffs(dev->id_irq)-1);
230 return(0);
231 break;
232 }
233 sc->sc_irq = dev->id_irq;
234
235 /* check if memory addr specified */
236
237 if(dev->id_maddr)
238 {
239 printf("isic%d: Error, mem addr 0x%lx specified for Creatix ISDN-S0 P&P!\n",
240 dev->id_unit, (u_long)dev->id_maddr);
241 return(0);
242 }
243 dev->id_msize = 0;
244
245 if(iobase2 == 0)
246 {
247 printf("isic%d: Error, iobase2 is 0 for Creatix ISDN-S0 P&P!\n",
248 dev->id_unit);
249 return(0);
250 }
251
252 /* check if we got an iobase */
253
254 switch(dev->id_iobase)
255 {
256 case 0x120:
257 case 0x180:
258 /*XXX*/ break;
259
260 default:
261 printf("isic%d: Error, invalid iobase 0x%x specified for Creatix ISDN-S0 P&P!\n",
262 dev->id_unit, dev->id_iobase);
263 return(0);
264 break;
265 }
266 sc->sc_port = dev->id_iobase;
267
268 /* setup access routines */
269
270 sc->clearirq = NULL;
271 sc->readreg = ctxs0P_read_reg;
272 sc->writereg = ctxs0P_write_reg;
273
274 sc->readfifo = ctxs0P_read_fifo;
275 sc->writefifo = ctxs0P_write_fifo;
276
277 /* setup card type */
278
279 sc->sc_cardtyp = CARD_TYPEP_CS0P;
280
281 /* setup IOM bus type */
282
283 sc->sc_bustyp = BUS_TYPE_IOM2;
284
285 sc->sc_ipac = 0;
286 sc->sc_bfifolen = HSCX_FIFO_LEN;
287
288 /* setup ISAC and HSCX base addr */
289
290 ISAC_BASE = (caddr_t) dev->id_iobase - 0x20;
291 HSCX_A_BASE = (caddr_t) iobase2 - 0x20;
292 HSCX_B_BASE = (caddr_t) iobase2;
293
294 /*
295 * Read HSCX A/B VSTR. Expected value for the Creatix PnP card is
296 * 0x05 ( = version 2.1 ) in the least significant bits.
297 */
298
299 if( ((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) ||
300 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) )
301 {
302 printf("isic%d: HSCX VSTR test failed for Creatix PnP\n",
303 dev->id_unit);
304 printf("isic%d: HSC0: VSTR: %#x\n",
305 dev->id_unit, HSCX_READ(0, H_VSTR));
306 printf("isic%d: HSC1: VSTR: %#x\n",
307 dev->id_unit, HSCX_READ(1, H_VSTR));
308 return (0);
309 }
310
311 return (1);
312 }
313
314 /*---------------------------------------------------------------------------*
315 * isic_attach_s0163P - attach Creatix ISDN-S0 P&P
316 *---------------------------------------------------------------------------*/
317 int
318 isic_attach_Cs0P(struct isa_device *dev, unsigned int iobase2)
319 {
320 outb((dev->id_iobase) + 0x1c, 0);
321 DELAY(SEC_DELAY / 10);
322 outb((dev->id_iobase) + 0x1c, 1);
323 DELAY(SEC_DELAY / 10);
324 return(1);
325 }
326
327 #else /* !__FreeBSD__ */
328
329 void
330 isic_attach_Cs0P(struct isic_softc *sc)
331 {
332 /* init card */
333 bus_space_tag_t t = sc->sc_maps[0].t;
334 bus_space_handle_t h = sc->sc_maps[0].h;
335 bus_space_write_1(t, h, 0x1c, 0);
336 DELAY(SEC_DELAY / 10);
337 bus_space_write_1(t, h, 0x1c, 1);
338 DELAY(SEC_DELAY / 10);
339
340 /* setup access routines */
341
342 sc->clearirq = NULL;
343 sc->readreg = ctxs0P_read_reg;
344 sc->writereg = ctxs0P_write_reg;
345
346 sc->readfifo = ctxs0P_read_fifo;
347 sc->writefifo = ctxs0P_write_fifo;
348
349 /* setup card type */
350
351 sc->sc_cardtyp = CARD_TYPEP_CS0P;
352
353 /* setup IOM bus type */
354
355 sc->sc_bustyp = BUS_TYPE_IOM2;
356
357 sc->sc_ipac = 0;
358 sc->sc_bfifolen = HSCX_FIFO_LEN;
359 }
360 #endif
361
362 #endif /* ISICPNP_CRTX_S0_P */
363
Cache object: b044993d0033877fb4c461effa48d664
|