]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/i4b/layer1/isic/i4b_isic_pnp.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / 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  *
38  *      i4b_isic_pnp.c - i4b pnp support
39  *      --------------------------------
40  *      last edit-date: [Fri Jan 26 14:01:04 2001]
41  *
42  *---------------------------------------------------------------------------*/
43
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
46
47 #include "opt_i4b.h"
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/module.h>
53 #include <sys/socket.h>
54 #include <net/if.h>
55
56 #include <i4b/include/i4b_ioctl.h>
57 #include <i4b/layer1/isic/i4b_isic.h>
58
59 #include <isa/isavar.h>
60
61 #define VID_TEL163PNP           0x10212750      /* Teles 16.3 PnP       */
62 #define VID_CREATIXPP           0x0000980e      /* Creatix S0/16 P+P    */
63 #define VID_DYNALINK            0x88167506      /* Dynalink             */
64 #define VID_SEDLBAUER           0x0100274c      /* Sedlbauer WinSpeed   */
65 #define VID_NICCYGO             0x5001814c      /* Neuhaus Niccy GO@    */
66 #define VID_ELSAQS1P            0x33019315      /* ELSA Quickstep1000pro*/
67 #define VID_ITK0025             0x25008b26      /* ITK Ix1 Micro V3     */
68 #define VID_AVMPNP              0x0009cd06      /* AVM Fritz! PnP       */
69 #define VID_SIESURF2            0x2000254d      /* Siemens I-Surf 2.0 PnP*/
70 #define VID_ASUSCOM_IPAC        0x90167506      /* Asuscom (with IPAC)  */      
71 #define VID_EICON_DIVA_20       0x7100891c      /* Eicon DIVA 2.0 ISAC/HSCX */
72 #define VID_EICON_DIVA_202      0xa100891c      /* Eicon DIVA 2.02 IPAC */
73 #define VID_COMPAQ_M610         0x0210110e      /* Compaq Microcom 610  */
74
75 static struct isic_pnp_ids {
76         u_long vend_id;
77         char *id_str;
78 } isic_pnp_ids[] = {
79 #if defined(TEL_S0_16_3_P) || defined(CRTX_S0_P) || defined(COMPAQ_M610)
80         { VID_TEL163PNP,        "Teles S0/16.3 PnP"             },
81         { VID_CREATIXPP,        "Creatix S0/16 PnP"             },
82         { VID_COMPAQ_M610,      "Compaq Microcom 610"           },
83 #endif
84 #ifdef DYNALINK
85         { VID_DYNALINK,         "Dynalink IS64PH"               },
86 #endif
87 #ifdef SEDLBAUER
88         { VID_SEDLBAUER,        "Sedlbauer WinSpeed"            },
89 #endif
90 #ifdef DRN_NGO
91         { VID_NICCYGO,          "Dr.Neuhaus Niccy Go@"          },
92 #endif
93 #ifdef ELSA_QS1ISA
94         { VID_ELSAQS1P,         "ELSA QuickStep 1000pro"        },      
95 #endif
96 #ifdef ITKIX1
97         { VID_ITK0025,          "ITK ix1 Micro V3.0"            },
98 #endif
99 #ifdef AVM_PNP
100         { VID_AVMPNP,           "AVM Fritz!Card PnP"            },      
101 #endif
102 #ifdef SIEMENS_ISURF2
103         { VID_SIESURF2,         "Siemens I-Surf 2.0 PnP"        },
104 #endif
105 #ifdef ASUSCOM_IPAC
106         { VID_ASUSCOM_IPAC,     "Asuscom ISDNLink 128 PnP"      },
107 #endif
108 #ifdef EICON_DIVA
109         { VID_EICON_DIVA_20,    "Eicon.Diehl DIVA 2.0 ISA PnP"  },
110         { VID_EICON_DIVA_202,   "Eicon.Diehl DIVA 2.02 ISA PnP" },
111 #endif
112         { 0, 0 }
113 };
114
115 static int isic_pnp_probe(device_t dev);
116 static int isic_pnp_attach(device_t dev);
117
118 static device_method_t isic_pnp_methods[] = {
119         DEVMETHOD(device_probe,         isic_pnp_probe),
120         DEVMETHOD(device_attach,        isic_pnp_attach),
121         { 0, 0 }
122 };
123                                 
124 static driver_t isic_pnp_driver = {
125         "isic",
126         isic_pnp_methods,
127         0,
128 };
129
130 static devclass_t isic_devclass;
131
132 DRIVER_MODULE(isicpnp, isa, isic_pnp_driver, isic_devclass, 0, 0);
133
134 /*---------------------------------------------------------------------------*
135  *      probe for ISA PnP cards
136  *---------------------------------------------------------------------------*/
137 static int
138 isic_pnp_probe(device_t dev)
139 {
140         struct isic_pnp_ids *ids;                       /* pnp id's */
141         char *string = NULL;                            /* the name */
142         u_int32_t vend_id = isa_get_vendorid(dev);      /* vendor id */
143
144         /* search table of knowd id's */
145         
146         for(ids = isic_pnp_ids; ids->vend_id != 0; ids++)
147         {
148                 if(vend_id == ids->vend_id)
149                 {
150                         string = ids->id_str;
151                         break;
152                 }
153         }
154         
155         if(string)              /* set name if we have one */
156         {
157                 device_set_desc(dev, string);   /* set description */
158                 return 0;
159         }
160         else
161         {
162                 return ENXIO;
163         }
164 }
165
166 /*---------------------------------------------------------------------------*
167  *      attach for ISA PnP cards
168  *---------------------------------------------------------------------------*/
169 static int
170 isic_pnp_attach(device_t dev)
171 {
172         u_int32_t vend_id = isa_get_vendorid(dev);      /* vendor id */
173         unsigned int unit = device_get_unit(dev);       /* get unit */
174         const char *name = device_get_desc(dev);        /* get description */
175         struct l1_softc *sc = 0;                        /* softc */
176         void *ih = 0;                                   /* a dummy */
177         int ret;
178  
179         /* see if we are out of bounds */
180         
181         if(unit >= ISIC_MAXUNIT)
182         {
183                 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for %s\n", unit, unit, name);
184                 return ENXIO;
185         }
186
187         /* get information structure for this unit */
188
189         sc = &l1_sc[unit];
190
191         /* get io_base */
192         if(!(sc->sc_resources.io_base[0] =
193                         bus_alloc_resource_any(dev, SYS_RES_IOPORT,
194                                                &sc->sc_resources.io_rid[0],
195                                                RF_ACTIVE ) ))
196         {
197                 printf("isic_pnp_attach: Couldn't get my io_base.\n");
198                 return ENXIO;                                       
199         }
200         
201         /* will not be used for pnp devices */
202
203         sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
204
205         /* get irq, release io_base if we don't get it */
206
207         if(!(sc->sc_resources.irq =
208                         bus_alloc_resource_any(dev, SYS_RES_IRQ,
209                                                &sc->sc_resources.irq_rid,
210                                                RF_ACTIVE)))
211         {
212                 printf("isic%d: Could not get irq.\n",unit);
213                 isic_detach_common(dev);
214                 return ENXIO;                                       
215         }
216         
217         /* not needed */
218         sc->sc_irq = rman_get_start(sc->sc_resources.irq);
219
220
221         /* set flag so we know what this card is */
222
223         ret = ENXIO;
224         
225         switch(vend_id)
226         {
227 #if defined(TEL_S0_16_3_P) || defined(CRTX_S0_P) || defined(COMPAQ_M610)
228                 case VID_TEL163PNP:
229                         sc->sc_cardtyp = CARD_TYPEP_163P;
230                         ret = isic_attach_Cs0P(dev);
231                         break;
232
233                 case VID_CREATIXPP:
234                         sc->sc_cardtyp = CARD_TYPEP_CS0P;
235                         ret = isic_attach_Cs0P(dev);
236                         break;
237
238                 case VID_COMPAQ_M610:
239                         sc->sc_cardtyp = CARD_TYPEP_COMPAQ_M610;
240                         ret = isic_attach_Cs0P(dev);
241                         break;
242 #endif
243 #ifdef DYNALINK
244                 case VID_DYNALINK:
245                         sc->sc_cardtyp = CARD_TYPEP_DYNALINK;
246                         ret = isic_attach_Dyn(dev);
247                         break;
248 #endif
249 #ifdef SEDLBAUER
250                 case VID_SEDLBAUER:
251                         sc->sc_cardtyp = CARD_TYPEP_SWS;
252                         ret = isic_attach_sws(dev);
253                         break;
254 #endif
255 #ifdef DRN_NGO
256                 case VID_NICCYGO:
257                         sc->sc_cardtyp = CARD_TYPEP_DRNNGO;
258                         ret = isic_attach_drnngo(dev);
259                         break;
260 #endif
261 #ifdef ELSA_QS1ISA
262                 case VID_ELSAQS1P:
263                         sc->sc_cardtyp = CARD_TYPEP_ELSAQS1ISA;
264                         ret = isic_attach_Eqs1pi(dev);
265                         break;
266 #endif
267 #ifdef ITKIX1
268                 case VID_ITK0025:
269                         sc->sc_cardtyp = CARD_TYPEP_ITKIX1;
270                         ret = isic_attach_itkix1(dev);
271                         break;
272 #endif                  
273 #ifdef SIEMENS_ISURF2
274                 case VID_SIESURF2:
275                         sc->sc_cardtyp = CARD_TYPEP_SIE_ISURF2;
276                         ret = isic_attach_siemens_isurf(dev);
277                         break;
278 #endif
279 #ifdef ASUSCOM_IPAC
280                 case VID_ASUSCOM_IPAC:
281                         sc->sc_cardtyp = CARD_TYPEP_ASUSCOMIPAC;
282                         ret = isic_attach_asi(dev);
283                         break;
284 #endif
285 #ifdef EICON_DIVA
286                 case VID_EICON_DIVA_20:
287                         sc->sc_cardtyp = CARD_TYPEP_DIVA_ISA;
288                         ret = isic_attach_diva(dev);
289                         break;
290                 
291                 case VID_EICON_DIVA_202:
292                         sc->sc_cardtyp = CARD_TYPEP_DIVA_ISA;
293                         ret = isic_attach_diva_ipac(dev);
294                         break;
295 #endif
296                 default:
297                         printf("isic%d: Error, no driver for %s\n", unit, name);
298                         ret = ENXIO;
299                         break;          
300         }
301
302         if(ret)
303         {
304                 isic_detach_common(dev);
305                 return ENXIO;                                       
306         }               
307                 
308         if(isic_attach_common(dev))
309         {
310                 /* unset flag */
311                 sc->sc_cardtyp = CARD_TYPEP_UNK;
312
313                 /* free irq here, it hasn't been attached yet */
314                 bus_release_resource(dev,SYS_RES_IRQ,sc->sc_resources.irq_rid,
315                                         sc->sc_resources.irq);
316                 sc->sc_resources.irq = 0;
317                 isic_detach_common(dev);
318                 return ENXIO;
319         }
320         else
321         {
322                 /* setup intr routine */
323                 if (bus_setup_intr(dev,sc->sc_resources.irq,INTR_TYPE_NET,
324                                 NULL, (void(*)(void*))isicintr, sc,&ih) != 0)
325                 {
326                         printf("isic%d: Could not setup irq.\n",unit);
327                         isic_detach_common(dev);
328                         return ENXIO;
329                 }
330
331                 return 0;
332         }
333 }