aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/ec.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/ec.c')
-rw-r--r--drivers/acpi/ec.c107
1 files changed, 69 insertions, 38 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index cb6066c809ea..3d304ff7f095 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -128,12 +128,13 @@ static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */
128static int EC_FLAGS_CLEAR_ON_RESUME; /* Needs acpi_ec_clear() on boot/resume */ 128static int EC_FLAGS_CLEAR_ON_RESUME; /* Needs acpi_ec_clear() on boot/resume */
129 129
130/* -------------------------------------------------------------------------- 130/* --------------------------------------------------------------------------
131 Transaction Management 131 * Transaction Management
132 -------------------------------------------------------------------------- */ 132 * -------------------------------------------------------------------------- */
133 133
134static inline u8 acpi_ec_read_status(struct acpi_ec *ec) 134static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
135{ 135{
136 u8 x = inb(ec->command_addr); 136 u8 x = inb(ec->command_addr);
137
137 pr_debug("EC_SC(R) = 0x%2.2x " 138 pr_debug("EC_SC(R) = 0x%2.2x "
138 "SCI_EVT=%d BURST=%d CMD=%d IBF=%d OBF=%d\n", 139 "SCI_EVT=%d BURST=%d CMD=%d IBF=%d OBF=%d\n",
139 x, 140 x,
@@ -148,6 +149,7 @@ static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
148static inline u8 acpi_ec_read_data(struct acpi_ec *ec) 149static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
149{ 150{
150 u8 x = inb(ec->data_addr); 151 u8 x = inb(ec->data_addr);
152
151 pr_debug("EC_DATA(R) = 0x%2.2x\n", x); 153 pr_debug("EC_DATA(R) = 0x%2.2x\n", x);
152 return x; 154 return x;
153} 155}
@@ -164,10 +166,32 @@ static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
164 outb(data, ec->data_addr); 166 outb(data, ec->data_addr);
165} 167}
166 168
169#ifdef DEBUG
170static const char *acpi_ec_cmd_string(u8 cmd)
171{
172 switch (cmd) {
173 case 0x80:
174 return "RD_EC";
175 case 0x81:
176 return "WR_EC";
177 case 0x82:
178 return "BE_EC";
179 case 0x83:
180 return "BD_EC";
181 case 0x84:
182 return "QR_EC";
183 }
184 return "UNKNOWN";
185}
186#else
187#define acpi_ec_cmd_string(cmd) "UNDEF"
188#endif
189
167static int ec_transaction_completed(struct acpi_ec *ec) 190static int ec_transaction_completed(struct acpi_ec *ec)
168{ 191{
169 unsigned long flags; 192 unsigned long flags;
170 int ret = 0; 193 int ret = 0;
194
171 spin_lock_irqsave(&ec->lock, flags); 195 spin_lock_irqsave(&ec->lock, flags);
172 if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_COMPLETE)) 196 if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_COMPLETE))
173 ret = 1; 197 ret = 1;
@@ -181,7 +205,8 @@ static bool advance_transaction(struct acpi_ec *ec)
181 u8 status; 205 u8 status;
182 bool wakeup = false; 206 bool wakeup = false;
183 207
184 pr_debug("===== %s =====\n", in_interrupt() ? "IRQ" : "TASK"); 208 pr_debug("===== %s (%d) =====\n",
209 in_interrupt() ? "IRQ" : "TASK", smp_processor_id());
185 status = acpi_ec_read_status(ec); 210 status = acpi_ec_read_status(ec);
186 t = ec->curr; 211 t = ec->curr;
187 if (!t) 212 if (!t)
@@ -198,7 +223,8 @@ static bool advance_transaction(struct acpi_ec *ec)
198 if (t->rlen == t->ri) { 223 if (t->rlen == t->ri) {
199 t->flags |= ACPI_EC_COMMAND_COMPLETE; 224 t->flags |= ACPI_EC_COMMAND_COMPLETE;
200 if (t->command == ACPI_EC_COMMAND_QUERY) 225 if (t->command == ACPI_EC_COMMAND_QUERY)
201 pr_debug("hardware QR_EC completion\n"); 226 pr_debug("***** Command(%s) hardware completion *****\n",
227 acpi_ec_cmd_string(t->command));
202 wakeup = true; 228 wakeup = true;
203 } 229 }
204 } else 230 } else
@@ -221,7 +247,8 @@ static bool advance_transaction(struct acpi_ec *ec)
221 t->flags |= ACPI_EC_COMMAND_POLL; 247 t->flags |= ACPI_EC_COMMAND_POLL;
222 t->rdata[t->ri++] = 0x00; 248 t->rdata[t->ri++] = 0x00;
223 t->flags |= ACPI_EC_COMMAND_COMPLETE; 249 t->flags |= ACPI_EC_COMMAND_COMPLETE;
224 pr_debug("software QR_EC completion\n"); 250 pr_debug("***** Command(%s) software completion *****\n",
251 acpi_ec_cmd_string(t->command));
225 wakeup = true; 252 wakeup = true;
226 } else if ((status & ACPI_EC_FLAG_IBF) == 0) { 253 } else if ((status & ACPI_EC_FLAG_IBF) == 0) {
227 acpi_ec_write_cmd(ec, t->command); 254 acpi_ec_write_cmd(ec, t->command);
@@ -264,6 +291,7 @@ static int ec_poll(struct acpi_ec *ec)
264{ 291{
265 unsigned long flags; 292 unsigned long flags;
266 int repeat = 5; /* number of command restarts */ 293 int repeat = 5; /* number of command restarts */
294
267 while (repeat--) { 295 while (repeat--) {
268 unsigned long delay = jiffies + 296 unsigned long delay = jiffies +
269 msecs_to_jiffies(ec_delay); 297 msecs_to_jiffies(ec_delay);
@@ -296,18 +324,25 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
296{ 324{
297 unsigned long tmp; 325 unsigned long tmp;
298 int ret = 0; 326 int ret = 0;
327
299 if (EC_FLAGS_MSI) 328 if (EC_FLAGS_MSI)
300 udelay(ACPI_EC_MSI_UDELAY); 329 udelay(ACPI_EC_MSI_UDELAY);
301 /* start transaction */ 330 /* start transaction */
302 spin_lock_irqsave(&ec->lock, tmp); 331 spin_lock_irqsave(&ec->lock, tmp);
303 /* following two actions should be kept atomic */ 332 /* following two actions should be kept atomic */
304 ec->curr = t; 333 ec->curr = t;
334 pr_debug("***** Command(%s) started *****\n",
335 acpi_ec_cmd_string(t->command));
305 start_transaction(ec); 336 start_transaction(ec);
306 spin_unlock_irqrestore(&ec->lock, tmp); 337 spin_unlock_irqrestore(&ec->lock, tmp);
307 ret = ec_poll(ec); 338 ret = ec_poll(ec);
308 spin_lock_irqsave(&ec->lock, tmp); 339 spin_lock_irqsave(&ec->lock, tmp);
309 if (ec->curr->command == ACPI_EC_COMMAND_QUERY) 340 if (ec->curr->command == ACPI_EC_COMMAND_QUERY) {
310 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); 341 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
342 pr_debug("***** Event stopped *****\n");
343 }
344 pr_debug("***** Command(%s) stopped *****\n",
345 acpi_ec_cmd_string(t->command));
311 ec->curr = NULL; 346 ec->curr = NULL;
312 spin_unlock_irqrestore(&ec->lock, tmp); 347 spin_unlock_irqrestore(&ec->lock, tmp);
313 return ret; 348 return ret;
@@ -317,6 +352,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
317{ 352{
318 int status; 353 int status;
319 u32 glk; 354 u32 glk;
355
320 if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata)) 356 if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata))
321 return -EINVAL; 357 return -EINVAL;
322 if (t->rdata) 358 if (t->rdata)
@@ -333,8 +369,6 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
333 goto unlock; 369 goto unlock;
334 } 370 }
335 } 371 }
336 pr_debug("transaction start (cmd=0x%02x, addr=0x%02x)\n",
337 t->command, t->wdata ? t->wdata[0] : 0);
338 /* disable GPE during transaction if storm is detected */ 372 /* disable GPE during transaction if storm is detected */
339 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) { 373 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
340 /* It has to be disabled, so that it doesn't trigger. */ 374 /* It has to be disabled, so that it doesn't trigger. */
@@ -355,7 +389,6 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
355 t->irq_count); 389 t->irq_count);
356 set_bit(EC_FLAGS_GPE_STORM, &ec->flags); 390 set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
357 } 391 }
358 pr_debug("transaction end\n");
359 if (ec->global_lock) 392 if (ec->global_lock)
360 acpi_release_global_lock(glk); 393 acpi_release_global_lock(glk);
361unlock: 394unlock:
@@ -383,7 +416,7 @@ static int acpi_ec_burst_disable(struct acpi_ec *ec)
383 acpi_ec_transaction(ec, &t) : 0; 416 acpi_ec_transaction(ec, &t) : 0;
384} 417}
385 418
386static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data) 419static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data)
387{ 420{
388 int result; 421 int result;
389 u8 d; 422 u8 d;
@@ -419,10 +452,9 @@ int ec_read(u8 addr, u8 *val)
419 if (!err) { 452 if (!err) {
420 *val = temp_data; 453 *val = temp_data;
421 return 0; 454 return 0;
422 } else 455 }
423 return err; 456 return err;
424} 457}
425
426EXPORT_SYMBOL(ec_read); 458EXPORT_SYMBOL(ec_read);
427 459
428int ec_write(u8 addr, u8 val) 460int ec_write(u8 addr, u8 val)
@@ -436,22 +468,21 @@ int ec_write(u8 addr, u8 val)
436 468
437 return err; 469 return err;
438} 470}
439
440EXPORT_SYMBOL(ec_write); 471EXPORT_SYMBOL(ec_write);
441 472
442int ec_transaction(u8 command, 473int ec_transaction(u8 command,
443 const u8 * wdata, unsigned wdata_len, 474 const u8 *wdata, unsigned wdata_len,
444 u8 * rdata, unsigned rdata_len) 475 u8 *rdata, unsigned rdata_len)
445{ 476{
446 struct transaction t = {.command = command, 477 struct transaction t = {.command = command,
447 .wdata = wdata, .rdata = rdata, 478 .wdata = wdata, .rdata = rdata,
448 .wlen = wdata_len, .rlen = rdata_len}; 479 .wlen = wdata_len, .rlen = rdata_len};
480
449 if (!first_ec) 481 if (!first_ec)
450 return -ENODEV; 482 return -ENODEV;
451 483
452 return acpi_ec_transaction(first_ec, &t); 484 return acpi_ec_transaction(first_ec, &t);
453} 485}
454
455EXPORT_SYMBOL(ec_transaction); 486EXPORT_SYMBOL(ec_transaction);
456 487
457/* Get the handle to the EC device */ 488/* Get the handle to the EC device */
@@ -461,7 +492,6 @@ acpi_handle ec_get_handle(void)
461 return NULL; 492 return NULL;
462 return first_ec->handle; 493 return first_ec->handle;
463} 494}
464
465EXPORT_SYMBOL(ec_get_handle); 495EXPORT_SYMBOL(ec_get_handle);
466 496
467/* 497/*
@@ -525,13 +555,14 @@ void acpi_ec_unblock_transactions_early(void)
525 clear_bit(EC_FLAGS_BLOCKED, &first_ec->flags); 555 clear_bit(EC_FLAGS_BLOCKED, &first_ec->flags);
526} 556}
527 557
528static int acpi_ec_query_unlocked(struct acpi_ec *ec, u8 * data) 558static int acpi_ec_query_unlocked(struct acpi_ec *ec, u8 *data)
529{ 559{
530 int result; 560 int result;
531 u8 d; 561 u8 d;
532 struct transaction t = {.command = ACPI_EC_COMMAND_QUERY, 562 struct transaction t = {.command = ACPI_EC_COMMAND_QUERY,
533 .wdata = NULL, .rdata = &d, 563 .wdata = NULL, .rdata = &d,
534 .wlen = 0, .rlen = 1}; 564 .wlen = 0, .rlen = 1};
565
535 if (!ec || !data) 566 if (!ec || !data)
536 return -EINVAL; 567 return -EINVAL;
537 /* 568 /*
@@ -557,6 +588,7 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
557{ 588{
558 struct acpi_ec_query_handler *handler = 589 struct acpi_ec_query_handler *handler =
559 kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL); 590 kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
591
560 if (!handler) 592 if (!handler)
561 return -ENOMEM; 593 return -ENOMEM;
562 594
@@ -569,12 +601,12 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
569 mutex_unlock(&ec->mutex); 601 mutex_unlock(&ec->mutex);
570 return 0; 602 return 0;
571} 603}
572
573EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler); 604EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
574 605
575void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) 606void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
576{ 607{
577 struct acpi_ec_query_handler *handler, *tmp; 608 struct acpi_ec_query_handler *handler, *tmp;
609
578 mutex_lock(&ec->mutex); 610 mutex_lock(&ec->mutex);
579 list_for_each_entry_safe(handler, tmp, &ec->list, node) { 611 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
580 if (query_bit == handler->query_bit) { 612 if (query_bit == handler->query_bit) {
@@ -584,20 +616,20 @@ void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
584 } 616 }
585 mutex_unlock(&ec->mutex); 617 mutex_unlock(&ec->mutex);
586} 618}
587
588EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler); 619EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
589 620
590static void acpi_ec_run(void *cxt) 621static void acpi_ec_run(void *cxt)
591{ 622{
592 struct acpi_ec_query_handler *handler = cxt; 623 struct acpi_ec_query_handler *handler = cxt;
624
593 if (!handler) 625 if (!handler)
594 return; 626 return;
595 pr_debug("start query execution\n"); 627 pr_debug("##### Query(0x%02x) started #####\n", handler->query_bit);
596 if (handler->func) 628 if (handler->func)
597 handler->func(handler->data); 629 handler->func(handler->data);
598 else if (handler->handle) 630 else if (handler->handle)
599 acpi_evaluate_object(handler->handle, NULL, NULL, NULL); 631 acpi_evaluate_object(handler->handle, NULL, NULL, NULL);
600 pr_debug("stop query execution\n"); 632 pr_debug("##### Query(0x%02x) stopped #####\n", handler->query_bit);
601 kfree(handler); 633 kfree(handler);
602} 634}
603 635
@@ -620,8 +652,8 @@ static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data)
620 if (!copy) 652 if (!copy)
621 return -ENOMEM; 653 return -ENOMEM;
622 memcpy(copy, handler, sizeof(*copy)); 654 memcpy(copy, handler, sizeof(*copy));
623 pr_debug("push query execution (0x%2x) on queue\n", 655 pr_debug("##### Query(0x%02x) scheduled #####\n",
624 value); 656 handler->query_bit);
625 return acpi_os_execute((copy->func) ? 657 return acpi_os_execute((copy->func) ?
626 OSL_NOTIFY_HANDLER : OSL_GPE_HANDLER, 658 OSL_NOTIFY_HANDLER : OSL_GPE_HANDLER,
627 acpi_ec_run, copy); 659 acpi_ec_run, copy);
@@ -633,6 +665,7 @@ static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data)
633static void acpi_ec_gpe_query(void *ec_cxt) 665static void acpi_ec_gpe_query(void *ec_cxt)
634{ 666{
635 struct acpi_ec *ec = ec_cxt; 667 struct acpi_ec *ec = ec_cxt;
668
636 if (!ec) 669 if (!ec)
637 return; 670 return;
638 mutex_lock(&ec->mutex); 671 mutex_lock(&ec->mutex);
@@ -644,7 +677,7 @@ static int ec_check_sci(struct acpi_ec *ec, u8 state)
644{ 677{
645 if (state & ACPI_EC_FLAG_SCI) { 678 if (state & ACPI_EC_FLAG_SCI) {
646 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { 679 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
647 pr_debug("push gpe query to the queue\n"); 680 pr_debug("***** Event started *****\n");
648 return acpi_os_execute(OSL_NOTIFY_HANDLER, 681 return acpi_os_execute(OSL_NOTIFY_HANDLER,
649 acpi_ec_gpe_query, ec); 682 acpi_ec_gpe_query, ec);
650 } 683 }
@@ -667,8 +700,8 @@ static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
667} 700}
668 701
669/* -------------------------------------------------------------------------- 702/* --------------------------------------------------------------------------
670 Address Space Management 703 * Address Space Management
671 -------------------------------------------------------------------------- */ 704 * -------------------------------------------------------------------------- */
672 705
673static acpi_status 706static acpi_status
674acpi_ec_space_handler(u32 function, acpi_physical_address address, 707acpi_ec_space_handler(u32 function, acpi_physical_address address,
@@ -699,27 +732,26 @@ acpi_ec_space_handler(u32 function, acpi_physical_address address,
699 switch (result) { 732 switch (result) {
700 case -EINVAL: 733 case -EINVAL:
701 return AE_BAD_PARAMETER; 734 return AE_BAD_PARAMETER;
702 break;
703 case -ENODEV: 735 case -ENODEV:
704 return AE_NOT_FOUND; 736 return AE_NOT_FOUND;
705 break;
706 case -ETIME: 737 case -ETIME:
707 return AE_TIME; 738 return AE_TIME;
708 break;
709 default: 739 default:
710 return AE_OK; 740 return AE_OK;
711 } 741 }
712} 742}
713 743
714/* -------------------------------------------------------------------------- 744/* --------------------------------------------------------------------------
715 Driver Interface 745 * Driver Interface
716 -------------------------------------------------------------------------- */ 746 * -------------------------------------------------------------------------- */
747
717static acpi_status 748static acpi_status
718ec_parse_io_ports(struct acpi_resource *resource, void *context); 749ec_parse_io_ports(struct acpi_resource *resource, void *context);
719 750
720static struct acpi_ec *make_acpi_ec(void) 751static struct acpi_ec *make_acpi_ec(void)
721{ 752{
722 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); 753 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
754
723 if (!ec) 755 if (!ec)
724 return NULL; 756 return NULL;
725 ec->flags = 1 << EC_FLAGS_QUERY_PENDING; 757 ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
@@ -742,9 +774,8 @@ acpi_ec_register_query_methods(acpi_handle handle, u32 level,
742 774
743 status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer); 775 status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
744 776
745 if (ACPI_SUCCESS(status) && sscanf(node_name, "_Q%x", &value) == 1) { 777 if (ACPI_SUCCESS(status) && sscanf(node_name, "_Q%x", &value) == 1)
746 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL); 778 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
747 }
748 return AE_OK; 779 return AE_OK;
749} 780}
750 781
@@ -753,7 +784,6 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
753{ 784{
754 acpi_status status; 785 acpi_status status;
755 unsigned long long tmp = 0; 786 unsigned long long tmp = 0;
756
757 struct acpi_ec *ec = context; 787 struct acpi_ec *ec = context;
758 788
759 /* clear addr values, ec_parse_io_ports depend on it */ 789 /* clear addr values, ec_parse_io_ports depend on it */
@@ -781,6 +811,7 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
781static int ec_install_handlers(struct acpi_ec *ec) 811static int ec_install_handlers(struct acpi_ec *ec)
782{ 812{
783 acpi_status status; 813 acpi_status status;
814
784 if (test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags)) 815 if (test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags))
785 return 0; 816 return 0;
786 status = acpi_install_gpe_handler(NULL, ec->gpe, 817 status = acpi_install_gpe_handler(NULL, ec->gpe,
@@ -1078,7 +1109,8 @@ int __init acpi_ec_ecdt_probe(void)
1078 boot_ec->data_addr = ecdt_ptr->data.address; 1109 boot_ec->data_addr = ecdt_ptr->data.address;
1079 boot_ec->gpe = ecdt_ptr->gpe; 1110 boot_ec->gpe = ecdt_ptr->gpe;
1080 boot_ec->handle = ACPI_ROOT_OBJECT; 1111 boot_ec->handle = ACPI_ROOT_OBJECT;
1081 acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle); 1112 acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id,
1113 &boot_ec->handle);
1082 /* Don't trust ECDT, which comes from ASUSTek */ 1114 /* Don't trust ECDT, which comes from ASUSTek */
1083 if (!EC_FLAGS_VALIDATE_ECDT) 1115 if (!EC_FLAGS_VALIDATE_ECDT)
1084 goto install; 1116 goto install;
@@ -1162,6 +1194,5 @@ static void __exit acpi_ec_exit(void)
1162{ 1194{
1163 1195
1164 acpi_bus_unregister_driver(&acpi_ec_driver); 1196 acpi_bus_unregister_driver(&acpi_ec_driver);
1165 return;
1166} 1197}
1167#endif /* 0 */ 1198#endif /* 0 */