driver: gpio: npcx: force io type as open-drain if select to 1p8v.
During configuring the low-voltage power supply of IO pads, the npcx GPIO driver needs to set the related PORTx_OUT_TYPE bit to 1, i.e. select to 'Open Drain IO type', also. This CL provides a mechanism that configuring these bits via 'def-lvol-io-list' node automatically in case the flag of gpios that have been configured to low-voltage power supply doesn't contain GPIO_OPEN_DRAIN. Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
This commit is contained in:
parent
478822f74c
commit
0d50628af9
3 changed files with 31 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue