static int acpi_ec_write ( struct acpi_ec *ec, u8 address, u8 data) { int result = 0; acpi_status status = AE_OK; unsigned long flags = 0; u32 glk = 0; ACPI_FUNCTION_TRACE("acpi_ec_write"); if (!ec) return_VALUE(-EINVAL); if (ec->global_lock) { status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); if (ACPI_FAILURE(status)) return_VALUE(-ENODEV); } spin_lock_irqsave(&ec->lock, flags); acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr); result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); if (result) goto end; acpi_hw_low_level_write(8, address, &ec->data_addr); result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); if (result) goto end; acpi_hw_low_level_write(8, data, &ec->data_addr); result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); if (result) goto end; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n", data, address)); end: spin_unlock_irqrestore(&ec->lock, flags); if (ec->global_lock) acpi_release_global_lock(glk); return_VALUE(result); }
int acpi_ec_leave_burst_mode(struct acpi_ec *ec) { u8 status = 0; status = acpi_ec_read_status(ec); if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)) { status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); if (status) goto end; acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE); acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); } atomic_set(&ec->leaving_burst, 1); return 0; end: ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode")); return -1; }
static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, const u8 * wdata, unsigned wdata_len, u8 * rdata, unsigned rdata_len) { int result = 0; unsigned count = atomic_read(&ec->event_count); acpi_ec_write_cmd(ec, command); for (; wdata_len > 0; --wdata_len) { result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count); if (result) { printk(KERN_ERR PREFIX "write_cmd timeout, command = %d\n", command); goto end; } count = atomic_read(&ec->event_count); acpi_ec_write_data(ec, *(wdata++)); } if (!rdata_len) { result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count); if (result) { printk(KERN_ERR PREFIX "finish-write timeout, command = %d\n", command); goto end; } } else if (command == ACPI_EC_COMMAND_QUERY) { atomic_set(&ec->query_pending, 0); } for (; rdata_len > 0; --rdata_len) { result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count); if (result) { printk(KERN_ERR PREFIX "read timeout, command = %d\n", command); goto end; } count = atomic_read(&ec->event_count); *(rdata++) = acpi_ec_read_data(ec); } end: return result; }
/* * Note: samsung nv5000 doesn't work with ec burst mode. * http://bugzilla.kernel.org/show_bug.cgi?id=4980 */ int acpi_ec_enter_burst_mode(struct acpi_ec *ec) { u8 tmp = 0; u8 status = 0; status = acpi_ec_read_status(ec); if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); if (status) goto end; acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE); status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); tmp = acpi_ec_read_data(ec); if (tmp != 0x90) { /* Burst ACK byte */ return -EINVAL; } } atomic_set(&ec->leaving_burst, 0); return 0; end: ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode")); return -1; }
static int acpi_ec_query ( struct acpi_ec *ec, u32 *data) { int result = 0; acpi_status status = AE_OK; unsigned long flags = 0; u32 glk = 0; ACPI_FUNCTION_TRACE("acpi_ec_query"); if (!ec || !data) return_VALUE(-EINVAL); *data = 0; if (ec->global_lock) { status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); if (ACPI_FAILURE(status)) return_VALUE(-ENODEV); } /* * Query the EC to find out which _Qxx method we need to evaluate. * Note that successful completion of the query causes the ACPI_EC_SCI * bit to be cleared (and thus clearing the interrupt source). */ spin_lock_irqsave(&ec->lock, flags); acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr); result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); if (result) goto end; acpi_hw_low_level_read(8, data, &ec->data_addr); if (!*data) result = -ENODATA; end: spin_unlock_irqrestore(&ec->lock, flags); if (ec->global_lock) acpi_release_global_lock(glk); return_VALUE(result); }
static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, const u8 * wdata, unsigned wdata_len, u8 * rdata, unsigned rdata_len) { int status; u32 glk; if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) return -EINVAL; if (rdata) memset(rdata, 0, rdata_len); mutex_lock(&ec->lock); if (ec->global_lock) { status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); if (ACPI_FAILURE(status)) { mutex_unlock(&ec->lock); return -ENODEV; } } /* Make sure GPE is enabled before doing transaction */ acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0); if (status) { printk(KERN_DEBUG PREFIX "input buffer is not empty, aborting transaction\n"); goto end; } status = acpi_ec_transaction_unlocked(ec, command, wdata, wdata_len, rdata, rdata_len); end: if (ec->global_lock) acpi_release_global_lock(glk); mutex_unlock(&ec->lock); return status; }