blob: 9fb9d5ac939db1c071c4cdcaa7fba49364236e25 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +04002 * battery.c - ACPI Battery Driver (Revision: 2.0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +04004 * Copyright (C) 2007 Alexey Starikovskiy <astarikovskiy@suse.de>
5 * Copyright (C) 2004-2007 Vladimir Lebedev <vladimir.p.lebedev@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
7 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
8 *
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 *
25 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 */
27
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/types.h>
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +040032#include <linux/jiffies.h>
Arjan van de Ven0f66af52009-01-10 14:19:05 -050033#include <linux/async.h>
Hector Martinbc76f902009-08-06 15:57:48 -070034#include <linux/dmi.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Alexey Starikovskiyd7380962007-09-26 19:43:04 +040036
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +030037#ifdef CONFIG_ACPI_PROCFS_POWER
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/proc_fs.h>
39#include <linux/seq_file.h>
40#include <asm/uaccess.h>
Alexey Starikovskiyd7380962007-09-26 19:43:04 +040041#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <acpi/acpi_bus.h>
44#include <acpi/acpi_drivers.h>
Alexey Starikovskiyd7380962007-09-26 19:43:04 +040045#include <linux/power_supply.h>
46
Len Browna192a952009-07-28 16:45:54 -040047#define PREFIX "ACPI: "
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define ACPI_BATTERY_VALUE_UNKNOWN 0xFFFFFFFF
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define ACPI_BATTERY_CLASS "battery"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define ACPI_BATTERY_DEVICE_NAME "Battery"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define ACPI_BATTERY_NOTIFY_STATUS 0x80
54#define ACPI_BATTERY_NOTIFY_INFO 0x81
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +040055#define ACPI_BATTERY_NOTIFY_THRESHOLD 0x82
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define _COMPONENT ACPI_BATTERY_COMPONENT
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +030058
Len Brownf52fd662007-02-12 22:42:12 -050059ACPI_MODULE_NAME("battery");
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Len Brownf52fd662007-02-12 22:42:12 -050061MODULE_AUTHOR("Paul Diefenbaugh");
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +040062MODULE_AUTHOR("Alexey Starikovskiy <astarikovskiy@suse.de>");
Len Brown7cda93e2007-02-12 23:50:02 -050063MODULE_DESCRIPTION("ACPI Battery Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070064MODULE_LICENSE("GPL");
65
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +040066static unsigned int cache_time = 1000;
67module_param(cache_time, uint, 0644);
68MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +030069
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +030070#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -040071extern struct proc_dir_entry *acpi_lock_battery_dir(void);
72extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
73
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +040074enum acpi_battery_files {
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +040075 info_tag = 0,
76 state_tag,
77 alarm_tag,
Alexey Starikovskiy78490d82007-05-11 13:18:55 -040078 ACPI_BATTERY_NUMFILES,
79};
80
Alexey Starikovskiyd7380962007-09-26 19:43:04 +040081#endif
82
83static const struct acpi_device_id battery_device_ids[] = {
84 {"PNP0C0A", 0},
85 {"", 0},
86};
87
88MODULE_DEVICE_TABLE(acpi, battery_device_ids);
89
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +040090enum {
91 ACPI_BATTERY_ALARM_PRESENT,
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +040092 ACPI_BATTERY_XINFO_PRESENT,
93 /* For buggy DSDTs that report negative 16-bit values for either
94 * charging or discharging current and/or report 0 as 65536
95 * due to bad math.
96 */
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +040097 ACPI_BATTERY_QUIRK_SIGNED16_CURRENT,
Zhang Rui557d5862010-10-22 10:02:06 +080098 ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY,
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +040099};
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400100
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400101struct acpi_battery {
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400102 struct mutex lock;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400103 struct power_supply bat;
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400104 struct acpi_device *device;
105 unsigned long update_time;
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400106 int rate_now;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400107 int capacity_now;
108 int voltage_now;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400109 int design_capacity;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400110 int full_charge_capacity;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400111 int technology;
112 int design_voltage;
113 int design_capacity_warning;
114 int design_capacity_low;
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400115 int cycle_count;
116 int measurement_accuracy;
117 int max_sampling_time;
118 int min_sampling_time;
119 int max_averaging_interval;
120 int min_averaging_interval;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400121 int capacity_granularity_1;
122 int capacity_granularity_2;
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400123 int alarm;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400124 char model_number[32];
125 char serial_number[32];
126 char type[32];
127 char oem_info[32];
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400128 int state;
129 int power_unit;
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400130 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
Zhang Rui3138b322010-12-08 10:40:49 +0800133static int acpi_battery_update(struct acpi_battery *battery);
134
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400135#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
136
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400137inline int acpi_battery_present(struct acpi_battery *battery)
138{
139 return battery->device->status.battery_present;
140}
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400141
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400142static int acpi_battery_technology(struct acpi_battery *battery)
143{
144 if (!strcasecmp("NiCd", battery->type))
145 return POWER_SUPPLY_TECHNOLOGY_NiCd;
146 if (!strcasecmp("NiMH", battery->type))
147 return POWER_SUPPLY_TECHNOLOGY_NiMH;
148 if (!strcasecmp("LION", battery->type))
149 return POWER_SUPPLY_TECHNOLOGY_LION;
Andrey Borzenkovad40e682007-11-10 20:02:49 +0300150 if (!strncasecmp("LI-ION", battery->type, 6))
Alexey Starikovskiy0bde7ee2007-10-28 15:33:10 +0300151 return POWER_SUPPLY_TECHNOLOGY_LION;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400152 if (!strcasecmp("LiP", battery->type))
153 return POWER_SUPPLY_TECHNOLOGY_LIPO;
154 return POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
155}
156
Alexey Starikovskiy91044762007-11-13 12:23:06 +0300157static int acpi_battery_get_state(struct acpi_battery *battery);
Alexey Starikovskiyb19073a2007-10-25 17:10:47 -0400158
Richard Hughes56f382a2009-01-25 15:05:50 +0000159static int acpi_battery_is_charged(struct acpi_battery *battery)
160{
161 /* either charging or discharging */
162 if (battery->state != 0)
163 return 0;
164
165 /* battery not reporting charge */
166 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN ||
167 battery->capacity_now == 0)
168 return 0;
169
170 /* good batteries update full_charge as the batteries degrade */
171 if (battery->full_charge_capacity == battery->capacity_now)
172 return 1;
173
174 /* fallback to using design values for broken batteries */
175 if (battery->design_capacity == battery->capacity_now)
176 return 1;
177
178 /* we don't do any sort of metric based on percentages */
179 return 0;
180}
181
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400182static int acpi_battery_get_property(struct power_supply *psy,
183 enum power_supply_property psp,
184 union power_supply_propval *val)
185{
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200186 int ret = 0;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400187 struct acpi_battery *battery = to_acpi_battery(psy);
188
Zhang Rui3138b322010-12-08 10:40:49 +0800189 if (acpi_battery_update(battery))
190 return -ENODEV;
191
Alexey Starikovskiy91044762007-11-13 12:23:06 +0300192 if (acpi_battery_present(battery)) {
193 /* run battery update only if it is present */
194 acpi_battery_get_state(battery);
195 } else if (psp != POWER_SUPPLY_PROP_PRESENT)
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400196 return -ENODEV;
197 switch (psp) {
198 case POWER_SUPPLY_PROP_STATUS:
199 if (battery->state & 0x01)
200 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
201 else if (battery->state & 0x02)
202 val->intval = POWER_SUPPLY_STATUS_CHARGING;
Richard Hughes56f382a2009-01-25 15:05:50 +0000203 else if (acpi_battery_is_charged(battery))
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400204 val->intval = POWER_SUPPLY_STATUS_FULL;
Roland Dreier4c41d3a2007-11-07 15:09:09 -0800205 else
206 val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400207 break;
208 case POWER_SUPPLY_PROP_PRESENT:
209 val->intval = acpi_battery_present(battery);
210 break;
211 case POWER_SUPPLY_PROP_TECHNOLOGY:
212 val->intval = acpi_battery_technology(battery);
213 break;
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400214 case POWER_SUPPLY_PROP_CYCLE_COUNT:
215 val->intval = battery->cycle_count;
216 break;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400217 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200218 if (battery->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN)
219 ret = -ENODEV;
220 else
221 val->intval = battery->design_voltage * 1000;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400222 break;
223 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200224 if (battery->voltage_now == ACPI_BATTERY_VALUE_UNKNOWN)
225 ret = -ENODEV;
226 else
227 val->intval = battery->voltage_now * 1000;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400228 break;
229 case POWER_SUPPLY_PROP_CURRENT_NOW:
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400230 case POWER_SUPPLY_PROP_POWER_NOW:
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200231 if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN)
232 ret = -ENODEV;
233 else
234 val->intval = battery->rate_now * 1000;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400235 break;
236 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
237 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200238 if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
239 ret = -ENODEV;
240 else
241 val->intval = battery->design_capacity * 1000;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400242 break;
243 case POWER_SUPPLY_PROP_CHARGE_FULL:
244 case POWER_SUPPLY_PROP_ENERGY_FULL:
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200245 if (battery->full_charge_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
246 ret = -ENODEV;
247 else
248 val->intval = battery->full_charge_capacity * 1000;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400249 break;
250 case POWER_SUPPLY_PROP_CHARGE_NOW:
251 case POWER_SUPPLY_PROP_ENERGY_NOW:
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200252 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN)
253 ret = -ENODEV;
254 else
255 val->intval = battery->capacity_now * 1000;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400256 break;
257 case POWER_SUPPLY_PROP_MODEL_NAME:
258 val->strval = battery->model_number;
259 break;
260 case POWER_SUPPLY_PROP_MANUFACTURER:
261 val->strval = battery->oem_info;
262 break;
maximilian attems7c2670b2008-01-22 18:46:50 +0100263 case POWER_SUPPLY_PROP_SERIAL_NUMBER:
264 val->strval = battery->serial_number;
265 break;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400266 default:
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200267 ret = -EINVAL;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400268 }
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200269 return ret;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400270}
271
272static enum power_supply_property charge_battery_props[] = {
273 POWER_SUPPLY_PROP_STATUS,
274 POWER_SUPPLY_PROP_PRESENT,
275 POWER_SUPPLY_PROP_TECHNOLOGY,
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400276 POWER_SUPPLY_PROP_CYCLE_COUNT,
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400277 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
278 POWER_SUPPLY_PROP_VOLTAGE_NOW,
279 POWER_SUPPLY_PROP_CURRENT_NOW,
280 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
281 POWER_SUPPLY_PROP_CHARGE_FULL,
282 POWER_SUPPLY_PROP_CHARGE_NOW,
283 POWER_SUPPLY_PROP_MODEL_NAME,
284 POWER_SUPPLY_PROP_MANUFACTURER,
maximilian attems7c2670b2008-01-22 18:46:50 +0100285 POWER_SUPPLY_PROP_SERIAL_NUMBER,
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400286};
287
288static enum power_supply_property energy_battery_props[] = {
289 POWER_SUPPLY_PROP_STATUS,
290 POWER_SUPPLY_PROP_PRESENT,
291 POWER_SUPPLY_PROP_TECHNOLOGY,
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400292 POWER_SUPPLY_PROP_CYCLE_COUNT,
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400293 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
294 POWER_SUPPLY_PROP_VOLTAGE_NOW,
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400295 POWER_SUPPLY_PROP_POWER_NOW,
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400296 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
297 POWER_SUPPLY_PROP_ENERGY_FULL,
298 POWER_SUPPLY_PROP_ENERGY_NOW,
299 POWER_SUPPLY_PROP_MODEL_NAME,
300 POWER_SUPPLY_PROP_MANUFACTURER,
maximilian attems7c2670b2008-01-22 18:46:50 +0100301 POWER_SUPPLY_PROP_SERIAL_NUMBER,
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400302};
303
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300304#ifdef CONFIG_ACPI_PROCFS_POWER
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400305inline char *acpi_battery_units(struct acpi_battery *battery)
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400306{
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400307 return (battery->power_unit)?"mA":"mW";
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400308}
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400309#endif
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/* --------------------------------------------------------------------------
312 Battery Management
313 -------------------------------------------------------------------------- */
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400314struct acpi_offsets {
315 size_t offset; /* offset inside struct acpi_sbs_battery */
316 u8 mode; /* int or string? */
317};
318
319static struct acpi_offsets state_offsets[] = {
320 {offsetof(struct acpi_battery, state), 0},
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400321 {offsetof(struct acpi_battery, rate_now), 0},
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400322 {offsetof(struct acpi_battery, capacity_now), 0},
323 {offsetof(struct acpi_battery, voltage_now), 0},
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400324};
325
326static struct acpi_offsets info_offsets[] = {
327 {offsetof(struct acpi_battery, power_unit), 0},
328 {offsetof(struct acpi_battery, design_capacity), 0},
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400329 {offsetof(struct acpi_battery, full_charge_capacity), 0},
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400330 {offsetof(struct acpi_battery, technology), 0},
331 {offsetof(struct acpi_battery, design_voltage), 0},
332 {offsetof(struct acpi_battery, design_capacity_warning), 0},
333 {offsetof(struct acpi_battery, design_capacity_low), 0},
334 {offsetof(struct acpi_battery, capacity_granularity_1), 0},
335 {offsetof(struct acpi_battery, capacity_granularity_2), 0},
336 {offsetof(struct acpi_battery, model_number), 1},
337 {offsetof(struct acpi_battery, serial_number), 1},
338 {offsetof(struct acpi_battery, type), 1},
339 {offsetof(struct acpi_battery, oem_info), 1},
340};
341
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400342static struct acpi_offsets extended_info_offsets[] = {
343 {offsetof(struct acpi_battery, power_unit), 0},
344 {offsetof(struct acpi_battery, design_capacity), 0},
345 {offsetof(struct acpi_battery, full_charge_capacity), 0},
346 {offsetof(struct acpi_battery, technology), 0},
347 {offsetof(struct acpi_battery, design_voltage), 0},
348 {offsetof(struct acpi_battery, design_capacity_warning), 0},
349 {offsetof(struct acpi_battery, design_capacity_low), 0},
350 {offsetof(struct acpi_battery, cycle_count), 0},
351 {offsetof(struct acpi_battery, measurement_accuracy), 0},
352 {offsetof(struct acpi_battery, max_sampling_time), 0},
353 {offsetof(struct acpi_battery, min_sampling_time), 0},
354 {offsetof(struct acpi_battery, max_averaging_interval), 0},
355 {offsetof(struct acpi_battery, min_averaging_interval), 0},
356 {offsetof(struct acpi_battery, capacity_granularity_1), 0},
357 {offsetof(struct acpi_battery, capacity_granularity_2), 0},
358 {offsetof(struct acpi_battery, model_number), 1},
359 {offsetof(struct acpi_battery, serial_number), 1},
360 {offsetof(struct acpi_battery, type), 1},
361 {offsetof(struct acpi_battery, oem_info), 1},
362};
363
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400364static int extract_package(struct acpi_battery *battery,
365 union acpi_object *package,
366 struct acpi_offsets *offsets, int num)
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300367{
Alexey Starikovskiy106449e2007-10-29 23:29:40 +0300368 int i;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400369 union acpi_object *element;
370 if (package->type != ACPI_TYPE_PACKAGE)
371 return -EFAULT;
372 for (i = 0; i < num; ++i) {
373 if (package->package.count <= i)
374 return -EFAULT;
375 element = &package->package.elements[i];
376 if (offsets[i].mode) {
Alexey Starikovskiy106449e2007-10-29 23:29:40 +0300377 u8 *ptr = (u8 *)battery + offsets[i].offset;
378 if (element->type == ACPI_TYPE_STRING ||
379 element->type == ACPI_TYPE_BUFFER)
380 strncpy(ptr, element->string.pointer, 32);
381 else if (element->type == ACPI_TYPE_INTEGER) {
382 strncpy(ptr, (u8 *)&element->integer.value,
Lin Ming439913f2010-01-28 10:53:19 +0800383 sizeof(u64));
384 ptr[sizeof(u64)] = 0;
Alexey Starikovskiyb8a1bdb2008-03-17 22:37:42 -0400385 } else
386 *ptr = 0; /* don't have value */
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400387 } else {
Alexey Starikovskiyb8a1bdb2008-03-17 22:37:42 -0400388 int *x = (int *)((u8 *)battery + offsets[i].offset);
389 *x = (element->type == ACPI_TYPE_INTEGER) ?
390 element->integer.value : -1;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300391 }
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300392 }
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300393 return 0;
394}
395
396static int acpi_battery_get_status(struct acpi_battery *battery)
397{
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400398 if (acpi_bus_get_status(battery->device)) {
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300399 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Evaluating _STA"));
400 return -ENODEV;
401 }
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400402 return 0;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300403}
404
405static int acpi_battery_get_info(struct acpi_battery *battery)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400407 int result = -EFAULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400408 acpi_status status = 0;
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400409 char *name = test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags)?
410 "_BIX" : "_BIF";
411
Len Brown4be44fc2005-08-05 00:44:28 -0400412 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300414 if (!acpi_battery_present(battery))
415 return 0;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400416 mutex_lock(&battery->lock);
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400417 status = acpi_evaluate_object(battery->device->handle, name,
418 NULL, &buffer);
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400419 mutex_unlock(&battery->lock);
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400422 ACPI_EXCEPTION((AE_INFO, status, "Evaluating %s", name));
Patrick Mocheld550d982006-06-27 00:41:40 -0400423 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400425 if (test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags))
426 result = extract_package(battery, buffer.pointer,
427 extended_info_offsets,
428 ARRAY_SIZE(extended_info_offsets));
429 else
430 result = extract_package(battery, buffer.pointer,
431 info_offsets, ARRAY_SIZE(info_offsets));
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400432 kfree(buffer.pointer);
Zhang Rui557d5862010-10-22 10:02:06 +0800433 if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags))
434 battery->full_charge_capacity = battery->design_capacity;
Patrick Mocheld550d982006-06-27 00:41:40 -0400435 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300438static int acpi_battery_get_state(struct acpi_battery *battery)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Len Brown4be44fc2005-08-05 00:44:28 -0400440 int result = 0;
441 acpi_status status = 0;
442 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300444 if (!acpi_battery_present(battery))
445 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400447 if (battery->update_time &&
448 time_before(jiffies, battery->update_time +
449 msecs_to_jiffies(cache_time)))
450 return 0;
451
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400452 mutex_lock(&battery->lock);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400453 status = acpi_evaluate_object(battery->device->handle, "_BST",
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400454 NULL, &buffer);
455 mutex_unlock(&battery->lock);
Len Brown5b31d892007-08-15 00:19:26 -0400456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400458 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400459 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 }
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400461
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400462 result = extract_package(battery, buffer.pointer,
463 state_offsets, ARRAY_SIZE(state_offsets));
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400464 battery->update_time = jiffies;
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400465 kfree(buffer.pointer);
Hector Martinbc76f902009-08-06 15:57:48 -0700466
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400467 if (test_bit(ACPI_BATTERY_QUIRK_SIGNED16_CURRENT, &battery->flags) &&
Hector Martinbc76f902009-08-06 15:57:48 -0700468 battery->rate_now != -1)
469 battery->rate_now = abs((s16)battery->rate_now);
470
Zhang Rui557d5862010-10-22 10:02:06 +0800471 if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags)
472 && battery->capacity_now >= 0 && battery->capacity_now <= 100)
473 battery->capacity_now = (battery->capacity_now *
474 battery->full_charge_capacity) / 100;
Patrick Mocheld550d982006-06-27 00:41:40 -0400475 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476}
477
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400478static int acpi_battery_set_alarm(struct acpi_battery *battery)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Len Brown4be44fc2005-08-05 00:44:28 -0400480 acpi_status status = 0;
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400481 union acpi_object arg0 = { .type = ACPI_TYPE_INTEGER };
Len Brown4be44fc2005-08-05 00:44:28 -0400482 struct acpi_object_list arg_list = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400484 if (!acpi_battery_present(battery) ||
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400485 !test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags))
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300486 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400488 arg0.integer.value = battery->alarm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400490 mutex_lock(&battery->lock);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400491 status = acpi_evaluate_object(battery->device->handle, "_BTP",
492 &arg_list, NULL);
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400493 mutex_unlock(&battery->lock);
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400496 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400498 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Alarm set to %d\n", battery->alarm));
Patrick Mocheld550d982006-06-27 00:41:40 -0400499 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500}
501
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300502static int acpi_battery_init_alarm(struct acpi_battery *battery)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Len Brown4be44fc2005-08-05 00:44:28 -0400504 acpi_status status = AE_OK;
505 acpi_handle handle = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300507 /* See if alarms are supported, and if so, set default */
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400508 status = acpi_get_handle(battery->device->handle, "_BTP", &handle);
509 if (ACPI_FAILURE(status)) {
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400510 clear_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400511 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 }
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400513 set_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400514 if (!battery->alarm)
515 battery->alarm = battery->design_capacity_warning;
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400516 return acpi_battery_set_alarm(battery);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
Andrey Borzenkov508df922007-10-28 12:50:09 +0300519static ssize_t acpi_battery_alarm_show(struct device *dev,
520 struct device_attribute *attr,
521 char *buf)
522{
523 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
524 return sprintf(buf, "%d\n", battery->alarm * 1000);
525}
526
527static ssize_t acpi_battery_alarm_store(struct device *dev,
528 struct device_attribute *attr,
529 const char *buf, size_t count)
530{
531 unsigned long x;
532 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
533 if (sscanf(buf, "%ld\n", &x) == 1)
534 battery->alarm = x/1000;
535 if (acpi_battery_present(battery))
536 acpi_battery_set_alarm(battery);
537 return count;
538}
539
540static struct device_attribute alarm_attr = {
Parag Warudkar01e8ef12008-10-18 20:28:50 -0700541 .attr = {.name = "alarm", .mode = 0644},
Andrey Borzenkov508df922007-10-28 12:50:09 +0300542 .show = acpi_battery_alarm_show,
543 .store = acpi_battery_alarm_store,
544};
545
546static int sysfs_add_battery(struct acpi_battery *battery)
547{
548 int result;
549
Andrey Borzenkov508df922007-10-28 12:50:09 +0300550 if (battery->power_unit) {
551 battery->bat.properties = charge_battery_props;
552 battery->bat.num_properties =
553 ARRAY_SIZE(charge_battery_props);
554 } else {
555 battery->bat.properties = energy_battery_props;
556 battery->bat.num_properties =
557 ARRAY_SIZE(energy_battery_props);
558 }
559
560 battery->bat.name = acpi_device_bid(battery->device);
561 battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;
562 battery->bat.get_property = acpi_battery_get_property;
563
564 result = power_supply_register(&battery->device->dev, &battery->bat);
565 if (result)
566 return result;
567 return device_create_file(battery->bat.dev, &alarm_attr);
568}
569
570static void sysfs_remove_battery(struct acpi_battery *battery)
571{
572 if (!battery->bat.dev)
573 return;
574 device_remove_file(battery->bat.dev, &alarm_attr);
575 power_supply_unregister(&battery->bat);
Alexey Starikovskiy91044762007-11-13 12:23:06 +0300576 battery->bat.dev = NULL;
Andrey Borzenkov508df922007-10-28 12:50:09 +0300577}
578
Hector Martinbc76f902009-08-06 15:57:48 -0700579static void acpi_battery_quirks(struct acpi_battery *battery)
580{
Hector Martinbc76f902009-08-06 15:57:48 -0700581 if (dmi_name_in_vendors("Acer") && battery->power_unit) {
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400582 set_bit(ACPI_BATTERY_QUIRK_SIGNED16_CURRENT, &battery->flags);
Hector Martinbc76f902009-08-06 15:57:48 -0700583 }
584}
585
Zhang Rui557d5862010-10-22 10:02:06 +0800586/*
587 * According to the ACPI spec, some kinds of primary batteries can
588 * report percentage battery remaining capacity directly to OS.
589 * In this case, it reports the Last Full Charged Capacity == 100
590 * and BatteryPresentRate == 0xFFFFFFFF.
591 *
592 * Now we found some battery reports percentage remaining capacity
593 * even if it's rechargeable.
594 * https://bugzilla.kernel.org/show_bug.cgi?id=15979
595 *
596 * Handle this correctly so that they won't break userspace.
597 */
598static void acpi_battery_quirks2(struct acpi_battery *battery)
599{
600 if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags))
601 return ;
602
603 if (battery->full_charge_capacity == 100 &&
604 battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN &&
605 battery->capacity_now >=0 && battery->capacity_now <= 100) {
606 set_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags);
607 battery->full_charge_capacity = battery->design_capacity;
608 battery->capacity_now = (battery->capacity_now *
609 battery->full_charge_capacity) / 100;
610 }
611}
612
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400613static int acpi_battery_update(struct acpi_battery *battery)
Vladimir Lebedev4bd35cd2007-02-10 01:43:48 -0500614{
Alexey Starikovskiy50b17852008-12-23 02:44:54 +0300615 int result, old_present = acpi_battery_present(battery);
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500616 result = acpi_battery_get_status(battery);
Andrey Borzenkov508df922007-10-28 12:50:09 +0300617 if (result)
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300618 return result;
Andrey Borzenkov508df922007-10-28 12:50:09 +0300619 if (!acpi_battery_present(battery)) {
620 sysfs_remove_battery(battery);
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500621 battery->update_time = 0;
Andrey Borzenkov508df922007-10-28 12:50:09 +0300622 return 0;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300623 }
Alexey Starikovskiy50b17852008-12-23 02:44:54 +0300624 if (!battery->update_time ||
625 old_present != acpi_battery_present(battery)) {
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500626 result = acpi_battery_get_info(battery);
627 if (result)
628 return result;
Hector Martinbc76f902009-08-06 15:57:48 -0700629 acpi_battery_quirks(battery);
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500630 acpi_battery_init_alarm(battery);
631 }
Andrey Borzenkov508df922007-10-28 12:50:09 +0300632 if (!battery->bat.dev)
633 sysfs_add_battery(battery);
Zhang Rui557d5862010-10-22 10:02:06 +0800634 result = acpi_battery_get_state(battery);
635 acpi_battery_quirks2(battery);
636 return result;
Vladimir Lebedev4bd35cd2007-02-10 01:43:48 -0500637}
638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639/* --------------------------------------------------------------------------
640 FS Interface (/proc)
641 -------------------------------------------------------------------------- */
642
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300643#ifdef CONFIG_ACPI_PROCFS_POWER
Len Brown4be44fc2005-08-05 00:44:28 -0400644static struct proc_dir_entry *acpi_battery_dir;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300645
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400646static int acpi_battery_print_info(struct seq_file *seq, int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200648 struct acpi_battery *battery = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300650 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 goto end;
652
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400653 seq_printf(seq, "present: %s\n",
654 acpi_battery_present(battery)?"yes":"no");
655 if (!acpi_battery_present(battery))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 goto end;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400657 if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 seq_printf(seq, "design capacity: unknown\n");
659 else
660 seq_printf(seq, "design capacity: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400661 battery->design_capacity,
662 acpi_battery_units(battery));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400664 if (battery->full_charge_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 seq_printf(seq, "last full capacity: unknown\n");
666 else
667 seq_printf(seq, "last full capacity: %d %sh\n",
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400668 battery->full_charge_capacity,
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400669 acpi_battery_units(battery));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400671 seq_printf(seq, "battery technology: %srechargeable\n",
672 (!battery->technology)?"non-":"");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400674 if (battery->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 seq_printf(seq, "design voltage: unknown\n");
676 else
677 seq_printf(seq, "design voltage: %d mV\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400678 battery->design_voltage);
Len Brown4be44fc2005-08-05 00:44:28 -0400679 seq_printf(seq, "design capacity warning: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400680 battery->design_capacity_warning,
681 acpi_battery_units(battery));
Len Brown4be44fc2005-08-05 00:44:28 -0400682 seq_printf(seq, "design capacity low: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400683 battery->design_capacity_low,
684 acpi_battery_units(battery));
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400685 seq_printf(seq, "cycle count: %i\n", battery->cycle_count);
Len Brown4be44fc2005-08-05 00:44:28 -0400686 seq_printf(seq, "capacity granularity 1: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400687 battery->capacity_granularity_1,
688 acpi_battery_units(battery));
Len Brown4be44fc2005-08-05 00:44:28 -0400689 seq_printf(seq, "capacity granularity 2: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400690 battery->capacity_granularity_2,
691 acpi_battery_units(battery));
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400692 seq_printf(seq, "model number: %s\n", battery->model_number);
693 seq_printf(seq, "serial number: %s\n", battery->serial_number);
694 seq_printf(seq, "battery type: %s\n", battery->type);
695 seq_printf(seq, "OEM info: %s\n", battery->oem_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400696 end:
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300697 if (result)
698 seq_printf(seq, "ERROR: Unable to read battery info\n");
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300699 return result;
700}
701
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400702static int acpi_battery_print_state(struct seq_file *seq, int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200704 struct acpi_battery *battery = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300706 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 goto end;
708
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400709 seq_printf(seq, "present: %s\n",
710 acpi_battery_present(battery)?"yes":"no");
711 if (!acpi_battery_present(battery))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400714 seq_printf(seq, "capacity state: %s\n",
715 (battery->state & 0x04)?"critical":"ok");
716 if ((battery->state & 0x01) && (battery->state & 0x02))
Len Brown4be44fc2005-08-05 00:44:28 -0400717 seq_printf(seq,
718 "charging state: charging/discharging\n");
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400719 else if (battery->state & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 seq_printf(seq, "charging state: discharging\n");
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400721 else if (battery->state & 0x02)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 seq_printf(seq, "charging state: charging\n");
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400723 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 seq_printf(seq, "charging state: charged\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400726 if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 seq_printf(seq, "present rate: unknown\n");
728 else
729 seq_printf(seq, "present rate: %d %s\n",
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400730 battery->rate_now, acpi_battery_units(battery));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400732 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 seq_printf(seq, "remaining capacity: unknown\n");
734 else
735 seq_printf(seq, "remaining capacity: %d %sh\n",
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400736 battery->capacity_now, acpi_battery_units(battery));
737 if (battery->voltage_now == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 seq_printf(seq, "present voltage: unknown\n");
739 else
740 seq_printf(seq, "present voltage: %d mV\n",
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400741 battery->voltage_now);
Len Brown4be44fc2005-08-05 00:44:28 -0400742 end:
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400743 if (result)
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300744 seq_printf(seq, "ERROR: Unable to read battery state\n");
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300745
746 return result;
747}
748
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400749static int acpi_battery_print_alarm(struct seq_file *seq, int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200751 struct acpi_battery *battery = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300753 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 goto end;
755
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300756 if (!acpi_battery_present(battery)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 seq_printf(seq, "present: no\n");
758 goto end;
759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 seq_printf(seq, "alarm: ");
761 if (!battery->alarm)
762 seq_printf(seq, "unsupported\n");
763 else
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400764 seq_printf(seq, "%u %sh\n", battery->alarm,
765 acpi_battery_units(battery));
Len Brown4be44fc2005-08-05 00:44:28 -0400766 end:
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300767 if (result)
768 seq_printf(seq, "ERROR: Unable to read battery alarm\n");
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300769 return result;
770}
771
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400772static ssize_t acpi_battery_write_alarm(struct file *file,
773 const char __user * buffer,
774 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
Len Brown4be44fc2005-08-05 00:44:28 -0400776 int result = 0;
777 char alarm_string[12] = { '\0' };
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200778 struct seq_file *m = file->private_data;
779 struct acpi_battery *battery = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 if (!battery || (count > sizeof(alarm_string) - 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400782 return -EINVAL;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300783 if (!acpi_battery_present(battery)) {
784 result = -ENODEV;
785 goto end;
786 }
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300787 if (copy_from_user(alarm_string, buffer, count)) {
788 result = -EFAULT;
789 goto end;
790 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 alarm_string[count] = '\0';
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400792 battery->alarm = simple_strtol(alarm_string, NULL, 0);
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400793 result = acpi_battery_set_alarm(battery);
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300794 end:
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300795 if (!result)
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400796 return count;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300797 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400800typedef int(*print_func)(struct seq_file *seq, int result);
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400801
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400802static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = {
803 acpi_battery_print_info,
804 acpi_battery_print_state,
805 acpi_battery_print_alarm,
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400806};
807
808static int acpi_battery_read(int fid, struct seq_file *seq)
809{
810 struct acpi_battery *battery = seq->private;
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400811 int result = acpi_battery_update(battery);
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400812 return acpi_print_funcs[fid](seq, result);
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400813}
814
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400815#define DECLARE_FILE_FUNCTIONS(_name) \
816static int acpi_battery_read_##_name(struct seq_file *seq, void *offset) \
817{ \
818 return acpi_battery_read(_name##_tag, seq); \
819} \
820static int acpi_battery_##_name##_open_fs(struct inode *inode, struct file *file) \
821{ \
822 return single_open(file, acpi_battery_read_##_name, PDE(inode)->data); \
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400823}
824
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400825DECLARE_FILE_FUNCTIONS(info);
826DECLARE_FILE_FUNCTIONS(state);
827DECLARE_FILE_FUNCTIONS(alarm);
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400828
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400829#undef DECLARE_FILE_FUNCTIONS
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400830
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400831#define FILE_DESCRIPTION_RO(_name) \
832 { \
833 .name = __stringify(_name), \
834 .mode = S_IRUGO, \
835 .ops = { \
836 .open = acpi_battery_##_name##_open_fs, \
837 .read = seq_read, \
838 .llseek = seq_lseek, \
839 .release = single_release, \
840 .owner = THIS_MODULE, \
841 }, \
842 }
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400843
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400844#define FILE_DESCRIPTION_RW(_name) \
845 { \
846 .name = __stringify(_name), \
847 .mode = S_IFREG | S_IRUGO | S_IWUSR, \
848 .ops = { \
849 .open = acpi_battery_##_name##_open_fs, \
850 .read = seq_read, \
851 .llseek = seq_lseek, \
852 .write = acpi_battery_write_##_name, \
853 .release = single_release, \
854 .owner = THIS_MODULE, \
855 }, \
856 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400858static struct battery_file {
859 struct file_operations ops;
860 mode_t mode;
Jan Engelhardt070d8eb2009-01-12 00:07:55 +0100861 const char *name;
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400862} acpi_battery_file[] = {
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400863 FILE_DESCRIPTION_RO(info),
864 FILE_DESCRIPTION_RO(state),
865 FILE_DESCRIPTION_RW(alarm),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866};
867
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400868#undef FILE_DESCRIPTION_RO
869#undef FILE_DESCRIPTION_RW
870
Len Brown4be44fc2005-08-05 00:44:28 -0400871static int acpi_battery_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
Len Brown4be44fc2005-08-05 00:44:28 -0400873 struct proc_dir_entry *entry = NULL;
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400874 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 if (!acpi_device_dir(device)) {
877 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400878 acpi_battery_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400880 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
882
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400883 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700884 entry = proc_create_data(acpi_battery_file[i].name,
885 acpi_battery_file[i].mode,
886 acpi_device_dir(device),
887 &acpi_battery_file[i].ops,
888 acpi_driver_data(device));
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400889 if (!entry)
890 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400892 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893}
894
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400895static void acpi_battery_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400897 int i;
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400898 if (!acpi_device_dir(device))
899 return;
900 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i)
901 remove_proc_entry(acpi_battery_file[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400904 remove_proc_entry(acpi_device_bid(device), acpi_battery_dir);
905 acpi_device_dir(device) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906}
907
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400908#endif
Alexey Starikovskiy3e58ea02007-09-26 19:43:11 +0400909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910/* --------------------------------------------------------------------------
911 Driver Interface
912 -------------------------------------------------------------------------- */
913
Bjorn Helgaasd9406692009-04-30 09:35:47 -0600914static void acpi_battery_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Bjorn Helgaasd9406692009-04-30 09:35:47 -0600916 struct acpi_battery *battery = acpi_driver_data(device);
Zhang Rui153e5002010-07-07 09:11:57 +0800917 struct device *old;
Bjorn Helgaasd9406692009-04-30 09:35:47 -0600918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 if (!battery)
Patrick Mocheld550d982006-06-27 00:41:40 -0400920 return;
Zhang Rui153e5002010-07-07 09:11:57 +0800921 old = battery->bat.dev;
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400922 acpi_battery_update(battery);
923 acpi_bus_generate_proc_event(device, event,
924 acpi_battery_present(battery));
925 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100926 dev_name(&device->dev), event,
Vladimir Lebedev9ea7d572007-02-20 15:48:06 +0300927 acpi_battery_present(battery));
Justin P. Mattock2345baf2009-12-13 14:42:36 -0800928 /* acpi_battery_update could remove power_supply object */
Zhang Rui153e5002010-07-07 09:11:57 +0800929 if (old && battery->bat.dev)
Alan Jenkinsf79e1ce2009-06-30 14:36:16 +0000930 power_supply_changed(&battery->bat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
Len Brown4be44fc2005-08-05 00:44:28 -0400933static int acpi_battery_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
Len Brown4be44fc2005-08-05 00:44:28 -0400935 int result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400936 struct acpi_battery *battery = NULL;
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400937 acpi_handle handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400939 return -EINVAL;
Burman Yan36bcbec2006-12-19 12:56:11 -0800940 battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 if (!battery)
Patrick Mocheld550d982006-06-27 00:41:40 -0400942 return -ENOMEM;
Patrick Mochel145def82006-05-19 16:54:39 -0400943 battery->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
945 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700946 device->driver_data = battery;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400947 mutex_init(&battery->lock);
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400948 if (ACPI_SUCCESS(acpi_get_handle(battery->device->handle,
949 "_BIX", &handle)))
950 set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400951 acpi_battery_update(battery);
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300952#ifdef CONFIG_ACPI_PROCFS_POWER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 result = acpi_battery_add_fs(device);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400954#endif
Len Brown586caae2009-06-18 00:38:27 -0400955 if (!result) {
956 printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n",
957 ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
958 device->status.battery_present ? "present" : "absent");
959 } else {
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300960#ifdef CONFIG_ACPI_PROCFS_POWER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 acpi_battery_remove_fs(device);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400962#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 kfree(battery);
964 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400965 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966}
967
Len Brown4be44fc2005-08-05 00:44:28 -0400968static int acpi_battery_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
Len Brown4be44fc2005-08-05 00:44:28 -0400970 struct acpi_battery *battery = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400973 return -EINVAL;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200974 battery = acpi_driver_data(device);
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300975#ifdef CONFIG_ACPI_PROCFS_POWER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 acpi_battery_remove_fs(device);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400977#endif
Andrey Borzenkov508df922007-10-28 12:50:09 +0300978 sysfs_remove_battery(battery);
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400979 mutex_destroy(&battery->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 kfree(battery);
Patrick Mocheld550d982006-06-27 00:41:40 -0400981 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982}
983
Jiri Kosina34c44152006-10-10 14:20:41 -0700984/* this is needed to learn about changes made in suspended state */
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800985static int acpi_battery_resume(struct acpi_device *device)
Jiri Kosina34c44152006-10-10 14:20:41 -0700986{
987 struct acpi_battery *battery;
Jiri Kosina34c44152006-10-10 14:20:41 -0700988 if (!device)
989 return -EINVAL;
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400990 battery = acpi_driver_data(device);
991 battery->update_time = 0;
Andrey Borzenkov508df922007-10-28 12:50:09 +0300992 acpi_battery_update(battery);
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300993 return 0;
Jiri Kosina34c44152006-10-10 14:20:41 -0700994}
995
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400996static struct acpi_driver acpi_battery_driver = {
997 .name = "battery",
998 .class = ACPI_BATTERY_CLASS,
999 .ids = battery_device_ids,
Bjorn Helgaasd9406692009-04-30 09:35:47 -06001000 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +04001001 .ops = {
1002 .add = acpi_battery_add,
1003 .resume = acpi_battery_resume,
1004 .remove = acpi_battery_remove,
Bjorn Helgaasd9406692009-04-30 09:35:47 -06001005 .notify = acpi_battery_notify,
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +04001006 },
1007};
1008
Linus Torvaldsb0cbc862009-04-11 12:45:20 -07001009static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
Pavel Machek4d8316d2006-08-14 22:37:22 -07001011 if (acpi_disabled)
Arjan van de Ven0f66af52009-01-10 14:19:05 -05001012 return;
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +03001013#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -04001014 acpi_battery_dir = acpi_lock_battery_dir();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (!acpi_battery_dir)
Arjan van de Ven0f66af52009-01-10 14:19:05 -05001016 return;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +04001017#endif
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +04001018 if (acpi_bus_register_driver(&acpi_battery_driver) < 0) {
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +03001019#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -04001020 acpi_unlock_battery_dir(acpi_battery_dir);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +04001021#endif
Arjan van de Ven0f66af52009-01-10 14:19:05 -05001022 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
Arjan van de Ven0f66af52009-01-10 14:19:05 -05001024 return;
1025}
1026
1027static int __init acpi_battery_init(void)
1028{
1029 async_schedule(acpi_battery_init_async, NULL);
Patrick Mocheld550d982006-06-27 00:41:40 -04001030 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031}
1032
Len Brown4be44fc2005-08-05 00:44:28 -04001033static void __exit acpi_battery_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 acpi_bus_unregister_driver(&acpi_battery_driver);
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +03001036#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -04001037 acpi_unlock_battery_dir(acpi_battery_dir);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +04001038#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039}
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041module_init(acpi_battery_init);
1042module_exit(acpi_battery_exit);