diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2018-02-01 11:33:25 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-02-02 10:17:30 -0800 |
commit | 76927bdc5a17ddbdc9fc601b761c2a4984ecc1e9 (patch) | |
tree | 0ef346ffe19b05b9fddeb0320c244705c5686baf | |
parent | c721ad9162b9fe20ce872c1d28cd8b1ad60e2c25 (diff) | |
download | chrome-ec-76927bdc5a17ddbdc9fc601b761c2a4984ecc1e9.tar.gz |
stm32/usb: Add HOOK_USB_PM_CHANGE, called when USB is resumed/suspended
In particular, this will allow touchpad driver and keyboard matrix
scanning to be powered off/disabled when the USB interface is
disabled without setting the remote wake feature
(USB_REQ_FEATURE_DEVICE_REMOTE_WAKEUP), as events would be
ignored anyway.
BRANCH=none
BUG=b:72683995
TEST=With next CLs, touchpad and keyboard matrix scanning are disabled
when lid is closed.
Change-Id: I3750bfaf8c31cde075adf9da4fef39753b8981c5
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/897067
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | chip/stm32/usb.c | 23 | ||||
-rw-r--r-- | common/hooks.c | 3 | ||||
-rw-r--r-- | core/cortex-m/ec.lds.S | 6 | ||||
-rw-r--r-- | core/cortex-m0/ec.lds.S | 6 | ||||
-rw-r--r-- | core/minute-ia/ec.lds.S | 6 | ||||
-rw-r--r-- | core/nds32/ec.lds.S | 6 | ||||
-rw-r--r-- | include/hooks.h | 10 | ||||
-rw-r--r-- | include/link_defs.h | 4 | ||||
-rw-r--r-- | include/usb_api.h | 7 |
9 files changed, 70 insertions, 1 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c index 57e629a3d1..560ca3da2d 100644 --- a/chip/stm32/usb.c +++ b/chip/stm32/usb.c @@ -379,10 +379,16 @@ static void usb_reset(void) } #ifdef CONFIG_USB_SUSPEND +static void usb_pm_change_notify_hooks(void) +{ + hook_notify(HOOK_USB_PM_CHANGE); +} +DECLARE_DEFERRED(usb_pm_change_notify_hooks); + /* See RM0091 Reference Manual 30.5.5 Suspend/Resume events */ static void usb_suspend(void) { - CPRINTF("SUS\n"); + CPRINTF("SUS%d\n", remote_wakeup_enabled); /* * usb_suspend can be called from hook task, make sure no interrupt is @@ -400,6 +406,8 @@ static void usb_suspend(void) /* USB is not in use anymore, we can (hopefully) sleep now. */ enable_sleep(SLEEP_MASK_USB_DEVICE); + + hook_call_deferred(&usb_pm_change_notify_hooks_data, 0); } static void usb_resume_deferred(void) @@ -410,6 +418,8 @@ static void usb_resume_deferred(void) CPRINTF("RSMd %d %04x\n", state, STM32_USB_CNTR); if (state == 2 || state == 3) usb_suspend(); + else + hook_call_deferred(&usb_pm_change_notify_hooks_data, 0); } DECLARE_DEFERRED(usb_resume_deferred); @@ -440,6 +450,8 @@ static void usb_resume(void) */ if (state == 2 || state == 3) hook_call_deferred(&usb_resume_deferred_data, 3 * MSEC); + else + hook_call_deferred(&usb_pm_change_notify_hooks_data, 0); } #ifdef CONFIG_USB_REMOTE_WAKEUP @@ -536,6 +548,15 @@ int usb_is_suspended(void) return 0; } + +int usb_is_remote_wakeup_enabled(void) +{ +#ifdef CONFIG_USB_REMOTE_WAKEUP + return remote_wakeup_enabled; +#else + return 0; +#endif +} #endif /* CONFIG_USB_SUSPEND */ #if defined(CONFIG_USB_SUSPEND) && defined(CONFIG_USB_REMOTE_WAKEUP) diff --git a/common/hooks.c b/common/hooks.c index d83c7a36c8..6b4bb8873d 100644 --- a/common/hooks.c +++ b/common/hooks.c @@ -50,6 +50,9 @@ static const struct hook_ptrs hook_list[] = { #ifdef CONFIG_CASE_CLOSED_DEBUG_V1 {__hooks_ccd_change, __hooks_ccd_change_end}, #endif +#ifdef CONFIG_USB_SUSPEND + {__hooks_usb_change, __hooks_usb_change_end}, +#endif {__hooks_tick, __hooks_tick_end}, {__hooks_second, __hooks_second_end}, }; diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index 64fb132462..5e84b56db0 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -204,6 +204,12 @@ SECTIONS __hooks_ccd_change_end = .; #endif +#ifdef CONFIG_USB_SUSPEND + __hooks_usb_change = .; + KEEP(*(.rodata.HOOK_USB_PM_CHANGE)) + __hooks_usb_change_end = .; +#endif + __hooks_tick = .; KEEP(*(.rodata.HOOK_TICK)) __hooks_tick_end = .; diff --git a/core/cortex-m0/ec.lds.S b/core/cortex-m0/ec.lds.S index a43499ab27..ce4ef3849d 100644 --- a/core/cortex-m0/ec.lds.S +++ b/core/cortex-m0/ec.lds.S @@ -139,6 +139,12 @@ SECTIONS KEEP(*(.rodata.HOOK_BATTERY_SOC_CHANGE)) __hooks_battery_soc_change_end = .; +#ifdef CONFIG_USB_SUSPEND + __hooks_usb_change = .; + KEEP(*(.rodata.HOOK_USB_PM_CHANGE)) + __hooks_usb_change_end = .; +#endif + __hooks_tick = .; KEEP(*(.rodata.HOOK_TICK)) __hooks_tick_end = .; diff --git a/core/minute-ia/ec.lds.S b/core/minute-ia/ec.lds.S index 7357737189..5c8f9d6fce 100644 --- a/core/minute-ia/ec.lds.S +++ b/core/minute-ia/ec.lds.S @@ -110,6 +110,12 @@ SECTIONS KEEP(*(.rodata.HOOK_BATTERY_SOC_CHANGE)) __hooks_battery_soc_change_end = .; +#ifdef CONFIG_USB_SUSPEND + __hooks_usb_change = .; + KEEP(*(.rodata.HOOK_USB_PM_CHANGE)) + __hooks_usb_change_end = .; +#endif + __hooks_tick = .; KEEP(*(.rodata.HOOK_TICK)) __hooks_tick_end = .; diff --git a/core/nds32/ec.lds.S b/core/nds32/ec.lds.S index df4a7aeaa8..c2897343e6 100644 --- a/core/nds32/ec.lds.S +++ b/core/nds32/ec.lds.S @@ -137,6 +137,12 @@ SECTIONS KEEP(*(.rodata.HOOK_BATTERY_SOC_CHANGE)) __hooks_battery_soc_change_end = .; +#ifdef CONFIG_USB_SUSPEND + __hooks_usb_change = .; + KEEP(*(.rodata.HOOK_USB_PM_CHANGE)) + __hooks_usb_change_end = .; +#endif + __hooks_tick = .; KEEP(*(.rodata.HOOK_TICK)) __hooks_tick_end = .; diff --git a/include/hooks.h b/include/hooks.h index 04206efde7..ee1d2bc475 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -171,6 +171,16 @@ enum hook_type { HOOK_CCD_CHANGE, #endif +#ifdef CONFIG_USB_SUSPEND + /* + * Called when there is a change in USB power management status + * (suspended or resumed). + * + * Hook routines are called from HOOKS task. + */ + HOOK_USB_PM_CHANGE, +#endif + /* * Periodic tick, every HOOK_TICK_INTERVAL. * diff --git a/include/link_defs.h b/include/link_defs.h index 9e621ebce7..c12a350924 100644 --- a/include/link_defs.h +++ b/include/link_defs.h @@ -58,6 +58,10 @@ extern const struct hook_data __hooks_battery_soc_change_end[]; extern const struct hook_data __hooks_ccd_change[]; extern const struct hook_data __hooks_ccd_change_end[]; #endif +#ifdef CONFIG_USB_SUSPEND +extern const struct hook_data __hooks_usb_change[]; +extern const struct hook_data __hooks_usb_change_end[]; +#endif extern const struct hook_data __hooks_tick[]; extern const struct hook_data __hooks_tick_end[]; extern const struct hook_data __hooks_second[]; diff --git a/include/usb_api.h b/include/usb_api.h index 8778dcc54e..7ebf25b135 100644 --- a/include/usb_api.h +++ b/include/usb_api.h @@ -49,6 +49,13 @@ void usb_release(void); int usb_is_suspended(void); /* + * Returns true if USB remote wakeup is currently enabled by host. + * Requires CONFIG_USB_SUSPEND to be defined, always return 0 if + * CONFIG_USB_REMOTE_WAKEUP is not defined. + */ +int usb_is_remote_wakeup_enabled(void); + +/* * Preserve in non-volatile memory the state of the USB hardware registers * which cannot be simply re-initialized when powered up again. */ |