Skip to content

Commit

Permalink
feat(kscan): Add PM support to GPIO kscan drivers.
Browse files Browse the repository at this point in the history
* Add PM device hook to the kscan direct & matrix drivers.
  • Loading branch information
petejohanson committed Nov 7, 2023
1 parent dcc9203 commit 2b4e65f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
27 changes: 26 additions & 1 deletion app/module/drivers/kscan/kscan_gpio_direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <zephyr/drivers/kscan.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/pm/device.h>
#include <zephyr/sys/util.h>

#include <zmk/debounce.h>
Expand Down Expand Up @@ -318,6 +319,28 @@ static int kscan_direct_init(const struct device *dev) {
return 0;
}

#if IS_ENABLED(CONFIG_PM_DEVICE)

static int kscan_direct_pm_action(const struct device *dev, enum pm_device_action action) {
int ret = 0;

switch (action) {
case PM_DEVICE_ACTION_SUSPEND:
kscan_direct_disable(dev);
break;
case PM_DEVICE_ACTION_RESUME:
kscan_direct_enable(dev);
break;
default:
ret = -ENOTSUP;
break;
}

return ret;
}

#endif // IS_ENABLED(CONFIG_PM_DEVICE)

static const struct kscan_driver_api kscan_direct_api = {
.config = kscan_direct_configure,
.enable_callback = kscan_direct_enable,
Expand Down Expand Up @@ -354,7 +377,9 @@ static const struct kscan_driver_api kscan_direct_api = {
.toggle_mode = DT_INST_PROP(n, toggle_mode), \
}; \
\
DEVICE_DT_INST_DEFINE(n, &kscan_direct_init, NULL, &kscan_direct_data_##n, \
PM_DEVICE_DT_INST_DEFINE(n, kscan_direct_pm_action); \
\
DEVICE_DT_INST_DEFINE(n, &kscan_direct_init, PM_DEVICE_DT_INST_GET(n), &kscan_direct_data_##n, \
&kscan_direct_config_##n, POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \
&kscan_direct_api);

Expand Down
27 changes: 26 additions & 1 deletion app/module/drivers/kscan/kscan_gpio_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/kscan.h>
#include <zephyr/pm/device.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/__assert.h>
Expand Down Expand Up @@ -421,6 +422,28 @@ static int kscan_matrix_init(const struct device *dev) {
return 0;
}

#if IS_ENABLED(CONFIG_PM_DEVICE)

static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_action action) {
int ret = 0;

switch (action) {
case PM_DEVICE_ACTION_SUSPEND:
kscan_matrix_disable(dev);
break;
case PM_DEVICE_ACTION_RESUME:
kscan_matrix_enable(dev);
break;
default:
ret = -ENOTSUP;
break;
}

return ret;
}

#endif // IS_ENABLED(CONFIG_PM_DEVICE)

static const struct kscan_driver_api kscan_matrix_api = {
.config = kscan_matrix_configure,
.enable_callback = kscan_matrix_enable,
Expand Down Expand Up @@ -465,7 +488,9 @@ static const struct kscan_driver_api kscan_matrix_api = {
.diode_direction = INST_DIODE_DIR(n), \
}; \
\
DEVICE_DT_INST_DEFINE(n, &kscan_matrix_init, NULL, &kscan_matrix_data_##n, \
PM_DEVICE_DT_INST_DEFINE(n, kscan_matrix_pm_action); \
\
DEVICE_DT_INST_DEFINE(n, &kscan_matrix_init, PM_DEVICE_DT_INST_GET(n), &kscan_matrix_data_##n, \
&kscan_matrix_config_##n, POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \
&kscan_matrix_api);

Expand Down

0 comments on commit 2b4e65f

Please sign in to comment.