Commit 080e412c authored by Alexey Starikovskiy's avatar Alexey Starikovskiy Committed by Len Brown

ACPI: EC: Replace atomic variables with bits

Number of flags is about to be increased, so it is better to
put them all into bits.
No functional changes.
Signed-off-by: default avatarAlexey Starikovskiy <astarikovskiy@suse.de>
Acked-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 23de5d9e
...@@ -65,7 +65,7 @@ enum ec_command { ...@@ -65,7 +65,7 @@ enum ec_command {
/* EC events */ /* EC events */
enum ec_event { enum ec_event {
ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
ACPI_EC_EVENT_IBF_0, /* Input buffer empty */ ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
}; };
#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
...@@ -76,6 +76,11 @@ static enum ec_mode { ...@@ -76,6 +76,11 @@ static enum ec_mode {
EC_POLL, /* Input buffer empty */ EC_POLL, /* Input buffer empty */
} acpi_ec_mode = EC_INTR; } acpi_ec_mode = EC_INTR;
enum {
EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */
EC_FLAGS_QUERY_PENDING, /* Query is pending */
};
static int acpi_ec_remove(struct acpi_device *device, int type); static int acpi_ec_remove(struct acpi_device *device, int type);
static int acpi_ec_start(struct acpi_device *device); static int acpi_ec_start(struct acpi_device *device);
static int acpi_ec_stop(struct acpi_device *device, int type); static int acpi_ec_stop(struct acpi_device *device, int type);
...@@ -116,9 +121,8 @@ static struct acpi_ec { ...@@ -116,9 +121,8 @@ static struct acpi_ec {
unsigned long command_addr; unsigned long command_addr;
unsigned long data_addr; unsigned long data_addr;
unsigned long global_lock; unsigned long global_lock;
unsigned long flags;
struct mutex lock; struct mutex lock;
atomic_t query_pending;
atomic_t event_count;
wait_queue_head_t wait; wait_queue_head_t wait;
struct list_head list; struct list_head list;
u8 handlers_installed; u8 handlers_installed;
...@@ -148,45 +152,42 @@ static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) ...@@ -148,45 +152,42 @@ static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
outb(data, ec->data_addr); outb(data, ec->data_addr);
} }
static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event, static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
unsigned old_count)
{ {
u8 status = acpi_ec_read_status(ec); if (test_bit(EC_FLAGS_WAIT_GPE, &ec->flags))
if (old_count == atomic_read(&ec->event_count))
return 0; return 0;
if (event == ACPI_EC_EVENT_OBF_1) { if (event == ACPI_EC_EVENT_OBF_1) {
if (status & ACPI_EC_FLAG_OBF) if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
return 1; return 1;
} else if (event == ACPI_EC_EVENT_IBF_0) { } else if (event == ACPI_EC_EVENT_IBF_0) {
if (!(status & ACPI_EC_FLAG_IBF)) if (!(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF))
return 1; return 1;
} }
return 0; return 0;
} }
static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
unsigned count, int force_poll)
{ {
if (unlikely(force_poll) || acpi_ec_mode == EC_POLL) { if (unlikely(force_poll) || acpi_ec_mode == EC_POLL) {
unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
while (time_before(jiffies, delay)) { while (time_before(jiffies, delay)) {
if (acpi_ec_check_status(ec, event, 0)) if (acpi_ec_check_status(ec, event))
return 0; return 0;
} }
} else { } else {
if (wait_event_timeout(ec->wait, if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
acpi_ec_check_status(ec, event, count), msecs_to_jiffies(ACPI_EC_DELAY)))
msecs_to_jiffies(ACPI_EC_DELAY)) || return 0;
acpi_ec_check_status(ec, event, 0)) { clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
if (acpi_ec_check_status(ec, event)) {
return 0; return 0;
} else {
printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
" status = %d, expect_event = %d\n",
acpi_ec_read_status(ec), event);
} }
} }
printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
" status = %d, expect_event = %d\n",
acpi_ec_read_status(ec), event);
return -ETIME; return -ETIME;
} }
...@@ -196,39 +197,38 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, ...@@ -196,39 +197,38 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
int force_poll) int force_poll)
{ {
int result = 0; int result = 0;
unsigned count = atomic_read(&ec->event_count); set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
acpi_ec_write_cmd(ec, command); acpi_ec_write_cmd(ec, command);
for (; wdata_len > 0; --wdata_len) { for (; wdata_len > 0; --wdata_len) {
result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll); result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
if (result) { if (result) {
printk(KERN_ERR PREFIX printk(KERN_ERR PREFIX
"write_cmd timeout, command = %d\n", command); "write_cmd timeout, command = %d\n", command);
goto end; goto end;
} }
count = atomic_read(&ec->event_count); set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
acpi_ec_write_data(ec, *(wdata++)); acpi_ec_write_data(ec, *(wdata++));
} }
if (!rdata_len) { if (!rdata_len) {
result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll); result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
if (result) { if (result) {
printk(KERN_ERR PREFIX printk(KERN_ERR PREFIX
"finish-write timeout, command = %d\n", command); "finish-write timeout, command = %d\n", command);
goto end; goto end;
} }
} else if (command == ACPI_EC_COMMAND_QUERY) { } else if (command == ACPI_EC_COMMAND_QUERY)
atomic_set(&ec->query_pending, 0); clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
}
for (; rdata_len > 0; --rdata_len) { for (; rdata_len > 0; --rdata_len) {
result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count, force_poll); result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
if (result) { if (result) {
printk(KERN_ERR PREFIX "read timeout, command = %d\n", printk(KERN_ERR PREFIX "read timeout, command = %d\n",
command); command);
goto end; goto end;
} }
count = atomic_read(&ec->event_count); set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
*(rdata++) = acpi_ec_read_data(ec); *(rdata++) = acpi_ec_read_data(ec);
} }
end: end:
...@@ -261,7 +261,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, ...@@ -261,7 +261,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
/* Make sure GPE is enabled before doing transaction */ /* Make sure GPE is enabled before doing transaction */
acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0); status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
if (status) { if (status) {
printk(KERN_ERR PREFIX printk(KERN_ERR PREFIX
"input buffer is not empty, aborting transaction\n"); "input buffer is not empty, aborting transaction\n");
...@@ -476,20 +476,18 @@ static void acpi_ec_gpe_query(void *ec_cxt) ...@@ -476,20 +476,18 @@ static void acpi_ec_gpe_query(void *ec_cxt)
static u32 acpi_ec_gpe_handler(void *data) static u32 acpi_ec_gpe_handler(void *data)
{ {
acpi_status status = AE_OK; acpi_status status = AE_OK;
u8 value;
struct acpi_ec *ec = data; struct acpi_ec *ec = data;
atomic_inc(&ec->event_count); clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
if (acpi_ec_mode == EC_INTR) { if (acpi_ec_mode == EC_INTR) {
wake_up(&ec->wait); wake_up(&ec->wait);
} }
value = acpi_ec_read_status(ec); if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) {
if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) { if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
atomic_set(&ec->query_pending, 1); status = acpi_os_execute(OSL_EC_BURST_HANDLER,
status = acpi_ec_gpe_query, ec);
acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec);
} }
return status == AE_OK ? return status == AE_OK ?
...@@ -642,8 +640,7 @@ static struct acpi_ec *make_acpi_ec(void) ...@@ -642,8 +640,7 @@ static struct acpi_ec *make_acpi_ec(void)
if (!ec) if (!ec)
return NULL; return NULL;
atomic_set(&ec->query_pending, 1); ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
atomic_set(&ec->event_count, 1);
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);
...@@ -833,7 +830,7 @@ static int acpi_ec_start(struct acpi_device *device) ...@@ -833,7 +830,7 @@ static int acpi_ec_start(struct acpi_device *device)
ret = ec_install_handlers(ec); ret = ec_install_handlers(ec);
/* EC is fully operational, allow queries */ /* EC is fully operational, allow queries */
atomic_set(&ec->query_pending, 0); clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment