Home | History | Annotate | Line # | Download | only in cardbus
if_ex_cardbus.c revision 1.46.2.1
      1  1.46.2.1  uebayasi /*	$NetBSD: if_ex_cardbus.c,v 1.46.2.1 2010/04/30 14:43:09 uebayasi Exp $	*/
      2       1.1      haya 
      3       1.1      haya /*
      4       1.1      haya  * Copyright (c) 1998 and 1999
      5       1.1      haya  *       HAYAKAWA Koichi.  All rights reserved.
      6       1.1      haya  *
      7       1.1      haya  * Redistribution and use in source and binary forms, with or without
      8       1.1      haya  * modification, are permitted provided that the following conditions
      9       1.1      haya  * are met:
     10       1.1      haya  * 1. Redistributions of source code must retain the above copyright
     11       1.1      haya  *    notice, this list of conditions and the following disclaimer.
     12       1.1      haya  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1      haya  *    notice, this list of conditions and the following disclaimer in the
     14       1.1      haya  *    documentation and/or other materials provided with the distribution.
     15       1.1      haya  *
     16       1.1      haya  * THIS SOFTWARE IS PROVIDED BY HAYAKAWA KOICHI ``AS IS'' AND
     17       1.1      haya  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18       1.1      haya  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19       1.1      haya  * ARE DISCLAIMED.  IN NO EVENT SHALL TAKESHI OHASHI OR CONTRIBUTORS BE LIABLE
     20       1.1      haya  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21       1.1      haya  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22       1.1      haya  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23       1.1      haya  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24       1.1      haya  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25       1.1      haya  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26       1.1      haya  * SUCH DAMAGE.
     27      1.46       snj  */
     28      1.46       snj 
     29      1.46       snj /*
     30      1.46       snj  * CardBus specific routines for 3Com 3C575-family CardBus ethernet adapter
     31       1.1      haya  */
     32      1.23     lukem 
     33      1.23     lukem #include <sys/cdefs.h>
     34  1.46.2.1  uebayasi __KERNEL_RCSID(0, "$NetBSD: if_ex_cardbus.c,v 1.46.2.1 2010/04/30 14:43:09 uebayasi Exp $");
     35       1.1      haya 
     36      1.22       wiz /* #define EX_DEBUG 4 */	/* define to report information for debugging */
     37       1.1      haya 
     38       1.1      haya #include <sys/param.h>
     39       1.1      haya #include <sys/systm.h>
     40       1.9   thorpej #include <sys/mbuf.h>
     41       1.9   thorpej #include <sys/socket.h>
     42       1.1      haya #include <sys/ioctl.h>
     43       1.1      haya #include <sys/errno.h>
     44       1.1      haya #include <sys/syslog.h>
     45      1.35     perry #include <sys/select.h>
     46       1.9   thorpej #include <sys/device.h>
     47       1.1      haya 
     48       1.1      haya #include <net/if.h>
     49       1.1      haya #include <net/if_dl.h>
     50       1.9   thorpej #include <net/if_ether.h>
     51       1.1      haya #include <net/if_media.h>
     52       1.1      haya 
     53      1.40        ad #include <sys/cpu.h>
     54      1.40        ad #include <sys/bus.h>
     55       1.5      haya 
     56       1.1      haya #include <dev/cardbus/cardbusvar.h>
     57      1.33   mycroft #include <dev/pci/pcidevs.h>
     58       1.1      haya 
     59       1.1      haya #include <dev/mii/miivar.h>
     60       1.1      haya 
     61       1.1      haya #include <dev/ic/elink3var.h>
     62       1.1      haya #include <dev/ic/elink3reg.h>
     63       1.1      haya #include <dev/ic/elinkxlreg.h>
     64       1.1      haya #include <dev/ic/elinkxlvar.h>
     65       1.1      haya 
     66       1.1      haya #if defined DEBUG && !defined EX_DEBUG
     67       1.1      haya #define EX_DEBUG
     68       1.1      haya #endif
     69       1.1      haya 
     70       1.1      haya #if defined EX_DEBUG
     71       1.1      haya #define DPRINTF(a) printf a
     72       1.1      haya #else
     73       1.1      haya #define DPRINTF(a)
     74       1.1      haya #endif
     75       1.1      haya 
     76  1.46.2.1  uebayasi #define CARDBUS_3C575BTX_FUNCSTAT_PCIREG  PCI_BAR2  /* means 0x18 */
     77       1.1      haya #define EX_CB_INTR 4		/* intr acknowledge reg. CardBus only */
     78       1.1      haya #define EX_CB_INTR_ACK 0x8000 /* intr acknowledge bit */
     79       1.1      haya 
     80      1.43       spz int ex_cardbus_match(device_t, cfdata_t, void *);
     81      1.44    cegger void ex_cardbus_attach(device_t, device_t, void *);
     82      1.43       spz int ex_cardbus_detach(device_t, int);
     83      1.34     perry void ex_cardbus_intr_ack(struct ex_softc *);
     84      1.34     perry 
     85      1.34     perry int ex_cardbus_enable(struct ex_softc *);
     86      1.34     perry void ex_cardbus_disable(struct ex_softc *);
     87       1.1      haya 
     88       1.1      haya struct ex_cardbus_softc {
     89       1.9   thorpej 	struct ex_softc sc_softc;
     90       1.1      haya 
     91       1.9   thorpej 	cardbus_devfunc_t sc_ct;
     92      1.45  drochner 	cardbus_intr_line_t sc_intrline;
     93      1.44    cegger 	uint8_t sc_cardbus_flags;
     94       1.1      haya #define EX_REATTACH		0x01
     95       1.1      haya #define EX_ABSENT		0x02
     96      1.44    cegger 	uint8_t sc_cardtype;
     97      1.16      haya #define EX_CB_BOOMERANG		1
     98      1.16      haya #define EX_CB_CYCLONE		2
     99       1.1      haya 
    100       1.9   thorpej 	/* CardBus function status space.  575B requests it. */
    101       1.9   thorpej 	bus_space_tag_t sc_funct;
    102       1.9   thorpej 	bus_space_handle_t sc_funch;
    103      1.11  augustss 	bus_size_t sc_funcsize;
    104      1.11  augustss 
    105      1.11  augustss 	bus_size_t sc_mapsize;		/* the size of mapped bus space region */
    106      1.35     perry 
    107  1.46.2.1  uebayasi 	pcitag_t sc_tag;
    108      1.19   thorpej 
    109  1.46.2.1  uebayasi 	pcireg_t	sc_csr;
    110      1.19   thorpej 	int	sc_bar_reg;		/* which BAR to use */
    111      1.19   thorpej 	pcireg_t sc_bar_val;		/* value of the BAR */
    112      1.19   thorpej 	int	sc_bar_reg1;		/* which BAR to use */
    113      1.19   thorpej 	pcireg_t sc_bar_val1;		/* value of the BAR */
    114      1.35     perry 
    115       1.1      haya };
    116       1.1      haya 
    117  1.46.2.1  uebayasi CFATTACH_DECL3_NEW(ex_cardbus, sizeof(struct ex_cardbus_softc),
    118  1.46.2.1  uebayasi     ex_cardbus_match, ex_cardbus_attach, ex_cardbus_detach, ex_activate,
    119  1.46.2.1  uebayasi     NULL, NULL, DVF_DETACH_SHUTDOWN);
    120       1.9   thorpej 
    121       1.9   thorpej const struct ex_cardbus_product {
    122      1.44    cegger 	uint32_t	ecp_prodid;	/* CardBus product ID */
    123       1.9   thorpej 	int		ecp_flags;	/* initial softc flags */
    124       1.9   thorpej 	pcireg_t	ecp_csr;	/* PCI CSR flags */
    125       1.9   thorpej 	int		ecp_cardtype;	/* card type */
    126       1.9   thorpej 	const char	*ecp_name;	/* device name */
    127       1.9   thorpej } ex_cardbus_products[] = {
    128      1.33   mycroft 	{ PCI_PRODUCT_3COM_3C575TX,
    129      1.18      fvdl 	  EX_CONF_MII | EX_CONF_EEPROM_OFF | EX_CONF_EEPROM_8BIT,
    130  1.46.2.1  uebayasi 	  PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE,
    131      1.16      haya 	  EX_CB_BOOMERANG,
    132       1.9   thorpej 	  "3c575-TX Ethernet" },
    133       1.9   thorpej 
    134      1.33   mycroft 	{ PCI_PRODUCT_3COM_3C575BTX,
    135      1.18      fvdl 	  EX_CONF_90XB|EX_CONF_MII|EX_CONF_INV_LED_POLARITY |
    136      1.18      fvdl 	    EX_CONF_EEPROM_OFF | EX_CONF_EEPROM_8BIT,
    137  1.46.2.1  uebayasi 	  PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    138  1.46.2.1  uebayasi 	      PCI_COMMAND_MASTER_ENABLE,
    139      1.16      haya 	  EX_CB_CYCLONE,
    140       1.9   thorpej 	  "3c575B-TX Ethernet" },
    141       1.9   thorpej 
    142      1.33   mycroft 	{ PCI_PRODUCT_3COM_3C575CTX,
    143      1.18      fvdl 	  EX_CONF_90XB | EX_CONF_PHY_POWER | EX_CONF_EEPROM_OFF |
    144      1.18      fvdl 	    EX_CONF_EEPROM_8BIT,
    145  1.46.2.1  uebayasi 	  PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    146  1.46.2.1  uebayasi 	      PCI_COMMAND_MASTER_ENABLE,
    147      1.16      haya 	  EX_CB_CYCLONE,
    148      1.15      haya 	  "3c575CT Ethernet" },
    149      1.15      haya 
    150      1.33   mycroft 	{ PCI_PRODUCT_3COM_3C656_E,
    151      1.31   mycroft 	  EX_CONF_90XB | EX_CONF_PHY_POWER | EX_CONF_EEPROM_OFF |
    152      1.32   mycroft 	    EX_CONF_EEPROM_8BIT | EX_CONF_INV_LED_POLARITY,
    153  1.46.2.1  uebayasi 	  PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    154  1.46.2.1  uebayasi 	      PCI_COMMAND_MASTER_ENABLE,
    155      1.31   mycroft 	  EX_CB_CYCLONE,
    156      1.31   mycroft 	  "3c656-TX Ethernet" },
    157      1.31   mycroft 
    158      1.33   mycroft 	{ PCI_PRODUCT_3COM_3C656B_E,
    159      1.31   mycroft 	  EX_CONF_90XB | EX_CONF_PHY_POWER | EX_CONF_EEPROM_OFF |
    160      1.32   mycroft 	    EX_CONF_EEPROM_8BIT | EX_CONF_INV_LED_POLARITY,
    161  1.46.2.1  uebayasi 	  PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    162  1.46.2.1  uebayasi 	      PCI_COMMAND_MASTER_ENABLE,
    163      1.31   mycroft 	  EX_CB_CYCLONE,
    164      1.31   mycroft 	  "3c656B-TX Ethernet" },
    165      1.31   mycroft 
    166      1.33   mycroft 	{ PCI_PRODUCT_3COM_3C656C_E,
    167      1.31   mycroft 	  EX_CONF_90XB | EX_CONF_PHY_POWER | EX_CONF_EEPROM_OFF |
    168      1.31   mycroft 	    EX_CONF_EEPROM_8BIT,
    169  1.46.2.1  uebayasi 	  PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    170  1.46.2.1  uebayasi 	      PCI_COMMAND_MASTER_ENABLE,
    171      1.31   mycroft 	  EX_CB_CYCLONE,
    172      1.31   mycroft 	  "3c656C-TX Ethernet" },
    173      1.31   mycroft 
    174       1.9   thorpej 	{ 0,
    175      1.14   thorpej 	  0,
    176       1.9   thorpej 	  0,
    177       1.9   thorpej 	  0,
    178       1.9   thorpej 	  NULL },
    179       1.1      haya };
    180       1.1      haya 
    181      1.19   thorpej 
    182      1.34     perry void ex_cardbus_setup(struct ex_cardbus_softc *);
    183      1.19   thorpej 
    184       1.9   thorpej const struct ex_cardbus_product *ex_cardbus_lookup
    185      1.34     perry    (const struct cardbus_attach_args *);
    186       1.9   thorpej 
    187       1.9   thorpej const struct ex_cardbus_product *
    188      1.44    cegger ex_cardbus_lookup(const struct cardbus_attach_args *ca)
    189       1.9   thorpej {
    190       1.9   thorpej 	const struct ex_cardbus_product *ecp;
    191       1.9   thorpej 
    192  1.46.2.1  uebayasi 	if (PCI_VENDOR(ca->ca_id) != PCI_VENDOR_3COM)
    193       1.9   thorpej 		return (NULL);
    194       1.1      haya 
    195       1.9   thorpej 	for (ecp = ex_cardbus_products; ecp->ecp_name != NULL; ecp++)
    196  1.46.2.1  uebayasi 		if (PCI_PRODUCT(ca->ca_id) == ecp->ecp_prodid)
    197       1.9   thorpej 			return (ecp);
    198       1.9   thorpej 	return (NULL);
    199       1.9   thorpej }
    200       1.1      haya 
    201       1.9   thorpej int
    202      1.43       spz ex_cardbus_match(device_t parent, cfdata_t cf, void *aux)
    203       1.1      haya {
    204       1.9   thorpej 	struct cardbus_attach_args *ca = aux;
    205       1.9   thorpej 
    206       1.9   thorpej 	if (ex_cardbus_lookup(ca) != NULL)
    207       1.9   thorpej 		return (1);
    208       1.1      haya 
    209       1.9   thorpej 	return (0);
    210       1.1      haya }
    211       1.1      haya 
    212       1.9   thorpej void
    213      1.43       spz ex_cardbus_attach(device_t parent, device_t self, void *aux)
    214       1.9   thorpej {
    215      1.37   thorpej 	struct ex_cardbus_softc *csc = device_private(self);
    216      1.17      haya 	struct ex_softc *sc = &csc->sc_softc;
    217       1.9   thorpej 	struct cardbus_attach_args *ca = aux;
    218       1.9   thorpej 	cardbus_devfunc_t ct = ca->ca_ct;
    219       1.9   thorpej 	const struct ex_cardbus_product *ecp;
    220      1.19   thorpej 	bus_addr_t adr, adr1;
    221       1.9   thorpej 
    222      1.43       spz 	sc->sc_dev = self;
    223      1.43       spz 
    224      1.19   thorpej 	sc->sc_dmat = ca->ca_dmat;
    225      1.19   thorpej 	csc->sc_ct = ca->ca_ct;
    226      1.19   thorpej 	csc->sc_intrline = ca->ca_intrline;
    227      1.19   thorpej 	csc->sc_tag = ca->ca_tag;
    228       1.9   thorpej 
    229       1.9   thorpej 	ecp = ex_cardbus_lookup(ca);
    230       1.9   thorpej 	if (ecp == NULL) {
    231       1.9   thorpej 		printf("\n");
    232       1.9   thorpej 		panic("ex_cardbus_attach: impossible");
    233       1.9   thorpej 	}
    234       1.1      haya 
    235      1.43       spz 	aprint_normal(": 3Com %s\n", ecp->ecp_name);
    236       1.1      haya 
    237       1.9   thorpej 	sc->ex_conf = ecp->ecp_flags;
    238      1.19   thorpej 	csc->sc_cardtype = ecp->ecp_cardtype;
    239      1.19   thorpej 	csc->sc_csr = ecp->ecp_csr;
    240       1.1      haya 
    241  1.46.2.1  uebayasi 	if (Cardbus_mapreg_map(ct, PCI_BAR0, PCI_MAPREG_TYPE_IO, 0,
    242      1.19   thorpej 		&sc->sc_iot, &sc->sc_ioh, &adr, &csc->sc_mapsize) == 0) {
    243  1.46.2.1  uebayasi 		csc->sc_bar_reg = PCI_BAR0;
    244  1.46.2.1  uebayasi 		csc->sc_bar_val = adr | PCI_MAPREG_TYPE_IO;
    245       1.1      haya 
    246      1.19   thorpej 		if (csc->sc_cardtype == EX_CB_CYCLONE) {
    247      1.19   thorpej 			/* Map CardBus function status window. */
    248      1.35     perry 			if (Cardbus_mapreg_map(ct,
    249      1.19   thorpej 				CARDBUS_3C575BTX_FUNCSTAT_PCIREG,
    250  1.46.2.1  uebayasi 		    		PCI_MAPREG_TYPE_MEM, 0,
    251      1.19   thorpej 				 &csc->sc_funct, &csc->sc_funch,
    252      1.19   thorpej 				 &adr1, &csc->sc_funcsize) == 0) {
    253      1.19   thorpej 
    254      1.19   thorpej 				csc->sc_bar_reg1 =
    255      1.19   thorpej 					CARDBUS_3C575BTX_FUNCSTAT_PCIREG;
    256      1.19   thorpej 				csc->sc_bar_val1 =
    257  1.46.2.1  uebayasi 					adr1 | PCI_MAPREG_TYPE_MEM;
    258      1.19   thorpej 
    259      1.19   thorpej 			} else {
    260      1.42    cegger 				aprint_error_dev(self, "unable to map function "
    261      1.42    cegger 					"status window\n");
    262      1.19   thorpej 				return;
    263      1.19   thorpej 			}
    264       1.9   thorpej 
    265      1.19   thorpej 			/* Setup interrupt acknowledge hook */
    266      1.19   thorpej 			sc->intr_ack = ex_cardbus_intr_ack;
    267       1.9   thorpej 		}
    268       1.9   thorpej 	}
    269      1.19   thorpej 	else {
    270      1.43       spz 		aprint_naive(": can't map i/o space\n");
    271      1.19   thorpej 		return;
    272       1.9   thorpej 	}
    273       1.1      haya 
    274      1.19   thorpej 	/* Power management hooks. */
    275      1.19   thorpej 	sc->enable = ex_cardbus_enable;
    276      1.19   thorpej 	sc->disable = ex_cardbus_disable;
    277       1.1      haya 
    278      1.19   thorpej 	/*
    279      1.19   thorpej 	 *  Handle power management nonsense and
    280      1.20   kanaoka 	 * initialize the configuration registers.
    281      1.19   thorpej 	 */
    282      1.19   thorpej 	ex_cardbus_setup(csc);
    283       1.1      haya 
    284       1.9   thorpej 	ex_config(sc);
    285       1.9   thorpej 
    286      1.17      haya 	if (csc->sc_cardtype == EX_CB_CYCLONE)
    287      1.17      haya 		bus_space_write_4(csc->sc_funct, csc->sc_funch,
    288       1.9   thorpej 		    EX_CB_INTR, EX_CB_INTR_ACK);
    289       1.1      haya 
    290      1.35     perry 	Cardbus_function_disable(csc->sc_ct);
    291       1.1      haya }
    292       1.1      haya 
    293       1.9   thorpej void
    294      1.44    cegger ex_cardbus_intr_ack(struct ex_softc *sc)
    295       1.1      haya {
    296      1.17      haya 	struct ex_cardbus_softc *csc = (struct ex_cardbus_softc *)sc;
    297       1.9   thorpej 
    298      1.17      haya 	bus_space_write_4(csc->sc_funct, csc->sc_funch, EX_CB_INTR,
    299       1.9   thorpej 	    EX_CB_INTR_ACK);
    300       1.1      haya }
    301       1.1      haya 
    302       1.9   thorpej int
    303  1.46.2.1  uebayasi ex_cardbus_detach(device_t self, int flags)
    304       1.1      haya {
    305      1.37   thorpej 	struct ex_cardbus_softc *csc = device_private(self);
    306      1.17      haya 	struct ex_softc *sc = &csc->sc_softc;
    307      1.17      haya 	struct cardbus_devfunc *ct = csc->sc_ct;
    308      1.11  augustss 	int rv;
    309       1.1      haya 
    310      1.11  augustss #if defined(DIAGNOSTIC)
    311      1.11  augustss 	if (ct == NULL) {
    312      1.43       spz 		panic("%s: data structure lacks", device_xname(self));
    313      1.11  augustss 	}
    314      1.11  augustss #endif
    315      1.10      haya 
    316  1.46.2.1  uebayasi 	if ((rv = ex_detach(sc)) != 0)
    317  1.46.2.1  uebayasi 		return rv;
    318       1.1      haya 
    319  1.46.2.1  uebayasi 	/*
    320  1.46.2.1  uebayasi 	 * Unhook the interrupt handler.
    321  1.46.2.1  uebayasi 	 */
    322  1.46.2.1  uebayasi 	Cardbus_intr_disestablish(ct, sc->sc_ih);
    323       1.1      haya 
    324  1.46.2.1  uebayasi 	if (csc->sc_cardtype == EX_CB_CYCLONE) {
    325  1.46.2.1  uebayasi 		Cardbus_mapreg_unmap(ct,
    326  1.46.2.1  uebayasi 		    CARDBUS_3C575BTX_FUNCSTAT_PCIREG,
    327  1.46.2.1  uebayasi 		    csc->sc_funct, csc->sc_funch, csc->sc_funcsize);
    328      1.11  augustss 	}
    329  1.46.2.1  uebayasi 
    330  1.46.2.1  uebayasi 	Cardbus_mapreg_unmap(ct, PCI_BAR0, sc->sc_iot,
    331  1.46.2.1  uebayasi 	    sc->sc_ioh, csc->sc_mapsize);
    332  1.46.2.1  uebayasi 	return 0;
    333       1.1      haya }
    334       1.1      haya 
    335       1.9   thorpej int
    336      1.44    cegger ex_cardbus_enable(struct ex_softc *sc)
    337       1.1      haya {
    338       1.9   thorpej 	struct ex_cardbus_softc *csc = (struct ex_cardbus_softc *)sc;
    339       1.9   thorpej 
    340       1.9   thorpej 	Cardbus_function_enable(csc->sc_ct);
    341      1.19   thorpej 	ex_cardbus_setup(csc);
    342       1.9   thorpej 
    343  1.46.2.1  uebayasi 	sc->sc_ih = Cardbus_intr_establish(csc->sc_ct, csc->sc_intrline,
    344       1.9   thorpej 	    IPL_NET, ex_intr, sc);
    345       1.9   thorpej 	if (NULL == sc->sc_ih) {
    346      1.43       spz 		aprint_error_dev(sc->sc_dev, "couldn't establish interrupt\n");
    347       1.9   thorpej 		return (1);
    348       1.9   thorpej 	}
    349       1.1      haya 
    350       1.9   thorpej 	return (0);
    351       1.1      haya }
    352       1.1      haya 
    353       1.9   thorpej void
    354      1.44    cegger ex_cardbus_disable(struct ex_softc *sc)
    355       1.1      haya {
    356       1.9   thorpej 	struct ex_cardbus_softc *csc = (struct ex_cardbus_softc *)sc;
    357       1.1      haya 
    358  1.46.2.1  uebayasi 	if (sc->sc_ih != NULL) {
    359  1.46.2.1  uebayasi 		Cardbus_intr_disestablish(csc->sc_ct, sc->sc_ih);
    360  1.46.2.1  uebayasi 		sc->sc_ih = NULL;
    361  1.46.2.1  uebayasi 	}
    362      1.19   thorpej 
    363       1.9   thorpej  	Cardbus_function_disable(csc->sc_ct);
    364       1.1      haya 
    365       1.1      haya }
    366      1.19   thorpej 
    367      1.35     perry void
    368      1.44    cegger ex_cardbus_setup(struct ex_cardbus_softc *csc)
    369      1.19   thorpej {
    370      1.19   thorpej 	cardbus_devfunc_t ct = csc->sc_ct;
    371  1.46.2.1  uebayasi 	pcireg_t reg;
    372      1.19   thorpej 
    373      1.41  jmcneill 	(void)cardbus_set_powerstate(ct, csc->sc_tag, PCI_PWR_D0);
    374      1.19   thorpej 
    375      1.30   mycroft 	/* Program the BAR */
    376  1.46.2.1  uebayasi 	Cardbus_conf_write(ct, csc->sc_tag, csc->sc_bar_reg, csc->sc_bar_val);
    377      1.19   thorpej 	/* Make sure the right access type is on the CardBus bridge. */
    378      1.19   thorpej 	if (csc->sc_cardtype == EX_CB_CYCLONE) {
    379      1.30   mycroft 		/* Program the BAR */
    380  1.46.2.1  uebayasi 		Cardbus_conf_write(ct, csc->sc_tag,
    381      1.35     perry 			csc->sc_bar_reg1, csc->sc_bar_val1);
    382      1.19   thorpej 		/*
    383      1.19   thorpej 		 * Make sure CardBus brigde can access memory space.  Usually
    384      1.19   thorpej 		 * memory access is enabled by BIOS, but some BIOSes do not
    385      1.19   thorpej 		 * enable it.
    386      1.19   thorpej 		 */
    387      1.19   thorpej 	}
    388      1.19   thorpej 
    389      1.19   thorpej 	/* Enable the appropriate bits in the CARDBUS CSR. */
    390  1.46.2.1  uebayasi 	reg = Cardbus_conf_read(ct, csc->sc_tag, PCI_COMMAND_STATUS_REG);
    391      1.19   thorpej 	reg |= csc->sc_csr;
    392  1.46.2.1  uebayasi 	Cardbus_conf_write(ct, csc->sc_tag, PCI_COMMAND_STATUS_REG, reg);
    393      1.35     perry 
    394      1.19   thorpej  	/*
    395      1.28       wiz 	 * set latency timer
    396      1.19   thorpej 	 */
    397  1.46.2.1  uebayasi 	reg = Cardbus_conf_read(ct, csc->sc_tag, PCI_BHLC_REG);
    398  1.46.2.1  uebayasi 	if (PCI_LATTIMER(reg) < 0x20) {
    399      1.19   thorpej 		/* at least the value of latency timer should 0x20. */
    400      1.19   thorpej 		DPRINTF(("if_ex_cardbus: lattimer 0x%x -> 0x20\n",
    401  1.46.2.1  uebayasi 		    PCI_LATTIMER(reg)));
    402  1.46.2.1  uebayasi 		reg &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
    403  1.46.2.1  uebayasi 		reg |= (0x20 << PCI_LATTIMER_SHIFT);
    404  1.46.2.1  uebayasi 		Cardbus_conf_write(ct, csc->sc_tag, PCI_BHLC_REG, reg);
    405      1.19   thorpej 	}
    406      1.19   thorpej }
    407