[Pkg-utopia-commits] r2101 - in /packages/unstable/hal/debian: changelog patches/92_fix_sysfs_batteries.patch
sjoerd at users.alioth.debian.org
sjoerd at users.alioth.debian.org
Sat Mar 1 12:11:40 UTC 2008
Author: sjoerd
Date: Sat Mar 1 12:11:40 2008
New Revision: 2101
URL: http://svn.debian.org/wsvn/pkg-utopia/?sc=1&rev=2101
Log:
Set suite to UNRELEASED
Added:
packages/unstable/hal/debian/patches/92_fix_sysfs_batteries.patch
Modified:
packages/unstable/hal/debian/changelog
Modified: packages/unstable/hal/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-utopia/packages/unstable/hal/debian/changelog?rev=2101&op=diff
==============================================================================
--- packages/unstable/hal/debian/changelog (original)
+++ packages/unstable/hal/debian/changelog Sat Mar 1 12:11:40 2008
@@ -1,4 +1,4 @@
-hal (0.5.10-6) unstable; urgency=low
+hal (0.5.10-6) UNRELEASED; urgency=low
* debian/rules
- Explicitly disable the macbook addon to ensure reliable build results
Added: packages/unstable/hal/debian/patches/92_fix_sysfs_batteries.patch
URL: http://svn.debian.org/wsvn/pkg-utopia/packages/unstable/hal/debian/patches/92_fix_sysfs_batteries.patch?rev=2101&op=file
==============================================================================
--- packages/unstable/hal/debian/patches/92_fix_sysfs_batteries.patch (added)
+++ packages/unstable/hal/debian/patches/92_fix_sysfs_batteries.patch Sat Mar 1 12:11:40 2008
@@ -1,0 +1,924 @@
+commit 0a4bf1cbedc3ed6416a56b35b569b0557d3eb625
+Author: Kyle McMartin <kmcmartin at redhat.com>
+Date: Mon Jan 28 15:19:39 2008 +0100
+
+ fix hal see same battery twice from sysfs and proc
+
+ I've turned on both ACPI_PROCFS_POWER and ACPI_SYSFS_POWER in Fedora
+ rawhide. With both options set, hal sees two battery devices, when it
+ should really only check the second if the first doesn't exist.
+
+ Fix this up by only checking procfs if we don't find anything in
+ sysfs.
+
+diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
+index cc97f15..a1f0fdd 100644
+--- a/hald/linux/acpi.c
++++ b/hald/linux/acpi.c
+@@ -944,10 +944,23 @@ acpi_synthesize_hotplug_events (void)
+ return TRUE;
+ }
+
++static gboolean
++is_power_supply(ACPIDevHandler *h)
++{
++ if (h && (h->acpi_type == ACPI_TYPE_BATTERY) ||
++ (h->acpi_type == ACPI_TYPE_AC_ADAPTER))
++ return TRUE;
++ return FALSE;
++}
++
+ static HalDevice *
+ acpi_generic_add (const gchar *acpi_path, HalDevice *parent, ACPIDevHandler *handler)
+ {
+ HalDevice *d;
++
++ if (is_power_supply(handler) && _have_sysfs_power_supply)
++ return NULL;
++
+ d = hal_device_new ();
+ hal_device_property_set_string (d, "linux.acpi_path", acpi_path);
+ hal_device_property_set_int (d, "linux.acpi_type", handler->acpi_type);
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index 1797227..57a8fac 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -3216,6 +3216,11 @@ power_supply_refresh (HalDevice *d)
+ return TRUE;
+ }
+
++/* don't bother looking for /proc/acpi batteries if they're in
++ * sysfs.
++ */
++gboolean _have_sysfs_power_supply = FALSE;
++
+ static HalDevice *
+ power_supply_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev,
+ const gchar *sysfs_path_in_devices)
+@@ -3266,6 +3271,8 @@ power_supply_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *
+ refresh_ac_adapter (d);
+ hal_device_add_capability (d, "ac_adapter");
+ }
++
++ _have_sysfs_power_supply = TRUE;
+ finish:
+ return d;
+ }
+diff --git a/hald/linux/device.h b/hald/linux/device.h
+index 1bd7286..4a7fd92 100644
+--- a/hald/linux/device.h
++++ b/hald/linux/device.h
+@@ -52,5 +52,6 @@ HotplugEvent *dev_generate_remove_hotplug_event (HalDevice *d);
+ extern gboolean _have_sysfs_lid_button;
+ extern gboolean _have_sysfs_power_button;
+ extern gboolean _have_sysfs_sleep_button;
++extern gboolean _have_sysfs_power_supply;
+
+ #endif
+
+commit 4894898a19c32bfd44feae3070c7dba6475b478a
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 29 16:44:27 2008 +0100
+
+ fixed power_supply_refresh() for batteries
+
+ Fixed power_supply_refresh() for the battery case. No need to
+ call refresh_battery_slow() on refresh, refresh_battery_fast()
+ should be enough since the info updated by refresh_battery_slow()
+ never change if the device is present.
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index 57a8fac..f0a1d41 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -3207,7 +3207,7 @@ power_supply_refresh (HalDevice *d)
+ device_property_atomic_update_end ();
+ } else if (strcmp (type, "battery") == 0) {
+ device_property_atomic_update_begin ();
+- refresh_battery_slow (d);
++ refresh_battery_fast (d);
+ device_property_atomic_update_end ();
+ } else {
+ HAL_WARNING (("Could not recognise power_supply type!"));
+
+commit e423d84bbc3a970acd9ea2b469648ee39d62ff10
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 29 17:36:53 2008 +0100
+
+ fixed refresh_battery_slow() for power_supply batteries
+
+ Fixed refresh_battery_slow() for power_supply batteries: removed not
+ needed variable 'technology', set the model_name correctly to
+ info.product and set also battery.model property.
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index f0a1d41..145554a 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -3156,7 +3156,6 @@ refresh_battery_fast (HalDevice *d)
+ static void
+ refresh_battery_slow (HalDevice *d)
+ {
+- const char *technology;
+ char *technology_raw;
+ char *model_name;
+ char *manufacturer;
+@@ -3171,13 +3170,12 @@ refresh_battery_slow (HalDevice *d)
+ if (technology_raw != NULL) {
+ hal_device_property_set_string (d, "battery.reporting.technology", technology_raw);
+ }
+- /* we set this, even if it's unknown */
+- technology = util_get_battery_technology (technology_raw);
+- hal_device_property_set_string (d, "battery.technology", technology);
++ hal_device_property_set_string (d, "battery.technology", util_get_battery_technology (technology_raw));
+
+ /* get product name */
+- model_name = hal_util_get_string_from_file (path, "technology");
++ model_name = hal_util_get_string_from_file (path, "model_name");
+ if (model_name != NULL) {
++ hal_device_property_set_string (d, "battery.model", model_name);
+ hal_device_property_set_string (d, "info.product", model_name);
+ } else {
+ hal_device_property_set_string (d, "info.product", "Generic Battery Device");
+
+commit d1abe61f7d0630e30ea0b8b95328ac51265748f4
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Fri Nov 23 23:13:49 2007 +0100
+
+ cleanup device.c
+
+ Added some comment lines between subsystem code sections. Moved some
+ functions of subsystems together.
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index 145554a..7ef9e0a 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -992,6 +992,8 @@ dvb_compute_udi (HalDevice *d)
+ return TRUE;
+ }
+
++/*--------------------------------------------------------------------------------------------------------------*/
++
+ static void
+ asound_card_id_set (int cardnum, HalDevice *d, const char *propertyname)
+ {
+@@ -1011,8 +1013,6 @@ asound_card_id_set (int cardnum, HalDevice *d, const char *propertyname)
+ }
+ }
+
+-/*--------------------------------------------------------------------------------------------------------------*/
+-
+ static HalDevice *
+ sound_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path)
+ {
+@@ -1513,6 +1513,8 @@ mmc_host_compute_udi (HalDevice *d)
+ return TRUE;
+ }
+
++/*--------------------------------------------------------------------------------------------------------------*/
++
+ static HalDevice *
+ pci_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path)
+ {
+@@ -2930,6 +2932,8 @@ iucv_compute_udi (HalDevice *d)
+
+ }
+
++/*--------------------------------------------------------------------------------------------------------------*/
++
+ static HalDevice *
+ backlight_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev,
+ const gchar *sysfs_path_in_devices)
+@@ -2951,7 +2955,7 @@ backlight_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *phy
+ }
+
+ static gboolean
+-power_supply_compute_udi (HalDevice *d)
++backlight_compute_udi (HalDevice *d)
+ {
+ gchar udi[256];
+ const char *dir;
+@@ -2961,13 +2965,15 @@ power_supply_compute_udi (HalDevice *d)
+
+ name = hal_util_get_last_element(dir);
+ hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
+- "%s_power_supply",
++ "%s_backlight",
+ hal_device_property_get_string (d, "info.parent"));
+ hal_device_set_udi (d, udi);
+ hal_device_property_set_string (d, "info.udi", udi);
+ return TRUE;
+ }
+
++/*--------------------------------------------------------------------------------------------------------------*/
++
+ static void
+ refresh_ac_adapter (HalDevice *d)
+ {
+@@ -3276,7 +3282,7 @@ finish:
+ }
+
+ static gboolean
+-backlight_compute_udi (HalDevice *d)
++power_supply_compute_udi (HalDevice *d)
+ {
+ gchar udi[256];
+ const char *dir;
+@@ -3286,7 +3292,7 @@ backlight_compute_udi (HalDevice *d)
+
+ name = hal_util_get_last_element(dir);
+ hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
+- "%s_backlight",
++ "%s_power_supply",
+ hal_device_property_get_string (d, "info.parent"));
+ hal_device_set_udi (d, udi);
+ hal_device_property_set_string (d, "info.udi", udi);
+
+commit da365882f8bc33ba402b94dc108320d26461a736
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 29 18:00:01 2008 +0100
+
+ fixed power_supply_compute_udi() to generate useful UDIs
+
+ Fixed power_supply_compute_udi() to generate useful UDIs, including
+ (if available) power_supply-type and ID of the device.
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index 7ef9e0a..ed12ba8 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -3291,9 +3291,18 @@ power_supply_compute_udi (HalDevice *d)
+ dir = hal_device_property_get_string (d, "linux.sysfs_path");
+
+ name = hal_util_get_last_element(dir);
+- hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
+- "%s_power_supply",
+- hal_device_property_get_string (d, "info.parent"));
++ if (name)
++ hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
++ "%s_power_supply_%s_%s",
++ hal_device_property_get_string (d, "info.parent"),
++ hal_device_property_get_string (d, "info.category"),
++ name);
++ else
++ hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
++ "%s_power_supply_%s",
++ hal_device_property_get_string (d, "info.parent"),
++ hal_device_property_get_string (d, "info.category"));
++
+ hal_device_set_udi (d, udi);
+ hal_device_property_set_string (d, "info.udi", udi);
+ return TRUE;
+
+commit 7bc61569f6c335469e8297796cc1d4ae6e876f56
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 29 18:18:41 2008 +0100
+
+ fixed refresh_battery_fast() for power_supply: battery.*.rate
+
+ Fixed refresh_battery_fast() for power_supply. Added missing key
+ battery.voltage.unit and replace not existing key battery.current (this
+ key was introduced with 356ccdfa3bbf64648c48da8b756eaccef13d0dd9, but
+ the key was never part of the spec!) with battery.charge_level.rate.
+ Added also battery.reporting.rate property.
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index ed12ba8..cd1daec 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -3045,13 +3045,16 @@ refresh_battery_fast (HalDevice *d)
+ }
+ if (hal_util_get_int_from_file (path, "voltage_max_design", &voltage_design, 10)) {
+ hal_device_property_set_int (d, "battery.voltage.design", voltage_design / 1000);
++ hal_device_property_set_string (d, "battery.voltage.unit", "mV");
+ }
+
+ /* CURRENT: we prefer the average if it exists, although present is still pretty good */
+- if (hal_util_get_int_from_file (path, "current_avg", ¤t, 10)) {
+- hal_device_property_set_int (d, "battery.current", current / 1000);
++ if (!hal_util_get_int_from_file (path, "current_avg", ¤t, 10)) {
++ hal_device_property_set_int (d, "battery.reporting.rate", current);
++ hal_device_property_set_int (d, "battery.charge_level.rate", current / 1000);
+ } else if (hal_util_get_int_from_file (path, "current_now", ¤t, 10)) {
+- hal_device_property_set_int (d, "battery.current", current / 1000);
++ hal_device_property_set_int (d, "battery.reporting.rate", current);
++ hal_device_property_set_int (d, "battery.charge_level.rate", current / 1000);
+ }
+
+ /* STATUS: Convert to charging/discharging state */
+
+commit ef6203e017fa4f747639c80c53f4252d1be41d9c
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Thu Dec 6 21:23:05 2007 +0100
+
+ fix normalised_rate if dis-/charging state is unknown
+
+ This fixes problems with machines which report not the correct charging
+ state in some cases (e.g. battery report 'charged' if on battery). With this
+ patch normalised_rate get set only to 0 if:
+
+ * the battery is not a primary (ACPI) battery
+ * the machines is on AC or
+ * there is in a multi battery system an other primary (ACPI) battery is
+ discharging
+
+ This should fix: https://bugzilla.novell.com/show_bug.cgi?id=258755
+
+diff --git a/hald/device_pm.c b/hald/device_pm.c
+index e84c4ff..c4fee3b 100644
+--- a/hald/device_pm.c
++++ b/hald/device_pm.c
+@@ -32,6 +32,7 @@
+
+ #include <glib.h>
+
++#include "hald.h"
+ #include "logger.h"
+ #include "util_pm.h"
+ #include "device_pm.h"
+@@ -127,8 +128,58 @@ device_pm_abstract_props (HalDevice *d)
+ charging = hal_device_property_get_bool (d, "battery.rechargeable.is_charging");
+ discharging = hal_device_property_get_bool (d, "battery.rechargeable.is_discharging");
+
+- if (!charging && !discharging)
+- normalised_rate = 0;
++ if (!charging && !discharging) {
++ GSList *i;
++ GSList *devices;
++ HalDevice *_d;
++ gboolean online;
++ const char *bat_type;
++
++ online = FALSE;
++
++ /* check if this is a primary, mean laptop battery */
++ bat_type = hal_device_property_get_string (d, "battery.type");
++ if (bat_type != NULL && !strncmp (bat_type, "primary", 7)) {
++
++ /* check if the machine is on AC or on battery */
++ devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
++ "info.category",
++ "ac_adapter");
++ for (i = devices; i != NULL; i = g_slist_next (i)) {
++ _d = HAL_DEVICE (i->data);
++ if (hal_device_has_property (_d, "linux.acpi_type")) {
++ if (hal_device_property_get_bool (_d, "ac_adapter.present")) {
++ online = TRUE;
++ }
++ }
++ }
++ g_slist_free (devices);
++
++ if (online) {
++ normalised_rate = 0;
++ } else {
++ /* check if there is an other battery already discharing, if so: set normalised_rate = 0 */
++ devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
++ "info.category",
++ "battery");
++ for (i = devices; i != NULL; i = g_slist_next (i)) {
++ _d = HAL_DEVICE (i->data);
++ if (hal_device_has_property (_d, "linux.acpi_type")) {
++ bat_type = hal_device_property_get_string (_d, "battery.type");
++ if (bat_type != NULL && !strncmp (bat_type, "primary", 7)) {
++ if (strcmp (hal_device_get_udi(d), hal_device_get_udi(_d)) != 0) {
++ if (hal_device_property_get_bool (_d, "battery.rechargeable.is_discharging"))
++ normalised_rate = 0;
++ }
++ }
++ }
++ }
++ g_slist_free(devices);
++ }
++ } else {
++ normalised_rate = 0;
++ }
++ }
+
+ /* Some laptops report current charge much larger than
+ * full charge when at 100%. Clamp back down to 100%. */
+
+commit 49948a5051dfb1fcbf222bb5c5a066ab3b529722
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 15 13:51:29 2008 +0100
+
+ fix percentage for empty batteries
+
+ With commit d7144f2aa1b59f9a0acfa0daada69e2a4ffd54d8 the handling of empty
+ batteries changed, which cause massive problems with multi battery machines.
+
+ In the past the battery.charge_level.percentage key was removed if there where
+ any problems with calculate the remaining percentage of a battery. This
+ include the case where the current charge level was 0, which was/is IMO also
+ wrong, since 0 is a correct value for a percentage.
+
+ With the current HAL the battery get set in such cases to 100% which cause
+ e.g. KPowersave to assume the battery is full and not empty, which also lead
+ to wrong overall remaining percentage calculation (never reach critical
+ battery levels, always over 50%) in multi battery systems, which can lead
+ to crash the complete system if both batteries get empty!
+
+ This patch change the code to remove the key again on problems. IMO we
+ should think about change the behavior if the current charge level is really
+ 0 to set the percentage also to 0. The userspace tools should be able to
+ handle this!
+
+diff --git a/hald/device_pm.c b/hald/device_pm.c
+index c4fee3b..1c7fe9d 100644
+--- a/hald/device_pm.c
++++ b/hald/device_pm.c
+@@ -205,19 +205,19 @@ device_pm_calculate_percentage (HalDevice *d)
+ int current;
+ int lastfull;
+
+- /* default to fully charge to avoid triggering low power warnings on
+- * really broken batteries */
+- percentage = 100;
++ percentage = -1;
+
+ /* use the charge level compared to the last full amount */
+ current = hal_device_property_get_int (d, "battery.charge_level.current");
+ lastfull = hal_device_property_get_int (d, "battery.charge_level.last_full");
+
+ /* make sure we have current */
+- if (current <= 0) {
+- HAL_WARNING (("battery.charge_level.current %i, returning -1!", current));
++ if (current < 0) {
++ HAL_WARNING (("battery.charge_level.current %i, delete battery.charge_level.percentage", current));
++ } else if (current == 0) {
++ percentage = 0; /* battery is empty */
+ } else if (lastfull <= 0) {
+- HAL_WARNING (("battery.charge_level.lastfull %i, percentage returning -1!", lastfull));
++ HAL_WARNING (("battery.charge_level.lastfull %i, delete battery.charge_level.percentage", lastfull));
+ } else {
+ percentage = ((double) current / (double) lastfull) * 100;
+ /* Some bios's will report this out of range of 0..100, limit it here */
+@@ -226,7 +226,11 @@ device_pm_calculate_percentage (HalDevice *d)
+ else if (percentage < 0)
+ percentage = 1;
+ }
+- hal_device_property_set_int (d, "battery.charge_level.percentage", percentage);
++
++ if (percentage < 0)
++ hal_device_property_remove (d, "battery.charge_level.percentage");
++ else
++ hal_device_property_set_int (d, "battery.charge_level.percentage", percentage);
+ }
+
+ /**
+
+commit d0235a0b0d7243e455a7fad3a37fbac673a7e953
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 29 19:08:55 2008 +0100
+
+ fixed device_pm_abstract_props() to set also battery.charge_level.design
+
+ Fixed device_pm_abstract_props() to set also battery.charge_level.design
+ since the key is mandatory.
+
+diff --git a/hald/device_pm.c b/hald/device_pm.c
+index 1c7fe9d..8a0262a 100644
+--- a/hald/device_pm.c
++++ b/hald/device_pm.c
+@@ -51,9 +51,11 @@ device_pm_abstract_props (HalDevice *d)
+ const char *reporting_unit;
+ int reporting_current;
+ int reporting_lastfull;
++ int reporting_design;
+ int reporting_rate;
+ int normalised_current;
+ int normalised_lastfull;
++ int normalised_design;
+ int normalised_rate;
+ int design_voltage;
+ int voltage;
+@@ -67,6 +69,8 @@ device_pm_abstract_props (HalDevice *d)
+ "battery.reporting.current");
+ reporting_lastfull = hal_device_property_get_int (d,
+ "battery.reporting.last_full");
++ reporting_design = hal_device_property_get_int (d,
++ "battery.reporting.design");
+ reporting_rate = hal_device_property_get_int (d,
+ "battery.reporting.rate");
+
+@@ -104,12 +108,14 @@ device_pm_abstract_props (HalDevice *d)
+
+ normalised_current = (reporting_current * voltage) / 1000;
+ normalised_lastfull = (reporting_lastfull * voltage) / 1000;
++ normalised_design = (reporting_design * voltage) / 1000;
+ normalised_rate = (reporting_rate * voltage) / 1000;
+ } else {
+ /* handle as if mWh (which don't need conversion), which is
+ * the most common case. */
+ normalised_current = reporting_current;
+ normalised_lastfull = reporting_lastfull;
++ normalised_design = reporting_design;
+ normalised_rate = reporting_rate;
+ }
+
+@@ -120,6 +126,8 @@ device_pm_abstract_props (HalDevice *d)
+ normalised_current = 0;
+ if (normalised_lastfull < 0)
+ normalised_lastfull = 0;
++ if (normalised_design < 0)
++ normalised_design = 0;
+ if (normalised_rate < 0)
+ normalised_rate = 0;
+
+@@ -142,6 +150,7 @@ device_pm_abstract_props (HalDevice *d)
+ if (bat_type != NULL && !strncmp (bat_type, "primary", 7)) {
+
+ /* check if the machine is on AC or on battery */
++ /* TODO: rework for power_supply */
+ devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
+ "info.category",
+ "ac_adapter");
+@@ -188,6 +197,7 @@ device_pm_abstract_props (HalDevice *d)
+
+ hal_device_property_set_int (d, "battery.charge_level.current", normalised_current);
+ hal_device_property_set_int (d, "battery.charge_level.last_full", normalised_lastfull);
++ hal_device_property_set_int (d, "battery.charge_level.design", normalised_design);
+ hal_device_property_set_int (d, "battery.charge_level.rate", normalised_rate);
+ }
+
+
+commit 1c5d9e03accbdb477d7dfc9f4185b63f71501759
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 29 19:11:02 2008 +0100
+
+ fixed refresh_battery_fast() for power_supply devices
+
+ Fixed refresh_battery_fast() for power_supply devices:
+ - reworked logic to get the reporting unit for the device and
+ prevent set battery.reporting.unit again, if not needed because
+ it is already set
+ - removed battery.charge_level.rate again, they get set somewhere
+ else.
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index cd1daec..d122736 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -3004,8 +3004,7 @@ refresh_battery_fast (HalDevice *d)
+ gint value_last_full = 0;
+ gint value_full_design = 0;
+ gboolean present = FALSE;
+- gboolean could_be_mah = TRUE;
+- gboolean could_be_mwh = TRUE;
++ gboolean unknown_unit = TRUE;
+ gboolean is_mah = FALSE;
+ gboolean is_mwh = FALSE;
+ gboolean is_charging = FALSE;
+@@ -3050,11 +3049,9 @@ refresh_battery_fast (HalDevice *d)
+
+ /* CURRENT: we prefer the average if it exists, although present is still pretty good */
+ if (!hal_util_get_int_from_file (path, "current_avg", ¤t, 10)) {
+- hal_device_property_set_int (d, "battery.reporting.rate", current);
+- hal_device_property_set_int (d, "battery.charge_level.rate", current / 1000);
++ hal_device_property_set_int (d, "battery.reporting.rate", current / 1000);
+ } else if (hal_util_get_int_from_file (path, "current_now", ¤t, 10)) {
+- hal_device_property_set_int (d, "battery.reporting.rate", current);
+- hal_device_property_set_int (d, "battery.charge_level.rate", current / 1000);
++ hal_device_property_set_int (d, "battery.reporting.rate", current / 1000);
+ }
+
+ /* STATUS: Convert to charging/discharging state */
+@@ -3087,14 +3084,16 @@ refresh_battery_fast (HalDevice *d)
+ reporting_unit = hal_device_property_get_string (d, "battery.reporting.unit");
+ if (reporting_unit != NULL) {
+ if (strcasecmp (reporting_unit, "mah") == 0) {
+- could_be_mwh = FALSE;
++ is_mah = TRUE;
++ unknown_unit = FALSE;
+ } else if (strcasecmp (reporting_unit, "mwh") == 0) {
+- could_be_mah = FALSE;
++ is_mah = TRUE;
++ unknown_unit = FALSE;
+ }
+ }
+
+ /* ENERGY (reported in uWh, so need to convert to mWh) */
+- if (could_be_mwh) {
++ if (unknown_unit || is_mwh) {
+ if (hal_util_get_int_from_file (path, "energy_avg", &value_now, 10)) {
+ hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000);
+ is_mwh = TRUE;
+@@ -3113,7 +3112,7 @@ refresh_battery_fast (HalDevice *d)
+ }
+
+ /* CHARGE (reported in uAh, so need to convert to mAh) */
+- if (could_be_mah) {
++ if ((unknown_unit && !is_mwh) || is_mah) {
+ if (hal_util_get_int_from_file (path, "charge_avg", &value_now, 10)) {
+ hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000);
+ is_mah = TRUE;
+@@ -3132,10 +3131,12 @@ refresh_battery_fast (HalDevice *d)
+ }
+
+ /* record these for future savings */
+- if (is_mwh == TRUE) {
+- hal_device_property_set_string (d, "battery.reporting.unit", "mWh");
+- } else if (is_mah == TRUE) {
+- hal_device_property_set_string (d, "battery.reporting.unit", "mAh");
++ if (unknown_unit) {
++ if (is_mwh == TRUE) {
++ hal_device_property_set_string (d, "battery.reporting.unit", "mWh");
++ } else if (is_mah == TRUE) {
++ hal_device_property_set_string (d, "battery.reporting.unit", "mAh");
++ }
+ }
+
+ /* we've now got the 'reporting' keys, now we need to populate the
+
+commit 6fef9c74cdd9c2c95b58812bed86845c972b111e
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 29 20:38:42 2008 +0100
+
+ power_supply battery: moved static stuff to refresh_battery_slow()
+
+ Moved static info (*_design) from refresh_battery_fast() to
+ refresh_battery_slow() since they should never change after the first
+ read of them. Try to set also battery.reporting.unit directly to
+ prevent reread in refresh_battery_fast().
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index d122736..5eafad6 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -2997,12 +2997,10 @@ refresh_battery_fast (HalDevice *d)
+ {
+ gint percentage = 0;
+ gint voltage_now = 0;
+- gint voltage_design = 0;
+ gint current = 0;
+ gint time = 0;
+ gint value_now = 0;
+ gint value_last_full = 0;
+- gint value_full_design = 0;
+ gboolean present = FALSE;
+ gboolean unknown_unit = TRUE;
+ gboolean is_mah = FALSE;
+@@ -3042,10 +3040,6 @@ refresh_battery_fast (HalDevice *d)
+ } else if (hal_util_get_int_from_file (path, "voltage_now", &voltage_now, 10)) {
+ hal_device_property_set_int (d, "battery.voltage.current", voltage_now / 1000);
+ }
+- if (hal_util_get_int_from_file (path, "voltage_max_design", &voltage_design, 10)) {
+- hal_device_property_set_int (d, "battery.voltage.design", voltage_design / 1000);
+- hal_device_property_set_string (d, "battery.voltage.unit", "mV");
+- }
+
+ /* CURRENT: we prefer the average if it exists, although present is still pretty good */
+ if (!hal_util_get_int_from_file (path, "current_avg", ¤t, 10)) {
+@@ -3105,10 +3099,6 @@ refresh_battery_fast (HalDevice *d)
+ hal_device_property_set_int (d, "battery.reporting.last_full", value_last_full / 1000);
+ is_mwh = TRUE;
+ }
+- if (hal_util_get_int_from_file (path, "energy_full_design", &value_full_design, 10)) {
+- hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000);
+- is_mwh = TRUE;
+- }
+ }
+
+ /* CHARGE (reported in uAh, so need to convert to mAh) */
+@@ -3124,10 +3114,6 @@ refresh_battery_fast (HalDevice *d)
+ hal_device_property_set_int (d, "battery.reporting.last_full", value_last_full / 1000);
+ is_mah = TRUE;
+ }
+- if (hal_util_get_int_from_file (path, "charge_full_design", &value_full_design, 10)) {
+- hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000);
+- is_mah = TRUE;
+- }
+ }
+
+ /* record these for future savings */
+@@ -3166,6 +3152,8 @@ refresh_battery_fast (HalDevice *d)
+ static void
+ refresh_battery_slow (HalDevice *d)
+ {
++ gint voltage_design = 0;
++ gint value_full_design = 0;
+ char *technology_raw;
+ char *model_name;
+ char *manufacturer;
+@@ -3197,6 +3185,21 @@ refresh_battery_slow (HalDevice *d)
+ hal_device_property_set_string (d, "battery.vendor", manufacturer);
+ }
+
++ /* get stuff that never changes */
++ if (hal_util_get_int_from_file (path, "voltage_max_design", &voltage_design, 10)) {
++ hal_device_property_set_int (d, "battery.voltage.design", voltage_design / 1000);
++ hal_device_property_set_string (d, "battery.voltage.unit", "mV");
++ }
++
++ /* try to get the design info and set the units */
++ if (hal_util_get_int_from_file (path, "energy_full_design", &value_full_design, 10)) {
++ hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000);
++ hal_device_property_set_string (d, "battery.reporting.unit", "mWh");
++ } else if (hal_util_get_int_from_file (path, "charge_full_design", &value_full_design, 10)) {
++ hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000);
++ hal_device_property_set_string (d, "battery.reporting.unit", "mAh");
++ }
++
+ /* now do stuff that happens quickly */
+ refresh_battery_fast (d);
+ }
+
+commit 28c9b8e1bd92df17d1ba2f0d24fc014495b4d9fd
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 29 23:21:04 2008 +0100
+
+ fixed power_supply primary batteries to update values
+
+ Fixed power_supply primary batteries to update values, since there are
+ no events about changes via ACPI or from udev/kernel. Added function
+ to poll for changes similar to the ACPI battery poll. Limited the poll
+ to power_supply primary batteries for now. If this is also needed for
+ ups/ubs/mains batteries, we can add them later. The poll interval
+ is 30 seconds.
+
+ TODO: differ in refresh_battery_fast between ACPI and other batteries
+ since there are several files which are currently not provided
+ by the sysfs interface for ACPI batteries in the power_supply
+ subsystem.
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index 5eafad6..d85e947 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -67,6 +67,9 @@
+ gboolean _have_sysfs_lid_button = FALSE;
+ gboolean _have_sysfs_power_button = FALSE;
+ gboolean _have_sysfs_sleep_button = FALSE;
++gboolean _have_sysfs_power_supply = FALSE;
++
++#define POWER_SUPPLY_BATTERY_POLL_INTERVAL 30000
+
+ /* we must use this kernel-compatible implementation */
+ #define BITS_PER_LONG (sizeof(long) * 8)
+@@ -3227,10 +3230,36 @@ power_supply_refresh (HalDevice *d)
+ return TRUE;
+ }
+
+-/* don't bother looking for /proc/acpi batteries if they're in
+- * sysfs.
+- */
+-gboolean _have_sysfs_power_supply = FALSE;
++
++static gboolean
++power_supply_battery_poll (gpointer data) {
++
++ GSList *i;
++ GSList *battery_devices;
++ HalDevice *d;
++
++ /* for now do it only for primary batteries and extend if neede for the other types */
++ battery_devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
++ "battery.type",
++ "primary");
++
++ if (battery_devices) {
++ for (i = battery_devices; i != NULL; i = g_slist_next (i)) {
++ const char *subsys;
++
++ d = HAL_DEVICE (i->data);
++ subsys = hal_device_property_get_string (d, "linux.subsystem");
++ if (subsys && (strcmp(subsys, "power_supply") == 0)) {
++ hal_util_grep_discard_existing_data();
++ device_property_atomic_update_begin ();
++ refresh_battery_fast(d);
++ device_property_atomic_update_end ();
++ }
++ }
++ }
++ g_slist_free (battery_devices);
++ return TRUE;
++}
+
+ static HalDevice *
+ power_supply_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev,
+@@ -3274,6 +3303,11 @@ power_supply_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *
+ hal_device_property_set_string (d, "battery.type", battery_type);
+ refresh_battery_slow (d);
+ hal_device_add_capability (d, "battery");
++
++ /* setup timer for things that we need to poll */
++ g_timeout_add ( POWER_SUPPLY_BATTERY_POLL_INTERVAL,
++ power_supply_battery_poll,
++ NULL);
+ }
+
+ if (is_ac_adapter == TRUE) {
+
+commit e34bd7913a0d2cbf9708304e2dc935e51f406a5a
+Author: Danny Kukawka <danny.kukawka at web.de>
+Date: Tue Jan 29 23:38:16 2008 +0100
+
+ get battery.voltage.design on ACPI power_supply batteries
+
+ Applied adopted version of a patch from Sjoerd Simons <sjoerd at luon.net>
+ git repo. Get battery.voltage.design for ACPI power_supply batteries
+ from voltage_min_design.
+
+ > According to Alexey Starikovskiy:
+ > On most new batteries design voltage is less than current voltage,
+ > thus I've chosen VOLTAGE_MIN_DESIGN. On older batteries, current
+ > voltage may become lower than design, so I think hal should not be
+ > very strict about how they relate to each other.
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index d85e947..cfc29bc 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -3192,6 +3192,9 @@ refresh_battery_slow (HalDevice *d)
+ if (hal_util_get_int_from_file (path, "voltage_max_design", &voltage_design, 10)) {
+ hal_device_property_set_int (d, "battery.voltage.design", voltage_design / 1000);
+ hal_device_property_set_string (d, "battery.voltage.unit", "mV");
++ } else if (hal_util_get_int_from_file (path, "voltage_min_design", &voltage_design, 10)) {
++ hal_device_property_set_int (d, "battery.voltage.design", voltage_design / 1000);
++ hal_device_property_set_string (d, "battery.voltage.unit", "mV");
+ }
+
+ /* try to get the design info and set the units */
+
+commit a48ed19cebaffe6f4f3d77e91cfa93c6f55df0ea
+Author: Thadeu Lima de Souza Cascardo <cascardo at minaslivre.org>
+Date: Tue Feb 5 22:37:18 2008 +0100
+
+ fixed typo in power_supply code
+
+ Test for success in reading file, not failure.
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index cfc29bc..441bab0 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -3045,7 +3045,7 @@ refresh_battery_fast (HalDevice *d)
+ }
+
+ /* CURRENT: we prefer the average if it exists, although present is still pretty good */
+- if (!hal_util_get_int_from_file (path, "current_avg", ¤t, 10)) {
++ if (hal_util_get_int_from_file (path, "current_avg", ¤t, 10)) {
+ hal_device_property_set_int (d, "battery.reporting.rate", current / 1000);
+ } else if (hal_util_get_int_from_file (path, "current_now", ¤t, 10)) {
+ hal_device_property_set_int (d, "battery.reporting.rate", current / 1000);
+
+commit 571d456534dfd4887fc81c142afa29761d2a6c4e
+Author: Sjoerd Simons <sjoerd at luon.net>
+Date: Sat Dec 8 21:38:36 2007 +0100
+
+ implement osspec_privileged_init in the dummy backend
+
+ This added a noop osspec_privileged_init implementation for the dummy backend.
+ Patch by Samuel Thibault in Debian bug #444574
+
+diff --git a/hald/dummy/osspec.c b/hald/dummy/osspec.c
+index c4bc3c9..36ed07b 100644
+--- a/hald/dummy/osspec.c
++++ b/hald/dummy/osspec.c
+@@ -38,6 +38,11 @@
+ #include "../device_info.h"
+
+ void
++osspec_privileged_init (void)
++{
++}
++
++void
+ osspec_init (void)
+ {
+ }
+
+commit 3b6d7bbc8dc95e2e2f0e7465376ce7ac8280944d
+Author: Sjoerd Simons <sjoerd at luon.net>
+Date: Sat Mar 1 12:42:23 2008 +0100
+
+ get battery serial number from sysfs
+
+ Get the battery serial number from sysfs
+
+diff --git a/hald/linux/device.c b/hald/linux/device.c
+index 441bab0..842b85a 100644
+--- a/hald/linux/device.c
++++ b/hald/linux/device.c
+@@ -3160,6 +3160,7 @@ refresh_battery_slow (HalDevice *d)
+ char *technology_raw;
+ char *model_name;
+ char *manufacturer;
++ char *serial;
+ const gchar *path;
+
+ path = hal_device_property_get_string (d, "linux.sysfs_path");
+@@ -3206,6 +3207,12 @@ refresh_battery_slow (HalDevice *d)
+ hal_device_property_set_string (d, "battery.reporting.unit", "mAh");
+ }
+
++ /* get serial */
++ serial = hal_util_get_string_from_file (path, "serial_number");
++ if (serial != NULL) {
++ hal_device_property_set_string (d, "battery.serial", serial);
++ }
++
+ /* now do stuff that happens quickly */
+ refresh_battery_fast (d);
+ }
More information about the Pkg-utopia-commits
mailing list