Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / isapnp / isic_isapnp_ctx_s0P.c
blobaca5dbaf62adda42426fd5bdbf7dc198186b25ab
1 /*
2 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
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.
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.
25 *---------------------------------------------------------------------------
27 * isic - I4B Siemens ISDN Chipset Driver for Creatix PnP cards
28 * ============================================================
30 * $Id: isic_isapnp_ctx_s0P.c,v 1.11 2007/10/19 12:00:32 ad Exp $
32 * last edit-date: [Fri Jan 5 11:38:29 2001]
34 *---------------------------------------------------------------------------*/
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: isic_isapnp_ctx_s0P.c,v 1.10 2007/03/04 06:02:13 christos Exp $");
39 #include "opt_isicpnp.h"
40 #if ISICPNP_CRTX_S0_P
42 #include <sys/param.h>
44 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
45 #include <sys/ioccom.h>
46 #else
47 #include <sys/ioctl.h>
48 #endif
50 #include <sys/kernel.h>
51 #include <sys/systm.h>
52 #include <sys/mbuf.h>
54 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
55 #include <sys/callout.h>
56 #endif
58 #ifdef __FreeBSD__
59 #include <machine/clock.h>
60 #include <i386/isa/isa_device.h>
61 #else
62 #include <sys/bus.h>
63 #include <sys/device.h>
64 #endif
66 #include <sys/socket.h>
67 #include <net/if.h>
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
77 #include <netisdn/i4b_global.h>
78 #include <netisdn/i4b_l2.h>
79 #include <netisdn/i4b_l1l2.h>
81 #include <dev/ic/isic_l1.h>
82 #include <dev/ic/isac.h>
83 #include <dev/ic/hscx.h>
85 #include <netisdn/i4b_mbuf.h>
87 #ifndef __FreeBSD__
88 static u_int8_t ctxs0P_read_reg(struct isic_softc *sc, int what, bus_size_t offs);
89 static void ctxs0P_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data);
90 static void ctxs0P_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size);
91 static void ctxs0P_write_fifo(struct isic_softc *sc, int what, const void *data, size_t size);
92 void isic_attach_Cs0P(struct isic_softc *sc);
93 #endif
95 #ifdef __FreeBSD__
96 #include <i386/isa/pnp.h>
97 extern void isicintr ( int unit );
98 #endif
100 /*---------------------------------------------------------------------------*
101 * Creatix ISDN-S0 P&P ISAC get fifo routine
102 *---------------------------------------------------------------------------*/
103 #ifdef __FreeBSD__
105 static void
106 ctxs0P_read_fifo(void *buf, const void *base, size_t len)
108 insb((int)base + 0x3e, (u_char *)buf, (u_int)len);
111 #else
113 static void
114 ctxs0P_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size)
116 bus_space_tag_t t = sc->sc_maps[what+1].t;
117 bus_space_handle_t h = sc->sc_maps[what+1].h;
118 bus_size_t o = sc->sc_maps[what+1].offset;
119 bus_space_read_multi_1(t, h, o + 0x3e, buf, size);
122 #endif
124 /*---------------------------------------------------------------------------*
125 * Creatix ISDN-S0 P&P ISAC put fifo routine
126 *---------------------------------------------------------------------------*/
127 #ifdef __FreeBSD__
129 static void
130 ctxs0P_write_fifo(void *base, const void *buf, size_t len)
132 outsb((int)base + 0x3e, (u_char *)buf, (u_int)len);
135 #else
137 static void
138 ctxs0P_write_fifo(struct isic_softc *sc, int what, const void *buf, size_t size)
140 bus_space_tag_t t = sc->sc_maps[what+1].t;
141 bus_space_handle_t h = sc->sc_maps[what+1].h;
142 bus_size_t o = sc->sc_maps[what+1].offset;
143 bus_space_write_multi_1(t, h, o + 0x3e, buf, size);
145 #endif
147 /*---------------------------------------------------------------------------*
148 * Creatix ISDN-S0 P&P ISAC put register routine
149 *---------------------------------------------------------------------------*/
150 #ifdef __FreeBSD__
152 static void
153 ctxs0P_write_reg(u_char *base, u_int offset, u_int v)
155 outb((int)base + offset, (u_char)v);
158 #else
160 static void
161 ctxs0P_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data)
163 bus_space_tag_t t = sc->sc_maps[what+1].t;
164 bus_space_handle_t h = sc->sc_maps[what+1].h;
165 bus_size_t o = sc->sc_maps[what+1].offset;
166 bus_space_write_1(t, h, o + offs, data);
168 #endif
170 /*---------------------------------------------------------------------------*
171 * Creatix ISDN-S0 P&P ISAC get register routine
172 *---------------------------------------------------------------------------*/
173 #ifdef __FreeBSD__
175 static u_char
176 ctxs0P_read_reg(u_char *base, u_int offset)
178 return (inb((int)base + offset));
181 #else
183 static u_int8_t
184 ctxs0P_read_reg(struct isic_softc *sc, int what, bus_size_t offs)
186 bus_space_tag_t t = sc->sc_maps[what+1].t;
187 bus_space_handle_t h = sc->sc_maps[what+1].h;
188 bus_size_t o = sc->sc_maps[what+1].offset;
189 return bus_space_read_1(t, h, o + offs);
192 #endif
194 #ifdef __FreeBSD__
196 /*---------------------------------------------------------------------------*
197 * isic_probe_Cs0P - probe for Creatix ISDN-S0 P&P and compatibles
198 *---------------------------------------------------------------------------*/
200 isic_probe_Cs0P(struct isa_device *dev, unsigned int iobase2)
202 struct isic_softc *sc = &l1_sc[dev->id_unit];
204 /* check max unit range */
206 if(dev->id_unit >= ISIC_MAXUNIT)
208 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Creatix ISDN-S0 P&P!\n",
209 dev->id_unit, dev->id_unit);
210 return(0);
212 sc->sc_unit = dev->id_unit;
214 /* check IRQ validity */
216 switch(ffs(dev->id_irq) - 1)
218 case 3:
219 case 5:
220 case 7:
221 case 10:
222 case 11:
223 case 12:
224 break;
226 default:
227 printf("isic%d: Error, invalid IRQ [%d] specified for Creatix ISDN-S0 P&P!\n",
228 dev->id_unit, ffs(dev->id_irq)-1);
229 return(0);
230 break;
232 sc->sc_irq = dev->id_irq;
234 /* check if memory addr specified */
236 if(dev->id_maddr)
238 printf("isic%d: Error, mem addr 0x%lx specified for Creatix ISDN-S0 P&P!\n",
239 dev->id_unit, (u_long)dev->id_maddr);
240 return(0);
242 dev->id_msize = 0;
244 if(iobase2 == 0)
246 printf("isic%d: Error, iobase2 is 0 for Creatix ISDN-S0 P&P!\n",
247 dev->id_unit);
248 return(0);
251 /* check if we got an iobase */
253 switch(dev->id_iobase)
255 case 0x120:
256 case 0x180:
257 /*XXX*/ break;
259 default:
260 printf("isic%d: Error, invalid iobase 0x%x specified for Creatix ISDN-S0 P&P!\n",
261 dev->id_unit, dev->id_iobase);
262 return(0);
263 break;
265 sc->sc_port = dev->id_iobase;
267 /* setup access routines */
269 sc->clearirq = NULL;
270 sc->readreg = ctxs0P_read_reg;
271 sc->writereg = ctxs0P_write_reg;
273 sc->readfifo = ctxs0P_read_fifo;
274 sc->writefifo = ctxs0P_write_fifo;
276 /* setup card type */
278 sc->sc_cardtyp = CARD_TYPEP_CS0P;
280 /* setup IOM bus type */
282 sc->sc_bustyp = BUS_TYPE_IOM2;
284 sc->sc_ipac = 0;
285 sc->sc_bfifolen = HSCX_FIFO_LEN;
287 /* setup ISAC and HSCX base addr */
289 ISAC_BASE = (void *) dev->id_iobase - 0x20;
290 HSCX_A_BASE = (void *) iobase2 - 0x20;
291 HSCX_B_BASE = (void *) iobase2;
294 * Read HSCX A/B VSTR. Expected value for the Creatix PnP card is
295 * 0x05 ( = version 2.1 ) in the least significant bits.
298 if( ((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) ||
299 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) )
301 printf("isic%d: HSCX VSTR test failed for Creatix PnP\n",
302 dev->id_unit);
303 printf("isic%d: HSC0: VSTR: %#x\n",
304 dev->id_unit, HSCX_READ(0, H_VSTR));
305 printf("isic%d: HSC1: VSTR: %#x\n",
306 dev->id_unit, HSCX_READ(1, H_VSTR));
307 return (0);
310 return (1);
313 /*---------------------------------------------------------------------------*
314 * isic_attach_s0163P - attach Creatix ISDN-S0 P&P
315 *---------------------------------------------------------------------------*/
317 isic_attach_Cs0P(struct isa_device *dev, unsigned int iobase2)
319 outb((dev->id_iobase) + 0x1c, 0);
320 DELAY(SEC_DELAY / 10);
321 outb((dev->id_iobase) + 0x1c, 1);
322 DELAY(SEC_DELAY / 10);
323 return(1);
326 #else /* !__FreeBSD__ */
328 void
329 isic_attach_Cs0P(struct isic_softc *sc)
331 /* init card */
332 bus_space_tag_t t = sc->sc_maps[0].t;
333 bus_space_handle_t h = sc->sc_maps[0].h;
334 bus_space_write_1(t, h, 0x1c, 0);
335 DELAY(SEC_DELAY / 10);
336 bus_space_write_1(t, h, 0x1c, 1);
337 DELAY(SEC_DELAY / 10);
339 /* setup access routines */
341 sc->clearirq = NULL;
342 sc->readreg = ctxs0P_read_reg;
343 sc->writereg = ctxs0P_write_reg;
345 sc->readfifo = ctxs0P_read_fifo;
346 sc->writefifo = ctxs0P_write_fifo;
348 /* setup card type */
350 sc->sc_cardtyp = CARD_TYPEP_CS0P;
352 /* setup IOM bus type */
354 sc->sc_bustyp = BUS_TYPE_IOM2;
356 sc->sc_ipac = 0;
357 sc->sc_bfifolen = HSCX_FIFO_LEN;
359 #endif
361 #endif /* ISICPNP_CRTX_S0_P */