aboutsummaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorPeter Johanson <[email protected]>2024-01-03 11:11:24 -0800
committerPete Johanson <[email protected]>2024-03-27 20:59:26 -0700
commit4198fac90f4f35e7464cb3793632f81601bbf1d5 (patch)
tree097fe4fb57acf8c0ea99d14ff7a6486f9971302a /app
parent09111f1cf36099690bf96091b46214c421b1fb3b (diff)
downloadzmk-4198fac90f4f35e7464cb3793632f81601bbf1d5.tar.gz
zmk-4198fac90f4f35e7464cb3793632f81601bbf1d5.zip
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.
Diffstat (limited to 'app')
-rw-r--r--app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml2
-rw-r--r--app/src/kscan.c5
-rw-r--r--app/src/kscan_sideband_behaviors.c29
3 files changed, 31 insertions, 5 deletions
diff --git a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml
index 7289b9e169..57b54a6041 100644
--- a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml
+++ b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml
@@ -7,7 +7,7 @@ description: |
compatible: "zmk,kscan-sideband-behaviors"
-include: [kscan.yaml]
+include: kscan.yaml
properties:
kscan:
diff --git a/app/src/kscan.c b/app/src/kscan.c
index c04ce2d879..5c7a5535a5 100644
--- a/app/src/kscan.c
+++ b/app/src/kscan.c
@@ -74,13 +74,14 @@ int zmk_kscan_init(const struct device *dev) {
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 (pm_device_wakeup_is_capable(dev)) {
pm_device_wakeup_enable(dev, true);
}
#endif // IS_ENABLED(CONFIG_PM_DEVICE)
+ kscan_config(dev, zmk_kscan_callback);
+ kscan_enable_callback(dev);
+
return 0;
}
diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c
index 3a03a29383..cff28e49d1 100644
--- a/app/src/kscan_sideband_behaviors.c
+++ b/app/src/kscan_sideband_behaviors.c
@@ -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) {
+ const struct ksbb_config *cfg = dev->config;
struct ksbb_data *data = dev->data;
if (!callback) {
@@ -82,6 +83,13 @@ static int ksbb_configure(const struct device *dev, kscan_callback_t 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;
}
@@ -119,6 +127,21 @@ static const struct kscan_driver_api ksbb_api = {
.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 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, (+)), \
}; \
struct ksbb_data ksbb_data_##n = {}; \
- DEVICE_DT_INST_DEFINE(n, ksbb_init, NULL, &ksbb_data_##n, &ksbb_config_##n, APPLICATION, \
- CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &ksbb_api);
+ PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \
+ 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)