mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-09 17:11:42 +00:00
gpio: Add function to clear pending interrupt
Currently if an interrupt is pending before it is enabled the interrupt will fire immediately. In most cases this is fine, but if we want to use the interrupt to trigger something like waking the AP it should be sure that it won't immediately fire once enabled. For example: on the Eve board we have the trackpad interrupt run to the AP and the EC in order to support wake from Deep S3 (magic AP state that only the EC can wake it from). This interrupt is used in S0 by the AP while ignored by the EC, and then enabled on the transition to S3 in order to be able to wake. Since it has been active the interrupt may be pending in the EC (depending on the chip), which can result in the interrupt firing immediately and waking the AP. BUG=chrome-os-partner:62224 BRANCH=none TEST=This has been functionally tested on npcx only as that is what I have a use case and system for, the others compile and look right but have not been directly tested. Change-Id: I9e0877d99e7f09f4c30bf9861fbad81c12c059ad Signed-off-by: Duncan Laurie <dlaurie@google.com> Reviewed-on: https://chromium-review.googlesource.com/446962 Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
850a227aea
commit
6e157818c1
@@ -256,6 +256,13 @@ int gpio_disable_interrupt(enum gpio_signal signal)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int gpio_clear_pending_interrupt(enum gpio_signal signal)
|
||||
{
|
||||
const struct gpio_info *g = gpio_list + signal;
|
||||
GR_GPIO_CLRINTSTAT(g->port) = g->mask;
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
void gpio_pre_init(void)
|
||||
{
|
||||
const struct gpio_info *g = gpio_list;
|
||||
|
||||
@@ -60,6 +60,11 @@ test_mockable int gpio_enable_interrupt(enum gpio_signal signal)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
test_mockable int gpio_clear_pending_interrupt(enum gpio_signal signal)
|
||||
{
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
test_mockable void gpio_set_flags_by_mask(uint32_t port, uint32_t mask,
|
||||
uint32_t flags)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,6 @@ void lpcrst_interrupt(enum gpio_signal signal);
|
||||
void peci_interrupt(void);
|
||||
void adc_interrupt(void);
|
||||
void i2c_interrupt(int port);
|
||||
int gpio_clear_pending_interrupt(enum gpio_signal signal);
|
||||
void clock_sleep_mode_wakeup_isr(void);
|
||||
int clock_ec_wake_from_sleep(void);
|
||||
void __enter_hibernate(uint32_t seconds, uint32_t microseconds);
|
||||
|
||||
@@ -170,6 +170,18 @@ int gpio_disable_interrupt(enum gpio_signal signal)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int gpio_clear_pending_interrupt(enum gpio_signal signal)
|
||||
{
|
||||
const struct gpio_info *g = gpio_list + signal;
|
||||
|
||||
/* Fail if no interrupt handler */
|
||||
if (signal >= GPIO_IH_COUNT)
|
||||
return EC_ERROR_INVAL;
|
||||
|
||||
LM4_GPIO_ICR(g->port) |= g->mask;
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LOW_POWER_IDLE
|
||||
/**
|
||||
* Convert GPIO port to a mask that can be used to set the
|
||||
|
||||
@@ -173,6 +173,24 @@ int gpio_disable_interrupt(enum gpio_signal signal)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int gpio_clear_pending_interrupt(enum gpio_signal signal)
|
||||
{
|
||||
int i, port, girq_id, bit_id;
|
||||
|
||||
if (gpio_list[signal].mask == 0)
|
||||
return EC_SUCCESS;
|
||||
|
||||
i = GPIO_MASK_TO_NUM(gpio_list[signal].mask);
|
||||
port = gpio_list[signal].port;
|
||||
girq_id = int_map[port].girq_id;
|
||||
bit_id = (port - int_map[port].port_offset) * 8 + i;
|
||||
|
||||
/* Clear interrupt source sticky status bit even if not enabled */
|
||||
MEC1322_INT_SOURCE(girq_id) |= 1 << bit_id;
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
void gpio_pre_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -669,6 +669,20 @@ int gpio_disable_interrupt(enum gpio_signal signal)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int gpio_clear_pending_interrupt(enum gpio_signal signal)
|
||||
{
|
||||
const struct gpio_info *g = gpio_list + signal;
|
||||
struct gpio_wui_gpio_info wui = gpio_find_wui_from_io(g->port, g->mask);
|
||||
|
||||
/* Clear pending interrupt for this signal */
|
||||
if (wui.valid)
|
||||
NPCX_WKPCL(wui.table, wui.group) |= (1 << wui.bit);
|
||||
else
|
||||
return EC_ERROR_PARAM1;
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
void gpio_pre_init(void)
|
||||
{
|
||||
const struct gpio_info *g = gpio_list;
|
||||
|
||||
@@ -98,6 +98,18 @@ int gpio_enable_interrupt(enum gpio_signal signal)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int gpio_clear_pending_interrupt(enum gpio_signal signal)
|
||||
{
|
||||
const struct gpio_info *g = gpio_list + signal;
|
||||
|
||||
if (!g->mask || signal >= GPIO_IH_COUNT)
|
||||
return EC_ERROR_INVAL;
|
||||
|
||||
STM32_EXTI_PR |= g->mask;
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Interrupt handler */
|
||||
|
||||
|
||||
@@ -215,6 +215,16 @@ int gpio_enable_interrupt(enum gpio_signal signal);
|
||||
*/
|
||||
int gpio_disable_interrupt(enum gpio_signal signal);
|
||||
|
||||
/**
|
||||
* Clear pending interrupts for the signal.
|
||||
*
|
||||
* The signal must have been defined with an interrupt handler.
|
||||
*
|
||||
* @param signal Signal to clear interrupts for
|
||||
* @return EC_SUCCESS, or non-zero on error.
|
||||
*/
|
||||
int gpio_clear_pending_interrupt(enum gpio_signal signal);
|
||||
|
||||
/**
|
||||
* Set flags for GPIO(s) by port and mask.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user