diff options
Diffstat (limited to 'drivers/acpi/ec.c')
-rw-r--r-- | drivers/acpi/ec.c | 910 |
1 files changed, 725 insertions, 185 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 8e665f2e3138..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,63 +279,176 @@ 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_DEBUG_PRINT((ACPI_DB_INFO,"entering burst mode \n")); | 282 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->common.command_addr); |
174 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr); | ||
175 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 283 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
176 | if (status){ | 284 | if (status){ |
177 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 285 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
178 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR," status = %d\n", status)); | ||
179 | return_VALUE(-EINVAL); | 286 | return_VALUE(-EINVAL); |
180 | } | 287 | } |
181 | acpi_hw_low_level_read(8, &tmp, &ec->data_addr); | 288 | acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr); |
182 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 289 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
183 | if(tmp != 0x90 ) {/* Burst ACK byte*/ | 290 | if(tmp != 0x90 ) {/* Burst ACK byte*/ |
184 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"Ack failed \n")); | ||
185 | return_VALUE(-EINVAL); | 291 | return_VALUE(-EINVAL); |
186 | } | 292 | } |
187 | } else | 293 | } |
188 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"already be in burst mode \n")); | 294 | |
189 | atomic_set(&ec->leaving_burst , 0); | 295 | atomic_set(&ec->burst.leaving_burst , 0); |
190 | return_VALUE(0); | 296 | return_VALUE(0); |
191 | } | 297 | } |
192 | 298 | ||
193 | static int | 299 | static int |
194 | acpi_ec_leave_burst_mode ( | 300 | acpi_ec_leave_burst_mode ( |
195 | struct acpi_ec *ec) | 301 | union acpi_ec *ec) |
196 | { | 302 | { |
197 | int status =0; | 303 | int status =0; |
198 | 304 | ||
199 | ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode"); | 305 | ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode"); |
200 | 306 | ||
201 | atomic_set(&ec->leaving_burst , 1); | 307 | atomic_set(&ec->burst.leaving_burst , 1); |
202 | status = acpi_ec_read_status(ec); | 308 | status = acpi_ec_read_status(ec); |
203 | if (status != -EINVAL && | 309 | if (status != -EINVAL && |
204 | (status & ACPI_EC_FLAG_BURST)){ | 310 | (status & ACPI_EC_FLAG_BURST)){ |
205 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"leaving burst mode\n")); | 311 | acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->common.command_addr); |
206 | acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->command_addr); | ||
207 | status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); | 312 | status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); |
208 | if (status){ | 313 | if (status){ |
209 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 314 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
210 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n")); | 315 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n")); |
211 | return_VALUE(-EINVAL); | 316 | return_VALUE(-EINVAL); |
212 | } | 317 | } |
213 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 318 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
214 | status = acpi_ec_read_status(ec); | 319 | status = acpi_ec_read_status(ec); |
215 | if (status != -EINVAL && | 320 | } |
216 | (status & ACPI_EC_FLAG_BURST)) { | ||
217 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->status fail\n")); | ||
218 | return_VALUE(-EINVAL); | ||
219 | } | ||
220 | }else | ||
221 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"already be in Non-burst mode \n")); | ||
222 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"leaving burst mode\n")); | ||
223 | 321 | ||
224 | return_VALUE(0); | 322 | return_VALUE(0); |
225 | } | 323 | } |
226 | 324 | ||
227 | static int | 325 | static int |
228 | acpi_ec_read ( | 326 | acpi_ec_read ( |
229 | 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, | ||
230 | u8 address, | 452 | u8 address, |
231 | u32 *data) | 453 | u32 *data) |
232 | { | 454 | { |
@@ -241,51 +463,51 @@ acpi_ec_read ( | |||
241 | retry: | 463 | retry: |
242 | *data = 0; | 464 | *data = 0; |
243 | 465 | ||
244 | if (ec->global_lock) { | 466 | if (ec->common.global_lock) { |
245 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | 467 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
246 | if (ACPI_FAILURE(status)) | 468 | if (ACPI_FAILURE(status)) |
247 | return_VALUE(-ENODEV); | 469 | return_VALUE(-ENODEV); |
248 | } | 470 | } |
249 | 471 | ||
250 | WARN_ON(in_interrupt()); | 472 | WARN_ON(in_interrupt()); |
251 | down(&ec->sem); | 473 | down(&ec->burst.sem); |
252 | 474 | ||
253 | if(acpi_ec_enter_burst_mode(ec)) | 475 | if(acpi_ec_enter_burst_mode(ec)) |
254 | goto end; | 476 | goto end; |
255 | 477 | ||
256 | 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); |
257 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 479 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
258 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 480 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
259 | if (status) { | 481 | if (status) { |
260 | goto end; | 482 | goto end; |
261 | } | 483 | } |
262 | 484 | ||
263 | acpi_hw_low_level_write(8, address, &ec->data_addr); | 485 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); |
264 | status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 486 | status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
265 | if (status){ | 487 | if (status){ |
266 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 488 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
267 | goto end; | 489 | goto end; |
268 | } | 490 | } |
269 | 491 | ||
270 | acpi_hw_low_level_read(8, data, &ec->data_addr); | 492 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); |
271 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 493 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
272 | 494 | ||
273 | 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", |
274 | *data, address)); | 496 | *data, address)); |
275 | 497 | ||
276 | end: | 498 | end: |
277 | acpi_ec_leave_burst_mode(ec); | 499 | acpi_ec_leave_burst_mode(ec); |
278 | up(&ec->sem); | 500 | up(&ec->burst.sem); |
279 | 501 | ||
280 | if (ec->global_lock) | 502 | if (ec->common.global_lock) |
281 | acpi_release_global_lock(glk); | 503 | acpi_release_global_lock(glk); |
282 | 504 | ||
283 | if(atomic_read(&ec->leaving_burst) == 2){ | 505 | if(atomic_read(&ec->burst.leaving_burst) == 2){ |
284 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); | 506 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); |
285 | while(atomic_read(&ec->pending_gpe)){ | 507 | while(atomic_read(&ec->burst.pending_gpe)){ |
286 | msleep(1); | 508 | msleep(1); |
287 | } | 509 | } |
288 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 510 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
289 | goto retry; | 511 | goto retry; |
290 | } | 512 | } |
291 | 513 | ||
@@ -294,8 +516,8 @@ end: | |||
294 | 516 | ||
295 | 517 | ||
296 | static int | 518 | static int |
297 | acpi_ec_write ( | 519 | acpi_ec_burst_write ( |
298 | struct acpi_ec *ec, | 520 | union acpi_ec *ec, |
299 | u8 address, | 521 | u8 address, |
300 | u8 data) | 522 | u8 data) |
301 | { | 523 | { |
@@ -308,14 +530,14 @@ acpi_ec_write ( | |||
308 | if (!ec) | 530 | if (!ec) |
309 | return_VALUE(-EINVAL); | 531 | return_VALUE(-EINVAL); |
310 | retry: | 532 | retry: |
311 | if (ec->global_lock) { | 533 | if (ec->common.global_lock) { |
312 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | 534 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
313 | if (ACPI_FAILURE(status)) | 535 | if (ACPI_FAILURE(status)) |
314 | return_VALUE(-ENODEV); | 536 | return_VALUE(-ENODEV); |
315 | } | 537 | } |
316 | 538 | ||
317 | WARN_ON(in_interrupt()); | 539 | WARN_ON(in_interrupt()); |
318 | down(&ec->sem); | 540 | down(&ec->burst.sem); |
319 | 541 | ||
320 | if(acpi_ec_enter_burst_mode(ec)) | 542 | if(acpi_ec_enter_burst_mode(ec)) |
321 | goto end; | 543 | goto end; |
@@ -323,33 +545,33 @@ retry: | |||
323 | status = acpi_ec_read_status(ec); | 545 | status = acpi_ec_read_status(ec); |
324 | if (status != -EINVAL && | 546 | if (status != -EINVAL && |
325 | !(status & ACPI_EC_FLAG_BURST)){ | 547 | !(status & ACPI_EC_FLAG_BURST)){ |
326 | 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); |
327 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 549 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
328 | if (status) | 550 | if (status) |
329 | goto end; | 551 | goto end; |
330 | acpi_hw_low_level_read(8, &tmp, &ec->data_addr); | 552 | acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr); |
331 | if(tmp != 0x90 ) /* Burst ACK byte*/ | 553 | if(tmp != 0x90 ) /* Burst ACK byte*/ |
332 | goto end; | 554 | goto end; |
333 | } | 555 | } |
334 | /*Now we are in burst mode*/ | 556 | /*Now we are in burst mode*/ |
335 | 557 | ||
336 | 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); |
337 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 559 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
338 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 560 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
339 | if (status){ | 561 | if (status){ |
340 | goto end; | 562 | goto end; |
341 | } | 563 | } |
342 | 564 | ||
343 | acpi_hw_low_level_write(8, address, &ec->data_addr); | 565 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); |
344 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 566 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
345 | if (status){ | 567 | if (status){ |
346 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 568 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
347 | goto end; | 569 | goto end; |
348 | } | 570 | } |
349 | 571 | ||
350 | acpi_hw_low_level_write(8, data, &ec->data_addr); | 572 | acpi_hw_low_level_write(8, data, &ec->common.data_addr); |
351 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 573 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
352 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 574 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
353 | if (status) | 575 | if (status) |
354 | goto end; | 576 | goto end; |
355 | 577 | ||
@@ -358,17 +580,17 @@ retry: | |||
358 | 580 | ||
359 | end: | 581 | end: |
360 | acpi_ec_leave_burst_mode(ec); | 582 | acpi_ec_leave_burst_mode(ec); |
361 | up(&ec->sem); | 583 | up(&ec->burst.sem); |
362 | 584 | ||
363 | if (ec->global_lock) | 585 | if (ec->common.global_lock) |
364 | acpi_release_global_lock(glk); | 586 | acpi_release_global_lock(glk); |
365 | 587 | ||
366 | if(atomic_read(&ec->leaving_burst) == 2){ | 588 | if(atomic_read(&ec->burst.leaving_burst) == 2){ |
367 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); | 589 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); |
368 | while(atomic_read(&ec->pending_gpe)){ | 590 | while(atomic_read(&ec->burst.pending_gpe)){ |
369 | msleep(1); | 591 | msleep(1); |
370 | } | 592 | } |
371 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 593 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
372 | goto retry; | 594 | goto retry; |
373 | } | 595 | } |
374 | 596 | ||
@@ -381,7 +603,7 @@ end: | |||
381 | int | 603 | int |
382 | ec_read(u8 addr, u8 *val) | 604 | ec_read(u8 addr, u8 *val) |
383 | { | 605 | { |
384 | struct acpi_ec *ec; | 606 | union acpi_ec *ec; |
385 | int err; | 607 | int err; |
386 | u32 temp_data; | 608 | u32 temp_data; |
387 | 609 | ||
@@ -404,7 +626,7 @@ EXPORT_SYMBOL(ec_read); | |||
404 | int | 626 | int |
405 | ec_write(u8 addr, u8 val) | 627 | ec_write(u8 addr, u8 val) |
406 | { | 628 | { |
407 | struct acpi_ec *ec; | 629 | union acpi_ec *ec; |
408 | int err; | 630 | int err; |
409 | 631 | ||
410 | if (!first_ec) | 632 | if (!first_ec) |
@@ -418,10 +640,66 @@ ec_write(u8 addr, u8 val) | |||
418 | } | 640 | } |
419 | EXPORT_SYMBOL(ec_write); | 641 | EXPORT_SYMBOL(ec_write); |
420 | 642 | ||
421 | |||
422 | static int | 643 | static int |
423 | acpi_ec_query ( | 644 | acpi_ec_query ( |
424 | 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, | ||
425 | u32 *data) | 703 | u32 *data) |
426 | { | 704 | { |
427 | int status = 0; | 705 | int status = 0; |
@@ -433,13 +711,13 @@ acpi_ec_query ( | |||
433 | return_VALUE(-EINVAL); | 711 | return_VALUE(-EINVAL); |
434 | *data = 0; | 712 | *data = 0; |
435 | 713 | ||
436 | if (ec->global_lock) { | 714 | if (ec->common.global_lock) { |
437 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | 715 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
438 | if (ACPI_FAILURE(status)) | 716 | if (ACPI_FAILURE(status)) |
439 | return_VALUE(-ENODEV); | 717 | return_VALUE(-ENODEV); |
440 | } | 718 | } |
441 | 719 | ||
442 | down(&ec->sem); | 720 | down(&ec->burst.sem); |
443 | if(acpi_ec_enter_burst_mode(ec)) | 721 | if(acpi_ec_enter_burst_mode(ec)) |
444 | goto end; | 722 | goto end; |
445 | /* | 723 | /* |
@@ -447,28 +725,28 @@ acpi_ec_query ( | |||
447 | * 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 |
448 | * bit to be cleared (and thus clearing the interrupt source). | 726 | * bit to be cleared (and thus clearing the interrupt source). |
449 | */ | 727 | */ |
450 | 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); |
451 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 729 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
452 | if (status){ | 730 | if (status){ |
453 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 731 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
454 | goto end; | 732 | goto end; |
455 | } | 733 | } |
456 | 734 | ||
457 | acpi_hw_low_level_read(8, data, &ec->data_addr); | 735 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); |
458 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 736 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
459 | if (!*data) | 737 | if (!*data) |
460 | status = -ENODATA; | 738 | status = -ENODATA; |
461 | 739 | ||
462 | end: | 740 | end: |
463 | acpi_ec_leave_burst_mode(ec); | 741 | acpi_ec_leave_burst_mode(ec); |
464 | up(&ec->sem); | 742 | up(&ec->burst.sem); |
465 | 743 | ||
466 | if (ec->global_lock) | 744 | if (ec->common.global_lock) |
467 | acpi_release_global_lock(glk); | 745 | acpi_release_global_lock(glk); |
468 | 746 | ||
469 | if(atomic_read(&ec->leaving_burst) == 2){ | 747 | if(atomic_read(&ec->burst.leaving_burst) == 2){ |
470 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); | 748 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); |
471 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 749 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
472 | status = -ENODATA; | 750 | status = -ENODATA; |
473 | } | 751 | } |
474 | return_VALUE(status); | 752 | return_VALUE(status); |
@@ -479,7 +757,7 @@ end: | |||
479 | Event Management | 757 | Event Management |
480 | -------------------------------------------------------------------------- */ | 758 | -------------------------------------------------------------------------- */ |
481 | 759 | ||
482 | struct acpi_ec_query_data { | 760 | union acpi_ec_query_data { |
483 | acpi_handle handle; | 761 | acpi_handle handle; |
484 | u8 data; | 762 | u8 data; |
485 | }; | 763 | }; |
@@ -488,7 +766,59 @@ static void | |||
488 | acpi_ec_gpe_query ( | 766 | acpi_ec_gpe_query ( |
489 | void *ec_cxt) | 767 | void *ec_cxt) |
490 | { | 768 | { |
491 | 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; | ||
492 | u32 value; | 822 | u32 value; |
493 | int result = -ENODATA; | 823 | int result = -ENODATA; |
494 | static char object_name[5] = {'_','Q','0','0','\0'}; | 824 | static char object_name[5] = {'_','Q','0','0','\0'}; |
@@ -508,9 +838,9 @@ acpi_ec_gpe_query ( | |||
508 | 838 | ||
509 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); | 839 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); |
510 | 840 | ||
511 | acpi_evaluate_object(ec->handle, object_name, NULL, NULL); | 841 | acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL); |
512 | end: | 842 | end: |
513 | atomic_dec(&ec->pending_gpe); | 843 | atomic_dec(&ec->burst.pending_gpe); |
514 | return; | 844 | return; |
515 | } | 845 | } |
516 | 846 | ||
@@ -518,48 +848,77 @@ static u32 | |||
518 | acpi_ec_gpe_handler ( | 848 | acpi_ec_gpe_handler ( |
519 | void *data) | 849 | void *data) |
520 | { | 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 | { | ||
521 | acpi_status status = AE_OK; | 880 | acpi_status status = AE_OK; |
522 | u32 value; | 881 | u32 value; |
523 | struct acpi_ec *ec = (struct acpi_ec *) data; | 882 | union acpi_ec *ec = (union acpi_ec *) data; |
524 | 883 | ||
525 | if (!ec) | 884 | if (!ec) |
526 | return ACPI_INTERRUPT_NOT_HANDLED; | 885 | return ACPI_INTERRUPT_NOT_HANDLED; |
527 | 886 | ||
528 | acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR); | 887 | acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
529 | 888 | ||
530 | value = acpi_ec_read_status(ec); | 889 | value = acpi_ec_read_status(ec); |
531 | 890 | ||
532 | if((value & ACPI_EC_FLAG_IBF) && | 891 | if((value & ACPI_EC_FLAG_IBF) && |
533 | !(value & ACPI_EC_FLAG_BURST) && | 892 | !(value & ACPI_EC_FLAG_BURST) && |
534 | (atomic_read(&ec->leaving_burst) == 0)) { | 893 | (atomic_read(&ec->burst.leaving_burst) == 0)) { |
535 | /* | 894 | /* |
536 | * the embedded controller disables | 895 | * the embedded controller disables |
537 | * burst mode for any reason other | 896 | * burst mode for any reason other |
538 | * than the burst disable command | 897 | * than the burst disable command |
539 | * to process critical event. | 898 | * to process critical event. |
540 | */ | 899 | */ |
541 | atomic_set(&ec->leaving_burst , 2); /* block current pending transaction | 900 | atomic_set(&ec->burst.leaving_burst , 2); /* block current pending transaction |
542 | and retry */ | 901 | and retry */ |
543 | wake_up(&ec->wait); | 902 | wake_up(&ec->burst.wait); |
544 | }else { | 903 | }else { |
545 | if ((ec->expect_event == ACPI_EC_EVENT_OBF && | 904 | if ((ec->burst.expect_event == ACPI_EC_EVENT_OBF && |
546 | (value & ACPI_EC_FLAG_OBF)) || | 905 | (value & ACPI_EC_FLAG_OBF)) || |
547 | (ec->expect_event == ACPI_EC_EVENT_IBE && | 906 | (ec->burst.expect_event == ACPI_EC_EVENT_IBE && |
548 | !(value & ACPI_EC_FLAG_IBF))) { | 907 | !(value & ACPI_EC_FLAG_IBF))) { |
549 | ec->expect_event = 0; | 908 | ec->burst.expect_event = 0; |
550 | wake_up(&ec->wait); | 909 | wake_up(&ec->burst.wait); |
551 | return ACPI_INTERRUPT_HANDLED; | 910 | return ACPI_INTERRUPT_HANDLED; |
552 | } | 911 | } |
553 | } | 912 | } |
554 | 913 | ||
555 | if (value & ACPI_EC_FLAG_SCI){ | 914 | if (value & ACPI_EC_FLAG_SCI){ |
556 | atomic_add(1, &ec->pending_gpe) ; | 915 | atomic_add(1, &ec->burst.pending_gpe) ; |
557 | status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, | 916 | status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, |
558 | acpi_ec_gpe_query, ec); | 917 | acpi_ec_gpe_query, ec); |
559 | return status == AE_OK ? | 918 | return status == AE_OK ? |
560 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; | 919 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
561 | } | 920 | } |
562 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR); | 921 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
563 | return status == AE_OK ? | 922 | return status == AE_OK ? |
564 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; | 923 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
565 | } | 924 | } |
@@ -596,7 +955,7 @@ acpi_ec_space_handler ( | |||
596 | void *region_context) | 955 | void *region_context) |
597 | { | 956 | { |
598 | int result = 0; | 957 | int result = 0; |
599 | struct acpi_ec *ec = NULL; | 958 | union acpi_ec *ec = NULL; |
600 | u64 temp = *value; | 959 | u64 temp = *value; |
601 | acpi_integer f_v = 0; | 960 | acpi_integer f_v = 0; |
602 | int i = 0; | 961 | int i = 0; |
@@ -611,7 +970,7 @@ acpi_ec_space_handler ( | |||
611 | return_VALUE(AE_BAD_PARAMETER); | 970 | return_VALUE(AE_BAD_PARAMETER); |
612 | } | 971 | } |
613 | 972 | ||
614 | ec = (struct acpi_ec *) handler_context; | 973 | ec = (union acpi_ec *) handler_context; |
615 | 974 | ||
616 | next_byte: | 975 | next_byte: |
617 | switch (function) { | 976 | switch (function) { |
@@ -672,7 +1031,7 @@ static struct proc_dir_entry *acpi_ec_dir; | |||
672 | static int | 1031 | static int |
673 | acpi_ec_read_info (struct seq_file *seq, void *offset) | 1032 | acpi_ec_read_info (struct seq_file *seq, void *offset) |
674 | { | 1033 | { |
675 | struct acpi_ec *ec = (struct acpi_ec *) seq->private; | 1034 | union acpi_ec *ec = (union acpi_ec *) seq->private; |
676 | 1035 | ||
677 | ACPI_FUNCTION_TRACE("acpi_ec_read_info"); | 1036 | ACPI_FUNCTION_TRACE("acpi_ec_read_info"); |
678 | 1037 | ||
@@ -680,12 +1039,12 @@ acpi_ec_read_info (struct seq_file *seq, void *offset) | |||
680 | goto end; | 1039 | goto end; |
681 | 1040 | ||
682 | seq_printf(seq, "gpe bit: 0x%02x\n", | 1041 | seq_printf(seq, "gpe bit: 0x%02x\n", |
683 | (u32) ec->gpe_bit); | 1042 | (u32) ec->common.gpe_bit); |
684 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", | 1043 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", |
685 | (u32) ec->status_addr.address, (u32) ec->data_addr.address); | 1044 | (u32) ec->common.status_addr.address, (u32) ec->common.data_addr.address); |
686 | seq_printf(seq, "use global lock: %s\n", | 1045 | seq_printf(seq, "use global lock: %s\n", |
687 | ec->global_lock?"yes":"no"); | 1046 | ec->common.global_lock?"yes":"no"); |
688 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 1047 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
689 | 1048 | ||
690 | end: | 1049 | end: |
691 | return_VALUE(0); | 1050 | return_VALUE(0); |
@@ -708,7 +1067,7 @@ static int | |||
708 | acpi_ec_add_fs ( | 1067 | acpi_ec_add_fs ( |
709 | struct acpi_device *device) | 1068 | struct acpi_device *device) |
710 | { | 1069 | { |
711 | struct proc_dir_entry *entry; | 1070 | struct proc_dir_entry *entry = NULL; |
712 | 1071 | ||
713 | ACPI_FUNCTION_TRACE("acpi_ec_add_fs"); | 1072 | ACPI_FUNCTION_TRACE("acpi_ec_add_fs"); |
714 | 1073 | ||
@@ -755,13 +1114,82 @@ acpi_ec_remove_fs ( | |||
755 | Driver Interface | 1114 | Driver Interface |
756 | -------------------------------------------------------------------------- */ | 1115 | -------------------------------------------------------------------------- */ |
757 | 1116 | ||
1117 | |||
758 | static int | 1118 | static int |
759 | acpi_ec_add ( | 1119 | acpi_ec_polling_add ( |
760 | struct acpi_device *device) | 1120 | struct acpi_device *device) |
761 | { | 1121 | { |
762 | int result; | 1122 | int result = 0; |
763 | acpi_status status; | 1123 | acpi_status status = AE_OK; |
764 | 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; | ||
765 | unsigned long uid; | 1193 | unsigned long uid; |
766 | 1194 | ||
767 | ACPI_FUNCTION_TRACE("acpi_ec_add"); | 1195 | ACPI_FUNCTION_TRACE("acpi_ec_add"); |
@@ -769,39 +1197,39 @@ acpi_ec_add ( | |||
769 | if (!device) | 1197 | if (!device) |
770 | return_VALUE(-EINVAL); | 1198 | return_VALUE(-EINVAL); |
771 | 1199 | ||
772 | ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 1200 | ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
773 | if (!ec) | 1201 | if (!ec) |
774 | return_VALUE(-ENOMEM); | 1202 | return_VALUE(-ENOMEM); |
775 | memset(ec, 0, sizeof(struct acpi_ec)); | 1203 | memset(ec, 0, sizeof(union acpi_ec)); |
776 | 1204 | ||
777 | ec->handle = device->handle; | 1205 | ec->common.handle = device->handle; |
778 | ec->uid = -1; | 1206 | ec->common.uid = -1; |
779 | atomic_set(&ec->pending_gpe, 0); | 1207 | atomic_set(&ec->burst.pending_gpe, 0); |
780 | atomic_set(&ec->leaving_burst , 1); | 1208 | atomic_set(&ec->burst.leaving_burst , 1); |
781 | init_MUTEX(&ec->sem); | 1209 | init_MUTEX(&ec->burst.sem); |
782 | init_waitqueue_head(&ec->wait); | 1210 | init_waitqueue_head(&ec->burst.wait); |
783 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); | 1211 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
784 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); | 1212 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
785 | acpi_driver_data(device) = ec; | 1213 | acpi_driver_data(device) = ec; |
786 | 1214 | ||
787 | /* Use the global lock for all EC transactions? */ | 1215 | /* Use the global lock for all EC transactions? */ |
788 | acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock); | 1216 | acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, &ec->common.global_lock); |
789 | 1217 | ||
790 | /* If our UID matches the UID for the ECDT-enumerated EC, | 1218 | /* If our UID matches the UID for the ECDT-enumerated EC, |
791 | 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.*/ |
792 | acpi_evaluate_integer(ec->handle, "_UID", NULL, &uid); | 1220 | acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid); |
793 | if (ec_ecdt && ec_ecdt->uid == uid) { | 1221 | if (ec_ecdt && ec_ecdt->common.uid == uid) { |
794 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, | 1222 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, |
795 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); | 1223 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); |
796 | 1224 | ||
797 | 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); |
798 | 1226 | ||
799 | kfree(ec_ecdt); | 1227 | kfree(ec_ecdt); |
800 | } | 1228 | } |
801 | 1229 | ||
802 | /* Get GPE bit assignment (EC events). */ | 1230 | /* Get GPE bit assignment (EC events). */ |
803 | /* TODO: Add support for _GPE returning a package */ | 1231 | /* TODO: Add support for _GPE returning a package */ |
804 | 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); |
805 | if (ACPI_FAILURE(status)) { | 1233 | if (ACPI_FAILURE(status)) { |
806 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 1234 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
807 | "Error obtaining GPE bit assignment\n")); | 1235 | "Error obtaining GPE bit assignment\n")); |
@@ -815,7 +1243,7 @@ acpi_ec_add ( | |||
815 | 1243 | ||
816 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n", | 1244 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n", |
817 | acpi_device_name(device), acpi_device_bid(device), | 1245 | acpi_device_name(device), acpi_device_bid(device), |
818 | (u32) ec->gpe_bit); | 1246 | (u32) ec->common.gpe_bit); |
819 | 1247 | ||
820 | if (!first_ec) | 1248 | if (!first_ec) |
821 | first_ec = device; | 1249 | first_ec = device; |
@@ -833,7 +1261,7 @@ acpi_ec_remove ( | |||
833 | struct acpi_device *device, | 1261 | struct acpi_device *device, |
834 | int type) | 1262 | int type) |
835 | { | 1263 | { |
836 | struct acpi_ec *ec; | 1264 | union acpi_ec *ec = NULL; |
837 | 1265 | ||
838 | ACPI_FUNCTION_TRACE("acpi_ec_remove"); | 1266 | ACPI_FUNCTION_TRACE("acpi_ec_remove"); |
839 | 1267 | ||
@@ -855,7 +1283,7 @@ acpi_ec_io_ports ( | |||
855 | struct acpi_resource *resource, | 1283 | struct acpi_resource *resource, |
856 | void *context) | 1284 | void *context) |
857 | { | 1285 | { |
858 | struct acpi_ec *ec = (struct acpi_ec *) context; | 1286 | union acpi_ec *ec = (union acpi_ec *) context; |
859 | struct acpi_generic_address *addr; | 1287 | struct acpi_generic_address *addr; |
860 | 1288 | ||
861 | if (resource->id != ACPI_RSTYPE_IO) { | 1289 | if (resource->id != ACPI_RSTYPE_IO) { |
@@ -867,10 +1295,10 @@ acpi_ec_io_ports ( | |||
867 | * the second address region returned is the status/command | 1295 | * the second address region returned is the status/command |
868 | * port. | 1296 | * port. |
869 | */ | 1297 | */ |
870 | if (ec->data_addr.register_bit_width == 0) { | 1298 | if (ec->common.data_addr.register_bit_width == 0) { |
871 | addr = &ec->data_addr; | 1299 | addr = &ec->common.data_addr; |
872 | } else if (ec->command_addr.register_bit_width == 0) { | 1300 | } else if (ec->common.command_addr.register_bit_width == 0) { |
873 | addr = &ec->command_addr; | 1301 | addr = &ec->common.command_addr; |
874 | } else { | 1302 | } else { |
875 | return AE_CTRL_TERMINATE; | 1303 | return AE_CTRL_TERMINATE; |
876 | } | 1304 | } |
@@ -888,8 +1316,8 @@ static int | |||
888 | acpi_ec_start ( | 1316 | acpi_ec_start ( |
889 | struct acpi_device *device) | 1317 | struct acpi_device *device) |
890 | { | 1318 | { |
891 | acpi_status status; | 1319 | acpi_status status = AE_OK; |
892 | struct acpi_ec *ec; | 1320 | union acpi_ec *ec = NULL; |
893 | 1321 | ||
894 | ACPI_FUNCTION_TRACE("acpi_ec_start"); | 1322 | ACPI_FUNCTION_TRACE("acpi_ec_start"); |
895 | 1323 | ||
@@ -904,35 +1332,36 @@ acpi_ec_start ( | |||
904 | /* | 1332 | /* |
905 | * Get I/O port addresses. Convert to GAS format. | 1333 | * Get I/O port addresses. Convert to GAS format. |
906 | */ | 1334 | */ |
907 | status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS, | 1335 | status = acpi_walk_resources(ec->common.handle, METHOD_NAME__CRS, |
908 | acpi_ec_io_ports, ec); | 1336 | acpi_ec_io_ports, ec); |
909 | if (ACPI_FAILURE(status) || ec->command_addr.register_bit_width == 0) { | 1337 | if (ACPI_FAILURE(status) || ec->common.command_addr.register_bit_width == 0) { |
910 | 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")); |
911 | return_VALUE(-ENODEV); | 1339 | return_VALUE(-ENODEV); |
912 | } | 1340 | } |
913 | 1341 | ||
914 | ec->status_addr = ec->command_addr; | 1342 | ec->common.status_addr = ec->common.command_addr; |
915 | 1343 | ||
916 | 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", |
917 | (u32) ec->gpe_bit, (u32) ec->command_addr.address, | 1345 | (u32) ec->common.gpe_bit, (u32) ec->common.command_addr.address, |
918 | (u32) ec->data_addr.address)); | 1346 | (u32) ec->common.data_addr.address)); |
1347 | |||
919 | 1348 | ||
920 | /* | 1349 | /* |
921 | * Install GPE handler | 1350 | * Install GPE handler |
922 | */ | 1351 | */ |
923 | status = acpi_install_gpe_handler(NULL, ec->gpe_bit, | 1352 | status = acpi_install_gpe_handler(NULL, ec->common.gpe_bit, |
924 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec); | 1353 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec); |
925 | if (ACPI_FAILURE(status)) { | 1354 | if (ACPI_FAILURE(status)) { |
926 | return_VALUE(-ENODEV); | 1355 | return_VALUE(-ENODEV); |
927 | } | 1356 | } |
928 | 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); |
929 | acpi_enable_gpe (NULL, ec->gpe_bit, ACPI_NOT_ISR); | 1358 | acpi_enable_gpe (NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
930 | 1359 | ||
931 | status = acpi_install_address_space_handler (ec->handle, | 1360 | status = acpi_install_address_space_handler (ec->common.handle, |
932 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, | 1361 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, |
933 | &acpi_ec_space_setup, ec); | 1362 | &acpi_ec_space_setup, ec); |
934 | if (ACPI_FAILURE(status)) { | 1363 | if (ACPI_FAILURE(status)) { |
935 | 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); |
936 | return_VALUE(-ENODEV); | 1365 | return_VALUE(-ENODEV); |
937 | } | 1366 | } |
938 | 1367 | ||
@@ -945,8 +1374,8 @@ acpi_ec_stop ( | |||
945 | struct acpi_device *device, | 1374 | struct acpi_device *device, |
946 | int type) | 1375 | int type) |
947 | { | 1376 | { |
948 | acpi_status status; | 1377 | acpi_status status = AE_OK; |
949 | struct acpi_ec *ec; | 1378 | union acpi_ec *ec = NULL; |
950 | 1379 | ||
951 | ACPI_FUNCTION_TRACE("acpi_ec_stop"); | 1380 | ACPI_FUNCTION_TRACE("acpi_ec_stop"); |
952 | 1381 | ||
@@ -955,12 +1384,12 @@ acpi_ec_stop ( | |||
955 | 1384 | ||
956 | ec = acpi_driver_data(device); | 1385 | ec = acpi_driver_data(device); |
957 | 1386 | ||
958 | status = acpi_remove_address_space_handler(ec->handle, | 1387 | status = acpi_remove_address_space_handler(ec->common.handle, |
959 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); | 1388 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); |
960 | if (ACPI_FAILURE(status)) | 1389 | if (ACPI_FAILURE(status)) |
961 | return_VALUE(-ENODEV); | 1390 | return_VALUE(-ENODEV); |
962 | 1391 | ||
963 | 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); |
964 | if (ACPI_FAILURE(status)) | 1393 | if (ACPI_FAILURE(status)) |
965 | return_VALUE(-ENODEV); | 1394 | return_VALUE(-ENODEV); |
966 | 1395 | ||
@@ -974,26 +1403,76 @@ acpi_fake_ecdt_callback ( | |||
974 | void *context, | 1403 | void *context, |
975 | void **retval) | 1404 | void **retval) |
976 | { | 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 | { | ||
977 | acpi_status status; | 1422 | acpi_status status; |
978 | 1423 | ||
979 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, | 1424 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
980 | acpi_ec_io_ports, ec_ecdt); | 1425 | acpi_ec_io_ports, ec_ecdt); |
981 | if (ACPI_FAILURE(status)) | 1426 | if (ACPI_FAILURE(status)) |
982 | return status; | 1427 | return status; |
983 | ec_ecdt->status_addr = ec_ecdt->command_addr; | 1428 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; |
984 | 1429 | ||
985 | ec_ecdt->uid = -1; | 1430 | ec_ecdt->common.uid = -1; |
986 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); | 1431 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); |
987 | 1432 | ||
988 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe_bit); | 1433 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit); |
989 | if (ACPI_FAILURE(status)) | 1434 | if (ACPI_FAILURE(status)) |
990 | return status; | 1435 | return status; |
991 | ec_ecdt->global_lock = TRUE; | 1436 | spin_lock_init(&ec_ecdt->polling.lock); |
992 | ec_ecdt->handle = handle; | 1437 | ec_ecdt->common.global_lock = TRUE; |
1438 | ec_ecdt->common.handle = handle; | ||
993 | 1439 | ||
994 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", | 1440 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", |
995 | (u32) ec_ecdt->gpe_bit, (u32) ec_ecdt->command_addr.address, | 1441 | (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address, |
996 | (u32) ec_ecdt->data_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 | { | ||
1454 | acpi_status status; | ||
1455 | |||
1456 | init_MUTEX(&ec_ecdt->burst.sem); | ||
1457 | init_waitqueue_head(&ec_ecdt->burst.wait); | ||
1458 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, | ||
1459 | acpi_ec_io_ports, ec_ecdt); | ||
1460 | if (ACPI_FAILURE(status)) | ||
1461 | return status; | ||
1462 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; | ||
1463 | |||
1464 | ec_ecdt->common.uid = -1; | ||
1465 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); | ||
1466 | |||
1467 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit); | ||
1468 | if (ACPI_FAILURE(status)) | ||
1469 | return status; | ||
1470 | ec_ecdt->common.global_lock = TRUE; | ||
1471 | ec_ecdt->common.handle = handle; | ||
1472 | |||
1473 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", | ||
1474 | (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address, | ||
1475 | (u32) ec_ecdt->common.data_addr.address); | ||
997 | 1476 | ||
998 | return AE_CTRL_TERMINATE; | 1477 | return AE_CTRL_TERMINATE; |
999 | } | 1478 | } |
@@ -1016,12 +1495,12 @@ acpi_ec_fake_ecdt(void) | |||
1016 | 1495 | ||
1017 | printk(KERN_INFO PREFIX "Try to make an fake ECDT\n"); | 1496 | printk(KERN_INFO PREFIX "Try to make an fake ECDT\n"); |
1018 | 1497 | ||
1019 | ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 1498 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
1020 | if (!ec_ecdt) { | 1499 | if (!ec_ecdt) { |
1021 | ret = -ENOMEM; | 1500 | ret = -ENOMEM; |
1022 | goto error; | 1501 | goto error; |
1023 | } | 1502 | } |
1024 | memset(ec_ecdt, 0, sizeof(struct acpi_ec)); | 1503 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
1025 | 1504 | ||
1026 | status = acpi_get_devices (ACPI_EC_HID, | 1505 | status = acpi_get_devices (ACPI_EC_HID, |
1027 | acpi_fake_ecdt_callback, | 1506 | acpi_fake_ecdt_callback, |
@@ -1042,6 +1521,60 @@ error: | |||
1042 | static int __init | 1521 | static int __init |
1043 | acpi_ec_get_real_ecdt(void) | 1522 | acpi_ec_get_real_ecdt(void) |
1044 | { | 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 | { | ||
1045 | acpi_status status; | 1578 | acpi_status status; |
1046 | struct acpi_table_ecdt *ecdt_ptr; | 1579 | struct acpi_table_ecdt *ecdt_ptr; |
1047 | 1580 | ||
@@ -1055,22 +1588,22 @@ acpi_ec_get_real_ecdt(void) | |||
1055 | /* | 1588 | /* |
1056 | * 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 |
1057 | */ | 1590 | */ |
1058 | ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 1591 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
1059 | if (!ec_ecdt) | 1592 | if (!ec_ecdt) |
1060 | return -ENOMEM; | 1593 | return -ENOMEM; |
1061 | memset(ec_ecdt, 0, sizeof(struct acpi_ec)); | 1594 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
1062 | 1595 | ||
1063 | init_MUTEX(&ec_ecdt->sem); | 1596 | init_MUTEX(&ec_ecdt->burst.sem); |
1064 | init_waitqueue_head(&ec_ecdt->wait); | 1597 | init_waitqueue_head(&ec_ecdt->burst.wait); |
1065 | ec_ecdt->command_addr = ecdt_ptr->ec_control; | 1598 | ec_ecdt->common.command_addr = ecdt_ptr->ec_control; |
1066 | ec_ecdt->status_addr = ecdt_ptr->ec_control; | 1599 | ec_ecdt->common.status_addr = ecdt_ptr->ec_control; |
1067 | ec_ecdt->data_addr = ecdt_ptr->ec_data; | 1600 | ec_ecdt->common.data_addr = ecdt_ptr->ec_data; |
1068 | ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; | 1601 | ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit; |
1069 | /* use the GL just to be safe */ | 1602 | /* use the GL just to be safe */ |
1070 | ec_ecdt->global_lock = TRUE; | 1603 | ec_ecdt->common.global_lock = TRUE; |
1071 | ec_ecdt->uid = ecdt_ptr->uid; | 1604 | ec_ecdt->common.uid = ecdt_ptr->uid; |
1072 | 1605 | ||
1073 | 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); |
1074 | if (ACPI_FAILURE(status)) { | 1607 | if (ACPI_FAILURE(status)) { |
1075 | goto error; | 1608 | goto error; |
1076 | } | 1609 | } |
@@ -1103,20 +1636,20 @@ acpi_ec_ecdt_probe (void) | |||
1103 | /* | 1636 | /* |
1104 | * Install GPE handler | 1637 | * Install GPE handler |
1105 | */ | 1638 | */ |
1106 | status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit, | 1639 | status = acpi_install_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
1107 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, | 1640 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, |
1108 | ec_ecdt); | 1641 | ec_ecdt); |
1109 | if (ACPI_FAILURE(status)) { | 1642 | if (ACPI_FAILURE(status)) { |
1110 | goto error; | 1643 | goto error; |
1111 | } | 1644 | } |
1112 | 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); |
1113 | acpi_enable_gpe (NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR); | 1646 | acpi_enable_gpe (NULL, ec_ecdt->common.gpe_bit, ACPI_NOT_ISR); |
1114 | 1647 | ||
1115 | status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT, | 1648 | status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT, |
1116 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, | 1649 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, |
1117 | &acpi_ec_space_setup, ec_ecdt); | 1650 | &acpi_ec_space_setup, ec_ecdt); |
1118 | if (ACPI_FAILURE(status)) { | 1651 | if (ACPI_FAILURE(status)) { |
1119 | acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, | 1652 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
1120 | &acpi_ec_gpe_handler); | 1653 | &acpi_ec_gpe_handler); |
1121 | goto error; | 1654 | goto error; |
1122 | } | 1655 | } |
@@ -1134,7 +1667,7 @@ error: | |||
1134 | 1667 | ||
1135 | static int __init acpi_ec_init (void) | 1668 | static int __init acpi_ec_init (void) |
1136 | { | 1669 | { |
1137 | int result; | 1670 | int result = 0; |
1138 | 1671 | ||
1139 | ACPI_FUNCTION_TRACE("acpi_ec_init"); | 1672 | ACPI_FUNCTION_TRACE("acpi_ec_init"); |
1140 | 1673 | ||
@@ -1178,3 +1711,10 @@ static int __init acpi_fake_ecdt_setup(char *str) | |||
1178 | return 0; | 1711 | return 0; |
1179 | } | 1712 | } |
1180 | __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); | ||