summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2023-03-10 10:27:09 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-15 22:09:58 +0000
commitbf1232c2b16696c1f36b94ad3d412c743009320e (patch)
tree32d7332fb56a1645e8685f8e5309a2fd91af5c5a
parent255c4a92012467ce40ab15389ef0a0f3b516f97c (diff)
downloadchrome-ec-bf1232c2b16696c1f36b94ad3d412c743009320e.tar.gz
zephyr: power_button: convert to the input API
Convert the shim button driver to use the input APIs for the debounced state, use gpio_pin_get_dt() for the signal level one. BUG=b:268200726 BRANCH=none TEST=./twister, cq dry run Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Cq-Depend: chromium:4339704 Change-Id: Ie4c3729709af7690332bc91aea2131a51aed184e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4329528 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Al Semjonovs <asemjonovs@google.com> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/Kconfig2
-rw-r--r--zephyr/Kconfig.defaults4
-rw-r--r--zephyr/shim/src/buttons/CMakeLists.txt4
-rw-r--r--zephyr/shim/src/buttons/buttons.c34
-rw-r--r--zephyr/shim/src/buttons/power_button.c10
-rw-r--r--zephyr/test/drivers/default/boards/power_button.dtsi4
-rw-r--r--zephyr/test/drivers/prj.conf2
-rw-r--r--zephyr/test/qcom_power/boards/power_button.dtsi4
-rw-r--r--zephyr/test/qcom_power/prj.conf2
-rw-r--r--zephyr/test/qcom_power/src/main.c26
10 files changed, 61 insertions, 31 deletions
diff --git a/zephyr/Kconfig b/zephyr/Kconfig
index 0177f1f289..f8ae3553ab 100644
--- a/zephyr/Kconfig
+++ b/zephyr/Kconfig
@@ -548,7 +548,7 @@ config PLATFORM_EC_PORT80
config PLATFORM_EC_POWER_BUTTON
bool "Power-button support"
- depends on PLATFORM_EC_HOSTCMD && !GPIO_KEYS_ZEPHYR
+ depends on PLATFORM_EC_HOSTCMD && !INPUT_GPIO_KEYS
help
Enable shimming the power button implementation and related
commands in platform/ec. This is used to implement the Chromium OS
diff --git a/zephyr/Kconfig.defaults b/zephyr/Kconfig.defaults
index 31d3de04b8..21bcaa6f59 100644
--- a/zephyr/Kconfig.defaults
+++ b/zephyr/Kconfig.defaults
@@ -46,4 +46,8 @@ config SENSOR_SHELL
config ESPI_NPCX_PERIPHERAL_DEBUG_PORT_80_MULTI_BYTE
default y
+choice INPUT_MODE
+ default INPUT_MODE_SYNCHRONOUS
+endchoice
+
orsource "Kconfig.defaults-$(ARCH)"
diff --git a/zephyr/shim/src/buttons/CMakeLists.txt b/zephyr/shim/src/buttons/CMakeLists.txt
index 28b0926023..de15c60889 100644
--- a/zephyr/shim/src/buttons/CMakeLists.txt
+++ b/zephyr/shim/src/buttons/CMakeLists.txt
@@ -2,5 +2,5 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-zephyr_library_sources_ifdef(CONFIG_GPIO_KEYS_ZEPHYR buttons.c)
-zephyr_library_sources_ifdef(CONFIG_GPIO_KEYS_ZEPHYR power_button.c)
+zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_KEYS buttons.c)
+zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_KEYS power_button.c)
diff --git a/zephyr/shim/src/buttons/buttons.c b/zephyr/shim/src/buttons/buttons.c
index 01aba6c822..32f79705c3 100644
--- a/zephyr/shim/src/buttons/buttons.c
+++ b/zephyr/shim/src/buttons/buttons.c
@@ -6,7 +6,7 @@
#include "power_button.h"
#include <zephyr/device.h>
-#include <zephyr/drivers/gpio_keys.h>
+#include <zephyr/input/input.h>
#include <zephyr/logging/log.h>
#include <dt-bindings/buttons.h>
@@ -15,31 +15,23 @@ LOG_MODULE_REGISTER(button, CONFIG_GPIO_LOG_LEVEL);
#define DT_DRV_COMPAT zephyr_gpio_keys
-static void buttons_cb_handler(const struct device *dev,
- struct gpio_keys_callback *cbdata, uint32_t pins)
+static void buttons_cb_handler(struct input_event *evt)
{
- LOG_DBG("Button %s, pins=0x%x, zephyr_code=%u, pin_state=%d", dev->name,
- pins, cbdata->zephyr_code, cbdata->pin_state);
+ if (evt->type != INPUT_EV_KEY) {
+ return;
+ }
+
+ LOG_DBG("Button %s, code=%u, pin_state=%d", evt->dev->name, evt->code,
+ evt->value);
- switch (cbdata->zephyr_code) {
+ switch (evt->code) {
case BUTTON_POWER:
- handle_power_button(cbdata->pin_state);
+ handle_power_button(evt->value);
break;
default:
- LOG_ERR("Unknown button code=%u", cbdata->zephyr_code);
+ LOG_ERR("Unknown button code=%u", evt->code);
break;
}
}
-
-#define BUTTONS_ENABLE_INT(node_id) \
- gpio_keys_enable_interrupt(DEVICE_DT_GET(DT_DRV_INST(node_id)), \
- buttons_cb_handler)
-
-static int buttons_init(const struct device *device)
-{
- DT_INST_FOREACH_STATUS_OKAY(BUTTONS_ENABLE_INT);
-
- return 0;
-}
-
-SYS_INIT(buttons_init, POST_KERNEL, 51);
+INPUT_LISTENER_CB_DEFINE(DEVICE_DT_GET_ONE(zephyr_gpio_keys),
+ buttons_cb_handler);
diff --git a/zephyr/shim/src/buttons/power_button.c b/zephyr/shim/src/buttons/power_button.c
index fdb684376c..8a4ebc9ac3 100644
--- a/zephyr/shim/src/buttons/power_button.c
+++ b/zephyr/shim/src/buttons/power_button.c
@@ -9,15 +9,15 @@
#include "task.h"
#include "util.h"
-#include <zephyr/drivers/gpio_keys.h>
+#include <zephyr/drivers/gpio.h>
#include <zephyr/logging/log.h>
#include <zephyr/shell/shell.h>
LOG_MODULE_REGISTER(power_button, CONFIG_GPIO_LOG_LEVEL);
-#define POWER_BUTTON_LBL DT_NODELABEL(power_button)
-#define POWER_BUTTON_IDX DT_NODE_CHILD_IDX(POWER_BUTTON_LBL)
-#define GPIOKEYS_DEV DEVICE_DT_GET(DT_PARENT(POWER_BUTTON_LBL))
+#define POWER_BUTTON_NODE DT_NODELABEL(power_button)
+static const struct gpio_dt_spec power_button =
+ GPIO_DT_SPEC_GET(POWER_BUTTON_NODE, gpios);
static struct power_button_data_s {
int8_t state;
@@ -30,7 +30,7 @@ int power_button_is_pressed(void)
int power_button_signal_asserted(void)
{
- return gpio_keys_get_pin(GPIOKEYS_DEV, POWER_BUTTON_IDX);
+ return gpio_pin_get_dt(&power_button);
}
int power_button_wait_for_release(int timeout_us)
diff --git a/zephyr/test/drivers/default/boards/power_button.dtsi b/zephyr/test/drivers/default/boards/power_button.dtsi
index b618b15fe2..f16a81bcbb 100644
--- a/zephyr/test/drivers/default/boards/power_button.dtsi
+++ b/zephyr/test/drivers/default/boards/power_button.dtsi
@@ -3,13 +3,15 @@
* found in the LICENSE file.
*/
#include <dt-bindings/buttons.h>
+#include <zephyr/dt-bindings/input/input-event-codes.h>
/ {
- gpio_keys0: gpio-keys {
+ gpio-keys {
compatible = "zephyr,gpio-keys";
debounce-interval-ms = <30>;
power_button: power_button {
gpios = <&gpio0 25 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
+ /* TODO: use an INPUT_KEY code here. */
zephyr,code = <BUTTON_POWER>;
};
};
diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf
index 555be472f1..4ab46e24c4 100644
--- a/zephyr/test/drivers/prj.conf
+++ b/zephyr/test/drivers/prj.conf
@@ -162,3 +162,5 @@ CONFIG_PLATFORM_EC_TABLET_MODE=y
# Power Management (Herobrine arch enables this)
CONFIG_PM=y
+
+CONFIG_INPUT=y
diff --git a/zephyr/test/qcom_power/boards/power_button.dtsi b/zephyr/test/qcom_power/boards/power_button.dtsi
index 5a91a799cb..0edbaa3e5b 100644
--- a/zephyr/test/qcom_power/boards/power_button.dtsi
+++ b/zephyr/test/qcom_power/boards/power_button.dtsi
@@ -3,13 +3,15 @@
* found in the LICENSE file.
*/
#include <dt-bindings/buttons.h>
+#include <zephyr/dt-bindings/input/input-event-codes.h>
/ {
- gpio_keys0: gpio-keys {
+ gpio-keys {
compatible = "zephyr,gpio-keys";
debounce-interval-ms = <30>;
power_button: power_button {
gpios = <&gpio0 25 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
+ /* TODO: use an INPUT_KEY code here. */
zephyr,code = <BUTTON_POWER>;
};
};
diff --git a/zephyr/test/qcom_power/prj.conf b/zephyr/test/qcom_power/prj.conf
index 2a160bd7da..688ce4ac1f 100644
--- a/zephyr/test/qcom_power/prj.conf
+++ b/zephyr/test/qcom_power/prj.conf
@@ -9,6 +9,8 @@ CONFIG_ZTEST_ASSERT_VERBOSE=1
CONFIG_ZTEST_MOCKING=y
CONFIG_ZTEST_NEW_API=y
+CONFIG_INPUT=y
+
# Print logs from Zephyr LOG_MODULE to stdout
CONFIG_NATIVE_UART_0_ON_STDINOUT=y
diff --git a/zephyr/test/qcom_power/src/main.c b/zephyr/test/qcom_power/src/main.c
index eb033e62f3..c5c3953208 100644
--- a/zephyr/test/qcom_power/src/main.c
+++ b/zephyr/test/qcom_power/src/main.c
@@ -22,10 +22,13 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/gpio/gpio_emul.h>
#include <zephyr/fff.h>
+#include <zephyr/input/input.h>
#include <zephyr/kernel.h>
#include <zephyr/shell/shell_dummy.h>
#include <zephyr/ztest.h>
+#include <dt-bindings/buttons.h>
+
/* For simplicity, enforce that all the gpios are on the same controller. */
#define GPIO_DEVICE \
DEVICE_DT_GET(DT_GPIO_CTLR(NAMED_GPIOS_GPIO_NODE(ap_rst_l), gpios))
@@ -362,6 +365,29 @@ ZTEST(qcom_power, test_power_button)
zassert_equal(power_get_state(), POWER_S0);
}
+#ifdef CONFIG_INPUT_GPIO_KEYS
+
+ZTEST(qcom_power, test_power_button_input_event)
+{
+ const struct device *dev = DEVICE_DT_GET_ONE(zephyr_gpio_keys);
+
+ zassert_equal(power_button_is_pressed(), 0);
+
+ input_report_key(dev, BUTTON_POWER, 1, true, K_FOREVER);
+ zassert_equal(power_button_is_pressed(), 1);
+
+ input_report_key(dev, BUTTON_RECOVERY, 1, true, K_FOREVER);
+ zassert_equal(power_button_is_pressed(), 1);
+
+ input_report_abs(dev, INPUT_ABS_X, 1, true, K_FOREVER);
+ zassert_equal(power_button_is_pressed(), 1);
+
+ input_report_key(dev, BUTTON_POWER, 0, true, K_FOREVER);
+ zassert_equal(power_button_is_pressed(), 0);
+}
+
+#endif
+
ZTEST(qcom_power, test_power_button_no_power_good)
{
static const struct device *gpio_dev = GPIO_DEVICE;