blob: ac74a7ddaaa4b006d1f58edd19670eea1e869927 [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>
45
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -050046#ifdef CONFIG_ACPI_SYSFS_POWER
Alexey Starikovskiyd7380962007-09-26 19:43:04 +040047#include <linux/power_supply.h>
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -050048#endif
Alexey Starikovskiyd7380962007-09-26 19:43:04 +040049
Len Browna192a952009-07-28 16:45:54 -040050#define PREFIX "ACPI: "
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define ACPI_BATTERY_VALUE_UNKNOWN 0xFFFFFFFF
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define ACPI_BATTERY_CLASS "battery"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#define ACPI_BATTERY_DEVICE_NAME "Battery"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#define ACPI_BATTERY_NOTIFY_STATUS 0x80
57#define ACPI_BATTERY_NOTIFY_INFO 0x81
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +040058#define ACPI_BATTERY_NOTIFY_THRESHOLD 0x82
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define _COMPONENT ACPI_BATTERY_COMPONENT
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +030061
Len Brownf52fd662007-02-12 22:42:12 -050062ACPI_MODULE_NAME("battery");
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Len Brownf52fd662007-02-12 22:42:12 -050064MODULE_AUTHOR("Paul Diefenbaugh");
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +040065MODULE_AUTHOR("Alexey Starikovskiy <astarikovskiy@suse.de>");
Len Brown7cda93e2007-02-12 23:50:02 -050066MODULE_DESCRIPTION("ACPI Battery Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067MODULE_LICENSE("GPL");
68
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +040069static unsigned int cache_time = 1000;
70module_param(cache_time, uint, 0644);
71MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +030072
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +030073#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -040074extern struct proc_dir_entry *acpi_lock_battery_dir(void);
75extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
76
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +040077enum acpi_battery_files {
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +040078 info_tag = 0,
79 state_tag,
80 alarm_tag,
Alexey Starikovskiy78490d82007-05-11 13:18:55 -040081 ACPI_BATTERY_NUMFILES,
82};
83
Alexey Starikovskiyd7380962007-09-26 19:43:04 +040084#endif
85
86static const struct acpi_device_id battery_device_ids[] = {
87 {"PNP0C0A", 0},
88 {"", 0},
89};
90
91MODULE_DEVICE_TABLE(acpi, battery_device_ids);
92
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +040093enum {
94 ACPI_BATTERY_ALARM_PRESENT,
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +040095 ACPI_BATTERY_XINFO_PRESENT,
96 /* For buggy DSDTs that report negative 16-bit values for either
97 * charging or discharging current and/or report 0 as 65536
98 * due to bad math.
99 */
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400100 ACPI_BATTERY_QUIRK_SIGNED16_CURRENT,
101};
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400102
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400103struct acpi_battery {
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400104 struct mutex lock;
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500105#ifdef CONFIG_ACPI_SYSFS_POWER
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400106 struct power_supply bat;
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500107#endif
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400108 struct acpi_device *device;
109 unsigned long update_time;
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400110 int rate_now;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400111 int capacity_now;
112 int voltage_now;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400113 int design_capacity;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400114 int full_charge_capacity;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400115 int technology;
116 int design_voltage;
117 int design_capacity_warning;
118 int design_capacity_low;
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400119 int cycle_count;
120 int measurement_accuracy;
121 int max_sampling_time;
122 int min_sampling_time;
123 int max_averaging_interval;
124 int min_averaging_interval;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400125 int capacity_granularity_1;
126 int capacity_granularity_2;
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400127 int alarm;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400128 char model_number[32];
129 char serial_number[32];
130 char type[32];
131 char oem_info[32];
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400132 int state;
133 int power_unit;
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400134 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400137#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
138
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400139inline int acpi_battery_present(struct acpi_battery *battery)
140{
141 return battery->device->status.battery_present;
142}
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400143
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500144#ifdef CONFIG_ACPI_SYSFS_POWER
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400145static int acpi_battery_technology(struct acpi_battery *battery)
146{
147 if (!strcasecmp("NiCd", battery->type))
148 return POWER_SUPPLY_TECHNOLOGY_NiCd;
149 if (!strcasecmp("NiMH", battery->type))
150 return POWER_SUPPLY_TECHNOLOGY_NiMH;
151 if (!strcasecmp("LION", battery->type))
152 return POWER_SUPPLY_TECHNOLOGY_LION;
Andrey Borzenkovad40e682007-11-10 20:02:49 +0300153 if (!strncasecmp("LI-ION", battery->type, 6))
Alexey Starikovskiy0bde7ee2007-10-28 15:33:10 +0300154 return POWER_SUPPLY_TECHNOLOGY_LION;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400155 if (!strcasecmp("LiP", battery->type))
156 return POWER_SUPPLY_TECHNOLOGY_LIPO;
157 return POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
158}
159
Alexey Starikovskiy91044762007-11-13 12:23:06 +0300160static int acpi_battery_get_state(struct acpi_battery *battery);
Alexey Starikovskiyb19073a2007-10-25 17:10:47 -0400161
Richard Hughes56f382a2009-01-25 15:05:50 +0000162static int acpi_battery_is_charged(struct acpi_battery *battery)
163{
164 /* either charging or discharging */
165 if (battery->state != 0)
166 return 0;
167
168 /* battery not reporting charge */
169 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN ||
170 battery->capacity_now == 0)
171 return 0;
172
173 /* good batteries update full_charge as the batteries degrade */
174 if (battery->full_charge_capacity == battery->capacity_now)
175 return 1;
176
177 /* fallback to using design values for broken batteries */
178 if (battery->design_capacity == battery->capacity_now)
179 return 1;
180
181 /* we don't do any sort of metric based on percentages */
182 return 0;
183}
184
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400185static int acpi_battery_get_property(struct power_supply *psy,
186 enum power_supply_property psp,
187 union power_supply_propval *val)
188{
Rafael J. Wysockia1b4bd62010-10-23 19:35:15 +0200189 int ret = 0;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400190 struct acpi_battery *battery = to_acpi_battery(psy);
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};
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500303#endif
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400304
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300305#ifdef CONFIG_ACPI_PROCFS_POWER
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400306inline char *acpi_battery_units(struct acpi_battery *battery)
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400307{
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400308 return (battery->power_unit)?"mA":"mW";
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400309}
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400310#endif
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312/* --------------------------------------------------------------------------
313 Battery Management
314 -------------------------------------------------------------------------- */
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400315struct acpi_offsets {
316 size_t offset; /* offset inside struct acpi_sbs_battery */
317 u8 mode; /* int or string? */
318};
319
320static struct acpi_offsets state_offsets[] = {
321 {offsetof(struct acpi_battery, state), 0},
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400322 {offsetof(struct acpi_battery, rate_now), 0},
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400323 {offsetof(struct acpi_battery, capacity_now), 0},
324 {offsetof(struct acpi_battery, voltage_now), 0},
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400325};
326
327static struct acpi_offsets info_offsets[] = {
328 {offsetof(struct acpi_battery, power_unit), 0},
329 {offsetof(struct acpi_battery, design_capacity), 0},
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400330 {offsetof(struct acpi_battery, full_charge_capacity), 0},
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400331 {offsetof(struct acpi_battery, technology), 0},
332 {offsetof(struct acpi_battery, design_voltage), 0},
333 {offsetof(struct acpi_battery, design_capacity_warning), 0},
334 {offsetof(struct acpi_battery, design_capacity_low), 0},
335 {offsetof(struct acpi_battery, capacity_granularity_1), 0},
336 {offsetof(struct acpi_battery, capacity_granularity_2), 0},
337 {offsetof(struct acpi_battery, model_number), 1},
338 {offsetof(struct acpi_battery, serial_number), 1},
339 {offsetof(struct acpi_battery, type), 1},
340 {offsetof(struct acpi_battery, oem_info), 1},
341};
342
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400343static struct acpi_offsets extended_info_offsets[] = {
344 {offsetof(struct acpi_battery, power_unit), 0},
345 {offsetof(struct acpi_battery, design_capacity), 0},
346 {offsetof(struct acpi_battery, full_charge_capacity), 0},
347 {offsetof(struct acpi_battery, technology), 0},
348 {offsetof(struct acpi_battery, design_voltage), 0},
349 {offsetof(struct acpi_battery, design_capacity_warning), 0},
350 {offsetof(struct acpi_battery, design_capacity_low), 0},
351 {offsetof(struct acpi_battery, cycle_count), 0},
352 {offsetof(struct acpi_battery, measurement_accuracy), 0},
353 {offsetof(struct acpi_battery, max_sampling_time), 0},
354 {offsetof(struct acpi_battery, min_sampling_time), 0},
355 {offsetof(struct acpi_battery, max_averaging_interval), 0},
356 {offsetof(struct acpi_battery, min_averaging_interval), 0},
357 {offsetof(struct acpi_battery, capacity_granularity_1), 0},
358 {offsetof(struct acpi_battery, capacity_granularity_2), 0},
359 {offsetof(struct acpi_battery, model_number), 1},
360 {offsetof(struct acpi_battery, serial_number), 1},
361 {offsetof(struct acpi_battery, type), 1},
362 {offsetof(struct acpi_battery, oem_info), 1},
363};
364
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400365static int extract_package(struct acpi_battery *battery,
366 union acpi_object *package,
367 struct acpi_offsets *offsets, int num)
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300368{
Alexey Starikovskiy106449e2007-10-29 23:29:40 +0300369 int i;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400370 union acpi_object *element;
371 if (package->type != ACPI_TYPE_PACKAGE)
372 return -EFAULT;
373 for (i = 0; i < num; ++i) {
374 if (package->package.count <= i)
375 return -EFAULT;
376 element = &package->package.elements[i];
377 if (offsets[i].mode) {
Alexey Starikovskiy106449e2007-10-29 23:29:40 +0300378 u8 *ptr = (u8 *)battery + offsets[i].offset;
379 if (element->type == ACPI_TYPE_STRING ||
380 element->type == ACPI_TYPE_BUFFER)
381 strncpy(ptr, element->string.pointer, 32);
382 else if (element->type == ACPI_TYPE_INTEGER) {
383 strncpy(ptr, (u8 *)&element->integer.value,
Lin Ming439913f2010-01-28 10:53:19 +0800384 sizeof(u64));
385 ptr[sizeof(u64)] = 0;
Alexey Starikovskiyb8a1bdb2008-03-17 22:37:42 -0400386 } else
387 *ptr = 0; /* don't have value */
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400388 } else {
Alexey Starikovskiyb8a1bdb2008-03-17 22:37:42 -0400389 int *x = (int *)((u8 *)battery + offsets[i].offset);
390 *x = (element->type == ACPI_TYPE_INTEGER) ?
391 element->integer.value : -1;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300392 }
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300393 }
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300394 return 0;
395}
396
397static int acpi_battery_get_status(struct acpi_battery *battery)
398{
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400399 if (acpi_bus_get_status(battery->device)) {
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300400 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Evaluating _STA"));
401 return -ENODEV;
402 }
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400403 return 0;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300404}
405
406static int acpi_battery_get_info(struct acpi_battery *battery)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400408 int result = -EFAULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400409 acpi_status status = 0;
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400410 char *name = test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags)?
411 "_BIX" : "_BIF";
412
Len Brown4be44fc2005-08-05 00:44:28 -0400413 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300415 if (!acpi_battery_present(battery))
416 return 0;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400417 mutex_lock(&battery->lock);
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400418 status = acpi_evaluate_object(battery->device->handle, name,
419 NULL, &buffer);
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400420 mutex_unlock(&battery->lock);
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 if (ACPI_FAILURE(status)) {
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400423 ACPI_EXCEPTION((AE_INFO, status, "Evaluating %s", name));
Patrick Mocheld550d982006-06-27 00:41:40 -0400424 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400426 if (test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags))
427 result = extract_package(battery, buffer.pointer,
428 extended_info_offsets,
429 ARRAY_SIZE(extended_info_offsets));
430 else
431 result = extract_package(battery, buffer.pointer,
432 info_offsets, ARRAY_SIZE(info_offsets));
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400433 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -0400434 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300437static int acpi_battery_get_state(struct acpi_battery *battery)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Len Brown4be44fc2005-08-05 00:44:28 -0400439 int result = 0;
440 acpi_status status = 0;
441 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300443 if (!acpi_battery_present(battery))
444 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400446 if (battery->update_time &&
447 time_before(jiffies, battery->update_time +
448 msecs_to_jiffies(cache_time)))
449 return 0;
450
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400451 mutex_lock(&battery->lock);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400452 status = acpi_evaluate_object(battery->device->handle, "_BST",
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400453 NULL, &buffer);
454 mutex_unlock(&battery->lock);
Len Brown5b31d892007-08-15 00:19:26 -0400455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400457 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400458 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400460
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400461 result = extract_package(battery, buffer.pointer,
462 state_offsets, ARRAY_SIZE(state_offsets));
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400463 battery->update_time = jiffies;
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400464 kfree(buffer.pointer);
Hector Martinbc76f902009-08-06 15:57:48 -0700465
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400466 if (test_bit(ACPI_BATTERY_QUIRK_SIGNED16_CURRENT, &battery->flags) &&
Hector Martinbc76f902009-08-06 15:57:48 -0700467 battery->rate_now != -1)
468 battery->rate_now = abs((s16)battery->rate_now);
469
Patrick Mocheld550d982006-06-27 00:41:40 -0400470 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}
472
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400473static int acpi_battery_set_alarm(struct acpi_battery *battery)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Len Brown4be44fc2005-08-05 00:44:28 -0400475 acpi_status status = 0;
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400476 union acpi_object arg0 = { .type = ACPI_TYPE_INTEGER };
Len Brown4be44fc2005-08-05 00:44:28 -0400477 struct acpi_object_list arg_list = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400479 if (!acpi_battery_present(battery) ||
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400480 !test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags))
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300481 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400483 arg0.integer.value = battery->alarm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400485 mutex_lock(&battery->lock);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400486 status = acpi_evaluate_object(battery->device->handle, "_BTP",
487 &arg_list, NULL);
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400488 mutex_unlock(&battery->lock);
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400491 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400493 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Alarm set to %d\n", battery->alarm));
Patrick Mocheld550d982006-06-27 00:41:40 -0400494 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495}
496
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300497static int acpi_battery_init_alarm(struct acpi_battery *battery)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
Len Brown4be44fc2005-08-05 00:44:28 -0400499 acpi_status status = AE_OK;
500 acpi_handle handle = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300502 /* See if alarms are supported, and if so, set default */
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400503 status = acpi_get_handle(battery->device->handle, "_BTP", &handle);
504 if (ACPI_FAILURE(status)) {
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400505 clear_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400506 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400508 set_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400509 if (!battery->alarm)
510 battery->alarm = battery->design_capacity_warning;
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400511 return acpi_battery_set_alarm(battery);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512}
513
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500514#ifdef CONFIG_ACPI_SYSFS_POWER
Andrey Borzenkov508df922007-10-28 12:50:09 +0300515static ssize_t acpi_battery_alarm_show(struct device *dev,
516 struct device_attribute *attr,
517 char *buf)
518{
519 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
520 return sprintf(buf, "%d\n", battery->alarm * 1000);
521}
522
523static ssize_t acpi_battery_alarm_store(struct device *dev,
524 struct device_attribute *attr,
525 const char *buf, size_t count)
526{
527 unsigned long x;
528 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
529 if (sscanf(buf, "%ld\n", &x) == 1)
530 battery->alarm = x/1000;
531 if (acpi_battery_present(battery))
532 acpi_battery_set_alarm(battery);
533 return count;
534}
535
536static struct device_attribute alarm_attr = {
Parag Warudkar01e8ef12008-10-18 20:28:50 -0700537 .attr = {.name = "alarm", .mode = 0644},
Andrey Borzenkov508df922007-10-28 12:50:09 +0300538 .show = acpi_battery_alarm_show,
539 .store = acpi_battery_alarm_store,
540};
541
542static int sysfs_add_battery(struct acpi_battery *battery)
543{
544 int result;
545
Andrey Borzenkov508df922007-10-28 12:50:09 +0300546 if (battery->power_unit) {
547 battery->bat.properties = charge_battery_props;
548 battery->bat.num_properties =
549 ARRAY_SIZE(charge_battery_props);
550 } else {
551 battery->bat.properties = energy_battery_props;
552 battery->bat.num_properties =
553 ARRAY_SIZE(energy_battery_props);
554 }
555
556 battery->bat.name = acpi_device_bid(battery->device);
557 battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;
558 battery->bat.get_property = acpi_battery_get_property;
559
560 result = power_supply_register(&battery->device->dev, &battery->bat);
561 if (result)
562 return result;
563 return device_create_file(battery->bat.dev, &alarm_attr);
564}
565
566static void sysfs_remove_battery(struct acpi_battery *battery)
567{
568 if (!battery->bat.dev)
569 return;
570 device_remove_file(battery->bat.dev, &alarm_attr);
571 power_supply_unregister(&battery->bat);
Alexey Starikovskiy91044762007-11-13 12:23:06 +0300572 battery->bat.dev = NULL;
Andrey Borzenkov508df922007-10-28 12:50:09 +0300573}
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500574#endif
Andrey Borzenkov508df922007-10-28 12:50:09 +0300575
Hector Martinbc76f902009-08-06 15:57:48 -0700576static void acpi_battery_quirks(struct acpi_battery *battery)
577{
Hector Martinbc76f902009-08-06 15:57:48 -0700578 if (dmi_name_in_vendors("Acer") && battery->power_unit) {
Alexey Starikovskiy7b3bcc42009-10-15 14:31:24 +0400579 set_bit(ACPI_BATTERY_QUIRK_SIGNED16_CURRENT, &battery->flags);
Hector Martinbc76f902009-08-06 15:57:48 -0700580 }
581}
582
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400583static int acpi_battery_update(struct acpi_battery *battery)
Vladimir Lebedev4bd35cd2007-02-10 01:43:48 -0500584{
Alexey Starikovskiy50b17852008-12-23 02:44:54 +0300585 int result, old_present = acpi_battery_present(battery);
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500586 result = acpi_battery_get_status(battery);
Andrey Borzenkov508df922007-10-28 12:50:09 +0300587 if (result)
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300588 return result;
Andrey Borzenkov508df922007-10-28 12:50:09 +0300589 if (!acpi_battery_present(battery)) {
Alan Jenkinse363a752009-06-30 14:35:05 +0000590#ifdef CONFIG_ACPI_SYSFS_POWER
Andrey Borzenkov508df922007-10-28 12:50:09 +0300591 sysfs_remove_battery(battery);
Alan Jenkinse363a752009-06-30 14:35:05 +0000592#endif
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500593 battery->update_time = 0;
Andrey Borzenkov508df922007-10-28 12:50:09 +0300594 return 0;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300595 }
Alexey Starikovskiy50b17852008-12-23 02:44:54 +0300596 if (!battery->update_time ||
597 old_present != acpi_battery_present(battery)) {
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500598 result = acpi_battery_get_info(battery);
599 if (result)
600 return result;
Hector Martinbc76f902009-08-06 15:57:48 -0700601 acpi_battery_quirks(battery);
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500602 acpi_battery_init_alarm(battery);
603 }
604#ifdef CONFIG_ACPI_SYSFS_POWER
Andrey Borzenkov508df922007-10-28 12:50:09 +0300605 if (!battery->bat.dev)
606 sysfs_add_battery(battery);
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500607#endif
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400608 return acpi_battery_get_state(battery);
Vladimir Lebedev4bd35cd2007-02-10 01:43:48 -0500609}
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611/* --------------------------------------------------------------------------
612 FS Interface (/proc)
613 -------------------------------------------------------------------------- */
614
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300615#ifdef CONFIG_ACPI_PROCFS_POWER
Len Brown4be44fc2005-08-05 00:44:28 -0400616static struct proc_dir_entry *acpi_battery_dir;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300617
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400618static int acpi_battery_print_info(struct seq_file *seq, int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200620 struct acpi_battery *battery = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300622 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 goto end;
624
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400625 seq_printf(seq, "present: %s\n",
626 acpi_battery_present(battery)?"yes":"no");
627 if (!acpi_battery_present(battery))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 goto end;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400629 if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 seq_printf(seq, "design capacity: unknown\n");
631 else
632 seq_printf(seq, "design capacity: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400633 battery->design_capacity,
634 acpi_battery_units(battery));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400636 if (battery->full_charge_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 seq_printf(seq, "last full capacity: unknown\n");
638 else
639 seq_printf(seq, "last full capacity: %d %sh\n",
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400640 battery->full_charge_capacity,
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400641 acpi_battery_units(battery));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400643 seq_printf(seq, "battery technology: %srechargeable\n",
644 (!battery->technology)?"non-":"");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400646 if (battery->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 seq_printf(seq, "design voltage: unknown\n");
648 else
649 seq_printf(seq, "design voltage: %d mV\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400650 battery->design_voltage);
Len Brown4be44fc2005-08-05 00:44:28 -0400651 seq_printf(seq, "design capacity warning: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400652 battery->design_capacity_warning,
653 acpi_battery_units(battery));
Len Brown4be44fc2005-08-05 00:44:28 -0400654 seq_printf(seq, "design capacity low: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400655 battery->design_capacity_low,
656 acpi_battery_units(battery));
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400657 seq_printf(seq, "cycle count: %i\n", battery->cycle_count);
Len Brown4be44fc2005-08-05 00:44:28 -0400658 seq_printf(seq, "capacity granularity 1: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400659 battery->capacity_granularity_1,
660 acpi_battery_units(battery));
Len Brown4be44fc2005-08-05 00:44:28 -0400661 seq_printf(seq, "capacity granularity 2: %d %sh\n",
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400662 battery->capacity_granularity_2,
663 acpi_battery_units(battery));
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400664 seq_printf(seq, "model number: %s\n", battery->model_number);
665 seq_printf(seq, "serial number: %s\n", battery->serial_number);
666 seq_printf(seq, "battery type: %s\n", battery->type);
667 seq_printf(seq, "OEM info: %s\n", battery->oem_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400668 end:
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300669 if (result)
670 seq_printf(seq, "ERROR: Unable to read battery info\n");
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300671 return result;
672}
673
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400674static int acpi_battery_print_state(struct seq_file *seq, int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200676 struct acpi_battery *battery = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300678 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 goto end;
680
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400681 seq_printf(seq, "present: %s\n",
682 acpi_battery_present(battery)?"yes":"no");
683 if (!acpi_battery_present(battery))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400686 seq_printf(seq, "capacity state: %s\n",
687 (battery->state & 0x04)?"critical":"ok");
688 if ((battery->state & 0x01) && (battery->state & 0x02))
Len Brown4be44fc2005-08-05 00:44:28 -0400689 seq_printf(seq,
690 "charging state: charging/discharging\n");
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400691 else if (battery->state & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 seq_printf(seq, "charging state: discharging\n");
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400693 else if (battery->state & 0x02)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 seq_printf(seq, "charging state: charging\n");
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400695 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 seq_printf(seq, "charging state: charged\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400698 if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 seq_printf(seq, "present rate: unknown\n");
700 else
701 seq_printf(seq, "present rate: %d %s\n",
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400702 battery->rate_now, acpi_battery_units(battery));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400704 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 seq_printf(seq, "remaining capacity: unknown\n");
706 else
707 seq_printf(seq, "remaining capacity: %d %sh\n",
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400708 battery->capacity_now, acpi_battery_units(battery));
709 if (battery->voltage_now == ACPI_BATTERY_VALUE_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 seq_printf(seq, "present voltage: unknown\n");
711 else
712 seq_printf(seq, "present voltage: %d mV\n",
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400713 battery->voltage_now);
Len Brown4be44fc2005-08-05 00:44:28 -0400714 end:
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400715 if (result)
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300716 seq_printf(seq, "ERROR: Unable to read battery state\n");
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300717
718 return result;
719}
720
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400721static int acpi_battery_print_alarm(struct seq_file *seq, int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200723 struct acpi_battery *battery = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300725 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 goto end;
727
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300728 if (!acpi_battery_present(battery)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 seq_printf(seq, "present: no\n");
730 goto end;
731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 seq_printf(seq, "alarm: ");
733 if (!battery->alarm)
734 seq_printf(seq, "unsupported\n");
735 else
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400736 seq_printf(seq, "%u %sh\n", battery->alarm,
737 acpi_battery_units(battery));
Len Brown4be44fc2005-08-05 00:44:28 -0400738 end:
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300739 if (result)
740 seq_printf(seq, "ERROR: Unable to read battery alarm\n");
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300741 return result;
742}
743
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400744static ssize_t acpi_battery_write_alarm(struct file *file,
745 const char __user * buffer,
746 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
Len Brown4be44fc2005-08-05 00:44:28 -0400748 int result = 0;
749 char alarm_string[12] = { '\0' };
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200750 struct seq_file *m = file->private_data;
751 struct acpi_battery *battery = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 if (!battery || (count > sizeof(alarm_string) - 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400754 return -EINVAL;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300755 if (!acpi_battery_present(battery)) {
756 result = -ENODEV;
757 goto end;
758 }
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300759 if (copy_from_user(alarm_string, buffer, count)) {
760 result = -EFAULT;
761 goto end;
762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 alarm_string[count] = '\0';
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400764 battery->alarm = simple_strtol(alarm_string, NULL, 0);
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400765 result = acpi_battery_set_alarm(battery);
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300766 end:
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300767 if (!result)
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400768 return count;
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300769 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
771
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400772typedef int(*print_func)(struct seq_file *seq, int result);
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400773
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400774static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = {
775 acpi_battery_print_info,
776 acpi_battery_print_state,
777 acpi_battery_print_alarm,
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400778};
779
780static int acpi_battery_read(int fid, struct seq_file *seq)
781{
782 struct acpi_battery *battery = seq->private;
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400783 int result = acpi_battery_update(battery);
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400784 return acpi_print_funcs[fid](seq, result);
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400785}
786
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400787#define DECLARE_FILE_FUNCTIONS(_name) \
788static int acpi_battery_read_##_name(struct seq_file *seq, void *offset) \
789{ \
790 return acpi_battery_read(_name##_tag, seq); \
791} \
792static int acpi_battery_##_name##_open_fs(struct inode *inode, struct file *file) \
793{ \
794 return single_open(file, acpi_battery_read_##_name, PDE(inode)->data); \
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400795}
796
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400797DECLARE_FILE_FUNCTIONS(info);
798DECLARE_FILE_FUNCTIONS(state);
799DECLARE_FILE_FUNCTIONS(alarm);
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400800
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400801#undef DECLARE_FILE_FUNCTIONS
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400802
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400803#define FILE_DESCRIPTION_RO(_name) \
804 { \
805 .name = __stringify(_name), \
806 .mode = S_IRUGO, \
807 .ops = { \
808 .open = acpi_battery_##_name##_open_fs, \
809 .read = seq_read, \
810 .llseek = seq_lseek, \
811 .release = single_release, \
812 .owner = THIS_MODULE, \
813 }, \
814 }
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400815
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400816#define FILE_DESCRIPTION_RW(_name) \
817 { \
818 .name = __stringify(_name), \
819 .mode = S_IFREG | S_IRUGO | S_IWUSR, \
820 .ops = { \
821 .open = acpi_battery_##_name##_open_fs, \
822 .read = seq_read, \
823 .llseek = seq_lseek, \
824 .write = acpi_battery_write_##_name, \
825 .release = single_release, \
826 .owner = THIS_MODULE, \
827 }, \
828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400830static struct battery_file {
831 struct file_operations ops;
832 mode_t mode;
Jan Engelhardt070d8eb2009-01-12 00:07:55 +0100833 const char *name;
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400834} acpi_battery_file[] = {
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400835 FILE_DESCRIPTION_RO(info),
836 FILE_DESCRIPTION_RO(state),
837 FILE_DESCRIPTION_RW(alarm),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838};
839
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400840#undef FILE_DESCRIPTION_RO
841#undef FILE_DESCRIPTION_RW
842
Len Brown4be44fc2005-08-05 00:44:28 -0400843static int acpi_battery_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
Len Brown4be44fc2005-08-05 00:44:28 -0400845 struct proc_dir_entry *entry = NULL;
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400846 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 if (!acpi_device_dir(device)) {
849 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400850 acpi_battery_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400852 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 }
854
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400855 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700856 entry = proc_create_data(acpi_battery_file[i].name,
857 acpi_battery_file[i].mode,
858 acpi_device_dir(device),
859 &acpi_battery_file[i].ops,
860 acpi_driver_data(device));
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400861 if (!entry)
862 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400864 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865}
866
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400867static void acpi_battery_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
Alexey Starikovskiy78490d82007-05-11 13:18:55 -0400869 int i;
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400870 if (!acpi_device_dir(device))
871 return;
872 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i)
873 remove_proc_entry(acpi_battery_file[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400876 remove_proc_entry(acpi_device_bid(device), acpi_battery_dir);
877 acpi_device_dir(device) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878}
879
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400880#endif
Alexey Starikovskiy3e58ea02007-09-26 19:43:11 +0400881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882/* --------------------------------------------------------------------------
883 Driver Interface
884 -------------------------------------------------------------------------- */
885
Bjorn Helgaasd9406692009-04-30 09:35:47 -0600886static void acpi_battery_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
Bjorn Helgaasd9406692009-04-30 09:35:47 -0600888 struct acpi_battery *battery = acpi_driver_data(device);
Zhang Rui153e5002010-07-07 09:11:57 +0800889#ifdef CONFIG_ACPI_SYSFS_POWER
890 struct device *old;
891#endif
Bjorn Helgaasd9406692009-04-30 09:35:47 -0600892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (!battery)
Patrick Mocheld550d982006-06-27 00:41:40 -0400894 return;
Zhang Rui153e5002010-07-07 09:11:57 +0800895#ifdef CONFIG_ACPI_SYSFS_POWER
896 old = battery->bat.dev;
897#endif
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400898 acpi_battery_update(battery);
899 acpi_bus_generate_proc_event(device, event,
900 acpi_battery_present(battery));
901 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100902 dev_name(&device->dev), event,
Vladimir Lebedev9ea7d572007-02-20 15:48:06 +0300903 acpi_battery_present(battery));
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500904#ifdef CONFIG_ACPI_SYSFS_POWER
Justin P. Mattock2345baf2009-12-13 14:42:36 -0800905 /* acpi_battery_update could remove power_supply object */
Zhang Rui153e5002010-07-07 09:11:57 +0800906 if (old && battery->bat.dev)
Alan Jenkinsf79e1ce2009-06-30 14:36:16 +0000907 power_supply_changed(&battery->bat);
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500908#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909}
910
Len Brown4be44fc2005-08-05 00:44:28 -0400911static int acpi_battery_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
Len Brown4be44fc2005-08-05 00:44:28 -0400913 int result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400914 struct acpi_battery *battery = NULL;
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400915 acpi_handle handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400917 return -EINVAL;
Burman Yan36bcbec2006-12-19 12:56:11 -0800918 battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 if (!battery)
Patrick Mocheld550d982006-06-27 00:41:40 -0400920 return -ENOMEM;
Patrick Mochel145def82006-05-19 16:54:39 -0400921 battery->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
923 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700924 device->driver_data = battery;
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400925 mutex_init(&battery->lock);
Alexey Starikovskiyc67fcd62009-10-15 14:31:44 +0400926 if (ACPI_SUCCESS(acpi_get_handle(battery->device->handle,
927 "_BIX", &handle)))
928 set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400929 acpi_battery_update(battery);
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300930#ifdef CONFIG_ACPI_PROCFS_POWER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 result = acpi_battery_add_fs(device);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400932#endif
Len Brown586caae2009-06-18 00:38:27 -0400933 if (!result) {
934 printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n",
935 ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
936 device->status.battery_present ? "present" : "absent");
937 } else {
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300938#ifdef CONFIG_ACPI_PROCFS_POWER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 acpi_battery_remove_fs(device);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400940#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 kfree(battery);
942 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400943 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944}
945
Len Brown4be44fc2005-08-05 00:44:28 -0400946static int acpi_battery_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
Len Brown4be44fc2005-08-05 00:44:28 -0400948 struct acpi_battery *battery = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400951 return -EINVAL;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200952 battery = acpi_driver_data(device);
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300953#ifdef CONFIG_ACPI_PROCFS_POWER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 acpi_battery_remove_fs(device);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400955#endif
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500956#ifdef CONFIG_ACPI_SYSFS_POWER
Andrey Borzenkov508df922007-10-28 12:50:09 +0300957 sysfs_remove_battery(battery);
Alexey Starikovskiy97749cd2008-01-01 14:27:24 -0500958#endif
Alexey Starikovskiy038fdea2007-09-26 19:42:46 +0400959 mutex_destroy(&battery->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 kfree(battery);
Patrick Mocheld550d982006-06-27 00:41:40 -0400961 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962}
963
Jiri Kosina34c44152006-10-10 14:20:41 -0700964/* this is needed to learn about changes made in suspended state */
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800965static int acpi_battery_resume(struct acpi_device *device)
Jiri Kosina34c44152006-10-10 14:20:41 -0700966{
967 struct acpi_battery *battery;
Jiri Kosina34c44152006-10-10 14:20:41 -0700968 if (!device)
969 return -EINVAL;
Alexey Starikovskiyf1d46612007-09-26 19:42:52 +0400970 battery = acpi_driver_data(device);
971 battery->update_time = 0;
Andrey Borzenkov508df922007-10-28 12:50:09 +0300972 acpi_battery_update(battery);
Vladimir Lebedevb6ce4082007-02-20 15:48:06 +0300973 return 0;
Jiri Kosina34c44152006-10-10 14:20:41 -0700974}
975
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400976static struct acpi_driver acpi_battery_driver = {
977 .name = "battery",
978 .class = ACPI_BATTERY_CLASS,
979 .ids = battery_device_ids,
Bjorn Helgaasd9406692009-04-30 09:35:47 -0600980 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400981 .ops = {
982 .add = acpi_battery_add,
983 .resume = acpi_battery_resume,
984 .remove = acpi_battery_remove,
Bjorn Helgaasd9406692009-04-30 09:35:47 -0600985 .notify = acpi_battery_notify,
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400986 },
987};
988
Linus Torvaldsb0cbc862009-04-11 12:45:20 -0700989static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990{
Pavel Machek4d8316d2006-08-14 22:37:22 -0700991 if (acpi_disabled)
Arjan van de Ven0f66af52009-01-10 14:19:05 -0500992 return;
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300993#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -0400994 acpi_battery_dir = acpi_lock_battery_dir();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 if (!acpi_battery_dir)
Arjan van de Ven0f66af52009-01-10 14:19:05 -0500996 return;
Alexey Starikovskiyd7380962007-09-26 19:43:04 +0400997#endif
Alexey Starikovskiyaa650bb2007-09-26 19:42:58 +0400998 if (acpi_bus_register_driver(&acpi_battery_driver) < 0) {
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300999#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -04001000 acpi_unlock_battery_dir(acpi_battery_dir);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +04001001#endif
Arjan van de Ven0f66af52009-01-10 14:19:05 -05001002 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
Arjan van de Ven0f66af52009-01-10 14:19:05 -05001004 return;
1005}
1006
1007static int __init acpi_battery_init(void)
1008{
1009 async_schedule(acpi_battery_init_async, NULL);
Patrick Mocheld550d982006-06-27 00:41:40 -04001010 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
1012
Len Brown4be44fc2005-08-05 00:44:28 -04001013static void __exit acpi_battery_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 acpi_bus_unregister_driver(&acpi_battery_driver);
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +03001016#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -04001017 acpi_unlock_battery_dir(acpi_battery_dir);
Alexey Starikovskiyd7380962007-09-26 19:43:04 +04001018#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019}
1020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021module_init(acpi_battery_init);
1022module_exit(acpi_battery_exit);