From 09dfdacac82dd72285492041e05e1d4336c6126c Mon Sep 17 00:00:00 2001 From: pooka Date: Mon, 14 Jan 2002 19:24:39 +0000 Subject: [PATCH] Use standard PCI power management definitions from pcireg.h instead of homegrown ones. suggested by Soren --- sys/dev/pci/esa.c | 22 ++++++++++++---------- sys/dev/pci/esareg.h | 9 +-------- sys/dev/pci/esm.c | 22 +++++++++++++--------- sys/dev/pci/esmreg.h | 13 +------------ 4 files changed, 27 insertions(+), 39 deletions(-) diff --git a/sys/dev/pci/esa.c b/sys/dev/pci/esa.c index 091e11127b54..ee31f343b2a0 100644 --- a/sys/dev/pci/esa.c +++ b/sys/dev/pci/esa.c @@ -1,4 +1,4 @@ -/* $NetBSD: esa.c,v 1.6 2002/01/13 15:07:28 jmcneill Exp $ */ +/* $NetBSD: esa.c,v 1.7 2002/01/14 19:24:39 pooka Exp $ */ /* * Copyright (c) 2001, 2002 Jared D. McNeill @@ -56,7 +56,6 @@ #include #include - #include #include #include @@ -952,7 +951,7 @@ esa_attach(struct device *parent, struct device *self, void *aux) printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr); /* Power up chip */ - esa_power(sc, ESA_PPMI_D0); + esa_power(sc, PCI_PMCSR_STATE_D0); /* Init chip */ if (esa_init(sc) == -1) { @@ -1402,12 +1401,15 @@ esa_power(struct esa_softc *sc, int state) { pcitag_t tag = sc->sc_tag; pci_chipset_tag_t pc = sc->sc_pct; - u_int32_t data; + pcireg_t data; + int pmcapreg; - data = pci_conf_read(pc, tag, ESA_CONF_PM_PTR); - if (pci_conf_read(pc, tag, data) == 1) - pci_conf_write(pc, tag, data + 4, state); - + if (pci_get_capability(pc, tag, PCI_CAP_PWRMGMT, &pmcapreg, 0)) { + data = pci_conf_read(pc, tag, pmcapreg + 4); + if ((data && PCI_PMCSR_STATE_MASK) != state) + pci_conf_write(pc, tag, pmcapreg + 4, state); + } + return (0); } @@ -1457,7 +1459,7 @@ esa_suspend(struct esa_softc *sc) sc->savemem[index++] = esa_read_assp(sc, ESA_MEMTYPE_INTERNAL_DATA, i); - esa_power(sc, ESA_PPMI_D3); + esa_power(sc, PCI_PMCSR_STATE_D3); return (0); } @@ -1471,7 +1473,7 @@ esa_resume(struct esa_softc *sc) { index = 0; - esa_power(sc, ESA_PPMI_D0); + esa_power(sc, PCI_PMCSR_STATE_D0); delay(10000); esa_config(sc); diff --git a/sys/dev/pci/esareg.h b/sys/dev/pci/esareg.h index ad21ac24c5ae..3a8001f19bc6 100644 --- a/sys/dev/pci/esareg.h +++ b/sys/dev/pci/esareg.h @@ -1,4 +1,4 @@ -/* $NetBSD: esareg.h,v 1.5 2002/01/13 14:48:01 jmcneill Exp $ */ +/* $NetBSD: esareg.h,v 1.6 2002/01/14 19:24:39 pooka Exp $ */ /* * Copyright (c) 2002 Lennart Augustsson @@ -38,13 +38,6 @@ #define PCI_LEGACY_AUDIO_CTRL 0x40 #define DISABLE_LEGACY 0x00008000 -/* Power management */ -#define ESA_CONF_PM_PTR 0x34 -#define ESA_PPMI_D0 0 -#define ESA_PPMI_D1 1 -#define ESA_PPMI_D2 2 -#define ESA_PPMI_D3 3 - #define ESA_PCI_ALLEGRO_CONFIG 0x50 #define ESA_SB_ADDR_240 0x00000004 #define ESA_MPU_ADDR_MASK 0x00000018 diff --git a/sys/dev/pci/esm.c b/sys/dev/pci/esm.c index ed5a69a34fee..e2607e5fae0b 100644 --- a/sys/dev/pci/esm.c +++ b/sys/dev/pci/esm.c @@ -1,4 +1,4 @@ -/* $NetBSD: esm.c,v 1.12 2001/11/13 07:48:42 lukem Exp $ */ +/* $NetBSD: esm.c,v 1.13 2002/01/14 19:24:39 pooka Exp $ */ /*- * Copyright (c) 2000, 2001 Rene Hexel @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: esm.c,v 1.12 2001/11/13 07:48:42 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: esm.c,v 1.13 2002/01/14 19:24:39 pooka Exp $"); #include #include @@ -507,11 +507,15 @@ wc_wrchctl(struct esm_softc *ess, int ch, u_int16_t data) void esm_power(struct esm_softc *ess, int status) { - u_int8_t data; + pcireg_t data; + int pmcapreg; - data = pci_conf_read(ess->pc, ess->tag, CONF_PM_PTR); - if ((pci_conf_read(ess->pc, ess->tag, data) & 0xff) == PPMI_CID) - pci_conf_write(ess->pc, ess->tag, data + PM_CTRL, status); + if (pci_get_capability(ess->pc, ess->tag, PCI_CAP_PWRMGMT, + &pmcapreg, 0)) { + data = pci_conf_read(ess->pc, ess->tag, pmcapreg + 4); + if ((data && PCI_PMCSR_STATE_MASK) != status) + pci_conf_write(ess->pc, ess->tag, pmcapreg + 4, status); + } } @@ -1362,7 +1366,7 @@ esm_attach(struct device *parent, struct device *self, void *aux) */ /* set to power state D0 */ - esm_power(ess, PPMI_D0); + esm_power(ess, PCI_PMCSR_STATE_D0); delay(100000); /* Disable all legacy emulations. */ @@ -1459,7 +1463,7 @@ esm_suspend(struct esm_softc *ess) delay(20); bus_space_write_4(ess->st, ess->sh, PORT_RINGBUS_CTRL, 0); delay(1); - esm_power(ess, PPMI_D3); + esm_power(ess, PCI_PMCSR_STATE_D3); return 0; } @@ -1469,7 +1473,7 @@ esm_resume(struct esm_softc *ess) { int x; - esm_power(ess, PPMI_D0); + esm_power(ess, PCI_PMCSR_STATE_D0); delay(100000); esm_init(ess); diff --git a/sys/dev/pci/esmreg.h b/sys/dev/pci/esmreg.h index 49e34aadb14b..04f587909ee4 100644 --- a/sys/dev/pci/esmreg.h +++ b/sys/dev/pci/esmreg.h @@ -1,4 +1,4 @@ -/* $NetBSD: esmreg.h,v 1.2 2001/01/18 17:48:04 tv Exp $ */ +/* $NetBSD: esmreg.h,v 1.3 2002/01/14 19:24:39 pooka Exp $ */ /*- * Copyright (c) 2000, 2001 Rene Hexel @@ -70,17 +70,6 @@ #define ACPI_PART_GAME_PORT 1 #define ACPI_PART_WP 0 -/* Power management */ -#define CONF_PM_PTR 0x34 /* BYTE R */ -#define PM_CID 0 /* BYTE R */ -#define PPMI_CID 1 -#define PM_CTRL 4 /* BYTE RW */ -#define PPMI_D0 0 /* Full power */ -#define PPMI_D1 1 /* Medium power */ -#define PPMI_D2 2 /* Low power */ -#define PPMI_D3 3 /* Turned off */ - - /* ----------------------------- * I/O ports */