blob: 01504c819e8f6692382a2b8138fb72a40bb50780 [file] [log] [blame]
Rich Townsend3f86b832006-07-01 11:36:54 -04001/*
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +04002 * sbs.c - ACPI Smart Battery System Driver ($Revision: 2.0 $)
Rich Townsend3f86b832006-07-01 11:36:54 -04003 *
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +04004 * Copyright (c) 2007 Alexey Starikovskiy <astarikovskiy@suse.de>
5 * Copyright (c) 2005-2007 Vladimir Lebedev <vladimir.p.lebedev@intel.com>
Rich Townsend3f86b832006-07-01 11:36:54 -04006 * Copyright (c) 2005 Rich Townsend <rhdt@bartol.udel.edu>
7 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 */
26
27#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Rich Townsend3f86b832006-07-01 11:36:54 -040029#include <linux/module.h>
30#include <linux/moduleparam.h>
31#include <linux/kernel.h>
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +040032
Rich Townsend3f86b832006-07-01 11:36:54 -040033#include <linux/acpi.h>
Vladimir Lebedev6d157022007-03-19 17:45:50 +030034#include <linux/timer.h>
Vladimir Lebedev72206232007-03-19 17:45:50 +030035#include <linux/jiffies.h>
Rich Townsend3f86b832006-07-01 11:36:54 -040036#include <linux/delay.h>
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +040037#include <linux/power_supply.h>
Matthew Garrett9faf6132014-09-20 13:19:46 +020038#include <linux/dmi.h>
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +040039
Alexey Starikovskiy91087df2007-09-26 19:43:28 +040040#include "sbshc.h"
Alexander Mezinf03be352014-03-12 00:58:46 +070041#include "battery.h"
Alexey Starikovskiy91087df2007-09-26 19:43:28 +040042
Len Browna192a952009-07-28 16:45:54 -040043#define PREFIX "ACPI: "
44
Rich Townsend3f86b832006-07-01 11:36:54 -040045#define ACPI_SBS_CLASS "sbs"
46#define ACPI_AC_CLASS "ac_adapter"
Rich Townsend3f86b832006-07-01 11:36:54 -040047#define ACPI_SBS_DEVICE_NAME "Smart Battery System"
48#define ACPI_SBS_FILE_INFO "info"
49#define ACPI_SBS_FILE_STATE "state"
50#define ACPI_SBS_FILE_ALARM "alarm"
51#define ACPI_BATTERY_DIR_NAME "BAT%i"
52#define ACPI_AC_DIR_NAME "AC0"
Rich Townsend3f86b832006-07-01 11:36:54 -040053
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040054#define ACPI_SBS_NOTIFY_STATUS 0x80
55#define ACPI_SBS_NOTIFY_INFO 0x81
Rich Townsend3f86b832006-07-01 11:36:54 -040056
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040057MODULE_AUTHOR("Alexey Starikovskiy <astarikovskiy@suse.de>");
Rich Townsend3f86b832006-07-01 11:36:54 -040058MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
59MODULE_LICENSE("GPL");
60
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040061static unsigned int cache_time = 1000;
62module_param(cache_time, uint, 0644);
63MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
Vladimir Lebedev6d157022007-03-19 17:45:50 +030064
Matthew Garrett9faf6132014-09-20 13:19:46 +020065static bool sbs_manager_broken;
66
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040067#define MAX_SBS_BAT 4
Vladimir Lebedev6d157022007-03-19 17:45:50 +030068#define ACPI_SBS_BLOCK_MAX 32
69
Thomas Renninger1ba90e32007-07-23 14:44:41 +020070static const struct acpi_device_id sbs_device_ids[] = {
Alexey Starikovskiy91087df2007-09-26 19:43:28 +040071 {"ACPI0002", 0},
Thomas Renninger1ba90e32007-07-23 14:44:41 +020072 {"", 0},
73};
74MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
75
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040076struct acpi_battery {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +010077 struct power_supply *bat;
78 struct power_supply_desc bat_desc;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040079 struct acpi_sbs *sbs;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040080 unsigned long update_time;
81 char name[8];
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040082 char manufacturer_name[ACPI_SBS_BLOCK_MAX];
83 char device_name[ACPI_SBS_BLOCK_MAX];
84 char device_chemistry[ACPI_SBS_BLOCK_MAX];
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +040085 u16 alarm_capacity;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040086 u16 full_charge_capacity;
87 u16 design_capacity;
88 u16 design_voltage;
89 u16 serial_number;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040090 u16 cycle_count;
91 u16 temp_now;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040092 u16 voltage_now;
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -040093 s16 rate_now;
94 s16 rate_avg;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040095 u16 capacity_now;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040096 u16 state_of_charge;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040097 u16 state;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040098 u16 mode;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040099 u16 spec;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +0400100 u8 id;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +0400101 u8 present:1;
Jeff Garzik037cbc62007-11-18 00:32:31 +0300102 u8 have_sysfs_alarm:1;
Rich Townsend3f86b832006-07-01 11:36:54 -0400103};
104
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100105#define to_acpi_battery(x) power_supply_get_drvdata(x)
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400106
Rich Townsend3f86b832006-07-01 11:36:54 -0400107struct acpi_sbs {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100108 struct power_supply *charger;
Rich Townsend3f86b832006-07-01 11:36:54 -0400109 struct acpi_device *device;
Alexey Starikovskiy91087df2007-09-26 19:43:28 +0400110 struct acpi_smb_hc *hc;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400111 struct mutex lock;
Rich Townsend3f86b832006-07-01 11:36:54 -0400112 struct acpi_battery battery[MAX_SBS_BAT];
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400113 u8 batteries_supported:4;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +0400114 u8 manager_present:1;
115 u8 charger_present:1;
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200116 u8 charger_exists:1;
Rich Townsend3f86b832006-07-01 11:36:54 -0400117};
118
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100119#define to_acpi_sbs(x) power_supply_get_drvdata(x)
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400120
Rafael J. Wysocki51fac832013-01-24 00:24:48 +0100121static int acpi_sbs_remove(struct acpi_device *device);
Lan Tianyu1dd5c712011-07-01 16:03:15 +0800122static int acpi_battery_get_state(struct acpi_battery *battery);
123
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400124static inline int battery_scale(int log)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300125{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400126 int scale = 1;
127 while (log--)
128 scale *= 10;
129 return scale;
Vladimir Lebedev72206232007-03-19 17:45:50 +0300130}
131
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400132static inline int acpi_battery_vscale(struct acpi_battery *battery)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300133{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400134 return battery_scale((battery->spec & 0x0f00) >> 8);
Vladimir Lebedev72206232007-03-19 17:45:50 +0300135}
136
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400137static inline int acpi_battery_ipscale(struct acpi_battery *battery)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300138{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400139 return battery_scale((battery->spec & 0xf000) >> 12);
140}
141
142static inline int acpi_battery_mode(struct acpi_battery *battery)
143{
144 return (battery->mode & 0x8000);
145}
146
147static inline int acpi_battery_scale(struct acpi_battery *battery)
148{
149 return (acpi_battery_mode(battery) ? 10 : 1) *
150 acpi_battery_ipscale(battery);
Vladimir Lebedev72206232007-03-19 17:45:50 +0300151}
152
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400153static int sbs_get_ac_property(struct power_supply *psy,
154 enum power_supply_property psp,
155 union power_supply_propval *val)
156{
157 struct acpi_sbs *sbs = to_acpi_sbs(psy);
158 switch (psp) {
159 case POWER_SUPPLY_PROP_ONLINE:
160 val->intval = sbs->charger_present;
161 break;
162 default:
163 return -EINVAL;
164 }
165 return 0;
166}
167
168static int acpi_battery_technology(struct acpi_battery *battery)
169{
170 if (!strcasecmp("NiCd", battery->device_chemistry))
171 return POWER_SUPPLY_TECHNOLOGY_NiCd;
172 if (!strcasecmp("NiMH", battery->device_chemistry))
173 return POWER_SUPPLY_TECHNOLOGY_NiMH;
174 if (!strcasecmp("LION", battery->device_chemistry))
175 return POWER_SUPPLY_TECHNOLOGY_LION;
176 if (!strcasecmp("LiP", battery->device_chemistry))
177 return POWER_SUPPLY_TECHNOLOGY_LIPO;
178 return POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
179}
180
181static int acpi_sbs_battery_get_property(struct power_supply *psy,
182 enum power_supply_property psp,
183 union power_supply_propval *val)
184{
185 struct acpi_battery *battery = to_acpi_battery(psy);
186
187 if ((!battery->present) && psp != POWER_SUPPLY_PROP_PRESENT)
188 return -ENODEV;
Lan Tianyu1dd5c712011-07-01 16:03:15 +0800189
190 acpi_battery_get_state(battery);
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400191 switch (psp) {
192 case POWER_SUPPLY_PROP_STATUS:
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400193 if (battery->rate_now < 0)
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400194 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400195 else if (battery->rate_now > 0)
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400196 val->intval = POWER_SUPPLY_STATUS_CHARGING;
197 else
198 val->intval = POWER_SUPPLY_STATUS_FULL;
199 break;
200 case POWER_SUPPLY_PROP_PRESENT:
201 val->intval = battery->present;
202 break;
203 case POWER_SUPPLY_PROP_TECHNOLOGY:
204 val->intval = acpi_battery_technology(battery);
205 break;
Alexey Starikovskiy16698852009-10-15 14:31:37 +0400206 case POWER_SUPPLY_PROP_CYCLE_COUNT:
207 val->intval = battery->cycle_count;
208 break;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400209 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
210 val->intval = battery->design_voltage *
211 acpi_battery_vscale(battery) * 1000;
212 break;
213 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
214 val->intval = battery->voltage_now *
215 acpi_battery_vscale(battery) * 1000;
216 break;
217 case POWER_SUPPLY_PROP_CURRENT_NOW:
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400218 case POWER_SUPPLY_PROP_POWER_NOW:
219 val->intval = abs(battery->rate_now) *
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400220 acpi_battery_ipscale(battery) * 1000;
Lan Tianyue4108292011-07-01 16:03:39 +0800221 val->intval *= (acpi_battery_mode(battery)) ?
222 (battery->voltage_now *
223 acpi_battery_vscale(battery) / 1000) : 1;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400224 break;
225 case POWER_SUPPLY_PROP_CURRENT_AVG:
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400226 case POWER_SUPPLY_PROP_POWER_AVG:
227 val->intval = abs(battery->rate_avg) *
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400228 acpi_battery_ipscale(battery) * 1000;
Lan Tianyue4108292011-07-01 16:03:39 +0800229 val->intval *= (acpi_battery_mode(battery)) ?
230 (battery->voltage_now *
231 acpi_battery_vscale(battery) / 1000) : 1;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400232 break;
233 case POWER_SUPPLY_PROP_CAPACITY:
234 val->intval = battery->state_of_charge;
235 break;
236 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
237 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
238 val->intval = battery->design_capacity *
239 acpi_battery_scale(battery) * 1000;
240 break;
241 case POWER_SUPPLY_PROP_CHARGE_FULL:
242 case POWER_SUPPLY_PROP_ENERGY_FULL:
243 val->intval = battery->full_charge_capacity *
244 acpi_battery_scale(battery) * 1000;
245 break;
246 case POWER_SUPPLY_PROP_CHARGE_NOW:
247 case POWER_SUPPLY_PROP_ENERGY_NOW:
248 val->intval = battery->capacity_now *
249 acpi_battery_scale(battery) * 1000;
250 break;
251 case POWER_SUPPLY_PROP_TEMP:
252 val->intval = battery->temp_now - 2730; // dK -> dC
253 break;
254 case POWER_SUPPLY_PROP_MODEL_NAME:
255 val->strval = battery->device_name;
256 break;
257 case POWER_SUPPLY_PROP_MANUFACTURER:
258 val->strval = battery->manufacturer_name;
259 break;
260 default:
261 return -EINVAL;
262 }
263 return 0;
264}
265
266static enum power_supply_property sbs_ac_props[] = {
267 POWER_SUPPLY_PROP_ONLINE,
268};
269
270static enum power_supply_property sbs_charge_battery_props[] = {
271 POWER_SUPPLY_PROP_STATUS,
272 POWER_SUPPLY_PROP_PRESENT,
273 POWER_SUPPLY_PROP_TECHNOLOGY,
Alexey Starikovskiy16698852009-10-15 14:31:37 +0400274 POWER_SUPPLY_PROP_CYCLE_COUNT,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400275 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
276 POWER_SUPPLY_PROP_VOLTAGE_NOW,
277 POWER_SUPPLY_PROP_CURRENT_NOW,
278 POWER_SUPPLY_PROP_CURRENT_AVG,
279 POWER_SUPPLY_PROP_CAPACITY,
280 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
281 POWER_SUPPLY_PROP_CHARGE_FULL,
282 POWER_SUPPLY_PROP_CHARGE_NOW,
283 POWER_SUPPLY_PROP_TEMP,
284 POWER_SUPPLY_PROP_MODEL_NAME,
285 POWER_SUPPLY_PROP_MANUFACTURER,
286};
287
288static enum power_supply_property sbs_energy_battery_props[] = {
289 POWER_SUPPLY_PROP_STATUS,
290 POWER_SUPPLY_PROP_PRESENT,
291 POWER_SUPPLY_PROP_TECHNOLOGY,
292 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
293 POWER_SUPPLY_PROP_VOLTAGE_NOW,
294 POWER_SUPPLY_PROP_CURRENT_NOW,
295 POWER_SUPPLY_PROP_CURRENT_AVG,
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400296 POWER_SUPPLY_PROP_POWER_NOW,
297 POWER_SUPPLY_PROP_POWER_AVG,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400298 POWER_SUPPLY_PROP_CAPACITY,
299 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
300 POWER_SUPPLY_PROP_ENERGY_FULL,
301 POWER_SUPPLY_PROP_ENERGY_NOW,
302 POWER_SUPPLY_PROP_TEMP,
303 POWER_SUPPLY_PROP_MODEL_NAME,
304 POWER_SUPPLY_PROP_MANUFACTURER,
305};
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400306
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100307static const struct power_supply_desc acpi_sbs_charger_desc = {
308 .name = "sbs-charger",
309 .type = POWER_SUPPLY_TYPE_MAINS,
310 .properties = sbs_ac_props,
311 .num_properties = ARRAY_SIZE(sbs_ac_props),
312 .get_property = sbs_get_ac_property,
313};
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400314
Rich Townsend3f86b832006-07-01 11:36:54 -0400315/* --------------------------------------------------------------------------
316 Smart Battery System Management
317 -------------------------------------------------------------------------- */
318
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400319struct acpi_battery_reader {
320 u8 command; /* command for battery */
321 u8 mode; /* word or block? */
322 size_t offset; /* offset inside struct acpi_sbs_battery */
323};
Vladimir Lebedev72206232007-03-19 17:45:50 +0300324
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400325static struct acpi_battery_reader info_readers[] = {
326 {0x01, SMBUS_READ_WORD, offsetof(struct acpi_battery, alarm_capacity)},
327 {0x03, SMBUS_READ_WORD, offsetof(struct acpi_battery, mode)},
328 {0x10, SMBUS_READ_WORD, offsetof(struct acpi_battery, full_charge_capacity)},
329 {0x17, SMBUS_READ_WORD, offsetof(struct acpi_battery, cycle_count)},
330 {0x18, SMBUS_READ_WORD, offsetof(struct acpi_battery, design_capacity)},
331 {0x19, SMBUS_READ_WORD, offsetof(struct acpi_battery, design_voltage)},
332 {0x1a, SMBUS_READ_WORD, offsetof(struct acpi_battery, spec)},
333 {0x1c, SMBUS_READ_WORD, offsetof(struct acpi_battery, serial_number)},
334 {0x20, SMBUS_READ_BLOCK, offsetof(struct acpi_battery, manufacturer_name)},
335 {0x21, SMBUS_READ_BLOCK, offsetof(struct acpi_battery, device_name)},
336 {0x22, SMBUS_READ_BLOCK, offsetof(struct acpi_battery, device_chemistry)},
337};
Rich Townsend3f86b832006-07-01 11:36:54 -0400338
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400339static struct acpi_battery_reader state_readers[] = {
340 {0x08, SMBUS_READ_WORD, offsetof(struct acpi_battery, temp_now)},
341 {0x09, SMBUS_READ_WORD, offsetof(struct acpi_battery, voltage_now)},
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400342 {0x0a, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_now)},
343 {0x0b, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_avg)},
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400344 {0x0f, SMBUS_READ_WORD, offsetof(struct acpi_battery, capacity_now)},
345 {0x0e, SMBUS_READ_WORD, offsetof(struct acpi_battery, state_of_charge)},
346 {0x16, SMBUS_READ_WORD, offsetof(struct acpi_battery, state)},
347};
Rich Townsend3f86b832006-07-01 11:36:54 -0400348
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400349static int acpi_manager_get_info(struct acpi_sbs *sbs)
Rich Townsend3f86b832006-07-01 11:36:54 -0400350{
Rich Townsend3f86b832006-07-01 11:36:54 -0400351 int result = 0;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400352 u16 battery_system_info;
Rich Townsend3f86b832006-07-01 11:36:54 -0400353
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400354 result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400355 0x04, (u8 *)&battery_system_info);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400356 if (!result)
357 sbs->batteries_supported = battery_system_info & 0x000f;
Len Brown635227e2006-07-01 16:48:23 -0400358 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400359}
360
361static int acpi_battery_get_info(struct acpi_battery *battery)
362{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400363 int i, result = 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400364
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400365 for (i = 0; i < ARRAY_SIZE(info_readers); ++i) {
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400366 result = acpi_smbus_read(battery->sbs->hc,
367 info_readers[i].mode,
368 ACPI_SBS_BATTERY,
369 info_readers[i].command,
370 (u8 *) battery +
371 info_readers[i].offset);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400372 if (result)
373 break;
Rich Townsend3f86b832006-07-01 11:36:54 -0400374 }
Len Brown635227e2006-07-01 16:48:23 -0400375 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400376}
377
Rich Townsend3f86b832006-07-01 11:36:54 -0400378static int acpi_battery_get_state(struct acpi_battery *battery)
379{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400380 int i, result = 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400381
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400382 if (battery->update_time &&
383 time_before(jiffies, battery->update_time +
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400384 msecs_to_jiffies(cache_time)))
385 return 0;
386 for (i = 0; i < ARRAY_SIZE(state_readers); ++i) {
387 result = acpi_smbus_read(battery->sbs->hc,
388 state_readers[i].mode,
389 ACPI_SBS_BATTERY,
390 state_readers[i].command,
391 (u8 *)battery +
392 state_readers[i].offset);
393 if (result)
394 goto end;
Rich Townsend3f86b832006-07-01 11:36:54 -0400395 }
Rich Townsend3f86b832006-07-01 11:36:54 -0400396 end:
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400397 battery->update_time = jiffies;
Len Brown635227e2006-07-01 16:48:23 -0400398 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400399}
400
401static int acpi_battery_get_alarm(struct acpi_battery *battery)
402{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400403 return acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
404 ACPI_SBS_BATTERY, 0x01,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400405 (u8 *)&battery->alarm_capacity);
Rich Townsend3f86b832006-07-01 11:36:54 -0400406}
407
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400408static int acpi_battery_set_alarm(struct acpi_battery *battery)
Rich Townsend3f86b832006-07-01 11:36:54 -0400409{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400410 struct acpi_sbs *sbs = battery->sbs;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400411 u16 value, sel = 1 << (battery->id + 12);
412
413 int ret;
414
Rich Townsend3f86b832006-07-01 11:36:54 -0400415
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400416 if (sbs->manager_present) {
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400417 ret = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER,
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400418 0x01, (u8 *)&value);
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400419 if (ret)
420 goto end;
421 if ((value & 0xf000) != sel) {
422 value &= 0x0fff;
423 value |= sel;
424 ret = acpi_smbus_write(sbs->hc, SMBUS_WRITE_WORD,
425 ACPI_SBS_MANAGER,
426 0x01, (u8 *)&value, 2);
427 if (ret)
428 goto end;
429 }
Rich Townsend3f86b832006-07-01 11:36:54 -0400430 }
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400431 ret = acpi_smbus_write(sbs->hc, SMBUS_WRITE_WORD, ACPI_SBS_BATTERY,
432 0x01, (u8 *)&battery->alarm_capacity, 2);
433 end:
434 return ret;
Rich Townsend3f86b832006-07-01 11:36:54 -0400435}
436
437static int acpi_ac_get_present(struct acpi_sbs *sbs)
438{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400439 int result;
440 u16 status;
Rich Townsend3f86b832006-07-01 11:36:54 -0400441
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400442 result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_CHARGER,
443 0x13, (u8 *) & status);
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200444
445 if (result)
446 return result;
447
448 /*
449 * The spec requires that bit 4 always be 1. If it's not set, assume
450 * that the implementation doesn't support an SBS charger
451 */
Rafael J. Wysocki5159e392014-09-28 01:27:42 +0200452 if (!((status >> 4) & 0x1))
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200453 return -ENODEV;
454
455 sbs->charger_present = (status >> 15) & 0x1;
456 return 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400457}
458
Alexey Starikovskiy8bd95532007-09-26 19:44:00 +0400459static ssize_t acpi_battery_alarm_show(struct device *dev,
460 struct device_attribute *attr,
461 char *buf)
462{
463 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
464 acpi_battery_get_alarm(battery);
465 return sprintf(buf, "%d\n", battery->alarm_capacity *
466 acpi_battery_scale(battery) * 1000);
467}
468
469static ssize_t acpi_battery_alarm_store(struct device *dev,
470 struct device_attribute *attr,
471 const char *buf, size_t count)
472{
473 unsigned long x;
474 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
Luis G.F32a90512014-02-10 11:36:42 +0100475 if (sscanf(buf, "%lu\n", &x) == 1)
Alexey Starikovskiy8bd95532007-09-26 19:44:00 +0400476 battery->alarm_capacity = x /
477 (1000 * acpi_battery_scale(battery));
478 if (battery->present)
479 acpi_battery_set_alarm(battery);
480 return count;
481}
482
483static struct device_attribute alarm_attr = {
Parag Warudkar01e8ef12008-10-18 20:28:50 -0700484 .attr = {.name = "alarm", .mode = 0644},
Alexey Starikovskiy8bd95532007-09-26 19:44:00 +0400485 .show = acpi_battery_alarm_show,
486 .store = acpi_battery_alarm_store,
487};
488
Rich Townsend3f86b832006-07-01 11:36:54 -0400489/* --------------------------------------------------------------------------
Rich Townsend3f86b832006-07-01 11:36:54 -0400490 Driver Interface
491 -------------------------------------------------------------------------- */
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400492static int acpi_battery_read(struct acpi_battery *battery)
493{
494 int result = 0, saved_present = battery->present;
495 u16 state;
496
497 if (battery->sbs->manager_present) {
498 result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
499 ACPI_SBS_MANAGER, 0x01, (u8 *)&state);
500 if (!result)
501 battery->present = state & (1 << battery->id);
502 state &= 0x0fff;
503 state |= 1 << (battery->id + 12);
504 acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD,
505 ACPI_SBS_MANAGER, 0x01, (u8 *)&state, 2);
506 } else if (battery->id == 0)
507 battery->present = 1;
Matthew Garrett9faf6132014-09-20 13:19:46 +0200508
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400509 if (result || !battery->present)
510 return result;
511
512 if (saved_present != battery->present) {
513 battery->update_time = 0;
514 result = acpi_battery_get_info(battery);
Matthew Garrett9faf6132014-09-20 13:19:46 +0200515 if (result) {
516 battery->present = 0;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400517 return result;
Matthew Garrett9faf6132014-09-20 13:19:46 +0200518 }
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400519 }
520 result = acpi_battery_get_state(battery);
Matthew Garrett9faf6132014-09-20 13:19:46 +0200521 if (result)
522 battery->present = 0;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400523 return result;
524}
525
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400526/* Smart Battery */
Rich Townsend3f86b832006-07-01 11:36:54 -0400527static int acpi_battery_add(struct acpi_sbs *sbs, int id)
528{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400529 struct acpi_battery *battery = &sbs->battery[id];
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100530 struct power_supply_config psy_cfg = { .drv_data = battery, };
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400531 int result;
532
Rich Townsend3f86b832006-07-01 11:36:54 -0400533 battery->id = id;
534 battery->sbs = sbs;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400535 result = acpi_battery_read(battery);
536 if (result)
537 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400538
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400539 sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100540 battery->bat_desc.name = battery->name;
541 battery->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400542 if (!acpi_battery_mode(battery)) {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100543 battery->bat_desc.properties = sbs_charge_battery_props;
544 battery->bat_desc.num_properties =
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400545 ARRAY_SIZE(sbs_charge_battery_props);
546 } else {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100547 battery->bat_desc.properties = sbs_energy_battery_props;
548 battery->bat_desc.num_properties =
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400549 ARRAY_SIZE(sbs_energy_battery_props);
550 }
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100551 battery->bat_desc.get_property = acpi_sbs_battery_get_property;
552 battery->bat = power_supply_register(&sbs->device->dev,
553 &battery->bat_desc, &psy_cfg);
554 if (IS_ERR(battery->bat)) {
555 result = PTR_ERR(battery->bat);
556 battery->bat = NULL;
Jeff Garzik037cbc62007-11-18 00:32:31 +0300557 goto end;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100558 }
Matthew Garrett9faf6132014-09-20 13:19:46 +0200559
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100560 result = device_create_file(&battery->bat->dev, &alarm_attr);
Jeff Garzik037cbc62007-11-18 00:32:31 +0300561 if (result)
562 goto end;
563 battery->have_sysfs_alarm = 1;
564 end:
Vladimir Lebedev72206232007-03-19 17:45:50 +0300565 printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n",
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400566 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
Alexey Starikovskiybbafbec2008-02-09 03:22:13 -0500567 battery->name, battery->present ? "present" : "absent");
Len Brown635227e2006-07-01 16:48:23 -0400568 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400569}
570
571static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
572{
Jeff Garzik037cbc62007-11-18 00:32:31 +0300573 struct acpi_battery *battery = &sbs->battery[id];
Rakib Mullickc19bdb62010-01-03 19:27:56 +0600574
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100575 if (battery->bat) {
Jeff Garzik037cbc62007-11-18 00:32:31 +0300576 if (battery->have_sysfs_alarm)
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100577 device_remove_file(&battery->bat->dev, &alarm_attr);
578 power_supply_unregister(battery->bat);
Rich Townsend3f86b832006-07-01 11:36:54 -0400579 }
580}
581
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400582static int acpi_charger_add(struct acpi_sbs *sbs)
Rich Townsend3f86b832006-07-01 11:36:54 -0400583{
584 int result;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100585 struct power_supply_config psy_cfg = { .drv_data = sbs, };
Rich Townsend3f86b832006-07-01 11:36:54 -0400586
Rich Townsend3f86b832006-07-01 11:36:54 -0400587 result = acpi_ac_get_present(sbs);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400588 if (result)
Rich Townsend3f86b832006-07-01 11:36:54 -0400589 goto end;
Lan Tianyu2a68b992013-10-11 09:54:09 +0800590
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200591 sbs->charger_exists = 1;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100592 sbs->charger = power_supply_register(&sbs->device->dev,
593 &acpi_sbs_charger_desc, &psy_cfg);
594 if (IS_ERR(sbs->charger)) {
595 result = PTR_ERR(sbs->charger);
596 sbs->charger = NULL;
597 }
Vladimir Lebedev72206232007-03-19 17:45:50 +0300598 printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n",
599 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
Alexey Starikovskiy89862e32007-09-26 19:43:35 +0400600 ACPI_AC_DIR_NAME, sbs->charger_present ? "on-line" : "off-line");
Rich Townsend3f86b832006-07-01 11:36:54 -0400601 end:
Len Brown635227e2006-07-01 16:48:23 -0400602 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400603}
604
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400605static void acpi_charger_remove(struct acpi_sbs *sbs)
Rich Townsend3f86b832006-07-01 11:36:54 -0400606{
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100607 if (sbs->charger)
608 power_supply_unregister(sbs->charger);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400609}
610
Adrian Bunke5685b92007-10-24 18:24:42 +0200611static void acpi_sbs_callback(void *context)
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400612{
613 int id;
614 struct acpi_sbs *sbs = context;
615 struct acpi_battery *bat;
616 u8 saved_charger_state = sbs->charger_present;
617 u8 saved_battery_state;
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200618
619 if (sbs->charger_exists) {
620 acpi_ac_get_present(sbs);
621 if (sbs->charger_present != saved_charger_state)
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100622 kobject_uevent(&sbs->charger->dev.kobj, KOBJ_CHANGE);
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200623 }
Thomas Renninger1696d9d2013-07-15 10:15:09 +0200624
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400625 if (sbs->manager_present) {
626 for (id = 0; id < MAX_SBS_BAT; ++id) {
627 if (!(sbs->batteries_supported & (1 << id)))
628 continue;
629 bat = &sbs->battery[id];
630 saved_battery_state = bat->present;
631 acpi_battery_read(bat);
632 if (saved_battery_state == bat->present)
633 continue;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100634 kobject_uevent(&bat->bat->dev.kobj, KOBJ_CHANGE);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400635 }
Rich Townsend3f86b832006-07-01 11:36:54 -0400636 }
637}
638
Matthew Garrett9faf6132014-09-20 13:19:46 +0200639static int disable_sbs_manager(const struct dmi_system_id *d)
640{
641 sbs_manager_broken = true;
642 return 0;
643}
644
645static struct dmi_system_id acpi_sbs_dmi_table[] = {
646 {
647 .callback = disable_sbs_manager,
648 .ident = "Apple",
649 .matches = {
650 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc.")
651 },
652 },
653 { },
654};
655
Rich Townsend3f86b832006-07-01 11:36:54 -0400656static int acpi_sbs_add(struct acpi_device *device)
657{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400658 struct acpi_sbs *sbs;
659 int result = 0;
Vladimir Lebedev6d157022007-03-19 17:45:50 +0300660 int id;
Rich Townsend3f86b832006-07-01 11:36:54 -0400661
Matthew Garrett9faf6132014-09-20 13:19:46 +0200662 dmi_check_system(acpi_sbs_dmi_table);
663
Burman Yan36bcbec2006-12-19 12:56:11 -0800664 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
Rich Townsend3f86b832006-07-01 11:36:54 -0400665 if (!sbs) {
Vladimir Lebedev72206232007-03-19 17:45:50 +0300666 result = -ENOMEM;
667 goto end;
Rich Townsend3f86b832006-07-01 11:36:54 -0400668 }
Rich Townsend3f86b832006-07-01 11:36:54 -0400669
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400670 mutex_init(&sbs->lock);
Vladimir Lebedev72206232007-03-19 17:45:50 +0300671
Alexey Starikovskiy91087df2007-09-26 19:43:28 +0400672 sbs->hc = acpi_driver_data(device->parent);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400673 sbs->device = device;
Rich Townsend3f86b832006-07-01 11:36:54 -0400674 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
675 strcpy(acpi_device_class(device), ACPI_SBS_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700676 device->driver_data = sbs;
Rich Townsend3f86b832006-07-01 11:36:54 -0400677
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400678 result = acpi_charger_add(sbs);
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200679 if (result && result != -ENODEV)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300680 goto end;
Rich Townsend3f86b832006-07-01 11:36:54 -0400681
Matthew Garrett9faf6132014-09-20 13:19:46 +0200682 result = 0;
683
684 if (!sbs_manager_broken) {
685 result = acpi_manager_get_info(sbs);
686 if (!result) {
Chris Bainbridge61f8ff62015-04-22 16:40:21 +0100687 sbs->manager_present = 1;
Matthew Garrett9faf6132014-09-20 13:19:46 +0200688 for (id = 0; id < MAX_SBS_BAT; ++id)
689 if ((sbs->batteries_supported & (1 << id)))
690 acpi_battery_add(sbs, id);
691 }
692 }
693
694 if (!sbs->manager_present)
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400695 acpi_battery_add(sbs, 0);
Matthew Garrett9faf6132014-09-20 13:19:46 +0200696
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400697 acpi_smbus_register_callback(sbs->hc, acpi_sbs_callback, sbs);
Rich Townsend3f86b832006-07-01 11:36:54 -0400698 end:
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400699 if (result)
Rafael J. Wysocki51fac832013-01-24 00:24:48 +0100700 acpi_sbs_remove(device);
Len Brown635227e2006-07-01 16:48:23 -0400701 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400702}
703
Rafael J. Wysocki51fac832013-01-24 00:24:48 +0100704static int acpi_sbs_remove(struct acpi_device *device)
Rich Townsend3f86b832006-07-01 11:36:54 -0400705{
Len Browncece9012006-12-16 01:04:27 -0500706 struct acpi_sbs *sbs;
Rich Townsend3f86b832006-07-01 11:36:54 -0400707 int id;
708
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400709 if (!device)
Lebedev, Vladimir P963497c2006-09-05 19:49:13 +0400710 return -EINVAL;
Vladimir Lebedev72206232007-03-19 17:45:50 +0300711 sbs = acpi_driver_data(device);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400712 if (!sbs)
Len Brown635227e2006-07-01 16:48:23 -0400713 return -EINVAL;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400714 mutex_lock(&sbs->lock);
715 acpi_smbus_unregister_callback(sbs->hc);
716 for (id = 0; id < MAX_SBS_BAT; ++id)
Rich Townsend3f86b832006-07-01 11:36:54 -0400717 acpi_battery_remove(sbs, id);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400718 acpi_charger_remove(sbs);
719 mutex_unlock(&sbs->lock);
720 mutex_destroy(&sbs->lock);
Rich Townsend3f86b832006-07-01 11:36:54 -0400721 kfree(sbs);
Len Brown635227e2006-07-01 16:48:23 -0400722 return 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400723}
724
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200725#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200726static int acpi_sbs_resume(struct device *dev)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300727{
728 struct acpi_sbs *sbs;
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200729 if (!dev)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300730 return -EINVAL;
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200731 sbs = to_acpi_device(dev)->driver_data;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400732 acpi_sbs_callback(sbs);
Vladimir Lebedev72206232007-03-19 17:45:50 +0300733 return 0;
734}
Shuah Khan15029dd2014-02-12 20:19:09 -0700735#else
736#define acpi_sbs_resume NULL
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200737#endif
Vladimir Lebedev72206232007-03-19 17:45:50 +0300738
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200739static SIMPLE_DEV_PM_OPS(acpi_sbs_pm, NULL, acpi_sbs_resume);
740
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400741static struct acpi_driver acpi_sbs_driver = {
742 .name = "sbs",
743 .class = ACPI_SBS_CLASS,
744 .ids = sbs_device_ids,
745 .ops = {
746 .add = acpi_sbs_add,
747 .remove = acpi_sbs_remove,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400748 },
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200749 .drv.pm = &acpi_sbs_pm,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400750};
751
Rich Townsend3f86b832006-07-01 11:36:54 -0400752static int __init acpi_sbs_init(void)
753{
754 int result = 0;
755
Len Brownb20d2ae2006-08-15 23:21:37 -0400756 if (acpi_disabled)
757 return -ENODEV;
Lan Tianyu2a68b992013-10-11 09:54:09 +0800758
Rich Townsend3f86b832006-07-01 11:36:54 -0400759 result = acpi_bus_register_driver(&acpi_sbs_driver);
Lan Tianyu2a68b992013-10-11 09:54:09 +0800760 if (result < 0)
Len Brown635227e2006-07-01 16:48:23 -0400761 return -ENODEV;
Lan Tianyu2a68b992013-10-11 09:54:09 +0800762
Len Brown635227e2006-07-01 16:48:23 -0400763 return 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400764}
765
766static void __exit acpi_sbs_exit(void)
767{
Rich Townsend3f86b832006-07-01 11:36:54 -0400768 acpi_bus_unregister_driver(&acpi_sbs_driver);
Len Brown635227e2006-07-01 16:48:23 -0400769 return;
Rich Townsend3f86b832006-07-01 11:36:54 -0400770}
771
772module_init(acpi_sbs_init);
773module_exit(acpi_sbs_exit);