Introduce regulator_set_enable_if_allowed()
v2 cover Introduce regulator_set_enable_if_allowed()
As per the discussion happenned here[1], introducing a new api regulator_set_enable_if_allowed() that discards certain error cases where consumer driver might not be intrested in. Also using the same api for omap_hsmmc driver which fixes the boot on dra7-evm.
[1] https://patchwork.ozlabs.org/patch/1018222/
Changes since v1:
- Add dm test for regulator_set_enable_if_allowed.
Lokesh Vutla (3):
Revert "power: regulator: Return success on attempt to disable an
always-on regulator"
power: regulator: Introduce regulator_set_enable_if_allowed api
mmc: omap_hsmmc: Use regulator_set_enable_if_allowed for enabling
regulator
drivers/mmc/omap_hsmmc.c | 16 ++++++++-------- drivers/power/regulator/regulator-uclass.c | 13 ++++++++++++- include/power/regulator.h | 11 +++++++++++ test/dm/regulator.c | 21 +++++++++++++++++++++ 4 files changed, 52 insertions(+), 9 deletions(-)
Signature · 1 line
2.19.2
PATCH v2 1/3 Revert "power: regulator: Return success on attempt to disable an always-on regulator"
This reverts commit e17e0ceb83538c015a50b965547f2f4d38f81c5d.
It is advised to return an error when trying to disable an always-on regulator and let the consumer driver handle the error if needed.
--- drivers/power/regulator/regulator-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/regulator/regulator-uclass.c +1 -1
@@ -113,7 +113,7 @@ int regulator_set_enable(struct udevice *dev, bool enable) uc_pdata =dev_get_uclass_platdata (dev);if (!enable && uc_pdata->always_on) -return 0 ; +return -EACCES ;return ops->set_enable (dev, enable); }
Signature · 1 line
2.19.2
PATCH v2 1/3 Revert "power: regulator: Return success on attempt to disable an always-on regulator"
Quoted 11 lines · Lokesh Vutla
This reverts commit
e17e0ceb83538c015a50b965547f2f4d38f81c5d.It is advised to return an error when trying to disable an always-on regulator and let the consumer driver handle the error if needed.
Reviewed-by Simon Glass <[email protected]>Signed-off-by Lokesh Vutla <[email protected]>--- drivers/power/regulator/regulator-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm, thanks!
PATCH v2 2/3 power: regulator: Introduce regulator_set_enable_if_allowed api
In reply to Lokesh Vutlaregulator_set_enable() api throws an error in the following three cases:
- when requested to disable an always-on regulator
- when set_enable() ops not provided by regulator driver
- when enabling is actually failed.(Error returned by the regulator driver)
Sometimes consumer drivers doesn't want to track the first two scenarios and just need to worry about the case where enabling is actually failed. But it is also a good practice to have an error value returned in the first two cases.
So introduce an api regulator_set_enable_if_allowed() which ignores the first two error cases and returns an error as given by regulator driver. Consumer drivers can use this api need not worry about the first two error conditions.
--- drivers/power/regulator/regulator-uclass.c | 11 +++++++++++ include/power/regulator.h | 11 +++++++++++ test/dm/regulator.c | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+)
drivers/power/regulator/regulator-uclass.c +11 -0
@@ -118,6 +118,17 @@ int regulator_set_enable(struct udevice *dev, bool enable)return ops->set_enable (dev, enable); } +int regulator_set_enable_if_allowed (struct udevice *dev,bool enable) +{ +int ret; + + ret =regulator_set_enable (dev, enable); +if (ret == -ENOSYS || ret == -EACCES ) +return 0 ; + +return ret; +} +int regulator_get_mode (struct udevice *dev) {const struct dm_regulator_ops *ops =dev_get_driver_ops (dev);
include/power/regulator.h +11 -0
@@ -303,6 +303,17 @@ int regulator_get_enable(struct udevice *dev);*/ int regulator_set_enable (struct udevice *dev,bool enable); +/** +* regulator_set_enable_if_allowed: set regulator enable state if allowed by +* regulator +* +* @dev - pointer to the regulator device +* @enable - set true or false +* @return - 0 on success or if enabling is not supported +* -errno val if fails. +*/ +int regulator_set_enable_if_allowed (struct udevice *dev,bool enable); +/** * regulator_get_mode: get active operation mode id of a given regulator *
test/dm/regulator.c +21 -0
@@ -175,6 +175,27 @@ static int dm_test_power_regulator_set_get_enable(struct unit_test_state *uts) }DM_TEST (dm_test_power_regulator_set_get_enable,DM_TESTF_SCAN_FDT ); +/* Test regulator set and get enable if allowed method */ +static +int dm_test_power_regulator_set_enable_if_allowed (struct unit_test_state *uts) +{ +const char *platname; +struct udevice *dev, *dev_autoset; +bool val_set = false; + +/* Get BUCK1 - always on regulator */ + platname = regulator_names[BUCK1 ][PLATNAME ]; +ut_assertok (regulator_autoset_by_name (platname, &dev_autoset)); +ut_assertok (regulator_get_by_platname (platname, &dev)); + +/* Try disabling always-on regulator */ +ut_assertok (regulator_set_enable_if_allowed (dev, val_set)); +ut_asserteq (regulator_get_enable (dev), !val_set); + +return 0 ; +} +DM_TEST (dm_test_power_regulator_set_enable_if_allowed,DM_TESTF_SCAN_FDT ); +/* Test regulator set and get mode method */ static int dm_test_power_regulator_set_get_mode (struct unit_test_state *uts) {
Signature · 1 line
2.19.2
PATCH v2 2/3 power: regulator: Introduce regulator_set_enable_if_allowed api
Quoted 16 lines · Lokesh Vutla
regulator_set_enable()api throws an error in the following three cases:
- when requested to disable an always-on regulator
- whenset_enable()ops not provided by regulator driver
- when enabling is actually failed.(Error returned by the regulator driver)Sometimes consumer drivers doesn't want to track the first two scenarios and just need to worry about the case where enabling is actually failed. But it is also a good practice to have an error value returned in the first two cases.
So introduce an api
regulator_set_enable_if_allowed()which ignores the first two error cases and returns an error as given by regulator driver. Consumer drivers can use this api need not worry about the first two error conditions.
Quoted 6 lines
Signed-off-by Lokesh Vutla <[email protected]>--- drivers/power/regulator/regulator-uclass.c | 11 +++++++++++ include/power/regulator.h | 11 +++++++++++ test/dm/regulator.c | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+)
PATCH v2 2/3 power: regulator: Introduce regulator_set_enable_if_allowed api
Quoted 16 lines · Lokesh Vutla
regulator_set_enable()api throws an error in the following three cases:
- when requested to disable an always-on regulator
- whenset_enable()ops not provided by regulator driver
- when enabling is actually failed.(Error returned by the regulator driver)Sometimes consumer drivers doesn't want to track the first two scenarios and just need to worry about the case where enabling is actually failed. But it is also a good practice to have an error value returned in the first two cases.
So introduce an api
regulator_set_enable_if_allowed()which ignores the first two error cases and returns an error as given by regulator driver. Consumer drivers can use this api need not worry about the first two error conditions.
Quoted 6 lines
Signed-off-by Lokesh Vutla <[email protected]>--- drivers/power/regulator/regulator-uclass.c | 11 +++++++++++ include/power/regulator.h | 11 +++++++++++ test/dm/regulator.c | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+)
Applied to u-boot-dm, thanks!
PATCH v2 3/3 mmc: omap_hsmmc: Use regulator_set_enable_if_allowed for enabling regulator
In reply to Lokesh VutlaUse regulator_set_enable_if_allowed() api instead of regulator_set_enable() while enabling io regulators. This way the driver doesn't see an error when disabling an always-on regulator and when enabling is not supported.
--- drivers/mmc/omap_hsmmc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/mmc/omap_hsmmc.c +8 -8
@@ -470,21 +470,21 @@ static int omap_hsmmc_set_io_regulator(struct mmc *mmc, int mV)return 0 ;/* Disable PBIAS */ - ret =regulator_set_enable (priv->pbias_supply, false); -if (ret && ret != -ENOSYS ) + ret =regulator_set_enable_if_allowed (priv->pbias_supply, false); +if (ret)return ret;/* Turn off IO voltage */ - ret =regulator_set_enable (mmc->vqmmc_supply, false); -if (ret && ret != -ENOSYS ) + ret =regulator_set_enable_if_allowed (mmc->vqmmc_supply, false); +if (ret)return ret;/* Program a new IO voltage value */ ret =regulator_set_value (mmc->vqmmc_supply, uV);if (ret)return ret;/* Turn on IO voltage */ - ret =regulator_set_enable (mmc->vqmmc_supply, true); -if (ret && ret != -ENOSYS ) + ret =regulator_set_enable_if_allowed (mmc->vqmmc_supply, true); +if (ret)return ret;/* Program PBIAS voltage*/
@@ -492,8 +492,8 @@ static int omap_hsmmc_set_io_regulator(struct mmc *mmc, int mV)if (ret && ret != -ENOSYS )return ret;/* Enable PBIAS */ - ret =regulator_set_enable (priv->pbias_supply, true); -if (ret && ret != -ENOSYS ) + ret =regulator_set_enable_if_allowed (priv->pbias_supply, true); +if (ret)return ret;return 0 ;
Signature · 1 line
2.19.2
PATCH v2 3/3 mmc: omap_hsmmc: Use regulator_set_enable_if_allowed for enabling regulator
Use regulator_set_enable_if_allowed() api instead of regulator_set_enable() while enabling io regulators. This way the driver doesn't see an error when disabling an always-on regulator and when enabling is not supported.
--- drivers/mmc/omap_hsmmc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Applied to u-boot-dm, thanks!