From 97713dba84a45d78445c9e50f28054c6d7ee5011 Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Tue, 1 Dec 2015 18:32:36 -0800 Subject: ec: Add a chipset reset hook There are hooks for chipset power sequencing but not one to indicate that the system has reset at runtime. Add a hook for this and implement for lm4 and mec1322. The hook is notified on any platform reset, including those that happen on the way into S3/S5 state. There is a new config variable added because the hook is notified in the interrupt handler and needs a deferrable function that needs to be added to every board. BUG=chrome-os-partner:46049 BRANCH=none TEST=tested on glados and samus Change-Id: I3be639414e18586344e0ec84632a50dfc1df586b Signed-off-by: Duncan Laurie Reviewed-on: https://chromium-review.googlesource.com/315221 Commit-Ready: Aaron Durbin Tested-by: Aaron Durbin Reviewed-by: Shawn N --- chip/lm4/lpc.c | 13 +++++++++++++ chip/mec1322/lpc.c | 13 +++++++++++++ chip/npcx/lpc.c | 25 ++++++++++++++++++++----- common/hooks.c | 1 + core/cortex-m/ec.lds.S | 4 ++++ core/cortex-m0/ec.lds.S | 4 ++++ core/host/host_exe.lds | 4 ++++ core/nds32/ec.lds.S | 4 ++++ include/config.h | 3 +++ include/hooks.h | 7 +++++++ include/link_defs.h | 2 ++ 11 files changed, 75 insertions(+), 5 deletions(-) diff --git a/chip/lm4/lpc.c b/chip/lm4/lpc.c index 8afd61f42b..4c27425273 100644 --- a/chip/lm4/lpc.c +++ b/chip/lm4/lpc.c @@ -578,6 +578,14 @@ static void handle_host_write(int is_cmd) host_command_received(&host_cmd_args); } +#ifdef CONFIG_CHIPSET_RESET_HOOK +static void lpc_chipset_reset(void) +{ + hook_notify(HOOK_CHIPSET_RESET); +} +DECLARE_DEFERRED(lpc_chipset_reset); +#endif + /** * LPC interrupt handler */ @@ -646,6 +654,11 @@ void lpc_interrupt(void) */ for (i = 0; i < 8; i++) LM4_LPC_ST(i) &= ~LM4_LPC_ST_FRMH; + +#ifdef CONFIG_CHIPSET_RESET_HOOK + /* Notify HOOK_CHIPSET_RESET */ + hook_call_deferred(lpc_chipset_reset, MSEC); +#endif } CPRINTS("LPC RESET# %sasserted", diff --git a/chip/mec1322/lpc.c b/chip/mec1322/lpc.c index 32d04036de..fe082d51ea 100644 --- a/chip/mec1322/lpc.c +++ b/chip/mec1322/lpc.c @@ -327,6 +327,14 @@ static void lpc_init(void) */ DECLARE_HOOK(HOOK_INIT, lpc_init, HOOK_PRIO_INIT_LPC); +#ifdef CONFIG_CHIPSET_RESET_HOOK +static void lpc_chipset_reset(void) +{ + hook_notify(HOOK_CHIPSET_RESET); +} +DECLARE_DEFERRED(lpc_chipset_reset); +#endif + void girq19_interrupt(void) { /* Check interrupt result for LRESET# trigger */ @@ -337,6 +345,11 @@ void girq19_interrupt(void) } else { /* Store port 80 reset event */ port_80_write(PORT_80_EVENT_RESET); + +#ifdef CONFIG_CHIPSET_RESET_HOOK + /* Notify HOOK_CHIPSET_RESET */ + hook_call_deferred(lpc_chipset_reset, MSEC); +#endif } CPRINTS("LPC RESET# %sasserted", diff --git a/chip/npcx/lpc.c b/chip/npcx/lpc.c index ff1049e1ff..5d5e13e185 100644 --- a/chip/npcx/lpc.c +++ b/chip/npcx/lpc.c @@ -729,6 +729,20 @@ void lpc_host_register_init(void) } +#ifdef CONFIG_CHIPSET_RESET_HOOK +static void lpc_chipset_reset(void) +{ + hook_notify(HOOK_CHIPSET_RESET); +} +DECLARE_DEFERRED(lpc_chipset_reset); +#endif + +int lpc_get_pltrst_asserted(void) +{ + /* Read current PLTRST status */ + return (NPCX_MSWCTL1 & 0x04) ? 1 : 0; +} + /* Initialize host settings by interrupt */ void lpc_lreset_pltrst_handler(void) { @@ -741,12 +755,13 @@ void lpc_lreset_pltrst_handler(void) * won't be reset by Host domain reset but Core domain does. */ lpc_host_register_init(); -} -int lpc_get_pltrst_asserted(void) -{ - /* Read current PLTRST status */ - return (NPCX_MSWCTL1 & 0x04) ? 1 : 0; +#ifdef CONFIG_CHIPSET_RESET_HOOK + if (lpc_get_pltrst_asserted()) { + /* Notify HOOK_CHIPSET_RESET */ + hook_call_deferred(lpc_chipset_reset, MSEC); + } +#endif } static void lpc_init(void) diff --git a/common/hooks.c b/common/hooks.c index 6cca00c914..f8e368c36d 100644 --- a/common/hooks.c +++ b/common/hooks.c @@ -41,6 +41,7 @@ static const struct hook_ptrs hook_list[] = { {__hooks_chipset_resume, __hooks_chipset_resume_end}, {__hooks_chipset_suspend, __hooks_chipset_suspend_end}, {__hooks_chipset_shutdown, __hooks_chipset_shutdown_end}, + {__hooks_chipset_reset, __hooks_chipset_reset_end}, {__hooks_ac_change, __hooks_ac_change_end}, {__hooks_lid_change, __hooks_lid_change_end}, {__hooks_pwrbtn_change, __hooks_pwrbtn_change_end}, diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index edd5308e93..9f08b98cc3 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -162,6 +162,10 @@ SECTIONS KEEP(*(.rodata.HOOK_CHIPSET_SHUTDOWN)) __hooks_chipset_shutdown_end = .; + __hooks_chipset_reset = .; + KEEP(*(.rodata.HOOK_CHIPSET_RESET)) + __hooks_chipset_reset_end = .; + __hooks_ac_change = .; KEEP(*(.rodata.HOOK_AC_CHANGE)) __hooks_ac_change_end = .; diff --git a/core/cortex-m0/ec.lds.S b/core/cortex-m0/ec.lds.S index dc36b49f72..484029b7a3 100644 --- a/core/cortex-m0/ec.lds.S +++ b/core/cortex-m0/ec.lds.S @@ -116,6 +116,10 @@ SECTIONS KEEP(*(.rodata.HOOK_CHIPSET_SHUTDOWN)) __hooks_chipset_shutdown_end = .; + __hooks_chipset_reset = .; + KEEP(*(.rodata.HOOK_CHIPSET_RESET)) + __hooks_chipset_reset_end = .; + __hooks_ac_change = .; KEEP(*(.rodata.HOOK_AC_CHANGE)) __hooks_ac_change_end = .; diff --git a/core/host/host_exe.lds b/core/host/host_exe.lds index 182d86cd6c..1f508e5795 100644 --- a/core/host/host_exe.lds +++ b/core/host/host_exe.lds @@ -56,6 +56,10 @@ SECTIONS { *(.rodata.HOOK_CHIPSET_SHUTDOWN) __hooks_chipset_shutdown_end = .; + __hooks_chipset_reset = .; + *(.rodata.HOOK_CHIPSET_RESET) + __hooks_chipset_reset_end = .; + __hooks_ac_change = .; *(.rodata.HOOK_AC_CHANGE) __hooks_ac_change_end = .; diff --git a/core/nds32/ec.lds.S b/core/nds32/ec.lds.S index 5a7f306f42..02c1aa9a11 100644 --- a/core/nds32/ec.lds.S +++ b/core/nds32/ec.lds.S @@ -101,6 +101,10 @@ SECTIONS KEEP(*(.rodata.HOOK_CHIPSET_SHUTDOWN)) __hooks_chipset_shutdown_end = .; + __hooks_chipset_reset = .; + KEEP(*(.rodata.HOOK_CHIPSET_RESET)) + __hooks_chipset_reset_end = .; + __hooks_ac_change = .; KEEP(*(.rodata.HOOK_AC_CHANGE)) __hooks_ac_change_end = .; diff --git a/include/config.h b/include/config.h index 942608e6e4..fba68c1c0e 100644 --- a/include/config.h +++ b/include/config.h @@ -482,6 +482,9 @@ /* Enable additional chipset debugging */ #undef CONFIG_CHIPSET_DEBUG +/* Enable chipset reset hook, requires a deferrable function */ +#undef CONFIG_CHIPSET_RESET_HOOK + /* Support power rail control */ #define CONFIG_CHIPSET_HAS_PP1350 #define CONFIG_CHIPSET_HAS_PP5000 diff --git a/include/hooks.h b/include/hooks.h index 49617aba95..c2b48ccd6c 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -108,6 +108,13 @@ enum hook_type { */ HOOK_CHIPSET_SHUTDOWN, + /* + * System reset in S0. All rails are still up. + * + * Hook routines are called from the chipset task. + */ + HOOK_CHIPSET_RESET, + /* * AC power plugged in or removed. * diff --git a/include/link_defs.h b/include/link_defs.h index ff443557b2..95fec83fff 100644 --- a/include/link_defs.h +++ b/include/link_defs.h @@ -42,6 +42,8 @@ extern const struct hook_data __hooks_chipset_suspend[]; extern const struct hook_data __hooks_chipset_suspend_end[]; extern const struct hook_data __hooks_chipset_shutdown[]; extern const struct hook_data __hooks_chipset_shutdown_end[]; +extern const struct hook_data __hooks_chipset_reset[]; +extern const struct hook_data __hooks_chipset_reset_end[]; extern const struct hook_data __hooks_ac_change[]; extern const struct hook_data __hooks_ac_change_end[]; extern const struct hook_data __hooks_lid_change[]; -- cgit v1.2.1