Source-Changes-HG archive

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

[src/trunk]: src Add a driver for ACPI power meters.



details:   https://anonhg.NetBSD.org/src/rev/10425dfcf173
branches:  trunk
changeset: 760472:10425dfcf173
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Wed Jan 05 20:08:12 2011 +0000

description:
Add a driver for ACPI power meters.

diffstat:

 distrib/sets/lists/man/mi   |    5 +-
 doc/CHANGES                 |    3 +-
 share/man/man4/Makefile     |    4 +-
 share/man/man4/acpipmtr.4   |   66 +++++
 sys/arch/amd64/conf/GENERIC |   12 +-
 sys/arch/i386/conf/GENERIC  |   12 +-
 sys/dev/acpi/acpi_pmtr.c    |  518 ++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/acpi/files.acpi     |    7 +-
 8 files changed, 608 insertions(+), 19 deletions(-)

diffs (truncated from 746 to 300 lines):

diff -r 3e4161930ef8 -r 10425dfcf173 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Wed Jan 05 19:59:48 2011 +0000
+++ b/distrib/sets/lists/man/mi Wed Jan 05 20:08:12 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1271 2010/12/27 17:26:57 jmcneill Exp $
+# $NetBSD: mi,v 1.1272 2011/01/05 20:08:12 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -637,6 +637,7 @@
 ./usr/share/man/cat4/acpiecdt.0                        man-sys-catman          .cat
 ./usr/share/man/cat4/acpilid.0                 man-sys-catman          .cat
 ./usr/share/man/cat4/acpiout.0                 man-sys-catman          .cat
+./usr/share/man/cat4/acpipmtr.0                        man-sys-catman          .cat
 ./usr/share/man/cat4/acpismbus.0               man-sys-catman          .cat
 ./usr/share/man/cat4/acpitz.0                  man-sys-catman          .cat
 ./usr/share/man/cat4/acpivga.0                 man-sys-catman          .cat
@@ -3401,6 +3402,7 @@
 ./usr/share/man/html4/acpiecdt.html            man-sys-htmlman         html
 ./usr/share/man/html4/acpilid.html             man-sys-htmlman         html
 ./usr/share/man/html4/acpiout.html             man-sys-htmlman         html
+./usr/share/man/html4/acpipmtr.html            man-sys-htmlman         html
 ./usr/share/man/html4/acpismbus.html           man-sys-htmlman         html
 ./usr/share/man/html4/acpitz.html              man-sys-htmlman         html
 ./usr/share/man/html4/acpivga.html             man-sys-htmlman         html
@@ -5865,6 +5867,7 @@
 ./usr/share/man/man4/acpiecdt.4                        man-sys-man             .man
 ./usr/share/man/man4/acpilid.4                 man-sys-man             .man
 ./usr/share/man/man4/acpiout.4                 man-sys-man             .man
+./usr/share/man/man4/acpipmtr.4                        man-sys-man             .man
 ./usr/share/man/man4/acpismbus.4               man-sys-man             .man
 ./usr/share/man/man4/acpitz.4                  man-sys-man             .man
 ./usr/share/man/man4/acpivga.4                 man-sys-man             .man
diff -r 3e4161930ef8 -r 10425dfcf173 doc/CHANGES
--- a/doc/CHANGES       Wed Jan 05 19:59:48 2011 +0000
+++ b/doc/CHANGES       Wed Jan 05 20:08:12 2011 +0000
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:                   <$Revision: 1.1484 $>
+# LIST OF CHANGES FROM LAST RELEASE:                   <$Revision: 1.1485 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -818,3 +818,4 @@
        dhcpcd(8): Import dhcpcd-5.2.10. [roy 20110103]
        resize_ffs(8): support byteswapped file systems, and support
                growing ufs2 file systems. [riz 20110104]
+       acpipmtr(4): Add a driver for ACPI power meters. [jruoho 20110105]
diff -r 3e4161930ef8 -r 10425dfcf173 share/man/man4/Makefile
--- a/share/man/man4/Makefile   Wed Jan 05 19:59:48 2011 +0000
+++ b/share/man/man4/Makefile   Wed Jan 05 20:08:12 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.540 2010/12/27 17:26:58 jmcneill Exp $
+#      $NetBSD: Makefile,v 1.541 2011/01/05 20:08:13 jruoho Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/18/93
 
 MAN=   aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -83,7 +83,7 @@
 # ACPI devices
 MAN+=  acpi.4 acpiacad.4 acpibat.4 acpibut.4 acpicpu.4 \
        acpidalb.4 acpiec.4 acpilid.4 \
-       acpismbus.4 acpitz.4 acpivga.4 acpiwmi.4
+       acpipmtr.4 acpismbus.4 acpitz.4 acpivga.4 acpiwmi.4
 
 # Radio devices
 MAN+=  radio.4 az.4 mr.4 rt.4 rtii.4 sf2r.4
diff -r 3e4161930ef8 -r 10425dfcf173 share/man/man4/acpipmtr.4
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/acpipmtr.4 Wed Jan 05 20:08:12 2011 +0000
@@ -0,0 +1,66 @@
+.\" $NetBSD: acpipmtr.4,v 1.1 2011/01/05 20:08:13 jruoho Exp $
+.\"
+.\" Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Neither the name of the author nor the names of any
+.\"    contributors may be used to endorse or promote products derived
+.\"    from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd December 22, 2010
+.Dt ACPIPMTR 4
+.Os
+.Sh NAME
+.Nm acpipmtr
+.Nd ACPI Power Meter
+.Sh SYNOPSIS
+.Cd "acpipmtr* at acpi?"
+.Sh DESCRIPTION
+The
+.Nm
+device driver provides support for
+.Dq power meters .
+These are sensors that approximate the current
+power consumption of the system.
+Alternatively, a power meter may measure also the power gain
+when the system is connected to an external power supply.
+.Pp
+The available information (namely, the power consumption)
+is made available through the
+.Xr envsys 4
+.Tn API
+and the
+.Xr envstat 8
+command.
+.Sh SEE ALSO
+.Xr acpi 4 ,
+.Xr acpibat 4
+.Sh HISTORY
+The
+.Nm
+device driver appeared in
+.Nx 6.0 .
+.Sh AUTHORS
+.An Jukka Ruohonen
+.Aq jruohonen%iki.fi@localhost
+.Sh CAVEATS
+The
+.Nm
+driver is experimental.
diff -r 3e4161930ef8 -r 10425dfcf173 sys/arch/amd64/conf/GENERIC
--- a/sys/arch/amd64/conf/GENERIC       Wed Jan 05 19:59:48 2011 +0000
+++ b/sys/arch/amd64/conf/GENERIC       Wed Jan 05 20:08:12 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.295 2011/01/03 06:07:42 tsutsui Exp $
+# $NetBSD: GENERIC,v 1.296 2011/01/05 20:08:12 jruoho Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.295 $"
+#ident                 "GENERIC-$Revision: 1.296 $"
 
 maxusers       64              # estimated number of users
 
@@ -276,12 +276,10 @@
 acpibut*       at acpi?                # ACPI Button
 #acpicpu*      at acpi?                # ACPI CPU
 acpidalb*      at acpi?                # Direct Application Launch Button
-# The ACPI Embedded Controller is generally configured via the special ECDT.
-# This is required as parts of the DSDT can reference the EC before the normal
-# attach phase.
-acpiec*        at acpi?                # ACPI Embedded Controller (late binding)
-acpiecdt*      at acpi?                # ACPI Embedded Controller (early binding)
+acpiec*        at acpi?                # ACPI Embedded Controller (late)
+acpiecdt*      at acpi?                # ACPI Embedded Controller (early)
 acpilid*       at acpi?                # ACPI Lid Switch
+#acpipmtr*     at acpi?                # ACPI Power Meter (experimental)
 #acpismbus*    at acpi?                # ACPI SMBus CMI (experimental)
 acpitz*        at acpi?                # ACPI Thermal Zone
 acpivga*       at acpi?                # ACPI Display Adapter
diff -r 3e4161930ef8 -r 10425dfcf173 sys/arch/i386/conf/GENERIC
--- a/sys/arch/i386/conf/GENERIC        Wed Jan 05 19:59:48 2011 +0000
+++ b/sys/arch/i386/conf/GENERIC        Wed Jan 05 20:08:12 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1004 2011/01/03 06:07:43 tsutsui Exp $
+# $NetBSD: GENERIC,v 1.1005 2011/01/05 20:08:12 jruoho Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.1004 $"
+#ident                 "GENERIC-$Revision: 1.1005 $"
 
 maxusers       64              # estimated number of users
 
@@ -356,12 +356,10 @@
 acpibut*       at acpi?                # ACPI Button
 #acpicpu*      at acpi?                # ACPI CPU
 acpidalb*      at acpi?                # ACPI Direct Application Launch Button
-# The ACPI Embedded Controller is generally configured via the special ECDT.
-# This is required as parts of the DSDT can reference the EC before the normal
-# attach phase.
-acpiec*        at acpi?                # ACPI Embedded Controller (late binding)
-acpiecdt*      at acpi?                # ACPI Embedded Controller (early binding)
+acpiec*        at acpi?                # ACPI Embedded Controller (late)
+acpiecdt*      at acpi?                # ACPI Embedded Controller (early)
 acpilid*       at acpi?                # ACPI Lid Switch
+#acpipmtr*     at acpi?                # ACPI Power Meter (experimental)
 #acpismbus*    at acpi?                # ACPI SMBus CMI (experimental)
 acpitz*        at acpi?                # ACPI Thermal Zone
 acpivga*       at acpi?                # ACPI Display Adapter
diff -r 3e4161930ef8 -r 10425dfcf173 sys/dev/acpi/acpi_pmtr.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/acpi_pmtr.c  Wed Jan 05 20:08:12 2011 +0000
@@ -0,0 +1,518 @@
+/*     $NetBSD: acpi_pmtr.c,v 1.1 2011/01/05 20:08:12 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: acpi_pmtr.c,v 1.1 2011/01/05 20:08:12 jruoho Exp $");
+
+#include <sys/param.h>
+#include <sys/module.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#include <dev/sysmon/sysmonvar.h>
+
+#define _COMPONENT                     ACPI_RESOURCE_COMPONENT
+ACPI_MODULE_NAME                       ("acpi_pmtr")
+
+#define ACPIPMTR_CAP_FLAGS             0
+#define ACPIPMTR_CAP_UNIT              1
+#define ACPIPMTR_CAP_TYPE              2
+#define ACPIPMTR_CAP_ACCURACY          3
+#define ACPIPMTR_CAP_SAMPLING          4
+#define ACPIPMTR_CAP_IVAL_MIN          5
+#define ACPIPMTR_CAP_IVAL_MAX          6
+#define ACPIPMTR_CAP_HYSTERESIS                7
+#define ACPIPMTR_CAP_HWLIMIT           8
+#define ACPIPMTR_CAP_HWLIMIT_MIN       9
+#define ACPIPMTR_CAP_HWLIMIT_MAX       10
+#define ACPIPMTR_CAP_COUNT             11
+/*      ACPIPMTR_CAP_MODEL             11 */
+/*      ACPIPMTR_CAP_SERIAL            12 */
+/*      ACPIPMTR_CAP_OEM               13 */
+
+#define ACPIPMTR_FLAGS_MEASURE         __BIT(0)
+#define ACPIPMTR_FLAGS_TRIP            __BIT(1)
+#define ACPIPMTR_FLAGS_HWLIMIT         __BIT(2)
+#define ACPIPMTR_FLAGS_NOTIFY          __BIT(3)
+#define ACPIPMTR_FLAGS_DISCHARGE       __BIT(8)
+
+#define ACPIPMTR_POWER_INPUT           0x00
+#define ACPIPMTR_POWER_OUTPUT          0x01
+
+#define ACPIPMTR_NOTIFY_CAP            0x80
+#define ACPIPMTR_NOTIFY_TRIP           0x81
+#define ACPIPMTR_NOTIFY_HWLIMIT1       0x82
+#define ACPIPMTR_NOTIFY_HWLIMIT2       0x83
+#define ACPIPMTR_NOTIFY_INTERVAL       0x84
+
+struct acpipmtr_softc {
+       device_t                 sc_dev;
+       struct acpi_devnode     *sc_node;
+       struct sysmon_envsys    *sc_sme;
+       envsys_data_t            sc_sensor_i;
+       envsys_data_t            sc_sensor_o;
+       uint32_t                 sc_cap[ACPIPMTR_CAP_COUNT];
+       int32_t                  sc_interval;
+};
+
+const char * const acpi_pmtr_ids[] = {
+       "ACPI000D",
+       NULL
+};
+
+static int     acpipmtr_match(device_t, cfdata_t, void *);
+static void    acpipmtr_attach(device_t, device_t, void *);
+static int     acpipmtr_detach(device_t, int);
+static bool    acpipmtr_cap_get(device_t, bool);
+static bool    acpipmtr_dev_print(device_t);



Home | Main Index | Thread Index | Old Index