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");
190 /* --------------------------------------------------------------------------
192 * -------------------------------------------------------------------------- */
232 ec_dbg_raw("%lu: " fmt, ec->reference_count, ## __VA_ARGS__)
234 /* --------------------------------------------------------------------------
236 * -------------------------------------------------------------------------- */
240 return test_bit(EC_FLAGS_STARTED, &ec->flags) && in acpi_ec_started()
241 !test_bit(EC_FLAGS_STOPPED, &ec->flags); in acpi_ec_started()
248 * (boot/resume), OSPMs shouldn't enable the event handling, only in acpi_ec_event_enabled()
251 if (!test_bit(EC_FLAGS_QUERY_ENABLED, &ec->flags)) in acpi_ec_event_enabled()
254 * However, disabling the event handling is experimental for late in acpi_ec_event_enabled()
257 * 1. true: The EC event handling is disabled before entering in acpi_ec_event_enabled()
259 * 2. false: The EC event handling is automatically disabled as in acpi_ec_event_enabled()
265 return test_bit(EC_FLAGS_STARTED, &ec->flags); in acpi_ec_event_enabled()
270 return ec->reference_count == 1; in acpi_ec_flushed()
273 /* --------------------------------------------------------------------------
275 * -------------------------------------------------------------------------- */
279 u8 x = inb(ec->command_addr); in acpi_ec_read_status()
294 u8 x = inb(ec->data_addr); in acpi_ec_read_data()
296 ec->timestamp = jiffies; in acpi_ec_read_data()
304 outb(command, ec->command_addr); in acpi_ec_write_cmd()
305 ec->timestamp = jiffies; in acpi_ec_write_cmd()
311 outb(data, ec->data_addr); in acpi_ec_write_data()
312 ec->timestamp = jiffies; in acpi_ec_write_data()
336 /* --------------------------------------------------------------------------
338 * -------------------------------------------------------------------------- */
344 (void)acpi_get_gpe_status(NULL, ec->gpe, &gpe_status); in acpi_ec_is_gpe_raised()
351 acpi_enable_gpe(NULL, ec->gpe); in acpi_ec_enable_gpe()
353 BUG_ON(ec->reference_count < 1); in acpi_ec_enable_gpe()
354 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE); in acpi_ec_enable_gpe()
359 * software need to manually trigger a pseudo GPE event on in acpi_ec_enable_gpe()
370 acpi_disable_gpe(NULL, ec->gpe); in acpi_ec_disable_gpe()
372 BUG_ON(ec->reference_count < 1); in acpi_ec_disable_gpe()
373 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE); in acpi_ec_disable_gpe()
391 acpi_clear_gpe(NULL, ec->gpe); in acpi_ec_clear_gpe()
394 /* --------------------------------------------------------------------------
396 * -------------------------------------------------------------------------- */
400 ec->reference_count++; in acpi_ec_submit_request()
401 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags) && in acpi_ec_submit_request()
402 ec->gpe >= 0 && ec->reference_count == 1) in acpi_ec_submit_request()
410 ec->reference_count--; in acpi_ec_complete_request()
411 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags) && in acpi_ec_complete_request()
412 ec->gpe >= 0 && ec->reference_count == 0) in acpi_ec_complete_request()
416 wake_up(&ec->wait); in acpi_ec_complete_request()
421 if (!test_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags)) { in acpi_ec_mask_events()
422 if (ec->gpe >= 0) in acpi_ec_mask_events()
425 disable_irq_nosync(ec->irq); in acpi_ec_mask_events()
428 set_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags); in acpi_ec_mask_events()
434 if (test_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags)) { in acpi_ec_unmask_events()
435 clear_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags); in acpi_ec_unmask_events()
436 if (ec->gpe >= 0) in acpi_ec_unmask_events()
439 enable_irq(ec->irq); in acpi_ec_unmask_events()
446 * acpi_ec_submit_flushable_request() - Increase the reference count unless
451 * This function must be used before taking a new action that should hold
452 * the reference count. If this function returns false, then the action
469 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { in acpi_ec_submit_query()
472 ec->nr_pending_queries++; in acpi_ec_submit_query()
473 ec->events_in_progress++; in acpi_ec_submit_query()
474 queue_work(ec_wq, &ec->work); in acpi_ec_submit_query()
480 if (test_and_clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) in acpi_ec_complete_query()
488 if (!test_and_set_bit(EC_FLAGS_QUERY_ENABLED, &ec->flags)) in __acpi_ec_enable_event()
489 ec_log_drv("event unblocked"); in __acpi_ec_enable_event()
491 * Unconditionally invoke this once after enabling the event in __acpi_ec_enable_event()
499 if (test_and_clear_bit(EC_FLAGS_QUERY_ENABLED, &ec->flags)) in __acpi_ec_disable_event()
500 ec_log_drv("event blocked"); in __acpi_ec_disable_event()
527 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_enable_event()
530 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_enable_event()
540 flush_workqueue(ec_wq); /* flush ec->work */ in __acpi_ec_flush_work()
548 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_disable_event()
550 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_disable_event()
574 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_guard_event()
576 * If firmware SCI_EVT clearing timing is "event", we actually in acpi_ec_guard_event()
578 * evaluating _Qxx, so we need to re-check SCI_EVT after waiting an in acpi_ec_guard_event()
591 !test_bit(EC_FLAGS_QUERY_PENDING, &ec->flags) || in acpi_ec_guard_event()
592 (ec->curr && ec->curr->command == ACPI_EC_COMMAND_QUERY)) in acpi_ec_guard_event()
594 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_guard_event()
603 spin_lock_irqsave(&ec->lock, flags); in ec_transaction_polled()
604 if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_POLL)) in ec_transaction_polled()
606 spin_unlock_irqrestore(&ec->lock, flags); in ec_transaction_polled()
615 spin_lock_irqsave(&ec->lock, flags); in ec_transaction_completed()
616 if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_COMPLETE)) in ec_transaction_completed()
618 spin_unlock_irqrestore(&ec->lock, flags); in ec_transaction_completed()
624 ec->curr->flags |= flag; in ec_transaction_transition()
625 if (ec->curr->command == ACPI_EC_COMMAND_QUERY) { in ec_transaction_transition()
634 set_bit(EC_FLAGS_QUERY_GUARDING, &ec->flags); in ec_transaction_transition()
642 bool wakeup = false; in advance_transaction() local
648 * ensure a hardware STS 0->1 change after this clearing can always in advance_transaction()
651 if (ec->gpe >= 0) in advance_transaction()
655 t = ec->curr; in advance_transaction()
660 if (!t || !(t->flags & ACPI_EC_COMMAND_POLL)) { in advance_transaction()
662 (!ec->nr_pending_queries || in advance_transaction()
663 test_bit(EC_FLAGS_QUERY_GUARDING, &ec->flags))) { in advance_transaction()
664 clear_bit(EC_FLAGS_QUERY_GUARDING, &ec->flags); in advance_transaction()
670 if (t->flags & ACPI_EC_COMMAND_POLL) { in advance_transaction()
671 if (t->wlen > t->wi) { in advance_transaction()
673 acpi_ec_write_data(ec, t->wdata[t->wi++]); in advance_transaction()
676 } else if (t->rlen > t->ri) { in advance_transaction()
678 t->rdata[t->ri++] = acpi_ec_read_data(ec); in advance_transaction()
679 if (t->rlen == t->ri) { in advance_transaction()
681 if (t->command == ACPI_EC_COMMAND_QUERY) in advance_transaction()
684 wakeup = true; in advance_transaction()
688 } else if (t->wlen == t->wi && in advance_transaction()
691 wakeup = true; in advance_transaction()
695 acpi_ec_write_cmd(ec, t->command); in advance_transaction()
706 if (t->irq_count < ec_storm_threshold) in advance_transaction()
707 ++t->irq_count; in advance_transaction()
709 if (t->irq_count == ec_storm_threshold) in advance_transaction()
716 if (wakeup && in_interrupt()) in advance_transaction()
717 wake_up(&ec->wait); in advance_transaction()
722 ec->curr->irq_count = ec->curr->wi = ec->curr->ri = 0; in start_transaction()
723 ec->curr->flags = 0; in start_transaction()
728 unsigned long guard = usecs_to_jiffies(ec->polling_guard); in ec_guard()
729 unsigned long timeout = ec->timestamp + guard; in ec_guard()
733 if (ec->busy_polling) { in ec_guard()
745 * for event clearing mode "event" before the in ec_guard()
752 if (wait_event_timeout(ec->wait, in ec_guard()
758 return -ETIME; in ec_guard()
766 while (repeat--) { in ec_poll()
772 spin_lock_irqsave(&ec->lock, flags); in ec_poll()
774 spin_unlock_irqrestore(&ec->lock, flags); in ec_poll()
777 spin_lock_irqsave(&ec->lock, flags); in ec_poll()
779 spin_unlock_irqrestore(&ec->lock, flags); in ec_poll()
781 return -ETIME; in ec_poll()
791 spin_lock_irqsave(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
794 ret = -EINVAL; in acpi_ec_transaction_unlocked()
799 ec->curr = t; in acpi_ec_transaction_unlocked()
800 ec_dbg_req("Command(%s) started", acpi_ec_cmd_string(t->command)); in acpi_ec_transaction_unlocked()
802 spin_unlock_irqrestore(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
806 spin_lock_irqsave(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
807 if (t->irq_count == ec_storm_threshold) in acpi_ec_transaction_unlocked()
809 ec_dbg_req("Command(%s) stopped", acpi_ec_cmd_string(t->command)); in acpi_ec_transaction_unlocked()
810 ec->curr = NULL; in acpi_ec_transaction_unlocked()
815 spin_unlock_irqrestore(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
824 if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata)) in acpi_ec_transaction()
825 return -EINVAL; in acpi_ec_transaction()
826 if (t->rdata) in acpi_ec_transaction()
827 memset(t->rdata, 0, t->rlen); in acpi_ec_transaction()
829 mutex_lock(&ec->mutex); in acpi_ec_transaction()
830 if (ec->global_lock) { in acpi_ec_transaction()
833 status = -ENODEV; in acpi_ec_transaction()
840 if (ec->global_lock) in acpi_ec_transaction()
843 mutex_unlock(&ec->mutex); in acpi_ec_transaction()
896 return -ENODEV; in ec_read()
913 return -ENODEV; in ec_write()
930 return -ENODEV; in ec_transaction()
941 return first_ec->handle; in ec_get_handle()
949 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_start()
950 if (!test_and_set_bit(EC_FLAGS_STARTED, &ec->flags)) { in acpi_ec_start()
952 /* Enable GPE for event processing (SCI_EVT=1) */ in acpi_ec_start()
959 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_start()
967 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_stopped()
969 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_stopped()
977 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_stop()
980 set_bit(EC_FLAGS_STOPPED, &ec->flags); in acpi_ec_stop()
981 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_stop()
982 wait_event(ec->wait, acpi_ec_stopped(ec)); in acpi_ec_stop()
983 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_stop()
984 /* Disable GPE for event processing (SCI_EVT=1) */ in acpi_ec_stop()
990 clear_bit(EC_FLAGS_STARTED, &ec->flags); in acpi_ec_stop()
991 clear_bit(EC_FLAGS_STOPPED, &ec->flags); in acpi_ec_stop()
994 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_stop()
1001 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_enter_noirq()
1002 ec->busy_polling = true; in acpi_ec_enter_noirq()
1003 ec->polling_guard = 0; in acpi_ec_enter_noirq()
1005 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_enter_noirq()
1012 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_leave_noirq()
1013 ec->busy_polling = ec_busy_polling; in acpi_ec_leave_noirq()
1014 ec->polling_guard = ec_polling_guard; in acpi_ec_leave_noirq()
1016 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_leave_noirq()
1026 mutex_lock(&ec->mutex); in acpi_ec_block_transactions()
1029 mutex_unlock(&ec->mutex); in acpi_ec_block_transactions()
1036 * atomic context during wakeup, so we don't need to acquire the mutex). in acpi_ec_unblock_transactions()
1042 /* --------------------------------------------------------------------------
1043 Event Management
1044 -------------------------------------------------------------------------- */
1050 mutex_lock(&ec->mutex); in acpi_ec_get_query_handler_by_value()
1051 list_for_each_entry(handler, &ec->list, node) { in acpi_ec_get_query_handler_by_value()
1052 if (value == handler->query_bit) { in acpi_ec_get_query_handler_by_value()
1053 kref_get(&handler->kref); in acpi_ec_get_query_handler_by_value()
1054 mutex_unlock(&ec->mutex); in acpi_ec_get_query_handler_by_value()
1058 mutex_unlock(&ec->mutex); in acpi_ec_get_query_handler_by_value()
1072 kref_put(&handler->kref, acpi_ec_query_handler_release); in acpi_ec_put_query_handler()
1083 return -ENOMEM; in acpi_ec_add_query_handler()
1085 handler->query_bit = query_bit; in acpi_ec_add_query_handler()
1086 handler->handle = handle; in acpi_ec_add_query_handler()
1087 handler->func = func; in acpi_ec_add_query_handler()
1088 handler->data = data; in acpi_ec_add_query_handler()
1089 mutex_lock(&ec->mutex); in acpi_ec_add_query_handler()
1090 kref_init(&handler->kref); in acpi_ec_add_query_handler()
1091 list_add(&handler->node, &ec->list); in acpi_ec_add_query_handler()
1092 mutex_unlock(&ec->mutex); in acpi_ec_add_query_handler()
1103 mutex_lock(&ec->mutex); in acpi_ec_remove_query_handlers()
1104 list_for_each_entry_safe(handler, tmp, &ec->list, node) { in acpi_ec_remove_query_handlers()
1105 if (remove_all || query_bit == handler->query_bit) { in acpi_ec_remove_query_handlers()
1106 list_del_init(&handler->node); in acpi_ec_remove_query_handlers()
1107 list_add(&handler->node, &free_list); in acpi_ec_remove_query_handlers()
1110 mutex_unlock(&ec->mutex); in acpi_ec_remove_query_handlers()
1130 INIT_WORK(&q->work, acpi_ec_event_processor); in acpi_ec_create_query()
1131 t = &q->transaction; in acpi_ec_create_query()
1132 t->command = ACPI_EC_COMMAND_QUERY; in acpi_ec_create_query()
1133 t->rdata = pval; in acpi_ec_create_query()
1134 t->rlen = 1; in acpi_ec_create_query()
1135 q->ec = ec; in acpi_ec_create_query()
1142 if (q->handler) in acpi_ec_delete_query()
1143 acpi_ec_put_query_handler(q->handler); in acpi_ec_delete_query()
1151 struct acpi_ec_query_handler *handler = q->handler; in acpi_ec_event_processor()
1152 struct acpi_ec *ec = q->ec; in acpi_ec_event_processor()
1154 ec_dbg_evt("Query(0x%02x) started", handler->query_bit); in acpi_ec_event_processor()
1156 if (handler->func) in acpi_ec_event_processor()
1157 handler->func(handler->data); in acpi_ec_event_processor()
1158 else if (handler->handle) in acpi_ec_event_processor()
1159 acpi_evaluate_object(handler->handle, NULL, NULL, NULL); in acpi_ec_event_processor()
1161 ec_dbg_evt("Query(0x%02x) stopped", handler->query_bit); in acpi_ec_event_processor()
1163 spin_lock_irq(&ec->lock); in acpi_ec_event_processor()
1164 ec->queries_in_progress--; in acpi_ec_event_processor()
1165 spin_unlock_irq(&ec->lock); in acpi_ec_event_processor()
1178 return -ENOMEM; in acpi_ec_query()
1185 result = acpi_ec_transaction(ec, &q->transaction); in acpi_ec_query()
1187 result = -ENODATA; in acpi_ec_query()
1191 q->handler = acpi_ec_get_query_handler_by_value(ec, value); in acpi_ec_query()
1192 if (!q->handler) { in acpi_ec_query()
1193 result = -ENODATA; in acpi_ec_query()
1206 spin_lock_irq(&ec->lock); in acpi_ec_query()
1208 ec->queries_in_progress++; in acpi_ec_query()
1209 queue_work(ec_query_wq, &q->work); in acpi_ec_query()
1211 spin_unlock_irq(&ec->lock); in acpi_ec_query()
1227 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_check_event()
1232 if (!ec->curr) in acpi_ec_check_event()
1234 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_check_event()
1244 ec_dbg_evt("Event started"); in acpi_ec_event_handler()
1246 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_event_handler()
1247 while (ec->nr_pending_queries) { in acpi_ec_event_handler()
1248 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_event_handler()
1250 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_event_handler()
1251 ec->nr_pending_queries--; in acpi_ec_event_handler()
1258 if (!ec->nr_pending_queries) { in acpi_ec_event_handler()
1264 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_event_handler()
1266 ec_dbg_evt("Event stopped"); in acpi_ec_event_handler()
1270 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_event_handler()
1271 ec->events_in_progress--; in acpi_ec_event_handler()
1272 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_event_handler()
1279 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_handle_interrupt()
1281 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_handle_interrupt()
1297 /* --------------------------------------------------------------------------
1299 * -------------------------------------------------------------------------- */
1316 if (ec->busy_polling || bits > 8) in acpi_ec_space_handler()
1324 if (ec->busy_polling || bits > 8) in acpi_ec_space_handler()
1328 case -EINVAL: in acpi_ec_space_handler()
1330 case -ENODEV: in acpi_ec_space_handler()
1332 case -ETIME: in acpi_ec_space_handler()
1339 /* --------------------------------------------------------------------------
1341 * -------------------------------------------------------------------------- */
1361 mutex_init(&ec->mutex); in acpi_ec_alloc()
1362 init_waitqueue_head(&ec->wait); in acpi_ec_alloc()
1363 INIT_LIST_HEAD(&ec->list); in acpi_ec_alloc()
1364 spin_lock_init(&ec->lock); in acpi_ec_alloc()
1365 INIT_WORK(&ec->work, acpi_ec_event_handler); in acpi_ec_alloc()
1366 ec->timestamp = jiffies; in acpi_ec_alloc()
1367 ec->busy_polling = true; in acpi_ec_alloc()
1368 ec->polling_guard = 0; in acpi_ec_alloc()
1369 ec->gpe = -1; in acpi_ec_alloc()
1370 ec->irq = -1; in acpi_ec_alloc()
1399 ec->command_addr = ec->data_addr = 0; in ec_parse_device()
1405 if (ec->data_addr == 0 || ec->command_addr == 0) in ec_parse_device()
1413 ec->gpe = boot_ec->gpe; in ec_parse_device()
1419 ec->gpe = tmp; in ec_parse_device()
1422 * Errors are non-fatal, allowing for ACPI Reduced Hardware in ec_parse_device()
1429 ec->global_lock = tmp; in ec_parse_device()
1430 ec->handle = handle; in ec_parse_device()
1438 status = acpi_install_gpe_raw_handler(NULL, ec->gpe, in install_gpe_event_handler()
1444 if (test_bit(EC_FLAGS_STARTED, &ec->flags) && ec->reference_count >= 1) in install_gpe_event_handler()
1452 return request_irq(ec->irq, acpi_ec_irq_handler, IRQF_SHARED, in install_gpio_irq_event_handler()
1457 * ec_install_handlers - Install service callbacks and register query methods.
1463 * namespace and register them, and install an event (either GPE or GPIO IRQ)
1467 * -ENODEV if the address space handler cannot be installed, which means
1469 * -EPROBE_DEFER if GPIO IRQ acquisition needs to be deferred,
1478 if (!test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) { in ec_install_handlers()
1480 status = acpi_install_address_space_handler(ec->handle, in ec_install_handlers()
1486 return -ENODEV; in ec_install_handlers()
1488 set_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags); in ec_install_handlers()
1494 if (ec->gpe < 0) { in ec_install_handlers()
1501 if (irq == -EPROBE_DEFER) in ec_install_handlers()
1502 return -EPROBE_DEFER; in ec_install_handlers()
1504 ec->irq = irq; in ec_install_handlers()
1507 if (!test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) { in ec_install_handlers()
1509 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1, in ec_install_handlers()
1512 set_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags); in ec_install_handlers()
1514 if (!test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) { in ec_install_handlers()
1517 if (ec->gpe >= 0) in ec_install_handlers()
1519 else if (ec->irq >= 0) in ec_install_handlers()
1523 set_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags); in ec_install_handlers()
1527 * Failures to install an event handler are not fatal, because in ec_install_handlers()
1539 if (test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) { in ec_remove_handlers()
1540 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, in ec_remove_handlers()
1543 clear_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags); in ec_remove_handlers()
1559 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) { in ec_remove_handlers()
1560 if (ec->gpe >= 0 && in ec_remove_handlers()
1561 ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, in ec_remove_handlers()
1565 if (ec->irq >= 0) in ec_remove_handlers()
1566 free_irq(ec->irq, ec); in ec_remove_handlers()
1568 clear_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags); in ec_remove_handlers()
1570 if (test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) { in ec_remove_handlers()
1572 clear_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags); in ec_remove_handlers()
1588 pr_info("EC_CMD/EC_SC=0x%lx, EC_DATA=0x%lx\n", ec->command_addr, in acpi_ec_setup()
1589 ec->data_addr); in acpi_ec_setup()
1591 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) { in acpi_ec_setup()
1592 if (ec->gpe >= 0) in acpi_ec_setup()
1593 pr_info("GPE=0x%x\n", ec->gpe); in acpi_ec_setup()
1595 pr_info("IRQ=%d\n", ec->irq); in acpi_ec_setup()
1609 if (boot_ec && (boot_ec->handle == device->handle || in acpi_ec_add()
1618 return -ENOMEM; in acpi_ec_add()
1620 status = ec_parse_device(device->handle, 0, ec, NULL); in acpi_ec_add()
1622 ret = -EINVAL; in acpi_ec_add()
1626 if (boot_ec && ec->command_addr == boot_ec->command_addr && in acpi_ec_add()
1627 ec->data_addr == boot_ec->data_addr && in acpi_ec_add()
1633 * boot_ec->gpe to ec->gpe. in acpi_ec_add()
1635 boot_ec->handle = ec->handle; in acpi_ec_add()
1636 acpi_handle_debug(ec->handle, "duplicated.\n"); in acpi_ec_add()
1647 acpi_handle_info(boot_ec->handle, in acpi_ec_add()
1651 acpi_handle_info(ec->handle, in acpi_ec_add()
1654 device->driver_data = ec; in acpi_ec_add()
1656 ret = !!request_region(ec->data_addr, 1, "EC data"); in acpi_ec_add()
1657 WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr); in acpi_ec_add()
1658 ret = !!request_region(ec->command_addr, 1, "EC cmd"); in acpi_ec_add()
1659 WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr); in acpi_ec_add()
1662 acpi_walk_dep_device_list(ec->handle); in acpi_ec_add()
1664 acpi_handle_debug(ec->handle, "enumerated.\n"); in acpi_ec_add()
1679 return -EINVAL; in acpi_ec_remove()
1682 release_region(ec->data_addr, 1); in acpi_ec_remove()
1683 release_region(ec->command_addr, 1); in acpi_ec_remove()
1684 device->driver_data = NULL; in acpi_ec_remove()
1697 if (resource->type != ACPI_RESOURCE_TYPE_IO) in ec_parse_io_ports()
1705 if (ec->data_addr == 0) in ec_parse_io_ports()
1706 ec->data_addr = resource->data.io.minimum; in ec_parse_io_ports()
1707 else if (ec->command_addr == 0) in ec_parse_io_ports()
1708 ec->command_addr = resource->data.io.minimum; in ec_parse_io_ports()
1722 * This function is not Windows-compatible as Windows never enumerates the
1750 if (ACPI_FAILURE(status) || !ec->handle) { in acpi_ec_dsdt_probe()
1756 * When the DSDT EC is available, always re-configure boot EC to in acpi_ec_dsdt_probe()
1770 acpi_handle_info(ec->handle, in acpi_ec_dsdt_probe()
1775 * acpi_ec_ecdt_start - Finalize the boot ECDT EC initialization.
1794 if (!boot_ec || boot_ec->handle != ACPI_ROOT_OBJECT) in acpi_ec_ecdt_start()
1803 status = acpi_get_handle(NULL, ecdt_ptr->id, &handle); in acpi_ec_ecdt_start()
1805 boot_ec->handle = handle; in acpi_ec_ecdt_start()
1841 * MSI MS-171F
1877 ec_correct_ecdt, "MSI MS-171F", {
1878 DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star"),
1879 DMI_MATCH(DMI_PRODUCT_NAME, "MS-171F"),}, NULL},
1918 ec_honor_dsdt_gpe, "HP Pavilion Gaming Laptop 15-cx0xxx", {
1920 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion Gaming Laptop 15-cx0xxx"),}, NULL},
1941 if (!ecdt_ptr->control.address || !ecdt_ptr->data.address) { in acpi_ec_ecdt_probe()
1954 ec->command_addr = ecdt_ptr->data.address; in acpi_ec_ecdt_probe()
1955 ec->data_addr = ecdt_ptr->control.address; in acpi_ec_ecdt_probe()
1957 ec->command_addr = ecdt_ptr->control.address; in acpi_ec_ecdt_probe()
1958 ec->data_addr = ecdt_ptr->data.address; in acpi_ec_ecdt_probe()
1966 ec->gpe = ecdt_ptr->gpe; in acpi_ec_ecdt_probe()
1968 ec->handle = ACPI_ROOT_OBJECT; in acpi_ec_ecdt_probe()
2008 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) && in acpi_ec_suspend_noirq()
2009 ec->gpe >= 0 && ec->reference_count >= 1) in acpi_ec_suspend_noirq()
2010 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE); in acpi_ec_suspend_noirq()
2023 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) && in acpi_ec_resume_noirq()
2024 ec->gpe >= 0 && ec->reference_count >= 1) in acpi_ec_resume_noirq()
2025 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE); in acpi_ec_resume_noirq()
2042 acpi_mark_gpe_for_wake(NULL, first_ec->gpe); in acpi_ec_mark_gpe_for_wake()
2046 void acpi_ec_set_gpe_wake_mask(u8 action) in acpi_ec_set_gpe_wake_mask() argument
2049 acpi_set_gpe_wake_mask(NULL, first_ec->gpe, action); in acpi_ec_set_gpe_wake_mask()
2061 * Report wakeup if the status bit is set for any enabled GPE other in acpi_ec_dispatch_gpe()
2064 if (acpi_any_gpe_status_set(first_ec->gpe)) in acpi_ec_dispatch_gpe()
2068 * Dispatch the EC GPE in-band, but do not report wakeup in any case in acpi_ec_dispatch_gpe()
2071 ret = acpi_dispatch_gpe(NULL, first_ec->gpe); in acpi_ec_dispatch_gpe()
2081 spin_lock_irq(&first_ec->lock); in acpi_ec_dispatch_gpe()
2083 work_in_progress = first_ec->events_in_progress + in acpi_ec_dispatch_gpe()
2084 first_ec->queries_in_progress > 0; in acpi_ec_dispatch_gpe()
2086 spin_unlock_irq(&first_ec->lock); in acpi_ec_dispatch_gpe()
2103 if (!strncmp(val, "status", sizeof("status") - 1)) { in param_set_event_clearing()
2106 } else if (!strncmp(val, "query", sizeof("query") - 1)) { in param_set_event_clearing()
2109 } else if (!strncmp(val, "event", sizeof("event") - 1)) { in param_set_event_clearing()
2111 pr_info("Assuming SCI_EVT clearing on event reads\n"); in param_set_event_clearing()
2113 result = -EINVAL; in param_set_event_clearing()
2126 return sprintf(buffer, "event\n"); in param_get_event_clearing()
2170 return -ENODEV; in acpi_ec_init_workqueues()
2209 * Disable EC wakeup on following systems to prevent periodic in acpi_ec_init()
2210 * wakeup from EC GPE. in acpi_ec_init()
2214 pr_debug("Disabling EC wakeup on suspend-to-idle\n"); in acpi_ec_init()