diff options
Diffstat (limited to 'drivers/acpi/ec.c')
-rw-r--r-- | drivers/acpi/ec.c | 893 |
1 files changed, 722 insertions, 171 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index fca4140a50a9..2dadb7f63269 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c | |||
@@ -59,76 +59,185 @@ ACPI_MODULE_NAME ("acpi_ec") | |||
59 | #define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ | 59 | #define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ |
60 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ | 60 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ |
61 | 61 | ||
62 | #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */ | ||
63 | #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */ | ||
64 | |||
62 | #define ACPI_EC_COMMAND_READ 0x80 | 65 | #define ACPI_EC_COMMAND_READ 0x80 |
63 | #define ACPI_EC_COMMAND_WRITE 0x81 | 66 | #define ACPI_EC_COMMAND_WRITE 0x81 |
64 | #define ACPI_EC_BURST_ENABLE 0x82 | 67 | #define ACPI_EC_BURST_ENABLE 0x82 |
65 | #define ACPI_EC_BURST_DISABLE 0x83 | 68 | #define ACPI_EC_BURST_DISABLE 0x83 |
66 | #define ACPI_EC_COMMAND_QUERY 0x84 | 69 | #define ACPI_EC_COMMAND_QUERY 0x84 |
67 | 70 | ||
68 | static int acpi_ec_add (struct acpi_device *device); | 71 | #define EC_POLLING 0xFF |
72 | #define EC_BURST 0x00 | ||
73 | |||
74 | |||
69 | static int acpi_ec_remove (struct acpi_device *device, int type); | 75 | static int acpi_ec_remove (struct acpi_device *device, int type); |
70 | static int acpi_ec_start (struct acpi_device *device); | 76 | static int acpi_ec_start (struct acpi_device *device); |
71 | static int acpi_ec_stop (struct acpi_device *device, int type); | 77 | static int acpi_ec_stop (struct acpi_device *device, int type); |
78 | static int acpi_ec_burst_add ( struct acpi_device *device); | ||
72 | 79 | ||
73 | static struct acpi_driver acpi_ec_driver = { | 80 | static struct acpi_driver acpi_ec_driver = { |
74 | .name = ACPI_EC_DRIVER_NAME, | 81 | .name = ACPI_EC_DRIVER_NAME, |
75 | .class = ACPI_EC_CLASS, | 82 | .class = ACPI_EC_CLASS, |
76 | .ids = ACPI_EC_HID, | 83 | .ids = ACPI_EC_HID, |
77 | .ops = { | 84 | .ops = { |
78 | .add = acpi_ec_add, | 85 | .add = acpi_ec_burst_add, |
79 | .remove = acpi_ec_remove, | 86 | .remove = acpi_ec_remove, |
80 | .start = acpi_ec_start, | 87 | .start = acpi_ec_start, |
81 | .stop = acpi_ec_stop, | 88 | .stop = acpi_ec_stop, |
82 | }, | 89 | }, |
83 | }; | 90 | }; |
84 | 91 | union acpi_ec { | |
85 | struct acpi_ec { | 92 | struct { |
86 | acpi_handle handle; | 93 | u32 mode; |
87 | unsigned long uid; | 94 | acpi_handle handle; |
88 | unsigned long gpe_bit; | 95 | unsigned long uid; |
89 | struct acpi_generic_address status_addr; | 96 | unsigned long gpe_bit; |
90 | struct acpi_generic_address command_addr; | 97 | struct acpi_generic_address status_addr; |
91 | struct acpi_generic_address data_addr; | 98 | struct acpi_generic_address command_addr; |
92 | unsigned long global_lock; | 99 | struct acpi_generic_address data_addr; |
93 | unsigned int expect_event; | 100 | unsigned long global_lock; |
94 | atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/ | 101 | } common; |
95 | atomic_t pending_gpe; | 102 | |
96 | struct semaphore sem; | 103 | struct { |
97 | wait_queue_head_t wait; | 104 | u32 mode; |
105 | acpi_handle handle; | ||
106 | unsigned long uid; | ||
107 | unsigned long gpe_bit; | ||
108 | struct acpi_generic_address status_addr; | ||
109 | struct acpi_generic_address command_addr; | ||
110 | struct acpi_generic_address data_addr; | ||
111 | unsigned long global_lock; | ||
112 | unsigned int expect_event; | ||
113 | atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/ | ||
114 | atomic_t pending_gpe; | ||
115 | struct semaphore sem; | ||
116 | wait_queue_head_t wait; | ||
117 | }burst; | ||
118 | |||
119 | struct { | ||
120 | u32 mode; | ||
121 | acpi_handle handle; | ||
122 | unsigned long uid; | ||
123 | unsigned long gpe_bit; | ||
124 | struct acpi_generic_address status_addr; | ||
125 | struct acpi_generic_address command_addr; | ||
126 | struct acpi_generic_address data_addr; | ||
127 | unsigned long global_lock; | ||
128 | spinlock_t lock; | ||
129 | }polling; | ||
98 | }; | 130 | }; |
99 | 131 | ||
132 | static int acpi_ec_polling_wait ( union acpi_ec *ec, u8 event); | ||
133 | static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event); | ||
134 | static int acpi_ec_polling_read ( union acpi_ec *ec, u8 address, u32 *data); | ||
135 | static int acpi_ec_burst_read( union acpi_ec *ec, u8 address, u32 *data); | ||
136 | static int acpi_ec_polling_write ( union acpi_ec *ec, u8 address, u8 data); | ||
137 | static int acpi_ec_burst_write ( union acpi_ec *ec, u8 address, u8 data); | ||
138 | static int acpi_ec_polling_query ( union acpi_ec *ec, u32 *data); | ||
139 | static int acpi_ec_burst_query ( union acpi_ec *ec, u32 *data); | ||
140 | static void acpi_ec_gpe_polling_query ( void *ec_cxt); | ||
141 | static void acpi_ec_gpe_burst_query ( void *ec_cxt); | ||
142 | static u32 acpi_ec_gpe_polling_handler ( void *data); | ||
143 | static u32 acpi_ec_gpe_burst_handler ( void *data); | ||
144 | static acpi_status __init | ||
145 | acpi_fake_ecdt_polling_callback ( | ||
146 | acpi_handle handle, | ||
147 | u32 Level, | ||
148 | void *context, | ||
149 | void **retval); | ||
150 | |||
151 | static acpi_status __init | ||
152 | acpi_fake_ecdt_burst_callback ( | ||
153 | acpi_handle handle, | ||
154 | u32 Level, | ||
155 | void *context, | ||
156 | void **retval); | ||
157 | |||
158 | static int __init | ||
159 | acpi_ec_polling_get_real_ecdt(void); | ||
160 | static int __init | ||
161 | acpi_ec_burst_get_real_ecdt(void); | ||
100 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ | 162 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ |
101 | static struct acpi_ec *ec_ecdt; | 163 | static union acpi_ec *ec_ecdt; |
102 | 164 | ||
103 | /* External interfaces use first EC only, so remember */ | 165 | /* External interfaces use first EC only, so remember */ |
104 | static struct acpi_device *first_ec; | 166 | static struct acpi_device *first_ec; |
167 | static int acpi_ec_polling_mode; | ||
105 | 168 | ||
106 | /* -------------------------------------------------------------------------- | 169 | /* -------------------------------------------------------------------------- |
107 | Transaction Management | 170 | Transaction Management |
108 | -------------------------------------------------------------------------- */ | 171 | -------------------------------------------------------------------------- */ |
109 | 172 | ||
110 | static inline u32 acpi_ec_read_status(struct acpi_ec *ec) | 173 | static inline u32 acpi_ec_read_status(union acpi_ec *ec) |
111 | { | 174 | { |
112 | u32 status = 0; | 175 | u32 status = 0; |
113 | 176 | ||
114 | acpi_hw_low_level_read(8, &status, &ec->status_addr); | 177 | acpi_hw_low_level_read(8, &status, &ec->common.status_addr); |
115 | return status; | 178 | return status; |
116 | } | 179 | } |
117 | 180 | ||
118 | static int acpi_ec_wait(struct acpi_ec *ec, unsigned int event) | 181 | static int |
182 | acpi_ec_wait ( | ||
183 | union acpi_ec *ec, | ||
184 | u8 event) | ||
185 | { | ||
186 | if (acpi_ec_polling_mode) | ||
187 | return acpi_ec_polling_wait (ec, event); | ||
188 | else | ||
189 | return acpi_ec_burst_wait (ec, event); | ||
190 | } | ||
191 | |||
192 | static int | ||
193 | acpi_ec_polling_wait ( | ||
194 | union acpi_ec *ec, | ||
195 | u8 event) | ||
196 | { | ||
197 | u32 acpi_ec_status = 0; | ||
198 | u32 i = ACPI_EC_UDELAY_COUNT; | ||
199 | |||
200 | if (!ec) | ||
201 | return -EINVAL; | ||
202 | |||
203 | /* Poll the EC status register waiting for the event to occur. */ | ||
204 | switch (event) { | ||
205 | case ACPI_EC_EVENT_OBF: | ||
206 | do { | ||
207 | acpi_hw_low_level_read(8, &acpi_ec_status, &ec->common.status_addr); | ||
208 | if (acpi_ec_status & ACPI_EC_FLAG_OBF) | ||
209 | return 0; | ||
210 | udelay(ACPI_EC_UDELAY); | ||
211 | } while (--i>0); | ||
212 | break; | ||
213 | case ACPI_EC_EVENT_IBE: | ||
214 | do { | ||
215 | acpi_hw_low_level_read(8, &acpi_ec_status, &ec->common.status_addr); | ||
216 | if (!(acpi_ec_status & ACPI_EC_FLAG_IBF)) | ||
217 | return 0; | ||
218 | udelay(ACPI_EC_UDELAY); | ||
219 | } while (--i>0); | ||
220 | break; | ||
221 | default: | ||
222 | return -EINVAL; | ||
223 | } | ||
224 | |||
225 | return -ETIME; | ||
226 | } | ||
227 | static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event) | ||
119 | { | 228 | { |
120 | int result = 0; | 229 | int result = 0; |
121 | 230 | ||
122 | ACPI_FUNCTION_TRACE("acpi_ec_wait"); | 231 | ACPI_FUNCTION_TRACE("acpi_ec_wait"); |
123 | 232 | ||
124 | ec->expect_event = event; | 233 | ec->burst.expect_event = event; |
125 | smp_mb(); | 234 | smp_mb(); |
126 | 235 | ||
127 | result = wait_event_interruptible_timeout(ec->wait, | 236 | result = wait_event_interruptible_timeout(ec->burst.wait, |
128 | !ec->expect_event, | 237 | !ec->burst.expect_event, |
129 | msecs_to_jiffies(ACPI_EC_DELAY)); | 238 | msecs_to_jiffies(ACPI_EC_DELAY)); |
130 | 239 | ||
131 | ec->expect_event = 0; | 240 | ec->burst.expect_event = 0; |
132 | smp_mb(); | 241 | smp_mb(); |
133 | 242 | ||
134 | if (result < 0){ | 243 | if (result < 0){ |
@@ -160,7 +269,7 @@ static int acpi_ec_wait(struct acpi_ec *ec, unsigned int event) | |||
160 | 269 | ||
161 | static int | 270 | static int |
162 | acpi_ec_enter_burst_mode ( | 271 | acpi_ec_enter_burst_mode ( |
163 | struct acpi_ec *ec) | 272 | union acpi_ec *ec) |
164 | { | 273 | { |
165 | u32 tmp = 0; | 274 | u32 tmp = 0; |
166 | int status = 0; | 275 | int status = 0; |
@@ -170,43 +279,43 @@ acpi_ec_enter_burst_mode ( | |||
170 | status = acpi_ec_read_status(ec); | 279 | status = acpi_ec_read_status(ec); |
171 | if (status != -EINVAL && | 280 | if (status != -EINVAL && |
172 | !(status & ACPI_EC_FLAG_BURST)){ | 281 | !(status & ACPI_EC_FLAG_BURST)){ |
173 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr); | 282 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->common.command_addr); |
174 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 283 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
175 | if (status){ | 284 | if (status){ |
176 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 285 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
177 | return_VALUE(-EINVAL); | 286 | return_VALUE(-EINVAL); |
178 | } | 287 | } |
179 | acpi_hw_low_level_read(8, &tmp, &ec->data_addr); | 288 | acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr); |
180 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 289 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
181 | if(tmp != 0x90 ) {/* Burst ACK byte*/ | 290 | if(tmp != 0x90 ) {/* Burst ACK byte*/ |
182 | return_VALUE(-EINVAL); | 291 | return_VALUE(-EINVAL); |
183 | } | 292 | } |
184 | } | 293 | } |
185 | 294 | ||
186 | atomic_set(&ec->leaving_burst , 0); | 295 | atomic_set(&ec->burst.leaving_burst , 0); |
187 | return_VALUE(0); | 296 | return_VALUE(0); |
188 | } | 297 | } |
189 | 298 | ||
190 | static int | 299 | static int |
191 | acpi_ec_leave_burst_mode ( | 300 | acpi_ec_leave_burst_mode ( |
192 | struct acpi_ec *ec) | 301 | union acpi_ec *ec) |
193 | { | 302 | { |
194 | int status =0; | 303 | int status =0; |
195 | 304 | ||
196 | ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode"); | 305 | ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode"); |
197 | 306 | ||
198 | atomic_set(&ec->leaving_burst , 1); | 307 | atomic_set(&ec->burst.leaving_burst , 1); |
199 | status = acpi_ec_read_status(ec); | 308 | status = acpi_ec_read_status(ec); |
200 | if (status != -EINVAL && | 309 | if (status != -EINVAL && |
201 | (status & ACPI_EC_FLAG_BURST)){ | 310 | (status & ACPI_EC_FLAG_BURST)){ |
202 | acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->command_addr); | 311 | acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->common.command_addr); |
203 | status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); | 312 | status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); |
204 | if (status){ | 313 | if (status){ |
205 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 314 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
206 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n")); | 315 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n")); |
207 | return_VALUE(-EINVAL); | 316 | return_VALUE(-EINVAL); |
208 | } | 317 | } |
209 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 318 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
210 | status = acpi_ec_read_status(ec); | 319 | status = acpi_ec_read_status(ec); |
211 | } | 320 | } |
212 | 321 | ||
@@ -215,7 +324,131 @@ acpi_ec_leave_burst_mode ( | |||
215 | 324 | ||
216 | static int | 325 | static int |
217 | acpi_ec_read ( | 326 | acpi_ec_read ( |
218 | struct acpi_ec *ec, | 327 | union acpi_ec *ec, |
328 | u8 address, | ||
329 | u32 *data) | ||
330 | { | ||
331 | if (acpi_ec_polling_mode) | ||
332 | return acpi_ec_polling_read(ec, address, data); | ||
333 | else | ||
334 | return acpi_ec_burst_read(ec, address, data); | ||
335 | } | ||
336 | static int | ||
337 | acpi_ec_write ( | ||
338 | union acpi_ec *ec, | ||
339 | u8 address, | ||
340 | u8 data) | ||
341 | { | ||
342 | if (acpi_ec_polling_mode) | ||
343 | return acpi_ec_polling_write(ec, address, data); | ||
344 | else | ||
345 | return acpi_ec_burst_write(ec, address, data); | ||
346 | } | ||
347 | static int | ||
348 | acpi_ec_polling_read ( | ||
349 | union acpi_ec *ec, | ||
350 | u8 address, | ||
351 | u32 *data) | ||
352 | { | ||
353 | acpi_status status = AE_OK; | ||
354 | int result = 0; | ||
355 | unsigned long flags = 0; | ||
356 | u32 glk = 0; | ||
357 | |||
358 | ACPI_FUNCTION_TRACE("acpi_ec_read"); | ||
359 | |||
360 | if (!ec || !data) | ||
361 | return_VALUE(-EINVAL); | ||
362 | |||
363 | *data = 0; | ||
364 | |||
365 | if (ec->common.global_lock) { | ||
366 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | ||
367 | if (ACPI_FAILURE(status)) | ||
368 | return_VALUE(-ENODEV); | ||
369 | } | ||
370 | |||
371 | spin_lock_irqsave(&ec->polling.lock, flags); | ||
372 | |||
373 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->common.command_addr); | ||
374 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
375 | if (result) | ||
376 | goto end; | ||
377 | |||
378 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); | ||
379 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | ||
380 | if (result) | ||
381 | goto end; | ||
382 | |||
383 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); | ||
384 | |||
385 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", | ||
386 | *data, address)); | ||
387 | |||
388 | end: | ||
389 | spin_unlock_irqrestore(&ec->polling.lock, flags); | ||
390 | |||
391 | if (ec->common.global_lock) | ||
392 | acpi_release_global_lock(glk); | ||
393 | |||
394 | return_VALUE(result); | ||
395 | } | ||
396 | |||
397 | |||
398 | static int | ||
399 | acpi_ec_polling_write ( | ||
400 | union acpi_ec *ec, | ||
401 | u8 address, | ||
402 | u8 data) | ||
403 | { | ||
404 | int result = 0; | ||
405 | acpi_status status = AE_OK; | ||
406 | unsigned long flags = 0; | ||
407 | u32 glk = 0; | ||
408 | |||
409 | ACPI_FUNCTION_TRACE("acpi_ec_write"); | ||
410 | |||
411 | if (!ec) | ||
412 | return_VALUE(-EINVAL); | ||
413 | |||
414 | if (ec->common.global_lock) { | ||
415 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | ||
416 | if (ACPI_FAILURE(status)) | ||
417 | return_VALUE(-ENODEV); | ||
418 | } | ||
419 | |||
420 | spin_lock_irqsave(&ec->polling.lock, flags); | ||
421 | |||
422 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->common.command_addr); | ||
423 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
424 | if (result) | ||
425 | goto end; | ||
426 | |||
427 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); | ||
428 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
429 | if (result) | ||
430 | goto end; | ||
431 | |||
432 | acpi_hw_low_level_write(8, data, &ec->common.data_addr); | ||
433 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
434 | if (result) | ||
435 | goto end; | ||
436 | |||
437 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n", | ||
438 | data, address)); | ||
439 | |||
440 | end: | ||
441 | spin_unlock_irqrestore(&ec->polling.lock, flags); | ||
442 | |||
443 | if (ec->common.global_lock) | ||
444 | acpi_release_global_lock(glk); | ||
445 | |||
446 | return_VALUE(result); | ||
447 | } | ||
448 | |||
449 | static int | ||
450 | acpi_ec_burst_read ( | ||
451 | union acpi_ec *ec, | ||
219 | u8 address, | 452 | u8 address, |
220 | u32 *data) | 453 | u32 *data) |
221 | { | 454 | { |
@@ -230,51 +463,51 @@ acpi_ec_read ( | |||
230 | retry: | 463 | retry: |
231 | *data = 0; | 464 | *data = 0; |
232 | 465 | ||
233 | if (ec->global_lock) { | 466 | if (ec->common.global_lock) { |
234 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | 467 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
235 | if (ACPI_FAILURE(status)) | 468 | if (ACPI_FAILURE(status)) |
236 | return_VALUE(-ENODEV); | 469 | return_VALUE(-ENODEV); |
237 | } | 470 | } |
238 | 471 | ||
239 | WARN_ON(in_interrupt()); | 472 | WARN_ON(in_interrupt()); |
240 | down(&ec->sem); | 473 | down(&ec->burst.sem); |
241 | 474 | ||
242 | if(acpi_ec_enter_burst_mode(ec)) | 475 | if(acpi_ec_enter_burst_mode(ec)) |
243 | goto end; | 476 | goto end; |
244 | 477 | ||
245 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->command_addr); | 478 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->common.command_addr); |
246 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 479 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
247 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 480 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
248 | if (status) { | 481 | if (status) { |
249 | goto end; | 482 | goto end; |
250 | } | 483 | } |
251 | 484 | ||
252 | acpi_hw_low_level_write(8, address, &ec->data_addr); | 485 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); |
253 | status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 486 | status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
254 | if (status){ | 487 | if (status){ |
255 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 488 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
256 | goto end; | 489 | goto end; |
257 | } | 490 | } |
258 | 491 | ||
259 | acpi_hw_low_level_read(8, data, &ec->data_addr); | 492 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); |
260 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 493 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
261 | 494 | ||
262 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", | 495 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", |
263 | *data, address)); | 496 | *data, address)); |
264 | 497 | ||
265 | end: | 498 | end: |
266 | acpi_ec_leave_burst_mode(ec); | 499 | acpi_ec_leave_burst_mode(ec); |
267 | up(&ec->sem); | 500 | up(&ec->burst.sem); |
268 | 501 | ||
269 | if (ec->global_lock) | 502 | if (ec->common.global_lock) |
270 | acpi_release_global_lock(glk); | 503 | acpi_release_global_lock(glk); |
271 | 504 | ||
272 | if(atomic_read(&ec->leaving_burst) == 2){ | 505 | if(atomic_read(&ec->burst.leaving_burst) == 2){ |
273 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); | 506 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); |
274 | while(atomic_read(&ec->pending_gpe)){ | 507 | while(atomic_read(&ec->burst.pending_gpe)){ |
275 | msleep(1); | 508 | msleep(1); |
276 | } | 509 | } |
277 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 510 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
278 | goto retry; | 511 | goto retry; |
279 | } | 512 | } |
280 | 513 | ||
@@ -283,8 +516,8 @@ end: | |||
283 | 516 | ||
284 | 517 | ||
285 | static int | 518 | static int |
286 | acpi_ec_write ( | 519 | acpi_ec_burst_write ( |
287 | struct acpi_ec *ec, | 520 | union acpi_ec *ec, |
288 | u8 address, | 521 | u8 address, |
289 | u8 data) | 522 | u8 data) |
290 | { | 523 | { |
@@ -297,14 +530,14 @@ acpi_ec_write ( | |||
297 | if (!ec) | 530 | if (!ec) |
298 | return_VALUE(-EINVAL); | 531 | return_VALUE(-EINVAL); |
299 | retry: | 532 | retry: |
300 | if (ec->global_lock) { | 533 | if (ec->common.global_lock) { |
301 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | 534 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
302 | if (ACPI_FAILURE(status)) | 535 | if (ACPI_FAILURE(status)) |
303 | return_VALUE(-ENODEV); | 536 | return_VALUE(-ENODEV); |
304 | } | 537 | } |
305 | 538 | ||
306 | WARN_ON(in_interrupt()); | 539 | WARN_ON(in_interrupt()); |
307 | down(&ec->sem); | 540 | down(&ec->burst.sem); |
308 | 541 | ||
309 | if(acpi_ec_enter_burst_mode(ec)) | 542 | if(acpi_ec_enter_burst_mode(ec)) |
310 | goto end; | 543 | goto end; |
@@ -312,33 +545,33 @@ retry: | |||
312 | status = acpi_ec_read_status(ec); | 545 | status = acpi_ec_read_status(ec); |
313 | if (status != -EINVAL && | 546 | if (status != -EINVAL && |
314 | !(status & ACPI_EC_FLAG_BURST)){ | 547 | !(status & ACPI_EC_FLAG_BURST)){ |
315 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr); | 548 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->common.command_addr); |
316 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 549 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
317 | if (status) | 550 | if (status) |
318 | goto end; | 551 | goto end; |
319 | acpi_hw_low_level_read(8, &tmp, &ec->data_addr); | 552 | acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr); |
320 | if(tmp != 0x90 ) /* Burst ACK byte*/ | 553 | if(tmp != 0x90 ) /* Burst ACK byte*/ |
321 | goto end; | 554 | goto end; |
322 | } | 555 | } |
323 | /*Now we are in burst mode*/ | 556 | /*Now we are in burst mode*/ |
324 | 557 | ||
325 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr); | 558 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->common.command_addr); |
326 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 559 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
327 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 560 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
328 | if (status){ | 561 | if (status){ |
329 | goto end; | 562 | goto end; |
330 | } | 563 | } |
331 | 564 | ||
332 | acpi_hw_low_level_write(8, address, &ec->data_addr); | 565 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); |
333 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 566 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
334 | if (status){ | 567 | if (status){ |
335 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 568 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
336 | goto end; | 569 | goto end; |
337 | } | 570 | } |
338 | 571 | ||
339 | acpi_hw_low_level_write(8, data, &ec->data_addr); | 572 | acpi_hw_low_level_write(8, data, &ec->common.data_addr); |
340 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 573 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
341 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 574 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
342 | if (status) | 575 | if (status) |
343 | goto end; | 576 | goto end; |
344 | 577 | ||
@@ -347,17 +580,17 @@ retry: | |||
347 | 580 | ||
348 | end: | 581 | end: |
349 | acpi_ec_leave_burst_mode(ec); | 582 | acpi_ec_leave_burst_mode(ec); |
350 | up(&ec->sem); | 583 | up(&ec->burst.sem); |
351 | 584 | ||
352 | if (ec->global_lock) | 585 | if (ec->common.global_lock) |
353 | acpi_release_global_lock(glk); | 586 | acpi_release_global_lock(glk); |
354 | 587 | ||
355 | if(atomic_read(&ec->leaving_burst) == 2){ | 588 | if(atomic_read(&ec->burst.leaving_burst) == 2){ |
356 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); | 589 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); |
357 | while(atomic_read(&ec->pending_gpe)){ | 590 | while(atomic_read(&ec->burst.pending_gpe)){ |
358 | msleep(1); | 591 | msleep(1); |
359 | } | 592 | } |
360 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 593 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
361 | goto retry; | 594 | goto retry; |
362 | } | 595 | } |
363 | 596 | ||
@@ -370,7 +603,7 @@ end: | |||
370 | int | 603 | int |
371 | ec_read(u8 addr, u8 *val) | 604 | ec_read(u8 addr, u8 *val) |
372 | { | 605 | { |
373 | struct acpi_ec *ec; | 606 | union acpi_ec *ec; |
374 | int err; | 607 | int err; |
375 | u32 temp_data; | 608 | u32 temp_data; |
376 | 609 | ||
@@ -393,7 +626,7 @@ EXPORT_SYMBOL(ec_read); | |||
393 | int | 626 | int |
394 | ec_write(u8 addr, u8 val) | 627 | ec_write(u8 addr, u8 val) |
395 | { | 628 | { |
396 | struct acpi_ec *ec; | 629 | union acpi_ec *ec; |
397 | int err; | 630 | int err; |
398 | 631 | ||
399 | if (!first_ec) | 632 | if (!first_ec) |
@@ -407,10 +640,66 @@ ec_write(u8 addr, u8 val) | |||
407 | } | 640 | } |
408 | EXPORT_SYMBOL(ec_write); | 641 | EXPORT_SYMBOL(ec_write); |
409 | 642 | ||
410 | |||
411 | static int | 643 | static int |
412 | acpi_ec_query ( | 644 | acpi_ec_query ( |
413 | struct acpi_ec *ec, | 645 | union acpi_ec *ec, |
646 | u32 *data) | ||
647 | { | ||
648 | if (acpi_ec_polling_mode) | ||
649 | return acpi_ec_polling_query(ec, data); | ||
650 | else | ||
651 | return acpi_ec_burst_query(ec, data); | ||
652 | } | ||
653 | static int | ||
654 | acpi_ec_polling_query ( | ||
655 | union acpi_ec *ec, | ||
656 | u32 *data) | ||
657 | { | ||
658 | int result = 0; | ||
659 | acpi_status status = AE_OK; | ||
660 | unsigned long flags = 0; | ||
661 | u32 glk = 0; | ||
662 | |||
663 | ACPI_FUNCTION_TRACE("acpi_ec_query"); | ||
664 | |||
665 | if (!ec || !data) | ||
666 | return_VALUE(-EINVAL); | ||
667 | |||
668 | *data = 0; | ||
669 | |||
670 | if (ec->common.global_lock) { | ||
671 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | ||
672 | if (ACPI_FAILURE(status)) | ||
673 | return_VALUE(-ENODEV); | ||
674 | } | ||
675 | |||
676 | /* | ||
677 | * Query the EC to find out which _Qxx method we need to evaluate. | ||
678 | * Note that successful completion of the query causes the ACPI_EC_SCI | ||
679 | * bit to be cleared (and thus clearing the interrupt source). | ||
680 | */ | ||
681 | spin_lock_irqsave(&ec->polling.lock, flags); | ||
682 | |||
683 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->common.command_addr); | ||
684 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | ||
685 | if (result) | ||
686 | goto end; | ||
687 | |||
688 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); | ||
689 | if (!*data) | ||
690 | result = -ENODATA; | ||
691 | |||
692 | end: | ||
693 | spin_unlock_irqrestore(&ec->polling.lock, flags); | ||
694 | |||
695 | if (ec->common.global_lock) | ||
696 | acpi_release_global_lock(glk); | ||
697 | |||
698 | return_VALUE(result); | ||
699 | } | ||
700 | static int | ||
701 | acpi_ec_burst_query ( | ||
702 | union acpi_ec *ec, | ||
414 | u32 *data) | 703 | u32 *data) |
415 | { | 704 | { |
416 | int status = 0; | 705 | int status = 0; |
@@ -422,13 +711,13 @@ acpi_ec_query ( | |||
422 | return_VALUE(-EINVAL); | 711 | return_VALUE(-EINVAL); |
423 | *data = 0; | 712 | *data = 0; |
424 | 713 | ||
425 | if (ec->global_lock) { | 714 | if (ec->common.global_lock) { |
426 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | 715 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
427 | if (ACPI_FAILURE(status)) | 716 | if (ACPI_FAILURE(status)) |
428 | return_VALUE(-ENODEV); | 717 | return_VALUE(-ENODEV); |
429 | } | 718 | } |
430 | 719 | ||
431 | down(&ec->sem); | 720 | down(&ec->burst.sem); |
432 | if(acpi_ec_enter_burst_mode(ec)) | 721 | if(acpi_ec_enter_burst_mode(ec)) |
433 | goto end; | 722 | goto end; |
434 | /* | 723 | /* |
@@ -436,28 +725,28 @@ acpi_ec_query ( | |||
436 | * Note that successful completion of the query causes the ACPI_EC_SCI | 725 | * Note that successful completion of the query causes the ACPI_EC_SCI |
437 | * bit to be cleared (and thus clearing the interrupt source). | 726 | * bit to be cleared (and thus clearing the interrupt source). |
438 | */ | 727 | */ |
439 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr); | 728 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->common.command_addr); |
440 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 729 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
441 | if (status){ | 730 | if (status){ |
442 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 731 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
443 | goto end; | 732 | goto end; |
444 | } | 733 | } |
445 | 734 | ||
446 | acpi_hw_low_level_read(8, data, &ec->data_addr); | 735 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); |
447 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 736 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
448 | if (!*data) | 737 | if (!*data) |
449 | status = -ENODATA; | 738 | status = -ENODATA; |
450 | 739 | ||
451 | end: | 740 | end: |
452 | acpi_ec_leave_burst_mode(ec); | 741 | acpi_ec_leave_burst_mode(ec); |
453 | up(&ec->sem); | 742 | up(&ec->burst.sem); |
454 | 743 | ||
455 | if (ec->global_lock) | 744 | if (ec->common.global_lock) |
456 | acpi_release_global_lock(glk); | 745 | acpi_release_global_lock(glk); |
457 | 746 | ||
458 | if(atomic_read(&ec->leaving_burst) == 2){ | 747 | if(atomic_read(&ec->burst.leaving_burst) == 2){ |
459 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); | 748 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); |
460 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 749 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
461 | status = -ENODATA; | 750 | status = -ENODATA; |
462 | } | 751 | } |
463 | return_VALUE(status); | 752 | return_VALUE(status); |
@@ -468,7 +757,7 @@ end: | |||
468 | Event Management | 757 | Event Management |
469 | -------------------------------------------------------------------------- */ | 758 | -------------------------------------------------------------------------- */ |
470 | 759 | ||
471 | struct acpi_ec_query_data { | 760 | union acpi_ec_query_data { |
472 | acpi_handle handle; | 761 | acpi_handle handle; |
473 | u8 data; | 762 | u8 data; |
474 | }; | 763 | }; |
@@ -477,7 +766,59 @@ static void | |||
477 | acpi_ec_gpe_query ( | 766 | acpi_ec_gpe_query ( |
478 | void *ec_cxt) | 767 | void *ec_cxt) |
479 | { | 768 | { |
480 | struct acpi_ec *ec = (struct acpi_ec *) ec_cxt; | 769 | if (acpi_ec_polling_mode) |
770 | acpi_ec_gpe_polling_query(ec_cxt); | ||
771 | else | ||
772 | acpi_ec_gpe_burst_query(ec_cxt); | ||
773 | } | ||
774 | |||
775 | static void | ||
776 | acpi_ec_gpe_polling_query ( | ||
777 | void *ec_cxt) | ||
778 | { | ||
779 | union acpi_ec *ec = (union acpi_ec *) ec_cxt; | ||
780 | u32 value = 0; | ||
781 | unsigned long flags = 0; | ||
782 | static char object_name[5] = {'_','Q','0','0','\0'}; | ||
783 | const char hex[] = {'0','1','2','3','4','5','6','7', | ||
784 | '8','9','A','B','C','D','E','F'}; | ||
785 | |||
786 | ACPI_FUNCTION_TRACE("acpi_ec_gpe_query"); | ||
787 | |||
788 | if (!ec_cxt) | ||
789 | goto end; | ||
790 | |||
791 | spin_lock_irqsave(&ec->polling.lock, flags); | ||
792 | acpi_hw_low_level_read(8, &value, &ec->common.command_addr); | ||
793 | spin_unlock_irqrestore(&ec->polling.lock, flags); | ||
794 | |||
795 | /* TBD: Implement asynch events! | ||
796 | * NOTE: All we care about are EC-SCI's. Other EC events are | ||
797 | * handled via polling (yuck!). This is because some systems | ||
798 | * treat EC-SCIs as level (versus EDGE!) triggered, preventing | ||
799 | * a purely interrupt-driven approach (grumble, grumble). | ||
800 | */ | ||
801 | if (!(value & ACPI_EC_FLAG_SCI)) | ||
802 | goto end; | ||
803 | |||
804 | if (acpi_ec_query(ec, &value)) | ||
805 | goto end; | ||
806 | |||
807 | object_name[2] = hex[((value >> 4) & 0x0F)]; | ||
808 | object_name[3] = hex[(value & 0x0F)]; | ||
809 | |||
810 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); | ||
811 | |||
812 | acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL); | ||
813 | |||
814 | end: | ||
815 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); | ||
816 | } | ||
817 | static void | ||
818 | acpi_ec_gpe_burst_query ( | ||
819 | void *ec_cxt) | ||
820 | { | ||
821 | union acpi_ec *ec = (union acpi_ec *) ec_cxt; | ||
481 | u32 value; | 822 | u32 value; |
482 | int result = -ENODATA; | 823 | int result = -ENODATA; |
483 | static char object_name[5] = {'_','Q','0','0','\0'}; | 824 | static char object_name[5] = {'_','Q','0','0','\0'}; |
@@ -497,9 +838,9 @@ acpi_ec_gpe_query ( | |||
497 | 838 | ||
498 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); | 839 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); |
499 | 840 | ||
500 | acpi_evaluate_object(ec->handle, object_name, NULL, NULL); | 841 | acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL); |
501 | end: | 842 | end: |
502 | atomic_dec(&ec->pending_gpe); | 843 | atomic_dec(&ec->burst.pending_gpe); |
503 | return; | 844 | return; |
504 | } | 845 | } |
505 | 846 | ||
@@ -507,48 +848,77 @@ static u32 | |||
507 | acpi_ec_gpe_handler ( | 848 | acpi_ec_gpe_handler ( |
508 | void *data) | 849 | void *data) |
509 | { | 850 | { |
851 | if (acpi_ec_polling_mode) | ||
852 | return acpi_ec_gpe_polling_handler(data); | ||
853 | else | ||
854 | return acpi_ec_gpe_burst_handler(data); | ||
855 | } | ||
856 | static u32 | ||
857 | acpi_ec_gpe_polling_handler ( | ||
858 | void *data) | ||
859 | { | ||
860 | acpi_status status = AE_OK; | ||
861 | union acpi_ec *ec = (union acpi_ec *) data; | ||
862 | |||
863 | if (!ec) | ||
864 | return ACPI_INTERRUPT_NOT_HANDLED; | ||
865 | |||
866 | acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); | ||
867 | |||
868 | status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, | ||
869 | acpi_ec_gpe_query, ec); | ||
870 | |||
871 | if (status == AE_OK) | ||
872 | return ACPI_INTERRUPT_HANDLED; | ||
873 | else | ||
874 | return ACPI_INTERRUPT_NOT_HANDLED; | ||
875 | } | ||
876 | static u32 | ||
877 | acpi_ec_gpe_burst_handler ( | ||
878 | void *data) | ||
879 | { | ||
510 | acpi_status status = AE_OK; | 880 | acpi_status status = AE_OK; |
511 | u32 value; | 881 | u32 value; |
512 | struct acpi_ec *ec = (struct acpi_ec *) data; | 882 | union acpi_ec *ec = (union acpi_ec *) data; |
513 | 883 | ||
514 | if (!ec) | 884 | if (!ec) |
515 | return ACPI_INTERRUPT_NOT_HANDLED; | 885 | return ACPI_INTERRUPT_NOT_HANDLED; |
516 | 886 | ||
517 | acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR); | 887 | acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
518 | 888 | ||
519 | value = acpi_ec_read_status(ec); | 889 | value = acpi_ec_read_status(ec); |
520 | 890 | ||
521 | if((value & ACPI_EC_FLAG_IBF) && | 891 | if((value & ACPI_EC_FLAG_IBF) && |
522 | !(value & ACPI_EC_FLAG_BURST) && | 892 | !(value & ACPI_EC_FLAG_BURST) && |
523 | (atomic_read(&ec->leaving_burst) == 0)) { | 893 | (atomic_read(&ec->burst.leaving_burst) == 0)) { |
524 | /* | 894 | /* |
525 | * the embedded controller disables | 895 | * the embedded controller disables |
526 | * burst mode for any reason other | 896 | * burst mode for any reason other |
527 | * than the burst disable command | 897 | * than the burst disable command |
528 | * to process critical event. | 898 | * to process critical event. |
529 | */ | 899 | */ |
530 | atomic_set(&ec->leaving_burst , 2); /* block current pending transaction | 900 | atomic_set(&ec->burst.leaving_burst , 2); /* block current pending transaction |
531 | and retry */ | 901 | and retry */ |
532 | wake_up(&ec->wait); | 902 | wake_up(&ec->burst.wait); |
533 | }else { | 903 | }else { |
534 | if ((ec->expect_event == ACPI_EC_EVENT_OBF && | 904 | if ((ec->burst.expect_event == ACPI_EC_EVENT_OBF && |
535 | (value & ACPI_EC_FLAG_OBF)) || | 905 | (value & ACPI_EC_FLAG_OBF)) || |
536 | (ec->expect_event == ACPI_EC_EVENT_IBE && | 906 | (ec->burst.expect_event == ACPI_EC_EVENT_IBE && |
537 | !(value & ACPI_EC_FLAG_IBF))) { | 907 | !(value & ACPI_EC_FLAG_IBF))) { |
538 | ec->expect_event = 0; | 908 | ec->burst.expect_event = 0; |
539 | wake_up(&ec->wait); | 909 | wake_up(&ec->burst.wait); |
540 | return ACPI_INTERRUPT_HANDLED; | 910 | return ACPI_INTERRUPT_HANDLED; |
541 | } | 911 | } |
542 | } | 912 | } |
543 | 913 | ||
544 | if (value & ACPI_EC_FLAG_SCI){ | 914 | if (value & ACPI_EC_FLAG_SCI){ |
545 | atomic_add(1, &ec->pending_gpe) ; | 915 | atomic_add(1, &ec->burst.pending_gpe) ; |
546 | status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, | 916 | status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, |
547 | acpi_ec_gpe_query, ec); | 917 | acpi_ec_gpe_query, ec); |
548 | return status == AE_OK ? | 918 | return status == AE_OK ? |
549 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; | 919 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
550 | } | 920 | } |
551 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR); | 921 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
552 | return status == AE_OK ? | 922 | return status == AE_OK ? |
553 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; | 923 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
554 | } | 924 | } |
@@ -585,7 +955,7 @@ acpi_ec_space_handler ( | |||
585 | void *region_context) | 955 | void *region_context) |
586 | { | 956 | { |
587 | int result = 0; | 957 | int result = 0; |
588 | struct acpi_ec *ec = NULL; | 958 | union acpi_ec *ec = NULL; |
589 | u64 temp = *value; | 959 | u64 temp = *value; |
590 | acpi_integer f_v = 0; | 960 | acpi_integer f_v = 0; |
591 | int i = 0; | 961 | int i = 0; |
@@ -600,7 +970,7 @@ acpi_ec_space_handler ( | |||
600 | return_VALUE(AE_BAD_PARAMETER); | 970 | return_VALUE(AE_BAD_PARAMETER); |
601 | } | 971 | } |
602 | 972 | ||
603 | ec = (struct acpi_ec *) handler_context; | 973 | ec = (union acpi_ec *) handler_context; |
604 | 974 | ||
605 | next_byte: | 975 | next_byte: |
606 | switch (function) { | 976 | switch (function) { |
@@ -661,7 +1031,7 @@ static struct proc_dir_entry *acpi_ec_dir; | |||
661 | static int | 1031 | static int |
662 | acpi_ec_read_info (struct seq_file *seq, void *offset) | 1032 | acpi_ec_read_info (struct seq_file *seq, void *offset) |
663 | { | 1033 | { |
664 | struct acpi_ec *ec = (struct acpi_ec *) seq->private; | 1034 | union acpi_ec *ec = (union acpi_ec *) seq->private; |
665 | 1035 | ||
666 | ACPI_FUNCTION_TRACE("acpi_ec_read_info"); | 1036 | ACPI_FUNCTION_TRACE("acpi_ec_read_info"); |
667 | 1037 | ||
@@ -669,12 +1039,12 @@ acpi_ec_read_info (struct seq_file *seq, void *offset) | |||
669 | goto end; | 1039 | goto end; |
670 | 1040 | ||
671 | seq_printf(seq, "gpe bit: 0x%02x\n", | 1041 | seq_printf(seq, "gpe bit: 0x%02x\n", |
672 | (u32) ec->gpe_bit); | 1042 | (u32) ec->common.gpe_bit); |
673 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", | 1043 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", |
674 | (u32) ec->status_addr.address, (u32) ec->data_addr.address); | 1044 | (u32) ec->common.status_addr.address, (u32) ec->common.data_addr.address); |
675 | seq_printf(seq, "use global lock: %s\n", | 1045 | seq_printf(seq, "use global lock: %s\n", |
676 | ec->global_lock?"yes":"no"); | 1046 | ec->common.global_lock?"yes":"no"); |
677 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 1047 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
678 | 1048 | ||
679 | end: | 1049 | end: |
680 | return_VALUE(0); | 1050 | return_VALUE(0); |
@@ -697,7 +1067,7 @@ static int | |||
697 | acpi_ec_add_fs ( | 1067 | acpi_ec_add_fs ( |
698 | struct acpi_device *device) | 1068 | struct acpi_device *device) |
699 | { | 1069 | { |
700 | struct proc_dir_entry *entry; | 1070 | struct proc_dir_entry *entry = NULL; |
701 | 1071 | ||
702 | ACPI_FUNCTION_TRACE("acpi_ec_add_fs"); | 1072 | ACPI_FUNCTION_TRACE("acpi_ec_add_fs"); |
703 | 1073 | ||
@@ -744,13 +1114,82 @@ acpi_ec_remove_fs ( | |||
744 | Driver Interface | 1114 | Driver Interface |
745 | -------------------------------------------------------------------------- */ | 1115 | -------------------------------------------------------------------------- */ |
746 | 1116 | ||
1117 | |||
747 | static int | 1118 | static int |
748 | acpi_ec_add ( | 1119 | acpi_ec_polling_add ( |
749 | struct acpi_device *device) | 1120 | struct acpi_device *device) |
750 | { | 1121 | { |
751 | int result; | 1122 | int result = 0; |
752 | acpi_status status; | 1123 | acpi_status status = AE_OK; |
753 | struct acpi_ec *ec; | 1124 | union acpi_ec *ec = NULL; |
1125 | unsigned long uid; | ||
1126 | |||
1127 | ACPI_FUNCTION_TRACE("acpi_ec_add"); | ||
1128 | |||
1129 | if (!device) | ||
1130 | return_VALUE(-EINVAL); | ||
1131 | |||
1132 | ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); | ||
1133 | if (!ec) | ||
1134 | return_VALUE(-ENOMEM); | ||
1135 | memset(ec, 0, sizeof(union acpi_ec)); | ||
1136 | |||
1137 | ec->common.handle = device->handle; | ||
1138 | ec->common.uid = -1; | ||
1139 | spin_lock_init(&ec->polling.lock); | ||
1140 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); | ||
1141 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); | ||
1142 | acpi_driver_data(device) = ec; | ||
1143 | |||
1144 | /* Use the global lock for all EC transactions? */ | ||
1145 | acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, &ec->common.global_lock); | ||
1146 | |||
1147 | /* If our UID matches the UID for the ECDT-enumerated EC, | ||
1148 | we now have the *real* EC info, so kill the makeshift one.*/ | ||
1149 | acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid); | ||
1150 | if (ec_ecdt && ec_ecdt->common.uid == uid) { | ||
1151 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, | ||
1152 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); | ||
1153 | |||
1154 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, &acpi_ec_gpe_handler); | ||
1155 | |||
1156 | kfree(ec_ecdt); | ||
1157 | } | ||
1158 | |||
1159 | /* Get GPE bit assignment (EC events). */ | ||
1160 | /* TODO: Add support for _GPE returning a package */ | ||
1161 | status = acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, &ec->common.gpe_bit); | ||
1162 | if (ACPI_FAILURE(status)) { | ||
1163 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
1164 | "Error obtaining GPE bit assignment\n")); | ||
1165 | result = -ENODEV; | ||
1166 | goto end; | ||
1167 | } | ||
1168 | |||
1169 | result = acpi_ec_add_fs(device); | ||
1170 | if (result) | ||
1171 | goto end; | ||
1172 | |||
1173 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n", | ||
1174 | acpi_device_name(device), acpi_device_bid(device), | ||
1175 | (u32) ec->common.gpe_bit); | ||
1176 | |||
1177 | if (!first_ec) | ||
1178 | first_ec = device; | ||
1179 | |||
1180 | end: | ||
1181 | if (result) | ||
1182 | kfree(ec); | ||
1183 | |||
1184 | return_VALUE(result); | ||
1185 | } | ||
1186 | static int | ||
1187 | acpi_ec_burst_add ( | ||
1188 | struct acpi_device *device) | ||
1189 | { | ||
1190 | int result = 0; | ||
1191 | acpi_status status = AE_OK; | ||
1192 | union acpi_ec *ec = NULL; | ||
754 | unsigned long uid; | 1193 | unsigned long uid; |
755 | 1194 | ||
756 | ACPI_FUNCTION_TRACE("acpi_ec_add"); | 1195 | ACPI_FUNCTION_TRACE("acpi_ec_add"); |
@@ -758,39 +1197,39 @@ acpi_ec_add ( | |||
758 | if (!device) | 1197 | if (!device) |
759 | return_VALUE(-EINVAL); | 1198 | return_VALUE(-EINVAL); |
760 | 1199 | ||
761 | ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 1200 | ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
762 | if (!ec) | 1201 | if (!ec) |
763 | return_VALUE(-ENOMEM); | 1202 | return_VALUE(-ENOMEM); |
764 | memset(ec, 0, sizeof(struct acpi_ec)); | 1203 | memset(ec, 0, sizeof(union acpi_ec)); |
765 | 1204 | ||
766 | ec->handle = device->handle; | 1205 | ec->common.handle = device->handle; |
767 | ec->uid = -1; | 1206 | ec->common.uid = -1; |
768 | atomic_set(&ec->pending_gpe, 0); | 1207 | atomic_set(&ec->burst.pending_gpe, 0); |
769 | atomic_set(&ec->leaving_burst , 1); | 1208 | atomic_set(&ec->burst.leaving_burst , 1); |
770 | init_MUTEX(&ec->sem); | 1209 | init_MUTEX(&ec->burst.sem); |
771 | init_waitqueue_head(&ec->wait); | 1210 | init_waitqueue_head(&ec->burst.wait); |
772 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); | 1211 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
773 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); | 1212 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
774 | acpi_driver_data(device) = ec; | 1213 | acpi_driver_data(device) = ec; |
775 | 1214 | ||
776 | /* Use the global lock for all EC transactions? */ | 1215 | /* Use the global lock for all EC transactions? */ |
777 | acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock); | 1216 | acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, &ec->common.global_lock); |
778 | 1217 | ||
779 | /* If our UID matches the UID for the ECDT-enumerated EC, | 1218 | /* If our UID matches the UID for the ECDT-enumerated EC, |
780 | we now have the *real* EC info, so kill the makeshift one.*/ | 1219 | we now have the *real* EC info, so kill the makeshift one.*/ |
781 | acpi_evaluate_integer(ec->handle, "_UID", NULL, &uid); | 1220 | acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid); |
782 | if (ec_ecdt && ec_ecdt->uid == uid) { | 1221 | if (ec_ecdt && ec_ecdt->common.uid == uid) { |
783 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, | 1222 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, |
784 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); | 1223 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); |
785 | 1224 | ||
786 | acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, &acpi_ec_gpe_handler); | 1225 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, &acpi_ec_gpe_handler); |
787 | 1226 | ||
788 | kfree(ec_ecdt); | 1227 | kfree(ec_ecdt); |
789 | } | 1228 | } |
790 | 1229 | ||
791 | /* Get GPE bit assignment (EC events). */ | 1230 | /* Get GPE bit assignment (EC events). */ |
792 | /* TODO: Add support for _GPE returning a package */ | 1231 | /* TODO: Add support for _GPE returning a package */ |
793 | status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe_bit); | 1232 | status = acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, &ec->common.gpe_bit); |
794 | if (ACPI_FAILURE(status)) { | 1233 | if (ACPI_FAILURE(status)) { |
795 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1234 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
796 | "Error obtaining GPE bit assignment\n")); | 1235 | "Error obtaining GPE bit assignment\n")); |
@@ -804,7 +1243,7 @@ acpi_ec_add ( | |||
804 | 1243 | ||
805 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n", | 1244 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n", |
806 | acpi_device_name(device), acpi_device_bid(device), | 1245 | acpi_device_name(device), acpi_device_bid(device), |
807 | (u32) ec->gpe_bit); | 1246 | (u32) ec->common.gpe_bit); |
808 | 1247 | ||
809 | if (!first_ec) | 1248 | if (!first_ec) |
810 | first_ec = device; | 1249 | first_ec = device; |
@@ -822,7 +1261,7 @@ acpi_ec_remove ( | |||
822 | struct acpi_device *device, | 1261 | struct acpi_device *device, |
823 | int type) | 1262 | int type) |
824 | { | 1263 | { |
825 | struct acpi_ec *ec; | 1264 | union acpi_ec *ec = NULL; |
826 | 1265 | ||
827 | ACPI_FUNCTION_TRACE("acpi_ec_remove"); | 1266 | ACPI_FUNCTION_TRACE("acpi_ec_remove"); |
828 | 1267 | ||
@@ -844,7 +1283,7 @@ acpi_ec_io_ports ( | |||
844 | struct acpi_resource *resource, | 1283 | struct acpi_resource *resource, |
845 | void *context) | 1284 | void *context) |
846 | { | 1285 | { |
847 | struct acpi_ec *ec = (struct acpi_ec *) context; | 1286 | union acpi_ec *ec = (union acpi_ec *) context; |
848 | struct acpi_generic_address *addr; | 1287 | struct acpi_generic_address *addr; |
849 | 1288 | ||
850 | if (resource->id != ACPI_RSTYPE_IO) { | 1289 | if (resource->id != ACPI_RSTYPE_IO) { |
@@ -856,10 +1295,10 @@ acpi_ec_io_ports ( | |||
856 | * the second address region returned is the status/command | 1295 | * the second address region returned is the status/command |
857 | * port. | 1296 | * port. |
858 | */ | 1297 | */ |
859 | if (ec->data_addr.register_bit_width == 0) { | 1298 | if (ec->common.data_addr.register_bit_width == 0) { |
860 | addr = &ec->data_addr; | 1299 | addr = &ec->common.data_addr; |
861 | } else if (ec->command_addr.register_bit_width == 0) { | 1300 | } else if (ec->common.command_addr.register_bit_width == 0) { |
862 | addr = &ec->command_addr; | 1301 | addr = &ec->common.command_addr; |
863 | } else { | 1302 | } else { |
864 | return AE_CTRL_TERMINATE; | 1303 | return AE_CTRL_TERMINATE; |
865 | } | 1304 | } |
@@ -877,8 +1316,8 @@ static int | |||
877 | acpi_ec_start ( | 1316 | acpi_ec_start ( |
878 | struct acpi_device *device) | 1317 | struct acpi_device *device) |
879 | { | 1318 | { |
880 | acpi_status status; | 1319 | acpi_status status = AE_OK; |
881 | struct acpi_ec *ec; | 1320 | union acpi_ec *ec = NULL; |
882 | 1321 | ||
883 | ACPI_FUNCTION_TRACE("acpi_ec_start"); | 1322 | ACPI_FUNCTION_TRACE("acpi_ec_start"); |
884 | 1323 | ||
@@ -893,35 +1332,36 @@ acpi_ec_start ( | |||
893 | /* | 1332 | /* |
894 | * Get I/O port addresses. Convert to GAS format. | 1333 | * Get I/O port addresses. Convert to GAS format. |
895 | */ | 1334 | */ |
896 | status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS, | 1335 | status = acpi_walk_resources(ec->common.handle, METHOD_NAME__CRS, |
897 | acpi_ec_io_ports, ec); | 1336 | acpi_ec_io_ports, ec); |
898 | if (ACPI_FAILURE(status) || ec->command_addr.register_bit_width == 0) { | 1337 | if (ACPI_FAILURE(status) || ec->common.command_addr.register_bit_width == 0) { |
899 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error getting I/O port addresses")); | 1338 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error getting I/O port addresses")); |
900 | return_VALUE(-ENODEV); | 1339 | return_VALUE(-ENODEV); |
901 | } | 1340 | } |
902 | 1341 | ||
903 | ec->status_addr = ec->command_addr; | 1342 | ec->common.status_addr = ec->common.command_addr; |
904 | 1343 | ||
905 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n", | 1344 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n", |
906 | (u32) ec->gpe_bit, (u32) ec->command_addr.address, | 1345 | (u32) ec->common.gpe_bit, (u32) ec->common.command_addr.address, |
907 | (u32) ec->data_addr.address)); | 1346 | (u32) ec->common.data_addr.address)); |
1347 | |||
908 | 1348 | ||
909 | /* | 1349 | /* |
910 | * Install GPE handler | 1350 | * Install GPE handler |
911 | */ | 1351 | */ |
912 | status = acpi_install_gpe_handler(NULL, ec->gpe_bit, | 1352 | status = acpi_install_gpe_handler(NULL, ec->common.gpe_bit, |
913 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec); | 1353 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec); |
914 | if (ACPI_FAILURE(status)) { | 1354 | if (ACPI_FAILURE(status)) { |
915 | return_VALUE(-ENODEV); | 1355 | return_VALUE(-ENODEV); |
916 | } | 1356 | } |
917 | acpi_set_gpe_type (NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME); | 1357 | acpi_set_gpe_type (NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME); |
918 | acpi_enable_gpe (NULL, ec->gpe_bit, ACPI_NOT_ISR); | 1358 | acpi_enable_gpe (NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
919 | 1359 | ||
920 | status = acpi_install_address_space_handler (ec->handle, | 1360 | status = acpi_install_address_space_handler (ec->common.handle, |
921 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, | 1361 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, |
922 | &acpi_ec_space_setup, ec); | 1362 | &acpi_ec_space_setup, ec); |
923 | if (ACPI_FAILURE(status)) { | 1363 | if (ACPI_FAILURE(status)) { |
924 | acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler); | 1364 | acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, &acpi_ec_gpe_handler); |
925 | return_VALUE(-ENODEV); | 1365 | return_VALUE(-ENODEV); |
926 | } | 1366 | } |
927 | 1367 | ||
@@ -934,8 +1374,8 @@ acpi_ec_stop ( | |||
934 | struct acpi_device *device, | 1374 | struct acpi_device *device, |
935 | int type) | 1375 | int type) |
936 | { | 1376 | { |
937 | acpi_status status; | 1377 | acpi_status status = AE_OK; |
938 | struct acpi_ec *ec; | 1378 | union acpi_ec *ec = NULL; |
939 | 1379 | ||
940 | ACPI_FUNCTION_TRACE("acpi_ec_stop"); | 1380 | ACPI_FUNCTION_TRACE("acpi_ec_stop"); |
941 | 1381 | ||
@@ -944,12 +1384,12 @@ acpi_ec_stop ( | |||
944 | 1384 | ||
945 | ec = acpi_driver_data(device); | 1385 | ec = acpi_driver_data(device); |
946 | 1386 | ||
947 | status = acpi_remove_address_space_handler(ec->handle, | 1387 | status = acpi_remove_address_space_handler(ec->common.handle, |
948 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); | 1388 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); |
949 | if (ACPI_FAILURE(status)) | 1389 | if (ACPI_FAILURE(status)) |
950 | return_VALUE(-ENODEV); | 1390 | return_VALUE(-ENODEV); |
951 | 1391 | ||
952 | status = acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler); | 1392 | status = acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, &acpi_ec_gpe_handler); |
953 | if (ACPI_FAILURE(status)) | 1393 | if (ACPI_FAILURE(status)) |
954 | return_VALUE(-ENODEV); | 1394 | return_VALUE(-ENODEV); |
955 | 1395 | ||
@@ -963,26 +1403,76 @@ acpi_fake_ecdt_callback ( | |||
963 | void *context, | 1403 | void *context, |
964 | void **retval) | 1404 | void **retval) |
965 | { | 1405 | { |
1406 | |||
1407 | if (acpi_ec_polling_mode) | ||
1408 | return acpi_fake_ecdt_polling_callback(handle, | ||
1409 | Level, context, retval); | ||
1410 | else | ||
1411 | return acpi_fake_ecdt_burst_callback(handle, | ||
1412 | Level, context, retval); | ||
1413 | } | ||
1414 | |||
1415 | static acpi_status __init | ||
1416 | acpi_fake_ecdt_polling_callback ( | ||
1417 | acpi_handle handle, | ||
1418 | u32 Level, | ||
1419 | void *context, | ||
1420 | void **retval) | ||
1421 | { | ||
1422 | acpi_status status; | ||
1423 | |||
1424 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, | ||
1425 | acpi_ec_io_ports, ec_ecdt); | ||
1426 | if (ACPI_FAILURE(status)) | ||
1427 | return status; | ||
1428 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; | ||
1429 | |||
1430 | ec_ecdt->common.uid = -1; | ||
1431 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); | ||
1432 | |||
1433 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit); | ||
1434 | if (ACPI_FAILURE(status)) | ||
1435 | return status; | ||
1436 | spin_lock_init(&ec_ecdt->polling.lock); | ||
1437 | ec_ecdt->common.global_lock = TRUE; | ||
1438 | ec_ecdt->common.handle = handle; | ||
1439 | |||
1440 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", | ||
1441 | (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address, | ||
1442 | (u32) ec_ecdt->common.data_addr.address); | ||
1443 | |||
1444 | return AE_CTRL_TERMINATE; | ||
1445 | } | ||
1446 | |||
1447 | static acpi_status __init | ||
1448 | acpi_fake_ecdt_burst_callback ( | ||
1449 | acpi_handle handle, | ||
1450 | u32 Level, | ||
1451 | void *context, | ||
1452 | void **retval) | ||
1453 | { | ||
966 | acpi_status status; | 1454 | acpi_status status; |
967 | 1455 | ||
1456 | init_MUTEX(&ec_ecdt->burst.sem); | ||
1457 | init_waitqueue_head(&ec_ecdt->burst.wait); | ||
968 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, | 1458 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
969 | acpi_ec_io_ports, ec_ecdt); | 1459 | acpi_ec_io_ports, ec_ecdt); |
970 | if (ACPI_FAILURE(status)) | 1460 | if (ACPI_FAILURE(status)) |
971 | return status; | 1461 | return status; |
972 | ec_ecdt->status_addr = ec_ecdt->command_addr; | 1462 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; |
973 | 1463 | ||
974 | ec_ecdt->uid = -1; | 1464 | ec_ecdt->common.uid = -1; |
975 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); | 1465 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); |
976 | 1466 | ||
977 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe_bit); | 1467 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit); |
978 | if (ACPI_FAILURE(status)) | 1468 | if (ACPI_FAILURE(status)) |
979 | return status; | 1469 | return status; |
980 | ec_ecdt->global_lock = TRUE; | 1470 | ec_ecdt->common.global_lock = TRUE; |
981 | ec_ecdt->handle = handle; | 1471 | ec_ecdt->common.handle = handle; |
982 | 1472 | ||
983 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", | 1473 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", |
984 | (u32) ec_ecdt->gpe_bit, (u32) ec_ecdt->command_addr.address, | 1474 | (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address, |
985 | (u32) ec_ecdt->data_addr.address); | 1475 | (u32) ec_ecdt->common.data_addr.address); |
986 | 1476 | ||
987 | return AE_CTRL_TERMINATE; | 1477 | return AE_CTRL_TERMINATE; |
988 | } | 1478 | } |
@@ -1005,12 +1495,12 @@ acpi_ec_fake_ecdt(void) | |||
1005 | 1495 | ||
1006 | printk(KERN_INFO PREFIX "Try to make an fake ECDT\n"); | 1496 | printk(KERN_INFO PREFIX "Try to make an fake ECDT\n"); |
1007 | 1497 | ||
1008 | ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 1498 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
1009 | if (!ec_ecdt) { | 1499 | if (!ec_ecdt) { |
1010 | ret = -ENOMEM; | 1500 | ret = -ENOMEM; |
1011 | goto error; | 1501 | goto error; |
1012 | } | 1502 | } |
1013 | memset(ec_ecdt, 0, sizeof(struct acpi_ec)); | 1503 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
1014 | 1504 | ||
1015 | status = acpi_get_devices (ACPI_EC_HID, | 1505 | status = acpi_get_devices (ACPI_EC_HID, |
1016 | acpi_fake_ecdt_callback, | 1506 | acpi_fake_ecdt_callback, |
@@ -1031,6 +1521,60 @@ error: | |||
1031 | static int __init | 1521 | static int __init |
1032 | acpi_ec_get_real_ecdt(void) | 1522 | acpi_ec_get_real_ecdt(void) |
1033 | { | 1523 | { |
1524 | if (acpi_ec_polling_mode) | ||
1525 | return acpi_ec_polling_get_real_ecdt(); | ||
1526 | else | ||
1527 | return acpi_ec_burst_get_real_ecdt(); | ||
1528 | } | ||
1529 | |||
1530 | static int __init | ||
1531 | acpi_ec_polling_get_real_ecdt(void) | ||
1532 | { | ||
1533 | acpi_status status; | ||
1534 | struct acpi_table_ecdt *ecdt_ptr; | ||
1535 | |||
1536 | status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, | ||
1537 | (struct acpi_table_header **) &ecdt_ptr); | ||
1538 | if (ACPI_FAILURE(status)) | ||
1539 | return -ENODEV; | ||
1540 | |||
1541 | printk(KERN_INFO PREFIX "Found ECDT\n"); | ||
1542 | |||
1543 | /* | ||
1544 | * Generate a temporary ec context to use until the namespace is scanned | ||
1545 | */ | ||
1546 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); | ||
1547 | if (!ec_ecdt) | ||
1548 | return -ENOMEM; | ||
1549 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); | ||
1550 | |||
1551 | ec_ecdt->common.command_addr = ecdt_ptr->ec_control; | ||
1552 | ec_ecdt->common.status_addr = ecdt_ptr->ec_control; | ||
1553 | ec_ecdt->common.data_addr = ecdt_ptr->ec_data; | ||
1554 | ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit; | ||
1555 | spin_lock_init(&ec_ecdt->polling.lock); | ||
1556 | /* use the GL just to be safe */ | ||
1557 | ec_ecdt->common.global_lock = TRUE; | ||
1558 | ec_ecdt->common.uid = ecdt_ptr->uid; | ||
1559 | |||
1560 | status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle); | ||
1561 | if (ACPI_FAILURE(status)) { | ||
1562 | goto error; | ||
1563 | } | ||
1564 | |||
1565 | return 0; | ||
1566 | error: | ||
1567 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); | ||
1568 | kfree(ec_ecdt); | ||
1569 | ec_ecdt = NULL; | ||
1570 | |||
1571 | return -ENODEV; | ||
1572 | } | ||
1573 | |||
1574 | |||
1575 | static int __init | ||
1576 | acpi_ec_burst_get_real_ecdt(void) | ||
1577 | { | ||
1034 | acpi_status status; | 1578 | acpi_status status; |
1035 | struct acpi_table_ecdt *ecdt_ptr; | 1579 | struct acpi_table_ecdt *ecdt_ptr; |
1036 | 1580 | ||
@@ -1044,22 +1588,22 @@ acpi_ec_get_real_ecdt(void) | |||
1044 | /* | 1588 | /* |
1045 | * Generate a temporary ec context to use until the namespace is scanned | 1589 | * Generate a temporary ec context to use until the namespace is scanned |
1046 | */ | 1590 | */ |
1047 | ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 1591 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
1048 | if (!ec_ecdt) | 1592 | if (!ec_ecdt) |
1049 | return -ENOMEM; | 1593 | return -ENOMEM; |
1050 | memset(ec_ecdt, 0, sizeof(struct acpi_ec)); | 1594 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
1051 | 1595 | ||
1052 | init_MUTEX(&ec_ecdt->sem); | 1596 | init_MUTEX(&ec_ecdt->burst.sem); |
1053 | init_waitqueue_head(&ec_ecdt->wait); | 1597 | init_waitqueue_head(&ec_ecdt->burst.wait); |
1054 | ec_ecdt->command_addr = ecdt_ptr->ec_control; | 1598 | ec_ecdt->common.command_addr = ecdt_ptr->ec_control; |
1055 | ec_ecdt->status_addr = ecdt_ptr->ec_control; | 1599 | ec_ecdt->common.status_addr = ecdt_ptr->ec_control; |
1056 | ec_ecdt->data_addr = ecdt_ptr->ec_data; | 1600 | ec_ecdt->common.data_addr = ecdt_ptr->ec_data; |
1057 | ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; | 1601 | ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit; |
1058 | /* use the GL just to be safe */ | 1602 | /* use the GL just to be safe */ |
1059 | ec_ecdt->global_lock = TRUE; | 1603 | ec_ecdt->common.global_lock = TRUE; |
1060 | ec_ecdt->uid = ecdt_ptr->uid; | 1604 | ec_ecdt->common.uid = ecdt_ptr->uid; |
1061 | 1605 | ||
1062 | status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle); | 1606 | status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle); |
1063 | if (ACPI_FAILURE(status)) { | 1607 | if (ACPI_FAILURE(status)) { |
1064 | goto error; | 1608 | goto error; |
1065 | } | 1609 | } |
@@ -1092,20 +1636,20 @@ acpi_ec_ecdt_probe (void) | |||
1092 | /* | 1636 | /* |
1093 | * Install GPE handler | 1637 | * Install GPE handler |
1094 | */ | 1638 | */ |
1095 | status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit, | 1639 | status = acpi_install_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
1096 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, | 1640 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, |
1097 | ec_ecdt); | 1641 | ec_ecdt); |
1098 | if (ACPI_FAILURE(status)) { | 1642 | if (ACPI_FAILURE(status)) { |
1099 | goto error; | 1643 | goto error; |
1100 | } | 1644 | } |
1101 | acpi_set_gpe_type (NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME); | 1645 | acpi_set_gpe_type (NULL, ec_ecdt->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME); |
1102 | acpi_enable_gpe (NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR); | 1646 | acpi_enable_gpe (NULL, ec_ecdt->common.gpe_bit, ACPI_NOT_ISR); |
1103 | 1647 | ||
1104 | status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT, | 1648 | status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT, |
1105 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, | 1649 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, |
1106 | &acpi_ec_space_setup, ec_ecdt); | 1650 | &acpi_ec_space_setup, ec_ecdt); |
1107 | if (ACPI_FAILURE(status)) { | 1651 | if (ACPI_FAILURE(status)) { |
1108 | acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, | 1652 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
1109 | &acpi_ec_gpe_handler); | 1653 | &acpi_ec_gpe_handler); |
1110 | goto error; | 1654 | goto error; |
1111 | } | 1655 | } |
@@ -1123,7 +1667,7 @@ error: | |||
1123 | 1667 | ||
1124 | static int __init acpi_ec_init (void) | 1668 | static int __init acpi_ec_init (void) |
1125 | { | 1669 | { |
1126 | int result; | 1670 | int result = 0; |
1127 | 1671 | ||
1128 | ACPI_FUNCTION_TRACE("acpi_ec_init"); | 1672 | ACPI_FUNCTION_TRACE("acpi_ec_init"); |
1129 | 1673 | ||
@@ -1167,3 +1711,10 @@ static int __init acpi_fake_ecdt_setup(char *str) | |||
1167 | return 0; | 1711 | return 0; |
1168 | } | 1712 | } |
1169 | __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); | 1713 | __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); |
1714 | static int __init acpi_ec_set_polling_mode(char *str) | ||
1715 | { | ||
1716 | acpi_ec_polling_mode = EC_POLLING; | ||
1717 | acpi_ec_driver.ops.add = acpi_ec_polling_add; | ||
1718 | return 0; | ||
1719 | } | ||
1720 | __setup("ec_polling", acpi_ec_set_polling_mode); | ||