Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / isapnp / isic_isapnp_tel_s0P.c
blob95d84110bb9a75699b76ba33a479be3fb4f2700a
1 /*
2 * Copyright (c) 1997 Andrew Gordon. All rights reserved.
4 * Copyright (c) 1997, 1999 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
8 * are met:
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
31 * SUCH DAMAGE.
33 *---------------------------------------------------------------------------
35 * isic - I4B Siemens ISDN Chipset Driver for Teles S0 PnP
36 * =======================================================
38 * EXPERIMENTAL !!!
39 * ================
41 * $Id: isic_isapnp_tel_s0P.c,v 1.11 2007/10/19 12:00:32 ad Exp $
43 * last edit-date: [Fri Jan 5 11:38:29 2001]
45 *---------------------------------------------------------------------------*/
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: isic_isapnp_tel_s0P.c,v 1.10 2007/03/04 06:02:14 christos Exp $");
50 #include "opt_isicpnp.h"
51 #ifdef ISICPNP_TEL_S0_16_3_P
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>
63 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
64 #include <sys/callout.h>
65 #endif
67 #ifdef __FreeBSD__
68 #include <machine/clock.h>
69 #include <i386/isa/isa_device.h>
70 #else
71 #include <sys/bus.h>
72 #include <sys/device.h>
73 #endif
75 #include <sys/socket.h>
76 #include <net/if.h>
78 #ifdef __FreeBSD__
79 #include <machine/i4b_debug.h>
80 #include <machine/i4b_ioctl.h>
81 #else
82 #include <netisdn/i4b_debug.h>
83 #include <netisdn/i4b_ioctl.h>
84 #include <netisdn/i4b_l2.h>
85 #endif
87 #include <dev/ic/isic_l1.h>
88 #include <dev/ic/isac.h>
89 #include <dev/ic/hscx.h>
91 #include <netisdn/i4b_global.h>
92 #include <netisdn/i4b_l1l2.h>
93 #include <netisdn/i4b_mbuf.h>
95 #ifndef __FreeBSD__
96 static u_int8_t tels0163P_read_reg(struct isic_softc *sc, int what, bus_size_t offs);
97 static void tels0163P_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data);
98 static void tels0163P_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size);
99 static void tels0163P_write_fifo(struct isic_softc *sc, int what, const void *data, size_t size);
100 void isic_attach_s0163P(struct isic_softc *sc);
101 #endif
104 /*---------------------------------------------------------------------------*
105 * Teles S0/16.3 PnP read fifo routine
106 *---------------------------------------------------------------------------*/
107 #ifdef __FreeBSD__
109 static void
110 tels0163P_read_fifo(void *buf, const void *base, size_t len)
112 insb((int)base + 0x3e, (u_char *)buf, (u_int)len);
115 #else
117 static void
118 tels0163P_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size)
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);
126 #endif
128 /*---------------------------------------------------------------------------*
129 * Teles S0/16.3 PnP write fifo routine
130 *---------------------------------------------------------------------------*/
131 #ifdef __FreeBSD__
133 static void
134 tels0163P_write_fifo(void *base, const void *buf, size_t len)
136 outsb((int)base + 0x3e, (u_char *)buf, (u_int)len);
139 #else
141 static void
142 tels0163P_write_fifo(struct isic_softc *sc, int what, const void *buf, size_t size)
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, buf, size);
149 #endif
151 /*---------------------------------------------------------------------------*
152 * Teles S0/16.3 PnP write register routine
153 *---------------------------------------------------------------------------*/
154 #ifdef __FreeBSD__
156 static void
157 tels0163P_write_reg(u_char *base, u_int offset, u_int v)
159 outb((int)base + offset, (u_char)v);
162 #else
164 static void
165 tels0163P_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data)
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);
172 #endif
174 /*---------------------------------------------------------------------------*
175 * Teles S0/16.3 PnP read register routine
176 *---------------------------------------------------------------------------*/
177 #ifdef __FreeBSD__
179 static u_char
180 tels0163P_read_reg(u_char *base, u_int offset)
182 return (inb((int)base + offset));
185 #else
187 static u_int8_t
188 tels0163P_read_reg(struct isic_softc *sc, int what, bus_size_t offs)
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);
195 #endif
197 /*---------------------------------------------------------------------------*
198 * isic_probe_s0163P - probe for Teles S0/16.3 PnP and compatibles
199 *---------------------------------------------------------------------------*/
200 #ifdef __FreeBSD__
202 isic_probe_s0163P(struct isa_device *dev, unsigned int iobase2)
204 struct isic_softc *sc = &l1_sc[dev->id_unit];
206 /* check max unit range */
208 if(dev->id_unit >= ISIC_MAXUNIT)
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);
214 sc->sc_unit = dev->id_unit;
216 /* check IRQ validity */
218 switch(ffs(dev->id_irq) - 1)
220 case 3:
221 case 5:
222 case 7:
223 case 10:
224 case 11:
225 case 12:
226 break;
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;
234 sc->sc_irq = dev->id_irq;
236 /* check if memory addr specified */
238 if(dev->id_maddr)
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);
244 dev->id_msize = 0;
246 /* check if we got an iobase */
248 switch(dev->id_iobase)
250 case 0x580:
251 case 0x500:
252 case 0x680:
253 break;
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;
261 sc->sc_port = dev->id_iobase;
263 /* setup access routines */
265 sc->clearirq = NULL;
266 sc->readreg = tels0163P_read_reg;
267 sc->writereg = tels0163P_write_reg;
269 sc->readfifo = tels0163P_read_fifo;
270 sc->writefifo = tels0163P_write_fifo;
272 /* setup card type */
274 sc->sc_cardtyp = CARD_TYPEP_163P;
276 /* setup IOM bus type */
278 sc->sc_bustyp = BUS_TYPE_IOM2;
280 sc->sc_ipac = 0;
281 sc->sc_bfifolen = HSCX_FIFO_LEN;
283 /* setup ISAC and HSCX base addr */
285 switch(dev->id_iobase)
287 case 0x580:
288 ISAC_BASE = (void *) 0x580 - 0x20;
289 HSCX_A_BASE = (void *) 0x180 - 0x20;
290 HSCX_B_BASE = (void *) 0x180;
291 break;
293 case 0x500:
294 ISAC_BASE = (void *) 0x500 - 0x20;
295 HSCX_A_BASE = (void *) 0x100 - 0x20;
296 HSCX_B_BASE = (void *) 0x100;
297 break;
299 case 0x680:
300 ISAC_BASE = (void *) 0x680 - 0x20;
301 HSCX_A_BASE = (void *) 0x280 - 0x20;
302 HSCX_B_BASE = (void *) 0x280;
303 break;
307 * Read HSCX A/B VSTR. Expected value for the S0/16.3 PnP card is
308 * 0x05 in the least significant bits.
311 if( ((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) ||
312 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) )
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);
323 return (1);
325 #endif
327 /*---------------------------------------------------------------------------*
328 * isic_attach_s0163P - attach Teles S0/16.3 PnP and compatibles
329 *---------------------------------------------------------------------------*/
330 #ifdef __FreeBSD__
332 isic_attach_s0163P(struct isa_device *dev, unsigned int iobase2)
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);
341 #else
343 void
344 isic_attach_s0163P(struct isic_softc *sc)
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);
354 /* setup access routines */
356 sc->clearirq = NULL;
357 sc->readreg = tels0163P_read_reg;
358 sc->writereg = tels0163P_write_reg;
360 sc->readfifo = tels0163P_read_fifo;
361 sc->writefifo = tels0163P_write_fifo;
363 /* setup card type */
365 sc->sc_cardtyp = CARD_TYPEP_163P;
367 /* setup IOM bus type */
369 sc->sc_bustyp = BUS_TYPE_IOM2;
371 sc->sc_ipac = 0;
372 sc->sc_bfifolen = HSCX_FIFO_LEN;
374 #endif
376 #endif /* ISICPNP_TEL_S0_16_3_P */