2 * Copyright (c) 2002 The NetBSD Foundation, Inc.
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
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>
39 #include <sys/systm.h>
40 #include <sys/malloc.h>
42 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
43 #include <sys/callout.h>
50 #include <dev/isa/isavar.h>
51 #include <dev/isapnp/isapnpreg.h>
52 #include <dev/isapnp/isapnpvar.h>
55 #include <machine/i4b_ioctl.h>
56 #include <machine/i4b_trace.h>
58 #include <netisdn/i4b_debug.h>
59 #include <netisdn/i4b_ioctl.h>
60 #include <netisdn/i4b_trace.h>
61 #include <netisdn/i4b_l2.h>
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
);
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
);
91 #ifdef ISICPNP_DRN_NGO
92 static void ngo_pnp_mapalloc(struct isapnp_attach_args
*ipa
, struct isic_softc
*sc
);
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
);
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
},
122 #ifdef ISICPNP_TEL_S0_16_3_P
123 { "TAG2110", "Teles S0/PnP", CARD_TYPEP_163P
,
124 tls_pnp_mapalloc
, isic_attach_s0163P
},
126 #ifdef ISICPNP_DRN_NGO
127 { "SDA0150", "Dr. Neuhaus NICCY GO@", CARD_TYPEP_DRNNGO
,
128 ngo_pnp_mapalloc
, isic_attach_drnngo
},
130 #ifdef ISICPNP_ELSA_QS1ISA
131 { "ELS0133", "Elsa QuickStep 1000 (ISA)", CARD_TYPEP_ELSAQS1ISA
,
132 generic_pnp_mapalloc
, isic_attach_Eqs1pi
},
134 #ifdef ISICPNP_SEDLBAUER
135 { "SAG0001", "Sedlbauer WinSpeed", CARD_TYPEP_SWS
,
136 generic_pnp_mapalloc
, isic_attach_sws
},
138 #ifdef ISICPNP_DYNALINK
139 { "ASU1688", "Dynalink IS64PH", CARD_TYPEP_DYNALINK
,
140 generic_pnp_mapalloc
, isic_attach_Dyn
},
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
},
147 { "ITK0025", "ix1-micro 3.0", 0,
148 generic_pnp_mapalloc
, isic_attach_isapnp_itkix1
},
151 #define NUM_DESCRIPTIONS (sizeof(isic_isapnp_descriptions)/sizeof(isic_isapnp_descriptions[0]))
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
;
164 for (i
= 0; i
< NUM_DESCRIPTIONS
; i
++, desc
++)
165 if (strcmp(ipa
->ipa_devlogic
, desc
->devlogic
) == 0)
171 /*---------------------------------------------------------------------------*
172 * card independend attach for ISA P&P cards
173 *---------------------------------------------------------------------------*/
175 /* parameter and format for message producing e.g. "isic0: " */
178 #define ISIC_FMT "isic%d: "
179 #define ISIC_PARM dev->id_unit
182 #define ISIC_FMT "%s: "
183 #define ISIC_PARM device_xname(&sc->sc_dev)
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",
195 "2085 Version V2.3 (B3)",
199 static const char *HSCXversion
[] = {
205 "82525 or 21525 Version 2.1",
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
;
214 if (isapnp_config(ipa
->ipa_iot
, ipa
->ipa_memt
, ipa
)) {
215 aprint_error_dev(&sc
->sc_dev
, "error in region allocation\n");
219 for (i
= 0; i
< NUM_DESCRIPTIONS
; i
++, desc
++)
220 if (strcmp(ipa
->ipa_devlogic
, desc
->devlogic
) == 0)
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");
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
)
254 printf(ISIC_FMT
"Error, ISAC version %d unknown!\n",
255 ISIC_PARM
, sc
->sc_isac_version
);
260 sc
->sc_hscx_version
= HSCX_READ(0, H_VSTR
) & 0xf;
262 switch(sc
->sc_hscx_version
)
271 printf(ISIC_FMT
"Error, HSCX version %d unknown!\n",
272 ISIC_PARM
, sc
->sc_hscx_version
);
277 sc
->sc_intr_valid
= ISIC_INTR_DISABLED
;
281 isic_bchannel_setup(sc
, HSCX_CH_A
, BPROT_NONE
, 0);
283 isic_bchannel_setup(sc
, HSCX_CH_B
, BPROT_NONE
, 0);
287 isic_init_linktab(sc
);
289 /* set trace level */
291 sc
->sc_trace
= TRACE_OFF
;
293 sc
->sc_state
= ISAC_IDLE
;
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);
312 /* announce chip versions */
314 if(sc
->sc_isac_version
>= ISAC_UNKN
)
316 printf(ISIC_FMT
"ISAC Version UNKNOWN (VN=0x%x)" TERMFMT
,
318 sc
->sc_isac_version
);
319 sc
->sc_isac_version
= ISAC_UNKN
;
323 printf(ISIC_FMT
"ISAC %s (IOM-%c)" TERMFMT
,
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
,
333 sc
->sc_hscx_version
);
334 sc
->sc_hscx_version
= HSCX_UNKN
;
338 printf(ISIC_FMT
"HSCX %s" TERMFMT
,
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)
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 */
361 #ifdef ISICPNP_DRN_NGO
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;
376 #if defined(ISICPNP_CRTX_S0_P) || defined(ISICPNP_TEL_S0_16_3_P)
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;