Home | History | Annotate | Line # | Download | only in cardbus
      1  1.46   thorpej /* $NetBSD: if_rtw_cardbus.c,v 1.46 2022/09/25 17:33:19 thorpej Exp $ */
      2   1.1    dyoung 
      3   1.1    dyoung /*-
      4   1.1    dyoung  * Copyright (c) 2004, 2005 David Young.  All rights reserved.
      5   1.1    dyoung  *
      6   1.1    dyoung  * Adapted for the RTL8180 by David Young.
      7   1.1    dyoung  *
      8   1.1    dyoung  * Redistribution and use in source and binary forms, with or without
      9   1.1    dyoung  * modification, are permitted provided that the following conditions
     10   1.1    dyoung  * are met:
     11   1.1    dyoung  * 1. Redistributions of source code must retain the above copyright
     12   1.1    dyoung  *    notice, this list of conditions and the following disclaimer.
     13   1.1    dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1    dyoung  *    notice, this list of conditions and the following disclaimer in the
     15   1.1    dyoung  *    documentation and/or other materials provided with the distribution.
     16   1.1    dyoung  *
     17   1.1    dyoung  * THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY
     18   1.1    dyoung  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     19   1.1    dyoung  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     20   1.1    dyoung  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL David
     21   1.1    dyoung  * Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     22   1.1    dyoung  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
     23   1.1    dyoung  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24   1.1    dyoung  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     25   1.1    dyoung  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26   1.1    dyoung  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27   1.1    dyoung  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
     28   1.1    dyoung  * OF SUCH DAMAGE.
     29   1.1    dyoung  */
     30   1.1    dyoung /*-
     31   1.1    dyoung  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
     32   1.1    dyoung  * All rights reserved.
     33   1.1    dyoung  *
     34   1.1    dyoung  * This code is derived from software contributed to The NetBSD Foundation
     35   1.1    dyoung  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     36   1.1    dyoung  * NASA Ames Research Center.
     37   1.1    dyoung  *
     38   1.1    dyoung  * Redistribution and use in source and binary forms, with or without
     39   1.1    dyoung  * modification, are permitted provided that the following conditions
     40   1.1    dyoung  * are met:
     41   1.1    dyoung  * 1. Redistributions of source code must retain the above copyright
     42   1.1    dyoung  *    notice, this list of conditions and the following disclaimer.
     43   1.1    dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     44   1.1    dyoung  *    notice, this list of conditions and the following disclaimer in the
     45   1.1    dyoung  *    documentation and/or other materials provided with the distribution.
     46   1.1    dyoung  *
     47   1.1    dyoung  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     48   1.1    dyoung  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     49   1.1    dyoung  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     50   1.1    dyoung  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     51   1.1    dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     52   1.1    dyoung  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     53   1.1    dyoung  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     54   1.1    dyoung  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     55   1.1    dyoung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     56   1.1    dyoung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     57   1.1    dyoung  * POSSIBILITY OF SUCH DAMAGE.
     58   1.1    dyoung  */
     59   1.1    dyoung 
     60   1.1    dyoung /*
     61   1.1    dyoung  * Cardbus front-end for the Realtek RTL8180 802.11 MAC/BBP driver.
     62   1.1    dyoung  *
     63   1.1    dyoung  * TBD factor with atw, tlp Cardbus front-ends?
     64   1.1    dyoung  */
     65   1.1    dyoung 
     66   1.1    dyoung #include <sys/cdefs.h>
     67  1.46   thorpej __KERNEL_RCSID(0, "$NetBSD: if_rtw_cardbus.c,v 1.46 2022/09/25 17:33:19 thorpej Exp $");
     68   1.1    dyoung 
     69   1.1    dyoung #include "opt_inet.h"
     70   1.1    dyoung 
     71   1.1    dyoung #include <sys/param.h>
     72   1.6     perry #include <sys/systm.h>
     73   1.6     perry #include <sys/mbuf.h>
     74   1.1    dyoung #include <sys/kernel.h>
     75   1.1    dyoung #include <sys/socket.h>
     76   1.1    dyoung #include <sys/ioctl.h>
     77   1.1    dyoung #include <sys/errno.h>
     78   1.1    dyoung #include <sys/device.h>
     79   1.1    dyoung 
     80   1.1    dyoung #include <machine/endian.h>
     81   1.6     perry 
     82   1.1    dyoung #include <net/if.h>
     83   1.1    dyoung #include <net/if_dl.h>
     84   1.1    dyoung #include <net/if_media.h>
     85   1.1    dyoung #include <net/if_ether.h>
     86   1.1    dyoung 
     87   1.7    dyoung #include <net80211/ieee80211_netbsd.h>
     88   1.1    dyoung #include <net80211/ieee80211_radiotap.h>
     89   1.1    dyoung #include <net80211/ieee80211_var.h>
     90   1.1    dyoung 
     91  1.16        ad #include <sys/bus.h>
     92  1.16        ad #include <sys/intr.h>
     93   1.1    dyoung 
     94   1.1    dyoung #include <dev/ic/rtwreg.h>
     95   1.1    dyoung #include <dev/ic/rtwvar.h>
     96   1.1    dyoung 
     97   1.1    dyoung #include <dev/pci/pcivar.h>
     98   1.1    dyoung #include <dev/pci/pcireg.h>
     99   1.1    dyoung #include <dev/pci/pcidevs.h>
    100   1.1    dyoung 
    101   1.1    dyoung #include <dev/cardbus/cardbusvar.h>
    102   1.1    dyoung #include <dev/pci/pcidevs.h>
    103   1.1    dyoung 
    104   1.1    dyoung /*
    105   1.1    dyoung  * PCI configuration space registers used by the RTL8180.
    106   1.1    dyoung  */
    107  1.41    dyoung #define RTW_PCI_IOBA PCI_BAR(0)	/* i/o mapped base */
    108  1.41    dyoung #define RTW_PCI_MMBA PCI_BAR(1)	/* memory mapped base */
    109   1.1    dyoung 
    110   1.1    dyoung struct rtw_cardbus_softc {
    111   1.1    dyoung 	struct rtw_softc sc_rtw;	/* real RTL8180 softc */
    112   1.1    dyoung 
    113   1.1    dyoung 	/* CardBus-specific goo. */
    114   1.1    dyoung 	void			*sc_ih;		/* interrupt handle */
    115   1.1    dyoung 	cardbus_devfunc_t	sc_ct;		/* our CardBus devfuncs */
    116  1.36    dyoung 	pcitag_t		sc_tag;		/* our CardBus tag */
    117   1.1    dyoung 	int			sc_csr;		/* CSR bits */
    118   1.1    dyoung 	bus_size_t		sc_mapsize;	/* size of the mapped bus space
    119   1.1    dyoung 						 * region
    120   1.1    dyoung 						 */
    121   1.1    dyoung 
    122  1.40    dyoung 	int			sc_bar;	/* which BAR to use */
    123   1.1    dyoung };
    124   1.1    dyoung 
    125  1.29    cegger int	rtw_cardbus_match(device_t, cfdata_t, void *);
    126  1.21    dyoung void	rtw_cardbus_attach(device_t, device_t, void *);
    127  1.21    dyoung int	rtw_cardbus_detach(device_t, int);
    128   1.1    dyoung 
    129  1.37    dyoung CFATTACH_DECL3_NEW(rtw_cardbus, sizeof(struct rtw_cardbus_softc),
    130  1.45   msaitoh     rtw_cardbus_match, rtw_cardbus_attach, rtw_cardbus_detach, NULL, NULL,
    131  1.45   msaitoh     NULL, DVF_DETACH_SHUTDOWN);
    132   1.1    dyoung 
    133   1.1    dyoung void	rtw_cardbus_setup(struct rtw_cardbus_softc *);
    134   1.1    dyoung 
    135  1.35    dyoung bool rtw_cardbus_resume(device_t, const pmf_qual_t *);
    136  1.35    dyoung bool rtw_cardbus_suspend(device_t, const pmf_qual_t *);
    137   1.1    dyoung 
    138   1.1    dyoung const struct rtw_cardbus_product *rtw_cardbus_lookup(
    139   1.1    dyoung      const struct cardbus_attach_args *);
    140   1.1    dyoung 
    141   1.1    dyoung const struct rtw_cardbus_product {
    142   1.1    dyoung 	u_int32_t	 rcp_vendor;	/* PCI vendor ID */
    143   1.1    dyoung 	u_int32_t	 rcp_product;	/* PCI product ID */
    144   1.1    dyoung 	const char	*rcp_product_name;
    145   1.1    dyoung } rtw_cardbus_products[] = {
    146   1.1    dyoung 	{ PCI_VENDOR_REALTEK,		PCI_PRODUCT_REALTEK_RT8180,
    147   1.1    dyoung 	  "Realtek RTL8180 802.11 MAC/BBP" },
    148   1.1    dyoung 
    149   1.3   jdarrow 	{ PCI_VENDOR_BELKIN,		PCI_PRODUCT_BELKIN_F5D6020V3,
    150   1.3   jdarrow 	  "Belkin F5D6020v3 802.11b (RTL8180 MAC/BBP)" },
    151   1.3   jdarrow 
    152  1.12    martin 	{ PCI_VENDOR_DLINK,		PCI_PRODUCT_DLINK_DWL610,
    153  1.12    martin 	  "DWL-610 D-Link Air 802.11b (RTL8180 MAC/BBP)" },
    154  1.12    martin 
    155   1.1    dyoung 	{ 0,				0,	NULL },
    156   1.1    dyoung };
    157   1.1    dyoung 
    158   1.1    dyoung const struct rtw_cardbus_product *
    159  1.11    rpaulo rtw_cardbus_lookup(const struct cardbus_attach_args *ca)
    160   1.1    dyoung {
    161   1.1    dyoung 	const struct rtw_cardbus_product *rcp;
    162   1.1    dyoung 
    163  1.18    dyoung 	for (rcp = rtw_cardbus_products; rcp->rcp_product_name != NULL; rcp++) {
    164   1.1    dyoung 		if (PCI_VENDOR(ca->ca_id) == rcp->rcp_vendor &&
    165   1.1    dyoung 		    PCI_PRODUCT(ca->ca_id) == rcp->rcp_product)
    166  1.18    dyoung 			return rcp;
    167   1.1    dyoung 	}
    168  1.18    dyoung 	return NULL;
    169   1.1    dyoung }
    170   1.1    dyoung 
    171   1.1    dyoung int
    172  1.29    cegger rtw_cardbus_match(device_t parent, cfdata_t match, void *aux)
    173   1.1    dyoung {
    174   1.1    dyoung 	struct cardbus_attach_args *ca = aux;
    175   1.1    dyoung 
    176   1.1    dyoung 	if (rtw_cardbus_lookup(ca) != NULL)
    177  1.18    dyoung 		return 1;
    178   1.1    dyoung 
    179  1.18    dyoung 	return 0;
    180   1.1    dyoung }
    181   1.1    dyoung 
    182   1.1    dyoung static void
    183   1.1    dyoung rtw_cardbus_funcregen(struct rtw_regs *regs, int enable)
    184   1.1    dyoung {
    185   1.1    dyoung 	u_int32_t reg;
    186   1.1    dyoung 	rtw_config0123_enable(regs, 1);
    187   1.1    dyoung 	reg = RTW_READ(regs, RTW_CONFIG3);
    188  1.18    dyoung 	if (enable)
    189   1.1    dyoung 		RTW_WRITE(regs, RTW_CONFIG3, reg | RTW_CONFIG3_FUNCREGEN);
    190  1.18    dyoung 	else
    191   1.1    dyoung 		RTW_WRITE(regs, RTW_CONFIG3, reg & ~RTW_CONFIG3_FUNCREGEN);
    192   1.1    dyoung 	rtw_config0123_enable(regs, 0);
    193   1.1    dyoung }
    194   1.1    dyoung 
    195   1.1    dyoung void
    196  1.21    dyoung rtw_cardbus_attach(device_t parent, device_t self, void *aux)
    197   1.1    dyoung {
    198  1.10   thorpej 	struct rtw_cardbus_softc *csc = device_private(self);
    199   1.1    dyoung 	struct rtw_softc *sc = &csc->sc_rtw;
    200   1.1    dyoung 	struct rtw_regs *regs = &sc->sc_regs;
    201   1.1    dyoung 	struct cardbus_attach_args *ca = aux;
    202   1.1    dyoung 	cardbus_devfunc_t ct = ca->ca_ct;
    203   1.1    dyoung 	const struct rtw_cardbus_product *rcp;
    204   1.1    dyoung 	bus_addr_t adr;
    205   1.1    dyoung 
    206  1.21    dyoung 	sc->sc_dev = self;
    207   1.1    dyoung 	sc->sc_dmat = ca->ca_dmat;
    208   1.1    dyoung 	csc->sc_ct = ct;
    209   1.1    dyoung 	csc->sc_tag = ca->ca_tag;
    210   1.1    dyoung 
    211   1.1    dyoung 	rcp = rtw_cardbus_lookup(ca);
    212   1.1    dyoung 	if (rcp == NULL) {
    213   1.1    dyoung 		printf("\n");
    214   1.1    dyoung 		panic("rtw_cardbus_attach: impossible");
    215   1.1    dyoung 	}
    216   1.1    dyoung 
    217  1.44       riz 	printf(": %s\n", rcp->rcp_product_name);
    218  1.44       riz 
    219  1.43  christos #ifdef notyet
    220   1.1    dyoung 	/* Get revision info. */
    221  1.43  christos 	int rev = PCI_REVISION(ca->ca_class);
    222   1.1    dyoung 
    223   1.5    dyoung 	RTW_DPRINTF(RTW_DEBUG_ATTACH,
    224  1.23    dyoung 	    ("%s: pass %d.%d signature %08x\n", device_xname(self),
    225   1.5    dyoung 	     (rev >> 4) & 0xf, rev & 0xf,
    226  1.37    dyoung 	     Cardbus_conf_read(ct, csc->sc_tag, 0x80)));
    227  1.44       riz #endif
    228   1.1    dyoung 
    229   1.1    dyoung 	/*
    230   1.1    dyoung 	 * Map the device.
    231   1.1    dyoung 	 */
    232  1.37    dyoung 	csc->sc_csr = PCI_COMMAND_MASTER_ENABLE |
    233  1.37    dyoung 	              PCI_COMMAND_PARITY_ENABLE |
    234  1.37    dyoung 		      PCI_COMMAND_SERR_ENABLE;
    235  1.37    dyoung 	if (Cardbus_mapreg_map(ct, RTW_PCI_MMBA, PCI_MAPREG_TYPE_MEM, 0,
    236  1.23    dyoung 	    &regs->r_bt, &regs->r_bh, &adr, &regs->r_sz) == 0) {
    237   1.5    dyoung 		RTW_DPRINTF(RTW_DEBUG_ATTACH,
    238  1.23    dyoung 		    ("%s: %s mapped %" PRIuMAX " bytes mem space\n",
    239  1.26    dyoung 		     device_xname(self), __func__, (uintmax_t)regs->r_sz));
    240  1.37    dyoung 		csc->sc_csr |= PCI_COMMAND_MEM_ENABLE;
    241  1.40    dyoung 		csc->sc_bar = RTW_PCI_MMBA;
    242  1.37    dyoung 	} else if (Cardbus_mapreg_map(ct, RTW_PCI_IOBA, PCI_MAPREG_TYPE_IO,
    243  1.23    dyoung 	    0, &regs->r_bt, &regs->r_bh, &adr, &regs->r_sz) == 0) {
    244   1.5    dyoung 		RTW_DPRINTF(RTW_DEBUG_ATTACH,
    245  1.23    dyoung 		    ("%s: %s mapped %" PRIuMAX " bytes I/O space\n",
    246  1.26    dyoung 		     device_xname(self), __func__, (uintmax_t)regs->r_sz));
    247  1.37    dyoung 		csc->sc_csr |= PCI_COMMAND_IO_ENABLE;
    248  1.40    dyoung 		csc->sc_bar = RTW_PCI_IOBA;
    249   1.1    dyoung 	} else {
    250  1.23    dyoung 		aprint_error_dev(self, "unable to map device registers\n");
    251   1.1    dyoung 		return;
    252   1.1    dyoung 	}
    253   1.1    dyoung 
    254   1.1    dyoung 	/*
    255   1.1    dyoung 	 * Bring the chip out of powersave mode and initialize the
    256   1.1    dyoung 	 * configuration registers.
    257   1.1    dyoung 	 */
    258   1.1    dyoung 	rtw_cardbus_setup(csc);
    259   1.1    dyoung 
    260   1.1    dyoung 	/*
    261   1.1    dyoung 	 * Finish off the attach.
    262   1.1    dyoung 	 */
    263   1.1    dyoung 	rtw_attach(sc);
    264   1.1    dyoung 
    265   1.1    dyoung 	rtw_cardbus_funcregen(regs, 1);
    266   1.1    dyoung 
    267  1.28    dyoung 	RTW_WRITE(regs, RTW_FEMR, 0);
    268  1.28    dyoung 	RTW_WRITE(regs, RTW_FER, RTW_READ(regs, RTW_FER));
    269   1.1    dyoung 
    270  1.30   tsutsui 	if (pmf_device_register(self,
    271  1.30   tsutsui 	    rtw_cardbus_suspend, rtw_cardbus_resume)) {
    272  1.23    dyoung 		pmf_class_network_register(self, &sc->sc_if);
    273  1.23    dyoung 		/*
    274  1.23    dyoung 		 * Power down the socket.
    275  1.23    dyoung 		 */
    276  1.31    dyoung 		pmf_device_suspend(self, &sc->sc_qual);
    277  1.30   tsutsui 	} else
    278  1.30   tsutsui 		aprint_error_dev(self, "couldn't establish power handler\n");
    279   1.1    dyoung }
    280   1.1    dyoung 
    281   1.1    dyoung int
    282  1.21    dyoung rtw_cardbus_detach(device_t self, int flags)
    283   1.1    dyoung {
    284  1.10   thorpej 	struct rtw_cardbus_softc *csc = device_private(self);
    285   1.1    dyoung 	struct rtw_softc *sc = &csc->sc_rtw;
    286   1.1    dyoung 	struct rtw_regs *regs = &sc->sc_regs;
    287   1.1    dyoung 	struct cardbus_devfunc *ct = csc->sc_ct;
    288  1.18    dyoung 	int rc;
    289   1.1    dyoung 
    290   1.1    dyoung #if defined(DIAGNOSTIC)
    291   1.1    dyoung 	if (ct == NULL)
    292  1.21    dyoung 		panic("%s: data structure lacks", device_xname(self));
    293   1.1    dyoung #endif
    294   1.1    dyoung 
    295  1.18    dyoung 	if ((rc = rtw_detach(sc)) != 0)
    296  1.18    dyoung 		return rc;
    297   1.1    dyoung 
    298   1.1    dyoung 	/*
    299   1.1    dyoung 	 * Unhook the interrupt handler.
    300   1.1    dyoung 	 */
    301   1.1    dyoung 	if (csc->sc_ih != NULL)
    302  1.38    dyoung 		Cardbus_intr_disestablish(ct, csc->sc_ih);
    303   1.1    dyoung 
    304   1.1    dyoung 	/*
    305   1.1    dyoung 	 * Release bus space and close window.
    306   1.1    dyoung 	 */
    307  1.40    dyoung 	if (csc->sc_bar != 0)
    308  1.40    dyoung 		Cardbus_mapreg_unmap(ct, csc->sc_bar,
    309  1.23    dyoung 		    regs->r_bt, regs->r_bh, regs->r_sz);
    310   1.1    dyoung 
    311  1.18    dyoung 	return 0;
    312   1.1    dyoung }
    313   1.1    dyoung 
    314  1.23    dyoung bool
    315  1.35    dyoung rtw_cardbus_resume(device_t self, const pmf_qual_t *qual)
    316   1.1    dyoung {
    317  1.23    dyoung 	struct rtw_cardbus_softc *csc = device_private(self);
    318  1.23    dyoung 	struct rtw_softc *sc = &csc->sc_rtw;
    319   1.1    dyoung 	cardbus_devfunc_t ct = csc->sc_ct;
    320   1.1    dyoung 
    321   1.1    dyoung 	/*
    322   1.1    dyoung 	 * Map and establish the interrupt.
    323   1.1    dyoung 	 */
    324  1.42  drochner 	csc->sc_ih = Cardbus_intr_establish(ct, IPL_NET, rtw_intr, sc);
    325   1.1    dyoung 	if (csc->sc_ih == NULL) {
    326  1.21    dyoung 		aprint_error_dev(sc->sc_dev,
    327  1.27  drochner 		    "unable to establish interrupt\n");
    328  1.23    dyoung 		return false;
    329   1.1    dyoung 	}
    330   1.1    dyoung 
    331   1.1    dyoung 	rtw_cardbus_funcregen(&sc->sc_regs, 1);
    332   1.1    dyoung 
    333   1.1    dyoung 	RTW_WRITE(&sc->sc_regs, RTW_FEMR, RTW_FEMR_INTR);
    334   1.1    dyoung 	RTW_WRITE(&sc->sc_regs, RTW_FER, RTW_FER_INTR);
    335   1.1    dyoung 
    336  1.33    dyoung 	return rtw_resume(self, qual);
    337   1.1    dyoung }
    338   1.1    dyoung 
    339  1.23    dyoung bool
    340  1.35    dyoung rtw_cardbus_suspend(device_t self, const pmf_qual_t *qual)
    341   1.1    dyoung {
    342  1.23    dyoung 	struct rtw_cardbus_softc *csc = device_private(self);
    343  1.23    dyoung 	struct rtw_softc *sc = &csc->sc_rtw;
    344   1.1    dyoung 	cardbus_devfunc_t ct = csc->sc_ct;
    345   1.1    dyoung 
    346  1.33    dyoung 	if (!rtw_suspend(self, qual))
    347  1.23    dyoung 		return false;
    348  1.23    dyoung 
    349   1.1    dyoung 	RTW_WRITE(&sc->sc_regs, RTW_FEMR,
    350   1.1    dyoung 	    RTW_READ(&sc->sc_regs, RTW_FEMR) & ~RTW_FEMR_INTR);
    351   1.1    dyoung 
    352   1.1    dyoung 	rtw_cardbus_funcregen(&sc->sc_regs, 0);
    353   1.1    dyoung 
    354   1.1    dyoung 	/* Unhook the interrupt handler. */
    355  1.38    dyoung 	Cardbus_intr_disestablish(ct, csc->sc_ih);
    356   1.1    dyoung 	csc->sc_ih = NULL;
    357  1.23    dyoung 	return true;
    358   1.1    dyoung }
    359   1.1    dyoung 
    360   1.1    dyoung void
    361  1.11    rpaulo rtw_cardbus_setup(struct rtw_cardbus_softc *csc)
    362   1.1    dyoung {
    363  1.36    dyoung 	pcitag_t tag = csc->sc_tag;
    364   1.1    dyoung 	cardbus_devfunc_t ct = csc->sc_ct;
    365  1.36    dyoung 	pcireg_t bhlc, csr, lattimer;
    366   1.1    dyoung 
    367  1.19  jmcneill 	(void)cardbus_set_powerstate(ct, tag, PCI_PWR_D0);
    368  1.17    dyoung 
    369  1.17    dyoung 	/* I believe the datasheet tries to warn us that the RTL8180
    370  1.17    dyoung 	 * wants for 16 (0x10) to divide the latency timer.
    371  1.17    dyoung 	 */
    372  1.37    dyoung 	bhlc = Cardbus_conf_read(ct, tag, PCI_BHLC_REG);
    373  1.17    dyoung 	lattimer = rounddown(PCI_LATTIMER(bhlc), 0x10);
    374  1.17    dyoung 	if (PCI_LATTIMER(bhlc) != lattimer) {
    375  1.17    dyoung 		bhlc &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
    376  1.17    dyoung 		bhlc |= (lattimer << PCI_LATTIMER_SHIFT);
    377  1.37    dyoung 		Cardbus_conf_write(ct, tag, PCI_BHLC_REG, bhlc);
    378   1.1    dyoung 	}
    379   1.1    dyoung 
    380   1.1    dyoung 	/* Enable the appropriate bits in the PCI CSR. */
    381  1.37    dyoung 	csr = Cardbus_conf_read(ct, tag, PCI_COMMAND_STATUS_REG);
    382  1.17    dyoung 	csr &= ~(PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE);
    383  1.17    dyoung 	csr |= csc->sc_csr;
    384  1.37    dyoung 	Cardbus_conf_write(ct, tag, PCI_COMMAND_STATUS_REG, csr);
    385   1.1    dyoung }
    386