Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Cleanup:



details:   https://anonhg.NetBSD.org/src/rev/a130ed546244
branches:  trunk
changeset: 751060:a130ed546244
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sat Jan 23 15:06:47 2010 +0000

description:
Cleanup:

  * Remove ACPI_BAT_DEBUG.
  * Reduce the amount of error reporting.
  * Remove the internal bookkeeping flags.
  * Remove the debugging functions used to print status and information
    changes. This information is fully conveyed in the output of envstat(8).
  * Always evaluate _STA. If it fails or the battery is not present, mark
    all remaining sensors as invalid. This will eliminate the convoluted
    update routine.
  * Semantics.

Over 200 LOC was eliminated, but functional change should again be minimal.

ok jmcneill@, pgoyette@

diffstat:

 sys/dev/acpi/acpi_bat.c |  480 +++++++++++++----------------------------------
 1 files changed, 133 insertions(+), 347 deletions(-)

diffs (truncated from 707 to 300 lines):

diff -r 98a8cdf5ae2f -r a130ed546244 sys/dev/acpi/acpi_bat.c
--- a/sys/dev/acpi/acpi_bat.c   Sat Jan 23 13:32:45 2010 +0000
+++ b/sys/dev/acpi/acpi_bat.c   Sat Jan 23 15:06:47 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_bat.c,v 1.76 2010/01/21 08:57:17 jruoho Exp $     */
+/*     $NetBSD: acpi_bat.c,v 1.77 2010/01/23 15:06:47 jruoho Exp $     */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -62,10 +62,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if 0
-#define ACPI_BAT_DEBUG
-#endif
-
 /*
  * ACPI Battery Driver.
  *
@@ -79,21 +75,22 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.76 2010/01/21 08:57:17 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.77 2010/01/23 15:06:47 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>                /* for hz */
 #include <sys/device.h>
 #include <sys/mutex.h>
+
 #include <dev/sysmon/sysmonvar.h>
 
 #include <dev/acpi/acpica.h>
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
 
-#define _COMPONENT          ACPI_BAT_COMPONENT
-ACPI_MODULE_NAME            ("acpi_bat")
+#define _COMPONENT              ACPI_BAT_COMPONENT
+ACPI_MODULE_NAME                ("acpi_bat")
 
 /*
  * Sensor indexes.
@@ -149,16 +146,12 @@
 };
 
 struct acpibat_softc {
-       struct acpi_devnode *sc_node;   /* our ACPI devnode */
-       int sc_flags;                   /* see below */
-       int sc_available;               /* available information level */
-
-       struct sysmon_envsys *sc_sme;
-       envsys_data_t sc_sensor[ACPIBAT_COUNT];
-       struct timeval sc_lastupdate;
-
-       kmutex_t sc_mutex;
-       kcondvar_t sc_condvar;
+       struct acpi_devnode     *sc_node;
+       struct sysmon_envsys    *sc_sme;
+       struct timeval           sc_lastupdate;
+       envsys_data_t            sc_sensor[ACPIBAT_COUNT];
+       kmutex_t                 sc_mutex;
+       kcondvar_t               sc_condvar;
 };
 
 static const char * const bat_hid[] = {
@@ -166,16 +159,7 @@
        NULL
 };
 
-/*
- * These flags are used to examine the battery device data returned from
- * the ACPI interface, specifically the "battery status"
- */
 #define ACPIBAT_PWRUNIT_MA     0x00000001  /* mA not mW */
-
-/*
- * These flags are used to examine the battery charge/discharge/critical
- * state returned from a get-status command.
- */
 #define ACPIBAT_ST_DISCHARGING 0x00000001  /* battery is discharging */
 #define ACPIBAT_ST_CHARGING    0x00000002  /* battery is charging */
 #define ACPIBAT_ST_CRITICAL    0x00000004  /* battery is critical */
@@ -201,50 +185,22 @@
 #define ACPIBAT_VAL_ISVALID(x)                                               \
        (((x) != ACPIBAT_VAL_UNKNOWN) ? ENVSYS_SVALID : ENVSYS_SINVALID)
 
-/*
- * These flags are used to set internal state in our softc.
- */
-#define        ABAT_F_VERBOSE          0x01    /* verbose events */
-#define ABAT_F_PWRUNIT_MA      0x02    /* mA instead of mW */
-#define ABAT_F_PRESENT         0x04    /* is the battery present? */
-
-#define ABAT_SET(sc, f)                (void)((sc)->sc_flags |= (f))
-#define ABAT_CLEAR(sc, f)      (void)((sc)->sc_flags &= ~(f))
-#define ABAT_ISSET(sc, f)      ((sc)->sc_flags & (f))
-
-/*
- * Available info level
- */
-
-#define ABAT_ALV_NONE          0       /* none is available */
-#define ABAT_ALV_PRESENCE      1       /* presence info is available */
-#define ABAT_ALV_INFO          2       /* battery info is available */
-#define ABAT_ALV_STAT          3       /* battery status is available */
-
-static int     acpibat_match(device_t, cfdata_t, void *);
-static void    acpibat_attach(device_t, device_t, void *);
-static bool    acpibat_resume(device_t, pmf_qual_t);
+static int         acpibat_match(device_t, cfdata_t, void *);
+static void        acpibat_attach(device_t, device_t, void *);
+static int          acpibat_get_sta(device_t);
+static ACPI_OBJECT *acpibat_get_object(ACPI_HANDLE, const char *, int);
+static void         acpibat_get_info(device_t);
+static void         acpibat_get_status(device_t);
+static void         acpibat_update_info(void *);
+static void         acpibat_update_status(void *);
+static void         acpibat_init_envsys(device_t);
+static void         acpibat_notify_handler(ACPI_HANDLE, UINT32, void *);
+static void         acpibat_refresh(struct sysmon_envsys *, envsys_data_t *);
+static bool        acpibat_resume(device_t, pmf_qual_t);
 
 CFATTACH_DECL_NEW(acpibat, sizeof(struct acpibat_softc),
     acpibat_match, acpibat_attach, NULL, NULL);
 
-static void acpibat_clear_presence(struct acpibat_softc *);
-static void acpibat_clear_info(struct acpibat_softc *);
-static void acpibat_clear_stat(struct acpibat_softc *);
-static int acpibat_battery_present(device_t);
-static ACPI_OBJECT *acpibat_get_object(ACPI_HANDLE, const char *, int);
-static ACPI_STATUS acpibat_get_status(device_t);
-static ACPI_STATUS acpibat_get_info(device_t);
-static void acpibat_print_info(device_t);
-static void acpibat_print_stat(device_t);
-static void acpibat_update(void *);
-static void acpibat_update_info(void *);
-static void acpibat_update_stat(void *);
-
-static void acpibat_init_envsys(device_t);
-static void acpibat_notify_handler(ACPI_HANDLE, UINT32, void *);
-static void acpibat_refresh(struct sysmon_envsys *, envsys_data_t *);
-
 /*
  * acpibat_match:
  *
@@ -261,23 +217,6 @@
        return acpi_match_hid(aa->aa_node->ad_devinfo, bat_hid);
 }
 
-static bool
-acpibat_resume(device_t dv, pmf_qual_t qual)
-{
-       ACPI_STATUS rv;
-
-       rv = AcpiOsExecute(OSL_NOTIFY_HANDLER, acpibat_update_stat, dv);
-       if (ACPI_FAILURE(rv))
-               aprint_error_dev(dv, "unable to queue status check: %s\n",
-                   AcpiFormatException(rv));
-       rv = AcpiOsExecute(OSL_NOTIFY_HANDLER, acpibat_update_info, dv);
-       if (ACPI_FAILURE(rv))
-               aprint_error_dev(dv, "unable to queue info check: %s\n",
-                   AcpiFormatException(rv));
-
-       return true;
-}
-
 /*
  * acpibat_attach:
  *
@@ -290,109 +229,54 @@
        struct acpi_attach_args *aa = aux;
        ACPI_STATUS rv;
 
-       aprint_naive(": ACPI Battery (Control Method)\n");
-       aprint_normal(": ACPI Battery (Control Method)\n");
+       aprint_naive(": ACPI Battery\n");
+       aprint_normal(": ACPI Battery\n");
 
        sc->sc_node = aa->aa_node;
 
        mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
        cv_init(&sc->sc_condvar, device_xname(self));
 
-       rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-                                     ACPI_ALL_NOTIFY,
-                                     acpibat_notify_handler, self);
-       if (ACPI_FAILURE(rv)) {
-               aprint_error_dev(self,
-                   "unable to register DEVICE/SYSTEM NOTIFY handler: %s\n",
-                   AcpiFormatException(rv));
-               return;
-       }
-
-#ifdef ACPI_BAT_DEBUG
-       ABAT_SET(sc, ABAT_F_VERBOSE);
-#endif
-
-       if (!pmf_device_register(self, NULL, acpibat_resume))
+       if (pmf_device_register(self, NULL, acpibat_resume) != true)
                aprint_error_dev(self, "couldn't establish power handler\n");
 
-       acpibat_init_envsys(self);
+       rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
+           ACPI_ALL_NOTIFY, acpibat_notify_handler, self);
+
+       if (ACPI_SUCCESS(rv))
+               acpibat_init_envsys(self);
+       else
+               aprint_error_dev(self, "couldn't install notify handler\n");
 }
 
 /*
- * clear informations
- */
-
-static void
-acpibat_clear_presence(struct acpibat_softc *sc)
-{
-       acpibat_clear_info(sc);
-       sc->sc_available = ABAT_ALV_NONE;
-       ABAT_CLEAR(sc, ABAT_F_PRESENT);
-}
-
-static void
-acpibat_clear_info(struct acpibat_softc *sc)
-{
-       acpibat_clear_stat(sc);
-       if (sc->sc_available > ABAT_ALV_PRESENCE)
-               sc->sc_available = ABAT_ALV_PRESENCE;
-
-       sc->sc_sensor[ACPIBAT_DCAPACITY].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_LFCCAPACITY].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_CAPACITY].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_TECHNOLOGY].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_DVOLTAGE].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_WCAPACITY].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_LCAPACITY].state = ENVSYS_SINVALID;
-}
-
-static void
-acpibat_clear_stat(struct acpibat_softc *sc)
-{
-       if (sc->sc_available > ABAT_ALV_INFO)
-               sc->sc_available = ABAT_ALV_INFO;
-
-       sc->sc_sensor[ACPIBAT_CHARGERATE].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_DISCHARGERATE].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_CAPACITY].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_VOLTAGE].state = ENVSYS_SINVALID;
-       sc->sc_sensor[ACPIBAT_CHARGING].state = ENVSYS_SINVALID;
-}
-
-/*
- * acpibat_battery_present:
+ * acpibat_get_sta:
  *
  *     Evaluate whether the battery is present or absent.
  *
  *     Returns: 0 for no battery, 1 for present, and -1 on error.
  */
 static int
-acpibat_battery_present(device_t dv)
+acpibat_get_sta(device_t dv)
 {
        struct acpibat_softc *sc = device_private(dv);
        ACPI_INTEGER val;
        ACPI_STATUS rv;
-       uint32_t sta;
 
        rv = acpi_eval_integer(sc->sc_node->ad_handle, "_STA", &val);
 
        if (ACPI_FAILURE(rv)) {
                aprint_error_dev(dv, "failed to evaluate _STA\n");
-               sc->sc_sensor[ACPIBAT_PRESENT].state = ENVSYS_SINVALID;
                return -1;
        }
 
-       sta = (uint32_t)val;
-
-       sc->sc_available = ABAT_ALV_PRESENCE;
        sc->sc_sensor[ACPIBAT_PRESENT].state = ENVSYS_SVALID;
 
-       if ((sta & ACPIBAT_STA_PRESENT) == 0) {
+       if ((val & ACPIBAT_STA_PRESENT) == 0) {
                sc->sc_sensor[ACPIBAT_PRESENT].value_cur = 0;
                return 0;
        }
 
-       ABAT_SET(sc, ABAT_F_PRESENT);
        sc->sc_sensor[ACPIBAT_PRESENT].value_cur = 1;
 
        return 1;
@@ -430,7 +314,7 @@
  *
  *     Get, and possibly display, the battery info.
  */



Home | Main Index | Thread Index | Old Index