Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / net / i4b / layer1 / iwic / i4b_iwic_pci.c
1 /*
2  * Copyright (c) 1999, 2000 Dave Boyce. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      i4b_iwic - isdn4bsd Winbond W6692 driver
28  *      ----------------------------------------
29  *
30  * $FreeBSD: src/sys/i4b/layer1/iwic/i4b_iwic_pci.c,v 1.6.2.1 2001/08/10 14:08:40 obrien Exp $
31  * $DragonFly: src/sys/net/i4b/layer1/iwic/i4b_iwic_pci.c,v 1.2 2003/06/17 04:28:40 dillon Exp $
32  *
33  *      last edit-date: [Tue Jan 16 10:53:03 2001]
34  *
35  *---------------------------------------------------------------------------*/
36
37 #include "iwic.h"
38 #include "opt_i4b.h"
39 #include "pci.h"
40
41 #if (NIWIC > 0) && (NPCI > 0)
42
43 #include <sys/param.h>
44 #include <sys/kernel.h>
45 #include <sys/systm.h>
46 #include <sys/socket.h>
47 #include <net/if.h>
48
49
50 #include <machine/bus.h>
51 #include <machine/resource.h>
52 #include <sys/bus.h>
53 #include <sys/rman.h>
54
55 #include <pci/pcireg.h>
56 #include <pci/pcivar.h>
57
58 #include <machine/i4b_ioctl.h>
59 #include <machine/i4b_trace.h>
60
61 #include <i4b/include/i4b_global.h>
62 #include <i4b/include/i4b_l3l4.h>
63
64 #include <i4b/layer1/i4b_l1.h>
65
66 #include <i4b/layer1/iwic/i4b_iwic.h>
67 #include <i4b/layer1/iwic/i4b_w6692.h>
68
69 extern struct i4b_l1mux_func iwic_l1mux_func;
70
71 /* Winbond PCI Configuration Space */
72
73 #define BASEREG0_MAPOFF 0x00
74 #define BASEREG1_MAPOFF 0x04
75
76 #define BADDR0 (PCIR_MAPS + BASEREG0_MAPOFF)
77 #define BADDR1 (PCIR_MAPS + BASEREG1_MAPOFF)
78
79
80 static void iwic_pci_intr(struct iwic_softc *sc);
81 static int iwic_pci_probe(device_t dev);
82 static int iwic_pci_attach(device_t dev);
83
84 static device_method_t iwic_pci_methods[] =
85 {
86         DEVMETHOD(device_probe,         iwic_pci_probe),
87         DEVMETHOD(device_attach,        iwic_pci_attach),
88         { 0, 0 }
89 };
90
91 static driver_t iwic_pci_driver =
92 {
93         "iwic",
94         iwic_pci_methods,
95         0
96 };
97
98 static devclass_t iwic_pci_devclass;
99
100 DRIVER_MODULE(iwic, pci, iwic_pci_driver, iwic_pci_devclass, 0, 0);
101
102 #define IWIC_MAXUNIT 4
103
104 struct iwic_softc iwic_sc[IWIC_MAXUNIT];
105
106 /*---------------------------------------------------------------------------*
107  * PCI ID list for ASUSCOM card got from Asuscom in March 2000:
108  *
109  * Vendor ID: 0675 Device ID: 1702
110  * Vendor ID: 0675 Device ID: 1703
111  * Vendor ID: 0675 Device ID: 1707
112  * Vendor ID: 10CF Device ID: 105E
113  * Vendor ID: 1043 Device ID: 0675 SubVendor: 144F SubDevice ID: 2000
114  * Vendor ID: 1043 Device ID: 0675 SubVendor: 144F SubDevice ID: 1702
115  * Vendor ID: 1043 Device ID: 0675 SubVendor: 144F SubDevice ID: 1707
116  * Vendor ID: 1043 Device ID: 0675 SubVendor: 1043 SubDevice ID: 1702
117  * Vendor ID: 1043 Device ID: 0675 SubVendor: 1043 SubDevice ID: 1707
118  * Vendor ID: 1050 Device ID: 6692 SubVendor: 0675 SubDevice ID: 1702
119  *---------------------------------------------------------------------------*/
120
121 static struct winids {
122         u_int32_t type;
123         int sv; 
124         int sd; 
125         const char *desc;
126 } win_ids[] = {
127  { 0x66921050, -1, -1,          "Generic Winbond W6692 ISDN PCI (0x66921050)"      },
128  { 0x66921050, 0x144F, 0x1707,  "Planet PCI ISDN Adapter (Model IA128P-STDV)"      },
129  { 0x17020675, -1, -1,          "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x17020675)" },
130  { 0x17030675, -1, -1,          "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x17030675)" },
131  { 0x17070675, -1, -1,          "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x17070675)" },
132  { 0x105e10cf, -1, -1,          "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x105e10cf)" },
133  { 0x06751043, 0x144F, 0x2000,  "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
134  { 0x06751043, 0x144F, 0x1702,  "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
135  { 0x06751043, 0x144F, 0x1707,  "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
136  { 0x06751043, 0x1443, 0x1702,  "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
137  { 0x06751043, 0x1443, 0x1707,  "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
138  { 0x06751043, 0x144F, 0x2000,  "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
139  { 0x06751043, 0x144F, 0x2000,  "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
140  { 0x06751043, 0x144F, 0x2000,  "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
141  { 0x00000000, 0, 0, NULL }
142 };
143
144 /*---------------------------------------------------------------------------*
145  *      iwic PCI probe
146  *---------------------------------------------------------------------------*/
147 static int
148 iwic_pci_probe(device_t dev)
149 {
150         u_int32_t type = pci_get_devid(dev);
151         u_int32_t sv = pci_get_subvendor(dev);
152         u_int32_t sd = pci_get_subdevice(dev);
153         
154         struct winids *wip = win_ids;
155
156         while(wip->type)
157         {
158                 if(wip->type == type)
159                 {
160                         if(((wip->sv == -1) && (wip->sd == -1)) ||
161                            ((wip->sv == sv) && (wip->sd == sd)))
162                                 break;
163                 }
164                 ++wip;
165         }
166
167         if(wip->desc)
168         {
169                 if(bootverbose)
170                 {
171                         printf("iwic_pci_probe: vendor = 0x%x, device = 0x%x\n", pci_get_vendor(dev), pci_get_device(dev));
172                         printf("iwic_pci_probe: subvendor = 0x%x, subdevice = 0x%x\n", sv, sd);
173                 }
174                 device_set_desc(dev, wip->desc);
175                 return(0);
176         }
177         else
178         {
179                 return(ENXIO);
180         }
181 }
182
183 /*---------------------------------------------------------------------------*
184  *      PCI attach
185  *---------------------------------------------------------------------------*/
186 static int
187 iwic_pci_attach(device_t dev)
188 {
189         unsigned short iobase;
190         struct iwic_softc *sc;
191         void *ih = 0;
192         int unit = device_get_unit(dev);
193         struct iwic_bchan *bchan;
194         
195         /* check max unit range */
196         
197         if(unit >= IWIC_MAXUNIT)
198         {
199                 printf("iwic%d: Error, unit %d >= IWIC_MAXUNIT!\n", unit, unit);
200                 return(ENXIO);  
201         }       
202
203         sc = iwic_find_sc(unit);        /* get softc */ 
204         
205         sc->sc_unit = unit;
206
207         /* use the i/o mapped base address */
208         
209         sc->sc_resources.io_rid[0] = BADDR1;
210         
211         if(!(sc->sc_resources.io_base[0] =
212                         bus_alloc_resource(dev, SYS_RES_IOPORT,
213                                                 &sc->sc_resources.io_rid[0],
214                                                 0UL, ~0UL, 1, RF_ACTIVE)))
215         {
216                 printf("iwic%d: Couldn't alloc io port!\n", unit);
217                 return(ENXIO);                                       
218         }
219
220         iobase = rman_get_start(sc->sc_resources.io_base[0]);
221
222         if(!(sc->sc_resources.irq =
223                         bus_alloc_resource(dev, SYS_RES_IRQ,
224                                            &sc->sc_resources.irq_rid,
225                                            0UL, ~0UL, 1, RF_SHAREABLE|RF_ACTIVE)))
226         {
227                 printf("iwic%d: Couldn't alloc irq!\n",unit);
228                 return(ENXIO);                                       
229         }
230         
231         /* setup card type */
232         
233         sc->sc_cardtyp = CARD_TYPEP_WINB6692;
234         sc->sc_iobase = (u_int32_t) iobase;
235         sc->sc_trace = TRACE_OFF;
236         sc->sc_I430state = ST_F3N;      /* Deactivated */
237         sc->enabled = FALSE;
238         
239         if(bus_setup_intr(dev, sc->sc_resources.irq, INTR_TYPE_NET,
240                                 (void(*)(void*))iwic_pci_intr,
241                                 sc, &ih))
242         {
243                 printf("iwic%d: Couldn't set up irq!\n", unit);
244                 return(ENXIO);
245         }
246
247         /* disable interrupts */
248         IWIC_WRITE(sc, IMASK, 0xff);
249
250         iwic_dchan_init(sc);
251
252         bchan = &sc->sc_bchan[IWIC_BCH_A];
253         bchan->unit = unit;
254         bchan->offset = B1_CHAN_OFFSET;
255         bchan->channel = IWIC_BCH_A;
256         bchan->state = ST_IDLE;
257                 
258         iwic_bchannel_setup(unit, IWIC_BCH_A, BPROT_NONE, 0);
259
260         bchan = &sc->sc_bchan[IWIC_BCH_B];
261         bchan->unit = unit;
262         bchan->offset = B2_CHAN_OFFSET;
263         bchan->channel = IWIC_BCH_B;
264         bchan->state = ST_IDLE;
265         
266         iwic_bchannel_setup(unit, IWIC_BCH_B, BPROT_NONE, 0);
267
268         iwic_init_linktab(sc);
269         
270         if(bootverbose)
271         {
272                 int ver = IWIC_READ(sc, D_RBCH);
273                 printf("iwic%d: W6692 chip version = %d\n", unit, D_RBCH_VN(ver));
274         }
275
276         i4b_l1_mph_status_ind(L0IWICUNIT(sc->sc_unit), STI_ATTACH, sc->sc_cardtyp, &iwic_l1mux_func);
277
278         IWIC_READ(sc, ISTA);
279
280         /* Enable interrupts */
281         IWIC_WRITE(sc, IMASK, IMASK_XINT0 | IMASK_XINT1);
282
283         return(0);
284 }
285
286 /*---------------------------------------------------------------------------*
287  *      IRQ handler
288  *---------------------------------------------------------------------------*/
289 static void
290 iwic_pci_intr(struct iwic_softc *sc)
291 {
292         while (1)
293         {
294                 int irq_stat = IWIC_READ(sc, ISTA);
295
296                 if (irq_stat == 0)
297                         break;
298
299                 if (irq_stat & (ISTA_D_RME | ISTA_D_RMR | ISTA_D_XFR))
300                 {
301                         iwic_dchan_xfer_irq(sc, irq_stat);
302                 }
303                 if (irq_stat & ISTA_D_EXI)
304                 {
305                         iwic_dchan_xirq(sc);
306                 }
307                 if (irq_stat & ISTA_B1_EXI)
308                 {
309                         iwic_bchan_xirq(sc, 0);
310                 }
311                 if (irq_stat & ISTA_B2_EXI)
312                 {
313                         iwic_bchan_xirq(sc, 1);
314                 }
315         }
316 }
317
318 #endif