Lines Matching +full:wakeup +full:- +full:event +full:- +full:action

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ec.c - ACPI Embedded Controller Driver (v3)
5 * Copyright (C) 2001-2015 Intel Corporation
43 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
53 * host should re-check SCI_EVT after the first time the SCI_EVT
56 * at any later time could indicate another event. Normally such
57 * kind of EC firmware has implemented an event queue and will
58 * return 0x00 to indicate "no outstanding event".
61 * event value in the data register (EC_DATA), the target can safely
63 * event is being handled by the host. The host then should check
64 * SCI_EVT right after reading the event response from the data
66 * EVENT: After seeing the event response read from the data register
97 EC_FLAGS_EVENT_HANDLER_INSTALLED, /* Event handler installed */
138 MODULE_PARM_DESC(ec_freeze_events, "Disabling event handling during suspend/resume");
142 MODULE_PARM_DESC(ec_no_wakeup, "Do not wake up from suspend-to-idle");
189 /* --------------------------------------------------------------------------
191 * -------------------------------------------------------------------------- */
231 ec_dbg_raw("%lu: " fmt, ec->reference_count, ## __VA_ARGS__)
233 /* --------------------------------------------------------------------------
235 * -------------------------------------------------------------------------- */
239 return test_bit(EC_FLAGS_STARTED, &ec->flags) && in acpi_ec_started()
240 !test_bit(EC_FLAGS_STOPPED, &ec->flags); in acpi_ec_started()
247 * (boot/resume), OSPMs shouldn't enable the event handling, only in acpi_ec_event_enabled()
250 if (!test_bit(EC_FLAGS_QUERY_ENABLED, &ec->flags)) in acpi_ec_event_enabled()
253 * However, disabling the event handling is experimental for late in acpi_ec_event_enabled()
256 * 1. true: The EC event handling is disabled before entering in acpi_ec_event_enabled()
258 * 2. false: The EC event handling is automatically disabled as in acpi_ec_event_enabled()
264 return test_bit(EC_FLAGS_STARTED, &ec->flags); in acpi_ec_event_enabled()
269 return ec->reference_count == 1; in acpi_ec_flushed()
272 /* --------------------------------------------------------------------------
274 * -------------------------------------------------------------------------- */
278 u8 x = inb(ec->command_addr); in acpi_ec_read_status()
293 u8 x = inb(ec->data_addr); in acpi_ec_read_data()
295 ec->timestamp = jiffies; in acpi_ec_read_data()
303 outb(command, ec->command_addr); in acpi_ec_write_cmd()
304 ec->timestamp = jiffies; in acpi_ec_write_cmd()
310 outb(data, ec->data_addr); in acpi_ec_write_data()
311 ec->timestamp = jiffies; in acpi_ec_write_data()
335 /* --------------------------------------------------------------------------
337 * -------------------------------------------------------------------------- */
343 (void)acpi_get_gpe_status(NULL, ec->gpe, &gpe_status); in acpi_ec_is_gpe_raised()
350 acpi_enable_gpe(NULL, ec->gpe); in acpi_ec_enable_gpe()
352 BUG_ON(ec->reference_count < 1); in acpi_ec_enable_gpe()
353 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE); in acpi_ec_enable_gpe()
358 * software need to manually trigger a pseudo GPE event on in acpi_ec_enable_gpe()
369 acpi_disable_gpe(NULL, ec->gpe); in acpi_ec_disable_gpe()
371 BUG_ON(ec->reference_count < 1); in acpi_ec_disable_gpe()
372 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE); in acpi_ec_disable_gpe()
390 acpi_clear_gpe(NULL, ec->gpe); in acpi_ec_clear_gpe()
393 /* --------------------------------------------------------------------------
395 * -------------------------------------------------------------------------- */
399 ec->reference_count++; in acpi_ec_submit_request()
400 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags) && in acpi_ec_submit_request()
401 ec->gpe >= 0 && ec->reference_count == 1) in acpi_ec_submit_request()
409 ec->reference_count--; in acpi_ec_complete_request()
410 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags) && in acpi_ec_complete_request()
411 ec->gpe >= 0 && ec->reference_count == 0) in acpi_ec_complete_request()
415 wake_up(&ec->wait); in acpi_ec_complete_request()
420 if (!test_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags)) { in acpi_ec_mask_events()
421 if (ec->gpe >= 0) in acpi_ec_mask_events()
424 disable_irq_nosync(ec->irq); in acpi_ec_mask_events()
427 set_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags); in acpi_ec_mask_events()
433 if (test_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags)) { in acpi_ec_unmask_events()
434 clear_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags); in acpi_ec_unmask_events()
435 if (ec->gpe >= 0) in acpi_ec_unmask_events()
438 enable_irq(ec->irq); in acpi_ec_unmask_events()
445 * acpi_ec_submit_flushable_request() - Increase the reference count unless
450 * This function must be used before taking a new action that should hold
451 * the reference count. If this function returns false, then the action
468 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { in acpi_ec_submit_query()
471 ec->nr_pending_queries++; in acpi_ec_submit_query()
472 ec->events_in_progress++; in acpi_ec_submit_query()
473 queue_work(ec_wq, &ec->work); in acpi_ec_submit_query()
479 if (test_and_clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) in acpi_ec_complete_query()
487 if (!test_and_set_bit(EC_FLAGS_QUERY_ENABLED, &ec->flags)) in __acpi_ec_enable_event()
488 ec_log_drv("event unblocked"); in __acpi_ec_enable_event()
490 * Unconditionally invoke this once after enabling the event in __acpi_ec_enable_event()
498 if (test_and_clear_bit(EC_FLAGS_QUERY_ENABLED, &ec->flags)) in __acpi_ec_disable_event()
499 ec_log_drv("event blocked"); in __acpi_ec_disable_event()
526 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_enable_event()
529 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_enable_event()
539 flush_workqueue(ec_wq); /* flush ec->work */ in __acpi_ec_flush_work()
547 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_disable_event()
549 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_disable_event()
573 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_guard_event()
575 * If firmware SCI_EVT clearing timing is "event", we actually in acpi_ec_guard_event()
577 * evaluating _Qxx, so we need to re-check SCI_EVT after waiting an in acpi_ec_guard_event()
590 !test_bit(EC_FLAGS_QUERY_PENDING, &ec->flags) || in acpi_ec_guard_event()
591 (ec->curr && ec->curr->command == ACPI_EC_COMMAND_QUERY)) in acpi_ec_guard_event()
593 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_guard_event()
602 spin_lock_irqsave(&ec->lock, flags); in ec_transaction_polled()
603 if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_POLL)) in ec_transaction_polled()
605 spin_unlock_irqrestore(&ec->lock, flags); in ec_transaction_polled()
614 spin_lock_irqsave(&ec->lock, flags); in ec_transaction_completed()
615 if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_COMPLETE)) in ec_transaction_completed()
617 spin_unlock_irqrestore(&ec->lock, flags); in ec_transaction_completed()
623 ec->curr->flags |= flag; in ec_transaction_transition()
624 if (ec->curr->command == ACPI_EC_COMMAND_QUERY) { in ec_transaction_transition()
633 set_bit(EC_FLAGS_QUERY_GUARDING, &ec->flags); in ec_transaction_transition()
641 bool wakeup = false; in advance_transaction() local
647 * ensure a hardware STS 0->1 change after this clearing can always in advance_transaction()
650 if (ec->gpe >= 0) in advance_transaction()
654 t = ec->curr; in advance_transaction()
659 if (!t || !(t->flags & ACPI_EC_COMMAND_POLL)) { in advance_transaction()
661 (!ec->nr_pending_queries || in advance_transaction()
662 test_bit(EC_FLAGS_QUERY_GUARDING, &ec->flags))) { in advance_transaction()
663 clear_bit(EC_FLAGS_QUERY_GUARDING, &ec->flags); in advance_transaction()
669 if (t->flags & ACPI_EC_COMMAND_POLL) { in advance_transaction()
670 if (t->wlen > t->wi) { in advance_transaction()
672 acpi_ec_write_data(ec, t->wdata[t->wi++]); in advance_transaction()
675 } else if (t->rlen > t->ri) { in advance_transaction()
677 t->rdata[t->ri++] = acpi_ec_read_data(ec); in advance_transaction()
678 if (t->rlen == t->ri) { in advance_transaction()
680 if (t->command == ACPI_EC_COMMAND_QUERY) in advance_transaction()
683 wakeup = true; in advance_transaction()
687 } else if (t->wlen == t->wi && in advance_transaction()
690 wakeup = true; in advance_transaction()
694 acpi_ec_write_cmd(ec, t->command); in advance_transaction()
705 if (t->irq_count < ec_storm_threshold) in advance_transaction()
706 ++t->irq_count; in advance_transaction()
708 if (t->irq_count == ec_storm_threshold) in advance_transaction()
715 if (wakeup && in_interrupt()) in advance_transaction()
716 wake_up(&ec->wait); in advance_transaction()
721 ec->curr->irq_count = ec->curr->wi = ec->curr->ri = 0; in start_transaction()
722 ec->curr->flags = 0; in start_transaction()
727 unsigned long guard = usecs_to_jiffies(ec->polling_guard); in ec_guard()
728 unsigned long timeout = ec->timestamp + guard; in ec_guard()
732 if (ec->busy_polling) { in ec_guard()
744 * for event clearing mode "event" before the in ec_guard()
751 if (wait_event_timeout(ec->wait, in ec_guard()
757 return -ETIME; in ec_guard()
765 while (repeat--) { in ec_poll()
771 spin_lock_irqsave(&ec->lock, flags); in ec_poll()
773 spin_unlock_irqrestore(&ec->lock, flags); in ec_poll()
776 spin_lock_irqsave(&ec->lock, flags); in ec_poll()
778 spin_unlock_irqrestore(&ec->lock, flags); in ec_poll()
780 return -ETIME; in ec_poll()
790 spin_lock_irqsave(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
793 ret = -EINVAL; in acpi_ec_transaction_unlocked()
798 ec->curr = t; in acpi_ec_transaction_unlocked()
799 ec_dbg_req("Command(%s) started", acpi_ec_cmd_string(t->command)); in acpi_ec_transaction_unlocked()
801 spin_unlock_irqrestore(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
805 spin_lock_irqsave(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
806 if (t->irq_count == ec_storm_threshold) in acpi_ec_transaction_unlocked()
808 ec_dbg_req("Command(%s) stopped", acpi_ec_cmd_string(t->command)); in acpi_ec_transaction_unlocked()
809 ec->curr = NULL; in acpi_ec_transaction_unlocked()
814 spin_unlock_irqrestore(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
823 if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata)) in acpi_ec_transaction()
824 return -EINVAL; in acpi_ec_transaction()
825 if (t->rdata) in acpi_ec_transaction()
826 memset(t->rdata, 0, t->rlen); in acpi_ec_transaction()
828 mutex_lock(&ec->mutex); in acpi_ec_transaction()
829 if (ec->global_lock) { in acpi_ec_transaction()
832 status = -ENODEV; in acpi_ec_transaction()
839 if (ec->global_lock) in acpi_ec_transaction()
842 mutex_unlock(&ec->mutex); in acpi_ec_transaction()
895 return -ENODEV; in ec_read()
912 return -ENODEV; in ec_write()
929 return -ENODEV; in ec_transaction()
940 return first_ec->handle; in ec_get_handle()
948 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_start()
949 if (!test_and_set_bit(EC_FLAGS_STARTED, &ec->flags)) { in acpi_ec_start()
951 /* Enable GPE for event processing (SCI_EVT=1) */ in acpi_ec_start()
958 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_start()
966 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_stopped()
968 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_stopped()
976 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_stop()
979 set_bit(EC_FLAGS_STOPPED, &ec->flags); in acpi_ec_stop()
980 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_stop()
981 wait_event(ec->wait, acpi_ec_stopped(ec)); in acpi_ec_stop()
982 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_stop()
983 /* Disable GPE for event processing (SCI_EVT=1) */ in acpi_ec_stop()
989 clear_bit(EC_FLAGS_STARTED, &ec->flags); in acpi_ec_stop()
990 clear_bit(EC_FLAGS_STOPPED, &ec->flags); in acpi_ec_stop()
993 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_stop()
1000 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_enter_noirq()
1001 ec->busy_polling = true; in acpi_ec_enter_noirq()
1002 ec->polling_guard = 0; in acpi_ec_enter_noirq()
1004 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_enter_noirq()
1011 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_leave_noirq()
1012 ec->busy_polling = ec_busy_polling; in acpi_ec_leave_noirq()
1013 ec->polling_guard = ec_polling_guard; in acpi_ec_leave_noirq()
1015 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_leave_noirq()
1025 mutex_lock(&ec->mutex); in acpi_ec_block_transactions()
1028 mutex_unlock(&ec->mutex); in acpi_ec_block_transactions()
1035 * atomic context during wakeup, so we don't need to acquire the mutex). in acpi_ec_unblock_transactions()
1041 /* --------------------------------------------------------------------------
1042 Event Management
1043 -------------------------------------------------------------------------- */
1049 mutex_lock(&ec->mutex); in acpi_ec_get_query_handler_by_value()
1050 list_for_each_entry(handler, &ec->list, node) { in acpi_ec_get_query_handler_by_value()
1051 if (value == handler->query_bit) { in acpi_ec_get_query_handler_by_value()
1052 kref_get(&handler->kref); in acpi_ec_get_query_handler_by_value()
1053 mutex_unlock(&ec->mutex); in acpi_ec_get_query_handler_by_value()
1057 mutex_unlock(&ec->mutex); in acpi_ec_get_query_handler_by_value()
1071 kref_put(&handler->kref, acpi_ec_query_handler_release); in acpi_ec_put_query_handler()
1082 return -ENOMEM; in acpi_ec_add_query_handler()
1084 handler->query_bit = query_bit; in acpi_ec_add_query_handler()
1085 handler->handle = handle; in acpi_ec_add_query_handler()
1086 handler->func = func; in acpi_ec_add_query_handler()
1087 handler->data = data; in acpi_ec_add_query_handler()
1088 mutex_lock(&ec->mutex); in acpi_ec_add_query_handler()
1089 kref_init(&handler->kref); in acpi_ec_add_query_handler()
1090 list_add(&handler->node, &ec->list); in acpi_ec_add_query_handler()
1091 mutex_unlock(&ec->mutex); in acpi_ec_add_query_handler()
1102 mutex_lock(&ec->mutex); in acpi_ec_remove_query_handlers()
1103 list_for_each_entry_safe(handler, tmp, &ec->list, node) { in acpi_ec_remove_query_handlers()
1104 if (remove_all || query_bit == handler->query_bit) { in acpi_ec_remove_query_handlers()
1105 list_del_init(&handler->node); in acpi_ec_remove_query_handlers()
1106 list_add(&handler->node, &free_list); in acpi_ec_remove_query_handlers()
1109 mutex_unlock(&ec->mutex); in acpi_ec_remove_query_handlers()
1129 INIT_WORK(&q->work, acpi_ec_event_processor); in acpi_ec_create_query()
1130 t = &q->transaction; in acpi_ec_create_query()
1131 t->command = ACPI_EC_COMMAND_QUERY; in acpi_ec_create_query()
1132 t->rdata = pval; in acpi_ec_create_query()
1133 t->rlen = 1; in acpi_ec_create_query()
1134 q->ec = ec; in acpi_ec_create_query()
1141 if (q->handler) in acpi_ec_delete_query()
1142 acpi_ec_put_query_handler(q->handler); in acpi_ec_delete_query()
1150 struct acpi_ec_query_handler *handler = q->handler; in acpi_ec_event_processor()
1151 struct acpi_ec *ec = q->ec; in acpi_ec_event_processor()
1153 ec_dbg_evt("Query(0x%02x) started", handler->query_bit); in acpi_ec_event_processor()
1155 if (handler->func) in acpi_ec_event_processor()
1156 handler->func(handler->data); in acpi_ec_event_processor()
1157 else if (handler->handle) in acpi_ec_event_processor()
1158 acpi_evaluate_object(handler->handle, NULL, NULL, NULL); in acpi_ec_event_processor()
1160 ec_dbg_evt("Query(0x%02x) stopped", handler->query_bit); in acpi_ec_event_processor()
1162 spin_lock_irq(&ec->lock); in acpi_ec_event_processor()
1163 ec->queries_in_progress--; in acpi_ec_event_processor()
1164 spin_unlock_irq(&ec->lock); in acpi_ec_event_processor()
1177 return -ENOMEM; in acpi_ec_query()
1184 result = acpi_ec_transaction(ec, &q->transaction); in acpi_ec_query()
1186 result = -ENODATA; in acpi_ec_query()
1190 q->handler = acpi_ec_get_query_handler_by_value(ec, value); in acpi_ec_query()
1191 if (!q->handler) { in acpi_ec_query()
1192 result = -ENODATA; in acpi_ec_query()
1205 spin_lock_irq(&ec->lock); in acpi_ec_query()
1207 ec->queries_in_progress++; in acpi_ec_query()
1208 queue_work(ec_query_wq, &q->work); in acpi_ec_query()
1210 spin_unlock_irq(&ec->lock); in acpi_ec_query()
1226 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_check_event()
1231 if (!ec->curr) in acpi_ec_check_event()
1233 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_check_event()
1243 ec_dbg_evt("Event started"); in acpi_ec_event_handler()
1245 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_event_handler()
1246 while (ec->nr_pending_queries) { in acpi_ec_event_handler()
1247 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_event_handler()
1249 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_event_handler()
1250 ec->nr_pending_queries--; in acpi_ec_event_handler()
1257 if (!ec->nr_pending_queries) { in acpi_ec_event_handler()
1263 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_event_handler()
1265 ec_dbg_evt("Event stopped"); in acpi_ec_event_handler()
1269 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_event_handler()
1270 ec->events_in_progress--; in acpi_ec_event_handler()
1271 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_event_handler()
1278 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_handle_interrupt()
1280 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_handle_interrupt()
1296 /* --------------------------------------------------------------------------
1298 * -------------------------------------------------------------------------- */
1315 if (ec->busy_polling || bits > 8) in acpi_ec_space_handler()
1323 if (ec->busy_polling || bits > 8) in acpi_ec_space_handler()
1327 case -EINVAL: in acpi_ec_space_handler()
1329 case -ENODEV: in acpi_ec_space_handler()
1331 case -ETIME: in acpi_ec_space_handler()
1338 /* --------------------------------------------------------------------------
1340 * -------------------------------------------------------------------------- */
1360 mutex_init(&ec->mutex); in acpi_ec_alloc()
1361 init_waitqueue_head(&ec->wait); in acpi_ec_alloc()
1362 INIT_LIST_HEAD(&ec->list); in acpi_ec_alloc()
1363 spin_lock_init(&ec->lock); in acpi_ec_alloc()
1364 INIT_WORK(&ec->work, acpi_ec_event_handler); in acpi_ec_alloc()
1365 ec->timestamp = jiffies; in acpi_ec_alloc()
1366 ec->busy_polling = true; in acpi_ec_alloc()
1367 ec->polling_guard = 0; in acpi_ec_alloc()
1368 ec->gpe = -1; in acpi_ec_alloc()
1369 ec->irq = -1; in acpi_ec_alloc()
1398 ec->command_addr = ec->data_addr = 0; in ec_parse_device()
1404 if (ec->data_addr == 0 || ec->command_addr == 0) in ec_parse_device()
1411 ec->gpe = tmp; in ec_parse_device()
1413 * Errors are non-fatal, allowing for ACPI Reduced Hardware in ec_parse_device()
1420 ec->global_lock = tmp; in ec_parse_device()
1421 ec->handle = handle; in ec_parse_device()
1429 status = acpi_install_gpe_raw_handler(NULL, ec->gpe, in install_gpe_event_handler()
1435 if (test_bit(EC_FLAGS_STARTED, &ec->flags) && ec->reference_count >= 1) in install_gpe_event_handler()
1443 return request_irq(ec->irq, acpi_ec_irq_handler, IRQF_SHARED, in install_gpio_irq_event_handler()
1448 * ec_install_handlers - Install service callbacks and register query methods.
1454 * namespace and register them, and install an event (either GPE or GPIO IRQ)
1458 * -ENODEV if the address space handler cannot be installed, which means
1460 * -EPROBE_DEFER if GPIO IRQ acquisition needs to be deferred,
1469 if (!test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) { in ec_install_handlers()
1471 status = acpi_install_address_space_handler(ec->handle, in ec_install_handlers()
1477 return -ENODEV; in ec_install_handlers()
1479 set_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags); in ec_install_handlers()
1485 if (ec->gpe < 0) { in ec_install_handlers()
1492 if (irq == -EPROBE_DEFER) in ec_install_handlers()
1493 return -EPROBE_DEFER; in ec_install_handlers()
1495 ec->irq = irq; in ec_install_handlers()
1498 if (!test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) { in ec_install_handlers()
1500 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1, in ec_install_handlers()
1503 set_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags); in ec_install_handlers()
1505 if (!test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) { in ec_install_handlers()
1508 if (ec->gpe >= 0) in ec_install_handlers()
1510 else if (ec->irq >= 0) in ec_install_handlers()
1514 set_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags); in ec_install_handlers()
1518 * Failures to install an event handler are not fatal, because in ec_install_handlers()
1530 if (test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) { in ec_remove_handlers()
1531 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, in ec_remove_handlers()
1534 clear_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags); in ec_remove_handlers()
1550 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) { in ec_remove_handlers()
1551 if (ec->gpe >= 0 && in ec_remove_handlers()
1552 ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, in ec_remove_handlers()
1556 if (ec->irq >= 0) in ec_remove_handlers()
1557 free_irq(ec->irq, ec); in ec_remove_handlers()
1559 clear_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags); in ec_remove_handlers()
1561 if (test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) { in ec_remove_handlers()
1563 clear_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags); in ec_remove_handlers()
1579 pr_info("EC_CMD/EC_SC=0x%lx, EC_DATA=0x%lx\n", ec->command_addr, in acpi_ec_setup()
1580 ec->data_addr); in acpi_ec_setup()
1582 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) { in acpi_ec_setup()
1583 if (ec->gpe >= 0) in acpi_ec_setup()
1584 pr_info("GPE=0x%x\n", ec->gpe); in acpi_ec_setup()
1586 pr_info("IRQ=%d\n", ec->irq); in acpi_ec_setup()
1600 if (boot_ec && (boot_ec->handle == device->handle || in acpi_ec_add()
1609 return -ENOMEM; in acpi_ec_add()
1611 status = ec_parse_device(device->handle, 0, ec, NULL); in acpi_ec_add()
1613 ret = -EINVAL; in acpi_ec_add()
1617 if (boot_ec && ec->command_addr == boot_ec->command_addr && in acpi_ec_add()
1618 ec->data_addr == boot_ec->data_addr && in acpi_ec_add()
1624 * boot_ec->gpe to ec->gpe. in acpi_ec_add()
1626 boot_ec->handle = ec->handle; in acpi_ec_add()
1627 acpi_handle_debug(ec->handle, "duplicated.\n"); in acpi_ec_add()
1638 acpi_handle_info(boot_ec->handle, in acpi_ec_add()
1642 acpi_handle_info(ec->handle, in acpi_ec_add()
1645 device->driver_data = ec; in acpi_ec_add()
1647 ret = !!request_region(ec->data_addr, 1, "EC data"); in acpi_ec_add()
1648 WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr); in acpi_ec_add()
1649 ret = !!request_region(ec->command_addr, 1, "EC cmd"); in acpi_ec_add()
1650 WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr); in acpi_ec_add()
1653 acpi_walk_dep_device_list(ec->handle); in acpi_ec_add()
1655 acpi_handle_debug(ec->handle, "enumerated.\n"); in acpi_ec_add()
1670 return -EINVAL; in acpi_ec_remove()
1673 release_region(ec->data_addr, 1); in acpi_ec_remove()
1674 release_region(ec->command_addr, 1); in acpi_ec_remove()
1675 device->driver_data = NULL; in acpi_ec_remove()
1688 if (resource->type != ACPI_RESOURCE_TYPE_IO) in ec_parse_io_ports()
1696 if (ec->data_addr == 0) in ec_parse_io_ports()
1697 ec->data_addr = resource->data.io.minimum; in ec_parse_io_ports()
1698 else if (ec->command_addr == 0) in ec_parse_io_ports()
1699 ec->command_addr = resource->data.io.minimum; in ec_parse_io_ports()
1713 * This function is not Windows-compatible as Windows never enumerates the
1741 if (ACPI_FAILURE(status) || !ec->handle) { in acpi_ec_dsdt_probe()
1747 * When the DSDT EC is available, always re-configure boot EC to in acpi_ec_dsdt_probe()
1761 acpi_handle_info(ec->handle, in acpi_ec_dsdt_probe()
1766 * acpi_ec_ecdt_start - Finalize the boot ECDT EC initialization.
1785 if (!boot_ec || boot_ec->handle != ACPI_ROOT_OBJECT) in acpi_ec_ecdt_start()
1794 status = acpi_get_handle(NULL, ecdt_ptr->id, &handle); in acpi_ec_ecdt_start()
1796 boot_ec->handle = handle; in acpi_ec_ecdt_start()
1832 * MSI MS-171F
1856 ec_correct_ecdt, "MSI MS-171F", {
1857 DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star"),
1858 DMI_MATCH(DMI_PRODUCT_NAME, "MS-171F"),}, NULL},
1861 ec_honor_dsdt_gpe, "HP Pavilion Gaming Laptop 15-cx0xxx", {
1863 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion Gaming Laptop 15-cx0xxx"),}, NULL},
1884 if (!ecdt_ptr->control.address || !ecdt_ptr->data.address) { in acpi_ec_ecdt_probe()
1897 ec->command_addr = ecdt_ptr->data.address; in acpi_ec_ecdt_probe()
1898 ec->data_addr = ecdt_ptr->control.address; in acpi_ec_ecdt_probe()
1900 ec->command_addr = ecdt_ptr->control.address; in acpi_ec_ecdt_probe()
1901 ec->data_addr = ecdt_ptr->data.address; in acpi_ec_ecdt_probe()
1909 ec->gpe = ecdt_ptr->gpe; in acpi_ec_ecdt_probe()
1911 ec->handle = ACPI_ROOT_OBJECT; in acpi_ec_ecdt_probe()
1951 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) && in acpi_ec_suspend_noirq()
1952 ec->gpe >= 0 && ec->reference_count >= 1) in acpi_ec_suspend_noirq()
1953 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE); in acpi_ec_suspend_noirq()
1966 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) && in acpi_ec_resume_noirq()
1967 ec->gpe >= 0 && ec->reference_count >= 1) in acpi_ec_resume_noirq()
1968 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE); in acpi_ec_resume_noirq()
1985 acpi_mark_gpe_for_wake(NULL, first_ec->gpe); in acpi_ec_mark_gpe_for_wake()
1989 void acpi_ec_set_gpe_wake_mask(u8 action) in acpi_ec_set_gpe_wake_mask() argument
1992 acpi_set_gpe_wake_mask(NULL, first_ec->gpe, action); in acpi_ec_set_gpe_wake_mask()
2004 * Report wakeup if the status bit is set for any enabled GPE other in acpi_ec_dispatch_gpe()
2007 if (acpi_any_gpe_status_set(first_ec->gpe)) in acpi_ec_dispatch_gpe()
2011 * Dispatch the EC GPE in-band, but do not report wakeup in any case in acpi_ec_dispatch_gpe()
2014 ret = acpi_dispatch_gpe(NULL, first_ec->gpe); in acpi_ec_dispatch_gpe()
2024 spin_lock_irq(&first_ec->lock); in acpi_ec_dispatch_gpe()
2026 work_in_progress = first_ec->events_in_progress + in acpi_ec_dispatch_gpe()
2027 first_ec->queries_in_progress > 0; in acpi_ec_dispatch_gpe()
2029 spin_unlock_irq(&first_ec->lock); in acpi_ec_dispatch_gpe()
2046 if (!strncmp(val, "status", sizeof("status") - 1)) { in param_set_event_clearing()
2049 } else if (!strncmp(val, "query", sizeof("query") - 1)) { in param_set_event_clearing()
2052 } else if (!strncmp(val, "event", sizeof("event") - 1)) { in param_set_event_clearing()
2054 pr_info("Assuming SCI_EVT clearing on event reads\n"); in param_set_event_clearing()
2056 result = -EINVAL; in param_set_event_clearing()
2069 return sprintf(buffer, "event\n"); in param_get_event_clearing()
2113 return -ENODEV; in acpi_ec_init_workqueues()
2145 * Disable EC wakeup on following systems to prevent periodic in acpi_ec_init()
2146 * wakeup from EC GPE. in acpi_ec_init()
2150 pr_debug("Disabling EC wakeup on suspend-to-idle\n"); in acpi_ec_init()