diff options
author | Alexey Starikovskiy <astarikovskiy@suse.de> | 2009-03-27 22:23:52 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2009-03-27 22:23:52 -0400 |
commit | 7faa144a518c456e2057918f030f50100144ccc6 (patch) | |
tree | 4f1a9406419ba486386b460164e3afb270a0beb5 | |
parent | 8e0ee43bc2c3e19db56a4adaa9a9b04ce885cd84 (diff) |
ACPI: battery: add power_{now,avg} properties to power_class
ACPI has smart batteries, which work in units of energy and measure
rate of (dis)charge as power, thus it is not appropriate to export it
as a current_now. Current_now will still be exported to allow
for userland applications to match.
Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r-- | drivers/acpi/battery.c | 12 | ||||
-rw-r--r-- | drivers/acpi/sbs.c | 27 | ||||
-rw-r--r-- | drivers/power/power_supply_sysfs.c | 2 | ||||
-rw-r--r-- | include/linux/power_supply.h | 2 |
4 files changed, 27 insertions, 16 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 69cbc57c2d1c..09a2240d5605 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -92,7 +92,7 @@ struct acpi_battery { | |||
92 | #endif | 92 | #endif |
93 | struct acpi_device *device; | 93 | struct acpi_device *device; |
94 | unsigned long update_time; | 94 | unsigned long update_time; |
95 | int current_now; | 95 | int rate_now; |
96 | int capacity_now; | 96 | int capacity_now; |
97 | int voltage_now; | 97 | int voltage_now; |
98 | int design_capacity; | 98 | int design_capacity; |
@@ -196,7 +196,8 @@ static int acpi_battery_get_property(struct power_supply *psy, | |||
196 | val->intval = battery->voltage_now * 1000; | 196 | val->intval = battery->voltage_now * 1000; |
197 | break; | 197 | break; |
198 | case POWER_SUPPLY_PROP_CURRENT_NOW: | 198 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
199 | val->intval = battery->current_now * 1000; | 199 | case POWER_SUPPLY_PROP_POWER_NOW: |
200 | val->intval = battery->rate_now * 1000; | ||
200 | break; | 201 | break; |
201 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: | 202 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: |
202 | case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: | 203 | case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: |
@@ -247,6 +248,7 @@ static enum power_supply_property energy_battery_props[] = { | |||
247 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, | 248 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, |
248 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | 249 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
249 | POWER_SUPPLY_PROP_CURRENT_NOW, | 250 | POWER_SUPPLY_PROP_CURRENT_NOW, |
251 | POWER_SUPPLY_PROP_POWER_NOW, | ||
250 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, | 252 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, |
251 | POWER_SUPPLY_PROP_ENERGY_FULL, | 253 | POWER_SUPPLY_PROP_ENERGY_FULL, |
252 | POWER_SUPPLY_PROP_ENERGY_NOW, | 254 | POWER_SUPPLY_PROP_ENERGY_NOW, |
@@ -273,7 +275,7 @@ struct acpi_offsets { | |||
273 | 275 | ||
274 | static struct acpi_offsets state_offsets[] = { | 276 | static struct acpi_offsets state_offsets[] = { |
275 | {offsetof(struct acpi_battery, state), 0}, | 277 | {offsetof(struct acpi_battery, state), 0}, |
276 | {offsetof(struct acpi_battery, current_now), 0}, | 278 | {offsetof(struct acpi_battery, rate_now), 0}, |
277 | {offsetof(struct acpi_battery, capacity_now), 0}, | 279 | {offsetof(struct acpi_battery, capacity_now), 0}, |
278 | {offsetof(struct acpi_battery, voltage_now), 0}, | 280 | {offsetof(struct acpi_battery, voltage_now), 0}, |
279 | }; | 281 | }; |
@@ -605,11 +607,11 @@ static int acpi_battery_print_state(struct seq_file *seq, int result) | |||
605 | else | 607 | else |
606 | seq_printf(seq, "charging state: charged\n"); | 608 | seq_printf(seq, "charging state: charged\n"); |
607 | 609 | ||
608 | if (battery->current_now == ACPI_BATTERY_VALUE_UNKNOWN) | 610 | if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN) |
609 | seq_printf(seq, "present rate: unknown\n"); | 611 | seq_printf(seq, "present rate: unknown\n"); |
610 | else | 612 | else |
611 | seq_printf(seq, "present rate: %d %s\n", | 613 | seq_printf(seq, "present rate: %d %s\n", |
612 | battery->current_now, acpi_battery_units(battery)); | 614 | battery->rate_now, acpi_battery_units(battery)); |
613 | 615 | ||
614 | if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN) | 616 | if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN) |
615 | seq_printf(seq, "remaining capacity: unknown\n"); | 617 | seq_printf(seq, "remaining capacity: unknown\n"); |
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index 6050ce481873..3963cb6e0f19 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c | |||
@@ -102,8 +102,8 @@ struct acpi_battery { | |||
102 | u16 cycle_count; | 102 | u16 cycle_count; |
103 | u16 temp_now; | 103 | u16 temp_now; |
104 | u16 voltage_now; | 104 | u16 voltage_now; |
105 | s16 current_now; | 105 | s16 rate_now; |
106 | s16 current_avg; | 106 | s16 rate_avg; |
107 | u16 capacity_now; | 107 | u16 capacity_now; |
108 | u16 state_of_charge; | 108 | u16 state_of_charge; |
109 | u16 state; | 109 | u16 state; |
@@ -202,9 +202,9 @@ static int acpi_sbs_battery_get_property(struct power_supply *psy, | |||
202 | return -ENODEV; | 202 | return -ENODEV; |
203 | switch (psp) { | 203 | switch (psp) { |
204 | case POWER_SUPPLY_PROP_STATUS: | 204 | case POWER_SUPPLY_PROP_STATUS: |
205 | if (battery->current_now < 0) | 205 | if (battery->rate_now < 0) |
206 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; | 206 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; |
207 | else if (battery->current_now > 0) | 207 | else if (battery->rate_now > 0) |
208 | val->intval = POWER_SUPPLY_STATUS_CHARGING; | 208 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
209 | else | 209 | else |
210 | val->intval = POWER_SUPPLY_STATUS_FULL; | 210 | val->intval = POWER_SUPPLY_STATUS_FULL; |
@@ -224,11 +224,13 @@ static int acpi_sbs_battery_get_property(struct power_supply *psy, | |||
224 | acpi_battery_vscale(battery) * 1000; | 224 | acpi_battery_vscale(battery) * 1000; |
225 | break; | 225 | break; |
226 | case POWER_SUPPLY_PROP_CURRENT_NOW: | 226 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
227 | val->intval = abs(battery->current_now) * | 227 | case POWER_SUPPLY_PROP_POWER_NOW: |
228 | val->intval = abs(battery->rate_now) * | ||
228 | acpi_battery_ipscale(battery) * 1000; | 229 | acpi_battery_ipscale(battery) * 1000; |
229 | break; | 230 | break; |
230 | case POWER_SUPPLY_PROP_CURRENT_AVG: | 231 | case POWER_SUPPLY_PROP_CURRENT_AVG: |
231 | val->intval = abs(battery->current_avg) * | 232 | case POWER_SUPPLY_PROP_POWER_AVG: |
233 | val->intval = abs(battery->rate_avg) * | ||
232 | acpi_battery_ipscale(battery) * 1000; | 234 | acpi_battery_ipscale(battery) * 1000; |
233 | break; | 235 | break; |
234 | case POWER_SUPPLY_PROP_CAPACITY: | 236 | case POWER_SUPPLY_PROP_CAPACITY: |
@@ -293,6 +295,8 @@ static enum power_supply_property sbs_energy_battery_props[] = { | |||
293 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | 295 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
294 | POWER_SUPPLY_PROP_CURRENT_NOW, | 296 | POWER_SUPPLY_PROP_CURRENT_NOW, |
295 | POWER_SUPPLY_PROP_CURRENT_AVG, | 297 | POWER_SUPPLY_PROP_CURRENT_AVG, |
298 | POWER_SUPPLY_PROP_POWER_NOW, | ||
299 | POWER_SUPPLY_PROP_POWER_AVG, | ||
296 | POWER_SUPPLY_PROP_CAPACITY, | 300 | POWER_SUPPLY_PROP_CAPACITY, |
297 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, | 301 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, |
298 | POWER_SUPPLY_PROP_ENERGY_FULL, | 302 | POWER_SUPPLY_PROP_ENERGY_FULL, |
@@ -301,6 +305,7 @@ static enum power_supply_property sbs_energy_battery_props[] = { | |||
301 | POWER_SUPPLY_PROP_MODEL_NAME, | 305 | POWER_SUPPLY_PROP_MODEL_NAME, |
302 | POWER_SUPPLY_PROP_MANUFACTURER, | 306 | POWER_SUPPLY_PROP_MANUFACTURER, |
303 | }; | 307 | }; |
308 | |||
304 | #endif | 309 | #endif |
305 | 310 | ||
306 | /* -------------------------------------------------------------------------- | 311 | /* -------------------------------------------------------------------------- |
@@ -330,8 +335,8 @@ static struct acpi_battery_reader info_readers[] = { | |||
330 | static struct acpi_battery_reader state_readers[] = { | 335 | static struct acpi_battery_reader state_readers[] = { |
331 | {0x08, SMBUS_READ_WORD, offsetof(struct acpi_battery, temp_now)}, | 336 | {0x08, SMBUS_READ_WORD, offsetof(struct acpi_battery, temp_now)}, |
332 | {0x09, SMBUS_READ_WORD, offsetof(struct acpi_battery, voltage_now)}, | 337 | {0x09, SMBUS_READ_WORD, offsetof(struct acpi_battery, voltage_now)}, |
333 | {0x0a, SMBUS_READ_WORD, offsetof(struct acpi_battery, current_now)}, | 338 | {0x0a, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_now)}, |
334 | {0x0b, SMBUS_READ_WORD, offsetof(struct acpi_battery, current_avg)}, | 339 | {0x0b, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_avg)}, |
335 | {0x0f, SMBUS_READ_WORD, offsetof(struct acpi_battery, capacity_now)}, | 340 | {0x0f, SMBUS_READ_WORD, offsetof(struct acpi_battery, capacity_now)}, |
336 | {0x0e, SMBUS_READ_WORD, offsetof(struct acpi_battery, state_of_charge)}, | 341 | {0x0e, SMBUS_READ_WORD, offsetof(struct acpi_battery, state_of_charge)}, |
337 | {0x16, SMBUS_READ_WORD, offsetof(struct acpi_battery, state)}, | 342 | {0x16, SMBUS_READ_WORD, offsetof(struct acpi_battery, state)}, |
@@ -589,9 +594,9 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) | |||
589 | seq_printf(seq, "capacity state: %s\n", | 594 | seq_printf(seq, "capacity state: %s\n", |
590 | (battery->state & 0x0010) ? "critical" : "ok"); | 595 | (battery->state & 0x0010) ? "critical" : "ok"); |
591 | seq_printf(seq, "charging state: %s\n", | 596 | seq_printf(seq, "charging state: %s\n", |
592 | (battery->current_now < 0) ? "discharging" : | 597 | (battery->rate_now < 0) ? "discharging" : |
593 | ((battery->current_now > 0) ? "charging" : "charged")); | 598 | ((battery->rate_now > 0) ? "charging" : "charged")); |
594 | rate = abs(battery->current_now) * acpi_battery_ipscale(battery); | 599 | rate = abs(battery->rate_now) * acpi_battery_ipscale(battery); |
595 | rate *= (acpi_battery_mode(battery))?(battery->voltage_now * | 600 | rate *= (acpi_battery_mode(battery))?(battery->voltage_now * |
596 | acpi_battery_vscale(battery)/1000):1; | 601 | acpi_battery_vscale(battery)/1000):1; |
597 | seq_printf(seq, "present rate: %d%s\n", rate, | 602 | seq_printf(seq, "present rate: %d%s\n", rate, |
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c index ac01e06817fb..da73591017f9 100644 --- a/drivers/power/power_supply_sysfs.c +++ b/drivers/power/power_supply_sysfs.c | |||
@@ -93,6 +93,8 @@ static struct device_attribute power_supply_attrs[] = { | |||
93 | POWER_SUPPLY_ATTR(voltage_avg), | 93 | POWER_SUPPLY_ATTR(voltage_avg), |
94 | POWER_SUPPLY_ATTR(current_now), | 94 | POWER_SUPPLY_ATTR(current_now), |
95 | POWER_SUPPLY_ATTR(current_avg), | 95 | POWER_SUPPLY_ATTR(current_avg), |
96 | POWER_SUPPLY_ATTR(power_now), | ||
97 | POWER_SUPPLY_ATTR(power_avg), | ||
96 | POWER_SUPPLY_ATTR(charge_full_design), | 98 | POWER_SUPPLY_ATTR(charge_full_design), |
97 | POWER_SUPPLY_ATTR(charge_empty_design), | 99 | POWER_SUPPLY_ATTR(charge_empty_design), |
98 | POWER_SUPPLY_ATTR(charge_full), | 100 | POWER_SUPPLY_ATTR(charge_full), |
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 8ff25e0e7f7a..594c494ac3f0 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h | |||
@@ -73,6 +73,8 @@ enum power_supply_property { | |||
73 | POWER_SUPPLY_PROP_VOLTAGE_AVG, | 73 | POWER_SUPPLY_PROP_VOLTAGE_AVG, |
74 | POWER_SUPPLY_PROP_CURRENT_NOW, | 74 | POWER_SUPPLY_PROP_CURRENT_NOW, |
75 | POWER_SUPPLY_PROP_CURRENT_AVG, | 75 | POWER_SUPPLY_PROP_CURRENT_AVG, |
76 | POWER_SUPPLY_PROP_POWER_NOW, | ||
77 | POWER_SUPPLY_PROP_POWER_AVG, | ||
76 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | 78 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
77 | POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, | 79 | POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, |
78 | POWER_SUPPLY_PROP_CHARGE_FULL, | 80 | POWER_SUPPLY_PROP_CHARGE_FULL, |