Skip to content

Commit

Permalink
fix: allow kscan-composite to wake up device. (#2682)
Browse files Browse the repository at this point in the history
* include kscan.yaml so we can set kscan-composite as a wakeup source
* modify enable and disable callback to check for wakeup capabilities of
composite and children
* disable children wakeup source

The disable function is only called
when the composite is not an enabled wakeup source.
In that case the children should also not be an enabled
wakeup source, so they can get suspended
  • Loading branch information
svek1 authored Dec 11, 2024
1 parent 84baf92 commit a8f5ab6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/dts/bindings/zmk,kscan-composite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ description: |
compatible: "zmk,kscan-composite"

include: kscan.yaml

properties:
label:
type: string
Expand Down
15 changes: 15 additions & 0 deletions app/module/drivers/kscan/kscan_composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ static int kscan_composite_enable_callback(const struct device *dev) {
for (int i = 0; i < cfg->children_len; i++) {
const struct kscan_composite_child_config *child_cfg = &cfg->children[i];

#if IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || IS_ENABLED(CONFIG_PM_DEVICE)
if (pm_device_wakeup_is_enabled(dev) && pm_device_wakeup_is_capable(child_cfg->child) &&
!pm_device_wakeup_enable(child_cfg->child, true)) {
LOG_ERR("Failed to enable wakeup for %s", child_cfg->child->name);
}
#endif // IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || IS_ENABLED(CONFIG_PM_DEVICE)

#if IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)
if (!pm_device_runtime_is_enabled(dev) && pm_device_runtime_is_enabled(child_cfg->child)) {
pm_device_runtime_get(child_cfg->child);
Expand All @@ -62,6 +69,14 @@ static int kscan_composite_disable_callback(const struct device *dev) {
for (int i = 0; i < cfg->children_len; i++) {
const struct kscan_composite_child_config *child_cfg = &cfg->children[i];

#if IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || IS_ENABLED(CONFIG_PM_DEVICE)
if (pm_device_wakeup_is_capable(child_cfg->child) &&
pm_device_wakeup_is_enabled(child_cfg->child) &&
!pm_device_wakeup_enable(child_cfg->child, false)) {
LOG_ERR("Failed to disable wakeup for %s", child_cfg->child->name);
}
#endif // IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || IS_ENABLED(CONFIG_PM_DEVICE)

kscan_disable_callback(child_cfg->child);

#if IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)
Expand Down
11 changes: 6 additions & 5 deletions docs/docs/config/kscan.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ Definition file: [zmk/app/dts/bindings/zmk,kscan-composite.yaml](https://github.

The `zmk,kscan-composite` node should have one child node per keyboard scan driver that should be composited. Each child node can have the following properties:

| Property | Type | Description | Default |
| ------------ | ------- | ------------------------------------------------------------------------------ | ------- |
| `kscan` | phandle | Label of the kscan driver to include | |
| `row-offset` | int | Shifts row 0 of the included driver to a new row in the composite matrix | 0 |
| `col-offset` | int | Shifts column 0 of the included driver to a new column in the composite matrix | 0 |
| Property | Type | Description | Default |
| --------------- | ------- | ------------------------------------------------------------------------------ | ------- |
| `kscan` | phandle | Label of the kscan driver to include | |
| `row-offset` | int | Shifts row 0 of the included driver to a new row in the composite matrix | 0 |
| `col-offset` | int | Shifts column 0 of the included driver to a new column in the composite matrix | 0 |
| `wakeup-source` | bool | Mark this kscan instance as able to wake the keyboard | n |

### Example Configuration

Expand Down

0 comments on commit a8f5ab6

Please sign in to comment.