summarylogtreecommitdiffstats
path: root/cpufreqd_acpi_battery.c.patch
blob: 51f63532d1e974e01008925a1730dfe922231345 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
--- src/cpufreqd_acpi_battery.c	2010-03-28 04:34:54.000000000 -0700
+++ 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;