Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 2 | * battery.c - ACPI Battery Driver (Revision: 2.0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 4 | * Copyright (C) 2007 Alexey Starikovskiy <astarikovskiy@suse.de> |
| 5 | * Copyright (C) 2004-2007 Vladimir Lebedev <vladimir.p.lebedev@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * 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 Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 32 | #include <linux/jiffies.h> |
Arjan van de Ven | 0f66af5 | 2009-01-10 14:19:05 -0500 | [diff] [blame] | 33 | #include <linux/async.h> |
Hector Martin | bc76f90 | 2009-08-06 15:57:48 -0700 | [diff] [blame] | 34 | #include <linux/dmi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 36 | |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 37 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/proc_fs.h> |
| 39 | #include <linux/seq_file.h> |
| 40 | #include <asm/uaccess.h> |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 41 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #include <acpi/acpi_bus.h> |
| 44 | #include <acpi/acpi_drivers.h> |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 45 | #include <linux/power_supply.h> |
| 46 | |
Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 47 | #define PREFIX "ACPI: " |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define ACPI_BATTERY_VALUE_UNKNOWN 0xFFFFFFFF |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define ACPI_BATTERY_CLASS "battery" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define ACPI_BATTERY_DEVICE_NAME "Battery" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define ACPI_BATTERY_NOTIFY_STATUS 0x80 |
| 54 | #define ACPI_BATTERY_NOTIFY_INFO 0x81 |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 55 | #define ACPI_BATTERY_NOTIFY_THRESHOLD 0x82 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #define _COMPONENT ACPI_BATTERY_COMPONENT |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 58 | |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 59 | ACPI_MODULE_NAME("battery"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 61 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 62 | MODULE_AUTHOR("Alexey Starikovskiy <astarikovskiy@suse.de>"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 63 | MODULE_DESCRIPTION("ACPI Battery Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | MODULE_LICENSE("GPL"); |
| 65 | |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 66 | static unsigned int cache_time = 1000; |
| 67 | module_param(cache_time, uint, 0644); |
| 68 | MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 69 | |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 70 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 71 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); |
| 72 | extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); |
| 73 | |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 74 | enum acpi_battery_files { |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 75 | info_tag = 0, |
| 76 | state_tag, |
| 77 | alarm_tag, |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 78 | ACPI_BATTERY_NUMFILES, |
| 79 | }; |
| 80 | |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 81 | #endif |
| 82 | |
| 83 | static const struct acpi_device_id battery_device_ids[] = { |
| 84 | {"PNP0C0A", 0}, |
| 85 | {"", 0}, |
| 86 | }; |
| 87 | |
| 88 | MODULE_DEVICE_TABLE(acpi, battery_device_ids); |
| 89 | |
Alexey Starikovskiy | 7b3bcc4 | 2009-10-15 14:31:24 +0400 | [diff] [blame] | 90 | enum { |
| 91 | ACPI_BATTERY_ALARM_PRESENT, |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 92 | 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 Starikovskiy | 7b3bcc4 | 2009-10-15 14:31:24 +0400 | [diff] [blame] | 97 | ACPI_BATTERY_QUIRK_SIGNED16_CURRENT, |
Zhang Rui | 557d586 | 2010-10-22 10:02:06 +0800 | [diff] [blame^] | 98 | ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, |
Alexey Starikovskiy | 7b3bcc4 | 2009-10-15 14:31:24 +0400 | [diff] [blame] | 99 | }; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 100 | |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 101 | struct acpi_battery { |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 102 | struct mutex lock; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 103 | struct power_supply bat; |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 104 | struct acpi_device *device; |
| 105 | unsigned long update_time; |
Alexey Starikovskiy | 7faa144 | 2009-03-27 22:23:52 -0400 | [diff] [blame] | 106 | int rate_now; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 107 | int capacity_now; |
| 108 | int voltage_now; |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 109 | int design_capacity; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 110 | int full_charge_capacity; |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 111 | int technology; |
| 112 | int design_voltage; |
| 113 | int design_capacity_warning; |
| 114 | int design_capacity_low; |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 115 | 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 Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 121 | int capacity_granularity_1; |
| 122 | int capacity_granularity_2; |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 123 | int alarm; |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 124 | char model_number[32]; |
| 125 | char serial_number[32]; |
| 126 | char type[32]; |
| 127 | char oem_info[32]; |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 128 | int state; |
| 129 | int power_unit; |
Alexey Starikovskiy | 7b3bcc4 | 2009-10-15 14:31:24 +0400 | [diff] [blame] | 130 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 133 | #define to_acpi_battery(x) container_of(x, struct acpi_battery, bat); |
| 134 | |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 135 | inline int acpi_battery_present(struct acpi_battery *battery) |
| 136 | { |
| 137 | return battery->device->status.battery_present; |
| 138 | } |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 139 | |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 140 | static int acpi_battery_technology(struct acpi_battery *battery) |
| 141 | { |
| 142 | if (!strcasecmp("NiCd", battery->type)) |
| 143 | return POWER_SUPPLY_TECHNOLOGY_NiCd; |
| 144 | if (!strcasecmp("NiMH", battery->type)) |
| 145 | return POWER_SUPPLY_TECHNOLOGY_NiMH; |
| 146 | if (!strcasecmp("LION", battery->type)) |
| 147 | return POWER_SUPPLY_TECHNOLOGY_LION; |
Andrey Borzenkov | ad40e68 | 2007-11-10 20:02:49 +0300 | [diff] [blame] | 148 | if (!strncasecmp("LI-ION", battery->type, 6)) |
Alexey Starikovskiy | 0bde7ee | 2007-10-28 15:33:10 +0300 | [diff] [blame] | 149 | return POWER_SUPPLY_TECHNOLOGY_LION; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 150 | if (!strcasecmp("LiP", battery->type)) |
| 151 | return POWER_SUPPLY_TECHNOLOGY_LIPO; |
| 152 | return POWER_SUPPLY_TECHNOLOGY_UNKNOWN; |
| 153 | } |
| 154 | |
Alexey Starikovskiy | 9104476 | 2007-11-13 12:23:06 +0300 | [diff] [blame] | 155 | static int acpi_battery_get_state(struct acpi_battery *battery); |
Alexey Starikovskiy | b19073a | 2007-10-25 17:10:47 -0400 | [diff] [blame] | 156 | |
Richard Hughes | 56f382a | 2009-01-25 15:05:50 +0000 | [diff] [blame] | 157 | static int acpi_battery_is_charged(struct acpi_battery *battery) |
| 158 | { |
| 159 | /* either charging or discharging */ |
| 160 | if (battery->state != 0) |
| 161 | return 0; |
| 162 | |
| 163 | /* battery not reporting charge */ |
| 164 | if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN || |
| 165 | battery->capacity_now == 0) |
| 166 | return 0; |
| 167 | |
| 168 | /* good batteries update full_charge as the batteries degrade */ |
| 169 | if (battery->full_charge_capacity == battery->capacity_now) |
| 170 | return 1; |
| 171 | |
| 172 | /* fallback to using design values for broken batteries */ |
| 173 | if (battery->design_capacity == battery->capacity_now) |
| 174 | return 1; |
| 175 | |
| 176 | /* we don't do any sort of metric based on percentages */ |
| 177 | return 0; |
| 178 | } |
| 179 | |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 180 | static int acpi_battery_get_property(struct power_supply *psy, |
| 181 | enum power_supply_property psp, |
| 182 | union power_supply_propval *val) |
| 183 | { |
| 184 | struct acpi_battery *battery = to_acpi_battery(psy); |
| 185 | |
Alexey Starikovskiy | 9104476 | 2007-11-13 12:23:06 +0300 | [diff] [blame] | 186 | if (acpi_battery_present(battery)) { |
| 187 | /* run battery update only if it is present */ |
| 188 | acpi_battery_get_state(battery); |
| 189 | } else if (psp != POWER_SUPPLY_PROP_PRESENT) |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 190 | return -ENODEV; |
| 191 | switch (psp) { |
| 192 | case POWER_SUPPLY_PROP_STATUS: |
| 193 | if (battery->state & 0x01) |
| 194 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; |
| 195 | else if (battery->state & 0x02) |
| 196 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
Richard Hughes | 56f382a | 2009-01-25 15:05:50 +0000 | [diff] [blame] | 197 | else if (acpi_battery_is_charged(battery)) |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 198 | val->intval = POWER_SUPPLY_STATUS_FULL; |
Roland Dreier | 4c41d3a | 2007-11-07 15:09:09 -0800 | [diff] [blame] | 199 | else |
| 200 | val->intval = POWER_SUPPLY_STATUS_UNKNOWN; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 201 | break; |
| 202 | case POWER_SUPPLY_PROP_PRESENT: |
| 203 | val->intval = acpi_battery_present(battery); |
| 204 | break; |
| 205 | case POWER_SUPPLY_PROP_TECHNOLOGY: |
| 206 | val->intval = acpi_battery_technology(battery); |
| 207 | break; |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 208 | case POWER_SUPPLY_PROP_CYCLE_COUNT: |
| 209 | val->intval = battery->cycle_count; |
| 210 | break; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 211 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: |
| 212 | val->intval = battery->design_voltage * 1000; |
| 213 | break; |
| 214 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
| 215 | val->intval = battery->voltage_now * 1000; |
| 216 | break; |
| 217 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
Alexey Starikovskiy | 7faa144 | 2009-03-27 22:23:52 -0400 | [diff] [blame] | 218 | case POWER_SUPPLY_PROP_POWER_NOW: |
| 219 | val->intval = battery->rate_now * 1000; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 220 | break; |
| 221 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: |
| 222 | case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: |
| 223 | val->intval = battery->design_capacity * 1000; |
| 224 | break; |
| 225 | case POWER_SUPPLY_PROP_CHARGE_FULL: |
| 226 | case POWER_SUPPLY_PROP_ENERGY_FULL: |
| 227 | val->intval = battery->full_charge_capacity * 1000; |
| 228 | break; |
| 229 | case POWER_SUPPLY_PROP_CHARGE_NOW: |
| 230 | case POWER_SUPPLY_PROP_ENERGY_NOW: |
| 231 | val->intval = battery->capacity_now * 1000; |
| 232 | break; |
| 233 | case POWER_SUPPLY_PROP_MODEL_NAME: |
| 234 | val->strval = battery->model_number; |
| 235 | break; |
| 236 | case POWER_SUPPLY_PROP_MANUFACTURER: |
| 237 | val->strval = battery->oem_info; |
| 238 | break; |
maximilian attems | 7c2670b | 2008-01-22 18:46:50 +0100 | [diff] [blame] | 239 | case POWER_SUPPLY_PROP_SERIAL_NUMBER: |
| 240 | val->strval = battery->serial_number; |
| 241 | break; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 242 | default: |
| 243 | return -EINVAL; |
| 244 | } |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | static enum power_supply_property charge_battery_props[] = { |
| 249 | POWER_SUPPLY_PROP_STATUS, |
| 250 | POWER_SUPPLY_PROP_PRESENT, |
| 251 | POWER_SUPPLY_PROP_TECHNOLOGY, |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 252 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 253 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, |
| 254 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 255 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 256 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
| 257 | POWER_SUPPLY_PROP_CHARGE_FULL, |
| 258 | POWER_SUPPLY_PROP_CHARGE_NOW, |
| 259 | POWER_SUPPLY_PROP_MODEL_NAME, |
| 260 | POWER_SUPPLY_PROP_MANUFACTURER, |
maximilian attems | 7c2670b | 2008-01-22 18:46:50 +0100 | [diff] [blame] | 261 | POWER_SUPPLY_PROP_SERIAL_NUMBER, |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | static enum power_supply_property energy_battery_props[] = { |
| 265 | POWER_SUPPLY_PROP_STATUS, |
| 266 | POWER_SUPPLY_PROP_PRESENT, |
| 267 | POWER_SUPPLY_PROP_TECHNOLOGY, |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 268 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 269 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, |
| 270 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
Alexey Starikovskiy | 7faa144 | 2009-03-27 22:23:52 -0400 | [diff] [blame] | 271 | POWER_SUPPLY_PROP_POWER_NOW, |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 272 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, |
| 273 | POWER_SUPPLY_PROP_ENERGY_FULL, |
| 274 | POWER_SUPPLY_PROP_ENERGY_NOW, |
| 275 | POWER_SUPPLY_PROP_MODEL_NAME, |
| 276 | POWER_SUPPLY_PROP_MANUFACTURER, |
maximilian attems | 7c2670b | 2008-01-22 18:46:50 +0100 | [diff] [blame] | 277 | POWER_SUPPLY_PROP_SERIAL_NUMBER, |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 278 | }; |
| 279 | |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 280 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 281 | inline char *acpi_battery_units(struct acpi_battery *battery) |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 282 | { |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 283 | return (battery->power_unit)?"mA":"mW"; |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 284 | } |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 285 | #endif |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | /* -------------------------------------------------------------------------- |
| 288 | Battery Management |
| 289 | -------------------------------------------------------------------------- */ |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 290 | struct acpi_offsets { |
| 291 | size_t offset; /* offset inside struct acpi_sbs_battery */ |
| 292 | u8 mode; /* int or string? */ |
| 293 | }; |
| 294 | |
| 295 | static struct acpi_offsets state_offsets[] = { |
| 296 | {offsetof(struct acpi_battery, state), 0}, |
Alexey Starikovskiy | 7faa144 | 2009-03-27 22:23:52 -0400 | [diff] [blame] | 297 | {offsetof(struct acpi_battery, rate_now), 0}, |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 298 | {offsetof(struct acpi_battery, capacity_now), 0}, |
| 299 | {offsetof(struct acpi_battery, voltage_now), 0}, |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | static struct acpi_offsets info_offsets[] = { |
| 303 | {offsetof(struct acpi_battery, power_unit), 0}, |
| 304 | {offsetof(struct acpi_battery, design_capacity), 0}, |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 305 | {offsetof(struct acpi_battery, full_charge_capacity), 0}, |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 306 | {offsetof(struct acpi_battery, technology), 0}, |
| 307 | {offsetof(struct acpi_battery, design_voltage), 0}, |
| 308 | {offsetof(struct acpi_battery, design_capacity_warning), 0}, |
| 309 | {offsetof(struct acpi_battery, design_capacity_low), 0}, |
| 310 | {offsetof(struct acpi_battery, capacity_granularity_1), 0}, |
| 311 | {offsetof(struct acpi_battery, capacity_granularity_2), 0}, |
| 312 | {offsetof(struct acpi_battery, model_number), 1}, |
| 313 | {offsetof(struct acpi_battery, serial_number), 1}, |
| 314 | {offsetof(struct acpi_battery, type), 1}, |
| 315 | {offsetof(struct acpi_battery, oem_info), 1}, |
| 316 | }; |
| 317 | |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 318 | static struct acpi_offsets extended_info_offsets[] = { |
| 319 | {offsetof(struct acpi_battery, power_unit), 0}, |
| 320 | {offsetof(struct acpi_battery, design_capacity), 0}, |
| 321 | {offsetof(struct acpi_battery, full_charge_capacity), 0}, |
| 322 | {offsetof(struct acpi_battery, technology), 0}, |
| 323 | {offsetof(struct acpi_battery, design_voltage), 0}, |
| 324 | {offsetof(struct acpi_battery, design_capacity_warning), 0}, |
| 325 | {offsetof(struct acpi_battery, design_capacity_low), 0}, |
| 326 | {offsetof(struct acpi_battery, cycle_count), 0}, |
| 327 | {offsetof(struct acpi_battery, measurement_accuracy), 0}, |
| 328 | {offsetof(struct acpi_battery, max_sampling_time), 0}, |
| 329 | {offsetof(struct acpi_battery, min_sampling_time), 0}, |
| 330 | {offsetof(struct acpi_battery, max_averaging_interval), 0}, |
| 331 | {offsetof(struct acpi_battery, min_averaging_interval), 0}, |
| 332 | {offsetof(struct acpi_battery, capacity_granularity_1), 0}, |
| 333 | {offsetof(struct acpi_battery, capacity_granularity_2), 0}, |
| 334 | {offsetof(struct acpi_battery, model_number), 1}, |
| 335 | {offsetof(struct acpi_battery, serial_number), 1}, |
| 336 | {offsetof(struct acpi_battery, type), 1}, |
| 337 | {offsetof(struct acpi_battery, oem_info), 1}, |
| 338 | }; |
| 339 | |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 340 | static int extract_package(struct acpi_battery *battery, |
| 341 | union acpi_object *package, |
| 342 | struct acpi_offsets *offsets, int num) |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 343 | { |
Alexey Starikovskiy | 106449e | 2007-10-29 23:29:40 +0300 | [diff] [blame] | 344 | int i; |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 345 | union acpi_object *element; |
| 346 | if (package->type != ACPI_TYPE_PACKAGE) |
| 347 | return -EFAULT; |
| 348 | for (i = 0; i < num; ++i) { |
| 349 | if (package->package.count <= i) |
| 350 | return -EFAULT; |
| 351 | element = &package->package.elements[i]; |
| 352 | if (offsets[i].mode) { |
Alexey Starikovskiy | 106449e | 2007-10-29 23:29:40 +0300 | [diff] [blame] | 353 | u8 *ptr = (u8 *)battery + offsets[i].offset; |
| 354 | if (element->type == ACPI_TYPE_STRING || |
| 355 | element->type == ACPI_TYPE_BUFFER) |
| 356 | strncpy(ptr, element->string.pointer, 32); |
| 357 | else if (element->type == ACPI_TYPE_INTEGER) { |
| 358 | strncpy(ptr, (u8 *)&element->integer.value, |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 359 | sizeof(u64)); |
| 360 | ptr[sizeof(u64)] = 0; |
Alexey Starikovskiy | b8a1bdb | 2008-03-17 22:37:42 -0400 | [diff] [blame] | 361 | } else |
| 362 | *ptr = 0; /* don't have value */ |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 363 | } else { |
Alexey Starikovskiy | b8a1bdb | 2008-03-17 22:37:42 -0400 | [diff] [blame] | 364 | int *x = (int *)((u8 *)battery + offsets[i].offset); |
| 365 | *x = (element->type == ACPI_TYPE_INTEGER) ? |
| 366 | element->integer.value : -1; |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 367 | } |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 368 | } |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static int acpi_battery_get_status(struct acpi_battery *battery) |
| 373 | { |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 374 | if (acpi_bus_get_status(battery->device)) { |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 375 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Evaluating _STA")); |
| 376 | return -ENODEV; |
| 377 | } |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 378 | return 0; |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | static int acpi_battery_get_info(struct acpi_battery *battery) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 383 | int result = -EFAULT; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 384 | acpi_status status = 0; |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 385 | char *name = test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags)? |
| 386 | "_BIX" : "_BIF"; |
| 387 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 388 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 390 | if (!acpi_battery_present(battery)) |
| 391 | return 0; |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 392 | mutex_lock(&battery->lock); |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 393 | status = acpi_evaluate_object(battery->device->handle, name, |
| 394 | NULL, &buffer); |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 395 | mutex_unlock(&battery->lock); |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | if (ACPI_FAILURE(status)) { |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 398 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating %s", name)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 399 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 401 | if (test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags)) |
| 402 | result = extract_package(battery, buffer.pointer, |
| 403 | extended_info_offsets, |
| 404 | ARRAY_SIZE(extended_info_offsets)); |
| 405 | else |
| 406 | result = extract_package(battery, buffer.pointer, |
| 407 | info_offsets, ARRAY_SIZE(info_offsets)); |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 408 | kfree(buffer.pointer); |
Zhang Rui | 557d586 | 2010-10-22 10:02:06 +0800 | [diff] [blame^] | 409 | if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags)) |
| 410 | battery->full_charge_capacity = battery->design_capacity; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 411 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 414 | static int acpi_battery_get_state(struct acpi_battery *battery) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | int result = 0; |
| 417 | acpi_status status = 0; |
| 418 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 420 | if (!acpi_battery_present(battery)) |
| 421 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 423 | if (battery->update_time && |
| 424 | time_before(jiffies, battery->update_time + |
| 425 | msecs_to_jiffies(cache_time))) |
| 426 | return 0; |
| 427 | |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 428 | mutex_lock(&battery->lock); |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 429 | status = acpi_evaluate_object(battery->device->handle, "_BST", |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 430 | NULL, &buffer); |
| 431 | mutex_unlock(&battery->lock); |
Len Brown | 5b31d89 | 2007-08-15 00:19:26 -0400 | [diff] [blame] | 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 434 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 435 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | } |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 437 | |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 438 | result = extract_package(battery, buffer.pointer, |
| 439 | state_offsets, ARRAY_SIZE(state_offsets)); |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 440 | battery->update_time = jiffies; |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 441 | kfree(buffer.pointer); |
Hector Martin | bc76f90 | 2009-08-06 15:57:48 -0700 | [diff] [blame] | 442 | |
Alexey Starikovskiy | 7b3bcc4 | 2009-10-15 14:31:24 +0400 | [diff] [blame] | 443 | if (test_bit(ACPI_BATTERY_QUIRK_SIGNED16_CURRENT, &battery->flags) && |
Hector Martin | bc76f90 | 2009-08-06 15:57:48 -0700 | [diff] [blame] | 444 | battery->rate_now != -1) |
| 445 | battery->rate_now = abs((s16)battery->rate_now); |
| 446 | |
Zhang Rui | 557d586 | 2010-10-22 10:02:06 +0800 | [diff] [blame^] | 447 | if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags) |
| 448 | && battery->capacity_now >= 0 && battery->capacity_now <= 100) |
| 449 | battery->capacity_now = (battery->capacity_now * |
| 450 | battery->full_charge_capacity) / 100; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 451 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 454 | static int acpi_battery_set_alarm(struct acpi_battery *battery) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | acpi_status status = 0; |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 457 | union acpi_object arg0 = { .type = ACPI_TYPE_INTEGER }; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 458 | struct acpi_object_list arg_list = { 1, &arg0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 460 | if (!acpi_battery_present(battery) || |
Alexey Starikovskiy | 7b3bcc4 | 2009-10-15 14:31:24 +0400 | [diff] [blame] | 461 | !test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags)) |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 462 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 464 | arg0.integer.value = battery->alarm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 466 | mutex_lock(&battery->lock); |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 467 | status = acpi_evaluate_object(battery->device->handle, "_BTP", |
| 468 | &arg_list, NULL); |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 469 | mutex_unlock(&battery->lock); |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 472 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 474 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Alarm set to %d\n", battery->alarm)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 475 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 478 | static int acpi_battery_init_alarm(struct acpi_battery *battery) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 480 | acpi_status status = AE_OK; |
| 481 | acpi_handle handle = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 483 | /* See if alarms are supported, and if so, set default */ |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 484 | status = acpi_get_handle(battery->device->handle, "_BTP", &handle); |
| 485 | if (ACPI_FAILURE(status)) { |
Alexey Starikovskiy | 7b3bcc4 | 2009-10-15 14:31:24 +0400 | [diff] [blame] | 486 | clear_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags); |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 487 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
Alexey Starikovskiy | 7b3bcc4 | 2009-10-15 14:31:24 +0400 | [diff] [blame] | 489 | set_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags); |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 490 | if (!battery->alarm) |
| 491 | battery->alarm = battery->design_capacity_warning; |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 492 | return acpi_battery_set_alarm(battery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 495 | static ssize_t acpi_battery_alarm_show(struct device *dev, |
| 496 | struct device_attribute *attr, |
| 497 | char *buf) |
| 498 | { |
| 499 | struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); |
| 500 | return sprintf(buf, "%d\n", battery->alarm * 1000); |
| 501 | } |
| 502 | |
| 503 | static ssize_t acpi_battery_alarm_store(struct device *dev, |
| 504 | struct device_attribute *attr, |
| 505 | const char *buf, size_t count) |
| 506 | { |
| 507 | unsigned long x; |
| 508 | struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); |
| 509 | if (sscanf(buf, "%ld\n", &x) == 1) |
| 510 | battery->alarm = x/1000; |
| 511 | if (acpi_battery_present(battery)) |
| 512 | acpi_battery_set_alarm(battery); |
| 513 | return count; |
| 514 | } |
| 515 | |
| 516 | static struct device_attribute alarm_attr = { |
Parag Warudkar | 01e8ef1 | 2008-10-18 20:28:50 -0700 | [diff] [blame] | 517 | .attr = {.name = "alarm", .mode = 0644}, |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 518 | .show = acpi_battery_alarm_show, |
| 519 | .store = acpi_battery_alarm_store, |
| 520 | }; |
| 521 | |
| 522 | static int sysfs_add_battery(struct acpi_battery *battery) |
| 523 | { |
| 524 | int result; |
| 525 | |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 526 | if (battery->power_unit) { |
| 527 | battery->bat.properties = charge_battery_props; |
| 528 | battery->bat.num_properties = |
| 529 | ARRAY_SIZE(charge_battery_props); |
| 530 | } else { |
| 531 | battery->bat.properties = energy_battery_props; |
| 532 | battery->bat.num_properties = |
| 533 | ARRAY_SIZE(energy_battery_props); |
| 534 | } |
| 535 | |
| 536 | battery->bat.name = acpi_device_bid(battery->device); |
| 537 | battery->bat.type = POWER_SUPPLY_TYPE_BATTERY; |
| 538 | battery->bat.get_property = acpi_battery_get_property; |
| 539 | |
| 540 | result = power_supply_register(&battery->device->dev, &battery->bat); |
| 541 | if (result) |
| 542 | return result; |
| 543 | return device_create_file(battery->bat.dev, &alarm_attr); |
| 544 | } |
| 545 | |
| 546 | static void sysfs_remove_battery(struct acpi_battery *battery) |
| 547 | { |
| 548 | if (!battery->bat.dev) |
| 549 | return; |
| 550 | device_remove_file(battery->bat.dev, &alarm_attr); |
| 551 | power_supply_unregister(&battery->bat); |
Alexey Starikovskiy | 9104476 | 2007-11-13 12:23:06 +0300 | [diff] [blame] | 552 | battery->bat.dev = NULL; |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 553 | } |
| 554 | |
Hector Martin | bc76f90 | 2009-08-06 15:57:48 -0700 | [diff] [blame] | 555 | static void acpi_battery_quirks(struct acpi_battery *battery) |
| 556 | { |
Hector Martin | bc76f90 | 2009-08-06 15:57:48 -0700 | [diff] [blame] | 557 | if (dmi_name_in_vendors("Acer") && battery->power_unit) { |
Alexey Starikovskiy | 7b3bcc4 | 2009-10-15 14:31:24 +0400 | [diff] [blame] | 558 | set_bit(ACPI_BATTERY_QUIRK_SIGNED16_CURRENT, &battery->flags); |
Hector Martin | bc76f90 | 2009-08-06 15:57:48 -0700 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
Zhang Rui | 557d586 | 2010-10-22 10:02:06 +0800 | [diff] [blame^] | 562 | /* |
| 563 | * According to the ACPI spec, some kinds of primary batteries can |
| 564 | * report percentage battery remaining capacity directly to OS. |
| 565 | * In this case, it reports the Last Full Charged Capacity == 100 |
| 566 | * and BatteryPresentRate == 0xFFFFFFFF. |
| 567 | * |
| 568 | * Now we found some battery reports percentage remaining capacity |
| 569 | * even if it's rechargeable. |
| 570 | * https://bugzilla.kernel.org/show_bug.cgi?id=15979 |
| 571 | * |
| 572 | * Handle this correctly so that they won't break userspace. |
| 573 | */ |
| 574 | static void acpi_battery_quirks2(struct acpi_battery *battery) |
| 575 | { |
| 576 | if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags)) |
| 577 | return ; |
| 578 | |
| 579 | if (battery->full_charge_capacity == 100 && |
| 580 | battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN && |
| 581 | battery->capacity_now >=0 && battery->capacity_now <= 100) { |
| 582 | set_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags); |
| 583 | battery->full_charge_capacity = battery->design_capacity; |
| 584 | battery->capacity_now = (battery->capacity_now * |
| 585 | battery->full_charge_capacity) / 100; |
| 586 | } |
| 587 | } |
| 588 | |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 589 | static int acpi_battery_update(struct acpi_battery *battery) |
Vladimir Lebedev | 4bd35cd | 2007-02-10 01:43:48 -0500 | [diff] [blame] | 590 | { |
Alexey Starikovskiy | 50b1785 | 2008-12-23 02:44:54 +0300 | [diff] [blame] | 591 | int result, old_present = acpi_battery_present(battery); |
Alexey Starikovskiy | 97749cd | 2008-01-01 14:27:24 -0500 | [diff] [blame] | 592 | result = acpi_battery_get_status(battery); |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 593 | if (result) |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 594 | return result; |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 595 | if (!acpi_battery_present(battery)) { |
| 596 | sysfs_remove_battery(battery); |
Alexey Starikovskiy | 97749cd | 2008-01-01 14:27:24 -0500 | [diff] [blame] | 597 | battery->update_time = 0; |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 598 | return 0; |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 599 | } |
Alexey Starikovskiy | 50b1785 | 2008-12-23 02:44:54 +0300 | [diff] [blame] | 600 | if (!battery->update_time || |
| 601 | old_present != acpi_battery_present(battery)) { |
Alexey Starikovskiy | 97749cd | 2008-01-01 14:27:24 -0500 | [diff] [blame] | 602 | result = acpi_battery_get_info(battery); |
| 603 | if (result) |
| 604 | return result; |
Hector Martin | bc76f90 | 2009-08-06 15:57:48 -0700 | [diff] [blame] | 605 | acpi_battery_quirks(battery); |
Alexey Starikovskiy | 97749cd | 2008-01-01 14:27:24 -0500 | [diff] [blame] | 606 | acpi_battery_init_alarm(battery); |
| 607 | } |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 608 | if (!battery->bat.dev) |
| 609 | sysfs_add_battery(battery); |
Zhang Rui | 557d586 | 2010-10-22 10:02:06 +0800 | [diff] [blame^] | 610 | result = acpi_battery_get_state(battery); |
| 611 | acpi_battery_quirks2(battery); |
| 612 | return result; |
Vladimir Lebedev | 4bd35cd | 2007-02-10 01:43:48 -0500 | [diff] [blame] | 613 | } |
| 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | /* -------------------------------------------------------------------------- |
| 616 | FS Interface (/proc) |
| 617 | -------------------------------------------------------------------------- */ |
| 618 | |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 619 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 620 | static struct proc_dir_entry *acpi_battery_dir; |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 621 | |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 622 | static int acpi_battery_print_info(struct seq_file *seq, int result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 624 | struct acpi_battery *battery = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 626 | if (result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | goto end; |
| 628 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 629 | seq_printf(seq, "present: %s\n", |
| 630 | acpi_battery_present(battery)?"yes":"no"); |
| 631 | if (!acpi_battery_present(battery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | goto end; |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 633 | if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | seq_printf(seq, "design capacity: unknown\n"); |
| 635 | else |
| 636 | seq_printf(seq, "design capacity: %d %sh\n", |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 637 | battery->design_capacity, |
| 638 | acpi_battery_units(battery)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 640 | if (battery->full_charge_capacity == ACPI_BATTERY_VALUE_UNKNOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | seq_printf(seq, "last full capacity: unknown\n"); |
| 642 | else |
| 643 | seq_printf(seq, "last full capacity: %d %sh\n", |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 644 | battery->full_charge_capacity, |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 645 | acpi_battery_units(battery)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 647 | seq_printf(seq, "battery technology: %srechargeable\n", |
| 648 | (!battery->technology)?"non-":""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 650 | if (battery->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | seq_printf(seq, "design voltage: unknown\n"); |
| 652 | else |
| 653 | seq_printf(seq, "design voltage: %d mV\n", |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 654 | battery->design_voltage); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 655 | seq_printf(seq, "design capacity warning: %d %sh\n", |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 656 | battery->design_capacity_warning, |
| 657 | acpi_battery_units(battery)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 658 | seq_printf(seq, "design capacity low: %d %sh\n", |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 659 | battery->design_capacity_low, |
| 660 | acpi_battery_units(battery)); |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 661 | seq_printf(seq, "cycle count: %i\n", battery->cycle_count); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 662 | seq_printf(seq, "capacity granularity 1: %d %sh\n", |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 663 | battery->capacity_granularity_1, |
| 664 | acpi_battery_units(battery)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 665 | seq_printf(seq, "capacity granularity 2: %d %sh\n", |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 666 | battery->capacity_granularity_2, |
| 667 | acpi_battery_units(battery)); |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 668 | seq_printf(seq, "model number: %s\n", battery->model_number); |
| 669 | seq_printf(seq, "serial number: %s\n", battery->serial_number); |
| 670 | seq_printf(seq, "battery type: %s\n", battery->type); |
| 671 | seq_printf(seq, "OEM info: %s\n", battery->oem_info); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 672 | end: |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 673 | if (result) |
| 674 | seq_printf(seq, "ERROR: Unable to read battery info\n"); |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 675 | return result; |
| 676 | } |
| 677 | |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 678 | static int acpi_battery_print_state(struct seq_file *seq, int result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 680 | struct acpi_battery *battery = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 682 | if (result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | goto end; |
| 684 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 685 | seq_printf(seq, "present: %s\n", |
| 686 | acpi_battery_present(battery)?"yes":"no"); |
| 687 | if (!acpi_battery_present(battery)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 690 | seq_printf(seq, "capacity state: %s\n", |
| 691 | (battery->state & 0x04)?"critical":"ok"); |
| 692 | if ((battery->state & 0x01) && (battery->state & 0x02)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 693 | seq_printf(seq, |
| 694 | "charging state: charging/discharging\n"); |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 695 | else if (battery->state & 0x01) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | seq_printf(seq, "charging state: discharging\n"); |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 697 | else if (battery->state & 0x02) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | seq_printf(seq, "charging state: charging\n"); |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 699 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | seq_printf(seq, "charging state: charged\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
Alexey Starikovskiy | 7faa144 | 2009-03-27 22:23:52 -0400 | [diff] [blame] | 702 | if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | seq_printf(seq, "present rate: unknown\n"); |
| 704 | else |
| 705 | seq_printf(seq, "present rate: %d %s\n", |
Alexey Starikovskiy | 7faa144 | 2009-03-27 22:23:52 -0400 | [diff] [blame] | 706 | battery->rate_now, acpi_battery_units(battery)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 708 | if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | seq_printf(seq, "remaining capacity: unknown\n"); |
| 710 | else |
| 711 | seq_printf(seq, "remaining capacity: %d %sh\n", |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 712 | battery->capacity_now, acpi_battery_units(battery)); |
| 713 | if (battery->voltage_now == ACPI_BATTERY_VALUE_UNKNOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | seq_printf(seq, "present voltage: unknown\n"); |
| 715 | else |
| 716 | seq_printf(seq, "present voltage: %d mV\n", |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 717 | battery->voltage_now); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 718 | end: |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 719 | if (result) |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 720 | seq_printf(seq, "ERROR: Unable to read battery state\n"); |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 721 | |
| 722 | return result; |
| 723 | } |
| 724 | |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 725 | static int acpi_battery_print_alarm(struct seq_file *seq, int result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 727 | struct acpi_battery *battery = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 729 | if (result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | goto end; |
| 731 | |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 732 | if (!acpi_battery_present(battery)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | seq_printf(seq, "present: no\n"); |
| 734 | goto end; |
| 735 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | seq_printf(seq, "alarm: "); |
| 737 | if (!battery->alarm) |
| 738 | seq_printf(seq, "unsupported\n"); |
| 739 | else |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 740 | seq_printf(seq, "%u %sh\n", battery->alarm, |
| 741 | acpi_battery_units(battery)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 742 | end: |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 743 | if (result) |
| 744 | seq_printf(seq, "ERROR: Unable to read battery alarm\n"); |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 745 | return result; |
| 746 | } |
| 747 | |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 748 | static ssize_t acpi_battery_write_alarm(struct file *file, |
| 749 | const char __user * buffer, |
| 750 | size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 752 | int result = 0; |
| 753 | char alarm_string[12] = { '\0' }; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 754 | struct seq_file *m = file->private_data; |
| 755 | struct acpi_battery *battery = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | if (!battery || (count > sizeof(alarm_string) - 1)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 758 | return -EINVAL; |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 759 | if (!acpi_battery_present(battery)) { |
| 760 | result = -ENODEV; |
| 761 | goto end; |
| 762 | } |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 763 | if (copy_from_user(alarm_string, buffer, count)) { |
| 764 | result = -EFAULT; |
| 765 | goto end; |
| 766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | alarm_string[count] = '\0'; |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 768 | battery->alarm = simple_strtol(alarm_string, NULL, 0); |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 769 | result = acpi_battery_set_alarm(battery); |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 770 | end: |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 771 | if (!result) |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 772 | return count; |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 773 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 776 | typedef int(*print_func)(struct seq_file *seq, int result); |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 777 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 778 | static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = { |
| 779 | acpi_battery_print_info, |
| 780 | acpi_battery_print_state, |
| 781 | acpi_battery_print_alarm, |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 782 | }; |
| 783 | |
| 784 | static int acpi_battery_read(int fid, struct seq_file *seq) |
| 785 | { |
| 786 | struct acpi_battery *battery = seq->private; |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 787 | int result = acpi_battery_update(battery); |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 788 | return acpi_print_funcs[fid](seq, result); |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 789 | } |
| 790 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 791 | #define DECLARE_FILE_FUNCTIONS(_name) \ |
| 792 | static int acpi_battery_read_##_name(struct seq_file *seq, void *offset) \ |
| 793 | { \ |
| 794 | return acpi_battery_read(_name##_tag, seq); \ |
| 795 | } \ |
| 796 | static int acpi_battery_##_name##_open_fs(struct inode *inode, struct file *file) \ |
| 797 | { \ |
| 798 | return single_open(file, acpi_battery_read_##_name, PDE(inode)->data); \ |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 799 | } |
| 800 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 801 | DECLARE_FILE_FUNCTIONS(info); |
| 802 | DECLARE_FILE_FUNCTIONS(state); |
| 803 | DECLARE_FILE_FUNCTIONS(alarm); |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 804 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 805 | #undef DECLARE_FILE_FUNCTIONS |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 806 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 807 | #define FILE_DESCRIPTION_RO(_name) \ |
| 808 | { \ |
| 809 | .name = __stringify(_name), \ |
| 810 | .mode = S_IRUGO, \ |
| 811 | .ops = { \ |
| 812 | .open = acpi_battery_##_name##_open_fs, \ |
| 813 | .read = seq_read, \ |
| 814 | .llseek = seq_lseek, \ |
| 815 | .release = single_release, \ |
| 816 | .owner = THIS_MODULE, \ |
| 817 | }, \ |
| 818 | } |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 819 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 820 | #define FILE_DESCRIPTION_RW(_name) \ |
| 821 | { \ |
| 822 | .name = __stringify(_name), \ |
| 823 | .mode = S_IFREG | S_IRUGO | S_IWUSR, \ |
| 824 | .ops = { \ |
| 825 | .open = acpi_battery_##_name##_open_fs, \ |
| 826 | .read = seq_read, \ |
| 827 | .llseek = seq_lseek, \ |
| 828 | .write = acpi_battery_write_##_name, \ |
| 829 | .release = single_release, \ |
| 830 | .owner = THIS_MODULE, \ |
| 831 | }, \ |
| 832 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 834 | static struct battery_file { |
| 835 | struct file_operations ops; |
| 836 | mode_t mode; |
Jan Engelhardt | 070d8eb | 2009-01-12 00:07:55 +0100 | [diff] [blame] | 837 | const char *name; |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 838 | } acpi_battery_file[] = { |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 839 | FILE_DESCRIPTION_RO(info), |
| 840 | FILE_DESCRIPTION_RO(state), |
| 841 | FILE_DESCRIPTION_RW(alarm), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | }; |
| 843 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 844 | #undef FILE_DESCRIPTION_RO |
| 845 | #undef FILE_DESCRIPTION_RW |
| 846 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 847 | static int acpi_battery_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 849 | struct proc_dir_entry *entry = NULL; |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 850 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | if (!acpi_device_dir(device)) { |
| 853 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 854 | acpi_battery_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | if (!acpi_device_dir(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 856 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 859 | for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 860 | entry = proc_create_data(acpi_battery_file[i].name, |
| 861 | acpi_battery_file[i].mode, |
| 862 | acpi_device_dir(device), |
| 863 | &acpi_battery_file[i].ops, |
| 864 | acpi_driver_data(device)); |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 865 | if (!entry) |
| 866 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 868 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 871 | static void acpi_battery_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | { |
Alexey Starikovskiy | 78490d8 | 2007-05-11 13:18:55 -0400 | [diff] [blame] | 873 | int i; |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 874 | if (!acpi_device_dir(device)) |
| 875 | return; |
| 876 | for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) |
| 877 | remove_proc_entry(acpi_battery_file[i].name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 880 | remove_proc_entry(acpi_device_bid(device), acpi_battery_dir); |
| 881 | acpi_device_dir(device) = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 884 | #endif |
Alexey Starikovskiy | 3e58ea0 | 2007-09-26 19:43:11 +0400 | [diff] [blame] | 885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | /* -------------------------------------------------------------------------- |
| 887 | Driver Interface |
| 888 | -------------------------------------------------------------------------- */ |
| 889 | |
Bjorn Helgaas | d940669 | 2009-04-30 09:35:47 -0600 | [diff] [blame] | 890 | static void acpi_battery_notify(struct acpi_device *device, u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | { |
Bjorn Helgaas | d940669 | 2009-04-30 09:35:47 -0600 | [diff] [blame] | 892 | struct acpi_battery *battery = acpi_driver_data(device); |
Zhang Rui | 153e500 | 2010-07-07 09:11:57 +0800 | [diff] [blame] | 893 | struct device *old; |
Bjorn Helgaas | d940669 | 2009-04-30 09:35:47 -0600 | [diff] [blame] | 894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | if (!battery) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 896 | return; |
Zhang Rui | 153e500 | 2010-07-07 09:11:57 +0800 | [diff] [blame] | 897 | old = battery->bat.dev; |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 898 | 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 Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 902 | dev_name(&device->dev), event, |
Vladimir Lebedev | 9ea7d57 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 903 | acpi_battery_present(battery)); |
Justin P. Mattock | 2345baf | 2009-12-13 14:42:36 -0800 | [diff] [blame] | 904 | /* acpi_battery_update could remove power_supply object */ |
Zhang Rui | 153e500 | 2010-07-07 09:11:57 +0800 | [diff] [blame] | 905 | if (old && battery->bat.dev) |
Alan Jenkins | f79e1ce | 2009-06-30 14:36:16 +0000 | [diff] [blame] | 906 | power_supply_changed(&battery->bat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 909 | static int acpi_battery_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 911 | int result = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 912 | struct acpi_battery *battery = NULL; |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 913 | acpi_handle handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 915 | return -EINVAL; |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 916 | battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | if (!battery) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 918 | return -ENOMEM; |
Patrick Mochel | 145def8 | 2006-05-19 16:54:39 -0400 | [diff] [blame] | 919 | battery->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); |
| 921 | strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 922 | device->driver_data = battery; |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 923 | mutex_init(&battery->lock); |
Alexey Starikovskiy | c67fcd6 | 2009-10-15 14:31:44 +0400 | [diff] [blame] | 924 | if (ACPI_SUCCESS(acpi_get_handle(battery->device->handle, |
| 925 | "_BIX", &handle))) |
| 926 | set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags); |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 927 | acpi_battery_update(battery); |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 928 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | result = acpi_battery_add_fs(device); |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 930 | #endif |
Len Brown | 586caae | 2009-06-18 00:38:27 -0400 | [diff] [blame] | 931 | if (!result) { |
| 932 | printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n", |
| 933 | ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device), |
| 934 | device->status.battery_present ? "present" : "absent"); |
| 935 | } else { |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 936 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | acpi_battery_remove_fs(device); |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 938 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | kfree(battery); |
| 940 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 941 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 944 | static int acpi_battery_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 946 | struct acpi_battery *battery = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 949 | return -EINVAL; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 950 | battery = acpi_driver_data(device); |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 951 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | acpi_battery_remove_fs(device); |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 953 | #endif |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 954 | sysfs_remove_battery(battery); |
Alexey Starikovskiy | 038fdea | 2007-09-26 19:42:46 +0400 | [diff] [blame] | 955 | mutex_destroy(&battery->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | kfree(battery); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 957 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Jiri Kosina | 34c4415 | 2006-10-10 14:20:41 -0700 | [diff] [blame] | 960 | /* this is needed to learn about changes made in suspended state */ |
Patrick Mochel | 5d9464a | 2006-12-07 20:56:27 +0800 | [diff] [blame] | 961 | static int acpi_battery_resume(struct acpi_device *device) |
Jiri Kosina | 34c4415 | 2006-10-10 14:20:41 -0700 | [diff] [blame] | 962 | { |
| 963 | struct acpi_battery *battery; |
Jiri Kosina | 34c4415 | 2006-10-10 14:20:41 -0700 | [diff] [blame] | 964 | if (!device) |
| 965 | return -EINVAL; |
Alexey Starikovskiy | f1d4661 | 2007-09-26 19:42:52 +0400 | [diff] [blame] | 966 | battery = acpi_driver_data(device); |
| 967 | battery->update_time = 0; |
Andrey Borzenkov | 508df92 | 2007-10-28 12:50:09 +0300 | [diff] [blame] | 968 | acpi_battery_update(battery); |
Vladimir Lebedev | b6ce408 | 2007-02-20 15:48:06 +0300 | [diff] [blame] | 969 | return 0; |
Jiri Kosina | 34c4415 | 2006-10-10 14:20:41 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 972 | static struct acpi_driver acpi_battery_driver = { |
| 973 | .name = "battery", |
| 974 | .class = ACPI_BATTERY_CLASS, |
| 975 | .ids = battery_device_ids, |
Bjorn Helgaas | d940669 | 2009-04-30 09:35:47 -0600 | [diff] [blame] | 976 | .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 977 | .ops = { |
| 978 | .add = acpi_battery_add, |
| 979 | .resume = acpi_battery_resume, |
| 980 | .remove = acpi_battery_remove, |
Bjorn Helgaas | d940669 | 2009-04-30 09:35:47 -0600 | [diff] [blame] | 981 | .notify = acpi_battery_notify, |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 982 | }, |
| 983 | }; |
| 984 | |
Linus Torvalds | b0cbc86 | 2009-04-11 12:45:20 -0700 | [diff] [blame] | 985 | static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | { |
Pavel Machek | 4d8316d | 2006-08-14 22:37:22 -0700 | [diff] [blame] | 987 | if (acpi_disabled) |
Arjan van de Ven | 0f66af5 | 2009-01-10 14:19:05 -0500 | [diff] [blame] | 988 | return; |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 989 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 990 | acpi_battery_dir = acpi_lock_battery_dir(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | if (!acpi_battery_dir) |
Arjan van de Ven | 0f66af5 | 2009-01-10 14:19:05 -0500 | [diff] [blame] | 992 | return; |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 993 | #endif |
Alexey Starikovskiy | aa650bb | 2007-09-26 19:42:58 +0400 | [diff] [blame] | 994 | if (acpi_bus_register_driver(&acpi_battery_driver) < 0) { |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 995 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 996 | acpi_unlock_battery_dir(acpi_battery_dir); |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 997 | #endif |
Arjan van de Ven | 0f66af5 | 2009-01-10 14:19:05 -0500 | [diff] [blame] | 998 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | } |
Arjan van de Ven | 0f66af5 | 2009-01-10 14:19:05 -0500 | [diff] [blame] | 1000 | return; |
| 1001 | } |
| 1002 | |
| 1003 | static int __init acpi_battery_init(void) |
| 1004 | { |
| 1005 | async_schedule(acpi_battery_init_async, NULL); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1006 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1009 | static void __exit acpi_battery_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | acpi_bus_unregister_driver(&acpi_battery_driver); |
Alexey Starikovskiy | fdcedbb | 2007-11-19 16:33:45 +0300 | [diff] [blame] | 1012 | #ifdef CONFIG_ACPI_PROCFS_POWER |
Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 1013 | acpi_unlock_battery_dir(acpi_battery_dir); |
Alexey Starikovskiy | d738096 | 2007-09-26 19:43:04 +0400 | [diff] [blame] | 1014 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | module_init(acpi_battery_init); |
| 1018 | module_exit(acpi_battery_exit); |