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