regulator: fix: Move code to enable gpio regulator to pre_probe from ofdata_to_platdata
authorLukasz Majewski <lukma@denx.de>
Sat, 25 Jan 2020 08:00:58 +0000 (09:00 +0100)
committerTom Rini <trini@konsulko.com>
Mon, 10 Feb 2020 23:00:38 +0000 (18:00 -0500)
The commit e8e9715df2d4 ("regulator: fixed: Modify enable-active-high behavior")
fixed the regulator driver behavior when 'enable-active-high' is defined.
Unfortunately, this patch used dm_regulator_platdata()'s "boot_on" member
to set GPIOD_IS_OUT_ACTIVE flag and enable the regulator.

The issue here is that regulator_common_ofdata_to_platdata() is called
_before_ regulator_pre_probe() function in which the 'regulator-boot-on'
property is asserted.

As a result the GPIOD_IS_OUT_ACTIVE flag is not set and gpio_request_by_name()
called in the former function is not enabling the regulator.
This is problematic for e.g. i.MX ethernet driver, which then tries to
perform initialization without power (and fails).

The solution here is to explicitly enable regulator in regulator_pre_probe()
callback only when 'regulator-boot-on' property is present in device tree.
The GPIOD_IS_OUT_ACTIVE flag is not set at all, but relevant gpio is
requested.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
Tested-by: Patrice Chotard <patrice.chotard@st.com>
drivers/power/regulator/regulator-uclass.c
drivers/power/regulator/regulator_common.c

index 90961de95c656d9790fed48221ddb0a289a3c9c3..c9d26344d78028eb599078d18b4a484c58c89bd6 100644 (file)
@@ -464,6 +464,9 @@ static int regulator_pre_probe(struct udevice *dev)
            (uc_pdata->min_uA == uc_pdata->max_uA))
                uc_pdata->flags |= REGULATOR_FLAG_AUTOSET_UA;
 
+       if (uc_pdata->boot_on)
+               regulator_set_enable(dev, uc_pdata->boot_on);
+
        return 0;
 }
 
index 939efb2c0d0d9ace36e74b95e59da8479a71c183..33b73b7c2f5eeb20feef6bee4ea3b22834f94ef3 100644 (file)
@@ -12,16 +12,11 @@ int regulator_common_ofdata_to_platdata(struct udevice *dev,
        struct regulator_common_platdata *dev_pdata, const char *enable_gpio_name)
 {
        struct gpio_desc *gpio;
-       struct dm_regulator_uclass_platdata *uc_pdata;
        int flags = GPIOD_IS_OUT;
        int ret;
 
-       uc_pdata = dev_get_uclass_platdata(dev);
-
        if (!dev_read_bool(dev, "enable-active-high"))
                flags |= GPIOD_ACTIVE_LOW;
-       if (uc_pdata->boot_on)
-               flags |= GPIOD_IS_OUT_ACTIVE;
 
        /* Get optional enable GPIO desc */
        gpio = &dev_pdata->gpio;