]> git.pld-linux.org Git - packages/cpufreqd.git/blobdiff - cpufreqd-battery.patch
- rel 2
[packages/cpufreqd.git] / cpufreqd-battery.patch
diff --git a/cpufreqd-battery.patch b/cpufreqd-battery.patch
new file mode 100644 (file)
index 0000000..a2fa0f0
--- /dev/null
@@ -0,0 +1,176 @@
+--- cpufreqd-2.4.2/src/cpufreqd_acpi_battery.c 2010-03-28 04:34:54.000000000 -0700
++++ cpufreqd-2.4.2/src/cpufreqd_acpi_battery.c 2010-11-21 18:51:32.000000000 -0800
+@@ -29,12 +29,15 @@ 
+ #define POWER_SUPPLY  "power_supply"
+ #define BATTERY_TYPE  "Battery"
++#define PRESENT               "present"
++#define STATUS                "status"
++//energy batter properties
+ #define ENERGY_FULL   "energy_full"
+ #define ENERGY_NOW    "energy_now"
++#define POWER_NOW     "power_now"
++//charge battery properties
+ #define CHARGE_FULL   "charge_full"
+ #define CHARGE_NOW    "charge_now"
+-#define PRESENT               "present"
+-#define STATUS                "status"
+ #define CURRENT_NOW   "current_now"
+ struct battery_info {
+@@ -45,11 +48,11 @@ 
+       int is_present;
+       struct sysfs_class_device *cdev;
+-      struct sysfs_attribute *energy_full; /* last full capacity */
+-      struct sysfs_attribute *energy_now; /* remaining capacity */
++      struct sysfs_attribute *full_capacity; /* last full capacity */
++      struct sysfs_attribute *remaining_capacity; /* remaining capacity */
+       struct sysfs_attribute *present;
+       struct sysfs_attribute *status;
+-      struct sysfs_attribute *current_now; /* present rate */
++      struct sysfs_attribute *draw_rate; /* present rate */
+       int open;
+ };
+@@ -87,16 +90,16 @@ 
+       if (!binfo->open) return;
+-      if (binfo->energy_full)
+-              put_attribute(binfo->energy_full);
+-      if (binfo->energy_now)
+-              put_attribute(binfo->energy_now);
++      if (binfo->full_capacity)
++              put_attribute(binfo->full_capacity);
++      if (binfo->remaining_capacity)
++              put_attribute(binfo->remaining_capacity);
+       if (binfo->present)
+               put_attribute(binfo->present);
+       if (binfo->status)
+               put_attribute(binfo->status);
+-      if (binfo->current_now)
+-              put_attribute(binfo->current_now);
++      if (binfo->draw_rate)
++              put_attribute(binfo->draw_rate);
+       binfo->open = 0;
+ }
+@@ -104,11 +107,11 @@ 
+ static int read_battery(struct battery_info *binfo) {
+       clog(LOG_DEBUG, "%s - reading battery levels\n", binfo->cdev->name);
+-      if (read_int(binfo->current_now, &binfo->present_rate) != 0) {
++      if (read_int(binfo->draw_rate, &binfo->present_rate) != 0) {
+               clog(LOG_ERR, "Skipping %s\n", binfo->cdev->name);
+               return -1;
+       }
+-      if (read_int(binfo->energy_now, &binfo->remaining) != 0) {
++      if (read_int(binfo->remaining_capacity, &binfo->remaining) != 0) {
+               clog(LOG_ERR, "Skipping %s\n", binfo->cdev->name);
+               return -1;
+       }
+@@ -120,38 +123,88 @@ 
+                       binfo->cdev->name, binfo->remaining);
+       return 0;
+ }
++
++/* open energy battery specific attributes */
++static int read_energy_battery_attributes(struct battery_info *binfo)
++{
++      binfo->full_capacity = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
++      if(!binfo->full_capacity)
++      {
++              return -1;
++      }
++
++      binfo->remaining_capacity = get_class_device_attribute(binfo->cdev, ENERGY_NOW);
++      if(!binfo->remaining_capacity)
++      {
++              return -1;
++      }
++
++      binfo->draw_rate = get_class_device_attribute(binfo->cdev, POWER_NOW);
++      if(!binfo->draw_rate)
++      {
++              return -1;
++      }
++
++      return 0;
++}
++
++/* open charge battery specific attributes */
++static int read_charge_battery_attributes(struct battery_info *binfo)
++{
++      binfo->full_capacity = get_class_device_attribute(binfo->cdev, CHARGE_FULL);
++      if(!binfo->full_capacity)
++      {
++              return -1;
++      }
++
++      binfo->remaining_capacity = get_class_device_attribute(binfo->cdev, CHARGE_NOW);
++      if(!binfo->remaining_capacity)
++      {
++              return -1;
++      }
++
++      binfo->draw_rate = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
++      if(!binfo->draw_rate)
++      {
++              return -1;
++      }
++
++      return 0;
++}
++
+ /* open all the required attributes and set the open status */
+ static int open_battery(struct battery_info *binfo) {
+       binfo->open = 1;
+-      binfo->energy_full = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
+-      if (!binfo->energy_full) {
+-              /* try the "charge_full" name */
+-              binfo->energy_full = get_class_device_attribute(binfo->cdev,
+-                              CHARGE_FULL);
+-              if (!binfo->energy_full)
++      //attempt to open energy attribute
++      struct sysfs_attribute *tmp_attribute = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
++
++      if(!tmp_attribute)
++      {
++              if(read_charge_battery_attributes(binfo) != 0)
++              {
+                       return -1;
++              }
+       }
+-      binfo->energy_now = get_class_device_attribute(binfo->cdev, ENERGY_NOW);
+-      if (!binfo->energy_now) {
+-              /* try the "charge_now" name */
+-              binfo->energy_now = get_class_device_attribute(binfo->cdev, CHARGE_NOW);
+-              if (!binfo->energy_now)
++      else
++      {
++              put_attribute(tmp_attribute);
++              if(read_energy_battery_attributes(binfo) != 0)
++              {
+                       return -1;
++              }
+       }
++
+       binfo->present = get_class_device_attribute(binfo->cdev, PRESENT);
+       if (!binfo->present)
+               return -1;
+       binfo->status = get_class_device_attribute(binfo->cdev, STATUS);
+       if (!binfo->status)
+               return -1;
+-      binfo->current_now = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
+-      if (!binfo->current_now)
+-              return -1;
+       /* read the last full capacity, this is not going to change
+        * very often, so no need to poke it later */
+-      if (read_int(binfo->energy_full, &binfo->capacity) != 0) {
++      if (read_int(binfo->full_capacity, &binfo->capacity) != 0) {
+               clog(LOG_WARNING, "Couldn't read %s capacity (%s)\n",
+                               binfo->cdev->name, strerror(errno));
+               return -1;
This page took 0.078353 seconds and 4 git commands to generate.