1 From 57d1450b4e5f27fa78c75895dc30213bde7191bc Mon Sep 17 00:00:00 2001
2 From: Dmitry Baryshkov <dbaryshkov@gmail.com>
3 Date: Wed, 9 Jan 2008 02:08:18 +0300
4 Subject: [PATCH 29/64] Support using VOLTAGE_* properties for apm calculations. It's pretty
5 dummy, but useful for batteries for which we can only get voltages.
8 drivers/power/apm_power.c | 63 ++++++++++++++++++++++++++++++++++++--------
9 1 files changed, 51 insertions(+), 12 deletions(-)
11 diff --git a/drivers/power/apm_power.c b/drivers/power/apm_power.c
12 index bbf3ee1..526c96e 100644
13 --- a/drivers/power/apm_power.c
14 +++ b/drivers/power/apm_power.c
16 #include <linux/power_supply.h>
17 #include <linux/apm-emulation.h>
25 #define PSY_PROP(psy, prop, val) psy->get_property(psy, \
26 POWER_SUPPLY_PROP_##prop, val)
28 @@ -87,7 +93,7 @@ static void find_main_battery(void)
32 -static int calculate_time(int status, int using_charge)
33 +static int calculate_time(int status, apm_source source)
35 union power_supply_propval full;
36 union power_supply_propval empty;
37 @@ -106,20 +112,34 @@ static int calculate_time(int status, int using_charge)
44 full_prop = POWER_SUPPLY_PROP_CHARGE_FULL;
45 full_design_prop = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;
46 empty_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
47 empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
48 cur_avg_prop = POWER_SUPPLY_PROP_CHARGE_AVG;
49 cur_now_prop = POWER_SUPPLY_PROP_CHARGE_NOW;
53 full_prop = POWER_SUPPLY_PROP_ENERGY_FULL;
54 full_design_prop = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN;
55 empty_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY;
56 empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
57 cur_avg_prop = POWER_SUPPLY_PROP_ENERGY_AVG;
58 cur_now_prop = POWER_SUPPLY_PROP_ENERGY_NOW;
60 + case SOURCE_VOLTAGE:
61 + full_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX;
62 + full_design_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN;
63 + empty_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN;
64 + empty_design_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN;
65 + cur_avg_prop = POWER_SUPPLY_PROP_VOLTAGE_AVG;
66 + cur_now_prop = POWER_SUPPLY_PROP_VOLTAGE_NOW;
69 + printk(KERN_ERR "Unsupported source: %d\n", source);
73 if (_MPSY_PROP(full_prop, &full)) {
74 @@ -146,7 +166,7 @@ static int calculate_time(int status, int using_charge)
75 return -((cur.intval - empty.intval) * 60L) / I.intval;
78 -static int calculate_capacity(int using_charge)
79 +static int calculate_capacity(apm_source source)
81 enum power_supply_property full_prop, empty_prop;
82 enum power_supply_property full_design_prop, empty_design_prop;
83 @@ -154,20 +174,33 @@ static int calculate_capacity(int using_charge)
84 union power_supply_propval empty, full, cur;
90 full_prop = POWER_SUPPLY_PROP_CHARGE_FULL;
91 empty_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
92 full_design_prop = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;
93 empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN;
94 now_prop = POWER_SUPPLY_PROP_CHARGE_NOW;
95 avg_prop = POWER_SUPPLY_PROP_CHARGE_AVG;
99 full_prop = POWER_SUPPLY_PROP_ENERGY_FULL;
100 empty_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY;
101 full_design_prop = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN;
102 empty_design_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN;
103 now_prop = POWER_SUPPLY_PROP_ENERGY_NOW;
104 avg_prop = POWER_SUPPLY_PROP_ENERGY_AVG;
105 + case SOURCE_VOLTAGE:
106 + full_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX;
107 + empty_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN;
108 + full_design_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN;
109 + empty_design_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN;
110 + now_prop = POWER_SUPPLY_PROP_VOLTAGE_NOW;
111 + avg_prop = POWER_SUPPLY_PROP_VOLTAGE_AVG;
114 + printk(KERN_ERR "Unsupported source: %d\n", source);
118 if (_MPSY_PROP(full_prop, &full)) {
119 @@ -234,10 +267,12 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
120 info->battery_life = capacity.intval;
122 /* try calculate using energy */
123 - info->battery_life = calculate_capacity(0);
124 + info->battery_life = calculate_capacity(SOURCE_ENERGY);
125 /* if failed try calculate using charge instead */
126 if (info->battery_life == -1)
127 - info->battery_life = calculate_capacity(1);
128 + info->battery_life = calculate_capacity(SOURCE_CHARGE);
129 + if (info->battery_life == -1)
130 + info->battery_life = calculate_capacity(SOURCE_VOLTAGE);
133 /* charging status */
134 @@ -263,18 +298,22 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
135 !MPSY_PROP(TIME_TO_FULL_NOW, &time_to_full)) {
136 info->time = time_to_full.intval / 60;
138 - info->time = calculate_time(status.intval, 0);
139 + info->time = calculate_time(status.intval, SOURCE_ENERGY);
140 if (info->time == -1)
141 - info->time = calculate_time(status.intval, 1);
142 + info->time = calculate_time(status.intval, SOURCE_CHARGE);
143 + if (info->time == -1)
144 + info->time = calculate_time(status.intval, SOURCE_VOLTAGE);
147 if (!MPSY_PROP(TIME_TO_EMPTY_AVG, &time_to_empty) ||
148 !MPSY_PROP(TIME_TO_EMPTY_NOW, &time_to_empty)) {
149 info->time = time_to_empty.intval / 60;
151 - info->time = calculate_time(status.intval, 0);
152 + info->time = calculate_time(status.intval, SOURCE_ENERGY);
153 + if (info->time == -1)
154 + info->time = calculate_time(status.intval, SOURCE_CHARGE);
155 if (info->time == -1)
156 - info->time = calculate_time(status.intval, 1);
157 + info->time = calculate_time(status.intval, SOURCE_VOLTAGE);