Skip to content

Commit d1fc8c7

Browse files
kartbendkalowsk
authored andcommitted
drivers: gpio: rpi_pico: add missing offsets
Fixed several occurrences of offset not being calculated in case multiple GPIO ports are present. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
1 parent b10d56e commit d1fc8c7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/gpio/gpio_rpi_pico.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ static int gpio_rpi_configure(const struct device *dev,
128128
struct gpio_rpi_data *data = dev->data;
129129

130130
if (flags == GPIO_DISCONNECTED) {
131-
gpio_disable_pulls(pin);
131+
gpio_disable_pulls(pin + offset);
132132
/* This is almost the opposite of the Pico SDK's gpio_set_function. */
133-
hw_write_masked(&pads_bank0_hw->io[pin], PADS_BANK0_GPIO0_OD_BITS,
133+
hw_write_masked(&pads_bank0_hw->io[pin + offset], PADS_BANK0_GPIO0_OD_BITS,
134134
PADS_BANK0_GPIO0_IE_BITS | PADS_BANK0_GPIO0_OD_BITS);
135135
#ifdef CONFIG_SOC_SERIES_RP2350
136-
hw_set_bits(&pads_bank0_hw->io[pin], PADS_BANK0_GPIO0_ISO_BITS);
136+
hw_set_bits(&pads_bank0_hw->io[pin + offset], PADS_BANK0_GPIO0_ISO_BITS);
137137
#endif
138138
return 0;
139139
}
@@ -205,7 +205,7 @@ static int gpio_rpi_get_config(const struct device *dev, gpio_pin_t pin, gpio_fl
205205
}
206206
}
207207

208-
if (pads_bank0_hw->io[pin] & PADS_BANK0_GPIO0_IE_BITS) {
208+
if (pads_bank0_hw->io[pin + offset] & PADS_BANK0_GPIO0_IE_BITS) {
209209
*flags |= GPIO_INPUT;
210210
}
211211

@@ -340,14 +340,16 @@ static uint32_t gpio_rpi_get_pending_int(const struct device *dev)
340340
static int gpio_rpi_port_get_direction(const struct device *port, gpio_port_pins_t map,
341341
gpio_port_pins_t *inputs, gpio_port_pins_t *outputs)
342342
{
343+
const int offset = GPIO_RPI_PINS_PER_PORT * PORT_NO(port);
344+
343345
/* The Zephyr API considers a disconnected pin to be neither an input nor output.
344346
* Since we disable both OE and IE for disconnected pins clear the mask bits.
345347
*/
346348
for (int pin = 0; pin < NUM_BANK0_GPIOS; pin++) {
347-
if (pads_bank0_hw->io[pin] & PADS_BANK0_GPIO0_OD_BITS) {
349+
if (pads_bank0_hw->io[pin + offset] & PADS_BANK0_GPIO0_OD_BITS) {
348350
map &= ~BIT(pin);
349351
}
350-
if (inputs && (pads_bank0_hw->io[pin] & PADS_BANK0_GPIO0_IE_BITS)) {
352+
if (inputs && (pads_bank0_hw->io[pin + offset] & PADS_BANK0_GPIO0_IE_BITS)) {
351353
*inputs |= BIT(pin);
352354
}
353355
}

0 commit comments

Comments
 (0)