Commit d1876ba4 authored by Len Brown's avatar Len Brown

Merge branch 'ec' into release

parents 547f7847 8517934e
...@@ -478,7 +478,7 @@ static int acpi_button_add(struct acpi_device *device) ...@@ -478,7 +478,7 @@ static int acpi_button_add(struct acpi_device *device)
device->wakeup.gpe_number, device->wakeup.gpe_number,
ACPI_GPE_TYPE_WAKE_RUN); ACPI_GPE_TYPE_WAKE_RUN);
acpi_enable_gpe(device->wakeup.gpe_device, acpi_enable_gpe(device->wakeup.gpe_device,
device->wakeup.gpe_number, ACPI_NOT_ISR); device->wakeup.gpe_number);
device->wakeup.state.enabled = 1; device->wakeup.state.enabled = 1;
} }
......
...@@ -70,7 +70,7 @@ enum ec_command { ...@@ -70,7 +70,7 @@ enum ec_command {
#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
#define ACPI_EC_UDELAY 100 /* Wait 100us before polling EC again */ #define ACPI_EC_UDELAY 100 /* Wait 100us before polling EC again */
#define ACPI_EC_STORM_THRESHOLD 20 /* number of false interrupts #define ACPI_EC_STORM_THRESHOLD 8 /* number of false interrupts
per one transaction */ per one transaction */
enum { enum {
...@@ -100,8 +100,11 @@ struct transaction { ...@@ -100,8 +100,11 @@ struct transaction {
u8 *rdata; u8 *rdata;
unsigned short irq_count; unsigned short irq_count;
u8 command; u8 command;
u8 wi;
u8 ri;
u8 wlen; u8 wlen;
u8 rlen; u8 rlen;
bool done;
}; };
static struct acpi_ec { static struct acpi_ec {
...@@ -178,34 +181,45 @@ static int ec_transaction_done(struct acpi_ec *ec) ...@@ -178,34 +181,45 @@ 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->curr_lock, flags); spin_lock_irqsave(&ec->curr_lock, flags);
if (!ec->curr || (!ec->curr->wlen && !ec->curr->rlen)) if (!ec->curr || ec->curr->done)
ret = 1; ret = 1;
spin_unlock_irqrestore(&ec->curr_lock, flags); spin_unlock_irqrestore(&ec->curr_lock, flags);
return ret; return ret;
} }
static void start_transaction(struct acpi_ec *ec)
{
ec->curr->irq_count = ec->curr->wi = ec->curr->ri = 0;
ec->curr->done = false;
acpi_ec_write_cmd(ec, ec->curr->command);
}
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->curr_lock, flags); spin_lock_irqsave(&ec->curr_lock, flags);
if (!ec->curr) if (!ec->curr)
goto unlock; goto unlock;
if (ec->curr->wlen > 0) { if (ec->curr->wlen > ec->curr->wi) {
if ((status & ACPI_EC_FLAG_IBF) == 0) { if ((status & ACPI_EC_FLAG_IBF) == 0)
acpi_ec_write_data(ec, *(ec->curr->wdata++)); acpi_ec_write_data(ec,
--ec->curr->wlen; ec->curr->wdata[ec->curr->wi++]);
} else else
/* false interrupt, state didn't change */ goto err;
++ec->curr->irq_count; } else if (ec->curr->rlen > ec->curr->ri) {
} else if (ec->curr->rlen > 0) {
if ((status & ACPI_EC_FLAG_OBF) == 1) { if ((status & ACPI_EC_FLAG_OBF) == 1) {
*(ec->curr->rdata++) = acpi_ec_read_data(ec); ec->curr->rdata[ec->curr->ri++] = acpi_ec_read_data(ec);
--ec->curr->rlen; if (ec->curr->rlen == ec->curr->ri)
ec->curr->done = true;
} else } else
/* false interrupt, state didn't change */ goto err;
++ec->curr->irq_count; } else if (ec->curr->wlen == ec->curr->wi &&
} (status & ACPI_EC_FLAG_IBF) == 0)
ec->curr->done = true;
goto unlock;
err:
/* false interrupt, state didn't change */
++ec->curr->irq_count;
unlock: unlock:
spin_unlock_irqrestore(&ec->curr_lock, flags); spin_unlock_irqrestore(&ec->curr_lock, flags);
} }
...@@ -215,6 +229,15 @@ static int acpi_ec_wait(struct acpi_ec *ec) ...@@ -215,6 +229,15 @@ static int acpi_ec_wait(struct acpi_ec *ec)
if (wait_event_timeout(ec->wait, ec_transaction_done(ec), if (wait_event_timeout(ec->wait, ec_transaction_done(ec),
msecs_to_jiffies(ACPI_EC_DELAY))) msecs_to_jiffies(ACPI_EC_DELAY)))
return 0; return 0;
/* try restart command if we get any false interrupts */
if (ec->curr->irq_count &&
(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) == 0) {
pr_debug(PREFIX "controller reset, restart transaction\n");
start_transaction(ec);
if (wait_event_timeout(ec->wait, ec_transaction_done(ec),
msecs_to_jiffies(ACPI_EC_DELAY)))
return 0;
}
/* missing GPEs, switch back to poll mode */ /* missing GPEs, switch back to poll mode */
if (printk_ratelimit()) if (printk_ratelimit())
pr_info(PREFIX "missing confirmations, " pr_info(PREFIX "missing confirmations, "
...@@ -239,10 +262,10 @@ static int ec_check_sci(struct acpi_ec *ec, u8 state) ...@@ -239,10 +262,10 @@ static int ec_check_sci(struct acpi_ec *ec, u8 state)
static int ec_poll(struct acpi_ec *ec) static int ec_poll(struct acpi_ec *ec)
{ {
unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
msleep(1); udelay(ACPI_EC_UDELAY);
while (time_before(jiffies, delay)) { while (time_before(jiffies, delay)) {
gpe_transaction(ec, acpi_ec_read_status(ec)); gpe_transaction(ec, acpi_ec_read_status(ec));
msleep(1); udelay(ACPI_EC_UDELAY);
if (ec_transaction_done(ec)) if (ec_transaction_done(ec))
return 0; return 0;
} }
...@@ -259,14 +282,13 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, ...@@ -259,14 +282,13 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
/* disable GPE during transaction if storm is detected */ /* disable GPE during transaction if storm is detected */
if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) { if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); acpi_disable_gpe(NULL, ec->gpe);
} }
/* start transaction */ /* start transaction */
spin_lock_irqsave(&ec->curr_lock, tmp); spin_lock_irqsave(&ec->curr_lock, tmp);
/* following two actions should be kept atomic */ /* following two actions should be kept atomic */
t->irq_count = 0;
ec->curr = t; ec->curr = t;
acpi_ec_write_cmd(ec, ec->curr->command); start_transaction(ec);
if (ec->curr->command == ACPI_EC_COMMAND_QUERY) 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->curr_lock, tmp); spin_unlock_irqrestore(&ec->curr_lock, tmp);
...@@ -283,10 +305,11 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, ...@@ -283,10 +305,11 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
/* 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);
} 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_info(PREFIX "GPE storm detected, "
"transactions will use polling mode\n");
set_bit(EC_FLAGS_GPE_STORM, &ec->flags); set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
} }
return ret; return ret;
...@@ -558,17 +581,26 @@ static u32 acpi_ec_gpe_handler(void *data) ...@@ -558,17 +581,26 @@ static u32 acpi_ec_gpe_handler(void *data)
pr_debug(PREFIX "~~~> interrupt\n"); pr_debug(PREFIX "~~~> interrupt\n");
status = acpi_ec_read_status(ec); status = acpi_ec_read_status(ec);
gpe_transaction(ec, status); if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) {
if (ec_transaction_done(ec) && (status & ACPI_EC_FLAG_IBF) == 0) gpe_transaction(ec, status);
wake_up(&ec->wait); if (ec_transaction_done(ec) &&
(status & ACPI_EC_FLAG_IBF) == 0)
wake_up(&ec->wait);
}
ec_check_sci(ec, status); ec_check_sci(ec, status);
if (!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) && if (!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
!test_bit(EC_FLAGS_NO_GPE, &ec->flags)) { !test_bit(EC_FLAGS_NO_GPE, &ec->flags)) {
/* this is non-query, must be confirmation */ /* this is non-query, must be confirmation */
if (printk_ratelimit()) if (!test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
pr_info(PREFIX "non-query interrupt received," if (printk_ratelimit())
pr_info(PREFIX "non-query interrupt received,"
" switching to interrupt mode\n");
} else {
/* hush, STORM switches the mode every transaction */
pr_debug(PREFIX "non-query interrupt received,"
" switching to interrupt mode\n"); " switching to interrupt mode\n");
}
set_bit(EC_FLAGS_GPE_MODE, &ec->flags); set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
} }
return ACPI_INTERRUPT_HANDLED; return ACPI_INTERRUPT_HANDLED;
...@@ -869,7 +901,7 @@ static int ec_install_handlers(struct acpi_ec *ec) ...@@ -869,7 +901,7 @@ static int ec_install_handlers(struct acpi_ec *ec)
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENODEV; return -ENODEV;
acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME); acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); acpi_enable_gpe(NULL, ec->gpe);
status = acpi_install_address_space_handler(ec->handle, status = acpi_install_address_space_handler(ec->handle,
ACPI_ADR_SPACE_EC, ACPI_ADR_SPACE_EC,
&acpi_ec_space_handler, &acpi_ec_space_handler,
...@@ -1008,7 +1040,7 @@ static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state) ...@@ -1008,7 +1040,7 @@ static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state)
/* Stop using GPE */ /* Stop using GPE */
set_bit(EC_FLAGS_NO_GPE, &ec->flags); set_bit(EC_FLAGS_NO_GPE, &ec->flags);
clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); acpi_disable_gpe(NULL, ec->gpe);
return 0; return 0;
} }
...@@ -1017,7 +1049,7 @@ static int acpi_ec_resume(struct acpi_device *device) ...@@ -1017,7 +1049,7 @@ static int acpi_ec_resume(struct acpi_device *device)
struct acpi_ec *ec = acpi_driver_data(device); struct acpi_ec *ec = acpi_driver_data(device);
/* Enable use of GPE back */ /* Enable use of GPE back */
clear_bit(EC_FLAGS_NO_GPE, &ec->flags); clear_bit(EC_FLAGS_NO_GPE, &ec->flags);
acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); acpi_enable_gpe(NULL, ec->gpe);
return 0; return 0;
} }
......
...@@ -248,21 +248,15 @@ ACPI_EXPORT_SYMBOL(acpi_set_gpe_type) ...@@ -248,21 +248,15 @@ ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
* DESCRIPTION: Enable an ACPI event (general purpose) * DESCRIPTION: Enable an ACPI event (general purpose)
* *
******************************************************************************/ ******************************************************************************/
acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags) acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
{ {
acpi_status status = AE_OK; acpi_status status = AE_OK;
acpi_cpu_flags flags;
struct acpi_gpe_event_info *gpe_event_info; struct acpi_gpe_event_info *gpe_event_info;
ACPI_FUNCTION_TRACE(acpi_enable_gpe); ACPI_FUNCTION_TRACE(acpi_enable_gpe);
/* Use semaphore lock if not executing at interrupt level */ flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
if (flags & ACPI_NOT_ISR) {
status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
}
}
/* Ensure that we have a valid GPE number */ /* Ensure that we have a valid GPE number */
...@@ -277,9 +271,7 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags) ...@@ -277,9 +271,7 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
status = acpi_ev_enable_gpe(gpe_event_info, TRUE); status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
unlock_and_exit: unlock_and_exit:
if (flags & ACPI_NOT_ISR) { acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
}
return_ACPI_STATUS(status); return_ACPI_STATUS(status);
} }
...@@ -299,22 +291,15 @@ ACPI_EXPORT_SYMBOL(acpi_enable_gpe) ...@@ -299,22 +291,15 @@ ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
* DESCRIPTION: Disable an ACPI event (general purpose) * DESCRIPTION: Disable an ACPI event (general purpose)
* *
******************************************************************************/ ******************************************************************************/
acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags) acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
{ {
acpi_status status = AE_OK; acpi_status status = AE_OK;
acpi_cpu_flags flags;
struct acpi_gpe_event_info *gpe_event_info; struct acpi_gpe_event_info *gpe_event_info;
ACPI_FUNCTION_TRACE(acpi_disable_gpe); ACPI_FUNCTION_TRACE(acpi_disable_gpe);
/* Use semaphore lock if not executing at interrupt level */ flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
if (flags & ACPI_NOT_ISR) {
status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
}
}
/* Ensure that we have a valid GPE number */ /* Ensure that we have a valid GPE number */
gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
...@@ -325,10 +310,8 @@ acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags) ...@@ -325,10 +310,8 @@ acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
status = acpi_ev_disable_gpe(gpe_event_info); status = acpi_ev_disable_gpe(gpe_event_info);
unlock_and_exit: unlock_and_exit:
if (flags & ACPI_NOT_ISR) { acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
}
return_ACPI_STATUS(status); return_ACPI_STATUS(status);
} }
......
...@@ -88,7 +88,7 @@ void acpi_enable_wakeup_device(u8 sleep_state) ...@@ -88,7 +88,7 @@ void acpi_enable_wakeup_device(u8 sleep_state)
spin_unlock(&acpi_device_lock); spin_unlock(&acpi_device_lock);
if (!dev->wakeup.flags.run_wake) if (!dev->wakeup.flags.run_wake)
acpi_enable_gpe(dev->wakeup.gpe_device, acpi_enable_gpe(dev->wakeup.gpe_device,
dev->wakeup.gpe_number, ACPI_ISR); dev->wakeup.gpe_number);
spin_lock(&acpi_device_lock); spin_lock(&acpi_device_lock);
} }
spin_unlock(&acpi_device_lock); spin_unlock(&acpi_device_lock);
...@@ -122,7 +122,7 @@ void acpi_disable_wakeup_device(u8 sleep_state) ...@@ -122,7 +122,7 @@ void acpi_disable_wakeup_device(u8 sleep_state)
ACPI_GPE_TYPE_WAKE_RUN); ACPI_GPE_TYPE_WAKE_RUN);
/* Re-enable it, since set_gpe_type will disable it */ /* Re-enable it, since set_gpe_type will disable it */
acpi_enable_gpe(dev->wakeup.gpe_device, acpi_enable_gpe(dev->wakeup.gpe_device,
dev->wakeup.gpe_number, ACPI_NOT_ISR); dev->wakeup.gpe_number);
spin_lock(&acpi_device_lock); spin_lock(&acpi_device_lock);
} }
continue; continue;
...@@ -133,7 +133,7 @@ void acpi_disable_wakeup_device(u8 sleep_state) ...@@ -133,7 +133,7 @@ void acpi_disable_wakeup_device(u8 sleep_state)
/* Never disable run-wake GPE */ /* Never disable run-wake GPE */
if (!dev->wakeup.flags.run_wake) { if (!dev->wakeup.flags.run_wake) {
acpi_disable_gpe(dev->wakeup.gpe_device, acpi_disable_gpe(dev->wakeup.gpe_device,
dev->wakeup.gpe_number, ACPI_NOT_ISR); dev->wakeup.gpe_number);
acpi_clear_gpe(dev->wakeup.gpe_device, acpi_clear_gpe(dev->wakeup.gpe_device,
dev->wakeup.gpe_number, ACPI_NOT_ISR); dev->wakeup.gpe_number, ACPI_NOT_ISR);
} }
...@@ -162,7 +162,7 @@ static int __init acpi_wakeup_device_init(void) ...@@ -162,7 +162,7 @@ static int __init acpi_wakeup_device_init(void)
dev->wakeup.gpe_number, dev->wakeup.gpe_number,
ACPI_GPE_TYPE_WAKE_RUN); ACPI_GPE_TYPE_WAKE_RUN);
acpi_enable_gpe(dev->wakeup.gpe_device, acpi_enable_gpe(dev->wakeup.gpe_device,
dev->wakeup.gpe_number, ACPI_NOT_ISR); dev->wakeup.gpe_number);
dev->wakeup.state.enabled = 1; dev->wakeup.state.enabled = 1;
spin_lock(&acpi_device_lock); spin_lock(&acpi_device_lock);
} }
......
...@@ -398,10 +398,10 @@ static ssize_t counter_set(struct kobject *kobj, ...@@ -398,10 +398,10 @@ static ssize_t counter_set(struct kobject *kobj,
if (index < num_gpes) { if (index < num_gpes) {
if (!strcmp(buf, "disable\n") && if (!strcmp(buf, "disable\n") &&
(status & ACPI_EVENT_FLAG_ENABLED)) (status & ACPI_EVENT_FLAG_ENABLED))
result = acpi_disable_gpe(handle, index, ACPI_NOT_ISR); result = acpi_disable_gpe(handle, index);
else if (!strcmp(buf, "enable\n") && else if (!strcmp(buf, "enable\n") &&
!(status & ACPI_EVENT_FLAG_ENABLED)) !(status & ACPI_EVENT_FLAG_ENABLED))
result = acpi_enable_gpe(handle, index, ACPI_NOT_ISR); result = acpi_enable_gpe(handle, index);
else if (!strcmp(buf, "clear\n") && else if (!strcmp(buf, "clear\n") &&
(status & ACPI_EVENT_FLAG_SET)) (status & ACPI_EVENT_FLAG_SET))
result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR); result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR);
......
...@@ -252,9 +252,9 @@ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status); ...@@ -252,9 +252,9 @@ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status);
acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type); acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type);
acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags); acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number);
acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags); acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number);
acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags); acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags);
......
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