fix(pm): Fix deep sleep with sideband behaviors.

* Properly implement the PM hook needed for sideband behavior
  kscan device to have wakeup source enabled on it.
This commit is contained in:
Peter Johanson 2024-01-03 11:11:24 -08:00 committed by Pete Johanson
parent 09111f1cf3
commit 4198fac90f
3 changed files with 31 additions and 5 deletions

View File

@ -7,7 +7,7 @@ description: |
compatible: "zmk,kscan-sideband-behaviors" compatible: "zmk,kscan-sideband-behaviors"
include: [kscan.yaml] include: kscan.yaml
properties: properties:
kscan: kscan:

View File

@ -74,13 +74,14 @@ int zmk_kscan_init(const struct device *dev) {
k_work_init(&msg_processor.work, zmk_kscan_process_msgq); k_work_init(&msg_processor.work, zmk_kscan_process_msgq);
kscan_config(dev, zmk_kscan_callback);
kscan_enable_callback(dev);
#if IS_ENABLED(CONFIG_PM_DEVICE) #if IS_ENABLED(CONFIG_PM_DEVICE)
if (pm_device_wakeup_is_capable(dev)) { if (pm_device_wakeup_is_capable(dev)) {
pm_device_wakeup_enable(dev, true); pm_device_wakeup_enable(dev, true);
} }
#endif // IS_ENABLED(CONFIG_PM_DEVICE) #endif // IS_ENABLED(CONFIG_PM_DEVICE)
kscan_config(dev, zmk_kscan_callback);
kscan_enable_callback(dev);
return 0; return 0;
} }

View File

@ -75,6 +75,7 @@ void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t
} }
static int ksbb_configure(const struct device *dev, kscan_callback_t callback) { static int ksbb_configure(const struct device *dev, kscan_callback_t callback) {
const struct ksbb_config *cfg = dev->config;
struct ksbb_data *data = dev->data; struct ksbb_data *data = dev->data;
if (!callback) { if (!callback) {
@ -82,6 +83,13 @@ static int ksbb_configure(const struct device *dev, kscan_callback_t callback) {
} }
data->callback = callback; data->callback = callback;
#if IS_ENABLED(CONFIG_PM_DEVICE)
if (pm_device_wakeup_is_enabled(dev) && pm_device_wakeup_is_capable(cfg->kscan)) {
pm_device_wakeup_enable(cfg->kscan, true);
}
#endif // IS_ENABLED(CONFIG_PM_DEVICE)
return 0; return 0;
} }
@ -119,6 +127,21 @@ static const struct kscan_driver_api ksbb_api = {
.disable_callback = ksbb_disable, .disable_callback = ksbb_disable,
}; };
#if IS_ENABLED(CONFIG_PM_DEVICE)
static int ksbb_pm_action(const struct device *dev, enum pm_device_action action) {
switch (action) {
case PM_DEVICE_ACTION_SUSPEND:
return ksbb_disable(dev);
case PM_DEVICE_ACTION_RESUME:
return ksbb_disable(dev);
default:
return -ENOTSUP;
}
}
#endif // IS_ENABLED(CONFIG_PM_DEVICE)
#define JUST_ONE(_id) 1 #define JUST_ONE(_id) 1
#define ENTRY(e) \ #define ENTRY(e) \
@ -136,7 +159,9 @@ static const struct kscan_driver_api ksbb_api = {
.entries_len = DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, JUST_ONE, (+)), \ .entries_len = DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, JUST_ONE, (+)), \
}; \ }; \
struct ksbb_data ksbb_data_##n = {}; \ struct ksbb_data ksbb_data_##n = {}; \
DEVICE_DT_INST_DEFINE(n, ksbb_init, NULL, &ksbb_data_##n, &ksbb_config_##n, APPLICATION, \ PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &ksbb_api); DEVICE_DT_INST_DEFINE(n, ksbb_init, PM_DEVICE_DT_INST_GET(n), &ksbb_data_##n, \
&ksbb_config_##n, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&ksbb_api);
DT_INST_FOREACH_STATUS_OKAY(KSBB_INST) DT_INST_FOREACH_STATUS_OKAY(KSBB_INST)