diff --git a/drivers/gpio/axp_gpio.c b/drivers/gpio/axp_gpio.c index f9b78efbb51..61a227081d7 100644 --- a/drivers/gpio/axp_gpio.c +++ b/drivers/gpio/axp_gpio.c @@ -25,6 +25,7 @@ struct axp_gpio_desc { u8 npins; u8 status_reg; u8 status_offset; + u8 pull_reg; u8 input_mux; }; @@ -61,10 +62,21 @@ static int axp_gpio_get_function(struct udevice *dev, unsigned pin) static int axp_gpio_set_flags(struct udevice *dev, unsigned pin, ulong flags) { const struct axp_gpio_desc *desc = dev_get_priv(dev); + bool pull_down = flags & GPIOD_PULL_DOWN; + int ret; u8 mux; - if (flags & (GPIOD_MASK_DSTYPE | GPIOD_MASK_PULL)) + if (flags & (GPIOD_MASK_DSTYPE | GPIOD_PULL_UP)) return -EINVAL; + if (pull_down && !desc->pull_reg) + return -EINVAL; + + if (desc->pull_reg) { + ret = pmic_clrsetbits(dev->parent, desc->pull_reg, + BIT(pin), pull_down ? BIT(pin) : 0); + if (ret) + return ret; + } if (flags & GPIOD_IS_IN) mux = desc->input_mux; @@ -130,6 +142,7 @@ static const struct axp_gpio_desc axp221_gpio_desc = { .pins = axp221_gpio_pins, .npins = ARRAY_SIZE(axp221_gpio_pins), .status_reg = 0x94, + .pull_reg = 0x97, .input_mux = 2, };