Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi In revision 1.103 the serial number was used to...



details:   https://anonhg.NetBSD.org/src/rev/a675b94c0259
branches:  trunk
changeset: 767246:a675b94c0259
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Wed Jul 13 09:58:53 2011 +0000

description:
In revision 1.103 the serial number was used to determine whether the
battery was changed to another one. However, this is unreliable as many
vendors hardcode the serial number string in the DSDT. Thus, use the design
capacity and voltage instead; these are likely read from the battery itself.

diffstat:

 sys/dev/acpi/acpi_bat.c |  39 ++++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 19 deletions(-)

diffs (99 lines):

diff -r 044bd2a69ca6 -r a675b94c0259 sys/dev/acpi/acpi_bat.c
--- a/sys/dev/acpi/acpi_bat.c   Wed Jul 13 08:38:16 2011 +0000
+++ b/sys/dev/acpi/acpi_bat.c   Wed Jul 13 09:58:53 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_bat.c,v 1.110 2011/06/20 20:24:59 pgoyette Exp $  */
+/*     $NetBSD: acpi_bat.c,v 1.111 2011/07/13 09:58:53 jruoho Exp $    */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.110 2011/06/20 20:24:59 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.111 2011/07/13 09:58:53 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -150,9 +150,10 @@
        struct sysmon_envsys    *sc_sme;
        struct timeval           sc_last;
        envsys_data_t           *sc_sensor;
-       char                     sc_serial[64];
        kmutex_t                 sc_mutex;
        kcondvar_t               sc_condvar;
+       int32_t                  sc_dcapacity;
+       int32_t                  sc_dvoltage;
        int32_t                  sc_lcapacity;
        int32_t                  sc_wcapacity;
        int                      sc_present;
@@ -231,6 +232,8 @@
        sc->sc_node = aa->aa_node;
 
        sc->sc_present = 0;
+       sc->sc_dvoltage = 0;
+       sc->sc_dcapacity = 0;
        sc->sc_lcapacity = 0;
        sc->sc_wcapacity = 0;
 
@@ -241,7 +244,6 @@
        cv_init(&sc->sc_condvar, device_xname(self));
 
        (void)pmf_device_register(self, NULL, acpibat_resume);
-       (void)memset(sc->sc_serial, '\0', sizeof(sc->sc_serial));
        (void)acpi_register_notify(sc->sc_node, acpibat_notify_handler);
 
        sc->sc_sensor = kmem_zalloc(ACPIBAT_COUNT *
@@ -442,7 +444,8 @@
 acpibat_print_info(device_t dv, ACPI_OBJECT *elm)
 {
        struct acpibat_softc *sc = device_private(dv);
-       const char *model, *serial, *tech, *unit;
+       const char *tech, *unit;
+       int32_t dcap, dvol;
        int i;
 
        for (i = ACPIBAT_BIF_OEM; i > ACPIBAT_BIF_GRANULARITY2; i--) {
@@ -457,20 +460,17 @@
                        return;
        }
 
-       model = elm[ACPIBAT_BIF_MODEL].String.Pointer;
-       serial = elm[ACPIBAT_BIF_SERIAL].String.Pointer;
-
-       if (elm[ACPIBAT_BIF_SERIAL].String.Length > sizeof(sc->sc_serial))
-               return;
+       dcap = elm[ACPIBAT_BIF_DCAPACITY].Integer.Value;
+       dvol = elm[ACPIBAT_BIF_DVOLTAGE].Integer.Value;
 
-       if (sc->sc_serial[0] == '\0')
-               (void)strlcpy(sc->sc_serial, serial, sizeof(sc->sc_serial));
+       /*
+        * Try to detect whether the battery was switched.
+        */
+       if (sc->sc_dcapacity == dcap && sc->sc_dvoltage == dvol)
+               return;
        else {
-               if (strcmp(sc->sc_serial, serial) == 0)
-                       return;
-
-               (void)memset(sc->sc_serial, '\0', sizeof(sc->sc_serial));
-               (void)strlcpy(sc->sc_serial, serial, sizeof(sc->sc_serial));
+               sc->sc_dcapacity = dcap;
+               sc->sc_dvoltage = dvol;
        }
 
        tech = (elm[ACPIBAT_BIF_TECHNOLOGY].Integer.Value != 0) ?
@@ -480,8 +480,9 @@
            elm[ACPIBAT_BIF_OEM].String.Pointer,
            elm[ACPIBAT_BIF_TYPE].String.Pointer, tech);
 
-       aprint_verbose_dev(dv, "model number %s, serial number %s\n",
-           model, serial);
+       aprint_debug_dev(dv, "model number %s, serial number %s\n",
+           elm[ACPIBAT_BIF_MODEL].String.Pointer,
+           elm[ACPIBAT_BIF_SERIAL].String.Pointer);
 
 #define SCALE(x) (((int)x) / 1000000), ((((int)x) % 1000000) / 1000)
 



Home | Main Index | Thread Index | Old Index