From 41950cab0f6c126c859daa29c2a722661bbb9b17 Mon Sep 17 00:00:00 2001 From: Chekhov Ma Date: Thu, 29 May 2025 16:18:03 +0800 Subject: [PATCH] drivers: gpio_adp5585: fix non-contiguous pin layout issue Fixes #90988. The pin gap handling is wrong in the original code. Signed-off-by: Chekhov Ma --- drivers/gpio/gpio_adp5585.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio_adp5585.c b/drivers/gpio/gpio_adp5585.c index 3011120726e..8b7776407bf 100644 --- a/drivers/gpio/gpio_adp5585.c +++ b/drivers/gpio/gpio_adp5585.c @@ -76,8 +76,7 @@ static int gpio_adp5585_config(const struct device *dev, gpio_pin_t pin, gpio_fl uint8_t reg_value; /* ADP5585 has non-contiguous gpio pin layouts, account for this */ - if ((pin & cfg->common.port_pin_mask) == 0) { - LOG_ERR("pin %d is invalid for this device", pin); + if ((BIT(pin) & cfg->common.port_pin_mask) == 0) { return -ENOTSUP; } @@ -225,6 +224,11 @@ static int gpio_adp5585_port_write(const struct device *dev, gpio_port_pins_t ma uint8_t reg_value; int ret; + /* ADP5585 has non-contiguous gpio pin layouts, account for this */ + if ((mask & cfg->common.port_pin_mask) == 0) { + return -ENOTSUP; + } + /* Can't do I2C bus operations from an ISR */ if (k_is_in_isr()) { return -EWOULDBLOCK; @@ -288,8 +292,7 @@ static int gpio_adp5585_pin_interrupt_configure(const struct device *dev, gpio_p } /* ADP5585 has non-contiguous gpio pin layouts, account for this */ - if ((pin & cfg->common.port_pin_mask) == 0) { - LOG_ERR("pin %d is invalid for this device", pin); + if ((BIT(pin) & cfg->common.port_pin_mask) == 0) { return -ENOTSUP; }