updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / cpufreqd / cpufreqd_acpi_battery.c.patch
blob029b24cafc30bd5317bab90d8d6c5d4d6de3e6f4
1 --- cpufreqd-2.4.2/src/cpufreqd_acpi_battery.c 2010-03-28 04:34:54.000000000 -0700
2 +++ cpufreqd-2.4.2/src/cpufreqd_acpi_battery.c 2010-11-21 18:51:32.000000000 -0800
3 @@ -29,12 +29,15 @@
5 #define POWER_SUPPLY "power_supply"
6 #define BATTERY_TYPE "Battery"
7 +#define PRESENT "present"
8 +#define STATUS "status"
9 +//energy batter properties
10 #define ENERGY_FULL "energy_full"
11 #define ENERGY_NOW "energy_now"
12 +#define POWER_NOW "power_now"
13 +//charge battery properties
14 #define CHARGE_FULL "charge_full"
15 #define CHARGE_NOW "charge_now"
16 -#define PRESENT "present"
17 -#define STATUS "status"
18 #define CURRENT_NOW "current_now"
20 struct battery_info {
21 @@ -45,11 +48,11 @@
22 int is_present;
24 struct sysfs_class_device *cdev;
25 - struct sysfs_attribute *energy_full; /* last full capacity */
26 - struct sysfs_attribute *energy_now; /* remaining capacity */
27 + struct sysfs_attribute *full_capacity; /* last full capacity */
28 + struct sysfs_attribute *remaining_capacity; /* remaining capacity */
29 struct sysfs_attribute *present;
30 struct sysfs_attribute *status;
31 - struct sysfs_attribute *current_now; /* present rate */
32 + struct sysfs_attribute *draw_rate; /* present rate */
34 int open;
36 @@ -87,16 +90,16 @@
38 if (!binfo->open) return;
40 - if (binfo->energy_full)
41 - put_attribute(binfo->energy_full);
42 - if (binfo->energy_now)
43 - put_attribute(binfo->energy_now);
44 + if (binfo->full_capacity)
45 + put_attribute(binfo->full_capacity);
46 + if (binfo->remaining_capacity)
47 + put_attribute(binfo->remaining_capacity);
48 if (binfo->present)
49 put_attribute(binfo->present);
50 if (binfo->status)
51 put_attribute(binfo->status);
52 - if (binfo->current_now)
53 - put_attribute(binfo->current_now);
54 + if (binfo->draw_rate)
55 + put_attribute(binfo->draw_rate);
57 binfo->open = 0;
59 @@ -104,11 +107,11 @@
60 static int read_battery(struct battery_info *binfo) {
61 clog(LOG_DEBUG, "%s - reading battery levels\n", binfo->cdev->name);
63 - if (read_int(binfo->current_now, &binfo->present_rate) != 0) {
64 + if (read_int(binfo->draw_rate, &binfo->present_rate) != 0) {
65 clog(LOG_ERR, "Skipping %s\n", binfo->cdev->name);
66 return -1;
68 - if (read_int(binfo->energy_now, &binfo->remaining) != 0) {
69 + if (read_int(binfo->remaining_capacity, &binfo->remaining) != 0) {
70 clog(LOG_ERR, "Skipping %s\n", binfo->cdev->name);
71 return -1;
73 @@ -120,38 +123,88 @@
74 binfo->cdev->name, binfo->remaining);
75 return 0;
78 +/* open energy battery specific attributes */
79 +static int read_energy_battery_attributes(struct battery_info *binfo)
81 + binfo->full_capacity = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
82 + if(!binfo->full_capacity)
83 + {
84 + return -1;
85 + }
87 + binfo->remaining_capacity = get_class_device_attribute(binfo->cdev, ENERGY_NOW);
88 + if(!binfo->remaining_capacity)
89 + {
90 + return -1;
91 + }
93 + binfo->draw_rate = get_class_device_attribute(binfo->cdev, POWER_NOW);
94 + if(!binfo->draw_rate)
95 + {
96 + return -1;
97 + }
99 + return 0;
102 +/* open charge battery specific attributes */
103 +static int read_charge_battery_attributes(struct battery_info *binfo)
105 + binfo->full_capacity = get_class_device_attribute(binfo->cdev, CHARGE_FULL);
106 + if(!binfo->full_capacity)
108 + return -1;
111 + binfo->remaining_capacity = get_class_device_attribute(binfo->cdev, CHARGE_NOW);
112 + if(!binfo->remaining_capacity)
114 + return -1;
117 + binfo->draw_rate = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
118 + if(!binfo->draw_rate)
120 + return -1;
123 + return 0;
126 /* open all the required attributes and set the open status */
127 static int open_battery(struct battery_info *binfo) {
128 binfo->open = 1;
130 - binfo->energy_full = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
131 - if (!binfo->energy_full) {
132 - /* try the "charge_full" name */
133 - binfo->energy_full = get_class_device_attribute(binfo->cdev,
134 - CHARGE_FULL);
135 - if (!binfo->energy_full)
136 + //attempt to open energy attribute
137 + struct sysfs_attribute *tmp_attribute = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
139 + if(!tmp_attribute)
141 + if(read_charge_battery_attributes(binfo) != 0)
143 return -1;
146 - binfo->energy_now = get_class_device_attribute(binfo->cdev, ENERGY_NOW);
147 - if (!binfo->energy_now) {
148 - /* try the "charge_now" name */
149 - binfo->energy_now = get_class_device_attribute(binfo->cdev, CHARGE_NOW);
150 - if (!binfo->energy_now)
151 + else
153 + put_attribute(tmp_attribute);
154 + if(read_energy_battery_attributes(binfo) != 0)
156 return -1;
160 binfo->present = get_class_device_attribute(binfo->cdev, PRESENT);
161 if (!binfo->present)
162 return -1;
163 binfo->status = get_class_device_attribute(binfo->cdev, STATUS);
164 if (!binfo->status)
165 return -1;
166 - binfo->current_now = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
167 - if (!binfo->current_now)
168 - return -1;
170 /* read the last full capacity, this is not going to change
171 * very often, so no need to poke it later */
172 - if (read_int(binfo->energy_full, &binfo->capacity) != 0) {
173 + if (read_int(binfo->full_capacity, &binfo->capacity) != 0) {
174 clog(LOG_WARNING, "Couldn't read %s capacity (%s)\n",
175 binfo->cdev->name, strerror(errno));
176 return -1;