Skip to content

Commit

Permalink
fix(pm): Fix deep sleep with sideband behaviors.
Browse files Browse the repository at this point in the history
* Properly implement the PM hook needed for sideband behavior
  kscan device to have wakeup source enabled on it.
  • Loading branch information
petejohanson committed Jan 3, 2024
1 parent 28b69c0 commit 1ce6e05
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |
compatible: "zmk,kscan-sideband-behaviors"

include: [kscan.yaml]
include: kscan.yaml

properties:
kscan:
Expand Down
5 changes: 3 additions & 2 deletions app/src/kscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
29 changes: 27 additions & 2 deletions app/src/kscan_sideband_behaviors.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@ 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) {
return -EINVAL;
}

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;
}

Expand Down Expand Up @@ -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) \
Expand All @@ -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)

0 comments on commit 1ce6e05

Please sign in to comment.