Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / isapnp / isic_isapnp.c
blob1adc35bc42632f1543f02f68575adf99c8d496ed
1 /*-
2 * Copyright (c) 2002 The NetBSD Foundation, Inc.
3 * All rights reserved.
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Martin Husemann <martin@NetBSD.org>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: isic_isapnp.c,v 1.30 2009/05/12 10:07:55 cegger Exp $");
33 #include <sys/param.h>
34 #include <sys/errno.h>
35 #include <sys/syslog.h>
36 #include <sys/device.h>
37 #include <sys/socket.h>
38 #include <net/if.h>
39 #include <sys/systm.h>
40 #include <sys/malloc.h>
42 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
43 #include <sys/callout.h>
44 #endif
46 #include <sys/cpu.h>
47 #include <sys/intr.h>
48 #include <sys/bus.h>
50 #include <dev/isa/isavar.h>
51 #include <dev/isapnp/isapnpreg.h>
52 #include <dev/isapnp/isapnpvar.h>
54 #ifdef __FreeBSD__
55 #include <machine/i4b_ioctl.h>
56 #include <machine/i4b_trace.h>
57 #else
58 #include <netisdn/i4b_debug.h>
59 #include <netisdn/i4b_ioctl.h>
60 #include <netisdn/i4b_trace.h>
61 #include <netisdn/i4b_l2.h>
62 #endif
64 #include <dev/ic/isic_l1.h>
65 #include <dev/ic/ipac.h>
66 #include <dev/ic/isac.h>
67 #include <dev/ic/hscx.h>
69 #include <netisdn/i4b_l1l2.h>
70 #include <netisdn/i4b_global.h>
72 #include "opt_isicpnp.h"
74 extern const struct isdn_layer1_isdnif_driver isic_std_driver;
76 static int isic_isapnp_probe(device_t, cfdata_t, void *);
77 static void isic_isapnp_attach(device_t, device_t, void *);
79 CFATTACH_DECL(isic_isapnp, sizeof(struct isic_softc),
80 isic_isapnp_probe, isic_isapnp_attach, NULL, NULL);
82 typedef void (*allocmaps_func)(struct isapnp_attach_args *ipa, struct isic_softc *sc);
83 typedef void (*attach_func)(struct isic_softc *sc);
85 /* map allocators */
86 #if defined(ISICPNP_ELSA_QS1ISA) || defined(ISICPNP_SEDLBAUER) \
87 || defined(ISICPNP_DYNALINK) || defined(ISICPNP_SIEMENS_ISURF2) \
88 || defined(ISICPNP_ITKIX)
89 static void generic_pnp_mapalloc(struct isapnp_attach_args *ipa, struct isic_softc *sc);
90 #endif
91 #ifdef ISICPNP_DRN_NGO
92 static void ngo_pnp_mapalloc(struct isapnp_attach_args *ipa, struct isic_softc *sc);
93 #endif
94 #if defined(ISICPNP_CRTX_S0_P) || defined(ISICPNP_TEL_S0_16_3_P)
95 static void tls_pnp_mapalloc(struct isapnp_attach_args *ipa, struct isic_softc *sc);
96 #endif
98 /* card attach functions */
99 extern void isic_attach_Cs0P(struct isic_softc *sc);
100 extern void isic_attach_Dyn(struct isic_softc *sc);
101 extern void isic_attach_s0163P(struct isic_softc *sc);
102 extern void isic_attach_drnngo(struct isic_softc *sc);
103 extern void isic_attach_sws(struct isic_softc *sc);
104 extern void isic_attach_Eqs1pi(struct isic_softc *sc);
105 extern void isic_attach_siemens_isurf(struct isic_softc *sc);
106 extern void isic_attach_isapnp_itkix1(struct isic_softc *sc);
108 struct isic_isapnp_card_desc {
109 const char *devlogic; /* ISAPNP logical device ID */
110 const char *name; /* Name of the card */
111 int card_type; /* isic card type identifier */
112 allocmaps_func allocmaps; /* map allocator function */
113 attach_func attach; /* card attach and init function */
115 static const struct isic_isapnp_card_desc
116 isic_isapnp_descriptions[] =
118 #ifdef ISICPNP_CRTX_S0_P
119 { "CTX0000", "Creatix ISDN S0-16 P&P", CARD_TYPEP_CS0P,
120 tls_pnp_mapalloc, isic_attach_Cs0P },
121 #endif
122 #ifdef ISICPNP_TEL_S0_16_3_P
123 { "TAG2110", "Teles S0/PnP", CARD_TYPEP_163P,
124 tls_pnp_mapalloc, isic_attach_s0163P },
125 #endif
126 #ifdef ISICPNP_DRN_NGO
127 { "SDA0150", "Dr. Neuhaus NICCY GO@", CARD_TYPEP_DRNNGO,
128 ngo_pnp_mapalloc, isic_attach_drnngo },
129 #endif
130 #ifdef ISICPNP_ELSA_QS1ISA
131 { "ELS0133", "Elsa QuickStep 1000 (ISA)", CARD_TYPEP_ELSAQS1ISA,
132 generic_pnp_mapalloc, isic_attach_Eqs1pi },
133 #endif
134 #ifdef ISICPNP_SEDLBAUER
135 { "SAG0001", "Sedlbauer WinSpeed", CARD_TYPEP_SWS,
136 generic_pnp_mapalloc, isic_attach_sws },
137 #endif
138 #ifdef ISICPNP_DYNALINK
139 { "ASU1688", "Dynalink IS64PH", CARD_TYPEP_DYNALINK,
140 generic_pnp_mapalloc, isic_attach_Dyn },
141 #endif
142 #ifdef ISICPNP_SIEMENS_ISURF2
143 { "SIE0020", "Siemens I-Surf 2.0 PnP", CARD_TYPEP_SIE_ISURF2,
144 generic_pnp_mapalloc, isic_attach_siemens_isurf },
145 #endif
146 #ifdef ISICPNP_ITKIX
147 { "ITK0025", "ix1-micro 3.0", 0,
148 generic_pnp_mapalloc, isic_attach_isapnp_itkix1 },
149 #endif
151 #define NUM_DESCRIPTIONS (sizeof(isic_isapnp_descriptions)/sizeof(isic_isapnp_descriptions[0]))
154 * Probe card
156 static int
157 isic_isapnp_probe(device_t parent,
158 cfdata_t cf, void *aux)
160 struct isapnp_attach_args *ipa = aux;
161 const struct isic_isapnp_card_desc *desc = isic_isapnp_descriptions;
162 int i;
164 for (i = 0; i < NUM_DESCRIPTIONS; i++, desc++)
165 if (strcmp(ipa->ipa_devlogic, desc->devlogic) == 0)
166 return 1;
168 return 0;
171 /*---------------------------------------------------------------------------*
172 * card independend attach for ISA P&P cards
173 *---------------------------------------------------------------------------*/
175 /* parameter and format for message producing e.g. "isic0: " */
177 #ifdef __FreeBSD__
178 #define ISIC_FMT "isic%d: "
179 #define ISIC_PARM dev->id_unit
180 #define TERMFMT " "
181 #else
182 #define ISIC_FMT "%s: "
183 #define ISIC_PARM device_xname(&sc->sc_dev)
184 #define TERMFMT "\n"
185 #endif
187 static void
188 isic_isapnp_attach(device_t parent,
189 device_t self, void *aux)
191 static const char *ISACversion[] = {
192 "2085 Version A1/A2 or 2086/2186 Version 1.1",
193 "2085 Version B1",
194 "2085 Version B2",
195 "2085 Version V2.3 (B3)",
196 "Unknown Version"
199 static const char *HSCXversion[] = {
200 "82525 Version A1",
201 "Unknown (0x01)",
202 "82525 Version A2",
203 "Unknown (0x03)",
204 "82525 Version A3",
205 "82525 or 21525 Version 2.1",
206 "Unknown Version"
209 struct isic_softc *sc = device_private(self);
210 struct isapnp_attach_args *ipa = aux;
211 const struct isic_isapnp_card_desc *desc = isic_isapnp_descriptions;
212 int i;
214 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
215 aprint_error_dev(&sc->sc_dev, "error in region allocation\n");
216 return;
219 for (i = 0; i < NUM_DESCRIPTIONS; i++, desc++)
220 if (strcmp(ipa->ipa_devlogic, desc->devlogic) == 0)
221 break;
222 if (i >= NUM_DESCRIPTIONS)
223 panic("could not identify isic PnP device");
225 /* setup parameters */
226 sc->sc_cardtyp = desc->card_type;
227 sc->sc_irq = ipa->ipa_irq[0].num;
228 desc->allocmaps(ipa, sc);
230 /* announce card name */
231 printf(": %s\n", desc->name);
233 /* establish interrupt handler */
234 if (isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num, ipa->ipa_irq[0].type,
235 IPL_NET, isicintr, sc) == NULL)
236 aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt handler\n");
238 /* init card */
239 desc->attach(sc);
241 /* announce chip versions */
242 sc->sc_isac_version = 0;
243 sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03;
245 switch(sc->sc_isac_version)
247 case ISAC_VA:
248 case ISAC_VB1:
249 case ISAC_VB2:
250 case ISAC_VB3:
251 break;
253 default:
254 printf(ISIC_FMT "Error, ISAC version %d unknown!\n",
255 ISIC_PARM, sc->sc_isac_version);
256 return;
257 break;
260 sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf;
262 switch(sc->sc_hscx_version)
264 case HSCX_VA1:
265 case HSCX_VA2:
266 case HSCX_VA3:
267 case HSCX_V21:
268 break;
270 default:
271 printf(ISIC_FMT "Error, HSCX version %d unknown!\n",
272 ISIC_PARM, sc->sc_hscx_version);
273 return;
274 break;
277 sc->sc_intr_valid = ISIC_INTR_DISABLED;
279 /* HSCX setup */
281 isic_bchannel_setup(sc, HSCX_CH_A, BPROT_NONE, 0);
283 isic_bchannel_setup(sc, HSCX_CH_B, BPROT_NONE, 0);
285 /* setup linktab */
287 isic_init_linktab(sc);
289 /* set trace level */
291 sc->sc_trace = TRACE_OFF;
293 sc->sc_state = ISAC_IDLE;
295 sc->sc_ibuf = NULL;
296 sc->sc_ib = NULL;
297 sc->sc_ilen = 0;
299 sc->sc_obuf = NULL;
300 sc->sc_op = NULL;
301 sc->sc_ol = 0;
302 sc->sc_freeflag = 0;
304 sc->sc_obuf2 = NULL;
305 sc->sc_freeflag2 = 0;
307 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
308 callout_init(&sc->sc_T3_callout, 0);
309 callout_init(&sc->sc_T4_callout, 0);
310 #endif
312 /* announce chip versions */
314 if(sc->sc_isac_version >= ISAC_UNKN)
316 printf(ISIC_FMT "ISAC Version UNKNOWN (VN=0x%x)" TERMFMT,
317 ISIC_PARM,
318 sc->sc_isac_version);
319 sc->sc_isac_version = ISAC_UNKN;
321 else
323 printf(ISIC_FMT "ISAC %s (IOM-%c)" TERMFMT,
324 ISIC_PARM,
325 ISACversion[sc->sc_isac_version],
326 sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2');
329 if(sc->sc_hscx_version >= HSCX_UNKN)
331 printf(ISIC_FMT "HSCX Version UNKNOWN (VN=0x%x)" TERMFMT,
332 ISIC_PARM,
333 sc->sc_hscx_version);
334 sc->sc_hscx_version = HSCX_UNKN;
336 else
338 printf(ISIC_FMT "HSCX %s" TERMFMT,
339 ISIC_PARM,
340 HSCXversion[sc->sc_hscx_version]);
343 /* init higher protocol layers and save l2 handle */
344 isic_attach_bri(sc, desc->name, &isic_std_driver);
347 #if defined(ISICPNP_ELSA_QS1ISA) || defined(ISICPNP_SEDLBAUER) \
348 || defined(ISICPNP_DYNALINK) || defined(ISICPNP_SIEMENS_ISURF2) \
349 || defined(ISICPNP_ITKIX)
350 static void
351 generic_pnp_mapalloc(struct isapnp_attach_args *ipa, struct isic_softc *sc)
353 sc->sc_num_mappings = 1; /* most cards have just one mapping */
354 MALLOC_MAPS(sc); /* malloc the maps */
355 sc->sc_maps[0].t = ipa->ipa_iot; /* copy the access handles */
356 sc->sc_maps[0].h = ipa->ipa_io[0].h;
357 sc->sc_maps[0].size = 0; /* foreign mapping, leave it alone */
359 #endif
361 #ifdef ISICPNP_DRN_NGO
362 static void
363 ngo_pnp_mapalloc(struct isapnp_attach_args *ipa, struct isic_softc *sc)
365 sc->sc_num_mappings = 2; /* one data, one address mapping */
366 MALLOC_MAPS(sc); /* malloc the maps */
367 sc->sc_maps[0].t = ipa->ipa_iot; /* copy the access handles */
368 sc->sc_maps[0].h = ipa->ipa_io[0].h;
369 sc->sc_maps[0].size = 0; /* foreign mapping, leave it alone */
370 sc->sc_maps[1].t = ipa->ipa_iot;
371 sc->sc_maps[1].h = ipa->ipa_io[1].h;
372 sc->sc_maps[1].size = 0;
374 #endif
376 #if defined(ISICPNP_CRTX_S0_P) || defined(ISICPNP_TEL_S0_16_3_P)
377 static void
378 tls_pnp_mapalloc(struct isapnp_attach_args *ipa, struct isic_softc *sc)
380 sc->sc_num_mappings = 4; /* config, isac, 2 * hscx */
381 MALLOC_MAPS(sc); /* malloc the maps */
382 sc->sc_maps[0].t = ipa->ipa_iot; /* copy the access handles */
383 sc->sc_maps[0].h = ipa->ipa_io[0].h;
384 sc->sc_maps[0].size = 0; /* foreign mapping, leave it alone */
385 sc->sc_maps[1].t = ipa->ipa_iot;
386 sc->sc_maps[1].h = ipa->ipa_io[0].h;
387 sc->sc_maps[1].size = 0;
388 sc->sc_maps[1].offset = - 0x20;
389 sc->sc_maps[2].t = ipa->ipa_iot;
390 sc->sc_maps[2].offset = - 0x20;
391 sc->sc_maps[2].h = ipa->ipa_io[1].h;
392 sc->sc_maps[2].size = 0;
393 sc->sc_maps[3].t = ipa->ipa_iot;
394 sc->sc_maps[3].offset = 0;
395 sc->sc_maps[3].h = ipa->ipa_io[1].h;
396 sc->sc_maps[3].size = 0;
398 #endif