125
112
hal_util_set_int_elem_from_file (d, "battery.voltage.current", path,
126
113
"state", "present voltage", 0, 10, TRUE);
127
/* get all the data we know */
128
reporting_unit = hal_device_property_get_string (d,
129
"battery.reporting.unit");
130
reporting_current = hal_device_property_get_int (d,
131
"battery.reporting.current");
132
reporting_lastfull = hal_device_property_get_int (d,
133
"battery.reporting.last_full");
134
reporting_rate = hal_device_property_get_int (d,
135
"battery.reporting.rate");
138
* ACPI gives out the special 'Ones' value for rate when it's unable
139
* to calculate the true rate. We should set the rate zero, and wait
140
* for the BIOS to stabilise.
142
* full details here: http://bugzilla.gnome.org/show_bug.cgi?id=348201
144
if (reporting_rate == 0xffff) {
149
* We are converting the unknown units into mWh because of ACPI's nature
150
* of not having a standard "energy" unit.
152
* full details here: http://bugzilla.gnome.org/show_bug.cgi?id=309944
154
if (reporting_unit && strcmp (reporting_unit, "mAh") == 0) {
155
/* convert mAh to mWh by multiplying by voltage. due to the
156
* general wonkiness of ACPI implementations, this is a lot
157
* harder than it should have to be...
160
design_voltage = hal_device_property_get_int (d, "battery.voltage.design");
161
voltage = hal_device_property_get_int (d, "battery.voltage.current");
163
/* Just in case we don't get design voltage information, then
164
* this will pretend that we have 1V. This degrades our
165
* ability to report accurate times on multi-battery systems
166
* but will always prevent negative charge levels and allow
167
* accurate reporting on single-battery systems.
169
if (design_voltage <= 0)
170
design_voltage = 1000; /* mV */
172
/* If the current voltage is unknown, smaller than 50% of design voltage (fd.o #8593)
173
* or greater than design, then use design voltage.
175
if (voltage < (design_voltage/2) || voltage > design_voltage) {
176
HAL_DEBUG (("Current voltage is unknown, smaller than 50%% or greater than design"));
177
voltage = design_voltage;
180
normalised_current = (reporting_current * voltage) / 1000;
181
normalised_lastfull = (reporting_lastfull * voltage) / 1000;
182
normalised_rate = (reporting_rate * voltage) / 1000;
185
* handle as if mWh (which don't need conversion), which is the most common case.
187
normalised_current = reporting_current;
188
normalised_lastfull = reporting_lastfull;
189
normalised_rate = reporting_rate;
193
* Set the normalised keys.
195
if (normalised_current < 0)
196
normalised_current = 0;
197
if (normalised_lastfull < 0)
198
normalised_lastfull = 0;
199
if (normalised_rate < 0)
203
* Some laptops report a rate even when not charging or discharging.
204
* If not charging and not discharging force rate to be zero.
206
* http://bugzilla.gnome.org/show_bug.cgi?id=323186
208
charging = hal_device_property_get_bool (d, "battery.rechargeable.is_charging");
209
discharging = hal_device_property_get_bool (d, "battery.rechargeable.is_discharging");
211
if (!charging && !discharging)
215
* Some laptops report current charge much larger than
216
* full charge when at 100%. Clamp back down to 100%.
218
if (normalised_current > normalised_lastfull)
219
normalised_current = normalised_lastfull;
221
hal_device_property_set_int (d, "battery.charge_level.current", normalised_current);
222
hal_device_property_set_int (d, "battery.charge_level.last_full", normalised_lastfull);
223
hal_device_property_set_int (d, "battery.charge_level.rate", normalised_rate);
225
remaining_time = util_compute_time_remaining (
226
hal_device_get_udi (d),
227
normalised_rate, normalised_current, normalised_lastfull,
228
hal_device_property_get_bool (d, "battery.rechargeable.is_discharging"),
229
hal_device_property_get_bool (d, "battery.rechargeable.is_charging"),
230
hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time"));
231
remaining_percentage = util_compute_percentage_charge (hal_device_get_udi (d), normalised_current, normalised_lastfull);
233
* Only set keys if no error (signified with negative return value)
234
* Scrict checking is needed to ensure that the values presented by HAL
238
if (remaining_time > 0)
239
hal_device_property_set_int (d, "battery.remaining_time", remaining_time);
241
hal_device_property_remove (d, "battery.remaining_time");
243
if (remaining_percentage > 0)
244
hal_device_property_set_int (d, "battery.charge_level.percentage", remaining_percentage);
246
hal_device_property_remove (d, "battery.charge_level.percentage");
115
/* we've now got the 'reporting' keys, now we need to populate the
116
* processed 'charge_level' keys so stuff like desktop power managers
117
* do not have to deal with odd quirks */
118
device_pm_abstract_props (d);
120
/* we calculate this more precisely */
121
device_pm_calculate_percentage (d);
123
/* try to calculate the time accurately (sic) using the rate */
124
device_pm_calculate_time (d);
421
* battery_refresh_remove:
422
* @d: Valid battery HalDevice
424
* Removes all the possible battery.* keys.
426
* Note: Removing a key that doesn't exist is OK.
429
battery_refresh_remove (HalDevice *d)
431
hal_device_property_remove (d, "battery.is_rechargeable");
432
hal_device_property_remove (d, "battery.rechargeable.is_charging");
433
hal_device_property_remove (d, "battery.rechargeable.is_discharging");
434
hal_device_property_remove (d, "battery.vendor");
435
hal_device_property_remove (d, "battery.model");
436
hal_device_property_remove (d, "battery.serial");
437
hal_device_property_remove (d, "battery.reporting.technology");
438
hal_device_property_remove (d, "battery.technology");
439
hal_device_property_remove (d, "battery.vendor");
440
hal_device_property_remove (d, "battery.charge_level.unit");
441
hal_device_property_remove (d, "battery.charge_level.current");
442
hal_device_property_remove (d, "battery.charge_level.percentage");
443
hal_device_property_remove (d, "battery.charge_level.last_full");
444
hal_device_property_remove (d, "battery.charge_level.design");
445
hal_device_property_remove (d, "battery.charge_level.capacity_state");
446
hal_device_property_remove (d, "battery.charge_level.warning");
447
hal_device_property_remove (d, "battery.charge_level.low");
448
hal_device_property_remove (d, "battery.charge_level.granularity_1");
449
hal_device_property_remove (d, "battery.charge_level.granularity_2");
450
hal_device_property_remove (d, "battery.charge_level.rate");
451
hal_device_property_remove (d, "battery.voltage.unit");
452
hal_device_property_remove (d, "battery.voltage.design");
453
hal_device_property_remove (d, "battery.voltage.current");
454
hal_device_property_remove (d, "battery.alarm.unit");
455
hal_device_property_remove (d, "battery.alarm.design");
456
hal_device_property_remove (d, "battery.reporting.current");
457
hal_device_property_remove (d, "battery.reporting.last_full");
458
hal_device_property_remove (d, "battery.reporting.design");
459
hal_device_property_remove (d, "battery.reporting.rate");
460
hal_device_property_remove (d, "battery.reporting.warning");
461
hal_device_property_remove (d, "battery.reporting.low");
462
hal_device_property_remove (d, "battery.reporting.granularity_1");
463
hal_device_property_remove (d, "battery.reporting.granularity_2");
464
hal_device_property_remove (d, "battery.reporting.unit");
465
hal_device_property_remove (d, "battery.remaining_time");
469
299
* battery_refresh_add:
470
300
* @d: Valid battery HalDevice
523
351
"info", "capacity granularity 1", 0, 10, TRUE);
524
352
hal_util_set_int_elem_from_file (d, "battery.reporting.granularity_2", path,
525
353
"info", "capacity granularity 2", 0, 10, TRUE);
527
* we'll need this is we want to convert mAh to mWh
354
/* we'll need this is we want to convert mAh to mWh */
529
355
hal_util_set_string_elem_from_file (d, "battery.voltage.unit", path, "info",
530
356
"design voltage", 1, TRUE);
531
357
hal_util_set_int_elem_from_file (d, "battery.voltage.design", path,
532
358
"info", "design voltage", 0, 10, TRUE);
534
* Convert the mWh or mAh units into mWh...
535
* We'll do as many as we can here as the values
536
* are not going to change.
537
* We'll set the correct unit (or unknown) also.
360
/* Convert the mWh or mAh units into mWh...
361
* We'll do as many as we can here as the values are not going to change.
362
* We'll set the correct unit (or unknown) also. */
539
363
reporting_unit = hal_device_property_get_string (d, "battery.reporting.unit");
540
364
reporting_design = hal_device_property_get_int (d, "battery.reporting.design");
541
365
reporting_warning = hal_device_property_get_int (d, "battery.reporting.warning");
1070
894
hal_util_set_string_elem_from_file (computer, "power_management.acpi.linux.version",
1071
895
"/proc/acpi", "info", "version", 0, FALSE);
1073
gchar *firmware_path;
1074
firmware_path = g_strdup_printf ("%s/firmware/acpi", get_hal_sysfs_path ());
1075
hal_util_set_string_elem_from_file (computer, "power_management.acpi.linux.version",
1076
firmware_path, "info", "version", 0, FALSE);
1077
g_free (firmware_path);
897
if (!hal_util_set_string_from_file (computer, "power_management.acpi.linux.version",
898
"/sys/module/acpi/parameters", "acpica_version"))
899
/* Fallback for some older kernel version, can get removed if HAL depends on >= 2.6.21 */
900
hal_util_set_string_elem_from_file (computer, "power_management.acpi.linux.version",
901
"/sys/firmware/acpi", "info", "version", 0, FALSE);
1080
904
/* collect batteries */
1081
snprintf (path, sizeof (path), "%s/acpi/battery", get_hal_proc_path ());
1082
acpi_synthesize (path, ACPI_TYPE_BATTERY);
905
acpi_synthesize ("/proc/acpi/battery", ACPI_TYPE_BATTERY, TRUE);
1084
906
/* collect processors */
1085
snprintf (path, sizeof (path), "%s/acpi/processor", get_hal_proc_path ());
1086
acpi_synthesize (path, ACPI_TYPE_PROCESSOR);
907
acpi_synthesize ("/proc/acpi/processor", ACPI_TYPE_PROCESSOR, TRUE);
1088
908
/* collect fans */
1089
snprintf (path, sizeof (path), "%s/acpi/fan", get_hal_proc_path ());
1090
acpi_synthesize (path, ACPI_TYPE_FAN);
909
acpi_synthesize ("/proc/acpi/fan", ACPI_TYPE_FAN, TRUE);
1092
910
/* collect AC adapters */
1093
snprintf (path, sizeof (path), "%s/acpi/ac_adapter", get_hal_proc_path ());
1094
acpi_synthesize (path, ACPI_TYPE_AC_ADAPTER);
911
acpi_synthesize ("/proc/acpi/ac_adapter", ACPI_TYPE_AC_ADAPTER, TRUE);
1096
913
/* collect buttons */
1097
snprintf (path, sizeof (path), "%s/acpi/button/lid", get_hal_proc_path ());
1098
acpi_synthesize (path, ACPI_TYPE_BUTTON);
1099
snprintf (path, sizeof (path), "%s/acpi/button/power", get_hal_proc_path ());
1100
acpi_synthesize (path, ACPI_TYPE_BUTTON);
1101
snprintf (path, sizeof (path), "%s/acpi/button/sleep", get_hal_proc_path ());
1102
acpi_synthesize (path, ACPI_TYPE_BUTTON);
914
acpi_synthesize ("/proc/acpi/button/lid", ACPI_TYPE_BUTTON, TRUE);
915
acpi_synthesize ("/proc/acpi/button/power", ACPI_TYPE_BUTTON, TRUE);
916
acpi_synthesize ("/proc/acpi/button/sleep", ACPI_TYPE_BUTTON, TRUE);
1105
919
* Collect video adaptors (from vendor added modules)