Lines Matching refs:ec

171 static int acpi_ec_query(struct acpi_ec *ec, u8 *data);
172 static void advance_transaction(struct acpi_ec *ec, bool interrupt);
230 #define ec_dbg_ref(ec, fmt, ...) \ argument
231 ec_dbg_raw("%lu: " fmt, ec->reference_count, ## __VA_ARGS__)
237 static bool acpi_ec_started(struct acpi_ec *ec) in acpi_ec_started() argument
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()
243 static bool acpi_ec_event_enabled(struct acpi_ec *ec) in acpi_ec_event_enabled() argument
250 if (!test_bit(EC_FLAGS_QUERY_ENABLED, &ec->flags)) in acpi_ec_event_enabled()
262 return acpi_ec_started(ec); in acpi_ec_event_enabled()
264 return test_bit(EC_FLAGS_STARTED, &ec->flags); in acpi_ec_event_enabled()
267 static bool acpi_ec_flushed(struct acpi_ec *ec) in acpi_ec_flushed() argument
269 return ec->reference_count == 1; in acpi_ec_flushed()
276 static inline u8 acpi_ec_read_status(struct acpi_ec *ec) in acpi_ec_read_status() argument
278 u8 x = inb(ec->command_addr); in acpi_ec_read_status()
291 static inline u8 acpi_ec_read_data(struct acpi_ec *ec) in acpi_ec_read_data() argument
293 u8 x = inb(ec->data_addr); in acpi_ec_read_data()
295 ec->timestamp = jiffies; in acpi_ec_read_data()
300 static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) in acpi_ec_write_cmd() argument
303 outb(command, ec->command_addr); in acpi_ec_write_cmd()
304 ec->timestamp = jiffies; in acpi_ec_write_cmd()
307 static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) in acpi_ec_write_data() argument
310 outb(data, ec->data_addr); in acpi_ec_write_data()
311 ec->timestamp = jiffies; in acpi_ec_write_data()
339 static inline bool acpi_ec_gpe_status_set(struct acpi_ec *ec) in acpi_ec_gpe_status_set() argument
343 (void)acpi_get_gpe_status(NULL, ec->gpe, &gpe_status); in acpi_ec_gpe_status_set()
347 static inline void acpi_ec_enable_gpe(struct acpi_ec *ec, bool open) in acpi_ec_enable_gpe() argument
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()
355 if (acpi_ec_gpe_status_set(ec)) { in acpi_ec_enable_gpe()
362 advance_transaction(ec, false); in acpi_ec_enable_gpe()
366 static inline void acpi_ec_disable_gpe(struct acpi_ec *ec, bool close) in acpi_ec_disable_gpe() argument
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()
380 static void acpi_ec_submit_request(struct acpi_ec *ec) in acpi_ec_submit_request() argument
382 ec->reference_count++; in acpi_ec_submit_request()
383 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags) && in acpi_ec_submit_request()
384 ec->gpe >= 0 && ec->reference_count == 1) in acpi_ec_submit_request()
385 acpi_ec_enable_gpe(ec, true); in acpi_ec_submit_request()
388 static void acpi_ec_complete_request(struct acpi_ec *ec) in acpi_ec_complete_request() argument
392 ec->reference_count--; in acpi_ec_complete_request()
393 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags) && in acpi_ec_complete_request()
394 ec->gpe >= 0 && ec->reference_count == 0) in acpi_ec_complete_request()
395 acpi_ec_disable_gpe(ec, true); in acpi_ec_complete_request()
396 flushed = acpi_ec_flushed(ec); in acpi_ec_complete_request()
398 wake_up(&ec->wait); in acpi_ec_complete_request()
401 static void acpi_ec_mask_events(struct acpi_ec *ec) in acpi_ec_mask_events() argument
403 if (!test_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags)) { in acpi_ec_mask_events()
404 if (ec->gpe >= 0) in acpi_ec_mask_events()
405 acpi_ec_disable_gpe(ec, false); in acpi_ec_mask_events()
407 disable_irq_nosync(ec->irq); in acpi_ec_mask_events()
410 set_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags); in acpi_ec_mask_events()
414 static void acpi_ec_unmask_events(struct acpi_ec *ec) in acpi_ec_unmask_events() argument
416 if (test_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags)) { in acpi_ec_unmask_events()
417 clear_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags); in acpi_ec_unmask_events()
418 if (ec->gpe >= 0) in acpi_ec_unmask_events()
419 acpi_ec_enable_gpe(ec, false); in acpi_ec_unmask_events()
421 enable_irq(ec->irq); in acpi_ec_unmask_events()
438 static bool acpi_ec_submit_flushable_request(struct acpi_ec *ec) in acpi_ec_submit_flushable_request() argument
440 if (!acpi_ec_started(ec)) in acpi_ec_submit_flushable_request()
442 acpi_ec_submit_request(ec); in acpi_ec_submit_flushable_request()
446 static void acpi_ec_submit_query(struct acpi_ec *ec) in acpi_ec_submit_query() argument
448 acpi_ec_mask_events(ec); in acpi_ec_submit_query()
449 if (!acpi_ec_event_enabled(ec)) in acpi_ec_submit_query()
451 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { in acpi_ec_submit_query()
454 ec->nr_pending_queries++; in acpi_ec_submit_query()
455 queue_work(ec_wq, &ec->work); in acpi_ec_submit_query()
459 static void acpi_ec_complete_query(struct acpi_ec *ec) in acpi_ec_complete_query() argument
461 if (test_and_clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) in acpi_ec_complete_query()
464 acpi_ec_unmask_events(ec); in acpi_ec_complete_query()
467 static inline void __acpi_ec_enable_event(struct acpi_ec *ec) in __acpi_ec_enable_event() argument
469 if (!test_and_set_bit(EC_FLAGS_QUERY_ENABLED, &ec->flags)) in __acpi_ec_enable_event()
475 advance_transaction(ec, false); in __acpi_ec_enable_event()
478 static inline void __acpi_ec_disable_event(struct acpi_ec *ec) in __acpi_ec_disable_event() argument
480 if (test_and_clear_bit(EC_FLAGS_QUERY_ENABLED, &ec->flags)) in __acpi_ec_disable_event()
488 static void acpi_ec_clear(struct acpi_ec *ec) in acpi_ec_clear() argument
494 status = acpi_ec_query(ec, &value); in acpi_ec_clear()
504 static void acpi_ec_enable_event(struct acpi_ec *ec) in acpi_ec_enable_event() argument
508 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_enable_event()
509 if (acpi_ec_started(ec)) in acpi_ec_enable_event()
510 __acpi_ec_enable_event(ec); in acpi_ec_enable_event()
511 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_enable_event()
515 acpi_ec_clear(ec); in acpi_ec_enable_event()
525 static void acpi_ec_disable_event(struct acpi_ec *ec) in acpi_ec_disable_event() argument
529 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_disable_event()
530 __acpi_ec_disable_event(ec); in acpi_ec_disable_event()
531 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_disable_event()
550 static bool acpi_ec_guard_event(struct acpi_ec *ec) in acpi_ec_guard_event() argument
555 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_guard_event()
572 !test_bit(EC_FLAGS_QUERY_PENDING, &ec->flags) || in acpi_ec_guard_event()
573 (ec->curr && ec->curr->command == ACPI_EC_COMMAND_QUERY)) in acpi_ec_guard_event()
575 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_guard_event()
579 static int ec_transaction_polled(struct acpi_ec *ec) in ec_transaction_polled() argument
584 spin_lock_irqsave(&ec->lock, flags); in ec_transaction_polled()
585 if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_POLL)) in ec_transaction_polled()
587 spin_unlock_irqrestore(&ec->lock, flags); in ec_transaction_polled()
591 static int ec_transaction_completed(struct acpi_ec *ec) in ec_transaction_completed() argument
596 spin_lock_irqsave(&ec->lock, flags); in ec_transaction_completed()
597 if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_COMPLETE)) in ec_transaction_completed()
599 spin_unlock_irqrestore(&ec->lock, flags); in ec_transaction_completed()
603 static inline void ec_transaction_transition(struct acpi_ec *ec, unsigned long flag) in ec_transaction_transition() argument
605 ec->curr->flags |= flag; in ec_transaction_transition()
606 if (ec->curr->command == ACPI_EC_COMMAND_QUERY) { in ec_transaction_transition()
609 acpi_ec_complete_query(ec); in ec_transaction_transition()
612 acpi_ec_complete_query(ec); in ec_transaction_transition()
615 set_bit(EC_FLAGS_QUERY_GUARDING, &ec->flags); in ec_transaction_transition()
619 static void acpi_ec_spurious_interrupt(struct acpi_ec *ec, struct transaction *t) in acpi_ec_spurious_interrupt() argument
626 acpi_ec_mask_events(ec); in acpi_ec_spurious_interrupt()
629 static void advance_transaction(struct acpi_ec *ec, bool interrupt) in advance_transaction() argument
631 struct transaction *t = ec->curr; in advance_transaction()
649 if (ec->gpe >= 0 && acpi_ec_gpe_status_set(ec)) in advance_transaction()
650 acpi_clear_gpe(NULL, ec->gpe); in advance_transaction()
652 status = acpi_ec_read_status(ec); in advance_transaction()
660 (!ec->nr_pending_queries || in advance_transaction()
661 test_bit(EC_FLAGS_QUERY_GUARDING, &ec->flags))) { in advance_transaction()
662 clear_bit(EC_FLAGS_QUERY_GUARDING, &ec->flags); in advance_transaction()
663 acpi_ec_complete_query(ec); in advance_transaction()
672 acpi_ec_write_data(ec, t->wdata[t->wi++]); in advance_transaction()
674 acpi_ec_spurious_interrupt(ec, t); in advance_transaction()
677 t->rdata[t->ri++] = acpi_ec_read_data(ec); in advance_transaction()
679 ec_transaction_transition(ec, ACPI_EC_COMMAND_COMPLETE); in advance_transaction()
686 acpi_ec_spurious_interrupt(ec, t); in advance_transaction()
689 ec_transaction_transition(ec, ACPI_EC_COMMAND_COMPLETE); in advance_transaction()
693 acpi_ec_write_cmd(ec, t->command); in advance_transaction()
694 ec_transaction_transition(ec, ACPI_EC_COMMAND_POLL); in advance_transaction()
699 acpi_ec_submit_query(ec); in advance_transaction()
702 wake_up(&ec->wait); in advance_transaction()
705 static void start_transaction(struct acpi_ec *ec) in start_transaction() argument
707 ec->curr->irq_count = ec->curr->wi = ec->curr->ri = 0; in start_transaction()
708 ec->curr->flags = 0; in start_transaction()
711 static int ec_guard(struct acpi_ec *ec) in ec_guard() argument
713 unsigned long guard = usecs_to_jiffies(ec->polling_guard); in ec_guard()
714 unsigned long timeout = ec->timestamp + guard; in ec_guard()
718 if (ec->busy_polling) { in ec_guard()
720 if (ec_transaction_completed(ec)) in ec_guard()
734 if (!ec_transaction_polled(ec) && in ec_guard()
735 !acpi_ec_guard_event(ec)) in ec_guard()
737 if (wait_event_timeout(ec->wait, in ec_guard()
738 ec_transaction_completed(ec), in ec_guard()
746 static int ec_poll(struct acpi_ec *ec) in ec_poll() argument
755 if (!ec_guard(ec)) in ec_poll()
757 spin_lock_irqsave(&ec->lock, flags); in ec_poll()
758 advance_transaction(ec, false); in ec_poll()
759 spin_unlock_irqrestore(&ec->lock, flags); in ec_poll()
762 spin_lock_irqsave(&ec->lock, flags); in ec_poll()
763 start_transaction(ec); in ec_poll()
764 spin_unlock_irqrestore(&ec->lock, flags); in ec_poll()
769 static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, in acpi_ec_transaction_unlocked() argument
776 spin_lock_irqsave(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
778 if (!acpi_ec_submit_flushable_request(ec)) { in acpi_ec_transaction_unlocked()
782 ec_dbg_ref(ec, "Increase command"); in acpi_ec_transaction_unlocked()
784 ec->curr = t; in acpi_ec_transaction_unlocked()
786 start_transaction(ec); in acpi_ec_transaction_unlocked()
787 spin_unlock_irqrestore(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
789 ret = ec_poll(ec); in acpi_ec_transaction_unlocked()
791 spin_lock_irqsave(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
793 acpi_ec_unmask_events(ec); in acpi_ec_transaction_unlocked()
795 ec->curr = NULL; in acpi_ec_transaction_unlocked()
797 acpi_ec_complete_request(ec); in acpi_ec_transaction_unlocked()
798 ec_dbg_ref(ec, "Decrease command"); in acpi_ec_transaction_unlocked()
800 spin_unlock_irqrestore(&ec->lock, tmp); in acpi_ec_transaction_unlocked()
804 static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t) in acpi_ec_transaction() argument
809 if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata)) in acpi_ec_transaction()
814 mutex_lock(&ec->mutex); in acpi_ec_transaction()
815 if (ec->global_lock) { in acpi_ec_transaction()
823 status = acpi_ec_transaction_unlocked(ec, t); in acpi_ec_transaction()
825 if (ec->global_lock) in acpi_ec_transaction()
828 mutex_unlock(&ec->mutex); in acpi_ec_transaction()
832 static int acpi_ec_burst_enable(struct acpi_ec *ec) in acpi_ec_burst_enable() argument
839 return acpi_ec_transaction(ec, &t); in acpi_ec_burst_enable()
842 static int acpi_ec_burst_disable(struct acpi_ec *ec) in acpi_ec_burst_disable() argument
848 return (acpi_ec_read_status(ec) & ACPI_EC_FLAG_BURST) ? in acpi_ec_burst_disable()
849 acpi_ec_transaction(ec, &t) : 0; in acpi_ec_burst_disable()
852 static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data) in acpi_ec_read() argument
860 result = acpi_ec_transaction(ec, &t); in acpi_ec_read()
865 static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data) in acpi_ec_write() argument
872 return acpi_ec_transaction(ec, &t); in acpi_ec_write()
930 static void acpi_ec_start(struct acpi_ec *ec, bool resuming) in acpi_ec_start() argument
934 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_start()
935 if (!test_and_set_bit(EC_FLAGS_STARTED, &ec->flags)) { in acpi_ec_start()
939 acpi_ec_submit_request(ec); in acpi_ec_start()
940 ec_dbg_ref(ec, "Increase driver"); in acpi_ec_start()
944 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_start()
947 static bool acpi_ec_stopped(struct acpi_ec *ec) in acpi_ec_stopped() argument
952 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_stopped()
953 flushed = acpi_ec_flushed(ec); in acpi_ec_stopped()
954 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_stopped()
958 static void acpi_ec_stop(struct acpi_ec *ec, bool suspending) in acpi_ec_stop() argument
962 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_stop()
963 if (acpi_ec_started(ec)) { in acpi_ec_stop()
965 set_bit(EC_FLAGS_STOPPED, &ec->flags); in acpi_ec_stop()
966 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_stop()
967 wait_event(ec->wait, acpi_ec_stopped(ec)); in acpi_ec_stop()
968 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_stop()
971 acpi_ec_complete_request(ec); in acpi_ec_stop()
972 ec_dbg_ref(ec, "Decrease driver"); in acpi_ec_stop()
974 __acpi_ec_disable_event(ec); in acpi_ec_stop()
975 clear_bit(EC_FLAGS_STARTED, &ec->flags); in acpi_ec_stop()
976 clear_bit(EC_FLAGS_STOPPED, &ec->flags); in acpi_ec_stop()
979 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_stop()
982 static void acpi_ec_enter_noirq(struct acpi_ec *ec) in acpi_ec_enter_noirq() argument
986 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_enter_noirq()
987 ec->busy_polling = true; in acpi_ec_enter_noirq()
988 ec->polling_guard = 0; in acpi_ec_enter_noirq()
990 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_enter_noirq()
993 static void acpi_ec_leave_noirq(struct acpi_ec *ec) in acpi_ec_leave_noirq() argument
997 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_leave_noirq()
998 ec->busy_polling = ec_busy_polling; in acpi_ec_leave_noirq()
999 ec->polling_guard = ec_polling_guard; in acpi_ec_leave_noirq()
1001 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_leave_noirq()
1006 struct acpi_ec *ec = first_ec; in acpi_ec_block_transactions() local
1008 if (!ec) in acpi_ec_block_transactions()
1011 mutex_lock(&ec->mutex); in acpi_ec_block_transactions()
1013 acpi_ec_stop(ec, true); in acpi_ec_block_transactions()
1014 mutex_unlock(&ec->mutex); in acpi_ec_block_transactions()
1031 acpi_ec_get_query_handler_by_value(struct acpi_ec *ec, u8 value) in acpi_ec_get_query_handler_by_value() argument
1035 mutex_lock(&ec->mutex); in acpi_ec_get_query_handler_by_value()
1036 list_for_each_entry(handler, &ec->list, node) { in acpi_ec_get_query_handler_by_value()
1039 mutex_unlock(&ec->mutex); in acpi_ec_get_query_handler_by_value()
1043 mutex_unlock(&ec->mutex); in acpi_ec_get_query_handler_by_value()
1060 int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, in acpi_ec_add_query_handler() argument
1074 mutex_lock(&ec->mutex); in acpi_ec_add_query_handler()
1076 list_add(&handler->node, &ec->list); in acpi_ec_add_query_handler()
1077 mutex_unlock(&ec->mutex); in acpi_ec_add_query_handler()
1082 static void acpi_ec_remove_query_handlers(struct acpi_ec *ec, in acpi_ec_remove_query_handlers() argument
1088 mutex_lock(&ec->mutex); in acpi_ec_remove_query_handlers()
1089 list_for_each_entry_safe(handler, tmp, &ec->list, node) { in acpi_ec_remove_query_handlers()
1095 mutex_unlock(&ec->mutex); in acpi_ec_remove_query_handlers()
1100 void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) in acpi_ec_remove_query_handler() argument
1102 acpi_ec_remove_query_handlers(ec, false, query_bit); in acpi_ec_remove_query_handler()
1145 static int acpi_ec_query(struct acpi_ec *ec, u8 *data) in acpi_ec_query() argument
1160 result = acpi_ec_transaction(ec, &q->transaction); in acpi_ec_query()
1166 q->handler = acpi_ec_get_query_handler_by_value(ec, value); in acpi_ec_query()
1195 static void acpi_ec_check_event(struct acpi_ec *ec) in acpi_ec_check_event() argument
1200 if (ec_guard(ec)) { in acpi_ec_check_event()
1201 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_check_event()
1206 if (!ec->curr) in acpi_ec_check_event()
1207 advance_transaction(ec, false); in acpi_ec_check_event()
1208 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_check_event()
1216 struct acpi_ec *ec = container_of(work, struct acpi_ec, work); in acpi_ec_event_handler() local
1220 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_event_handler()
1221 while (ec->nr_pending_queries) { in acpi_ec_event_handler()
1222 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_event_handler()
1223 (void)acpi_ec_query(ec, NULL); in acpi_ec_event_handler()
1224 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_event_handler()
1225 ec->nr_pending_queries--; in acpi_ec_event_handler()
1232 if (!ec->nr_pending_queries) { in acpi_ec_event_handler()
1235 acpi_ec_complete_query(ec); in acpi_ec_event_handler()
1238 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_event_handler()
1242 acpi_ec_check_event(ec); in acpi_ec_event_handler()
1245 static void acpi_ec_handle_interrupt(struct acpi_ec *ec) in acpi_ec_handle_interrupt() argument
1249 spin_lock_irqsave(&ec->lock, flags); in acpi_ec_handle_interrupt()
1250 advance_transaction(ec, true); in acpi_ec_handle_interrupt()
1251 spin_unlock_irqrestore(&ec->lock, flags); in acpi_ec_handle_interrupt()
1276 struct acpi_ec *ec = handler_context; in acpi_ec_space_handler() local
1286 if (ec->busy_polling || bits > 8) in acpi_ec_space_handler()
1287 acpi_ec_burst_enable(ec); in acpi_ec_space_handler()
1291 acpi_ec_read(ec, address, value) : in acpi_ec_space_handler()
1292 acpi_ec_write(ec, address, *value); in acpi_ec_space_handler()
1294 if (ec->busy_polling || bits > 8) in acpi_ec_space_handler()
1295 acpi_ec_burst_disable(ec); in acpi_ec_space_handler()
1316 static void acpi_ec_free(struct acpi_ec *ec) in acpi_ec_free() argument
1318 if (first_ec == ec) in acpi_ec_free()
1320 if (boot_ec == ec) in acpi_ec_free()
1322 kfree(ec); in acpi_ec_free()
1327 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); in acpi_ec_alloc() local
1329 if (!ec) in acpi_ec_alloc()
1331 mutex_init(&ec->mutex); in acpi_ec_alloc()
1332 init_waitqueue_head(&ec->wait); in acpi_ec_alloc()
1333 INIT_LIST_HEAD(&ec->list); in acpi_ec_alloc()
1334 spin_lock_init(&ec->lock); in acpi_ec_alloc()
1335 INIT_WORK(&ec->work, acpi_ec_event_handler); in acpi_ec_alloc()
1336 ec->timestamp = jiffies; in acpi_ec_alloc()
1337 ec->busy_polling = true; in acpi_ec_alloc()
1338 ec->polling_guard = 0; in acpi_ec_alloc()
1339 ec->gpe = -1; in acpi_ec_alloc()
1340 ec->irq = -1; in acpi_ec_alloc()
1341 return ec; in acpi_ec_alloc()
1350 struct acpi_ec *ec = context; in acpi_ec_register_query_methods() local
1357 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL); in acpi_ec_register_query_methods()
1366 struct acpi_ec *ec = context; in ec_parse_device() local
1369 ec->command_addr = ec->data_addr = 0; in ec_parse_device()
1372 ec_parse_io_ports, ec); in ec_parse_device()
1375 if (ec->data_addr == 0 || ec->command_addr == 0) in ec_parse_device()
1383 ec->gpe = boot_ec->gpe; in ec_parse_device()
1389 ec->gpe = tmp; in ec_parse_device()
1399 ec->global_lock = tmp; in ec_parse_device()
1400 ec->handle = handle; in ec_parse_device()
1404 static bool install_gpe_event_handler(struct acpi_ec *ec) in install_gpe_event_handler() argument
1408 status = acpi_install_gpe_raw_handler(NULL, ec->gpe, in install_gpe_event_handler()
1410 &acpi_ec_gpe_handler, ec); in install_gpe_event_handler()
1414 if (test_bit(EC_FLAGS_STARTED, &ec->flags) && ec->reference_count >= 1) in install_gpe_event_handler()
1415 acpi_ec_enable_gpe(ec, true); in install_gpe_event_handler()
1420 static bool install_gpio_irq_event_handler(struct acpi_ec *ec) in install_gpio_irq_event_handler() argument
1422 return request_irq(ec->irq, acpi_ec_irq_handler, IRQF_SHARED, in install_gpio_irq_event_handler()
1423 "ACPI EC", ec) >= 0; in install_gpio_irq_event_handler()
1442 static int ec_install_handlers(struct acpi_ec *ec, struct acpi_device *device) in ec_install_handlers() argument
1446 acpi_ec_start(ec, false); in ec_install_handlers()
1448 if (!test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) { in ec_install_handlers()
1449 acpi_ec_enter_noirq(ec); in ec_install_handlers()
1450 status = acpi_install_address_space_handler(ec->handle, in ec_install_handlers()
1453 NULL, ec); in ec_install_handlers()
1455 acpi_ec_stop(ec, false); in ec_install_handlers()
1458 set_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags); in ec_install_handlers()
1464 if (ec->gpe < 0) { in ec_install_handlers()
1474 ec->irq = irq; in ec_install_handlers()
1477 if (!test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) { in ec_install_handlers()
1479 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1, in ec_install_handlers()
1481 NULL, ec, NULL); in ec_install_handlers()
1482 set_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags); in ec_install_handlers()
1484 if (!test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) { in ec_install_handlers()
1487 if (ec->gpe >= 0) in ec_install_handlers()
1488 ready = install_gpe_event_handler(ec); in ec_install_handlers()
1489 else if (ec->irq >= 0) in ec_install_handlers()
1490 ready = install_gpio_irq_event_handler(ec); in ec_install_handlers()
1493 set_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags); in ec_install_handlers()
1494 acpi_ec_leave_noirq(ec); in ec_install_handlers()
1502 acpi_ec_enable_event(ec); in ec_install_handlers()
1507 static void ec_remove_handlers(struct acpi_ec *ec) in ec_remove_handlers() argument
1509 if (test_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags)) { in ec_remove_handlers()
1510 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, in ec_remove_handlers()
1513 clear_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags); in ec_remove_handlers()
1527 acpi_ec_stop(ec, false); in ec_remove_handlers()
1529 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) { in ec_remove_handlers()
1530 if (ec->gpe >= 0 && in ec_remove_handlers()
1531 ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, in ec_remove_handlers()
1535 if (ec->irq >= 0) in ec_remove_handlers()
1536 free_irq(ec->irq, ec); in ec_remove_handlers()
1538 clear_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags); in ec_remove_handlers()
1540 if (test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) { in ec_remove_handlers()
1541 acpi_ec_remove_query_handlers(ec, true, 0); in ec_remove_handlers()
1542 clear_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags); in ec_remove_handlers()
1546 static int acpi_ec_setup(struct acpi_ec *ec, struct acpi_device *device) in acpi_ec_setup() argument
1550 ret = ec_install_handlers(ec, device); in acpi_ec_setup()
1556 first_ec = ec; in acpi_ec_setup()
1558 pr_info("EC_CMD/EC_SC=0x%lx, EC_DATA=0x%lx\n", ec->command_addr, in acpi_ec_setup()
1559 ec->data_addr); in acpi_ec_setup()
1561 if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) { in acpi_ec_setup()
1562 if (ec->gpe >= 0) in acpi_ec_setup()
1563 pr_info("GPE=0x%x\n", ec->gpe); in acpi_ec_setup()
1565 pr_info("IRQ=%d\n", ec->irq); in acpi_ec_setup()
1573 struct acpi_ec *ec; in acpi_ec_add() local
1582 ec = boot_ec; in acpi_ec_add()
1586 ec = acpi_ec_alloc(); in acpi_ec_add()
1587 if (!ec) in acpi_ec_add()
1590 status = ec_parse_device(device->handle, 0, ec, NULL); in acpi_ec_add()
1596 if (boot_ec && ec->command_addr == boot_ec->command_addr && in acpi_ec_add()
1597 ec->data_addr == boot_ec->data_addr && in acpi_ec_add()
1605 boot_ec->handle = ec->handle; in acpi_ec_add()
1606 acpi_handle_debug(ec->handle, "duplicated.\n"); in acpi_ec_add()
1607 acpi_ec_free(ec); in acpi_ec_add()
1608 ec = boot_ec; in acpi_ec_add()
1612 ret = acpi_ec_setup(ec, device); in acpi_ec_add()
1616 if (ec == boot_ec) in acpi_ec_add()
1621 acpi_handle_info(ec->handle, in acpi_ec_add()
1624 device->driver_data = ec; in acpi_ec_add()
1626 ret = !!request_region(ec->data_addr, 1, "EC data"); in acpi_ec_add()
1627 WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr); in acpi_ec_add()
1628 ret = !!request_region(ec->command_addr, 1, "EC cmd"); in acpi_ec_add()
1629 WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr); in acpi_ec_add()
1634 acpi_handle_debug(ec->handle, "enumerated.\n"); in acpi_ec_add()
1638 if (ec != boot_ec) in acpi_ec_add()
1639 acpi_ec_free(ec); in acpi_ec_add()
1646 struct acpi_ec *ec; in acpi_ec_remove() local
1651 ec = acpi_driver_data(device); in acpi_ec_remove()
1652 release_region(ec->data_addr, 1); in acpi_ec_remove()
1653 release_region(ec->command_addr, 1); in acpi_ec_remove()
1655 if (ec != boot_ec) { in acpi_ec_remove()
1656 ec_remove_handlers(ec); in acpi_ec_remove()
1657 acpi_ec_free(ec); in acpi_ec_remove()
1665 struct acpi_ec *ec = context; in ec_parse_io_ports() local
1675 if (ec->data_addr == 0) in ec_parse_io_ports()
1676 ec->data_addr = resource->data.io.minimum; in ec_parse_io_ports()
1677 else if (ec->command_addr == 0) in ec_parse_io_ports()
1678 ec->command_addr = resource->data.io.minimum; in ec_parse_io_ports()
1698 struct acpi_ec *ec; in acpi_ec_dsdt_probe() local
1711 ec = acpi_ec_alloc(); in acpi_ec_dsdt_probe()
1712 if (!ec) in acpi_ec_dsdt_probe()
1719 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, ec, NULL); in acpi_ec_dsdt_probe()
1720 if (ACPI_FAILURE(status) || !ec->handle) { in acpi_ec_dsdt_probe()
1721 acpi_ec_free(ec); in acpi_ec_dsdt_probe()
1732 ret = acpi_ec_setup(ec, NULL); in acpi_ec_dsdt_probe()
1734 acpi_ec_free(ec); in acpi_ec_dsdt_probe()
1738 boot_ec = ec; in acpi_ec_dsdt_probe()
1740 acpi_handle_info(ec->handle, in acpi_ec_dsdt_probe()
1900 struct acpi_ec *ec; in acpi_ec_ecdt_probe() local
1919 ec = acpi_ec_alloc(); in acpi_ec_ecdt_probe()
1920 if (!ec) in acpi_ec_ecdt_probe()
1924 ec->command_addr = ecdt_ptr->data.address; in acpi_ec_ecdt_probe()
1925 ec->data_addr = ecdt_ptr->control.address; in acpi_ec_ecdt_probe()
1927 ec->command_addr = ecdt_ptr->control.address; in acpi_ec_ecdt_probe()
1928 ec->data_addr = ecdt_ptr->data.address; in acpi_ec_ecdt_probe()
1936 ec->gpe = ecdt_ptr->gpe; in acpi_ec_ecdt_probe()
1938 ec->handle = ACPI_ROOT_OBJECT; in acpi_ec_ecdt_probe()
1944 ret = acpi_ec_setup(ec, NULL); in acpi_ec_ecdt_probe()
1946 acpi_ec_free(ec); in acpi_ec_ecdt_probe()
1950 boot_ec = ec; in acpi_ec_ecdt_probe()
1962 struct acpi_ec *ec = in acpi_ec_suspend() local
1966 acpi_ec_disable_event(ec); in acpi_ec_suspend()
1972 struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev)); in acpi_ec_suspend_noirq() local
1978 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) && in acpi_ec_suspend_noirq()
1979 ec->gpe >= 0 && ec->reference_count >= 1) in acpi_ec_suspend_noirq()
1980 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE); in acpi_ec_suspend_noirq()
1982 acpi_ec_enter_noirq(ec); in acpi_ec_suspend_noirq()
1989 struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev)); in acpi_ec_resume_noirq() local
1991 acpi_ec_leave_noirq(ec); in acpi_ec_resume_noirq()
1993 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) && in acpi_ec_resume_noirq()
1994 ec->gpe >= 0 && ec->reference_count >= 1) in acpi_ec_resume_noirq()
1995 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE); in acpi_ec_resume_noirq()
2002 struct acpi_ec *ec = in acpi_ec_resume() local
2005 acpi_ec_enable_event(ec); in acpi_ec_resume()