blob: 6e88224f60f097525120de47626d5249050123df [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Rich Townsend3f86b832006-07-01 11:36:54 -04002/*
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +04003 * sbs.c - ACPI Smart Battery System Driver ($Revision: 2.0 $)
Rich Townsend3f86b832006-07-01 11:36:54 -04004 *
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +04005 * Copyright (c) 2007 Alexey Starikovskiy <astarikovskiy@suse.de>
6 * Copyright (c) 2005-2007 Vladimir Lebedev <vladimir.p.lebedev@intel.com>
Rich Townsend3f86b832006-07-01 11:36:54 -04007 * Copyright (c) 2005 Rich Townsend <rhdt@bartol.udel.edu>
Rich Townsend3f86b832006-07-01 11:36:54 -04008 */
9
10#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Rich Townsend3f86b832006-07-01 11:36:54 -040012#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/kernel.h>
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +040015
Rich Townsend3f86b832006-07-01 11:36:54 -040016#include <linux/acpi.h>
Vladimir Lebedev6d157022007-03-19 17:45:50 +030017#include <linux/timer.h>
Vladimir Lebedev72206232007-03-19 17:45:50 +030018#include <linux/jiffies.h>
Rich Townsend3f86b832006-07-01 11:36:54 -040019#include <linux/delay.h>
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +040020#include <linux/power_supply.h>
Lukas Wunner630b3af2017-08-01 14:10:41 +020021#include <linux/platform_data/x86/apple.h>
Ognjen Galicfa938542018-02-07 15:58:13 +010022#include <acpi/battery.h>
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +040023
Alexey Starikovskiy91087df2007-09-26 19:43:28 +040024#include "sbshc.h"
25
Len Browna192a952009-07-28 16:45:54 -040026#define PREFIX "ACPI: "
27
Rich Townsend3f86b832006-07-01 11:36:54 -040028#define ACPI_SBS_CLASS "sbs"
29#define ACPI_AC_CLASS "ac_adapter"
Rich Townsend3f86b832006-07-01 11:36:54 -040030#define ACPI_SBS_DEVICE_NAME "Smart Battery System"
31#define ACPI_SBS_FILE_INFO "info"
32#define ACPI_SBS_FILE_STATE "state"
33#define ACPI_SBS_FILE_ALARM "alarm"
34#define ACPI_BATTERY_DIR_NAME "BAT%i"
35#define ACPI_AC_DIR_NAME "AC0"
Rich Townsend3f86b832006-07-01 11:36:54 -040036
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040037#define ACPI_SBS_NOTIFY_STATUS 0x80
38#define ACPI_SBS_NOTIFY_INFO 0x81
Rich Townsend3f86b832006-07-01 11:36:54 -040039
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040040MODULE_AUTHOR("Alexey Starikovskiy <astarikovskiy@suse.de>");
Rich Townsend3f86b832006-07-01 11:36:54 -040041MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
42MODULE_LICENSE("GPL");
43
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040044static unsigned int cache_time = 1000;
45module_param(cache_time, uint, 0644);
46MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
Vladimir Lebedev6d157022007-03-19 17:45:50 +030047
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040048#define MAX_SBS_BAT 4
Vladimir Lebedev6d157022007-03-19 17:45:50 +030049#define ACPI_SBS_BLOCK_MAX 32
50
Thomas Renninger1ba90e32007-07-23 14:44:41 +020051static const struct acpi_device_id sbs_device_ids[] = {
Alexey Starikovskiy91087df2007-09-26 19:43:28 +040052 {"ACPI0002", 0},
Thomas Renninger1ba90e32007-07-23 14:44:41 +020053 {"", 0},
54};
55MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
56
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040057struct acpi_battery {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +010058 struct power_supply *bat;
59 struct power_supply_desc bat_desc;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040060 struct acpi_sbs *sbs;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040061 unsigned long update_time;
62 char name[8];
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040063 char manufacturer_name[ACPI_SBS_BLOCK_MAX];
64 char device_name[ACPI_SBS_BLOCK_MAX];
65 char device_chemistry[ACPI_SBS_BLOCK_MAX];
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +040066 u16 alarm_capacity;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040067 u16 full_charge_capacity;
68 u16 design_capacity;
69 u16 design_voltage;
70 u16 serial_number;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040071 u16 cycle_count;
72 u16 temp_now;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040073 u16 voltage_now;
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -040074 s16 rate_now;
75 s16 rate_avg;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040076 u16 capacity_now;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040077 u16 state_of_charge;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040078 u16 state;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040079 u16 mode;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040080 u16 spec;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040081 u8 id;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040082 u8 present:1;
Jeff Garzik037cbc62007-11-18 00:32:31 +030083 u8 have_sysfs_alarm:1;
Rich Townsend3f86b832006-07-01 11:36:54 -040084};
85
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +010086#define to_acpi_battery(x) power_supply_get_drvdata(x)
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +040087
Rich Townsend3f86b832006-07-01 11:36:54 -040088struct acpi_sbs {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +010089 struct power_supply *charger;
Rich Townsend3f86b832006-07-01 11:36:54 -040090 struct acpi_device *device;
Alexey Starikovskiy91087df2007-09-26 19:43:28 +040091 struct acpi_smb_hc *hc;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040092 struct mutex lock;
Rich Townsend3f86b832006-07-01 11:36:54 -040093 struct acpi_battery battery[MAX_SBS_BAT];
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +040094 u8 batteries_supported:4;
Alexey Starikovskiy89862e32007-09-26 19:43:35 +040095 u8 manager_present:1;
96 u8 charger_present:1;
Matthew Garrett3031cdd2014-09-20 13:19:45 +020097 u8 charger_exists:1;
Rich Townsend3f86b832006-07-01 11:36:54 -040098};
99
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100100#define to_acpi_sbs(x) power_supply_get_drvdata(x)
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400101
Rafael J. Wysocki51fac832013-01-24 00:24:48 +0100102static int acpi_sbs_remove(struct acpi_device *device);
Lan Tianyu1dd5c712011-07-01 16:03:15 +0800103static int acpi_battery_get_state(struct acpi_battery *battery);
104
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400105static inline int battery_scale(int log)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300106{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400107 int scale = 1;
108 while (log--)
109 scale *= 10;
110 return scale;
Vladimir Lebedev72206232007-03-19 17:45:50 +0300111}
112
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400113static inline int acpi_battery_vscale(struct acpi_battery *battery)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300114{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400115 return battery_scale((battery->spec & 0x0f00) >> 8);
Vladimir Lebedev72206232007-03-19 17:45:50 +0300116}
117
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400118static inline int acpi_battery_ipscale(struct acpi_battery *battery)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300119{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400120 return battery_scale((battery->spec & 0xf000) >> 12);
121}
122
123static inline int acpi_battery_mode(struct acpi_battery *battery)
124{
125 return (battery->mode & 0x8000);
126}
127
128static inline int acpi_battery_scale(struct acpi_battery *battery)
129{
130 return (acpi_battery_mode(battery) ? 10 : 1) *
131 acpi_battery_ipscale(battery);
Vladimir Lebedev72206232007-03-19 17:45:50 +0300132}
133
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400134static int sbs_get_ac_property(struct power_supply *psy,
135 enum power_supply_property psp,
136 union power_supply_propval *val)
137{
138 struct acpi_sbs *sbs = to_acpi_sbs(psy);
139 switch (psp) {
140 case POWER_SUPPLY_PROP_ONLINE:
141 val->intval = sbs->charger_present;
142 break;
143 default:
144 return -EINVAL;
145 }
146 return 0;
147}
148
149static int acpi_battery_technology(struct acpi_battery *battery)
150{
151 if (!strcasecmp("NiCd", battery->device_chemistry))
152 return POWER_SUPPLY_TECHNOLOGY_NiCd;
153 if (!strcasecmp("NiMH", battery->device_chemistry))
154 return POWER_SUPPLY_TECHNOLOGY_NiMH;
155 if (!strcasecmp("LION", battery->device_chemistry))
156 return POWER_SUPPLY_TECHNOLOGY_LION;
157 if (!strcasecmp("LiP", battery->device_chemistry))
158 return POWER_SUPPLY_TECHNOLOGY_LIPO;
159 return POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
160}
161
162static int acpi_sbs_battery_get_property(struct power_supply *psy,
163 enum power_supply_property psp,
164 union power_supply_propval *val)
165{
166 struct acpi_battery *battery = to_acpi_battery(psy);
167
168 if ((!battery->present) && psp != POWER_SUPPLY_PROP_PRESENT)
169 return -ENODEV;
Lan Tianyu1dd5c712011-07-01 16:03:15 +0800170
171 acpi_battery_get_state(battery);
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400172 switch (psp) {
173 case POWER_SUPPLY_PROP_STATUS:
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400174 if (battery->rate_now < 0)
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400175 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400176 else if (battery->rate_now > 0)
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400177 val->intval = POWER_SUPPLY_STATUS_CHARGING;
178 else
179 val->intval = POWER_SUPPLY_STATUS_FULL;
180 break;
181 case POWER_SUPPLY_PROP_PRESENT:
182 val->intval = battery->present;
183 break;
184 case POWER_SUPPLY_PROP_TECHNOLOGY:
185 val->intval = acpi_battery_technology(battery);
186 break;
Alexey Starikovskiy16698852009-10-15 14:31:37 +0400187 case POWER_SUPPLY_PROP_CYCLE_COUNT:
188 val->intval = battery->cycle_count;
189 break;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400190 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
191 val->intval = battery->design_voltage *
192 acpi_battery_vscale(battery) * 1000;
193 break;
194 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
195 val->intval = battery->voltage_now *
196 acpi_battery_vscale(battery) * 1000;
197 break;
198 case POWER_SUPPLY_PROP_CURRENT_NOW:
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400199 case POWER_SUPPLY_PROP_POWER_NOW:
200 val->intval = abs(battery->rate_now) *
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400201 acpi_battery_ipscale(battery) * 1000;
Lan Tianyue4108292011-07-01 16:03:39 +0800202 val->intval *= (acpi_battery_mode(battery)) ?
203 (battery->voltage_now *
204 acpi_battery_vscale(battery) / 1000) : 1;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400205 break;
206 case POWER_SUPPLY_PROP_CURRENT_AVG:
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400207 case POWER_SUPPLY_PROP_POWER_AVG:
208 val->intval = abs(battery->rate_avg) *
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400209 acpi_battery_ipscale(battery) * 1000;
Lan Tianyue4108292011-07-01 16:03:39 +0800210 val->intval *= (acpi_battery_mode(battery)) ?
211 (battery->voltage_now *
212 acpi_battery_vscale(battery) / 1000) : 1;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400213 break;
214 case POWER_SUPPLY_PROP_CAPACITY:
215 val->intval = battery->state_of_charge;
216 break;
217 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
218 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
219 val->intval = battery->design_capacity *
220 acpi_battery_scale(battery) * 1000;
221 break;
222 case POWER_SUPPLY_PROP_CHARGE_FULL:
223 case POWER_SUPPLY_PROP_ENERGY_FULL:
224 val->intval = battery->full_charge_capacity *
225 acpi_battery_scale(battery) * 1000;
226 break;
227 case POWER_SUPPLY_PROP_CHARGE_NOW:
228 case POWER_SUPPLY_PROP_ENERGY_NOW:
229 val->intval = battery->capacity_now *
230 acpi_battery_scale(battery) * 1000;
231 break;
232 case POWER_SUPPLY_PROP_TEMP:
233 val->intval = battery->temp_now - 2730; // dK -> dC
234 break;
235 case POWER_SUPPLY_PROP_MODEL_NAME:
236 val->strval = battery->device_name;
237 break;
238 case POWER_SUPPLY_PROP_MANUFACTURER:
239 val->strval = battery->manufacturer_name;
240 break;
241 default:
242 return -EINVAL;
243 }
244 return 0;
245}
246
247static enum power_supply_property sbs_ac_props[] = {
248 POWER_SUPPLY_PROP_ONLINE,
249};
250
251static enum power_supply_property sbs_charge_battery_props[] = {
252 POWER_SUPPLY_PROP_STATUS,
253 POWER_SUPPLY_PROP_PRESENT,
254 POWER_SUPPLY_PROP_TECHNOLOGY,
Alexey Starikovskiy16698852009-10-15 14:31:37 +0400255 POWER_SUPPLY_PROP_CYCLE_COUNT,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400256 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
257 POWER_SUPPLY_PROP_VOLTAGE_NOW,
258 POWER_SUPPLY_PROP_CURRENT_NOW,
259 POWER_SUPPLY_PROP_CURRENT_AVG,
260 POWER_SUPPLY_PROP_CAPACITY,
261 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
262 POWER_SUPPLY_PROP_CHARGE_FULL,
263 POWER_SUPPLY_PROP_CHARGE_NOW,
264 POWER_SUPPLY_PROP_TEMP,
265 POWER_SUPPLY_PROP_MODEL_NAME,
266 POWER_SUPPLY_PROP_MANUFACTURER,
267};
268
269static enum power_supply_property sbs_energy_battery_props[] = {
270 POWER_SUPPLY_PROP_STATUS,
271 POWER_SUPPLY_PROP_PRESENT,
272 POWER_SUPPLY_PROP_TECHNOLOGY,
273 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
274 POWER_SUPPLY_PROP_VOLTAGE_NOW,
275 POWER_SUPPLY_PROP_CURRENT_NOW,
276 POWER_SUPPLY_PROP_CURRENT_AVG,
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400277 POWER_SUPPLY_PROP_POWER_NOW,
278 POWER_SUPPLY_PROP_POWER_AVG,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400279 POWER_SUPPLY_PROP_CAPACITY,
280 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
281 POWER_SUPPLY_PROP_ENERGY_FULL,
282 POWER_SUPPLY_PROP_ENERGY_NOW,
283 POWER_SUPPLY_PROP_TEMP,
284 POWER_SUPPLY_PROP_MODEL_NAME,
285 POWER_SUPPLY_PROP_MANUFACTURER,
286};
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400287
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100288static const struct power_supply_desc acpi_sbs_charger_desc = {
289 .name = "sbs-charger",
290 .type = POWER_SUPPLY_TYPE_MAINS,
291 .properties = sbs_ac_props,
292 .num_properties = ARRAY_SIZE(sbs_ac_props),
293 .get_property = sbs_get_ac_property,
294};
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400295
Rich Townsend3f86b832006-07-01 11:36:54 -0400296/* --------------------------------------------------------------------------
297 Smart Battery System Management
298 -------------------------------------------------------------------------- */
299
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400300struct acpi_battery_reader {
301 u8 command; /* command for battery */
302 u8 mode; /* word or block? */
303 size_t offset; /* offset inside struct acpi_sbs_battery */
304};
Vladimir Lebedev72206232007-03-19 17:45:50 +0300305
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400306static struct acpi_battery_reader info_readers[] = {
307 {0x01, SMBUS_READ_WORD, offsetof(struct acpi_battery, alarm_capacity)},
308 {0x03, SMBUS_READ_WORD, offsetof(struct acpi_battery, mode)},
309 {0x10, SMBUS_READ_WORD, offsetof(struct acpi_battery, full_charge_capacity)},
310 {0x17, SMBUS_READ_WORD, offsetof(struct acpi_battery, cycle_count)},
311 {0x18, SMBUS_READ_WORD, offsetof(struct acpi_battery, design_capacity)},
312 {0x19, SMBUS_READ_WORD, offsetof(struct acpi_battery, design_voltage)},
313 {0x1a, SMBUS_READ_WORD, offsetof(struct acpi_battery, spec)},
314 {0x1c, SMBUS_READ_WORD, offsetof(struct acpi_battery, serial_number)},
315 {0x20, SMBUS_READ_BLOCK, offsetof(struct acpi_battery, manufacturer_name)},
316 {0x21, SMBUS_READ_BLOCK, offsetof(struct acpi_battery, device_name)},
317 {0x22, SMBUS_READ_BLOCK, offsetof(struct acpi_battery, device_chemistry)},
318};
Rich Townsend3f86b832006-07-01 11:36:54 -0400319
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400320static struct acpi_battery_reader state_readers[] = {
321 {0x08, SMBUS_READ_WORD, offsetof(struct acpi_battery, temp_now)},
322 {0x09, SMBUS_READ_WORD, offsetof(struct acpi_battery, voltage_now)},
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400323 {0x0a, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_now)},
324 {0x0b, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_avg)},
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400325 {0x0f, SMBUS_READ_WORD, offsetof(struct acpi_battery, capacity_now)},
326 {0x0e, SMBUS_READ_WORD, offsetof(struct acpi_battery, state_of_charge)},
327 {0x16, SMBUS_READ_WORD, offsetof(struct acpi_battery, state)},
328};
Rich Townsend3f86b832006-07-01 11:36:54 -0400329
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400330static int acpi_manager_get_info(struct acpi_sbs *sbs)
Rich Townsend3f86b832006-07-01 11:36:54 -0400331{
Rich Townsend3f86b832006-07-01 11:36:54 -0400332 int result = 0;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400333 u16 battery_system_info;
Rich Townsend3f86b832006-07-01 11:36:54 -0400334
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400335 result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400336 0x04, (u8 *)&battery_system_info);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400337 if (!result)
338 sbs->batteries_supported = battery_system_info & 0x000f;
Len Brown635227e2006-07-01 16:48:23 -0400339 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400340}
341
342static int acpi_battery_get_info(struct acpi_battery *battery)
343{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400344 int i, result = 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400345
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400346 for (i = 0; i < ARRAY_SIZE(info_readers); ++i) {
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400347 result = acpi_smbus_read(battery->sbs->hc,
348 info_readers[i].mode,
349 ACPI_SBS_BATTERY,
350 info_readers[i].command,
351 (u8 *) battery +
352 info_readers[i].offset);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400353 if (result)
354 break;
Rich Townsend3f86b832006-07-01 11:36:54 -0400355 }
Len Brown635227e2006-07-01 16:48:23 -0400356 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400357}
358
Rich Townsend3f86b832006-07-01 11:36:54 -0400359static int acpi_battery_get_state(struct acpi_battery *battery)
360{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400361 int i, result = 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400362
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400363 if (battery->update_time &&
364 time_before(jiffies, battery->update_time +
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400365 msecs_to_jiffies(cache_time)))
366 return 0;
367 for (i = 0; i < ARRAY_SIZE(state_readers); ++i) {
368 result = acpi_smbus_read(battery->sbs->hc,
369 state_readers[i].mode,
370 ACPI_SBS_BATTERY,
371 state_readers[i].command,
372 (u8 *)battery +
373 state_readers[i].offset);
374 if (result)
375 goto end;
Rich Townsend3f86b832006-07-01 11:36:54 -0400376 }
Rich Townsend3f86b832006-07-01 11:36:54 -0400377 end:
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400378 battery->update_time = jiffies;
Len Brown635227e2006-07-01 16:48:23 -0400379 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400380}
381
382static int acpi_battery_get_alarm(struct acpi_battery *battery)
383{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400384 return acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
385 ACPI_SBS_BATTERY, 0x01,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400386 (u8 *)&battery->alarm_capacity);
Rich Townsend3f86b832006-07-01 11:36:54 -0400387}
388
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400389static int acpi_battery_set_alarm(struct acpi_battery *battery)
Rich Townsend3f86b832006-07-01 11:36:54 -0400390{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400391 struct acpi_sbs *sbs = battery->sbs;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400392 u16 value, sel = 1 << (battery->id + 12);
393
394 int ret;
395
Rich Townsend3f86b832006-07-01 11:36:54 -0400396
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400397 if (sbs->manager_present) {
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400398 ret = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER,
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400399 0x01, (u8 *)&value);
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400400 if (ret)
401 goto end;
402 if ((value & 0xf000) != sel) {
403 value &= 0x0fff;
404 value |= sel;
Colin Ian Kinga84bc8c2016-01-01 23:53:45 +0000405 ret = acpi_smbus_write(sbs->hc, SMBUS_WRITE_WORD,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400406 ACPI_SBS_MANAGER,
407 0x01, (u8 *)&value, 2);
Colin Ian Kinga84bc8c2016-01-01 23:53:45 +0000408 if (ret)
409 goto end;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400410 }
Rich Townsend3f86b832006-07-01 11:36:54 -0400411 }
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400412 ret = acpi_smbus_write(sbs->hc, SMBUS_WRITE_WORD, ACPI_SBS_BATTERY,
413 0x01, (u8 *)&battery->alarm_capacity, 2);
414 end:
415 return ret;
Rich Townsend3f86b832006-07-01 11:36:54 -0400416}
417
418static int acpi_ac_get_present(struct acpi_sbs *sbs)
419{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400420 int result;
421 u16 status;
Rich Townsend3f86b832006-07-01 11:36:54 -0400422
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400423 result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_CHARGER,
424 0x13, (u8 *) & status);
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200425
426 if (result)
427 return result;
428
429 /*
430 * The spec requires that bit 4 always be 1. If it's not set, assume
Ronald Tschalärca1721c52018-09-30 19:52:51 -0700431 * that the implementation doesn't support an SBS charger.
432 *
433 * And on some MacBooks a status of 0xffff is always returned, no
434 * matter whether the charger is plugged in or not, which is also
435 * wrong, so ignore the SBS charger for those too.
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200436 */
Ronald Tschalärca1721c52018-09-30 19:52:51 -0700437 if (!((status >> 4) & 0x1) || status == 0xffff)
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200438 return -ENODEV;
439
440 sbs->charger_present = (status >> 15) & 0x1;
441 return 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400442}
443
Alexey Starikovskiy8bd95532007-09-26 19:44:00 +0400444static ssize_t acpi_battery_alarm_show(struct device *dev,
445 struct device_attribute *attr,
446 char *buf)
447{
448 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
449 acpi_battery_get_alarm(battery);
450 return sprintf(buf, "%d\n", battery->alarm_capacity *
451 acpi_battery_scale(battery) * 1000);
452}
453
454static ssize_t acpi_battery_alarm_store(struct device *dev,
455 struct device_attribute *attr,
456 const char *buf, size_t count)
457{
458 unsigned long x;
459 struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
Luis G.F32a90512014-02-10 11:36:42 +0100460 if (sscanf(buf, "%lu\n", &x) == 1)
Alexey Starikovskiy8bd95532007-09-26 19:44:00 +0400461 battery->alarm_capacity = x /
462 (1000 * acpi_battery_scale(battery));
463 if (battery->present)
464 acpi_battery_set_alarm(battery);
465 return count;
466}
467
Bhumika Goyal82d2b612017-08-21 17:13:07 +0530468static const struct device_attribute alarm_attr = {
Parag Warudkar01e8ef12008-10-18 20:28:50 -0700469 .attr = {.name = "alarm", .mode = 0644},
Alexey Starikovskiy8bd95532007-09-26 19:44:00 +0400470 .show = acpi_battery_alarm_show,
471 .store = acpi_battery_alarm_store,
472};
473
Rich Townsend3f86b832006-07-01 11:36:54 -0400474/* --------------------------------------------------------------------------
Rich Townsend3f86b832006-07-01 11:36:54 -0400475 Driver Interface
476 -------------------------------------------------------------------------- */
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400477static int acpi_battery_read(struct acpi_battery *battery)
478{
479 int result = 0, saved_present = battery->present;
480 u16 state;
481
482 if (battery->sbs->manager_present) {
483 result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
484 ACPI_SBS_MANAGER, 0x01, (u8 *)&state);
485 if (!result)
486 battery->present = state & (1 << battery->id);
487 state &= 0x0fff;
488 state |= 1 << (battery->id + 12);
489 acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD,
490 ACPI_SBS_MANAGER, 0x01, (u8 *)&state, 2);
491 } else if (battery->id == 0)
492 battery->present = 1;
Matthew Garrett9faf6132014-09-20 13:19:46 +0200493
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400494 if (result || !battery->present)
495 return result;
496
497 if (saved_present != battery->present) {
498 battery->update_time = 0;
499 result = acpi_battery_get_info(battery);
Matthew Garrett9faf6132014-09-20 13:19:46 +0200500 if (result) {
501 battery->present = 0;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400502 return result;
Matthew Garrett9faf6132014-09-20 13:19:46 +0200503 }
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400504 }
505 result = acpi_battery_get_state(battery);
Matthew Garrett9faf6132014-09-20 13:19:46 +0200506 if (result)
507 battery->present = 0;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400508 return result;
509}
510
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400511/* Smart Battery */
Rich Townsend3f86b832006-07-01 11:36:54 -0400512static int acpi_battery_add(struct acpi_sbs *sbs, int id)
513{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400514 struct acpi_battery *battery = &sbs->battery[id];
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100515 struct power_supply_config psy_cfg = { .drv_data = battery, };
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400516 int result;
517
Rich Townsend3f86b832006-07-01 11:36:54 -0400518 battery->id = id;
519 battery->sbs = sbs;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400520 result = acpi_battery_read(battery);
521 if (result)
522 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400523
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400524 sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100525 battery->bat_desc.name = battery->name;
526 battery->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400527 if (!acpi_battery_mode(battery)) {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100528 battery->bat_desc.properties = sbs_charge_battery_props;
529 battery->bat_desc.num_properties =
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400530 ARRAY_SIZE(sbs_charge_battery_props);
531 } else {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100532 battery->bat_desc.properties = sbs_energy_battery_props;
533 battery->bat_desc.num_properties =
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400534 ARRAY_SIZE(sbs_energy_battery_props);
535 }
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100536 battery->bat_desc.get_property = acpi_sbs_battery_get_property;
537 battery->bat = power_supply_register(&sbs->device->dev,
538 &battery->bat_desc, &psy_cfg);
539 if (IS_ERR(battery->bat)) {
540 result = PTR_ERR(battery->bat);
541 battery->bat = NULL;
Jeff Garzik037cbc62007-11-18 00:32:31 +0300542 goto end;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100543 }
Matthew Garrett9faf6132014-09-20 13:19:46 +0200544
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100545 result = device_create_file(&battery->bat->dev, &alarm_attr);
Jeff Garzik037cbc62007-11-18 00:32:31 +0300546 if (result)
547 goto end;
548 battery->have_sysfs_alarm = 1;
549 end:
Vladimir Lebedev72206232007-03-19 17:45:50 +0300550 printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n",
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400551 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
Alexey Starikovskiybbafbec2008-02-09 03:22:13 -0500552 battery->name, battery->present ? "present" : "absent");
Len Brown635227e2006-07-01 16:48:23 -0400553 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400554}
555
556static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
557{
Jeff Garzik037cbc62007-11-18 00:32:31 +0300558 struct acpi_battery *battery = &sbs->battery[id];
Rakib Mullickc19bdb62010-01-03 19:27:56 +0600559
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100560 if (battery->bat) {
Jeff Garzik037cbc62007-11-18 00:32:31 +0300561 if (battery->have_sysfs_alarm)
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100562 device_remove_file(&battery->bat->dev, &alarm_attr);
563 power_supply_unregister(battery->bat);
Rich Townsend3f86b832006-07-01 11:36:54 -0400564 }
565}
566
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400567static int acpi_charger_add(struct acpi_sbs *sbs)
Rich Townsend3f86b832006-07-01 11:36:54 -0400568{
569 int result;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100570 struct power_supply_config psy_cfg = { .drv_data = sbs, };
Rich Townsend3f86b832006-07-01 11:36:54 -0400571
Rich Townsend3f86b832006-07-01 11:36:54 -0400572 result = acpi_ac_get_present(sbs);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400573 if (result)
Rich Townsend3f86b832006-07-01 11:36:54 -0400574 goto end;
Lan Tianyu2a68b992013-10-11 09:54:09 +0800575
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200576 sbs->charger_exists = 1;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100577 sbs->charger = power_supply_register(&sbs->device->dev,
578 &acpi_sbs_charger_desc, &psy_cfg);
579 if (IS_ERR(sbs->charger)) {
580 result = PTR_ERR(sbs->charger);
581 sbs->charger = NULL;
582 }
Vladimir Lebedev72206232007-03-19 17:45:50 +0300583 printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n",
584 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
Alexey Starikovskiy89862e32007-09-26 19:43:35 +0400585 ACPI_AC_DIR_NAME, sbs->charger_present ? "on-line" : "off-line");
Rich Townsend3f86b832006-07-01 11:36:54 -0400586 end:
Len Brown635227e2006-07-01 16:48:23 -0400587 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400588}
589
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400590static void acpi_charger_remove(struct acpi_sbs *sbs)
Rich Townsend3f86b832006-07-01 11:36:54 -0400591{
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100592 if (sbs->charger)
593 power_supply_unregister(sbs->charger);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400594}
595
Adrian Bunke5685b92007-10-24 18:24:42 +0200596static void acpi_sbs_callback(void *context)
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400597{
598 int id;
599 struct acpi_sbs *sbs = context;
600 struct acpi_battery *bat;
601 u8 saved_charger_state = sbs->charger_present;
602 u8 saved_battery_state;
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200603
604 if (sbs->charger_exists) {
605 acpi_ac_get_present(sbs);
606 if (sbs->charger_present != saved_charger_state)
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100607 kobject_uevent(&sbs->charger->dev.kobj, KOBJ_CHANGE);
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200608 }
Thomas Renninger1696d9d2013-07-15 10:15:09 +0200609
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400610 if (sbs->manager_present) {
611 for (id = 0; id < MAX_SBS_BAT; ++id) {
612 if (!(sbs->batteries_supported & (1 << id)))
613 continue;
614 bat = &sbs->battery[id];
615 saved_battery_state = bat->present;
616 acpi_battery_read(bat);
617 if (saved_battery_state == bat->present)
618 continue;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100619 kobject_uevent(&bat->bat->dev.kobj, KOBJ_CHANGE);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400620 }
Rich Townsend3f86b832006-07-01 11:36:54 -0400621 }
622}
623
Rich Townsend3f86b832006-07-01 11:36:54 -0400624static int acpi_sbs_add(struct acpi_device *device)
625{
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400626 struct acpi_sbs *sbs;
627 int result = 0;
Vladimir Lebedev6d157022007-03-19 17:45:50 +0300628 int id;
Rich Townsend3f86b832006-07-01 11:36:54 -0400629
Burman Yan36bcbec2006-12-19 12:56:11 -0800630 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
Rich Townsend3f86b832006-07-01 11:36:54 -0400631 if (!sbs) {
Vladimir Lebedev72206232007-03-19 17:45:50 +0300632 result = -ENOMEM;
633 goto end;
Rich Townsend3f86b832006-07-01 11:36:54 -0400634 }
Rich Townsend3f86b832006-07-01 11:36:54 -0400635
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400636 mutex_init(&sbs->lock);
Vladimir Lebedev72206232007-03-19 17:45:50 +0300637
Alexey Starikovskiy91087df2007-09-26 19:43:28 +0400638 sbs->hc = acpi_driver_data(device->parent);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400639 sbs->device = device;
Rich Townsend3f86b832006-07-01 11:36:54 -0400640 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
641 strcpy(acpi_device_class(device), ACPI_SBS_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700642 device->driver_data = sbs;
Rich Townsend3f86b832006-07-01 11:36:54 -0400643
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400644 result = acpi_charger_add(sbs);
Matthew Garrett3031cdd2014-09-20 13:19:45 +0200645 if (result && result != -ENODEV)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300646 goto end;
Rich Townsend3f86b832006-07-01 11:36:54 -0400647
Matthew Garrett9faf6132014-09-20 13:19:46 +0200648 result = 0;
649
Lukas Wunner630b3af2017-08-01 14:10:41 +0200650 if (!x86_apple_machine) {
Matthew Garrett9faf6132014-09-20 13:19:46 +0200651 result = acpi_manager_get_info(sbs);
652 if (!result) {
Chris Bainbridge61f8ff62015-04-22 16:40:21 +0100653 sbs->manager_present = 1;
Matthew Garrett9faf6132014-09-20 13:19:46 +0200654 for (id = 0; id < MAX_SBS_BAT; ++id)
655 if ((sbs->batteries_supported & (1 << id)))
656 acpi_battery_add(sbs, id);
657 }
658 }
659
660 if (!sbs->manager_present)
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400661 acpi_battery_add(sbs, 0);
Matthew Garrett9faf6132014-09-20 13:19:46 +0200662
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400663 acpi_smbus_register_callback(sbs->hc, acpi_sbs_callback, sbs);
Rich Townsend3f86b832006-07-01 11:36:54 -0400664 end:
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400665 if (result)
Rafael J. Wysocki51fac832013-01-24 00:24:48 +0100666 acpi_sbs_remove(device);
Len Brown635227e2006-07-01 16:48:23 -0400667 return result;
Rich Townsend3f86b832006-07-01 11:36:54 -0400668}
669
Rafael J. Wysocki51fac832013-01-24 00:24:48 +0100670static int acpi_sbs_remove(struct acpi_device *device)
Rich Townsend3f86b832006-07-01 11:36:54 -0400671{
Len Browncece9012006-12-16 01:04:27 -0500672 struct acpi_sbs *sbs;
Rich Townsend3f86b832006-07-01 11:36:54 -0400673 int id;
674
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400675 if (!device)
Lebedev, Vladimir P963497c2006-09-05 19:49:13 +0400676 return -EINVAL;
Vladimir Lebedev72206232007-03-19 17:45:50 +0300677 sbs = acpi_driver_data(device);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400678 if (!sbs)
Len Brown635227e2006-07-01 16:48:23 -0400679 return -EINVAL;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400680 mutex_lock(&sbs->lock);
681 acpi_smbus_unregister_callback(sbs->hc);
682 for (id = 0; id < MAX_SBS_BAT; ++id)
Rich Townsend3f86b832006-07-01 11:36:54 -0400683 acpi_battery_remove(sbs, id);
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400684 acpi_charger_remove(sbs);
685 mutex_unlock(&sbs->lock);
686 mutex_destroy(&sbs->lock);
Rich Townsend3f86b832006-07-01 11:36:54 -0400687 kfree(sbs);
Len Brown635227e2006-07-01 16:48:23 -0400688 return 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400689}
690
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200691#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200692static int acpi_sbs_resume(struct device *dev)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300693{
694 struct acpi_sbs *sbs;
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200695 if (!dev)
Vladimir Lebedev72206232007-03-19 17:45:50 +0300696 return -EINVAL;
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200697 sbs = to_acpi_device(dev)->driver_data;
Alexey Starikovskiydb1c2912007-09-26 19:43:41 +0400698 acpi_sbs_callback(sbs);
Vladimir Lebedev72206232007-03-19 17:45:50 +0300699 return 0;
700}
Shuah Khan15029dd2014-02-12 20:19:09 -0700701#else
702#define acpi_sbs_resume NULL
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200703#endif
Vladimir Lebedev72206232007-03-19 17:45:50 +0300704
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200705static SIMPLE_DEV_PM_OPS(acpi_sbs_pm, NULL, acpi_sbs_resume);
706
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400707static struct acpi_driver acpi_sbs_driver = {
708 .name = "sbs",
709 .class = ACPI_SBS_CLASS,
710 .ids = sbs_device_ids,
711 .ops = {
712 .add = acpi_sbs_add,
713 .remove = acpi_sbs_remove,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400714 },
Rafael J. Wysockid202f772012-06-27 23:27:07 +0200715 .drv.pm = &acpi_sbs_pm,
Alexey Starikovskiy94f6c082007-09-26 19:43:48 +0400716};
717
Rich Townsend3f86b832006-07-01 11:36:54 -0400718static int __init acpi_sbs_init(void)
719{
720 int result = 0;
721
Len Brownb20d2ae2006-08-15 23:21:37 -0400722 if (acpi_disabled)
723 return -ENODEV;
Lan Tianyu2a68b992013-10-11 09:54:09 +0800724
Rich Townsend3f86b832006-07-01 11:36:54 -0400725 result = acpi_bus_register_driver(&acpi_sbs_driver);
Lan Tianyu2a68b992013-10-11 09:54:09 +0800726 if (result < 0)
Len Brown635227e2006-07-01 16:48:23 -0400727 return -ENODEV;
Lan Tianyu2a68b992013-10-11 09:54:09 +0800728
Len Brown635227e2006-07-01 16:48:23 -0400729 return 0;
Rich Townsend3f86b832006-07-01 11:36:54 -0400730}
731
732static void __exit acpi_sbs_exit(void)
733{
Rich Townsend3f86b832006-07-01 11:36:54 -0400734 acpi_bus_unregister_driver(&acpi_sbs_driver);
Len Brown635227e2006-07-01 16:48:23 -0400735 return;
Rich Townsend3f86b832006-07-01 11:36:54 -0400736}
737
738module_init(acpi_sbs_init);
739module_exit(acpi_sbs_exit);