From 96da6f2234678a030b5a27e2cfffffe9ad2352f2 Mon Sep 17 00:00:00 2001 From: Ravik Hasija Date: Thu, 22 Sep 2022 13:03:50 -0700 Subject: [PATCH] driver: dw: Use base_addr variable to set dir. Change Summary: Update Base addr to set direction to use Aligned IP base address instead of Port Base Address. Port Base Address + offset to direction register will set incorrect value for Port B,C & D. For ex: In cases when more than 1 port is configured on the same IP, the DTS node for port B will start at offset 0xC. Calculating the port using Port Base will yield offset of PORTB DIR register which is at offset 0x10 from Aligned Base, and as a result will result in setting DIR register of PORTC instead. Signed-off-by: Ravik Hasija --- drivers/gpio/gpio_dw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio_dw.c b/drivers/gpio/gpio_dw.c index 6b3687e7eef..cd1a97a6afa 100644 --- a/drivers/gpio/gpio_dw.c +++ b/drivers/gpio/gpio_dw.c @@ -196,7 +196,7 @@ static int gpio_dw_pin_interrupt_configure(const struct device *port, } /* Interrupt to be enabled but pin is not set to input */ - dir_reg = dw_read(port_base_addr, dir_port) & BIT(pin); + dir_reg = dw_read(base_addr, dir_port) & BIT(pin); if (dir_reg != 0U) { return -EINVAL; } @@ -245,7 +245,7 @@ static inline void dw_pin_config(const struct device *port, /* Set init value then direction */ pin_is_output = (flags & GPIO_OUTPUT) != 0U; - dw_set_bit(port_base_addr, dir_port, pin, pin_is_output); + dw_set_bit(base_addr, dir_port, pin, pin_is_output); if (pin_is_output) { if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0U) {