5ae4cffe7850d4f1faa5faafa6f60a039b8d9c5d
[dragonfly.git] / sys / net / i4b / layer1 / isic / i4b_isic_pnp.c
1 /*
2  *   Copyright (c) 1998 Eivind Eklund. All rights reserved.
3  *
4  *   Copyright (c) 1998, 1999 German Tischler. All rights reserved.
5  *
6  *   Copyright (c) 1998, 2001 Hellmuth Michaelis. All rights reserved. 
7  *
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  *
12  *   1. Redistributions of source code must retain the above copyright
13  *      notice, this list of conditions and the following disclaimer.
14  *   2. Redistributions in binary form must reproduce the above copyright
15  *      notice, this list of conditions and the following disclaimer in the
16  *      documentation and/or other materials provided with the distribution.
17  *   3. Neither the name of the author nor the names of any co-contributors
18  *      may be used to endorse or promote products derived from this software
19  *      without specific prior written permission.
20  *   4. Altered versions must be plainly marked as such, and must not be
21  *      misrepresented as being the original software and/or documentation.
22  *   
23  *   THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24  *   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  *   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  *   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27  *   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  *   OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  *   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  *   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  *   SUCH DAMAGE.
34  *
35  *---------------------------------------------------------------------------
36  *
37  *      i4b_isic_pnp.c - i4b pnp support
38  *      --------------------------------
39  *
40  * $FreeBSD: src/sys/i4b/layer1/isic/i4b_isic_pnp.c,v 1.5.2.2 2001/12/10 12:18:11 hm Exp $
41  *
42  *      last edit-date: [Fri Jan 26 14:01:04 2001]
43  *
44  *---------------------------------------------------------------------------*/
45
46 #include "use_isic.h"
47 #include "opt_i4b.h"
48
49 #if (NISIC > 0)
50
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
54 #include <sys/socket.h>
55 #include <net/if.h>
56
57 #include <net/i4b/include/machine/i4b_ioctl.h>
58 #include "i4b_isic.h"
59
60 #include <bus/isa/isavar.h>
61
62 #define VID_TEL163PNP           0x10212750      /* Teles 16.3 PnP       */
63 #define VID_CREATIXPP           0x0000980e      /* Creatix S0/16 P+P    */
64 #define VID_DYNALINK            0x88167506      /* Dynalink             */
65 #define VID_SEDLBAUER           0x0100274c      /* Sedlbauer WinSpeed   */
66 #define VID_NICCYGO             0x5001814c      /* Neuhaus Niccy GO@    */
67 #define VID_ELSAQS1P            0x33019315      /* ELSA Quickstep1000pro*/
68 #define VID_ITK0025             0x25008b26      /* ITK Ix1 Micro V3     */
69 #define VID_AVMPNP              0x0009cd06      /* AVM Fritz! PnP       */
70 #define VID_SIESURF2            0x2000254d      /* Siemens I-Surf 2.0 PnP*/
71 #define VID_ASUSCOM_IPAC        0x90167506      /* Asuscom (with IPAC)  */      
72 #define VID_EICON_DIVA_20       0x7100891c      /* Eicon DIVA 2.0 ISAC/HSCX */
73 #define VID_EICON_DIVA_202      0xa100891c      /* Eicon DIVA 2.02 IPAC */
74 #define VID_COMPAQ_M610         0x0210110e      /* Compaq Microcom 610  */
75
76 static struct isic_pnp_ids {
77         u_long vend_id;
78         char *id_str;
79 } isic_pnp_ids[] = {
80 #if defined(TEL_S0_16_3_P) || defined(CRTX_S0_P) || defined(COMPAQ_M610)
81         { VID_TEL163PNP,        "Teles S0/16.3 PnP"             },
82         { VID_CREATIXPP,        "Creatix S0/16 PnP"             },
83         { VID_COMPAQ_M610,      "Compaq Microcom 610"           },
84 #endif
85 #ifdef DYNALINK
86         { VID_DYNALINK,         "Dynalink IS64PH"               },
87 #endif
88 #ifdef SEDLBAUER
89         { VID_SEDLBAUER,        "Sedlbauer WinSpeed"            },
90 #endif
91 #ifdef DRN_NGO
92         { VID_NICCYGO,          "Dr.Neuhaus Niccy Go@"          },
93 #endif
94 #ifdef ELSA_QS1ISA
95         { VID_ELSAQS1P,         "ELSA QuickStep 1000pro"        },      
96 #endif
97 #ifdef ITKIX1
98         { VID_ITK0025,          "ITK ix1 Micro V3.0"            },
99 #endif
100 #ifdef AVM_PNP
101         { VID_AVMPNP,           "AVM Fritz!Card PnP"            },      
102 #endif
103 #ifdef SIEMENS_ISURF2
104         { VID_SIESURF2,         "Siemens I-Surf 2.0 PnP"        },
105 #endif
106 #ifdef ASUSCOM_IPAC
107         { VID_ASUSCOM_IPAC,     "Asuscom ISDNLink 128 PnP"      },
108 #endif
109 #ifdef EICON_DIVA
110         { VID_EICON_DIVA_20,    "Eicon.Diehl DIVA 2.0 ISA PnP"  },
111         { VID_EICON_DIVA_202,   "Eicon.Diehl DIVA 2.02 ISA PnP" },
112 #endif
113         { 0, 0 }
114 };
115
116 static int isic_pnp_probe(device_t dev);
117 static int isic_pnp_attach(device_t dev);
118
119 static device_method_t isic_pnp_methods[] = {
120         DEVMETHOD(device_probe,         isic_pnp_probe),
121         DEVMETHOD(device_attach,        isic_pnp_attach),
122         { 0, 0 }
123 };
124                                 
125 static driver_t isic_pnp_driver = {
126         "isic",
127         isic_pnp_methods,
128         0,
129 };
130
131 static devclass_t isic_devclass;
132
133 DRIVER_MODULE(isicpnp, isa, isic_pnp_driver, isic_devclass, NULL, NULL);
134
135 /*---------------------------------------------------------------------------*
136  *      probe for ISA PnP cards
137  *---------------------------------------------------------------------------*/
138 int
139 isic_pnp_probe(device_t dev)
140 {
141         struct isic_pnp_ids *ids;                       /* pnp id's */
142         char *string = NULL;                            /* the name */
143         u_int32_t vend_id = isa_get_vendorid(dev);      /* vendor id */
144
145         /* search table of knowd id's */
146         
147         for(ids = isic_pnp_ids; ids->vend_id != 0; ids++)
148         {
149                 if(vend_id == ids->vend_id)
150                 {
151                         string = ids->id_str;
152                         break;
153                 }
154         }
155         
156         if(string)              /* set name if we have one */
157         {
158                 device_set_desc(dev, string);   /* set description */
159                 return 0;
160         }
161         else
162         {
163                 return ENXIO;
164         }
165 }
166
167 /*---------------------------------------------------------------------------*
168  *      attach for ISA PnP cards
169  *---------------------------------------------------------------------------*/
170 int
171 isic_pnp_attach(device_t dev)
172 {
173         u_int32_t vend_id = isa_get_vendorid(dev);      /* vendor id */
174         unsigned int unit = device_get_unit(dev);       /* get unit */
175         const char *name = device_get_desc(dev);        /* get description */
176         struct l1_softc *sc = 0;                        /* softc */
177         void *ih = 0;                                   /* a dummy */
178         int ret;
179  
180         /* see if we are out of bounds */
181         
182         if(unit >= ISIC_MAXUNIT)
183         {
184                 kprintf("isic%d: Error, unit %d >= ISIC_MAXUNIT for %s\n", unit, unit, name);
185                 return ENXIO;
186         }
187
188         /* get information structure for this unit */
189
190         sc = &l1_sc[unit];
191
192         /* get io_base */
193         if(!(sc->sc_resources.io_base[0] =
194                         bus_alloc_resource(dev, SYS_RES_IOPORT,
195                                                 &sc->sc_resources.io_rid[0],
196                                                 0UL, ~0UL, 1, RF_ACTIVE ) ))
197         {
198                 kprintf("isic_pnp_attach: Couldn't get my io_base.\n");
199                 return ENXIO;                                       
200         }
201         
202         /* will not be used for pnp devices */
203
204         sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
205
206         /* get irq, release io_base if we don't get it */
207
208         if(!(sc->sc_resources.irq =
209                         bus_alloc_resource(dev, SYS_RES_IRQ,
210                                            &sc->sc_resources.irq_rid,
211                                            0UL, ~0UL, 1, RF_ACTIVE)))
212         {
213                 kprintf("isic%d: Could not get irq.\n",unit);
214                 isic_detach_common(dev);
215                 return ENXIO;                                       
216         }
217         
218         /* not needed */
219         sc->sc_irq = rman_get_start(sc->sc_resources.irq);
220
221
222         /* set flag so we know what this card is */
223
224         ret = ENXIO;
225         
226         switch(vend_id)
227         {
228 #if defined(TEL_S0_16_3_P) || defined(CRTX_S0_P) || defined(COMPAQ_M610)
229                 case VID_TEL163PNP:
230                         sc->sc_cardtyp = CARD_TYPEP_163P;
231                         ret = isic_attach_Cs0P(dev);
232                         break;
233
234                 case VID_CREATIXPP:
235                         sc->sc_cardtyp = CARD_TYPEP_CS0P;
236                         ret = isic_attach_Cs0P(dev);
237                         break;
238
239                 case VID_COMPAQ_M610:
240                         sc->sc_cardtyp = CARD_TYPEP_COMPAQ_M610;
241                         ret = isic_attach_Cs0P(dev);
242                         break;
243 #endif
244 #ifdef DYNALINK
245                 case VID_DYNALINK:
246                         sc->sc_cardtyp = CARD_TYPEP_DYNALINK;
247                         ret = isic_attach_Dyn(dev);
248                         break;
249 #endif
250 #ifdef SEDLBAUER
251                 case VID_SEDLBAUER:
252                         sc->sc_cardtyp = CARD_TYPEP_SWS;
253                         ret = isic_attach_sws(dev);
254                         break;
255 #endif
256 #ifdef DRN_NGO
257                 case VID_NICCYGO:
258                         sc->sc_cardtyp = CARD_TYPEP_DRNNGO;
259                         ret = isic_attach_drnngo(dev);
260                         break;
261 #endif
262 #ifdef ELSA_QS1ISA
263                 case VID_ELSAQS1P:
264                         sc->sc_cardtyp = CARD_TYPEP_ELSAQS1ISA;
265                         ret = isic_attach_Eqs1pi(dev);
266                         break;
267 #endif
268 #ifdef ITKIX1
269                 case VID_ITK0025:
270                         sc->sc_cardtyp = CARD_TYPEP_ITKIX1;
271                         ret = isic_attach_itkix1(dev);
272                         break;
273 #endif                  
274 #ifdef SIEMENS_ISURF2
275                 case VID_SIESURF2:
276                         sc->sc_cardtyp = CARD_TYPEP_SIE_ISURF2;
277                         ret = isic_attach_siemens_isurf(dev);
278                         break;
279 #endif
280 #ifdef ASUSCOM_IPAC
281                 case VID_ASUSCOM_IPAC:
282                         sc->sc_cardtyp = CARD_TYPEP_ASUSCOMIPAC;
283                         ret = isic_attach_asi(dev);
284                         break;
285 #endif
286 #ifdef EICON_DIVA
287                 case VID_EICON_DIVA_20:
288                         sc->sc_cardtyp = CARD_TYPEP_DIVA_ISA;
289                         ret = isic_attach_diva(dev);
290                         break;
291                 
292                 case VID_EICON_DIVA_202:
293                         sc->sc_cardtyp = CARD_TYPEP_DIVA_ISA;
294                         ret = isic_attach_diva_ipac(dev);
295                         break;
296 #endif
297                 default:
298                         kprintf("isic%d: Error, no driver for %s\n", unit, name);
299                         ret = ENXIO;
300                         break;          
301         }
302
303         if(ret)
304         {
305                 isic_detach_common(dev);
306                 return ENXIO;                                       
307         }               
308                 
309         if(isic_attach_common(dev))
310         {
311                 /* unset flag */
312                 sc->sc_cardtyp = CARD_TYPEP_UNK;
313
314                 /* free irq here, it hasn't been attached yet */
315                 bus_release_resource(dev,SYS_RES_IRQ,sc->sc_resources.irq_rid,
316                                         sc->sc_resources.irq);
317                 sc->sc_resources.irq = 0;
318                 isic_detach_common(dev);
319                 return ENXIO;
320         }
321         else
322         {
323                 /* setup intr routine */
324                 bus_setup_intr(dev, sc->sc_resources.irq, 0,
325                                 (void(*)(void*))isicintr,
326                                 sc, &ih, NULL);
327                 return 0;
328         }
329 }
330 #endif /* (NISIC > 0) */