Lines Matching refs:ec

2  *  ec.c - ACPI Embedded Controller Driver (v2.1)
85 /* ec.c is compiled in acpi namespace so this shows up as acpi.ec_delay param */
125 static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
127 u8 x = inb(ec->command_addr);
132 static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
134 u8 x = inb(ec->data_addr);
139 static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
142 outb(command, ec->command_addr);
145 static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
148 outb(data, ec->data_addr);
151 static int ec_transaction_done(struct acpi_ec *ec)
155 spin_lock_irqsave(&ec->curr_lock, flags);
156 if (!ec->curr || ec->curr->done)
158 spin_unlock_irqrestore(&ec->curr_lock, flags);
162 static void start_transaction(struct acpi_ec *ec)
164 ec->curr->irq_count = ec->curr->wi = ec->curr->ri = 0;
165 ec->curr->done = false;
166 acpi_ec_write_cmd(ec, ec->curr->command);
169 static void advance_transaction(struct acpi_ec *ec, u8 status)
172 spin_lock_irqsave(&ec->curr_lock, flags);
173 if (!ec->curr)
175 if (ec->curr->wlen > ec->curr->wi) {
177 acpi_ec_write_data(ec,
178 ec->curr->wdata[ec->curr->wi++]);
181 } else if (ec->curr->rlen > ec->curr->ri) {
183 ec->curr->rdata[ec->curr->ri++] = acpi_ec_read_data(ec);
184 if (ec->curr->rlen == ec->curr->ri)
185 ec->curr->done = true;
188 } else if (ec->curr->wlen == ec->curr->wi &&
190 ec->curr->done = true;
195 ++ec->curr->irq_count;
197 spin_unlock_irqrestore(&ec->curr_lock, flags);
200 static int acpi_ec_sync_query(struct acpi_ec *ec);
202 static int ec_check_sci_sync(struct acpi_ec *ec, u8 state)
205 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
206 return acpi_ec_sync_query(ec);
211 static int ec_poll(struct acpi_ec *ec)
222 if (ec_transaction_done(ec))
225 if (wait_event_timeout(ec->wait,
226 ec_transaction_done(ec),
230 advance_transaction(ec, acpi_ec_read_status(ec));
232 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)
235 spin_lock_irqsave(&ec->curr_lock, flags);
236 start_transaction(ec);
237 spin_unlock_irqrestore(&ec->curr_lock, flags);
242 static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
250 spin_lock_irqsave(&ec->curr_lock, tmp);
252 ec->curr = t;
253 start_transaction(ec);
254 if (ec->curr->command == ACPI_EC_COMMAND_QUERY)
255 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
256 spin_unlock_irqrestore(&ec->curr_lock, tmp);
257 ret = ec_poll(ec);
258 spin_lock_irqsave(&ec->curr_lock, tmp);
259 ec->curr = NULL;
260 spin_unlock_irqrestore(&ec->curr_lock, tmp);
264 static int ec_check_ibf0(struct acpi_ec *ec)
266 u8 status = acpi_ec_read_status(ec);
270 static int ec_wait_ibf0(struct acpi_ec *ec)
275 if (wait_event_timeout(ec->wait, ec_check_ibf0(ec),
281 static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
285 if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata))
289 mutex_lock(&ec->lock);
290 if (test_bit(EC_FLAGS_BLOCKED, &ec->flags)) {
294 if (ec->global_lock) {
301 if (ec_wait_ibf0(ec)) {
309 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
311 acpi_disable_gpe(NULL, ec->gpe);
314 status = acpi_ec_transaction_unlocked(ec, t);
317 ec_check_sci_sync(ec, acpi_ec_read_status(ec));
318 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
321 acpi_enable_gpe(NULL, ec->gpe);
325 set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
329 if (ec->global_lock)
332 mutex_unlock(&ec->lock);
336 static int acpi_ec_burst_enable(struct acpi_ec *ec)
343 return acpi_ec_transaction(ec, &t);
346 static int acpi_ec_burst_disable(struct acpi_ec *ec)
352 return (acpi_ec_read_status(ec) & ACPI_EC_FLAG_BURST) ?
353 acpi_ec_transaction(ec, &t) : 0;
356 static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
364 result = acpi_ec_transaction(ec, &t);
369 static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
376 return acpi_ec_transaction(ec, &t);
460 struct acpi_ec *ec = first_ec;
462 if (!ec)
465 mutex_lock(&ec->lock);
467 set_bit(EC_FLAGS_BLOCKED, &ec->flags);
468 mutex_unlock(&ec->lock);
473 struct acpi_ec *ec = first_ec;
475 if (!ec)
478 mutex_lock(&ec->lock);
480 clear_bit(EC_FLAGS_BLOCKED, &ec->flags);
481 mutex_unlock(&ec->lock);
494 static int acpi_ec_query_unlocked(struct acpi_ec *ec, u8 * data)
501 if (!ec || !data)
508 result = acpi_ec_transaction_unlocked(ec, &t);
520 int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
533 mutex_lock(&ec->lock);
534 list_add(&handler->node, &ec->list);
535 mutex_unlock(&ec->lock);
541 void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
544 mutex_lock(&ec->lock);
545 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
551 mutex_unlock(&ec->lock);
570 static int acpi_ec_sync_query(struct acpi_ec *ec)
575 if ((status = acpi_ec_query_unlocked(ec, &value)))
577 list_for_each_entry(handler, &ec->list, node) {
595 struct acpi_ec *ec = ec_cxt;
596 if (!ec)
598 mutex_lock(&ec->lock);
599 acpi_ec_sync_query(ec);
600 mutex_unlock(&ec->lock);
603 static int ec_check_sci(struct acpi_ec *ec, u8 state)
606 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
609 acpi_ec_gpe_query, ec);
618 struct acpi_ec *ec = data;
622 advance_transaction(ec, acpi_ec_read_status(ec));
623 if (ec_transaction_done(ec) &&
624 (acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) == 0) {
625 wake_up(&ec->wait);
626 ec_check_sci(ec, acpi_ec_read_status(ec));
640 struct acpi_ec *ec = handler_context;
651 acpi_ec_burst_enable(ec);
655 acpi_ec_read(ec, address, value) :
656 acpi_ec_write(ec, address, *value);
659 acpi_ec_burst_disable(ec);
684 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
685 if (!ec)
687 ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
688 mutex_init(&ec->lock);
689 init_waitqueue_head(&ec->wait);
690 INIT_LIST_HEAD(&ec->list);
691 spin_lock_init(&ec->curr_lock);
692 return ec;
701 struct acpi_ec *ec = context;
708 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
719 struct acpi_ec *ec = context;
722 ec->command_addr = ec->data_addr = 0;
725 ec_parse_io_ports, ec);
734 ec->gpe = tmp;
738 ec->global_lock = tmp;
739 ec->handle = handle;
743 static int ec_install_handlers(struct acpi_ec *ec)
746 if (test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags))
748 status = acpi_install_gpe_handler(NULL, ec->gpe,
750 &acpi_ec_gpe_handler, ec);
754 acpi_enable_gpe(NULL, ec->gpe);
755 status = acpi_install_address_space_handler(ec->handle,
758 NULL, ec);
769 acpi_remove_gpe_handler(NULL, ec->gpe,
771 acpi_disable_gpe(NULL, ec->gpe);
776 set_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
780 static void ec_remove_handlers(struct acpi_ec *ec)
782 acpi_disable_gpe(NULL, ec->gpe);
783 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
786 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
789 clear_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
794 struct acpi_ec *ec = NULL;
804 ec = boot_ec;
807 ec = make_acpi_ec();
808 if (!ec)
811 if (ec_parse_device(device->handle, 0, ec, NULL) !=
813 kfree(ec);
818 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
819 acpi_ec_register_query_methods, NULL, ec, NULL);
822 first_ec = ec;
823 device->driver_data = ec;
825 ret = !!request_region(ec->data_addr, 1, "EC data");
826 WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr);
827 ret = !!request_region(ec->command_addr, 1, "EC cmd");
828 WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr);
831 ec->gpe, ec->command_addr, ec->data_addr);
833 ret = ec_install_handlers(ec);
836 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
842 struct acpi_ec *ec;
848 ec = acpi_driver_data(device);
849 ec_remove_handlers(ec);
850 mutex_lock(&ec->lock);
851 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
855 mutex_unlock(&ec->lock);
856 release_region(ec->data_addr, 1);
857 release_region(ec->command_addr, 1);
859 if (ec == first_ec)
861 kfree(ec);
868 struct acpi_ec *ec = context;
878 if (ec->data_addr == 0)
879 ec->data_addr = resource->data.io.minimum;
880 else if (ec->command_addr == 0)
881 ec->command_addr = resource->data.io.minimum;
972 * Generate a boot ec context
1039 .name = "ec",