/*
* Copyright 2009, Intel Corporation
* Copyright 2009, Sun Microsystems, Inc
*
* This file is part of PowerTOP
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file named COPYING; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authors:
* Arjan van de Ven <arjan@linux.intel.com>
* Eric C Saxe <eric.saxe@sun.com>
* Aubrey Li <aubrey.li@intel.com>
*/
/*
* GPL Disclaimer
*
* For the avoidance of doubt, except that if any license choice other
* than GPL or LGPL is available it will apply instead, Sun elects to
* use only the General Public License version 2 (GPLv2) at this time
* for any software where a choice of GPL license versions is made
* available with the language indicating that GPLv2 or any later
* version may be used, or where a choice of which version of the GPL
* is applied is otherwise unspecified.
*/
#include <string.h>
#include <kstat.h>
#include <errno.h>
#include "powertop.h"
typedef struct battery_state {
double present_rate;
double remain_cap;
double last_cap;
static int pt_battery_stat_snapshot(void);
/*
* Checks if the kstat module for battery information is present and
* whether it's called 'battery' or 'acpi_drv'
*/
void
pt_battery_mod_lookup(void)
{
kstat_batt_idx = 1;
else
kstat_batt_idx = 2;
else
kstat_batt_idx = 0;
(void) kstat_close(kc);
}
void
pt_battery_print(void)
{
int err;
/*
* The return value of pt_battery_stat_snapshot() can be used for
* make the distinction of a system that runs only on AC and one
* that runs on battery but has no kstat battery info.
*
* We still display the estimate power usage for systems
* running on AC with a fully charged battery because some
* batteries may still consume power.
*
* If pt_battery_mod_lookup() didn't find a kstat battery module, don't
* bother trying to take the snapshot
*/
if (kstat_batt_idx > 0) {
if ((err = pt_battery_stat_snapshot()) < 0)
}
}
static int
pt_battery_stat_snapshot(void)
{
kc = kstat_open();
/*
* power unit:
* 0 - Capacity information is reported in [mWh] and
* 1 - Capacity information is reported in [mAh] and
*/
"battery BIF0");
(void) kstat_close(kc);
return (-1);
}
(void) kstat_close(kc);
return (-1);
}
/*
* Present rate:
* the power or current being supplied or accepted
* through the battery's terminal
*/
"battery BST0");
(void) kstat_close(kc);
return (-1);
}
(void) kstat_close(kc);
return (-1);
}
else {
}
/*
* Last Full charge capacity:
* Predicted battery capacity when fully charged.
*/
"battery BIF0");
(void) kstat_close(kc);
return (-1);
}
(void) kstat_close(kc);
return (-1);
}
/*
* Remaining capacity:
* the estimated remaining battery capacity
*/
"battery BST0");
(void) kstat_close(kc);
return (-1);
}
(void) kstat_close(kc);
return (-1);
}
/*
* Battery State:
* Bit0 - 1 : discharging
* Bit1 - 1 : charging
* Bit2 - 1 : critical energy state
*/
"battery BST0");
(void) kstat_close(kc);
return (-1);
}
(void) kstat_close(kc);
return (-1);
}
(void) kstat_close(kc);
return (0);
}