1 --- cpufreqd-2.4.2/src/cpufreqd_acpi_battery.c 2010-03-28 04:34:54.000000000 -0700
2 +++ cpufreqd-2.4.2/src/cpufreqd_acpi_battery.c 2010-11-21 18:51:32.000000000 -0800
5 #define POWER_SUPPLY "power_supply"
6 #define BATTERY_TYPE "Battery"
7 +#define PRESENT "present"
8 +#define STATUS "status"
9 +//energy batter properties
10 #define ENERGY_FULL "energy_full"
11 #define ENERGY_NOW "energy_now"
12 +#define POWER_NOW "power_now"
13 +//charge battery properties
14 #define CHARGE_FULL "charge_full"
15 #define CHARGE_NOW "charge_now"
16 -#define PRESENT "present"
17 -#define STATUS "status"
18 #define CURRENT_NOW "current_now"
24 struct sysfs_class_device *cdev;
25 - struct sysfs_attribute *energy_full; /* last full capacity */
26 - struct sysfs_attribute *energy_now; /* remaining capacity */
27 + struct sysfs_attribute *full_capacity; /* last full capacity */
28 + struct sysfs_attribute *remaining_capacity; /* remaining capacity */
29 struct sysfs_attribute *present;
30 struct sysfs_attribute *status;
31 - struct sysfs_attribute *current_now; /* present rate */
32 + struct sysfs_attribute *draw_rate; /* present rate */
38 if (!binfo->open) return;
40 - if (binfo->energy_full)
41 - put_attribute(binfo->energy_full);
42 - if (binfo->energy_now)
43 - put_attribute(binfo->energy_now);
44 + if (binfo->full_capacity)
45 + put_attribute(binfo->full_capacity);
46 + if (binfo->remaining_capacity)
47 + put_attribute(binfo->remaining_capacity);
49 put_attribute(binfo->present);
51 put_attribute(binfo->status);
52 - if (binfo->current_now)
53 - put_attribute(binfo->current_now);
54 + if (binfo->draw_rate)
55 + put_attribute(binfo->draw_rate);
60 static int read_battery(struct battery_info *binfo) {
61 clog(LOG_DEBUG, "%s - reading battery levels\n", binfo->cdev->name);
63 - if (read_int(binfo->current_now, &binfo->present_rate) != 0) {
64 + if (read_int(binfo->draw_rate, &binfo->present_rate) != 0) {
65 clog(LOG_ERR, "Skipping %s\n", binfo->cdev->name);
68 - if (read_int(binfo->energy_now, &binfo->remaining) != 0) {
69 + if (read_int(binfo->remaining_capacity, &binfo->remaining) != 0) {
70 clog(LOG_ERR, "Skipping %s\n", binfo->cdev->name);
74 binfo->cdev->name, binfo->remaining);
78 +/* open energy battery specific attributes */
79 +static int read_energy_battery_attributes(struct battery_info *binfo)
81 + binfo->full_capacity = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
82 + if(!binfo->full_capacity)
87 + binfo->remaining_capacity = get_class_device_attribute(binfo->cdev, ENERGY_NOW);
88 + if(!binfo->remaining_capacity)
93 + binfo->draw_rate = get_class_device_attribute(binfo->cdev, POWER_NOW);
94 + if(!binfo->draw_rate)
102 +/* open charge battery specific attributes */
103 +static int read_charge_battery_attributes(struct battery_info *binfo)
105 + binfo->full_capacity = get_class_device_attribute(binfo->cdev, CHARGE_FULL);
106 + if(!binfo->full_capacity)
111 + binfo->remaining_capacity = get_class_device_attribute(binfo->cdev, CHARGE_NOW);
112 + if(!binfo->remaining_capacity)
117 + binfo->draw_rate = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
118 + if(!binfo->draw_rate)
126 /* open all the required attributes and set the open status */
127 static int open_battery(struct battery_info *binfo) {
130 - binfo->energy_full = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
131 - if (!binfo->energy_full) {
132 - /* try the "charge_full" name */
133 - binfo->energy_full = get_class_device_attribute(binfo->cdev,
135 - if (!binfo->energy_full)
136 + //attempt to open energy attribute
137 + struct sysfs_attribute *tmp_attribute = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
141 + if(read_charge_battery_attributes(binfo) != 0)
146 - binfo->energy_now = get_class_device_attribute(binfo->cdev, ENERGY_NOW);
147 - if (!binfo->energy_now) {
148 - /* try the "charge_now" name */
149 - binfo->energy_now = get_class_device_attribute(binfo->cdev, CHARGE_NOW);
150 - if (!binfo->energy_now)
153 + put_attribute(tmp_attribute);
154 + if(read_energy_battery_attributes(binfo) != 0)
160 binfo->present = get_class_device_attribute(binfo->cdev, PRESENT);
163 binfo->status = get_class_device_attribute(binfo->cdev, STATUS);
166 - binfo->current_now = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
167 - if (!binfo->current_now)
170 /* read the last full capacity, this is not going to change
171 * very often, so no need to poke it later */
172 - if (read_int(binfo->energy_full, &binfo->capacity) != 0) {
173 + if (read_int(binfo->full_capacity, &binfo->capacity) != 0) {
174 clog(LOG_WARNING, "Couldn't read %s capacity (%s)\n",
175 binfo->cdev->name, strerror(errno));