diff options
author | Vladimir Lebedev <vladimir.p.lebedev@intel.com> | 2007-03-19 10:45:50 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2007-03-22 01:15:57 -0400 |
commit | 6d15702cc07503b74494dc4f1ddb15f354987b14 (patch) | |
tree | 4e0eaf31f6a4609a1ce94e556e529eeb405c1771 /drivers/acpi/sbs.c | |
parent | 8559840c4ca3f2fff73a882803bc8916078fac1f (diff) |
ACPI: sbs: use EC rather than I2C
SBS is based on EC function(ec_read/ec_write).
Not needed using of I2C structures/functions ... is removed.
SBS does not depend on I2C now.
Signed-off-by: Vladimir Lebedev <vladimir.p.lebedev@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/sbs.c')
-rw-r--r-- | drivers/acpi/sbs.c | 565 |
1 files changed, 287 insertions, 278 deletions
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index 59640d9a0acc..eab5c680a6ac 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c | |||
@@ -30,30 +30,9 @@ | |||
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/delay.h> | 34 | #include <linux/delay.h> |
35 | 35 | ||
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 | |||
52 | extern struct proc_dir_entry *acpi_lock_ac_dir(void); | ||
53 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); | ||
54 | extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); | ||
55 | extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | ||
56 | |||
57 | #define ACPI_SBS_COMPONENT 0x00080000 | 36 | #define ACPI_SBS_COMPONENT 0x00080000 |
58 | #define ACPI_SBS_CLASS "sbs" | 37 | #define ACPI_SBS_CLASS "sbs" |
59 | #define ACPI_AC_CLASS "ac_adapter" | 38 | #define ACPI_AC_CLASS "ac_adapter" |
@@ -74,15 +53,62 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | |||
74 | 53 | ||
75 | #define _COMPONENT ACPI_SBS_COMPONENT | 54 | #define _COMPONENT ACPI_SBS_COMPONENT |
76 | 55 | ||
77 | #define MAX_SBS_BAT 4 | ||
78 | #define MAX_SMBUS_ERR 1 | ||
79 | |||
80 | ACPI_MODULE_NAME("sbs"); | 56 | ACPI_MODULE_NAME("sbs"); |
81 | 57 | ||
82 | MODULE_AUTHOR("Rich Townsend"); | 58 | MODULE_AUTHOR("Rich Townsend"); |
83 | MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); | 59 | MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); |
84 | MODULE_LICENSE("GPL"); | 60 | MODULE_LICENSE("GPL"); |
85 | 61 | ||
62 | #define xmsleep(t) msleep(t) | ||
63 | |||
64 | #define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */ | ||
65 | |||
66 | #define ACPI_EC_SMB_STS 0x01 /* status */ | ||
67 | #define ACPI_EC_SMB_ADDR 0x02 /* address */ | ||
68 | #define ACPI_EC_SMB_CMD 0x03 /* command */ | ||
69 | #define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */ | ||
70 | #define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */ | ||
71 | |||
72 | #define ACPI_EC_SMB_STS_DONE 0x80 | ||
73 | #define ACPI_EC_SMB_STS_STATUS 0x1f | ||
74 | |||
75 | #define ACPI_EC_SMB_PRTCL_WRITE 0x00 | ||
76 | #define ACPI_EC_SMB_PRTCL_READ 0x01 | ||
77 | #define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08 | ||
78 | #define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a | ||
79 | |||
80 | #define ACPI_EC_SMB_TRANSACTION_SLEEP 1 | ||
81 | #define ACPI_EC_SMB_ACCESS_SLEEP1 1 | ||
82 | #define ACPI_EC_SMB_ACCESS_SLEEP2 10 | ||
83 | |||
84 | #define DEF_CAPACITY_UNIT 3 | ||
85 | #define MAH_CAPACITY_UNIT 1 | ||
86 | #define MWH_CAPACITY_UNIT 2 | ||
87 | #define CAPACITY_UNIT DEF_CAPACITY_UNIT | ||
88 | |||
89 | #define REQUEST_UPDATE_MODE 1 | ||
90 | #define QUEUE_UPDATE_MODE 2 | ||
91 | |||
92 | #define DATA_TYPE_COMMON 0 | ||
93 | #define DATA_TYPE_INFO 1 | ||
94 | #define DATA_TYPE_STATE 2 | ||
95 | #define DATA_TYPE_ALARM 3 | ||
96 | #define DATA_TYPE_AC_STATE 4 | ||
97 | |||
98 | extern struct proc_dir_entry *acpi_lock_ac_dir(void); | ||
99 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); | ||
100 | extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); | ||
101 | extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | ||
102 | |||
103 | #define MAX_SBS_BAT 4 | ||
104 | #define ACPI_SBS_BLOCK_MAX 32 | ||
105 | |||
106 | #define ACPI_SBS_SMBUS_READ 1 | ||
107 | #define ACPI_SBS_SMBUS_WRITE 2 | ||
108 | |||
109 | #define ACPI_SBS_WORD_DATA 1 | ||
110 | #define ACPI_SBS_BLOCK_DATA 2 | ||
111 | |||
86 | static struct semaphore sbs_sem; | 112 | static struct semaphore sbs_sem; |
87 | 113 | ||
88 | #define UPDATE_MODE QUEUE_UPDATE_MODE | 114 | #define UPDATE_MODE QUEUE_UPDATE_MODE |
@@ -105,7 +131,6 @@ module_param(update_time2, int, 0); | |||
105 | 131 | ||
106 | static int acpi_sbs_add(struct acpi_device *device); | 132 | static int acpi_sbs_add(struct acpi_device *device); |
107 | static int acpi_sbs_remove(struct acpi_device *device, int type); | 133 | static int acpi_sbs_remove(struct acpi_device *device, int type); |
108 | static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus); | ||
109 | static void acpi_sbs_update_queue(void *data); | 134 | static void acpi_sbs_update_queue(void *data); |
110 | 135 | ||
111 | static struct acpi_driver acpi_sbs_driver = { | 136 | static struct acpi_driver acpi_sbs_driver = { |
@@ -126,9 +151,9 @@ struct acpi_battery_info { | |||
126 | int vscale; | 151 | int vscale; |
127 | int ipscale; | 152 | int ipscale; |
128 | s16 serial_number; | 153 | s16 serial_number; |
129 | char manufacturer_name[I2C_SMBUS_BLOCK_MAX + 3]; | 154 | char manufacturer_name[ACPI_SBS_BLOCK_MAX + 3]; |
130 | char device_name[I2C_SMBUS_BLOCK_MAX + 3]; | 155 | char device_name[ACPI_SBS_BLOCK_MAX + 3]; |
131 | char device_chemistry[I2C_SMBUS_BLOCK_MAX + 3]; | 156 | char device_chemistry[ACPI_SBS_BLOCK_MAX + 3]; |
132 | }; | 157 | }; |
133 | 158 | ||
134 | struct acpi_battery_state { | 159 | struct acpi_battery_state { |
@@ -158,8 +183,8 @@ struct acpi_battery { | |||
158 | 183 | ||
159 | struct acpi_sbs { | 184 | struct acpi_sbs { |
160 | acpi_handle handle; | 185 | acpi_handle handle; |
186 | int base; | ||
161 | struct acpi_device *device; | 187 | struct acpi_device *device; |
162 | struct acpi_ec_smbus *smbus; | ||
163 | int sbsm_present; | 188 | int sbsm_present; |
164 | int sbsm_batteries_supported; | 189 | int sbsm_batteries_supported; |
165 | int ac_present; | 190 | int ac_present; |
@@ -172,6 +197,14 @@ struct acpi_sbs { | |||
172 | struct timer_list update_timer; | 197 | struct timer_list update_timer; |
173 | }; | 198 | }; |
174 | 199 | ||
200 | union sbs_rw_data { | ||
201 | u16 word; | ||
202 | u8 block[ACPI_SBS_BLOCK_MAX + 2]; | ||
203 | }; | ||
204 | |||
205 | static int acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr, | ||
206 | char read_write, u8 command, int size, | ||
207 | union sbs_rw_data *data); | ||
175 | static void acpi_update_delay(struct acpi_sbs *sbs); | 208 | static void acpi_update_delay(struct acpi_sbs *sbs); |
176 | static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type); | 209 | static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type); |
177 | 210 | ||
@@ -179,155 +212,172 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type); | |||
179 | SMBus Communication | 212 | SMBus Communication |
180 | -------------------------------------------------------------------------- */ | 213 | -------------------------------------------------------------------------- */ |
181 | 214 | ||
182 | static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus) | 215 | static int acpi_ec_sbs_read(struct acpi_sbs *sbs, u8 address, u8 * data) |
183 | { | 216 | { |
184 | union i2c_smbus_data data; | 217 | u8 val; |
185 | int result = 0; | 218 | int err; |
186 | char *err_str; | ||
187 | int err_number; | ||
188 | 219 | ||
189 | data.word = 0; | 220 | err = ec_read(sbs->base + address, &val); |
221 | if (!err) { | ||
222 | *data = val; | ||
223 | } | ||
224 | xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP); | ||
225 | return (err); | ||
226 | } | ||
190 | 227 | ||
191 | result = smbus->adapter.algo-> | 228 | static int acpi_ec_sbs_write(struct acpi_sbs *sbs, u8 address, u8 data) |
192 | smbus_xfer(&smbus->adapter, | 229 | { |
193 | ACPI_SB_SMBUS_ADDR, | 230 | int err; |
194 | 0, I2C_SMBUS_READ, 0x16, I2C_SMBUS_BLOCK_DATA, &data); | ||
195 | 231 | ||
196 | err_number = (data.word & 0x000f); | 232 | err = ec_write(sbs->base + address, data); |
233 | return (err); | ||
234 | } | ||
197 | 235 | ||
198 | switch (data.word & 0x000f) { | 236 | static int |
199 | case 0x0000: | 237 | acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr, |
200 | err_str = "unexpected bus error"; | 238 | char read_write, u8 command, int size, |
201 | break; | 239 | union sbs_rw_data *data) |
202 | case 0x0001: | 240 | { |
203 | err_str = "busy"; | 241 | unsigned char protocol, len = 0, temp[2] = { 0, 0 }; |
204 | break; | 242 | int i; |
205 | case 0x0002: | 243 | |
206 | err_str = "reserved command"; | 244 | if (read_write == ACPI_SBS_SMBUS_READ) { |
207 | break; | 245 | protocol = ACPI_EC_SMB_PRTCL_READ; |
208 | case 0x0003: | 246 | } else { |
209 | err_str = "unsupported command"; | 247 | protocol = ACPI_EC_SMB_PRTCL_WRITE; |
210 | break; | 248 | } |
211 | case 0x0004: | 249 | |
212 | err_str = "access denied"; | 250 | switch (size) { |
251 | |||
252 | case ACPI_SBS_WORD_DATA: | ||
253 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command); | ||
254 | if (read_write == ACPI_SBS_SMBUS_WRITE) { | ||
255 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA, data->word); | ||
256 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + 1, | ||
257 | data->word >> 8); | ||
258 | } | ||
259 | protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA; | ||
213 | break; | 260 | break; |
214 | case 0x0005: | 261 | case ACPI_SBS_BLOCK_DATA: |
215 | err_str = "overflow/underflow"; | 262 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command); |
263 | if (read_write == ACPI_SBS_SMBUS_WRITE) { | ||
264 | len = min_t(u8, data->block[0], 32); | ||
265 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_BCNT, len); | ||
266 | for (i = 0; i < len; i++) | ||
267 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + i, | ||
268 | data->block[i + 1]); | ||
269 | } | ||
270 | protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA; | ||
216 | break; | 271 | break; |
217 | case 0x0006: | 272 | default: |
218 | err_str = "bad size"; | 273 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
274 | "unsupported transaction %d\n", size)); | ||
275 | return (-1); | ||
276 | } | ||
277 | |||
278 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_ADDR, addr << 1); | ||
279 | acpi_ec_sbs_write(sbs, ACPI_EC_SMB_PRTCL, protocol); | ||
280 | |||
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_SLEEP1); | ||
285 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp); | ||
286 | } | ||
287 | if (~temp[0] & ACPI_EC_SMB_STS_DONE) { | ||
288 | xmsleep(ACPI_EC_SMB_ACCESS_SLEEP2); | ||
289 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp); | ||
290 | } | ||
291 | if ((~temp[0] & ACPI_EC_SMB_STS_DONE) | ||
292 | || (temp[0] & ACPI_EC_SMB_STS_STATUS)) { | ||
293 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, | ||
294 | "transaction %d error\n", size)); | ||
295 | return (-1); | ||
296 | } | ||
297 | |||
298 | if (read_write == ACPI_SBS_SMBUS_WRITE) { | ||
299 | return (0); | ||
300 | } | ||
301 | |||
302 | switch (size) { | ||
303 | |||
304 | case ACPI_SBS_WORD_DATA: | ||
305 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA, temp); | ||
306 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + 1, temp + 1); | ||
307 | data->word = (temp[1] << 8) | temp[0]; | ||
219 | break; | 308 | break; |
220 | case 0x0007: | 309 | |
221 | err_str = "unknown error"; | 310 | case ACPI_SBS_BLOCK_DATA: |
311 | len = 0; | ||
312 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_BCNT, &len); | ||
313 | len = min_t(u8, len, 32); | ||
314 | for (i = 0; i < len; i++) | ||
315 | acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + i, | ||
316 | data->block + i + 1); | ||
317 | data->block[0] = len; | ||
222 | break; | 318 | break; |
223 | default: | 319 | default: |
224 | err_str = "unrecognized error"; | 320 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, |
321 | "unsupported transaction %d\n", size)); | ||
322 | return (-1); | ||
225 | } | 323 | } |
226 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 324 | |
227 | "%s: ret %i, err %i\n", err_str, result, err_number)); | 325 | return (0); |
228 | } | 326 | } |
229 | 327 | ||
230 | static int | 328 | static int |
231 | acpi_sbs_smbus_read_word(struct acpi_ec_smbus *smbus, int addr, int func, | 329 | acpi_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 | { | 330 | { |
235 | union i2c_smbus_data data; | 331 | union sbs_rw_data data; |
236 | int result = 0; | 332 | int result = 0; |
237 | int i; | ||
238 | 333 | ||
239 | if (err_handler == NULL) { | 334 | result = acpi_ec_sbs_access(sbs, addr, |
240 | err_handler = acpi_battery_smbus_err_handler; | 335 | ACPI_SBS_SMBUS_READ, func, |
241 | } | 336 | ACPI_SBS_WORD_DATA, &data); |
242 | 337 | if (result) { | |
243 | for (i = 0; i < MAX_SMBUS_ERR; i++) { | 338 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
244 | result = | 339 | "acpi_ec_sbs_access() failed\n")); |
245 | smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, | 340 | } else { |
246 | I2C_SMBUS_READ, func, | 341 | *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 | } | 342 | } |
260 | 343 | ||
261 | return result; | 344 | return result; |
262 | } | 345 | } |
263 | 346 | ||
264 | static int | 347 | static int |
265 | acpi_sbs_smbus_read_str(struct acpi_ec_smbus *smbus, int addr, int func, | 348 | acpi_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 | { | 349 | { |
269 | union i2c_smbus_data data; | 350 | union sbs_rw_data data; |
270 | int result = 0; | 351 | int result = 0; |
271 | int i; | ||
272 | |||
273 | if (err_handler == NULL) { | ||
274 | err_handler = acpi_battery_smbus_err_handler; | ||
275 | } | ||
276 | 352 | ||
277 | for (i = 0; i < MAX_SMBUS_ERR; i++) { | 353 | result = acpi_ec_sbs_access(sbs, addr, |
278 | result = | 354 | ACPI_SBS_SMBUS_READ, func, |
279 | smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, | 355 | ACPI_SBS_BLOCK_DATA, &data); |
280 | I2C_SMBUS_READ, func, | 356 | if (result) { |
281 | I2C_SMBUS_BLOCK_DATA, | 357 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
282 | &data); | 358 | "acpi_ec_sbs_access() failed\n")); |
283 | if (result) { | 359 | } else { |
284 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 360 | strncpy(str, (const char *)data.block + 1, data.block[0]); |
285 | "try %i: smbus->adapter.algo->smbus_xfer() failed\n", | 361 | 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 | } | 362 | } |
297 | 363 | ||
298 | return result; | 364 | return result; |
299 | } | 365 | } |
300 | 366 | ||
301 | static int | 367 | static int |
302 | acpi_sbs_smbus_write_word(struct acpi_ec_smbus *smbus, int addr, int func, | 368 | acpi_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 | { | 369 | { |
306 | union i2c_smbus_data data; | 370 | union sbs_rw_data data; |
307 | int result = 0; | 371 | int result = 0; |
308 | int i; | ||
309 | |||
310 | if (err_handler == NULL) { | ||
311 | err_handler = acpi_battery_smbus_err_handler; | ||
312 | } | ||
313 | 372 | ||
314 | data.word = word; | 373 | data.word = word; |
315 | 374 | ||
316 | for (i = 0; i < MAX_SMBUS_ERR; i++) { | 375 | result = acpi_ec_sbs_access(sbs, addr, |
317 | result = | 376 | ACPI_SBS_SMBUS_WRITE, func, |
318 | smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, | 377 | ACPI_SBS_WORD_DATA, &data); |
319 | I2C_SMBUS_WRITE, func, | 378 | if (result) { |
320 | I2C_SMBUS_WORD_DATA, &data); | 379 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
321 | if (result) { | 380 | "acpi_ec_sbs_access() failed\n")); |
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 | } | 381 | } |
332 | 382 | ||
333 | return result; | 383 | return result; |
@@ -366,12 +416,11 @@ static int acpi_battery_get_present(struct acpi_battery *battery) | |||
366 | int result = 0; | 416 | int result = 0; |
367 | int is_present = 0; | 417 | int is_present = 0; |
368 | 418 | ||
369 | result = acpi_sbs_smbus_read_word(battery->sbs->smbus, | 419 | result = acpi_sbs_read_word(battery->sbs, |
370 | ACPI_SBSM_SMBUS_ADDR, 0x01, | 420 | ACPI_SBSM_SMBUS_ADDR, 0x01, &state); |
371 | &state, NULL); | ||
372 | if (result) { | 421 | if (result) { |
373 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 422 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
374 | "acpi_sbs_smbus_read_word() failed")); | 423 | "acpi_sbs_read_word() failed")); |
375 | } | 424 | } |
376 | if (!result) { | 425 | if (!result) { |
377 | is_present = (state & 0x000f) & (1 << battery->id); | 426 | is_present = (state & 0x000f) & (1 << battery->id); |
@@ -393,7 +442,7 @@ static int acpi_ac_is_present(struct acpi_sbs *sbs) | |||
393 | 442 | ||
394 | static int acpi_battery_select(struct acpi_battery *battery) | 443 | static int acpi_battery_select(struct acpi_battery *battery) |
395 | { | 444 | { |
396 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 445 | struct acpi_sbs *sbs = battery->sbs; |
397 | int result = 0; | 446 | int result = 0; |
398 | s16 state; | 447 | s16 state; |
399 | int foo; | 448 | int foo; |
@@ -405,21 +454,19 @@ static int acpi_battery_select(struct acpi_battery *battery) | |||
405 | * it causes charging to halt on SBSELs */ | 454 | * it causes charging to halt on SBSELs */ |
406 | 455 | ||
407 | result = | 456 | result = |
408 | acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01, | 457 | acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, &state); |
409 | &state, NULL); | ||
410 | if (result) { | 458 | if (result) { |
411 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 459 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
412 | "acpi_sbs_smbus_read_word() failed\n")); | 460 | "acpi_sbs_read_word() failed\n")); |
413 | goto end; | 461 | goto end; |
414 | } | 462 | } |
415 | 463 | ||
416 | foo = (state & 0x0fff) | (1 << (battery->id + 12)); | 464 | foo = (state & 0x0fff) | (1 << (battery->id + 12)); |
417 | result = | 465 | result = |
418 | acpi_sbs_smbus_write_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01, | 466 | acpi_sbs_write_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, foo); |
419 | foo, NULL); | ||
420 | if (result) { | 467 | if (result) { |
421 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 468 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
422 | "acpi_sbs_smbus_write_word() failed\n")); | 469 | "acpi_sbs_write_word() failed\n")); |
423 | goto end; | 470 | goto end; |
424 | } | 471 | } |
425 | } | 472 | } |
@@ -430,15 +477,14 @@ static int acpi_battery_select(struct acpi_battery *battery) | |||
430 | 477 | ||
431 | static int acpi_sbsm_get_info(struct acpi_sbs *sbs) | 478 | static int acpi_sbsm_get_info(struct acpi_sbs *sbs) |
432 | { | 479 | { |
433 | struct acpi_ec_smbus *smbus = sbs->smbus; | ||
434 | int result = 0; | 480 | int result = 0; |
435 | s16 battery_system_info; | 481 | s16 battery_system_info; |
436 | 482 | ||
437 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x04, | 483 | result = acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x04, |
438 | &battery_system_info, NULL); | 484 | &battery_system_info); |
439 | if (result) { | 485 | if (result) { |
440 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 486 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
441 | "acpi_sbs_smbus_read_word() failed\n")); | 487 | "acpi_sbs_read_word() failed\n")); |
442 | goto end; | 488 | goto end; |
443 | } | 489 | } |
444 | 490 | ||
@@ -451,53 +497,48 @@ static int acpi_sbsm_get_info(struct acpi_sbs *sbs) | |||
451 | 497 | ||
452 | static int acpi_battery_get_info(struct acpi_battery *battery) | 498 | static int acpi_battery_get_info(struct acpi_battery *battery) |
453 | { | 499 | { |
454 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 500 | struct acpi_sbs *sbs = battery->sbs; |
455 | int result = 0; | 501 | int result = 0; |
456 | s16 battery_mode; | 502 | s16 battery_mode; |
457 | s16 specification_info; | 503 | s16 specification_info; |
458 | 504 | ||
459 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03, | 505 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03, |
460 | &battery_mode, | 506 | &battery_mode); |
461 | &acpi_battery_smbus_err_handler); | ||
462 | if (result) { | 507 | if (result) { |
463 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 508 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
464 | "acpi_sbs_smbus_read_word() failed\n")); | 509 | "acpi_sbs_read_word() failed\n")); |
465 | goto end; | 510 | goto end; |
466 | } | 511 | } |
467 | battery->info.capacity_mode = (battery_mode & 0x8000) >> 15; | 512 | battery->info.capacity_mode = (battery_mode & 0x8000) >> 15; |
468 | 513 | ||
469 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x10, | 514 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x10, |
470 | &battery->info.full_charge_capacity, | 515 | &battery->info.full_charge_capacity); |
471 | &acpi_battery_smbus_err_handler); | ||
472 | if (result) { | 516 | if (result) { |
473 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 517 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
474 | "acpi_sbs_smbus_read_word() failed\n")); | 518 | "acpi_sbs_read_word() failed\n")); |
475 | goto end; | 519 | goto end; |
476 | } | 520 | } |
477 | 521 | ||
478 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x18, | 522 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x18, |
479 | &battery->info.design_capacity, | 523 | &battery->info.design_capacity); |
480 | &acpi_battery_smbus_err_handler); | ||
481 | 524 | ||
482 | if (result) { | 525 | if (result) { |
483 | goto end; | 526 | goto end; |
484 | } | 527 | } |
485 | 528 | ||
486 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x19, | 529 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x19, |
487 | &battery->info.design_voltage, | 530 | &battery->info.design_voltage); |
488 | &acpi_battery_smbus_err_handler); | ||
489 | if (result) { | 531 | if (result) { |
490 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 532 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
491 | "acpi_sbs_smbus_read_word() failed\n")); | 533 | "acpi_sbs_read_word() failed\n")); |
492 | goto end; | 534 | goto end; |
493 | } | 535 | } |
494 | 536 | ||
495 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1a, | 537 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1a, |
496 | &specification_info, | 538 | &specification_info); |
497 | &acpi_battery_smbus_err_handler); | ||
498 | if (result) { | 539 | if (result) { |
499 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 540 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
500 | "acpi_sbs_smbus_read_word() failed\n")); | 541 | "acpi_sbs_read_word() failed\n")); |
501 | goto end; | 542 | goto end; |
502 | } | 543 | } |
503 | 544 | ||
@@ -529,37 +570,33 @@ static int acpi_battery_get_info(struct acpi_battery *battery) | |||
529 | battery->info.ipscale = 1; | 570 | battery->info.ipscale = 1; |
530 | } | 571 | } |
531 | 572 | ||
532 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1c, | 573 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1c, |
533 | &battery->info.serial_number, | 574 | &battery->info.serial_number); |
534 | &acpi_battery_smbus_err_handler); | ||
535 | if (result) { | 575 | if (result) { |
536 | goto end; | 576 | goto end; |
537 | } | 577 | } |
538 | 578 | ||
539 | result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x20, | 579 | result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x20, |
540 | battery->info.manufacturer_name, | 580 | battery->info.manufacturer_name); |
541 | &acpi_battery_smbus_err_handler); | ||
542 | if (result) { | 581 | if (result) { |
543 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 582 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
544 | "acpi_sbs_smbus_read_str() failed\n")); | 583 | "acpi_sbs_read_str() failed\n")); |
545 | goto end; | 584 | goto end; |
546 | } | 585 | } |
547 | 586 | ||
548 | result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x21, | 587 | result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x21, |
549 | battery->info.device_name, | 588 | battery->info.device_name); |
550 | &acpi_battery_smbus_err_handler); | ||
551 | if (result) { | 589 | if (result) { |
552 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 590 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
553 | "acpi_sbs_smbus_read_str() failed\n")); | 591 | "acpi_sbs_read_str() failed\n")); |
554 | goto end; | 592 | goto end; |
555 | } | 593 | } |
556 | 594 | ||
557 | result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x22, | 595 | result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x22, |
558 | battery->info.device_chemistry, | 596 | battery->info.device_chemistry); |
559 | &acpi_battery_smbus_err_handler); | ||
560 | if (result) { | 597 | if (result) { |
561 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 598 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
562 | "acpi_sbs_smbus_read_str() failed\n")); | 599 | "acpi_sbs_read_str() failed\n")); |
563 | goto end; | 600 | goto end; |
564 | } | 601 | } |
565 | 602 | ||
@@ -579,66 +616,60 @@ static void acpi_update_delay(struct acpi_sbs *sbs) | |||
579 | 616 | ||
580 | static int acpi_battery_get_state(struct acpi_battery *battery) | 617 | static int acpi_battery_get_state(struct acpi_battery *battery) |
581 | { | 618 | { |
582 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 619 | struct acpi_sbs *sbs = battery->sbs; |
583 | int result = 0; | 620 | int result = 0; |
584 | 621 | ||
585 | acpi_update_delay(battery->sbs); | 622 | acpi_update_delay(battery->sbs); |
586 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x09, | 623 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x09, |
587 | &battery->state.voltage, | 624 | &battery->state.voltage); |
588 | &acpi_battery_smbus_err_handler); | ||
589 | if (result) { | 625 | if (result) { |
590 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 626 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
591 | "acpi_sbs_smbus_read_word() failed\n")); | 627 | "acpi_sbs_read_word() failed\n")); |
592 | goto end; | 628 | goto end; |
593 | } | 629 | } |
594 | 630 | ||
595 | acpi_update_delay(battery->sbs); | 631 | acpi_update_delay(battery->sbs); |
596 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0a, | 632 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0a, |
597 | &battery->state.amperage, | 633 | &battery->state.amperage); |
598 | &acpi_battery_smbus_err_handler); | ||
599 | if (result) { | 634 | if (result) { |
600 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 635 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
601 | "acpi_sbs_smbus_read_word() failed\n")); | 636 | "acpi_sbs_read_word() failed\n")); |
602 | goto end; | 637 | goto end; |
603 | } | 638 | } |
604 | 639 | ||
605 | acpi_update_delay(battery->sbs); | 640 | acpi_update_delay(battery->sbs); |
606 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0f, | 641 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0f, |
607 | &battery->state.remaining_capacity, | 642 | &battery->state.remaining_capacity); |
608 | &acpi_battery_smbus_err_handler); | ||
609 | if (result) { | 643 | if (result) { |
610 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 644 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
611 | "acpi_sbs_smbus_read_word() failed\n")); | 645 | "acpi_sbs_read_word() failed\n")); |
612 | goto end; | 646 | goto end; |
613 | } | 647 | } |
614 | 648 | ||
615 | acpi_update_delay(battery->sbs); | 649 | acpi_update_delay(battery->sbs); |
616 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x12, | 650 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x12, |
617 | &battery->state.average_time_to_empty, | 651 | &battery->state.average_time_to_empty); |
618 | &acpi_battery_smbus_err_handler); | ||
619 | if (result) { | 652 | if (result) { |
620 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 653 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
621 | "acpi_sbs_smbus_read_word() failed\n")); | 654 | "acpi_sbs_read_word() failed\n")); |
622 | goto end; | 655 | goto end; |
623 | } | 656 | } |
624 | 657 | ||
625 | acpi_update_delay(battery->sbs); | 658 | acpi_update_delay(battery->sbs); |
626 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x13, | 659 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x13, |
627 | &battery->state.average_time_to_full, | 660 | &battery->state.average_time_to_full); |
628 | &acpi_battery_smbus_err_handler); | ||
629 | if (result) { | 661 | if (result) { |
630 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 662 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
631 | "acpi_sbs_smbus_read_word() failed\n")); | 663 | "acpi_sbs_read_word() failed\n")); |
632 | goto end; | 664 | goto end; |
633 | } | 665 | } |
634 | 666 | ||
635 | acpi_update_delay(battery->sbs); | 667 | acpi_update_delay(battery->sbs); |
636 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x16, | 668 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x16, |
637 | &battery->state.battery_status, | 669 | &battery->state.battery_status); |
638 | &acpi_battery_smbus_err_handler); | ||
639 | if (result) { | 670 | if (result) { |
640 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 671 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
641 | "acpi_sbs_smbus_read_word() failed\n")); | 672 | "acpi_sbs_read_word() failed\n")); |
642 | goto end; | 673 | goto end; |
643 | } | 674 | } |
644 | 675 | ||
@@ -650,15 +681,14 @@ static int acpi_battery_get_state(struct acpi_battery *battery) | |||
650 | 681 | ||
651 | static int acpi_battery_get_alarm(struct acpi_battery *battery) | 682 | static int acpi_battery_get_alarm(struct acpi_battery *battery) |
652 | { | 683 | { |
653 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 684 | struct acpi_sbs *sbs = battery->sbs; |
654 | int result = 0; | 685 | int result = 0; |
655 | 686 | ||
656 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, | 687 | result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, |
657 | &battery->alarm.remaining_capacity, | 688 | &battery->alarm.remaining_capacity); |
658 | &acpi_battery_smbus_err_handler); | ||
659 | if (result) { | 689 | if (result) { |
660 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 690 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
661 | "acpi_sbs_smbus_read_word() failed\n")); | 691 | "acpi_sbs_read_word() failed\n")); |
662 | goto end; | 692 | goto end; |
663 | } | 693 | } |
664 | 694 | ||
@@ -672,7 +702,7 @@ static int acpi_battery_get_alarm(struct acpi_battery *battery) | |||
672 | static int acpi_battery_set_alarm(struct acpi_battery *battery, | 702 | static int acpi_battery_set_alarm(struct acpi_battery *battery, |
673 | unsigned long alarm) | 703 | unsigned long alarm) |
674 | { | 704 | { |
675 | struct acpi_ec_smbus *smbus = battery->sbs->smbus; | 705 | struct acpi_sbs *sbs = battery->sbs; |
676 | int result = 0; | 706 | int result = 0; |
677 | s16 battery_mode; | 707 | s16 battery_mode; |
678 | int foo; | 708 | int foo; |
@@ -688,33 +718,29 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery, | |||
688 | 718 | ||
689 | if (alarm > 0) { | 719 | if (alarm > 0) { |
690 | result = | 720 | result = |
691 | acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03, | 721 | acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03, |
692 | &battery_mode, | 722 | &battery_mode); |
693 | &acpi_battery_smbus_err_handler); | ||
694 | if (result) { | 723 | if (result) { |
695 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 724 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
696 | "acpi_sbs_smbus_read_word() failed\n")); | 725 | "acpi_sbs_read_word() failed\n")); |
697 | goto end; | 726 | goto end; |
698 | } | 727 | } |
699 | 728 | ||
700 | result = | 729 | result = |
701 | acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, | 730 | acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, |
702 | battery_mode & 0xbfff, | 731 | battery_mode & 0xbfff); |
703 | &acpi_battery_smbus_err_handler); | ||
704 | if (result) { | 732 | if (result) { |
705 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 733 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
706 | "acpi_sbs_smbus_write_word() failed\n")); | 734 | "acpi_sbs_write_word() failed\n")); |
707 | goto end; | 735 | goto end; |
708 | } | 736 | } |
709 | } | 737 | } |
710 | 738 | ||
711 | foo = alarm / (battery->info.capacity_mode ? 10 : 1); | 739 | foo = alarm / (battery->info.capacity_mode ? 10 : 1); |
712 | result = acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, | 740 | result = acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, foo); |
713 | foo, | ||
714 | &acpi_battery_smbus_err_handler); | ||
715 | if (result) { | 741 | if (result) { |
716 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 742 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
717 | "acpi_sbs_smbus_write_word() failed\n")); | 743 | "acpi_sbs_write_word() failed\n")); |
718 | goto end; | 744 | goto end; |
719 | } | 745 | } |
720 | 746 | ||
@@ -732,12 +758,11 @@ static int acpi_battery_set_mode(struct acpi_battery *battery) | |||
732 | goto end; | 758 | goto end; |
733 | } | 759 | } |
734 | 760 | ||
735 | result = acpi_sbs_smbus_read_word(battery->sbs->smbus, | 761 | result = acpi_sbs_read_word(battery->sbs, |
736 | ACPI_SB_SMBUS_ADDR, 0x03, | 762 | ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode); |
737 | &battery_mode, NULL); | ||
738 | if (result) { | 763 | if (result) { |
739 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 764 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
740 | "acpi_sbs_smbus_read_word() failed\n")); | 765 | "acpi_sbs_read_word() failed\n")); |
741 | goto end; | 766 | goto end; |
742 | } | 767 | } |
743 | 768 | ||
@@ -746,21 +771,19 @@ static int acpi_battery_set_mode(struct acpi_battery *battery) | |||
746 | } else { | 771 | } else { |
747 | battery_mode |= 0x8000; | 772 | battery_mode |= 0x8000; |
748 | } | 773 | } |
749 | result = acpi_sbs_smbus_write_word(battery->sbs->smbus, | 774 | result = acpi_sbs_write_word(battery->sbs, |
750 | ACPI_SB_SMBUS_ADDR, 0x03, | 775 | ACPI_SB_SMBUS_ADDR, 0x03, battery_mode); |
751 | battery_mode, NULL); | ||
752 | if (result) { | 776 | if (result) { |
753 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 777 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
754 | "acpi_sbs_smbus_write_word() failed\n")); | 778 | "acpi_sbs_write_word() failed\n")); |
755 | goto end; | 779 | goto end; |
756 | } | 780 | } |
757 | 781 | ||
758 | result = acpi_sbs_smbus_read_word(battery->sbs->smbus, | 782 | result = acpi_sbs_read_word(battery->sbs, |
759 | ACPI_SB_SMBUS_ADDR, 0x03, | 783 | ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode); |
760 | &battery_mode, NULL); | ||
761 | if (result) { | 784 | if (result) { |
762 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 785 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
763 | "acpi_sbs_smbus_read_word() failed\n")); | 786 | "acpi_sbs_read_word() failed\n")); |
764 | goto end; | 787 | goto end; |
765 | } | 788 | } |
766 | 789 | ||
@@ -813,16 +836,15 @@ static int acpi_battery_init(struct acpi_battery *battery) | |||
813 | 836 | ||
814 | static int acpi_ac_get_present(struct acpi_sbs *sbs) | 837 | static int acpi_ac_get_present(struct acpi_sbs *sbs) |
815 | { | 838 | { |
816 | struct acpi_ec_smbus *smbus = sbs->smbus; | ||
817 | int result = 0; | 839 | int result = 0; |
818 | s16 charger_status; | 840 | s16 charger_status; |
819 | 841 | ||
820 | result = acpi_sbs_smbus_read_word(smbus, ACPI_SBC_SMBUS_ADDR, 0x13, | 842 | result = acpi_sbs_read_word(sbs, ACPI_SBC_SMBUS_ADDR, 0x13, |
821 | &charger_status, NULL); | 843 | &charger_status); |
822 | 844 | ||
823 | if (result) { | 845 | if (result) { |
824 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 846 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
825 | "acpi_sbs_smbus_read_word() failed\n")); | 847 | "acpi_sbs_read_word() failed\n")); |
826 | goto end; | 848 | goto end; |
827 | } | 849 | } |
828 | 850 | ||
@@ -1567,38 +1589,27 @@ static void acpi_sbs_update_queue(void *data) | |||
1567 | static int acpi_sbs_add(struct acpi_device *device) | 1589 | static int acpi_sbs_add(struct acpi_device *device) |
1568 | { | 1590 | { |
1569 | struct acpi_sbs *sbs = NULL; | 1591 | struct acpi_sbs *sbs = NULL; |
1570 | struct acpi_ec_hc *ec_hc = NULL; | 1592 | int result; |
1571 | int result, remove_result = 0; | ||
1572 | unsigned long sbs_obj; | 1593 | unsigned long sbs_obj; |
1573 | int id, cnt; | 1594 | int id; |
1574 | acpi_status status = AE_OK; | 1595 | acpi_status status = AE_OK; |
1596 | unsigned long val; | ||
1597 | |||
1598 | status = | ||
1599 | acpi_evaluate_integer(device->parent->handle, "_EC", NULL, &val); | ||
1600 | if (ACPI_FAILURE(status)) { | ||
1601 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Error obtaining _EC\n")); | ||
1602 | return -EIO; | ||
1603 | } | ||
1575 | 1604 | ||
1576 | sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); | 1605 | sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); |
1577 | if (!sbs) { | 1606 | if (!sbs) { |
1578 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n")); | 1607 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n")); |
1579 | return -ENOMEM; | 1608 | return -ENOMEM; |
1580 | } | 1609 | } |
1581 | 1610 | sbs->base = (val & 0xff00ull) >> 8; | |
1582 | cnt = 0; | ||
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 | |||
1592 | if (!ec_hc) { | ||
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 | 1611 | ||
1600 | sbs->device = device; | 1612 | sbs->device = device; |
1601 | sbs->smbus = ec_hc->smbus; | ||
1602 | 1613 | ||
1603 | strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); | 1614 | strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); |
1604 | strcpy(acpi_device_class(device), ACPI_SBS_CLASS); | 1615 | strcpy(acpi_device_class(device), ACPI_SBS_CLASS); |
@@ -1669,11 +1680,7 @@ static int acpi_sbs_add(struct acpi_device *device) | |||
1669 | 1680 | ||
1670 | end: | 1681 | end: |
1671 | if (result) { | 1682 | if (result) { |
1672 | remove_result = acpi_sbs_remove(device, 0); | 1683 | acpi_sbs_remove(device, 0); |
1673 | if (remove_result) { | ||
1674 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
1675 | "acpi_sbs_remove() failed\n")); | ||
1676 | } | ||
1677 | } | 1684 | } |
1678 | 1685 | ||
1679 | return result; | 1686 | return result; |
@@ -1707,6 +1714,8 @@ int acpi_sbs_remove(struct acpi_device *device, int type) | |||
1707 | 1714 | ||
1708 | acpi_ac_remove(sbs); | 1715 | acpi_ac_remove(sbs); |
1709 | 1716 | ||
1717 | acpi_driver_data(device) = NULL; | ||
1718 | |||
1710 | kfree(sbs); | 1719 | kfree(sbs); |
1711 | 1720 | ||
1712 | return 0; | 1721 | return 0; |