aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/sbs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/sbs.c')
-rw-r--r--drivers/acpi/sbs.c1291
1 files changed, 680 insertions, 611 deletions
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 59640d9a0acc..c1bae106833c 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -30,30 +30,10 @@
30#include <linux/seq_file.h> 30#include <linux/seq_file.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32#include <linux/acpi.h> 32#include <linux/acpi.h>
33#include <linux/i2c.h> 33#include <linux/timer.h>
34#include <linux/jiffies.h>
34#include <linux/delay.h> 35#include <linux/delay.h>
35 36
36#include "i2c_ec.h"
37
38#define DEF_CAPACITY_UNIT 3
39#define MAH_CAPACITY_UNIT 1
40#define MWH_CAPACITY_UNIT 2
41#define CAPACITY_UNIT DEF_CAPACITY_UNIT
42
43#define REQUEST_UPDATE_MODE 1
44#define QUEUE_UPDATE_MODE 2
45
46#define DATA_TYPE_COMMON 0
47#define DATA_TYPE_INFO 1
48#define DATA_TYPE_STATE 2
49#define DATA_TYPE_ALARM 3
50#define DATA_TYPE_AC_STATE 4
51
52extern struct proc_dir_entry *acpi_lock_ac_dir(void);
53extern struct proc_dir_entry *acpi_lock_battery_dir(void);
54extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
55extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
56
57#define ACPI_SBS_COMPONENT 0x00080000 37#define ACPI_SBS_COMPONENT 0x00080000
58#define ACPI_SBS_CLASS "sbs" 38#define ACPI_SBS_CLASS "sbs"
59#define ACPI_AC_CLASS "ac_adapter" 39#define ACPI_AC_CLASS "ac_adapter"
@@ -74,39 +54,75 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
74 54
75#define _COMPONENT ACPI_SBS_COMPONENT 55#define _COMPONENT ACPI_SBS_COMPONENT
76 56
77#define MAX_SBS_BAT 4
78#define MAX_SMBUS_ERR 1
79
80ACPI_MODULE_NAME("sbs"); 57ACPI_MODULE_NAME("sbs");
81 58
82MODULE_AUTHOR("Rich Townsend"); 59MODULE_AUTHOR("Rich Townsend");
83MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); 60MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
84MODULE_LICENSE("GPL"); 61MODULE_LICENSE("GPL");
85 62
86static struct semaphore sbs_sem; 63#define xmsleep(t) msleep(t)
64
65#define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */
66
67#define ACPI_EC_SMB_STS 0x01 /* status */
68#define ACPI_EC_SMB_ADDR 0x02 /* address */
69#define ACPI_EC_SMB_CMD 0x03 /* command */
70#define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */
71#define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */
87 72
88#define UPDATE_MODE QUEUE_UPDATE_MODE 73#define ACPI_EC_SMB_STS_DONE 0x80
89/* REQUEST_UPDATE_MODE QUEUE_UPDATE_MODE */ 74#define ACPI_EC_SMB_STS_STATUS 0x1f
90#define UPDATE_INFO_MODE 0
91#define UPDATE_TIME 60
92#define UPDATE_TIME2 0
93 75
94static int capacity_mode = CAPACITY_UNIT; 76#define ACPI_EC_SMB_PRTCL_WRITE 0x00
95static int update_mode = UPDATE_MODE; 77#define ACPI_EC_SMB_PRTCL_READ 0x01
96static int update_info_mode = UPDATE_INFO_MODE; 78#define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08
97static int update_time = UPDATE_TIME; 79#define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a
98static int update_time2 = UPDATE_TIME2;
99 80
100module_param(capacity_mode, int, 0); 81#define ACPI_EC_SMB_TRANSACTION_SLEEP 1
101module_param(update_mode, int, 0); 82#define ACPI_EC_SMB_ACCESS_SLEEP1 1
102module_param(update_info_mode, int, 0); 83#define ACPI_EC_SMB_ACCESS_SLEEP2 10
103module_param(update_time, int, 0); 84
104module_param(update_time2, int, 0); 85#define DEF_CAPACITY_UNIT 3
86#define MAH_CAPACITY_UNIT 1
87#define MWH_CAPACITY_UNIT 2
88#define CAPACITY_UNIT DEF_CAPACITY_UNIT
89
90#define REQUEST_UPDATE_MODE 1
91#define QUEUE_UPDATE_MODE 2
92
93#define DATA_TYPE_COMMON 0
94#define DATA_TYPE_INFO 1
95#define DATA_TYPE_STATE 2
96#define DATA_TYPE_ALARM 3
97#define DATA_TYPE_AC_STATE 4
98
99extern struct proc_dir_entry *acpi_lock_ac_dir(void);
100extern struct proc_dir_entry *acpi_lock_battery_dir(void);
101extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
102extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
103
104#define MAX_SBS_BAT 4
105#define ACPI_SBS_BLOCK_MAX 32
106
107#define ACPI_SBS_SMBUS_READ 1
108#define ACPI_SBS_SMBUS_WRITE 2
109
110#define ACPI_SBS_WORD_DATA 1
111#define ACPI_SBS_BLOCK_DATA 2
112
113#define UPDATE_DELAY 10
114
115/* 0 - every time, > 0 - by update_time */
116static unsigned int update_time = 120;
117
118static unsigned int capacity_mode = CAPACITY_UNIT;
119
120module_param(update_time, uint, 0644);
121module_param(capacity_mode, uint, 0444);
105 122
106static int acpi_sbs_add(struct acpi_device *device); 123static int acpi_sbs_add(struct acpi_device *device);
107static int acpi_sbs_remove(struct acpi_device *device, int type); 124static int acpi_sbs_remove(struct acpi_device *device, int type);
108static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus); 125static int acpi_sbs_resume(struct acpi_device *device);
109static void acpi_sbs_update_queue(void *data);
110 126
111static struct acpi_driver acpi_sbs_driver = { 127static struct acpi_driver acpi_sbs_driver = {
112 .name = "sbs", 128 .name = "sbs",
@@ -115,9 +131,14 @@ static struct acpi_driver acpi_sbs_driver = {
115 .ops = { 131 .ops = {
116 .add = acpi_sbs_add, 132 .add = acpi_sbs_add,
117 .remove = acpi_sbs_remove, 133 .remove = acpi_sbs_remove,
134 .resume = acpi_sbs_resume,
118 }, 135 },
119}; 136};
120 137
138struct acpi_ac {
139 int ac_present;
140};
141
121struct acpi_battery_info { 142struct acpi_battery_info {
122 int capacity_mode; 143 int capacity_mode;
123 s16 full_charge_capacity; 144 s16 full_charge_capacity;
@@ -126,18 +147,16 @@ struct acpi_battery_info {
126 int vscale; 147 int vscale;
127 int ipscale; 148 int ipscale;
128 s16 serial_number; 149 s16 serial_number;
129 char manufacturer_name[I2C_SMBUS_BLOCK_MAX + 3]; 150 char manufacturer_name[ACPI_SBS_BLOCK_MAX + 3];
130 char device_name[I2C_SMBUS_BLOCK_MAX + 3]; 151 char device_name[ACPI_SBS_BLOCK_MAX + 3];
131 char device_chemistry[I2C_SMBUS_BLOCK_MAX + 3]; 152 char device_chemistry[ACPI_SBS_BLOCK_MAX + 3];
132}; 153};
133 154
134struct acpi_battery_state { 155struct acpi_battery_state {
135 s16 voltage; 156 s16 voltage;
136 s16 amperage; 157 s16 amperage;
137 s16 remaining_capacity; 158 s16 remaining_capacity;
138 s16 average_time_to_empty; 159 s16 battery_state;
139 s16 average_time_to_full;
140 s16 battery_status;
141}; 160};
142 161
143struct acpi_battery_alarm { 162struct acpi_battery_alarm {
@@ -146,9 +165,9 @@ struct acpi_battery_alarm {
146 165
147struct acpi_battery { 166struct acpi_battery {
148 int alive; 167 int alive;
149 int battery_present;
150 int id; 168 int id;
151 int init_state; 169 int init_state;
170 int battery_present;
152 struct acpi_sbs *sbs; 171 struct acpi_sbs *sbs;
153 struct acpi_battery_info info; 172 struct acpi_battery_info info;
154 struct acpi_battery_state state; 173 struct acpi_battery_state state;
@@ -158,186 +177,251 @@ struct acpi_battery {
158 177
159struct acpi_sbs { 178struct acpi_sbs {
160 acpi_handle handle; 179 acpi_handle handle;
180 int base;
161 struct acpi_device *device; 181 struct acpi_device *device;
162 struct acpi_ec_smbus *smbus; 182 struct acpi_ec_smbus *smbus;
183 struct mutex mutex;
163 int sbsm_present; 184 int sbsm_present;
164 int sbsm_batteries_supported; 185 int sbsm_batteries_supported;
165 int ac_present;
166 struct proc_dir_entry *ac_entry; 186 struct proc_dir_entry *ac_entry;
187 struct acpi_ac ac;
167 struct acpi_battery battery[MAX_SBS_BAT]; 188 struct acpi_battery battery[MAX_SBS_BAT];
168 int update_info_mode;
169 int zombie; 189 int zombie;
170 int update_time;
171 int update_time2;
172 struct timer_list update_timer; 190 struct timer_list update_timer;
191 int run_cnt;
192 int update_proc_flg;
173}; 193};
174 194
175static void acpi_update_delay(struct acpi_sbs *sbs); 195static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type);
176static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type); 196static void acpi_sbs_update_time(void *data);
197
198union sbs_rw_data {
199 u16 word;
200 u8 block[ACPI_SBS_BLOCK_MAX + 2];
201};
202
203static int acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr,
204 char read_write, u8 command, int size,
205 union sbs_rw_data *data);
177 206
178/* -------------------------------------------------------------------------- 207/* --------------------------------------------------------------------------
179 SMBus Communication 208 SMBus Communication
180 -------------------------------------------------------------------------- */ 209 -------------------------------------------------------------------------- */
181 210
182static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus) 211static int acpi_ec_sbs_read(struct acpi_sbs *sbs, u8 address, u8 * data)
183{ 212{
184 union i2c_smbus_data data; 213 u8 val;
185 int result = 0; 214 int err;
186 char *err_str;
187 int err_number;
188 215
189 data.word = 0; 216 err = ec_read(sbs->base + address, &val);
217 if (!err) {
218 *data = val;
219 }
220 xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP);
221 return (err);
222}
190 223
191 result = smbus->adapter.algo-> 224static int acpi_ec_sbs_write(struct acpi_sbs *sbs, u8 address, u8 data)
192 smbus_xfer(&smbus->adapter, 225{
193 ACPI_SB_SMBUS_ADDR, 226 int err;
194 0, I2C_SMBUS_READ, 0x16, I2C_SMBUS_BLOCK_DATA, &data);
195 227
196 err_number = (data.word & 0x000f); 228 err = ec_write(sbs->base + address, data);
229 return (err);
230}
197 231
198 switch (data.word & 0x000f) { 232static int
199 case 0x0000: 233acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr,
200 err_str = "unexpected bus error"; 234 char read_write, u8 command, int size,
201 break; 235 union sbs_rw_data *data)
202 case 0x0001: 236{
203 err_str = "busy"; 237 unsigned char protocol, len = 0, temp[2] = { 0, 0 };
204 break; 238 int i;
205 case 0x0002: 239
206 err_str = "reserved command"; 240 if (read_write == ACPI_SBS_SMBUS_READ) {
207 break; 241 protocol = ACPI_EC_SMB_PRTCL_READ;
208 case 0x0003: 242 } else {
209 err_str = "unsupported command"; 243 protocol = ACPI_EC_SMB_PRTCL_WRITE;
210 break; 244 }
211 case 0x0004: 245
212 err_str = "access denied"; 246 switch (size) {
247
248 case ACPI_SBS_WORD_DATA:
249 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command);
250 if (read_write == ACPI_SBS_SMBUS_WRITE) {
251 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA, data->word);
252 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + 1,
253 data->word >> 8);
254 }
255 protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA;
213 break; 256 break;
214 case 0x0005: 257 case ACPI_SBS_BLOCK_DATA:
215 err_str = "overflow/underflow"; 258 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command);
259 if (read_write == ACPI_SBS_SMBUS_WRITE) {
260 len = min_t(u8, data->block[0], 32);
261 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_BCNT, len);
262 for (i = 0; i < len; i++)
263 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + i,
264 data->block[i + 1]);
265 }
266 protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA;
216 break; 267 break;
217 case 0x0006: 268 default:
218 err_str = "bad size"; 269 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
270 "unsupported transaction %d", size));
271 return (-1);
272 }
273
274 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_ADDR, addr << 1);
275 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_PRTCL, protocol);
276
277 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp);
278
279 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
280 xmsleep(ACPI_EC_SMB_ACCESS_SLEEP1);
281 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp);
282 }
283 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
284 xmsleep(ACPI_EC_SMB_ACCESS_SLEEP2);
285 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp);
286 }
287 if ((~temp[0] & ACPI_EC_SMB_STS_DONE)
288 || (temp[0] & ACPI_EC_SMB_STS_STATUS)) {
289 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
290 "transaction %d error", size));
291 return (-1);
292 }
293
294 if (read_write == ACPI_SBS_SMBUS_WRITE) {
295 return (0);
296 }
297
298 switch (size) {
299
300 case ACPI_SBS_WORD_DATA:
301 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA, temp);
302 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + 1, temp + 1);
303 data->word = (temp[1] << 8) | temp[0];
219 break; 304 break;
220 case 0x0007: 305
221 err_str = "unknown error"; 306 case ACPI_SBS_BLOCK_DATA:
307 len = 0;
308 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_BCNT, &len);
309 len = min_t(u8, len, 32);
310 for (i = 0; i < len; i++)
311 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + i,
312 data->block + i + 1);
313 data->block[0] = len;
222 break; 314 break;
223 default: 315 default:
224 err_str = "unrecognized error"; 316 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
317 "unsupported transaction %d", size));
318 return (-1);
225 } 319 }
226 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 320
227 "%s: ret %i, err %i\n", err_str, result, err_number)); 321 return (0);
228} 322}
229 323
230static int 324static int
231acpi_sbs_smbus_read_word(struct acpi_ec_smbus *smbus, int addr, int func, 325acpi_sbs_read_word(struct acpi_sbs *sbs, int addr, int func, u16 * word)
232 u16 * word,
233 void (*err_handler) (struct acpi_ec_smbus * smbus))
234{ 326{
235 union i2c_smbus_data data; 327 union sbs_rw_data data;
236 int result = 0; 328 int result = 0;
237 int i;
238 329
239 if (err_handler == NULL) { 330 result = acpi_ec_sbs_access(sbs, addr,
240 err_handler = acpi_battery_smbus_err_handler; 331 ACPI_SBS_SMBUS_READ, func,
241 } 332 ACPI_SBS_WORD_DATA, &data);
242 333 if (result) {
243 for (i = 0; i < MAX_SMBUS_ERR; i++) { 334 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
244 result = 335 "acpi_ec_sbs_access() failed"));
245 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, 336 } else {
246 I2C_SMBUS_READ, func, 337 *word = data.word;
247 I2C_SMBUS_WORD_DATA, &data);
248 if (result) {
249 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
250 "try %i: smbus->adapter.algo->smbus_xfer() failed\n",
251 i));
252 if (err_handler) {
253 err_handler(smbus);
254 }
255 } else {
256 *word = data.word;
257 break;
258 }
259 } 338 }
260 339
261 return result; 340 return result;
262} 341}
263 342
264static int 343static int
265acpi_sbs_smbus_read_str(struct acpi_ec_smbus *smbus, int addr, int func, 344acpi_sbs_read_str(struct acpi_sbs *sbs, int addr, int func, char *str)
266 char *str,
267 void (*err_handler) (struct acpi_ec_smbus * smbus))
268{ 345{
269 union i2c_smbus_data data; 346 union sbs_rw_data data;
270 int result = 0; 347 int result = 0;
271 int i;
272
273 if (err_handler == NULL) {
274 err_handler = acpi_battery_smbus_err_handler;
275 }
276 348
277 for (i = 0; i < MAX_SMBUS_ERR; i++) { 349 result = acpi_ec_sbs_access(sbs, addr,
278 result = 350 ACPI_SBS_SMBUS_READ, func,
279 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, 351 ACPI_SBS_BLOCK_DATA, &data);
280 I2C_SMBUS_READ, func, 352 if (result) {
281 I2C_SMBUS_BLOCK_DATA, 353 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
282 &data); 354 "acpi_ec_sbs_access() failed"));
283 if (result) { 355 } else {
284 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 356 strncpy(str, (const char *)data.block + 1, data.block[0]);
285 "try %i: smbus->adapter.algo->smbus_xfer() failed\n", 357 str[data.block[0]] = 0;
286 i));
287 if (err_handler) {
288 err_handler(smbus);
289 }
290 } else {
291 strncpy(str, (const char *)data.block + 1,
292 data.block[0]);
293 str[data.block[0]] = 0;
294 break;
295 }
296 } 358 }
297 359
298 return result; 360 return result;
299} 361}
300 362
301static int 363static int
302acpi_sbs_smbus_write_word(struct acpi_ec_smbus *smbus, int addr, int func, 364acpi_sbs_write_word(struct acpi_sbs *sbs, int addr, int func, int word)
303 int word,
304 void (*err_handler) (struct acpi_ec_smbus * smbus))
305{ 365{
306 union i2c_smbus_data data; 366 union sbs_rw_data data;
307 int result = 0; 367 int result = 0;
308 int i;
309
310 if (err_handler == NULL) {
311 err_handler = acpi_battery_smbus_err_handler;
312 }
313 368
314 data.word = word; 369 data.word = word;
315 370
316 for (i = 0; i < MAX_SMBUS_ERR; i++) { 371 result = acpi_ec_sbs_access(sbs, addr,
317 result = 372 ACPI_SBS_SMBUS_WRITE, func,
318 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, 373 ACPI_SBS_WORD_DATA, &data);
319 I2C_SMBUS_WRITE, func, 374 if (result) {
320 I2C_SMBUS_WORD_DATA, &data); 375 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
321 if (result) { 376 "acpi_ec_sbs_access() failed"));
322 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
323 "try %i: smbus->adapter.algo"
324 "->smbus_xfer() failed\n", i));
325 if (err_handler) {
326 err_handler(smbus);
327 }
328 } else {
329 break;
330 }
331 } 377 }
332 378
333 return result; 379 return result;
334} 380}
335 381
382static int sbs_zombie(struct acpi_sbs *sbs)
383{
384 return (sbs->zombie);
385}
386
387static int sbs_mutex_lock(struct acpi_sbs *sbs)
388{
389 if (sbs_zombie(sbs)) {
390 return -ENODEV;
391 }
392 mutex_lock(&sbs->mutex);
393 return 0;
394}
395
396static void sbs_mutex_unlock(struct acpi_sbs *sbs)
397{
398 mutex_unlock(&sbs->mutex);
399}
400
336/* -------------------------------------------------------------------------- 401/* --------------------------------------------------------------------------
337 Smart Battery System Management 402 Smart Battery System Management
338 -------------------------------------------------------------------------- */ 403 -------------------------------------------------------------------------- */
339 404
340/* Smart Battery */ 405static int acpi_check_update_proc(struct acpi_sbs *sbs)
406{
407 acpi_status status = AE_OK;
408
409 if (update_time == 0) {
410 sbs->update_proc_flg = 0;
411 return 0;
412 }
413 if (sbs->update_proc_flg == 0) {
414 status = acpi_os_execute(OSL_GPE_HANDLER,
415 acpi_sbs_update_time, sbs);
416 if (status != AE_OK) {
417 ACPI_EXCEPTION((AE_INFO, status,
418 "acpi_os_execute() failed"));
419 return 1;
420 }
421 sbs->update_proc_flg = 1;
422 }
423 return 0;
424}
341 425
342static int acpi_sbs_generate_event(struct acpi_device *device, 426static int acpi_sbs_generate_event(struct acpi_device *device,
343 int event, int state, char *bid, char *class) 427 int event, int state, char *bid, char *class)
@@ -366,12 +450,11 @@ static int acpi_battery_get_present(struct acpi_battery *battery)
366 int result = 0; 450 int result = 0;
367 int is_present = 0; 451 int is_present = 0;
368 452
369 result = acpi_sbs_smbus_read_word(battery->sbs->smbus, 453 result = acpi_sbs_read_word(battery->sbs,
370 ACPI_SBSM_SMBUS_ADDR, 0x01, 454 ACPI_SBSM_SMBUS_ADDR, 0x01, &state);
371 &state, NULL);
372 if (result) { 455 if (result) {
373 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 456 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
374 "acpi_sbs_smbus_read_word() failed")); 457 "acpi_sbs_read_word() failed"));
375 } 458 }
376 if (!result) { 459 if (!result) {
377 is_present = (state & 0x000f) & (1 << battery->id); 460 is_present = (state & 0x000f) & (1 << battery->id);
@@ -381,45 +464,33 @@ static int acpi_battery_get_present(struct acpi_battery *battery)
381 return result; 464 return result;
382} 465}
383 466
384static int acpi_battery_is_present(struct acpi_battery *battery)
385{
386 return (battery->battery_present);
387}
388
389static int acpi_ac_is_present(struct acpi_sbs *sbs)
390{
391 return (sbs->ac_present);
392}
393
394static int acpi_battery_select(struct acpi_battery *battery) 467static int acpi_battery_select(struct acpi_battery *battery)
395{ 468{
396 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 469 struct acpi_sbs *sbs = battery->sbs;
397 int result = 0; 470 int result = 0;
398 s16 state; 471 s16 state;
399 int foo; 472 int foo;
400 473
401 if (battery->sbs->sbsm_present) { 474 if (sbs->sbsm_present) {
402 475
403 /* Take special care not to knobble other nibbles of 476 /* Take special care not to knobble other nibbles of
404 * state (aka selector_state), since 477 * state (aka selector_state), since
405 * it causes charging to halt on SBSELs */ 478 * it causes charging to halt on SBSELs */
406 479
407 result = 480 result =
408 acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01, 481 acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, &state);
409 &state, NULL);
410 if (result) { 482 if (result) {
411 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 483 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
412 "acpi_sbs_smbus_read_word() failed\n")); 484 "acpi_sbs_read_word() failed"));
413 goto end; 485 goto end;
414 } 486 }
415 487
416 foo = (state & 0x0fff) | (1 << (battery->id + 12)); 488 foo = (state & 0x0fff) | (1 << (battery->id + 12));
417 result = 489 result =
418 acpi_sbs_smbus_write_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01, 490 acpi_sbs_write_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, foo);
419 foo, NULL);
420 if (result) { 491 if (result) {
421 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 492 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
422 "acpi_sbs_smbus_write_word() failed\n")); 493 "acpi_sbs_write_word() failed"));
423 goto end; 494 goto end;
424 } 495 }
425 } 496 }
@@ -430,15 +501,14 @@ static int acpi_battery_select(struct acpi_battery *battery)
430 501
431static int acpi_sbsm_get_info(struct acpi_sbs *sbs) 502static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
432{ 503{
433 struct acpi_ec_smbus *smbus = sbs->smbus;
434 int result = 0; 504 int result = 0;
435 s16 battery_system_info; 505 s16 battery_system_info;
436 506
437 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x04, 507 result = acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x04,
438 &battery_system_info, NULL); 508 &battery_system_info);
439 if (result) { 509 if (result) {
440 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 510 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
441 "acpi_sbs_smbus_read_word() failed\n")); 511 "acpi_sbs_read_word() failed"));
442 goto end; 512 goto end;
443 } 513 }
444 514
@@ -451,53 +521,50 @@ static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
451 521
452static int acpi_battery_get_info(struct acpi_battery *battery) 522static int acpi_battery_get_info(struct acpi_battery *battery)
453{ 523{
454 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 524 struct acpi_sbs *sbs = battery->sbs;
455 int result = 0; 525 int result = 0;
456 s16 battery_mode; 526 s16 battery_mode;
457 s16 specification_info; 527 s16 specification_info;
458 528
459 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03, 529 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03,
460 &battery_mode, 530 &battery_mode);
461 &acpi_battery_smbus_err_handler);
462 if (result) { 531 if (result) {
463 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 532 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
464 "acpi_sbs_smbus_read_word() failed\n")); 533 "acpi_sbs_read_word() failed"));
465 goto end; 534 goto end;
466 } 535 }
467 battery->info.capacity_mode = (battery_mode & 0x8000) >> 15; 536 battery->info.capacity_mode = (battery_mode & 0x8000) >> 15;
468 537
469 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x10, 538 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x10,
470 &battery->info.full_charge_capacity, 539 &battery->info.full_charge_capacity);
471 &acpi_battery_smbus_err_handler);
472 if (result) { 540 if (result) {
473 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 541 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
474 "acpi_sbs_smbus_read_word() failed\n")); 542 "acpi_sbs_read_word() failed"));
475 goto end; 543 goto end;
476 } 544 }
477 545
478 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x18, 546 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x18,
479 &battery->info.design_capacity, 547 &battery->info.design_capacity);
480 &acpi_battery_smbus_err_handler);
481 548
482 if (result) { 549 if (result) {
550 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
551 "acpi_sbs_read_word() failed"));
483 goto end; 552 goto end;
484 } 553 }
485 554
486 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x19, 555 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x19,
487 &battery->info.design_voltage, 556 &battery->info.design_voltage);
488 &acpi_battery_smbus_err_handler);
489 if (result) { 557 if (result) {
490 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 558 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
491 "acpi_sbs_smbus_read_word() failed\n")); 559 "acpi_sbs_read_word() failed"));
492 goto end; 560 goto end;
493 } 561 }
494 562
495 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1a, 563 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1a,
496 &specification_info, 564 &specification_info);
497 &acpi_battery_smbus_err_handler);
498 if (result) { 565 if (result) {
499 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 566 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
500 "acpi_sbs_smbus_read_word() failed\n")); 567 "acpi_sbs_read_word() failed"));
501 goto end; 568 goto end;
502 } 569 }
503 570
@@ -529,37 +596,35 @@ static int acpi_battery_get_info(struct acpi_battery *battery)
529 battery->info.ipscale = 1; 596 battery->info.ipscale = 1;
530 } 597 }
531 598
532 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1c, 599 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1c,
533 &battery->info.serial_number, 600 &battery->info.serial_number);
534 &acpi_battery_smbus_err_handler);
535 if (result) { 601 if (result) {
602 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
603 "acpi_sbs_read_word() failed"));
536 goto end; 604 goto end;
537 } 605 }
538 606
539 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x20, 607 result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x20,
540 battery->info.manufacturer_name, 608 battery->info.manufacturer_name);
541 &acpi_battery_smbus_err_handler);
542 if (result) { 609 if (result) {
543 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 610 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
544 "acpi_sbs_smbus_read_str() failed\n")); 611 "acpi_sbs_read_str() failed"));
545 goto end; 612 goto end;
546 } 613 }
547 614
548 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x21, 615 result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x21,
549 battery->info.device_name, 616 battery->info.device_name);
550 &acpi_battery_smbus_err_handler);
551 if (result) { 617 if (result) {
552 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 618 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
553 "acpi_sbs_smbus_read_str() failed\n")); 619 "acpi_sbs_read_str() failed"));
554 goto end; 620 goto end;
555 } 621 }
556 622
557 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x22, 623 result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x22,
558 battery->info.device_chemistry, 624 battery->info.device_chemistry);
559 &acpi_battery_smbus_err_handler);
560 if (result) { 625 if (result) {
561 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 626 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
562 "acpi_sbs_smbus_read_str() failed\n")); 627 "acpi_sbs_read_str() failed"));
563 goto end; 628 goto end;
564 } 629 }
565 630
@@ -567,103 +632,60 @@ static int acpi_battery_get_info(struct acpi_battery *battery)
567 return result; 632 return result;
568} 633}
569 634
570static void acpi_update_delay(struct acpi_sbs *sbs)
571{
572 if (sbs->zombie) {
573 return;
574 }
575 if (sbs->update_time2 > 0) {
576 msleep(sbs->update_time2 * 1000);
577 }
578}
579
580static int acpi_battery_get_state(struct acpi_battery *battery) 635static int acpi_battery_get_state(struct acpi_battery *battery)
581{ 636{
582 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 637 struct acpi_sbs *sbs = battery->sbs;
583 int result = 0; 638 int result = 0;
584 639
585 acpi_update_delay(battery->sbs); 640 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x09,
586 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x09, 641 &battery->state.voltage);
587 &battery->state.voltage,
588 &acpi_battery_smbus_err_handler);
589 if (result) { 642 if (result) {
590 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 643 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
591 "acpi_sbs_smbus_read_word() failed\n")); 644 "acpi_sbs_read_word() failed"));
592 goto end; 645 goto end;
593 } 646 }
594 647
595 acpi_update_delay(battery->sbs); 648 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0a,
596 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0a, 649 &battery->state.amperage);
597 &battery->state.amperage,
598 &acpi_battery_smbus_err_handler);
599 if (result) { 650 if (result) {
600 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 651 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
601 "acpi_sbs_smbus_read_word() failed\n")); 652 "acpi_sbs_read_word() failed"));
602 goto end; 653 goto end;
603 } 654 }
604 655
605 acpi_update_delay(battery->sbs); 656 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0f,
606 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0f, 657 &battery->state.remaining_capacity);
607 &battery->state.remaining_capacity,
608 &acpi_battery_smbus_err_handler);
609 if (result) { 658 if (result) {
610 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 659 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
611 "acpi_sbs_smbus_read_word() failed\n")); 660 "acpi_sbs_read_word() failed"));
612 goto end; 661 goto end;
613 } 662 }
614 663
615 acpi_update_delay(battery->sbs); 664 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x16,
616 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x12, 665 &battery->state.battery_state);
617 &battery->state.average_time_to_empty,
618 &acpi_battery_smbus_err_handler);
619 if (result) { 666 if (result) {
620 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 667 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
621 "acpi_sbs_smbus_read_word() failed\n")); 668 "acpi_sbs_read_word() failed"));
622 goto end; 669 goto end;
623 } 670 }
624 671
625 acpi_update_delay(battery->sbs);
626 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x13,
627 &battery->state.average_time_to_full,
628 &acpi_battery_smbus_err_handler);
629 if (result) {
630 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
631 "acpi_sbs_smbus_read_word() failed\n"));
632 goto end;
633 }
634
635 acpi_update_delay(battery->sbs);
636 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x16,
637 &battery->state.battery_status,
638 &acpi_battery_smbus_err_handler);
639 if (result) {
640 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
641 "acpi_sbs_smbus_read_word() failed\n"));
642 goto end;
643 }
644
645 acpi_update_delay(battery->sbs);
646
647 end: 672 end:
648 return result; 673 return result;
649} 674}
650 675
651static int acpi_battery_get_alarm(struct acpi_battery *battery) 676static int acpi_battery_get_alarm(struct acpi_battery *battery)
652{ 677{
653 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 678 struct acpi_sbs *sbs = battery->sbs;
654 int result = 0; 679 int result = 0;
655 680
656 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, 681 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01,
657 &battery->alarm.remaining_capacity, 682 &battery->alarm.remaining_capacity);
658 &acpi_battery_smbus_err_handler);
659 if (result) { 683 if (result) {
660 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 684 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
661 "acpi_sbs_smbus_read_word() failed\n")); 685 "acpi_sbs_read_word() failed"));
662 goto end; 686 goto end;
663 } 687 }
664 688
665 acpi_update_delay(battery->sbs);
666
667 end: 689 end:
668 690
669 return result; 691 return result;
@@ -672,15 +694,15 @@ static int acpi_battery_get_alarm(struct acpi_battery *battery)
672static int acpi_battery_set_alarm(struct acpi_battery *battery, 694static int acpi_battery_set_alarm(struct acpi_battery *battery,
673 unsigned long alarm) 695 unsigned long alarm)
674{ 696{
675 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 697 struct acpi_sbs *sbs = battery->sbs;
676 int result = 0; 698 int result = 0;
677 s16 battery_mode; 699 s16 battery_mode;
678 int foo; 700 int foo;
679 701
680 result = acpi_battery_select(battery); 702 result = acpi_battery_select(battery);
681 if (result) { 703 if (result) {
682 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 704 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
683 "acpi_battery_select() failed\n")); 705 "acpi_battery_select() failed"));
684 goto end; 706 goto end;
685 } 707 }
686 708
@@ -688,33 +710,29 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery,
688 710
689 if (alarm > 0) { 711 if (alarm > 0) {
690 result = 712 result =
691 acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03, 713 acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03,
692 &battery_mode, 714 &battery_mode);
693 &acpi_battery_smbus_err_handler);
694 if (result) { 715 if (result) {
695 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 716 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
696 "acpi_sbs_smbus_read_word() failed\n")); 717 "acpi_sbs_read_word() failed"));
697 goto end; 718 goto end;
698 } 719 }
699 720
700 result = 721 result =
701 acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, 722 acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01,
702 battery_mode & 0xbfff, 723 battery_mode & 0xbfff);
703 &acpi_battery_smbus_err_handler);
704 if (result) { 724 if (result) {
705 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 725 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
706 "acpi_sbs_smbus_write_word() failed\n")); 726 "acpi_sbs_write_word() failed"));
707 goto end; 727 goto end;
708 } 728 }
709 } 729 }
710 730
711 foo = alarm / (battery->info.capacity_mode ? 10 : 1); 731 foo = alarm / (battery->info.capacity_mode ? 10 : 1);
712 result = acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, 732 result = acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, foo);
713 foo,
714 &acpi_battery_smbus_err_handler);
715 if (result) { 733 if (result) {
716 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 734 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
717 "acpi_sbs_smbus_write_word() failed\n")); 735 "acpi_sbs_write_word() failed"));
718 goto end; 736 goto end;
719 } 737 }
720 738
@@ -725,6 +743,7 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery,
725 743
726static int acpi_battery_set_mode(struct acpi_battery *battery) 744static int acpi_battery_set_mode(struct acpi_battery *battery)
727{ 745{
746 struct acpi_sbs *sbs = battery->sbs;
728 int result = 0; 747 int result = 0;
729 s16 battery_mode; 748 s16 battery_mode;
730 749
@@ -732,12 +751,11 @@ static int acpi_battery_set_mode(struct acpi_battery *battery)
732 goto end; 751 goto end;
733 } 752 }
734 753
735 result = acpi_sbs_smbus_read_word(battery->sbs->smbus, 754 result = acpi_sbs_read_word(sbs,
736 ACPI_SB_SMBUS_ADDR, 0x03, 755 ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode);
737 &battery_mode, NULL);
738 if (result) { 756 if (result) {
739 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 757 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
740 "acpi_sbs_smbus_read_word() failed\n")); 758 "acpi_sbs_read_word() failed"));
741 goto end; 759 goto end;
742 } 760 }
743 761
@@ -746,21 +764,19 @@ static int acpi_battery_set_mode(struct acpi_battery *battery)
746 } else { 764 } else {
747 battery_mode |= 0x8000; 765 battery_mode |= 0x8000;
748 } 766 }
749 result = acpi_sbs_smbus_write_word(battery->sbs->smbus, 767 result = acpi_sbs_write_word(sbs,
750 ACPI_SB_SMBUS_ADDR, 0x03, 768 ACPI_SB_SMBUS_ADDR, 0x03, battery_mode);
751 battery_mode, NULL);
752 if (result) { 769 if (result) {
753 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 770 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
754 "acpi_sbs_smbus_write_word() failed\n")); 771 "acpi_sbs_write_word() failed"));
755 goto end; 772 goto end;
756 } 773 }
757 774
758 result = acpi_sbs_smbus_read_word(battery->sbs->smbus, 775 result = acpi_sbs_read_word(sbs,
759 ACPI_SB_SMBUS_ADDR, 0x03, 776 ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode);
760 &battery_mode, NULL);
761 if (result) { 777 if (result) {
762 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 778 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
763 "acpi_sbs_smbus_read_word() failed\n")); 779 "acpi_sbs_read_word() failed"));
764 goto end; 780 goto end;
765 } 781 }
766 782
@@ -774,36 +790,36 @@ static int acpi_battery_init(struct acpi_battery *battery)
774 790
775 result = acpi_battery_select(battery); 791 result = acpi_battery_select(battery);
776 if (result) { 792 if (result) {
777 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 793 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
778 "acpi_battery_init() failed\n")); 794 "acpi_battery_select() failed"));
779 goto end; 795 goto end;
780 } 796 }
781 797
782 result = acpi_battery_set_mode(battery); 798 result = acpi_battery_set_mode(battery);
783 if (result) { 799 if (result) {
784 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 800 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
785 "acpi_battery_set_mode() failed\n")); 801 "acpi_battery_set_mode() failed"));
786 goto end; 802 goto end;
787 } 803 }
788 804
789 result = acpi_battery_get_info(battery); 805 result = acpi_battery_get_info(battery);
790 if (result) { 806 if (result) {
791 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 807 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
792 "acpi_battery_get_info() failed\n")); 808 "acpi_battery_get_info() failed"));
793 goto end; 809 goto end;
794 } 810 }
795 811
796 result = acpi_battery_get_state(battery); 812 result = acpi_battery_get_state(battery);
797 if (result) { 813 if (result) {
798 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 814 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
799 "acpi_battery_get_state() failed\n")); 815 "acpi_battery_get_state() failed"));
800 goto end; 816 goto end;
801 } 817 }
802 818
803 result = acpi_battery_get_alarm(battery); 819 result = acpi_battery_get_alarm(battery);
804 if (result) { 820 if (result) {
805 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 821 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
806 "acpi_battery_get_alarm() failed\n")); 822 "acpi_battery_get_alarm() failed"));
807 goto end; 823 goto end;
808 } 824 }
809 825
@@ -813,20 +829,19 @@ static int acpi_battery_init(struct acpi_battery *battery)
813 829
814static int acpi_ac_get_present(struct acpi_sbs *sbs) 830static int acpi_ac_get_present(struct acpi_sbs *sbs)
815{ 831{
816 struct acpi_ec_smbus *smbus = sbs->smbus;
817 int result = 0; 832 int result = 0;
818 s16 charger_status; 833 s16 charger_status;
819 834
820 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBC_SMBUS_ADDR, 0x13, 835 result = acpi_sbs_read_word(sbs, ACPI_SBC_SMBUS_ADDR, 0x13,
821 &charger_status, NULL); 836 &charger_status);
822 837
823 if (result) { 838 if (result) {
824 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 839 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
825 "acpi_sbs_smbus_read_word() failed\n")); 840 "acpi_sbs_read_word() failed"));
826 goto end; 841 goto end;
827 } 842 }
828 843
829 sbs->ac_present = (charger_status & 0x8000) >> 15; 844 sbs->ac.ac_present = (charger_status & 0x8000) >> 15;
830 845
831 end: 846 end:
832 847
@@ -852,8 +867,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
852 if (!*dir) { 867 if (!*dir) {
853 *dir = proc_mkdir(dir_name, parent_dir); 868 *dir = proc_mkdir(dir_name, parent_dir);
854 if (!*dir) { 869 if (!*dir) {
855 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 870 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
856 "proc_mkdir() failed\n")); 871 "proc_mkdir() failed"));
857 return -ENODEV; 872 return -ENODEV;
858 } 873 }
859 (*dir)->owner = THIS_MODULE; 874 (*dir)->owner = THIS_MODULE;
@@ -863,8 +878,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
863 if (info_fops) { 878 if (info_fops) {
864 entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir); 879 entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir);
865 if (!entry) { 880 if (!entry) {
866 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 881 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
867 "create_proc_entry() failed\n")); 882 "create_proc_entry() failed"));
868 } else { 883 } else {
869 entry->proc_fops = info_fops; 884 entry->proc_fops = info_fops;
870 entry->data = data; 885 entry->data = data;
@@ -876,8 +891,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
876 if (state_fops) { 891 if (state_fops) {
877 entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir); 892 entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir);
878 if (!entry) { 893 if (!entry) {
879 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 894 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
880 "create_proc_entry() failed\n")); 895 "create_proc_entry() failed"));
881 } else { 896 } else {
882 entry->proc_fops = state_fops; 897 entry->proc_fops = state_fops;
883 entry->data = data; 898 entry->data = data;
@@ -889,8 +904,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
889 if (alarm_fops) { 904 if (alarm_fops) {
890 entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir); 905 entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir);
891 if (!entry) { 906 if (!entry) {
892 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 907 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
893 "create_proc_entry() failed\n")); 908 "create_proc_entry() failed"));
894 } else { 909 } else {
895 entry->proc_fops = alarm_fops; 910 entry->proc_fops = alarm_fops;
896 entry->data = data; 911 entry->data = data;
@@ -923,24 +938,27 @@ static struct proc_dir_entry *acpi_battery_dir = NULL;
923static int acpi_battery_read_info(struct seq_file *seq, void *offset) 938static int acpi_battery_read_info(struct seq_file *seq, void *offset)
924{ 939{
925 struct acpi_battery *battery = seq->private; 940 struct acpi_battery *battery = seq->private;
941 struct acpi_sbs *sbs = battery->sbs;
926 int cscale; 942 int cscale;
927 int result = 0; 943 int result = 0;
928 944
929 if (battery->sbs->zombie) { 945 if (sbs_mutex_lock(sbs)) {
930 return -ENODEV; 946 return -ENODEV;
931 } 947 }
932 948
933 down(&sbs_sem); 949 result = acpi_check_update_proc(sbs);
950 if (result)
951 goto end;
934 952
935 if (update_mode == REQUEST_UPDATE_MODE) { 953 if (update_time == 0) {
936 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_INFO); 954 result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_INFO);
937 if (result) { 955 if (result) {
938 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 956 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
939 "acpi_sbs_update_run() failed\n")); 957 "acpi_sbs_update_run() failed"));
940 } 958 }
941 } 959 }
942 960
943 if (acpi_battery_is_present(battery)) { 961 if (battery->battery_present) {
944 seq_printf(seq, "present: yes\n"); 962 seq_printf(seq, "present: yes\n");
945 } else { 963 } else {
946 seq_printf(seq, "present: no\n"); 964 seq_printf(seq, "present: no\n");
@@ -952,13 +970,13 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
952 } else { 970 } else {
953 cscale = battery->info.ipscale; 971 cscale = battery->info.ipscale;
954 } 972 }
955 seq_printf(seq, "design capacity: %i%s", 973 seq_printf(seq, "design capacity: %i%s\n",
956 battery->info.design_capacity * cscale, 974 battery->info.design_capacity * cscale,
957 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); 975 battery->info.capacity_mode ? "0 mWh" : " mAh");
958 976
959 seq_printf(seq, "last full capacity: %i%s", 977 seq_printf(seq, "last full capacity: %i%s\n",
960 battery->info.full_charge_capacity * cscale, 978 battery->info.full_charge_capacity * cscale,
961 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); 979 battery->info.capacity_mode ? "0 mWh" : " mAh");
962 980
963 seq_printf(seq, "battery technology: rechargeable\n"); 981 seq_printf(seq, "battery technology: rechargeable\n");
964 982
@@ -984,7 +1002,7 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
984 1002
985 end: 1003 end:
986 1004
987 up(&sbs_sem); 1005 sbs_mutex_unlock(sbs);
988 1006
989 return result; 1007 return result;
990} 1008}
@@ -996,26 +1014,29 @@ static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
996 1014
997static int acpi_battery_read_state(struct seq_file *seq, void *offset) 1015static int acpi_battery_read_state(struct seq_file *seq, void *offset)
998{ 1016{
999 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 1017 struct acpi_battery *battery = seq->private;
1018 struct acpi_sbs *sbs = battery->sbs;
1000 int result = 0; 1019 int result = 0;
1001 int cscale; 1020 int cscale;
1002 int foo; 1021 int foo;
1003 1022
1004 if (battery->sbs->zombie) { 1023 if (sbs_mutex_lock(sbs)) {
1005 return -ENODEV; 1024 return -ENODEV;
1006 } 1025 }
1007 1026
1008 down(&sbs_sem); 1027 result = acpi_check_update_proc(sbs);
1028 if (result)
1029 goto end;
1009 1030
1010 if (update_mode == REQUEST_UPDATE_MODE) { 1031 if (update_time == 0) {
1011 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_STATE); 1032 result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_STATE);
1012 if (result) { 1033 if (result) {
1013 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1034 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1014 "acpi_sbs_update_run() failed\n")); 1035 "acpi_sbs_update_run() failed"));
1015 } 1036 }
1016 } 1037 }
1017 1038
1018 if (acpi_battery_is_present(battery)) { 1039 if (battery->battery_present) {
1019 seq_printf(seq, "present: yes\n"); 1040 seq_printf(seq, "present: yes\n");
1020 } else { 1041 } else {
1021 seq_printf(seq, "present: no\n"); 1042 seq_printf(seq, "present: no\n");
@@ -1028,7 +1049,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
1028 cscale = battery->info.ipscale; 1049 cscale = battery->info.ipscale;
1029 } 1050 }
1030 1051
1031 if (battery->state.battery_status & 0x0010) { 1052 if (battery->state.battery_state & 0x0010) {
1032 seq_printf(seq, "capacity state: critical\n"); 1053 seq_printf(seq, "capacity state: critical\n");
1033 } else { 1054 } else {
1034 seq_printf(seq, "capacity state: ok\n"); 1055 seq_printf(seq, "capacity state: ok\n");
@@ -1052,16 +1073,16 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
1052 battery->info.capacity_mode ? "mW" : "mA"); 1073 battery->info.capacity_mode ? "mW" : "mA");
1053 } 1074 }
1054 1075
1055 seq_printf(seq, "remaining capacity: %i%s", 1076 seq_printf(seq, "remaining capacity: %i%s\n",
1056 battery->state.remaining_capacity * cscale, 1077 battery->state.remaining_capacity * cscale,
1057 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); 1078 battery->info.capacity_mode ? "0 mWh" : " mAh");
1058 1079
1059 seq_printf(seq, "present voltage: %i mV\n", 1080 seq_printf(seq, "present voltage: %i mV\n",
1060 battery->state.voltage * battery->info.vscale); 1081 battery->state.voltage * battery->info.vscale);
1061 1082
1062 end: 1083 end:
1063 1084
1064 up(&sbs_sem); 1085 sbs_mutex_unlock(sbs);
1065 1086
1066 return result; 1087 return result;
1067} 1088}
@@ -1074,24 +1095,27 @@ static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
1074static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) 1095static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
1075{ 1096{
1076 struct acpi_battery *battery = seq->private; 1097 struct acpi_battery *battery = seq->private;
1098 struct acpi_sbs *sbs = battery->sbs;
1077 int result = 0; 1099 int result = 0;
1078 int cscale; 1100 int cscale;
1079 1101
1080 if (battery->sbs->zombie) { 1102 if (sbs_mutex_lock(sbs)) {
1081 return -ENODEV; 1103 return -ENODEV;
1082 } 1104 }
1083 1105
1084 down(&sbs_sem); 1106 result = acpi_check_update_proc(sbs);
1107 if (result)
1108 goto end;
1085 1109
1086 if (update_mode == REQUEST_UPDATE_MODE) { 1110 if (update_time == 0) {
1087 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_ALARM); 1111 result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_ALARM);
1088 if (result) { 1112 if (result) {
1089 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1113 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1090 "acpi_sbs_update_run() failed\n")); 1114 "acpi_sbs_update_run() failed"));
1091 } 1115 }
1092 } 1116 }
1093 1117
1094 if (!acpi_battery_is_present(battery)) { 1118 if (!battery->battery_present) {
1095 seq_printf(seq, "present: no\n"); 1119 seq_printf(seq, "present: no\n");
1096 goto end; 1120 goto end;
1097 } 1121 }
@@ -1104,16 +1128,16 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
1104 1128
1105 seq_printf(seq, "alarm: "); 1129 seq_printf(seq, "alarm: ");
1106 if (battery->alarm.remaining_capacity) { 1130 if (battery->alarm.remaining_capacity) {
1107 seq_printf(seq, "%i%s", 1131 seq_printf(seq, "%i%s\n",
1108 battery->alarm.remaining_capacity * cscale, 1132 battery->alarm.remaining_capacity * cscale,
1109 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); 1133 battery->info.capacity_mode ? "0 mWh" : " mAh");
1110 } else { 1134 } else {
1111 seq_printf(seq, "disabled\n"); 1135 seq_printf(seq, "disabled\n");
1112 } 1136 }
1113 1137
1114 end: 1138 end:
1115 1139
1116 up(&sbs_sem); 1140 sbs_mutex_unlock(sbs);
1117 1141
1118 return result; 1142 return result;
1119} 1143}
@@ -1124,16 +1148,19 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1124{ 1148{
1125 struct seq_file *seq = file->private_data; 1149 struct seq_file *seq = file->private_data;
1126 struct acpi_battery *battery = seq->private; 1150 struct acpi_battery *battery = seq->private;
1151 struct acpi_sbs *sbs = battery->sbs;
1127 char alarm_string[12] = { '\0' }; 1152 char alarm_string[12] = { '\0' };
1128 int result, old_alarm, new_alarm; 1153 int result, old_alarm, new_alarm;
1129 1154
1130 if (battery->sbs->zombie) { 1155 if (sbs_mutex_lock(sbs)) {
1131 return -ENODEV; 1156 return -ENODEV;
1132 } 1157 }
1133 1158
1134 down(&sbs_sem); 1159 result = acpi_check_update_proc(sbs);
1160 if (result)
1161 goto end;
1135 1162
1136 if (!acpi_battery_is_present(battery)) { 1163 if (!battery->battery_present) {
1137 result = -ENODEV; 1164 result = -ENODEV;
1138 goto end; 1165 goto end;
1139 } 1166 }
@@ -1155,21 +1182,21 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1155 1182
1156 result = acpi_battery_set_alarm(battery, new_alarm); 1183 result = acpi_battery_set_alarm(battery, new_alarm);
1157 if (result) { 1184 if (result) {
1158 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1185 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1159 "acpi_battery_set_alarm() failed\n")); 1186 "acpi_battery_set_alarm() failed"));
1160 acpi_battery_set_alarm(battery, old_alarm); 1187 acpi_battery_set_alarm(battery, old_alarm);
1161 goto end; 1188 goto end;
1162 } 1189 }
1163 result = acpi_battery_get_alarm(battery); 1190 result = acpi_battery_get_alarm(battery);
1164 if (result) { 1191 if (result) {
1165 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1192 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1166 "acpi_battery_get_alarm() failed\n")); 1193 "acpi_battery_get_alarm() failed"));
1167 acpi_battery_set_alarm(battery, old_alarm); 1194 acpi_battery_set_alarm(battery, old_alarm);
1168 goto end; 1195 goto end;
1169 } 1196 }
1170 1197
1171 end: 1198 end:
1172 up(&sbs_sem); 1199 sbs_mutex_unlock(sbs);
1173 1200
1174 if (result) { 1201 if (result) {
1175 return result; 1202 return result;
@@ -1217,24 +1244,22 @@ static int acpi_ac_read_state(struct seq_file *seq, void *offset)
1217 struct acpi_sbs *sbs = seq->private; 1244 struct acpi_sbs *sbs = seq->private;
1218 int result; 1245 int result;
1219 1246
1220 if (sbs->zombie) { 1247 if (sbs_mutex_lock(sbs)) {
1221 return -ENODEV; 1248 return -ENODEV;
1222 } 1249 }
1223 1250
1224 down(&sbs_sem); 1251 if (update_time == 0) {
1225 1252 result = acpi_sbs_update_run(sbs, -1, DATA_TYPE_AC_STATE);
1226 if (update_mode == REQUEST_UPDATE_MODE) {
1227 result = acpi_sbs_update_run(sbs, DATA_TYPE_AC_STATE);
1228 if (result) { 1253 if (result) {
1229 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1254 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1230 "acpi_sbs_update_run() failed\n")); 1255 "acpi_sbs_update_run() failed"));
1231 } 1256 }
1232 } 1257 }
1233 1258
1234 seq_printf(seq, "state: %s\n", 1259 seq_printf(seq, "state: %s\n",
1235 sbs->ac_present ? "on-line" : "off-line"); 1260 sbs->ac.ac_present ? "on-line" : "off-line");
1236 1261
1237 up(&sbs_sem); 1262 sbs_mutex_unlock(sbs);
1238 1263
1239 return 0; 1264 return 0;
1240} 1265}
@@ -1275,25 +1300,25 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
1275 1300
1276 result = acpi_battery_select(battery); 1301 result = acpi_battery_select(battery);
1277 if (result) { 1302 if (result) {
1278 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1303 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1279 "acpi_battery_select() failed\n")); 1304 "acpi_battery_select() failed"));
1280 goto end; 1305 goto end;
1281 } 1306 }
1282 1307
1283 result = acpi_battery_get_present(battery); 1308 result = acpi_battery_get_present(battery);
1284 if (result) { 1309 if (result) {
1285 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1310 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1286 "acpi_battery_get_present() failed\n")); 1311 "acpi_battery_get_present() failed"));
1287 goto end; 1312 goto end;
1288 } 1313 }
1289 1314
1290 is_present = acpi_battery_is_present(battery); 1315 is_present = battery->battery_present;
1291 1316
1292 if (is_present) { 1317 if (is_present) {
1293 result = acpi_battery_init(battery); 1318 result = acpi_battery_init(battery);
1294 if (result) { 1319 if (result) {
1295 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1320 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1296 "acpi_battery_init() failed\n")); 1321 "acpi_battery_init() failed"));
1297 goto end; 1322 goto end;
1298 } 1323 }
1299 battery->init_state = 1; 1324 battery->init_state = 1;
@@ -1308,12 +1333,16 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
1308 &acpi_battery_state_fops, 1333 &acpi_battery_state_fops,
1309 &acpi_battery_alarm_fops, battery); 1334 &acpi_battery_alarm_fops, battery);
1310 if (result) { 1335 if (result) {
1311 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1336 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1312 "acpi_sbs_generic_add_fs() failed\n")); 1337 "acpi_sbs_generic_add_fs() failed"));
1313 goto end; 1338 goto end;
1314 } 1339 }
1315 battery->alive = 1; 1340 battery->alive = 1;
1316 1341
1342 printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n",
1343 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), dir_name,
1344 sbs->battery->battery_present ? "present" : "absent");
1345
1317 end: 1346 end:
1318 return result; 1347 return result;
1319} 1348}
@@ -1333,8 +1362,8 @@ static int acpi_ac_add(struct acpi_sbs *sbs)
1333 1362
1334 result = acpi_ac_get_present(sbs); 1363 result = acpi_ac_get_present(sbs);
1335 if (result) { 1364 if (result) {
1336 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1365 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1337 "acpi_ac_get_present() failed\n")); 1366 "acpi_ac_get_present() failed"));
1338 goto end; 1367 goto end;
1339 } 1368 }
1340 1369
@@ -1343,11 +1372,15 @@ static int acpi_ac_add(struct acpi_sbs *sbs)
1343 ACPI_AC_DIR_NAME, 1372 ACPI_AC_DIR_NAME,
1344 NULL, &acpi_ac_state_fops, NULL, sbs); 1373 NULL, &acpi_ac_state_fops, NULL, sbs);
1345 if (result) { 1374 if (result) {
1346 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1375 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1347 "acpi_sbs_generic_add_fs() failed\n")); 1376 "acpi_sbs_generic_add_fs() failed"));
1348 goto end; 1377 goto end;
1349 } 1378 }
1350 1379
1380 printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n",
1381 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
1382 ACPI_AC_DIR_NAME, sbs->ac.ac_present ? "on-line" : "off-line");
1383
1351 end: 1384 end:
1352 1385
1353 return result; 1386 return result;
@@ -1361,45 +1394,85 @@ static void acpi_ac_remove(struct acpi_sbs *sbs)
1361 } 1394 }
1362} 1395}
1363 1396
1364static void acpi_sbs_update_queue_run(unsigned long data) 1397static void acpi_sbs_update_time_run(unsigned long data)
1365{ 1398{
1366 acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_queue, (void *)data); 1399 acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_time, (void *)data);
1367} 1400}
1368 1401
1369static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type) 1402static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type)
1370{ 1403{
1371 struct acpi_battery *battery; 1404 struct acpi_battery *battery;
1372 int result = 0; 1405 int result = 0, cnt;
1373 int old_ac_present; 1406 int old_ac_present = -1;
1374 int old_battery_present; 1407 int old_battery_present = -1;
1375 int new_ac_present; 1408 int new_ac_present = -1;
1376 int new_battery_present; 1409 int new_battery_present = -1;
1377 int id; 1410 int id_min = 0, id_max = MAX_SBS_BAT - 1;
1378 char dir_name[32]; 1411 char dir_name[32];
1379 int do_battery_init, do_ac_init; 1412 int do_battery_init = 0, do_ac_init = 0;
1380 s16 old_remaining_capacity; 1413 int old_remaining_capacity = 0;
1414 int update_ac = 1, update_battery = 1;
1415 int up_tm = update_time;
1381 1416
1382 if (sbs->zombie) { 1417 if (sbs_zombie(sbs)) {
1383 goto end; 1418 goto end;
1384 } 1419 }
1385 1420
1386 old_ac_present = acpi_ac_is_present(sbs); 1421 if (id >= 0) {
1422 id_min = id_max = id;
1423 }
1424
1425 if (data_type == DATA_TYPE_COMMON && up_tm > 0) {
1426 cnt = up_tm / (up_tm > UPDATE_DELAY ? UPDATE_DELAY : up_tm);
1427 if (sbs->run_cnt % cnt != 0) {
1428 update_battery = 0;
1429 }
1430 }
1431
1432 sbs->run_cnt++;
1433
1434 if (!update_ac && !update_battery) {
1435 goto end;
1436 }
1437
1438 old_ac_present = sbs->ac.ac_present;
1387 1439
1388 result = acpi_ac_get_present(sbs); 1440 result = acpi_ac_get_present(sbs);
1389 if (result) { 1441 if (result) {
1390 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1442 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1391 "acpi_ac_get_present() failed\n")); 1443 "acpi_ac_get_present() failed"));
1392 } 1444 }
1393 1445
1394 new_ac_present = acpi_ac_is_present(sbs); 1446 new_ac_present = sbs->ac.ac_present;
1395 1447
1396 do_ac_init = (old_ac_present != new_ac_present); 1448 do_ac_init = (old_ac_present != new_ac_present);
1449 if (sbs->run_cnt == 1 && data_type == DATA_TYPE_COMMON) {
1450 do_ac_init = 1;
1451 }
1397 1452
1398 if (data_type == DATA_TYPE_AC_STATE) { 1453 if (do_ac_init) {
1454 result = acpi_sbs_generate_event(sbs->device,
1455 ACPI_SBS_AC_NOTIFY_STATUS,
1456 new_ac_present,
1457 ACPI_AC_DIR_NAME,
1458 ACPI_AC_CLASS);
1459 if (result) {
1460 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1461 "acpi_sbs_generate_event() failed"));
1462 }
1463 }
1464
1465 if (data_type == DATA_TYPE_COMMON) {
1466 if (!do_ac_init && !update_battery) {
1467 goto end;
1468 }
1469 }
1470
1471 if (data_type == DATA_TYPE_AC_STATE && !do_ac_init) {
1399 goto end; 1472 goto end;
1400 } 1473 }
1401 1474
1402 for (id = 0; id < MAX_SBS_BAT; id++) { 1475 for (id = id_min; id <= id_max; id++) {
1403 battery = &sbs->battery[id]; 1476 battery = &sbs->battery[id];
1404 if (battery->alive == 0) { 1477 if (battery->alive == 0) {
1405 continue; 1478 continue;
@@ -1407,94 +1480,92 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1407 1480
1408 old_remaining_capacity = battery->state.remaining_capacity; 1481 old_remaining_capacity = battery->state.remaining_capacity;
1409 1482
1410 old_battery_present = acpi_battery_is_present(battery); 1483 old_battery_present = battery->battery_present;
1411 1484
1412 result = acpi_battery_select(battery); 1485 result = acpi_battery_select(battery);
1413 if (result) { 1486 if (result) {
1414 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1487 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1415 "acpi_battery_select() failed\n")); 1488 "acpi_battery_select() failed"));
1416 }
1417 if (sbs->zombie) {
1418 goto end;
1419 } 1489 }
1420 1490
1421 result = acpi_battery_get_present(battery); 1491 result = acpi_battery_get_present(battery);
1422 if (result) { 1492 if (result) {
1423 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1493 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1424 "acpi_battery_get_present() failed\n")); 1494 "acpi_battery_get_present() failed"));
1425 }
1426 if (sbs->zombie) {
1427 goto end;
1428 } 1495 }
1429 1496
1430 new_battery_present = acpi_battery_is_present(battery); 1497 new_battery_present = battery->battery_present;
1431 1498
1432 do_battery_init = ((old_battery_present != new_battery_present) 1499 do_battery_init = ((old_battery_present != new_battery_present)
1433 && new_battery_present); 1500 && new_battery_present);
1434 1501 if (!new_battery_present)
1435 if (sbs->zombie) { 1502 goto event;
1503 if (do_ac_init || do_battery_init) {
1504 result = acpi_battery_init(battery);
1505 if (result) {
1506 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1507 "acpi_battery_init() "
1508 "failed"));
1509 }
1510 }
1511 if (sbs_zombie(sbs)) {
1436 goto end; 1512 goto end;
1437 } 1513 }
1438 if (do_ac_init || do_battery_init || 1514
1439 update_info_mode || sbs->update_info_mode) { 1515 if ((data_type == DATA_TYPE_COMMON
1440 if (sbs->update_info_mode) { 1516 || data_type == DATA_TYPE_INFO)
1441 sbs->update_info_mode = 0; 1517 && new_battery_present) {
1442 } else { 1518 result = acpi_battery_get_info(battery);
1443 sbs->update_info_mode = 1;
1444 }
1445 result = acpi_battery_init(battery);
1446 if (result) { 1519 if (result) {
1447 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1520 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1448 "acpi_battery_init() " 1521 "acpi_battery_get_info() failed"));
1449 "failed\n"));
1450 } 1522 }
1451 } 1523 }
1452 if (data_type == DATA_TYPE_INFO) { 1524 if (data_type == DATA_TYPE_INFO) {
1453 continue; 1525 continue;
1454 } 1526 }
1455 1527 if (sbs_zombie(sbs)) {
1456 if (sbs->zombie) {
1457 goto end; 1528 goto end;
1458 } 1529 }
1459 if (new_battery_present) {
1460 result = acpi_battery_get_alarm(battery);
1461 if (result) {
1462 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1463 "acpi_battery_get_alarm() "
1464 "failed\n"));
1465 }
1466 if (data_type == DATA_TYPE_ALARM) {
1467 continue;
1468 }
1469 1530
1531 if ((data_type == DATA_TYPE_COMMON
1532 || data_type == DATA_TYPE_STATE)
1533 && new_battery_present) {
1470 result = acpi_battery_get_state(battery); 1534 result = acpi_battery_get_state(battery);
1471 if (result) { 1535 if (result) {
1472 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1536 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1473 "acpi_battery_get_state() " 1537 "acpi_battery_get_state() failed"));
1474 "failed\n"));
1475 } 1538 }
1476 } 1539 }
1477 if (sbs->zombie) { 1540 if (data_type == DATA_TYPE_STATE) {
1478 goto end; 1541 goto event;
1479 } 1542 }
1480 if (data_type != DATA_TYPE_COMMON) { 1543 if (sbs_zombie(sbs)) {
1481 continue; 1544 goto end;
1482 } 1545 }
1483 1546
1484 if (old_battery_present != new_battery_present) { 1547 if ((data_type == DATA_TYPE_COMMON
1485 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1548 || data_type == DATA_TYPE_ALARM)
1486 result = acpi_sbs_generate_event(sbs->device, 1549 && new_battery_present) {
1487 ACPI_SBS_BATTERY_NOTIFY_STATUS, 1550 result = acpi_battery_get_alarm(battery);
1488 new_battery_present,
1489 dir_name,
1490 ACPI_BATTERY_CLASS);
1491 if (result) { 1551 if (result) {
1492 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1552 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1493 "acpi_sbs_generate_event() " 1553 "acpi_battery_get_alarm() "
1494 "failed\n")); 1554 "failed"));
1495 } 1555 }
1496 } 1556 }
1497 if (old_remaining_capacity != battery->state.remaining_capacity) { 1557 if (data_type == DATA_TYPE_ALARM) {
1558 continue;
1559 }
1560 if (sbs_zombie(sbs)) {
1561 goto end;
1562 }
1563
1564 event:
1565
1566 if (old_battery_present != new_battery_present || do_ac_init ||
1567 old_remaining_capacity !=
1568 battery->state.remaining_capacity) {
1498 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1569 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1499 result = acpi_sbs_generate_event(sbs->device, 1570 result = acpi_sbs_generate_event(sbs->device,
1500 ACPI_SBS_BATTERY_NOTIFY_STATUS, 1571 ACPI_SBS_BATTERY_NOTIFY_STATUS,
@@ -1502,138 +1573,120 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1502 dir_name, 1573 dir_name,
1503 ACPI_BATTERY_CLASS); 1574 ACPI_BATTERY_CLASS);
1504 if (result) { 1575 if (result) {
1505 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1576 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1506 "acpi_sbs_generate_event() failed\n")); 1577 "acpi_sbs_generate_event() "
1578 "failed"));
1507 } 1579 }
1508 } 1580 }
1509
1510 }
1511 if (sbs->zombie) {
1512 goto end;
1513 }
1514 if (data_type != DATA_TYPE_COMMON) {
1515 goto end;
1516 }
1517
1518 if (old_ac_present != new_ac_present) {
1519 result = acpi_sbs_generate_event(sbs->device,
1520 ACPI_SBS_AC_NOTIFY_STATUS,
1521 new_ac_present,
1522 ACPI_AC_DIR_NAME,
1523 ACPI_AC_CLASS);
1524 if (result) {
1525 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1526 "acpi_sbs_generate_event() failed\n"));
1527 }
1528 } 1581 }
1529 1582
1530 end: 1583 end:
1584
1531 return result; 1585 return result;
1532} 1586}
1533 1587
1534static void acpi_sbs_update_queue(void *data) 1588static void acpi_sbs_update_time(void *data)
1535{ 1589{
1536 struct acpi_sbs *sbs = data; 1590 struct acpi_sbs *sbs = data;
1537 unsigned long delay = -1; 1591 unsigned long delay = -1;
1538 int result; 1592 int result;
1593 unsigned int up_tm = update_time;
1539 1594
1540 if (sbs->zombie) { 1595 if (sbs_mutex_lock(sbs))
1541 goto end; 1596 return;
1542 }
1543 1597
1544 result = acpi_sbs_update_run(sbs, DATA_TYPE_COMMON); 1598 result = acpi_sbs_update_run(sbs, -1, DATA_TYPE_COMMON);
1545 if (result) { 1599 if (result) {
1546 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1600 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1547 "acpi_sbs_update_run() failed\n")); 1601 "acpi_sbs_update_run() failed"));
1548 } 1602 }
1549 1603
1550 if (sbs->zombie) { 1604 if (sbs_zombie(sbs)) {
1551 goto end; 1605 goto end;
1552 } 1606 }
1553 1607
1554 if (update_mode == REQUEST_UPDATE_MODE) { 1608 if (!up_tm) {
1555 goto end; 1609 if (timer_pending(&sbs->update_timer))
1610 del_timer(&sbs->update_timer);
1611 } else {
1612 delay = (up_tm > UPDATE_DELAY ? UPDATE_DELAY : up_tm);
1613 delay = jiffies + HZ * delay;
1614 if (timer_pending(&sbs->update_timer)) {
1615 mod_timer(&sbs->update_timer, delay);
1616 } else {
1617 sbs->update_timer.data = (unsigned long)data;
1618 sbs->update_timer.function = acpi_sbs_update_time_run;
1619 sbs->update_timer.expires = delay;
1620 add_timer(&sbs->update_timer);
1621 }
1556 } 1622 }
1557 1623
1558 delay = jiffies + HZ * update_time;
1559 sbs->update_timer.data = (unsigned long)data;
1560 sbs->update_timer.function = acpi_sbs_update_queue_run;
1561 sbs->update_timer.expires = delay;
1562 add_timer(&sbs->update_timer);
1563 end: 1624 end:
1564 ; 1625
1626 sbs_mutex_unlock(sbs);
1565} 1627}
1566 1628
1567static int acpi_sbs_add(struct acpi_device *device) 1629static int acpi_sbs_add(struct acpi_device *device)
1568{ 1630{
1569 struct acpi_sbs *sbs = NULL; 1631 struct acpi_sbs *sbs = NULL;
1570 struct acpi_ec_hc *ec_hc = NULL; 1632 int result = 0, remove_result = 0;
1571 int result, remove_result = 0;
1572 unsigned long sbs_obj; 1633 unsigned long sbs_obj;
1573 int id, cnt; 1634 int id;
1574 acpi_status status = AE_OK; 1635 acpi_status status = AE_OK;
1636 unsigned long val;
1637
1638 status =
1639 acpi_evaluate_integer(device->parent->handle, "_EC", NULL, &val);
1640 if (ACPI_FAILURE(status)) {
1641 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Error obtaining _EC"));
1642 return -EIO;
1643 }
1575 1644
1576 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); 1645 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
1577 if (!sbs) { 1646 if (!sbs) {
1578 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n")); 1647 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "kzalloc() failed"));
1579 return -ENOMEM; 1648 result = -ENOMEM;
1649 goto end;
1580 } 1650 }
1581 1651
1582 cnt = 0; 1652 mutex_init(&sbs->mutex);
1583 while (cnt < 10) {
1584 cnt++;
1585 ec_hc = acpi_get_ec_hc(device);
1586 if (ec_hc) {
1587 break;
1588 }
1589 msleep(1000);
1590 }
1591 1653
1592 if (!ec_hc) { 1654 sbs_mutex_lock(sbs);
1593 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1594 "acpi_get_ec_hc() failed: "
1595 "NO driver found for EC HC SMBus\n"));
1596 result = -ENODEV;
1597 goto end;
1598 }
1599 1655
1656 sbs->base = (val & 0xff00ull) >> 8;
1600 sbs->device = device; 1657 sbs->device = device;
1601 sbs->smbus = ec_hc->smbus;
1602 1658
1603 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); 1659 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
1604 strcpy(acpi_device_class(device), ACPI_SBS_CLASS); 1660 strcpy(acpi_device_class(device), ACPI_SBS_CLASS);
1605 acpi_driver_data(device) = sbs; 1661 acpi_driver_data(device) = sbs;
1606 1662
1607 sbs->update_time = 0;
1608 sbs->update_time2 = 0;
1609
1610 result = acpi_ac_add(sbs); 1663 result = acpi_ac_add(sbs);
1611 if (result) { 1664 if (result) {
1612 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_ac_add() failed\n")); 1665 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "acpi_ac_add() failed"));
1613 goto end; 1666 goto end;
1614 } 1667 }
1615 result = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj); 1668 status = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj);
1616 if (ACPI_FAILURE(result)) { 1669 if (status) {
1617 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1670 ACPI_EXCEPTION((AE_INFO, status,
1618 "acpi_evaluate_integer() failed\n")); 1671 "acpi_evaluate_integer() failed"));
1619 result = -EIO; 1672 result = -EIO;
1620 goto end; 1673 goto end;
1621 } 1674 }
1622
1623 if (sbs_obj > 0) { 1675 if (sbs_obj > 0) {
1624 result = acpi_sbsm_get_info(sbs); 1676 result = acpi_sbsm_get_info(sbs);
1625 if (result) { 1677 if (result) {
1626 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1678 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1627 "acpi_sbsm_get_info() failed\n")); 1679 "acpi_sbsm_get_info() failed"));
1628 goto end; 1680 goto end;
1629 } 1681 }
1630 sbs->sbsm_present = 1; 1682 sbs->sbsm_present = 1;
1631 } 1683 }
1684
1632 if (sbs->sbsm_present == 0) { 1685 if (sbs->sbsm_present == 0) {
1633 result = acpi_battery_add(sbs, 0); 1686 result = acpi_battery_add(sbs, 0);
1634 if (result) { 1687 if (result) {
1635 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1688 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1636 "acpi_battery_add() failed\n")); 1689 "acpi_battery_add() failed"));
1637 goto end; 1690 goto end;
1638 } 1691 }
1639 } else { 1692 } else {
@@ -1641,9 +1694,8 @@ static int acpi_sbs_add(struct acpi_device *device)
1641 if ((sbs->sbsm_batteries_supported & (1 << id))) { 1694 if ((sbs->sbsm_batteries_supported & (1 << id))) {
1642 result = acpi_battery_add(sbs, id); 1695 result = acpi_battery_add(sbs, id);
1643 if (result) { 1696 if (result) {
1644 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1697 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1645 "acpi_battery_add() " 1698 "acpi_battery_add() failed"));
1646 "failed\n"));
1647 goto end; 1699 goto end;
1648 } 1700 }
1649 } 1701 }
@@ -1653,33 +1705,26 @@ static int acpi_sbs_add(struct acpi_device *device)
1653 sbs->handle = device->handle; 1705 sbs->handle = device->handle;
1654 1706
1655 init_timer(&sbs->update_timer); 1707 init_timer(&sbs->update_timer);
1656 if (update_mode == QUEUE_UPDATE_MODE) { 1708 result = acpi_check_update_proc(sbs);
1657 status = acpi_os_execute(OSL_GPE_HANDLER, 1709 if (result)
1658 acpi_sbs_update_queue, sbs); 1710 goto end;
1659 if (status != AE_OK) {
1660 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1661 "acpi_os_execute() failed\n"));
1662 }
1663 }
1664 sbs->update_time = update_time;
1665 sbs->update_time2 = update_time2;
1666
1667 printk(KERN_INFO PREFIX "%s [%s]\n",
1668 acpi_device_name(device), acpi_device_bid(device));
1669 1711
1670 end: 1712 end:
1713
1714 sbs_mutex_unlock(sbs);
1715
1671 if (result) { 1716 if (result) {
1672 remove_result = acpi_sbs_remove(device, 0); 1717 remove_result = acpi_sbs_remove(device, 0);
1673 if (remove_result) { 1718 if (remove_result) {
1674 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1719 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1675 "acpi_sbs_remove() failed\n")); 1720 "acpi_sbs_remove() failed"));
1676 } 1721 }
1677 } 1722 }
1678 1723
1679 return result; 1724 return result;
1680} 1725}
1681 1726
1682int acpi_sbs_remove(struct acpi_device *device, int type) 1727static int acpi_sbs_remove(struct acpi_device *device, int type)
1683{ 1728{
1684 struct acpi_sbs *sbs; 1729 struct acpi_sbs *sbs;
1685 int id; 1730 int id;
@@ -1688,15 +1733,14 @@ int acpi_sbs_remove(struct acpi_device *device, int type)
1688 return -EINVAL; 1733 return -EINVAL;
1689 } 1734 }
1690 1735
1691 sbs = (struct acpi_sbs *)acpi_driver_data(device); 1736 sbs = acpi_driver_data(device);
1692
1693 if (!sbs) { 1737 if (!sbs) {
1694 return -EINVAL; 1738 return -EINVAL;
1695 } 1739 }
1696 1740
1741 sbs_mutex_lock(sbs);
1742
1697 sbs->zombie = 1; 1743 sbs->zombie = 1;
1698 sbs->update_time = 0;
1699 sbs->update_time2 = 0;
1700 del_timer_sync(&sbs->update_timer); 1744 del_timer_sync(&sbs->update_timer);
1701 acpi_os_wait_events_complete(NULL); 1745 acpi_os_wait_events_complete(NULL);
1702 del_timer_sync(&sbs->update_timer); 1746 del_timer_sync(&sbs->update_timer);
@@ -1707,11 +1751,41 @@ int acpi_sbs_remove(struct acpi_device *device, int type)
1707 1751
1708 acpi_ac_remove(sbs); 1752 acpi_ac_remove(sbs);
1709 1753
1754 sbs_mutex_unlock(sbs);
1755
1756 mutex_destroy(&sbs->mutex);
1757
1710 kfree(sbs); 1758 kfree(sbs);
1711 1759
1712 return 0; 1760 return 0;
1713} 1761}
1714 1762
1763static void acpi_sbs_rmdirs(void)
1764{
1765 if (acpi_ac_dir) {
1766 acpi_unlock_ac_dir(acpi_ac_dir);
1767 acpi_ac_dir = NULL;
1768 }
1769 if (acpi_battery_dir) {
1770 acpi_unlock_battery_dir(acpi_battery_dir);
1771 acpi_battery_dir = NULL;
1772 }
1773}
1774
1775static int acpi_sbs_resume(struct acpi_device *device)
1776{
1777 struct acpi_sbs *sbs;
1778
1779 if (!device)
1780 return -EINVAL;
1781
1782 sbs = device->driver_data;
1783
1784 sbs->run_cnt = 0;
1785
1786 return 0;
1787}
1788
1715static int __init acpi_sbs_init(void) 1789static int __init acpi_sbs_init(void)
1716{ 1790{
1717 int result = 0; 1791 int result = 0;
@@ -1719,35 +1793,34 @@ static int __init acpi_sbs_init(void)
1719 if (acpi_disabled) 1793 if (acpi_disabled)
1720 return -ENODEV; 1794 return -ENODEV;
1721 1795
1722 init_MUTEX(&sbs_sem);
1723
1724 if (capacity_mode != DEF_CAPACITY_UNIT 1796 if (capacity_mode != DEF_CAPACITY_UNIT
1725 && capacity_mode != MAH_CAPACITY_UNIT 1797 && capacity_mode != MAH_CAPACITY_UNIT
1726 && capacity_mode != MWH_CAPACITY_UNIT) { 1798 && capacity_mode != MWH_CAPACITY_UNIT) {
1727 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_sbs_init: " 1799 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1728 "invalid capacity_mode = %d\n", 1800 "invalid capacity_mode = %d", capacity_mode));
1729 capacity_mode));
1730 return -EINVAL; 1801 return -EINVAL;
1731 } 1802 }
1732 1803
1733 acpi_ac_dir = acpi_lock_ac_dir(); 1804 acpi_ac_dir = acpi_lock_ac_dir();
1734 if (!acpi_ac_dir) { 1805 if (!acpi_ac_dir) {
1735 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1806 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1736 "acpi_lock_ac_dir() failed\n")); 1807 "acpi_lock_ac_dir() failed"));
1737 return -ENODEV; 1808 return -ENODEV;
1738 } 1809 }
1739 1810
1740 acpi_battery_dir = acpi_lock_battery_dir(); 1811 acpi_battery_dir = acpi_lock_battery_dir();
1741 if (!acpi_battery_dir) { 1812 if (!acpi_battery_dir) {
1742 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1813 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1743 "acpi_lock_battery_dir() failed\n")); 1814 "acpi_lock_battery_dir() failed"));
1815 acpi_sbs_rmdirs();
1744 return -ENODEV; 1816 return -ENODEV;
1745 } 1817 }
1746 1818
1747 result = acpi_bus_register_driver(&acpi_sbs_driver); 1819 result = acpi_bus_register_driver(&acpi_sbs_driver);
1748 if (result < 0) { 1820 if (result < 0) {
1749 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1821 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1750 "acpi_bus_register_driver() failed\n")); 1822 "acpi_bus_register_driver() failed"));
1823 acpi_sbs_rmdirs();
1751 return -ENODEV; 1824 return -ENODEV;
1752 } 1825 }
1753 1826
@@ -1756,13 +1829,9 @@ static int __init acpi_sbs_init(void)
1756 1829
1757static void __exit acpi_sbs_exit(void) 1830static void __exit acpi_sbs_exit(void)
1758{ 1831{
1759
1760 acpi_bus_unregister_driver(&acpi_sbs_driver); 1832 acpi_bus_unregister_driver(&acpi_sbs_driver);
1761 1833
1762 acpi_unlock_ac_dir(acpi_ac_dir); 1834 acpi_sbs_rmdirs();
1763 acpi_ac_dir = NULL;
1764 acpi_unlock_battery_dir(acpi_battery_dir);
1765 acpi_battery_dir = NULL;
1766 1835
1767 return; 1836 return;
1768} 1837}