Current-Users archive

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

viaide(4) patch for suspend/resume (second try)



Hi all,
second try at getting someone to actually test this diff.
It is the fixed version based on the input of Christos and Jared.

Joerg
Index: viaide.c
===================================================================
RCS file: /data/repo/netbsd/src/sys/dev/pci/viaide.c,v
retrieving revision 1.50
diff -u -p -r1.50 viaide.c
--- viaide.c    20 Dec 2007 22:24:40 -0000      1.50
+++ viaide.c    21 Dec 2007 23:44:44 -0000
@@ -67,6 +67,8 @@ static int    viaide_match(struct device *,
 static void    viaide_attach(struct device *, struct device *, void *);
 static const struct pciide_product_desc *
                viaide_lookup(pcireg_t);
+static bool    viaide_suspend(device_t);
+static bool    viaide_resume(device_t);
 
 CFATTACH_DECL(viaide, sizeof(struct pciide_softc),
     viaide_match, viaide_attach, NULL, NULL);
@@ -374,6 +376,9 @@ viaide_attach(struct device *parent, str
        if (pp == NULL)
                panic("viaide_attach");
        pciide_common_attach(sc, pa, pp);
+
+       if (!pmf_device_register(self, viaide_suspend, viaide_resume))
+               aprint_error_dev(self, "couldn't establish power handler\n");
 }
 
 static int
@@ -386,6 +391,39 @@ via_pcib_match(struct pci_attach_args *p
        return 0;
 }
 
+static bool
+viaide_suspend(device_t dv)
+{
+       struct pciide_softc *sc = device_private(dv);
+
+       sc->sc_pm_reg[0] = pci_conf_read(sc->sc_pc, sc->sc_tag, 
APO_IDECONF(sc));
+       /* APO_DATATIM(sc) includes APO_UDMA(sc) */
+       sc->sc_pm_reg[1] = pci_conf_read(sc->sc_pc, sc->sc_tag, 
APO_DATATIM(sc));
+       /* This two are VIA-only, but should be ignored by other devices. */
+       sc->sc_pm_reg[2] = pci_conf_read(sc->sc_pc, sc->sc_tag, 
APO_CTLMISC(sc));
+       sc->sc_pm_reg[3] = pci_conf_read(sc->sc_pc, sc->sc_tag, 
APO_MISCTIM(sc));
+
+       return true;
+}
+
+static bool
+viaide_resume(device_t dv)
+{
+       struct pciide_softc *sc = device_private(dv);
+
+       pci_conf_write(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc),
+           sc->sc_pm_reg[0]);
+       pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc),
+           sc->sc_pm_reg[1]);
+       /* This two are VIA-only, but should be ignored by other devices. */
+       pci_conf_write(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc),
+           sc->sc_pm_reg[2]);
+       pci_conf_write(sc->sc_pc, sc->sc_tag, APO_MISCTIM(sc),
+           sc->sc_pm_reg[3]);
+
+       return true;
+}
+
 static void
 via_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
 {


Home | Main Index | Thread Index | Old Index