summaryrefslogtreecommitdiff
path: root/chip/npcx/lpc.c
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@chromium.org>2017-10-09 22:02:22 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-10-17 23:14:19 -0700
commitb9e07ce1bfa42ea2a5e7564575b0072c13811c31 (patch)
tree16e69783b0b8e1825c88a2753912949dc9ef7ef8 /chip/npcx/lpc.c
parent501fba17a93c5a08afd4bdaeb9c632712557c362 (diff)
downloadchrome-ec-b9e07ce1bfa42ea2a5e7564575b0072c13811c31.tar.gz
host_event: Move host events and mask handling into common code
Instead of duplicating the handling of host events and host event masks in chip lpc drivers, add routines in common code to provide basic functions like setting/getting of masks, setting/getting of events and handling of masks transitions across sysjump. BUG=None BRANCH=None TEST=make -j buildall. Verified following: 1. Event masks are correctly retained across sysjumps. 2. Wake from S3 works fine. 3. Wake from S0ix works fine. 4. SCI generated correctly. Change-Id: Ie409f91b12788e4b902b2627e31ba5ce40ff1d27 Signed-off-by: Furquan Shaikh <furquan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/707771 Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'chip/npcx/lpc.c')
-rw-r--r--chip/npcx/lpc.c103
1 files changed, 17 insertions, 86 deletions
diff --git a/chip/npcx/lpc.c b/chip/npcx/lpc.c
index 556276dbc8..6bc07fedfb 100644
--- a/chip/npcx/lpc.c
+++ b/chip/npcx/lpc.c
@@ -35,8 +35,6 @@
#define CPRINTS(format, args...) cprints(CC_LPC, format, ## args)
#endif
-#define LPC_SYSJUMP_TAG 0x4c50 /* "LP" */
-
/* PM channel definitions */
#define PMC_ACPI PM_CHAN_1
#define PMC_HOST_CMD PM_CHAN_2
@@ -59,8 +57,6 @@
#define LPC_HOST_TRANSACTION_TIMEOUT_US 5
#endif
-static uint32_t host_events; /* Currently pending SCI/SMI events */
-static uint32_t event_mask[3]; /* Event masks for each type */
static struct host_packet lpc_packet;
static struct host_cmd_handler_args host_cmd_args;
static uint8_t host_cmd_flags; /* Flags from host command */
@@ -139,6 +135,8 @@ static void lpc_task_disable_irq(void)
*/
static void lpc_generate_smi(void)
{
+ uint32_t smi;
+
#ifdef CONFIG_SCI_GPIO
/* Enforce signal-high for long enough to debounce high */
gpio_set_level(GPIO_PCH_SMI_L, 1);
@@ -173,9 +171,9 @@ static void lpc_generate_smi(void)
/* Set signal high */
SET_BIT(NPCX_HIPMIC(PMC_ACPI), NPCX_HIPMIC_SMIB);
#endif
- if (host_events & event_mask[LPC_HOST_EVENT_SMI])
- CPRINTS("smi 0x%08x",
- host_events & event_mask[LPC_HOST_EVENT_SMI]);
+ smi = lpc_get_host_events_by_type(LPC_HOST_EVENT_SMI);
+ if (smi)
+ CPRINTS("smi 0x%08x", smi);
}
/**
@@ -183,6 +181,8 @@ static void lpc_generate_smi(void)
*/
static void lpc_generate_sci(void)
{
+ uint32_t sci;
+
#ifdef CONFIG_SCI_GPIO
/* Enforce signal-high for long enough to debounce high */
gpio_set_level(CONFIG_SCI_GPIO, 1);
@@ -218,9 +218,9 @@ static void lpc_generate_sci(void)
SET_BIT(NPCX_HIPMIC(PMC_ACPI), NPCX_HIPMIC_SCIB);
#endif
- if (host_events & event_mask[LPC_HOST_EVENT_SCI])
- CPRINTS("sci 0x%08x",
- host_events & event_mask[LPC_HOST_EVENT_SCI]);
+ sci = lpc_get_host_events_by_type(LPC_HOST_EVENT_SCI);
+ if (sci)
+ CPRINTS("sci 0x%08x", sci);
}
/**
@@ -422,7 +422,7 @@ void lpc_keyboard_resume_irq(void)
* - SMI pulse via EC_SMI_L GPIO
* - SCI pulse via LPC0SCI
*/
-static void update_host_event_status(void)
+void lpc_update_host_event_status(void)
{
int need_sci = 0;
int need_smi = 0;
@@ -432,7 +432,7 @@ static void update_host_event_status(void)
/* Disable LPC interrupt while updating status register */
lpc_task_disable_irq();
- if (host_events & event_mask[LPC_HOST_EVENT_SMI]) {
+ if (lpc_get_host_events_by_type(LPC_HOST_EVENT_SMI)) {
/* Only generate SMI for first event */
if (!(NPCX_HIPMST(PMC_ACPI) & NPCX_HIPMST_ST2))
need_smi = 1;
@@ -440,7 +440,7 @@ static void update_host_event_status(void)
} else
CLEAR_BIT(NPCX_HIPMST(PMC_ACPI), NPCX_HIPMST_ST2);
- if (host_events & event_mask[LPC_HOST_EVENT_SCI]) {
+ if (lpc_get_host_events_by_type(LPC_HOST_EVENT_SCI)) {
/* Generate SCI for every event */
need_sci = 1;
SET_BIT(NPCX_HIPMST(PMC_ACPI), NPCX_HIPMST_ST1);
@@ -448,12 +448,13 @@ static void update_host_event_status(void)
CLEAR_BIT(NPCX_HIPMST(PMC_ACPI), NPCX_HIPMST_ST1);
/* Copy host events to mapped memory */
- *(uint32_t *)host_get_memmap(EC_MEMMAP_HOST_EVENTS) = host_events;
+ *(uint32_t *)host_get_memmap(EC_MEMMAP_HOST_EVENTS) =
+ lpc_get_host_events();
lpc_task_enable_irq();
/* Process the wake events. */
- lpc_update_wake(host_events & event_mask[LPC_HOST_EVENT_WAKE]);
+ lpc_update_wake(lpc_get_host_events_by_type(LPC_HOST_EVENT_WAKE));
/* Send pulse on SMI signal if needed */
if (need_smi)
@@ -464,54 +465,6 @@ static void update_host_event_status(void)
lpc_generate_sci();
}
-void lpc_set_host_event_state(uint32_t mask)
-{
- if (mask != host_events) {
- host_events = mask;
- update_host_event_status();
- }
-}
-
-int lpc_query_host_event_state(void)
-{
- const uint32_t any_mask = event_mask[0] | event_mask[1] | event_mask[2];
- int evt_index = 0;
- int i;
-
- for (i = 0; i < 32; i++) {
- const uint32_t e = (1 << i);
-
- if (host_events & e) {
- host_clear_events(e);
-
- /*
- * If host hasn't unmasked this event, drop it. We do
- * this at query time rather than event generation time
- * so that the host has a chance to unmask events
- * before they're dropped by a query.
- */
- if (!(e & any_mask))
- continue;
-
- evt_index = i + 1; /* Events are 1-based */
- break;
- }
- }
-
- return evt_index;
-}
-
-void lpc_set_host_event_mask(enum lpc_host_event_type type, uint32_t mask)
-{
- event_mask[type] = mask;
- update_host_event_status();
-}
-
-uint32_t lpc_get_host_event_mask(enum lpc_host_event_type type)
-{
- return event_mask[type];
-}
-
void lpc_set_acpi_status_mask(uint8_t mask)
{
NPCX_HIPMST(PMC_ACPI) |= mask;
@@ -689,28 +642,9 @@ static void lpc_sysjump(void)
/* Reset base address for Win 1 and 2. */
NPCX_WIN_BASE(0) = 0xfffffff8;
NPCX_WIN_BASE(1) = 0xfffffff8;
-
- system_add_jump_tag(LPC_SYSJUMP_TAG, 1,
- sizeof(event_mask), event_mask);
}
DECLARE_HOOK(HOOK_SYSJUMP, lpc_sysjump, HOOK_PRIO_DEFAULT);
-/**
- * Restore event masks after a sysjump.
- */
-static void lpc_post_sysjump(void)
-{
- const uint32_t *prev_mask;
- int size, version;
-
- prev_mask = (const uint32_t *)system_get_jump_tag(LPC_SYSJUMP_TAG,
- &version, &size);
- if (!prev_mask || version != 1 || size != sizeof(event_mask))
- return;
-
- memcpy(event_mask, prev_mask, sizeof(event_mask));
-}
-
/* Super-IO read/write function */
void lpc_sib_write_reg(uint8_t io_offset, uint8_t index_value,
uint8_t io_data)
@@ -1011,9 +945,6 @@ static void lpc_init(void)
/* Clear status */
NPCX_SMC_STS = NPCX_SMC_STS;
- /* Restore event masks if needed */
- lpc_post_sysjump();
-
/* Create mailbox */
/*
@@ -1074,7 +1005,7 @@ static void lpc_init(void)
init_done = 1;
/* Update host events now that we can copy them to memmap */
- update_host_event_status();
+ lpc_update_host_event_status();
/*
* TODO: For testing LPC with Chromebox, please make sure LPC_CLK is