From 32d0a4bf4102148d394dc5a7acc962e71c5ed000 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 16 Sep 2024 14:13:51 -0600 Subject: [PATCH] fix: Fix wakeup from kscan wrapped in sideband. * If using a sideband kscan device to wrap a native kscan device, ensure the inner kscan device is also wakeup enabled to it can be waken from a deep sleep state by key press. --- app/src/kscan_sideband_behaviors.c | 7 +++++++ app/src/physical_layouts.c | 7 +++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c index 4ef5b052f..9f38e0fbc 100644 --- a/app/src/kscan_sideband_behaviors.c +++ b/app/src/kscan_sideband_behaviors.c @@ -111,6 +111,9 @@ static int ksbb_enable(const struct device *dev) { pm_device_runtime_get(config->kscan); } #elif IS_ENABLED(CONFIG_PM_DEVICE) + if (pm_device_wakeup_is_capable(config->kscan)) { + pm_device_wakeup_enable(config->kscan, true); + } pm_device_action_run(config->kscan, PM_DEVICE_ACTION_RESUME); #endif // IS_ENABLED(CONFIG_PM_DEVICE) @@ -132,6 +135,10 @@ static int ksbb_disable(const struct device *dev) { pm_device_runtime_put(config->kscan); } #elif IS_ENABLED(CONFIG_PM_DEVICE) + if (pm_device_wakeup_is_capable(config->kscan) && !pm_device_wakeup_is_enabled(dev) && + pm_device_wakeup_is_enabled(config->kscan)) { + pm_device_wakeup_enable(config->kscan, false); + } pm_device_action_run(config->kscan, PM_DEVICE_ACTION_SUSPEND); #endif // IS_ENABLED(CONFIG_PM_DEVICE) diff --git a/app/src/physical_layouts.c b/app/src/physical_layouts.c index a7f650781..ac627f465 100644 --- a/app/src/physical_layouts.c +++ b/app/src/physical_layouts.c @@ -393,10 +393,9 @@ static int zmk_physical_layouts_init(void) { #if IS_ENABLED(CONFIG_PM_DEVICE) for (int l = 0; l < ARRAY_SIZE(layouts); l++) { const struct zmk_physical_layout *pl = layouts[l]; - if (pl->kscan) { - if (pm_device_wakeup_is_capable(pl->kscan)) { - pm_device_wakeup_enable(pl->kscan, true); - } + if (pl->kscan && pm_device_wakeup_is_capable(pl->kscan) && + !pm_device_wakeup_enable(pl->kscan, true)) { + LOG_WRN("Failed to wakeup enable %s", pl->kscan->name); } } #endif // IS_ENABLED(CONFIG_PM_DEVICE)