From d1fc8c7f29b0ddb8f58e695ffc43b62c873da136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Mon, 9 Jun 2025 21:29:36 +0200 Subject: [PATCH] drivers: gpio: rpi_pico: add missing offsets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed several occurrences of offset not being calculated in case multiple GPIO ports are present. Signed-off-by: Benjamin Cabé --- drivers/gpio/gpio_rpi_pico.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpio_rpi_pico.c b/drivers/gpio/gpio_rpi_pico.c index 6e8098381d3..7c556b9e45e 100644 --- a/drivers/gpio/gpio_rpi_pico.c +++ b/drivers/gpio/gpio_rpi_pico.c @@ -128,12 +128,12 @@ static int gpio_rpi_configure(const struct device *dev, struct gpio_rpi_data *data = dev->data; if (flags == GPIO_DISCONNECTED) { - gpio_disable_pulls(pin); + gpio_disable_pulls(pin + offset); /* This is almost the opposite of the Pico SDK's gpio_set_function. */ - hw_write_masked(&pads_bank0_hw->io[pin], PADS_BANK0_GPIO0_OD_BITS, + hw_write_masked(&pads_bank0_hw->io[pin + offset], PADS_BANK0_GPIO0_OD_BITS, PADS_BANK0_GPIO0_IE_BITS | PADS_BANK0_GPIO0_OD_BITS); #ifdef CONFIG_SOC_SERIES_RP2350 - hw_set_bits(&pads_bank0_hw->io[pin], PADS_BANK0_GPIO0_ISO_BITS); + hw_set_bits(&pads_bank0_hw->io[pin + offset], PADS_BANK0_GPIO0_ISO_BITS); #endif return 0; } @@ -205,7 +205,7 @@ static int gpio_rpi_get_config(const struct device *dev, gpio_pin_t pin, gpio_fl } } - if (pads_bank0_hw->io[pin] & PADS_BANK0_GPIO0_IE_BITS) { + if (pads_bank0_hw->io[pin + offset] & PADS_BANK0_GPIO0_IE_BITS) { *flags |= GPIO_INPUT; } @@ -340,14 +340,16 @@ static uint32_t gpio_rpi_get_pending_int(const struct device *dev) static int gpio_rpi_port_get_direction(const struct device *port, gpio_port_pins_t map, gpio_port_pins_t *inputs, gpio_port_pins_t *outputs) { + const int offset = GPIO_RPI_PINS_PER_PORT * PORT_NO(port); + /* The Zephyr API considers a disconnected pin to be neither an input nor output. * Since we disable both OE and IE for disconnected pins clear the mask bits. */ for (int pin = 0; pin < NUM_BANK0_GPIOS; pin++) { - if (pads_bank0_hw->io[pin] & PADS_BANK0_GPIO0_OD_BITS) { + if (pads_bank0_hw->io[pin + offset] & PADS_BANK0_GPIO0_OD_BITS) { map &= ~BIT(pin); } - if (inputs && (pads_bank0_hw->io[pin] & PADS_BANK0_GPIO0_IE_BITS)) { + if (inputs && (pads_bank0_hw->io[pin + offset] & PADS_BANK0_GPIO0_IE_BITS)) { *inputs |= BIT(pin); } }