diff --git a/drivers/gpio/gpio_npcx.c b/drivers/gpio/gpio_npcx.c index e496ca9412d..b5c21c321a8 100644 --- a/drivers/gpio/gpio_npcx.c +++ b/drivers/gpio/gpio_npcx.c @@ -90,6 +90,7 @@ void npcx_gpio_disable_io_pads(const struct device *dev, int pin) static int gpio_npcx_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags) { + const struct gpio_npcx_config *const config = DRV_CONFIG(dev); struct gpio_reg *const inst = HAL_INSTANCE(dev); uint32_t mask = BIT(pin); @@ -112,6 +113,15 @@ static int gpio_npcx_config(const struct device *dev, if ((flags & GPIO_OUTPUT) == 0) inst->PDIR &= ~mask; + /* + * If this IO pad is configured for low-voltage power supply, the GPIO + * driver must set the related PORTx_OUT_TYPE bit to 1 (i.e. select io + * type to open-drain) also. + */ + if (npcx_lvol_is_enabled(config->port, pin)) { + flags |= GPIO_OPEN_DRAIN; + } + /* Select open drain 0:push-pull 1:open-drain */ if ((flags & GPIO_OPEN_DRAIN) != 0) inst->PTYPE |= mask; diff --git a/soc/arm/nuvoton_npcx/common/scfg.c b/soc/arm/nuvoton_npcx/common/scfg.c index 3f1aa026403..b577a01818e 100644 --- a/soc/arm/nuvoton_npcx/common/scfg.c +++ b/soc/arm/nuvoton_npcx/common/scfg.c @@ -127,6 +127,18 @@ void npcx_lvol_suspend_io_pads(void) } } +bool npcx_lvol_is_enabled(int port, int pin) +{ + for (int i = 0; i < ARRAY_SIZE(def_lvols); i++) { + if (def_lvols[i].io_port == port && + def_lvols[i].io_bit == pin) { + return true; + } + } + + return false; +} + void npcx_pinctrl_i2c_port_sel(int controller, int port) { struct glue_reg *const inst_glue = HAL_GLUE_INST(); diff --git a/soc/arm/nuvoton_npcx/common/soc_pins.h b/soc/arm/nuvoton_npcx/common/soc_pins.h index d0b8b16a52b..7bcc270d870 100644 --- a/soc/arm/nuvoton_npcx/common/soc_pins.h +++ b/soc/arm/nuvoton_npcx/common/soc_pins.h @@ -158,6 +158,15 @@ void npcx_lvol_restore_io_pads(void); */ void npcx_lvol_suspend_io_pads(void); +/** + * @brief Get the low-voltage power supply status of GPIO pads + * + * @param port port index of GPIO device + * @param pin pin of GPIO device + * @return 1 means the low-voltage power supply is enabled, otherwise disabled. + */ +bool npcx_lvol_is_enabled(int port, int pin); + #ifdef __cplusplus } #endif