Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Power management support for the CardBus Etherlink X...



details:   https://anonhg.NetBSD.org/src/rev/b6a544891c62
branches:  trunk
changeset: 503073:b6a544891c62
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Jan 30 19:27:39 2001 +0000

description:
Power management support for the CardBus Etherlink XL cards.
>From Masanori Kanaoka <kanaoka%ann.hi-ho.ne.jp@localhost>.

diffstat:

 sys/dev/cardbus/if_ex_cardbus.c |  270 ++++++++++++++++++++++++---------------
 sys/dev/ic/elinkxl.c            |   89 +++++++++++-
 sys/dev/ic/elinkxlvar.h         |    5 +-
 3 files changed, 252 insertions(+), 112 deletions(-)

diffs (truncated from 555 to 300 lines):

diff -r 29d9f692919c -r b6a544891c62 sys/dev/cardbus/if_ex_cardbus.c
--- a/sys/dev/cardbus/if_ex_cardbus.c   Tue Jan 30 19:24:54 2001 +0000
+++ b/sys/dev/cardbus/if_ex_cardbus.c   Tue Jan 30 19:27:39 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ex_cardbus.c,v 1.18 2000/09/19 01:10:12 fvdl Exp $  */
+/*     $NetBSD: if_ex_cardbus.c,v 1.19 2001/01/30 19:27:39 thorpej Exp $       */
 
 /*
  * CardBus specific routines for 3Com 3C575-family CardBus ethernet adapter
@@ -38,11 +38,6 @@
 
 /* #define EX_DEBUG 4 */       /* define to report infomation for debugging */
 
-#define EX_POWER_STATIC                /* do not use enable/disable functions */
-                               /* I'm waiting elinkxl.c uses
-                                   sc->enable and sc->disable
-                                   functions. */
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/mbuf.h>
@@ -90,10 +85,9 @@
 int ex_cardbus_detach __P((struct device *, int));
 void ex_cardbus_intr_ack __P((struct ex_softc *));
 
-#if !defined EX_POWER_STATIC
-int ex_cardbus_enable __P((struct ex_softc *sc));
-void ex_cardbus_disable __P((struct ex_softc *sc));
-#endif /* !defined EX_POWER_STATIC */
+int ex_cardbus_enable __P((struct ex_softc *));
+void ex_cardbus_disable __P((struct ex_softc *));
+void ex_cardbus_power __P((struct ex_softc *, int));
 
 struct ex_cardbus_softc {
        struct ex_softc sc_softc;
@@ -113,6 +107,15 @@
        bus_size_t sc_funcsize;
 
        bus_size_t sc_mapsize;          /* the size of mapped bus space region */
+       
+       cardbustag_t sc_tag;
+
+       int     sc_csr;                 /* CSR bits */
+       int     sc_bar_reg;             /* which BAR to use */
+       pcireg_t sc_bar_val;            /* value of the BAR */
+       int     sc_bar_reg1;            /* which BAR to use */
+       pcireg_t sc_bar_val1;           /* value of the BAR */
+       
 };
 
 struct cfattach ex_cardbus_ca = {
@@ -156,6 +159,9 @@
          NULL },
 };
 
+
+void ex_cardbus_setup __P((struct ex_cardbus_softc *));
+
 const struct ex_cardbus_product *ex_cardbus_lookup
     __P((const struct cardbus_attach_args *));
 
@@ -198,18 +204,18 @@
        struct ex_softc *sc = &csc->sc_softc;
        struct cardbus_attach_args *ca = aux;
        cardbus_devfunc_t ct = ca->ca_ct;
+#if rbus
+#else
        cardbus_chipset_tag_t cc = ct->ct_cc;
-       cardbus_function_tag_t cf = ct->ct_cf;
-       cardbusreg_t iob, command, bhlc;
+#endif
        const struct ex_cardbus_product *ecp;
-       bus_space_handle_t ioh;
-       bus_addr_t adr;
+       bus_addr_t adr, adr1;
 
-       if (Cardbus_mapreg_map(ct, CARDBUS_BASE0_REG, CARDBUS_MAPREG_TYPE_IO, 0,
-           &sc->sc_iot, &ioh, &adr, &csc->sc_mapsize)) {
-               printf(": can't map i/o space\n");
-               return;
-       }
+       sc->ex_bustype = EX_BUS_CARDBUS;
+       sc->sc_dmat = ca->ca_dmat;
+       csc->sc_ct = ca->ca_ct;
+       csc->sc_intrline = ca->ca_intrline;
+       csc->sc_tag = ca->ca_tag;
 
        ecp = ex_cardbus_lookup(ca);
        if (ecp == NULL) {
@@ -219,90 +225,57 @@
 
        printf(": 3Com %s\n", ecp->ecp_name);
 
-#if !defined EX_POWER_STATIC
-       sc->enable = ex_cardbus_enable;
-       sc->disable = ex_cardbus_disable;
-#else
-       sc->enable = NULL;
-       sc->disable = NULL;
-#endif  
-       sc->enabled = 1;
+       sc->ex_conf = ecp->ecp_flags;
+       csc->sc_cardtype = ecp->ecp_cardtype;
+       csc->sc_csr = ecp->ecp_csr;
 
-       sc->sc_dmat = ca->ca_dmat;
-
-       sc->ex_bustype = EX_BUS_CARDBUS;
-       sc->ex_conf = ecp->ecp_flags;
-
-       iob = adr;
-       sc->sc_ioh = ioh;
-
+       if (Cardbus_mapreg_map(ct, CARDBUS_BASE0_REG, CARDBUS_MAPREG_TYPE_IO, 0,
+               &sc->sc_iot, &sc->sc_ioh, &adr, &csc->sc_mapsize) == 0) {
 #if rbus
 #else
-       (ct->ct_cf->cardbus_io_open)(cc, 0, iob, iob + 0x40);
+               (*ct->ct_cf->cardbus_io_open)(cc, 0, adr, adr + csc->sc_mapsize);
 #endif
-       (ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_IO_ENABLE);
+               csc->sc_bar_reg = CARDBUS_BASE0_REG;
+               csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_IO;
 
-       command = cardbus_conf_read(cc, cf, ca->ca_tag,
-           CARDBUS_COMMAND_STATUS_REG);
-       command |= ecp->ecp_csr;
-       csc->sc_cardtype = ecp->ecp_cardtype;
+               if (csc->sc_cardtype == EX_CB_CYCLONE) {
+                       /* Map CardBus function status window. */
+                       if (Cardbus_mapreg_map(ct, 
+                               CARDBUS_3C575BTX_FUNCSTAT_PCIREG,
+                               CARDBUS_MAPREG_TYPE_MEM, 0,
+                                &csc->sc_funct, &csc->sc_funch,
+                                &adr1, &csc->sc_funcsize) == 0) {
 
-       if (csc->sc_cardtype == EX_CB_CYCLONE) {
-               /* Map CardBus function status window. */
-               if (Cardbus_mapreg_map(ct, CARDBUS_3C575BTX_FUNCSTAT_PCIREG,
-                   CARDBUS_MAPREG_TYPE_MEM, 0, &csc->sc_funct,
-                   &csc->sc_funch, 0, &csc->sc_funcsize)) {
-                       printf("%s: unable to map function status window\n",
-                           self->dv_xname);
-                       return;
-               }
+                               csc->sc_bar_reg1 =
+                                       CARDBUS_3C575BTX_FUNCSTAT_PCIREG;
+                               csc->sc_bar_val1 =
+                                       adr1 | CARDBUS_MAPREG_TYPE_MEM;
 
-               /*
-                * Make sure CardBus brigde can access memory space.  Usually
-                * memory access is enabled by BIOS, but some BIOSes do not
-                * enable it.
-                */
-               (ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_MEM_ENABLE);
+                       } else {
+                               printf("%s: unable to map function 
+                                       status window\n", self->dv_xname);
+                               return;
+                       }
 
-               /* Setup interrupt acknowledge hook */
-               sc->intr_ack = ex_cardbus_intr_ack;
+                       /* Setup interrupt acknowledge hook */
+                       sc->intr_ack = ex_cardbus_intr_ack;
+               }
+       }
+       else {
+               printf(": can't map i/o space\n");
+               return;
        }
 
-       (ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
-       cardbus_conf_write(cc, cf, ca->ca_tag, CARDBUS_COMMAND_STATUS_REG,
-           command);
-  
-       /*
-        * set latency timmer
-        */
-       bhlc = cardbus_conf_read(cc, cf, ca->ca_tag, CARDBUS_BHLC_REG);
-       if (CARDBUS_LATTIMER(bhlc) < 0x20) {
-               /* at least the value of latency timer should 0x20. */
-               DPRINTF(("if_ex_cardbus: lattimer 0x%x -> 0x20\n",
-                   CARDBUS_LATTIMER(bhlc)));
-               bhlc &= ~(CARDBUS_LATTIMER_MASK << CARDBUS_LATTIMER_SHIFT);
-               bhlc |= (0x20 << CARDBUS_LATTIMER_SHIFT);
-               cardbus_conf_write(cc, cf, ca->ca_tag, CARDBUS_BHLC_REG, bhlc);
-       }
+       /* Power management hooks. */
+       sc->enable = ex_cardbus_enable;
+       sc->disable = ex_cardbus_disable;
+       sc->power = ex_cardbus_power;
 
-       csc->sc_ct = ca->ca_ct;
-       csc->sc_intrline = ca->ca_intrline;
-
-#if defined EX_POWER_STATIC
-       /* Map and establish the interrupt. */
-
-       sc->sc_ih = cardbus_intr_establish(cc, cf, ca->ca_intrline, IPL_NET,
-           ex_intr, csc);
-       if (sc->sc_ih == NULL) {
-               printf("%s: couldn't establish interrupt",
-                   sc->sc_dev.dv_xname);
-               printf(" at %d", ca->ca_intrline);
-               printf("\n");
-               return;
-       }
-       printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname,
-           ca->ca_intrline);
-#endif
+       /*
+        *  Handle power management nonsense and
+        * Initialize th configuration register.
+        */
+       ex_cardbus_setup(csc);
 
        ex_config(sc);
 
@@ -310,10 +283,7 @@
                bus_space_write_4(csc->sc_funct, csc->sc_funch,
                    EX_CB_INTR, EX_CB_INTR_ACK);
 
-#if !defined EX_POWER_STATIC
-       cardbus_function_disable(csc->sc_ct);  
-       sc->enabled = 0;
-#endif
+       Cardbus_function_disable(csc->sc_ct);  
 }
 
 void
@@ -361,7 +331,6 @@
        return (rv);
 }
 
-#if !defined EX_POWER_STATIC
 int
 ex_cardbus_enable(sc)
        struct ex_softc *sc;
@@ -371,7 +340,7 @@
        cardbus_chipset_tag_t cc = csc->sc_ct->ct_cc;
 
        Cardbus_function_enable(csc->sc_ct);
-       cardbus_restore_bar(csc->sc_ct);
+       ex_cardbus_setup(csc);
 
        sc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline,
            IPL_NET, ex_intr, sc);
@@ -380,6 +349,8 @@
                    sc->sc_dev.dv_xname);
                return (1);
        }
+       printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname,
+               csc->sc_intrline);
 
        return (0);
 }
@@ -392,10 +363,105 @@
        cardbus_function_tag_t cf = csc->sc_ct->ct_cf;
        cardbus_chipset_tag_t cc = csc->sc_ct->ct_cc;
 
-       cardbus_save_bar(csc->sc_ct);
-  
+       cardbus_intr_disestablish(cc, cf, sc->sc_ih);
+       sc->sc_ih = NULL;
+
        Cardbus_function_disable(csc->sc_ct);
 
-       cardbus_intr_disestablish(cc, cf, sc->sc_ih);
+}
+
+void 
+ex_cardbus_power(sc, why)
+       struct ex_softc *sc;
+       int why;
+{
+       struct ex_cardbus_softc *csc = (void *) sc;
+
+       if (why == PWR_RESUME) {
+               /*
+                * Give the PCI configuration registers a kick
+                * in the head.
+                */
+#ifdef DIAGNOSTIC
+               if (sc->enabled == 0)
+                       panic("ex_cardbus_power");
+#endif
+               ex_cardbus_setup(csc);
+       }
 }
-#endif /* EX_POWER_STATIC */
+
+void 
+ex_cardbus_setup(csc)
+       struct ex_cardbus_softc *csc;
+{
+       struct ex_softc *sc = &csc->sc_softc;
+       cardbus_devfunc_t ct = csc->sc_ct;
+       cardbus_chipset_tag_t cc = ct->ct_cc;



Home | Main Index | Thread Index | Old Index