feat(kscan): Add PM support to GPIO kscan drivers.
* Add PM device hook to the kscan direct & matrix drivers.
This commit is contained in:
parent
adb3a13dc5
commit
738c3c0e3b
2 changed files with 52 additions and 2 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <zephyr/drivers/kscan.h>
|
#include <zephyr/drivers/kscan.h>
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
|
#include <zephyr/pm/device.h>
|
||||||
#include <zephyr/sys/util.h>
|
#include <zephyr/sys/util.h>
|
||||||
|
|
||||||
#include <zmk/debounce.h>
|
#include <zmk/debounce.h>
|
||||||
|
@ -318,6 +319,28 @@ static int kscan_direct_init(const struct device *dev) {
|
||||||
return 0;
|
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 = {
|
static const struct kscan_driver_api kscan_direct_api = {
|
||||||
.config = kscan_direct_configure,
|
.config = kscan_direct_configure,
|
||||||
.enable_callback = kscan_direct_enable,
|
.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), \
|
.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_config_##n, POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \
|
||||||
&kscan_direct_api);
|
&kscan_direct_api);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <zephyr/devicetree.h>
|
#include <zephyr/devicetree.h>
|
||||||
#include <zephyr/drivers/gpio.h>
|
#include <zephyr/drivers/gpio.h>
|
||||||
#include <zephyr/drivers/kscan.h>
|
#include <zephyr/drivers/kscan.h>
|
||||||
|
#include <zephyr/pm/device.h>
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
#include <zephyr/sys/__assert.h>
|
#include <zephyr/sys/__assert.h>
|
||||||
|
@ -421,6 +422,28 @@ static int kscan_matrix_init(const struct device *dev) {
|
||||||
return 0;
|
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 = {
|
static const struct kscan_driver_api kscan_matrix_api = {
|
||||||
.config = kscan_matrix_configure,
|
.config = kscan_matrix_configure,
|
||||||
.enable_callback = kscan_matrix_enable,
|
.enable_callback = kscan_matrix_enable,
|
||||||
|
@ -465,7 +488,9 @@ static const struct kscan_driver_api kscan_matrix_api = {
|
||||||
.diode_direction = INST_DIODE_DIR(n), \
|
.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_config_##n, POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \
|
||||||
&kscan_matrix_api);
|
&kscan_matrix_api);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue