2 * Copyright (c) 1999, 2000 Dave Boyce. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
26 /*---------------------------------------------------------------------------
28 * i4b_iwic - isdn4bsd Winbond W6692 driver
29 * ----------------------------------------
30 * last edit-date: [Tue Jan 16 10:53:03 2001]
32 *---------------------------------------------------------------------------*/
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/systm.h>
42 #include <sys/socket.h>
45 #include <machine/bus.h>
46 #include <machine/resource.h>
50 #include <dev/pci/pcireg.h>
51 #include <dev/pci/pcivar.h>
53 #include <i4b/include/i4b_ioctl.h>
54 #include <i4b/include/i4b_trace.h>
56 #include <i4b/include/i4b_global.h>
57 #include <i4b/include/i4b_l3l4.h>
59 #include <i4b/layer1/i4b_l1.h>
61 #include <i4b/layer1/iwic/i4b_iwic.h>
62 #include <i4b/layer1/iwic/i4b_w6692.h>
64 extern struct i4b_l1mux_func iwic_l1mux_func;
66 /* Winbond PCI Configuration Space */
68 #define BADDR0 PCIR_BAR(0)
69 #define BADDR1 PCIR_BAR(1)
72 static void iwic_pci_intr(struct iwic_softc *sc);
73 static int iwic_pci_probe(device_t dev);
74 static int iwic_pci_attach(device_t dev);
76 static device_method_t iwic_pci_methods[] =
78 DEVMETHOD(device_probe, iwic_pci_probe),
79 DEVMETHOD(device_attach, iwic_pci_attach),
83 static driver_t iwic_pci_driver =
90 static devclass_t iwic_pci_devclass;
92 DRIVER_MODULE(iwic, pci, iwic_pci_driver, iwic_pci_devclass, 0, 0);
94 #define IWIC_MAXUNIT 4
96 struct iwic_softc iwic_sc[IWIC_MAXUNIT];
98 /*---------------------------------------------------------------------------*
99 * PCI ID list for ASUSCOM card got from Asuscom in March 2000:
101 * Vendor ID: 0675 Device ID: 1702
102 * Vendor ID: 0675 Device ID: 1703
103 * Vendor ID: 0675 Device ID: 1707
104 * Vendor ID: 10CF Device ID: 105E
105 * Vendor ID: 1043 Device ID: 0675 SubVendor: 144F SubDevice ID: 2000
106 * Vendor ID: 1043 Device ID: 0675 SubVendor: 144F SubDevice ID: 1702
107 * Vendor ID: 1043 Device ID: 0675 SubVendor: 144F SubDevice ID: 1707
108 * Vendor ID: 1043 Device ID: 0675 SubVendor: 1043 SubDevice ID: 1702
109 * Vendor ID: 1043 Device ID: 0675 SubVendor: 1043 SubDevice ID: 1707
110 * Vendor ID: 1050 Device ID: 6692 SubVendor: 0675 SubDevice ID: 1702
111 * Vendor ID: 1043 Device ID: 0675 SubVendor: 0675 SubDevice ID: 1704
112 *---------------------------------------------------------------------------*/
114 static struct winids {
120 { 0x66921050, -1, -1, "Generic Winbond W6692 ISDN PCI (0x66921050)" },
121 { 0x06751043, 0x0675, 0x1704, "Planet PCI ISDN Adapter (IA128P-STD) ASUS-HCF675" },
122 { 0x66921050, 0x144F, 0x1707, "Planet PCI ISDN Adapter (Model IA128P-STDV)" },
123 { 0x17020675, -1, -1, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x17020675)" },
124 { 0x17030675, -1, -1, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x17030675)" },
125 { 0x17070675, -1, -1, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x17070675)" },
126 { 0x105e10cf, -1, -1, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x105e10cf)" },
127 { 0x06751043, 0x144F, 0x2000, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
128 { 0x06751043, 0x144F, 0x1702, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
129 { 0x06751043, 0x144F, 0x1707, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
130 { 0x06751043, 0x1443, 0x1702, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
131 { 0x06751043, 0x1443, 0x1707, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
132 { 0x06751043, 0x144F, 0x2000, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
133 { 0x06751043, 0x144F, 0x2000, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
134 { 0x06751043, 0x144F, 0x2000, "ASUSCOM P-IN100-ST-D (Winbond W6692, 0x06751043)" },
135 { 0x00000000, 0, 0, NULL }
138 /*---------------------------------------------------------------------------*
140 *---------------------------------------------------------------------------*/
142 iwic_pci_probe(device_t dev)
144 u_int32_t type = pci_get_devid(dev);
145 u_int32_t sv = pci_get_subvendor(dev);
146 u_int32_t sd = pci_get_subdevice(dev);
148 struct winids *wip = win_ids;
152 if(wip->type == type)
154 if(((wip->sv == -1) && (wip->sd == -1)) ||
155 ((wip->sv == sv) && (wip->sd == sd)))
165 printf("iwic_pci_probe: vendor = 0x%x, device = 0x%x\n", pci_get_vendor(dev), pci_get_device(dev));
166 printf("iwic_pci_probe: subvendor = 0x%x, subdevice = 0x%x\n", sv, sd);
168 device_set_desc(dev, wip->desc);
177 /*---------------------------------------------------------------------------*
179 *---------------------------------------------------------------------------*/
181 iwic_pci_attach(device_t dev)
183 unsigned short iobase;
184 struct iwic_softc *sc;
186 int unit = device_get_unit(dev);
187 struct iwic_bchan *bchan;
189 /* check max unit range */
191 if(unit >= IWIC_MAXUNIT)
193 printf("iwic%d: Error, unit %d >= IWIC_MAXUNIT!\n", unit, unit);
197 sc = iwic_find_sc(unit); /* get softc */
201 /* use the i/o mapped base address */
203 sc->sc_resources.io_rid[0] = BADDR1;
205 if(!(sc->sc_resources.io_base[0] =
206 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
207 &sc->sc_resources.io_rid[0],
210 printf("iwic%d: Couldn't alloc io port!\n", unit);
214 iobase = rman_get_start(sc->sc_resources.io_base[0]);
216 if(!(sc->sc_resources.irq =
217 bus_alloc_resource_any(dev, SYS_RES_IRQ,
218 &sc->sc_resources.irq_rid,
219 RF_SHAREABLE|RF_ACTIVE)))
221 printf("iwic%d: Couldn't alloc irq!\n",unit);
225 /* setup card type */
227 sc->sc_cardtyp = CARD_TYPEP_WINB6692;
228 sc->sc_iobase = (u_int32_t) iobase;
229 sc->sc_trace = TRACE_OFF;
230 sc->sc_I430state = ST_F3N; /* Deactivated */
233 if(bus_setup_intr(dev, sc->sc_resources.irq, INTR_TYPE_NET,
234 NULL, (void(*)(void*))iwic_pci_intr,
237 printf("iwic%d: Couldn't set up irq!\n", unit);
241 /* disable interrupts */
242 IWIC_WRITE(sc, IMASK, 0xff);
246 bchan = &sc->sc_bchan[IWIC_BCH_A];
248 bchan->offset = B1_CHAN_OFFSET;
249 bchan->channel = IWIC_BCH_A;
250 bchan->state = ST_IDLE;
252 iwic_bchannel_setup(unit, IWIC_BCH_A, BPROT_NONE, 0);
254 bchan = &sc->sc_bchan[IWIC_BCH_B];
256 bchan->offset = B2_CHAN_OFFSET;
257 bchan->channel = IWIC_BCH_B;
258 bchan->state = ST_IDLE;
260 iwic_bchannel_setup(unit, IWIC_BCH_B, BPROT_NONE, 0);
262 iwic_init_linktab(sc);
266 int ver = IWIC_READ(sc, D_RBCH);
267 printf("iwic%d: W6692 chip version = %d\n", unit, D_RBCH_VN(ver));
270 i4b_l1_mph_status_ind(L0IWICUNIT(sc->sc_unit), STI_ATTACH, sc->sc_cardtyp, &iwic_l1mux_func);
274 /* Enable interrupts */
275 IWIC_WRITE(sc, IMASK, IMASK_XINT0 | IMASK_XINT1);
280 /*---------------------------------------------------------------------------*
282 *---------------------------------------------------------------------------*/
284 iwic_pci_intr(struct iwic_softc *sc)
288 int irq_stat = IWIC_READ(sc, ISTA);
293 if (irq_stat & (ISTA_D_RME | ISTA_D_RMR | ISTA_D_XFR))
295 iwic_dchan_xfer_irq(sc, irq_stat);
297 if (irq_stat & ISTA_D_EXI)
301 if (irq_stat & ISTA_B1_EXI)
303 iwic_bchan_xirq(sc, 0);
305 if (irq_stat & ISTA_B2_EXI)
307 iwic_bchan_xirq(sc, 1);