From 0a62701c1a5e13d86cea5390318659364fd088f6 Mon Sep 17 00:00:00 2001 From: songnannan Date: Tue, 21 Dec 2021 21:33:36 +0800 Subject: [PATCH] fix: regulator: set ioexpander direction in regulator gpio init. Signed-off-by: songnannan --- drivers/power/regulator_gpio.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/power/regulator_gpio.c b/drivers/power/regulator_gpio.c index 4d92389e3c..c53d80e28c 100644 --- a/drivers/power/regulator_gpio.c +++ b/drivers/power/regulator_gpio.c @@ -125,6 +125,7 @@ int regulator_gpio_init(FAR struct ioexpander_dev_s *iodev, FAR const struct regulator_desc_s *desc) { FAR struct regulator_gpio_priv *priv; + int ret; if (!iodev || !desc) { @@ -138,13 +139,24 @@ int regulator_gpio_init(FAR struct ioexpander_dev_s *iodev, } priv->iodev = iodev; - priv->rdev = regulator_register(desc, &g_regulator_gpio_ops, - priv); - if (!priv->rdev) + + ret = IOEXP_SETDIRECTION(priv->iodev, desc->enable_reg, + IOEXPANDER_DIRECTION_OUT); + if (ret >= 0) { - kmm_free(priv); - return -EINVAL; + priv->rdev = regulator_register(desc, + &g_regulator_gpio_ops, + priv); + if (priv->rdev == NULL) + { + ret = -EINVAL; + } } - return 0; + if (ret < 0) + { + kmm_free(priv); + } + + return ret; }