From d5b1a7d929e62a69d0d79c8603fbf92c4928bbf6 Mon Sep 17 00:00:00 2001 From: Jason Yu Date: Mon, 11 Mar 2024 13:08:54 +0900 Subject: [PATCH] driver: input: gt911: Support case that no dedicated reset pin On some boards, there is not dedicated reset pin for GT911, it might be the same pin with display IC, or might be tighted to a high level voltage. This patch makes the rst_gpio can be empty. Signed-off-by: Jason Yu --- drivers/input/input_gt911.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/input/input_gt911.c b/drivers/input/input_gt911.c index 01699c0637..23950cc4c7 100644 --- a/drivers/input/input_gt911.c +++ b/drivers/input/input_gt911.c @@ -225,15 +225,17 @@ static int gt911_init(const struct device *dev) return -ENODEV; } - if (!gpio_is_ready_dt(&config->rst_gpio)) { - LOG_ERR("Reset GPIO controller device not ready"); - return -ENODEV; - } + if (config->rst_gpio.port != NULL) { + if (!gpio_is_ready_dt(&config->rst_gpio)) { + LOG_ERR("Reset GPIO controller device not ready"); + return -ENODEV; + } - r = gpio_pin_configure_dt(&config->rst_gpio, GPIO_OUTPUT_ACTIVE); - if (r < 0) { - LOG_ERR("Could not configure reset GPIO pin"); - return r; + r = gpio_pin_configure_dt(&config->rst_gpio, GPIO_OUTPUT_ACTIVE); + if (r < 0) { + LOG_ERR("Could not configure reset GPIO pin"); + return r; + } } if (config->alt_addr == 0x0) { @@ -252,13 +254,15 @@ static int gt911_init(const struct device *dev) } /* Delay at least 10 ms after power on before we configure gt911 */ k_sleep(K_MSEC(20)); - /* reset the device and confgiure the addr mode0 */ - gpio_pin_set_dt(&config->rst_gpio, 1); - /* hold down at least 1us, 1ms here */ - k_sleep(K_MSEC(1)); - gpio_pin_set_dt(&config->rst_gpio, 0); - /* hold down at least 5ms. This is the point the INT pin must be low. */ - k_sleep(K_MSEC(5)); + if (config->rst_gpio.port != NULL) { + /* reset the device and confgiure the addr mode0 */ + gpio_pin_set_dt(&config->rst_gpio, 1); + /* hold down at least 1us, 1ms here */ + k_sleep(K_MSEC(1)); + gpio_pin_set_dt(&config->rst_gpio, 0); + /* hold down at least 5ms. This is the point the INT pin must be low. */ + k_sleep(K_MSEC(5)); + } /* hold down 50ms to make sure the address available */ k_sleep(K_MSEC(50)); @@ -359,7 +363,7 @@ static int gt911_init(const struct device *dev) #define GT911_INIT(index) \ static const struct gt911_config gt911_config_##index = { \ .bus = I2C_DT_SPEC_INST_GET(index), \ - .rst_gpio = GPIO_DT_SPEC_INST_GET(index, reset_gpios), \ + .rst_gpio = GPIO_DT_SPEC_INST_GET_OR(index, reset_gpios, {0}), \ .int_gpio = GPIO_DT_SPEC_INST_GET(index, irq_gpios), \ .alt_addr = DT_INST_PROP_OR(index, alt_addr, 0), \ }; \