ACPI: EC: Rename some variables
No functional changes. Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de> Acked-by: Rafael J. Wysocki <rjw@suse.com> Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
parent
7c6db4e050
commit
8463200a00
|
@ -95,10 +95,11 @@ struct acpi_ec_query_handler {
|
||||||
u8 query_bit;
|
u8 query_bit;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct transaction_data {
|
struct transaction {
|
||||||
const u8 *wdata;
|
const u8 *wdata;
|
||||||
u8 *rdata;
|
u8 *rdata;
|
||||||
unsigned short irq_count;
|
unsigned short irq_count;
|
||||||
|
u8 command;
|
||||||
u8 wlen;
|
u8 wlen;
|
||||||
u8 rlen;
|
u8 rlen;
|
||||||
};
|
};
|
||||||
|
@ -113,8 +114,8 @@ static struct acpi_ec {
|
||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
wait_queue_head_t wait;
|
wait_queue_head_t wait;
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
struct transaction_data *t;
|
struct transaction *curr;
|
||||||
spinlock_t t_lock;
|
spinlock_t curr_lock;
|
||||||
} *boot_ec, *first_ec;
|
} *boot_ec, *first_ec;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -176,37 +177,37 @@ static int ec_transaction_done(struct acpi_ec *ec)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
spin_lock_irqsave(&ec->t_lock, flags);
|
spin_lock_irqsave(&ec->curr_lock, flags);
|
||||||
if (!ec->t || (!ec->t->wlen && !ec->t->rlen))
|
if (!ec->curr || (!ec->curr->wlen && !ec->curr->rlen))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
spin_unlock_irqrestore(&ec->t_lock, flags);
|
spin_unlock_irqrestore(&ec->curr_lock, flags);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gpe_transaction(struct acpi_ec *ec, u8 status)
|
static void gpe_transaction(struct acpi_ec *ec, u8 status)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
spin_lock_irqsave(&ec->t_lock, flags);
|
spin_lock_irqsave(&ec->curr_lock, flags);
|
||||||
if (!ec->t)
|
if (!ec->curr)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
if (ec->t->wlen > 0) {
|
if (ec->curr->wlen > 0) {
|
||||||
if ((status & ACPI_EC_FLAG_IBF) == 0) {
|
if ((status & ACPI_EC_FLAG_IBF) == 0) {
|
||||||
acpi_ec_write_data(ec, *(ec->t->wdata++));
|
acpi_ec_write_data(ec, *(ec->curr->wdata++));
|
||||||
--ec->t->wlen;
|
--ec->curr->wlen;
|
||||||
} else
|
} else
|
||||||
/* false interrupt, state didn't change */
|
/* false interrupt, state didn't change */
|
||||||
++ec->t->irq_count;
|
++ec->curr->irq_count;
|
||||||
|
|
||||||
} else if (ec->t->rlen > 0) {
|
} else if (ec->curr->rlen > 0) {
|
||||||
if ((status & ACPI_EC_FLAG_OBF) == 1) {
|
if ((status & ACPI_EC_FLAG_OBF) == 1) {
|
||||||
*(ec->t->rdata++) = acpi_ec_read_data(ec);
|
*(ec->curr->rdata++) = acpi_ec_read_data(ec);
|
||||||
--ec->t->rlen;
|
--ec->curr->rlen;
|
||||||
} else
|
} else
|
||||||
/* false interrupt, state didn't change */
|
/* false interrupt, state didn't change */
|
||||||
++ec->t->irq_count;
|
++ec->curr->irq_count;
|
||||||
}
|
}
|
||||||
unlock:
|
unlock:
|
||||||
spin_unlock_irqrestore(&ec->t_lock, flags);
|
spin_unlock_irqrestore(&ec->curr_lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acpi_ec_wait(struct acpi_ec *ec)
|
static int acpi_ec_wait(struct acpi_ec *ec)
|
||||||
|
@ -248,15 +249,11 @@ static int ec_poll(struct acpi_ec *ec)
|
||||||
return -ETIME;
|
return -ETIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
|
static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
|
||||||
const u8 * wdata, unsigned wdata_len,
|
struct transaction *t,
|
||||||
u8 * rdata, unsigned rdata_len,
|
|
||||||
int force_poll)
|
int force_poll)
|
||||||
{
|
{
|
||||||
unsigned long tmp;
|
unsigned long tmp;
|
||||||
struct transaction_data t = {.wdata = wdata, .rdata = rdata,
|
|
||||||
.wlen = wdata_len, .rlen = rdata_len,
|
|
||||||
.irq_count = 0};
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
pr_debug(PREFIX "transaction start\n");
|
pr_debug(PREFIX "transaction start\n");
|
||||||
/* disable GPE during transaction if storm is detected */
|
/* disable GPE during transaction if storm is detected */
|
||||||
|
@ -265,29 +262,30 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
|
||||||
acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
|
acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
|
||||||
}
|
}
|
||||||
/* start transaction */
|
/* start transaction */
|
||||||
spin_lock_irqsave(&ec->t_lock, tmp);
|
spin_lock_irqsave(&ec->curr_lock, tmp);
|
||||||
/* following two actions should be kept atomic */
|
/* following two actions should be kept atomic */
|
||||||
ec->t = &t;
|
t->irq_count = 0;
|
||||||
acpi_ec_write_cmd(ec, command);
|
ec->curr = t;
|
||||||
if (command == ACPI_EC_COMMAND_QUERY)
|
acpi_ec_write_cmd(ec, ec->curr->command);
|
||||||
|
if (ec->curr->command == ACPI_EC_COMMAND_QUERY)
|
||||||
clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
|
clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
|
||||||
spin_unlock_irqrestore(&ec->t_lock, tmp);
|
spin_unlock_irqrestore(&ec->curr_lock, tmp);
|
||||||
/* if we selected poll mode or failed in GPE-mode do a poll loop */
|
/* if we selected poll mode or failed in GPE-mode do a poll loop */
|
||||||
if (force_poll ||
|
if (force_poll ||
|
||||||
!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) ||
|
!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) ||
|
||||||
acpi_ec_wait(ec))
|
acpi_ec_wait(ec))
|
||||||
ret = ec_poll(ec);
|
ret = ec_poll(ec);
|
||||||
pr_debug(PREFIX "transaction end\n");
|
pr_debug(PREFIX "transaction end\n");
|
||||||
spin_lock_irqsave(&ec->t_lock, tmp);
|
spin_lock_irqsave(&ec->curr_lock, tmp);
|
||||||
ec->t = NULL;
|
ec->curr = NULL;
|
||||||
spin_unlock_irqrestore(&ec->t_lock, tmp);
|
spin_unlock_irqrestore(&ec->curr_lock, tmp);
|
||||||
if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
|
if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
|
||||||
/* check if we received SCI during transaction */
|
/* check if we received SCI during transaction */
|
||||||
ec_check_sci(ec, acpi_ec_read_status(ec));
|
ec_check_sci(ec, acpi_ec_read_status(ec));
|
||||||
/* it is safe to enable GPE outside of transaction */
|
/* it is safe to enable GPE outside of transaction */
|
||||||
acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
|
acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
|
||||||
} else if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
|
} else if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
|
||||||
t.irq_count > ACPI_EC_STORM_THRESHOLD) {
|
t->irq_count > ACPI_EC_STORM_THRESHOLD) {
|
||||||
pr_debug(PREFIX "GPE storm detected\n");
|
pr_debug(PREFIX "GPE storm detected\n");
|
||||||
set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
|
set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
|
||||||
}
|
}
|
||||||
|
@ -300,17 +298,15 @@ static int ec_check_ibf0(struct acpi_ec *ec)
|
||||||
return (status & ACPI_EC_FLAG_IBF) == 0;
|
return (status & ACPI_EC_FLAG_IBF) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
|
static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t,
|
||||||
const u8 * wdata, unsigned wdata_len,
|
|
||||||
u8 * rdata, unsigned rdata_len,
|
|
||||||
int force_poll)
|
int force_poll)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
u32 glk;
|
u32 glk;
|
||||||
if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
|
if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (rdata)
|
if (t->rdata)
|
||||||
memset(rdata, 0, rdata_len);
|
memset(t->rdata, 0, t->rlen);
|
||||||
mutex_lock(&ec->lock);
|
mutex_lock(&ec->lock);
|
||||||
if (ec->global_lock) {
|
if (ec->global_lock) {
|
||||||
status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
|
status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
|
||||||
|
@ -326,10 +322,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
|
||||||
status = -ETIME;
|
status = -ETIME;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
status = acpi_ec_transaction_unlocked(ec, command,
|
status = acpi_ec_transaction_unlocked(ec, t, force_poll);
|
||||||
wdata, wdata_len,
|
|
||||||
rdata, rdata_len,
|
|
||||||
force_poll);
|
|
||||||
end:
|
end:
|
||||||
if (ec->global_lock)
|
if (ec->global_lock)
|
||||||
acpi_release_global_lock(glk);
|
acpi_release_global_lock(glk);
|
||||||
|
@ -345,23 +338,32 @@ unlock:
|
||||||
int acpi_ec_burst_enable(struct acpi_ec *ec)
|
int acpi_ec_burst_enable(struct acpi_ec *ec)
|
||||||
{
|
{
|
||||||
u8 d;
|
u8 d;
|
||||||
return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0);
|
struct transaction t = {.command = ACPI_EC_BURST_ENABLE,
|
||||||
|
.wdata = NULL, .rdata = &d,
|
||||||
|
.wlen = 0, .rlen = 1};
|
||||||
|
|
||||||
|
return acpi_ec_transaction(ec, &t, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int acpi_ec_burst_disable(struct acpi_ec *ec)
|
int acpi_ec_burst_disable(struct acpi_ec *ec)
|
||||||
{
|
{
|
||||||
|
struct transaction t = {.command = ACPI_EC_BURST_DISABLE,
|
||||||
|
.wdata = NULL, .rdata = NULL,
|
||||||
|
.wlen = 0, .rlen = 0};
|
||||||
|
|
||||||
return (acpi_ec_read_status(ec) & ACPI_EC_FLAG_BURST) ?
|
return (acpi_ec_read_status(ec) & ACPI_EC_FLAG_BURST) ?
|
||||||
acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE,
|
acpi_ec_transaction(ec, &t, 0) : 0;
|
||||||
NULL, 0, NULL, 0, 0) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
|
static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
u8 d;
|
u8 d;
|
||||||
|
struct transaction t = {.command = ACPI_EC_COMMAND_READ,
|
||||||
|
.wdata = &address, .rdata = &d,
|
||||||
|
.wlen = 1, .rlen = 1};
|
||||||
|
|
||||||
result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
|
result = acpi_ec_transaction(ec, &t, 0);
|
||||||
&address, 1, &d, 1, 0);
|
|
||||||
*data = d;
|
*data = d;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -369,8 +371,11 @@ static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
|
||||||
static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
|
static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
|
||||||
{
|
{
|
||||||
u8 wdata[2] = { address, data };
|
u8 wdata[2] = { address, data };
|
||||||
return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
|
struct transaction t = {.command = ACPI_EC_COMMAND_WRITE,
|
||||||
wdata, 2, NULL, 0, 0);
|
.wdata = wdata, .rdata = NULL,
|
||||||
|
.wlen = 2, .rlen = 0};
|
||||||
|
|
||||||
|
return acpi_ec_transaction(ec, &t, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -432,12 +437,13 @@ int ec_transaction(u8 command,
|
||||||
u8 * rdata, unsigned rdata_len,
|
u8 * rdata, unsigned rdata_len,
|
||||||
int force_poll)
|
int force_poll)
|
||||||
{
|
{
|
||||||
|
struct transaction t = {.command = command,
|
||||||
|
.wdata = wdata, .rdata = rdata,
|
||||||
|
.wlen = wdata_len, .rlen = rdata_len};
|
||||||
if (!first_ec)
|
if (!first_ec)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
return acpi_ec_transaction(first_ec, command, wdata,
|
return acpi_ec_transaction(first_ec, &t, force_poll);
|
||||||
wdata_len, rdata, rdata_len,
|
|
||||||
force_poll);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_SYMBOL(ec_transaction);
|
EXPORT_SYMBOL(ec_transaction);
|
||||||
|
@ -446,7 +452,9 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
u8 d;
|
u8 d;
|
||||||
|
struct transaction t = {.command = ACPI_EC_COMMAND_QUERY,
|
||||||
|
.wdata = NULL, .rdata = &d,
|
||||||
|
.wlen = 0, .rlen = 1};
|
||||||
if (!ec || !data)
|
if (!ec || !data)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
@ -456,7 +464,7 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
|
||||||
* bit to be cleared (and thus clearing the interrupt source).
|
* bit to be cleared (and thus clearing the interrupt source).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0);
|
result = acpi_ec_transaction(ec, &t, 0);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
@ -696,7 +704,7 @@ static struct acpi_ec *make_acpi_ec(void)
|
||||||
mutex_init(&ec->lock);
|
mutex_init(&ec->lock);
|
||||||
init_waitqueue_head(&ec->wait);
|
init_waitqueue_head(&ec->wait);
|
||||||
INIT_LIST_HEAD(&ec->list);
|
INIT_LIST_HEAD(&ec->list);
|
||||||
spin_lock_init(&ec->t_lock);
|
spin_lock_init(&ec->curr_lock);
|
||||||
return ec;
|
return ec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue