aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPeter Johanson <[email protected]>2023-09-13 19:58:53 +0000
committerPete Johanson <[email protected]>2024-03-27 20:59:26 -0700
commit738c3c0e3b3878ddaebafae65becdf5e5f68fe86 (patch)
tree24ec600331486a9501cfd5dfcdaefbd2c9b51f56
parentadb3a13dc583e1876d5aa17da0ade4c1024cad7d (diff)
downloadzmk-738c3c0e3b3878ddaebafae65becdf5e5f68fe86.tar.gz
zmk-738c3c0e3b3878ddaebafae65becdf5e5f68fe86.zip
feat(kscan): Add PM support to GPIO kscan drivers.
* Add PM device hook to the kscan direct & matrix drivers.
-rw-r--r--app/module/drivers/kscan/kscan_gpio_direct.c27
-rw-r--r--app/module/drivers/kscan/kscan_gpio_matrix.c27
2 files changed, 52 insertions, 2 deletions
diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c
index b5e77f6330..2bc35f4c0b 100644
--- a/app/module/drivers/kscan/kscan_gpio_direct.c
+++ b/app/module/drivers/kscan/kscan_gpio_direct.c
@@ -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>
@@ -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,
@@ -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);
diff --git a/app/module/drivers/kscan/kscan_gpio_matrix.c b/app/module/drivers/kscan/kscan_gpio_matrix.c
index 6e91bf95fb..3917196e6c 100644
--- a/app/module/drivers/kscan/kscan_gpio_matrix.c
+++ b/app/module/drivers/kscan/kscan_gpio_matrix.c
@@ -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>
@@ -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,
@@ -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);