Sat Apr 3 16:29:22 2010 UTC ()
Update the limits when a change from absent to present is detected.


(jruoho)
diff -r1.97 -r1.98 src/sys/dev/acpi/acpi_bat.c

cvs diff -r1.97 -r1.98 src/sys/dev/acpi/acpi_bat.c (expand / switch to unified diff)

--- src/sys/dev/acpi/acpi_bat.c 2010/03/26 15:51:55 1.97
+++ src/sys/dev/acpi/acpi_bat.c 2010/04/03 16:29:22 1.98
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: acpi_bat.c,v 1.97 2010/03/26 15:51:55 pooka Exp $ */ 1/* $NetBSD: acpi_bat.c,v 1.98 2010/04/03 16:29:22 jruoho Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum of By Noon Software, Inc. 8 * by Charles M. Hannum of By Noon Software, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -65,27 +65,27 @@ @@ -65,27 +65,27 @@
65/* 65/*
66 * ACPI Battery Driver. 66 * ACPI Battery Driver.
67 * 67 *
68 * ACPI defines two different battery device interfaces: "Control 68 * ACPI defines two different battery device interfaces: "Control
69 * Method" batteries, in which AML methods are defined in order to get 69 * Method" batteries, in which AML methods are defined in order to get
70 * battery status and set battery alarm thresholds, and a "Smart 70 * battery status and set battery alarm thresholds, and a "Smart
71 * Battery" device, which is an SMbus device accessed through the ACPI 71 * Battery" device, which is an SMbus device accessed through the ACPI
72 * Embedded Controller device. 72 * Embedded Controller device.
73 * 73 *
74 * This driver is for the "Control Method"-style battery only. 74 * This driver is for the "Control Method"-style battery only.
75 */ 75 */
76 76
77#include <sys/cdefs.h> 77#include <sys/cdefs.h>
78__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.97 2010/03/26 15:51:55 pooka Exp $"); 78__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.98 2010/04/03 16:29:22 jruoho Exp $");
79 79
80#include <sys/param.h> 80#include <sys/param.h>
81#include <sys/condvar.h> 81#include <sys/condvar.h>
82#include <sys/device.h> 82#include <sys/device.h>
83#include <sys/kernel.h> 83#include <sys/kernel.h>
84#include <sys/kmem.h> 84#include <sys/kmem.h>
85#include <sys/module.h> 85#include <sys/module.h>
86#include <sys/mutex.h> 86#include <sys/mutex.h>
87#include <sys/systm.h> 87#include <sys/systm.h>
88 88
89#include <dev/acpi/acpireg.h> 89#include <dev/acpi/acpireg.h>
90#include <dev/acpi/acpivar.h> 90#include <dev/acpi/acpivar.h>
91 91
@@ -580,29 +580,37 @@ out: @@ -580,29 +580,37 @@ out:
580} 580}
581 581
582static void 582static void
583acpibat_update_info(void *arg) 583acpibat_update_info(void *arg)
584{ 584{
585 device_t dv = arg; 585 device_t dv = arg;
586 struct acpibat_softc *sc = device_private(dv); 586 struct acpibat_softc *sc = device_private(dv);
587 int i, rv; 587 int i, rv;
588 588
589 mutex_enter(&sc->sc_mutex); 589 mutex_enter(&sc->sc_mutex);
590 590
591 rv = acpibat_get_sta(dv); 591 rv = acpibat_get_sta(dv);
592 592
593 if (rv > 0) 593 if (rv > 0) {
594 acpibat_get_info(dv); 594 acpibat_get_info(dv);
595 else { 595
 596 /*
 597 * If the status changed, update the limits.
 598 */
 599 if (sc->sc_present == 0 &&
 600 sc->sc_sensor[ACPIBAT_CAPACITY].value_max > 0)
 601 sysmon_envsys_update_limits(sc->sc_sme,
 602 &sc->sc_sensor[ACPIBAT_CAPACITY]);
 603 } else {
596 i = (rv < 0) ? 0 : ACPIBAT_DVOLTAGE; 604 i = (rv < 0) ? 0 : ACPIBAT_DVOLTAGE;
597 605
598 while (i < ACPIBAT_COUNT) { 606 while (i < ACPIBAT_COUNT) {
599 sc->sc_sensor[i].state = ENVSYS_SINVALID; 607 sc->sc_sensor[i].state = ENVSYS_SINVALID;
600 i++; 608 i++;
601 } 609 }
602 } 610 }
603 611
604 sc->sc_present = rv; 612 sc->sc_present = rv;
605 613
606 mutex_exit(&sc->sc_mutex); 614 mutex_exit(&sc->sc_mutex);
607} 615}
608 616