2 * Copyright (c) 1998 Martin Husemann. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 * 4. Altered versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software and/or documentation.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 *---------------------------------------------------------------------------
33 * pcmcia_isic.c - pcmcia bus frontend for i4b_isic driver
34 * -------------------------------------------------------
36 * $Id: pcmcia_isic.c,v 1.4 1999/02/14 09:45:00 hm Exp $
38 * last edit-date: [Sun Feb 14 10:29:29 1999]
40 * -mh original implementation
42 *---------------------------------------------------------------------------*/
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <sys/errno.h>
47 #include <sys/syslog.h>
48 #include <sys/device.h>
49 #include <sys/socket.h>
51 #include <sys/systm.h>
52 #include <sys/malloc.h>
54 #include <machine/cpu.h>
55 #include <machine/intr.h>
56 #include <machine/bus.h>
58 #include <dev/pcmcia/pcmciareg.h>
59 #include <dev/pcmcia/pcmciavar.h>
60 #include <dev/pcmcia/pcmciadevs.h>
63 #include <machine/i4b_ioctl.h>
64 #include <machine/i4b_trace.h>
66 #include <i4b/i4b_ioctl.h>
67 #include <i4b/i4b_trace.h>
70 #include <i4b/layer1/i4b_l1.h>
71 #include <i4b/layer1/i4b_ipac.h>
72 #include <i4b/layer1/i4b_isac.h>
73 #include <i4b/layer1/i4b_hscx.h>
75 #include <i4b/include/i4b_l1l2.h>
76 #include <i4b/include/i4b_global.h>
78 #include <i4b/layer1/pcmcia_isic.h>
80 static int pcmcia_isic_match __P((struct device *, struct cfdata *, void *));
81 static void pcmcia_isic_attach __P((struct device *, struct device *, void *));
82 static const struct isic_pcmcia_card_entry * find_matching_card __P((struct pcmcia_attach_args *pa));
83 static int pcmcia_isicattach __P((struct isic_softc *sc));
85 struct cfattach pcmcia_isic_ca = {
86 sizeof(struct pcmcia_isic_softc), pcmcia_isic_match, pcmcia_isic_attach
89 struct isic_pcmcia_card_entry {
90 int32_t vendor; /* vendor ID */
91 int32_t product; /* product ID */
92 char *cis1_info[4]; /* CIS info to match */
93 char *name; /* name of controller */
94 int function; /* expected PCMCIA function type */
95 int card_type; /* card type found */
96 isic_pcmcia_attach_func attach; /* card initialization */
99 static const struct isic_pcmcia_card_entry card_list[] = {
102 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
103 { "AVM", "ISDN A", NULL, NULL },
104 "AVM Fritz!Card", PCMCIA_FUNCTION_NETWORK,
105 CARD_TYPEP_PCFRITZ, isic_attach_fritzpcmcia },
109 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
110 { "ELSA GmbH, Aachen", "MicroLink ISDN/MC ", NULL, NULL },
111 "ELSA MicroLink ISDN/MC", PCMCIA_FUNCTION_NETWORK,
112 CARD_TYPEP_ELSAMLIMC, isic_attach_elsaisdnmc },
113 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
114 { "ELSA AG, Aachen", "MicroLink ISDN/MC ", NULL, NULL },
115 "ELSA MicroLink ISDN/MC", PCMCIA_FUNCTION_NETWORK,
116 CARD_TYPEP_ELSAMLIMC, isic_attach_elsaisdnmc },
121 { "ELSA", "MicroLink MC all", NULL, NULL },
122 "ELSA MicroLink MCall", PCMCIA_FUNCTION_NETWORK,
123 CARD_TYPEP_ELSAMLMCALL, isic_attach_elsamcall },
127 #define NUM_MATCH_ENTRIES (sizeof(card_list)/sizeof(card_list[0]))
129 static const struct isic_pcmcia_card_entry *
130 find_matching_card(pa)
131 struct pcmcia_attach_args *pa;
135 for (i = 0; i < NUM_MATCH_ENTRIES; i++) {
136 if (card_list[i].vendor != PCMCIA_VENDOR_INVALID && pa->card->manufacturer != card_list[i].vendor)
138 if (card_list[i].product != PCMCIA_PRODUCT_INVALID && pa->card->product != card_list[i].product)
140 if (pa->pf->function != card_list[i].function)
142 for (j = 0; j < 4; j++) {
143 if (card_list[i].cis1_info[j] == NULL)
144 continue; /* wildcard */
145 if (pa->card->cis1_info[j] == NULL)
146 break; /* not available */
147 if (strcmp(pa->card->cis1_info[j], card_list[i].cis1_info[j]) != 0)
148 break; /* mismatch */
153 if (i >= NUM_MATCH_ENTRIES)
156 return &card_list[i];
163 pcmcia_isic_match(parent, match, aux)
164 struct device *parent;
165 struct cfdata *match;
168 struct pcmcia_attach_args *pa = aux;
170 if (!find_matching_card(pa))
180 pcmcia_isic_attach(parent, self, aux)
181 struct device *parent, *self;
184 struct pcmcia_isic_softc *psc = (void*) self;
185 struct isic_softc *sc = &psc->sc_isic;
186 struct pcmcia_attach_args *pa = aux;
187 struct pcmcia_config_entry *cfe;
188 const struct isic_pcmcia_card_entry * cde;
190 /* Which card is it? */
191 cde = find_matching_card(pa);
192 if (cde == NULL) return; /* oops - not found?!? */
195 cfe = pa->pf->cfe_head.sqh_first;
197 /* Enable the card */
198 pcmcia_function_init(pa->pf, cfe);
199 pcmcia_function_enable(pa->pf);
201 if (!cde->attach(psc, cfe, pa))
202 return; /* Ooops ? */
204 sc->sc_unit = sc->sc_dev.dv_unit;
206 /* Announce card name */
207 printf(": %s\n", cde->name);
209 /* MI initilization */
210 pcmcia_isicattach(sc);
212 /* setup interrupt */
213 psc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_NET, isicintr, sc);
216 /*---------------------------------------------------------------------------*
217 * card independend attach for pcmicia cards
218 *---------------------------------------------------------------------------*/
220 /* parameter and format for message producing e.g. "isic0: " */
223 #define ISIC_FMT "isic%d: "
224 #define ISIC_PARM dev->id_unit
227 #define ISIC_FMT "%s: "
228 #define ISIC_PARM sc->sc_dev.dv_xname
233 pcmcia_isicattach(struct isic_softc *sc)
235 static char *ISACversion[] = {
236 "2085 Version A1/A2 or 2086/2186 Version 1.1",
239 "2085 Version V2.3 (B3)",
243 static char *HSCXversion[] = {
249 "82525 or 21525 Version 2.1",
253 isic_sc[sc->sc_unit] = sc;
254 sc->sc_isac_version = 0;
255 sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03;
257 switch(sc->sc_isac_version)
266 printf(ISIC_FMT "Error, ISAC version %d unknown!\n",
267 ISIC_PARM, sc->sc_isac_version);
272 sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf;
274 switch(sc->sc_hscx_version)
283 printf(ISIC_FMT "Error, HSCX version %d unknown!\n",
284 ISIC_PARM, sc->sc_hscx_version);
295 isic_bchannel_setup(sc->sc_unit, HSCX_CH_A, BPROT_NONE, 0);
297 isic_bchannel_setup(sc->sc_unit, HSCX_CH_B, BPROT_NONE, 0);
301 isic_init_linktab(sc);
303 /* set trace level */
305 sc->sc_trace = TRACE_OFF;
307 sc->sc_state = ISAC_IDLE;
319 sc->sc_freeflag2 = 0;
321 /* init higher protocol layers */
323 MPH_Status_Ind(sc->sc_unit, STI_ATTACH, sc->sc_cardtyp);
325 /* announce chip versions */
327 if(sc->sc_isac_version >= ISAC_UNKN)
329 printf(ISIC_FMT "ISAC Version UNKNOWN (VN=0x%x)" TERMFMT,
331 sc->sc_isac_version);
332 sc->sc_isac_version = ISAC_UNKN;
336 printf(ISIC_FMT "ISAC %s (IOM-%c)" TERMFMT,
338 ISACversion[sc->sc_isac_version],
339 sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2');
342 if(sc->sc_hscx_version >= HSCX_UNKN)
344 printf(ISIC_FMT "HSCX Version UNKNOWN (VN=0x%x)" TERMFMT,
346 sc->sc_hscx_version);
347 sc->sc_hscx_version = HSCX_UNKN;
351 printf(ISIC_FMT "HSCX %s" TERMFMT,
353 HSCXversion[sc->sc_hscx_version]);