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