]> git.pld-linux.org Git - packages/cpufreqd.git/blob - cpufreqd-battery.patch
- release 4 (by relup.sh)
[packages/cpufreqd.git] / cpufreqd-battery.patch
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 @@ 
4  
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"
19  
20  struct battery_info {
21 @@ -45,11 +48,11 @@ 
22         int is_present;
23  
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 */
33  
34         int open;
35  };
36 @@ -87,16 +90,16 @@ 
37  
38         if (!binfo->open) return;
39  
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);
56  
57         binfo->open = 0;
58  }
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);
62  
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;
67         }
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;
72         }
73 @@ -120,38 +123,88 @@ 
74                         binfo->cdev->name, binfo->remaining);
75         return 0;
76  }
77 +
78 +/* open energy battery specific attributes */
79 +static int read_energy_battery_attributes(struct battery_info *binfo)
80 +{
81 +       binfo->full_capacity = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
82 +       if(!binfo->full_capacity)
83 +       {
84 +               return -1;
85 +       }
86 +
87 +       binfo->remaining_capacity = get_class_device_attribute(binfo->cdev, ENERGY_NOW);
88 +       if(!binfo->remaining_capacity)
89 +       {
90 +               return -1;
91 +       }
92 +
93 +       binfo->draw_rate = get_class_device_attribute(binfo->cdev, POWER_NOW);
94 +       if(!binfo->draw_rate)
95 +       {
96 +               return -1;
97 +       }
98 +
99 +       return 0;
100 +}
101 +
102 +/* open charge battery specific attributes */
103 +static int read_charge_battery_attributes(struct battery_info *binfo)
104 +{
105 +       binfo->full_capacity = get_class_device_attribute(binfo->cdev, CHARGE_FULL);
106 +       if(!binfo->full_capacity)
107 +       {
108 +               return -1;
109 +       }
110 +
111 +       binfo->remaining_capacity = get_class_device_attribute(binfo->cdev, CHARGE_NOW);
112 +       if(!binfo->remaining_capacity)
113 +       {
114 +               return -1;
115 +       }
116 +
117 +       binfo->draw_rate = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
118 +       if(!binfo->draw_rate)
119 +       {
120 +               return -1;
121 +       }
122 +
123 +       return 0;
124 +}
125 +
126  /* open all the required attributes and set the open status */
127  static int open_battery(struct battery_info *binfo) {
128         binfo->open = 1;
129  
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);
138 +
139 +       if(!tmp_attribute)
140 +       {
141 +               if(read_charge_battery_attributes(binfo) != 0)
142 +               {
143                         return -1;
144 +               }
145         }
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
152 +       {
153 +               put_attribute(tmp_attribute);
154 +               if(read_energy_battery_attributes(binfo) != 0)
155 +               {
156                         return -1;
157 +               }
158         }
159 +
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;
169  
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;
This page took 0.056957 seconds and 3 git commands to generate.