From 4ddfebd3b0d5b65c69492408bb67fd1202104643 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 13 Sep 2013 19:50:37 +0100 Subject: regulator: core: Provide a dummy regulator with full constraints When a system has said that it has fully specified constraints for its regulators it is still possible that some supplies may be missing, especially if regulator support has been added to a driver after the board was integrated. We can handle such situations more gracefully by providing a dummy regulator. Unless the caller has specifically indicated that the system design may not include a given regulator by using regulator_get_optional() or that it needs its interactions to have an effect using regulator_get_exclusive() provide a dummy regulator if we can't locate a real one. The kconfig option REGULATOR_DUMMY that provided similar behaviour for all regulators has been removed, systems that need it should flag that they have full constraints instead. Signed-off-by: Mark Brown --- drivers/regulator/Kconfig | 10 ---------- drivers/regulator/core.c | 36 +++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 27 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index dfe58096b374..0417ce327cd8 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -28,16 +28,6 @@ config REGULATOR_DEBUG help Say yes here to enable debugging support. -config REGULATOR_DUMMY - bool "Provide a dummy regulator if regulator lookups fail" - help - If this option is enabled then when a regulator lookup fails - and the board has not specified that it has provided full - constraints the regulator core will provide an always - enabled dummy regulator, allowing consumer drivers to continue. - - A warning will be generated when this substitution is done. - config REGULATOR_FIXED_VOLTAGE tristate "Fixed voltage regulator support" help diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index a01b8b3b70ca..8fd170788c3e 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1243,7 +1243,7 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev, /* Internal regulator request function */ static struct regulator *_regulator_get(struct device *dev, const char *id, - bool exclusive) + bool exclusive, bool allow_dummy) { struct regulator_dev *rdev; struct regulator *regulator = ERR_PTR(-EPROBE_DEFER); @@ -1268,30 +1268,32 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, * If we have return value from dev_lookup fail, we do not expect to * succeed, so, quit with appropriate error value */ - if (ret) { + if (ret && ret != -ENODEV) { regulator = ERR_PTR(ret); goto out; } - if (board_wants_dummy_regulator) { - rdev = dummy_regulator_rdev; - goto found; - } - -#ifdef CONFIG_REGULATOR_DUMMY if (!devname) devname = "deviceless"; - /* If the board didn't flag that it was fully constrained then - * substitute in a dummy regulator so consumers can continue. + /* + * Assume that a regulator is physically present and enabled + * even if it isn't hooked up and just provide a dummy. */ - if (!has_full_constraints) { - pr_warn("%s supply %s not found, using dummy regulator\n", - devname, id); + if (has_full_constraints && allow_dummy) { + /* + * Log the substitution if regulator configuration is + * not complete to help development. + */ + if (!has_full_constraints) + pr_warn("%s supply %s not found, using dummy regulator\n", + devname, id); + rdev = dummy_regulator_rdev; goto found; + } else { + dev_err(dev, "dummy supplies not allowed\n"); } -#endif mutex_unlock(®ulator_list_mutex); return regulator; @@ -1349,7 +1351,7 @@ out: */ struct regulator *regulator_get(struct device *dev, const char *id) { - return _regulator_get(dev, id, false); + return _regulator_get(dev, id, false, true); } EXPORT_SYMBOL_GPL(regulator_get); @@ -1410,7 +1412,7 @@ EXPORT_SYMBOL_GPL(devm_regulator_get); */ struct regulator *regulator_get_exclusive(struct device *dev, const char *id) { - return _regulator_get(dev, id, true); + return _regulator_get(dev, id, true, false); } EXPORT_SYMBOL_GPL(regulator_get_exclusive); @@ -1439,7 +1441,7 @@ EXPORT_SYMBOL_GPL(regulator_get_exclusive); */ struct regulator *regulator_get_optional(struct device *dev, const char *id) { - return _regulator_get(dev, id, 0); + return _regulator_get(dev, id, false, false); } EXPORT_SYMBOL_GPL(regulator_get_optional); -- cgit v1.2.3-70-g09d2 From 4f0ac6dabf867095b31f851ba0d0ceaca2f87e2e Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 13 Sep 2013 19:51:47 +0100 Subject: regulator: core: Remove unused regulator_use_dummy_regulator() No boards have used this functionality and the new default of providing dummy regulators by default provides a better solution to the problem it was trying to solve. Signed-off-by: Mark Brown --- drivers/regulator/core.c | 17 ----------------- include/linux/regulator/machine.h | 5 ----- 2 files changed, 22 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 8fd170788c3e..ac3a864d3635 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -53,7 +53,6 @@ static LIST_HEAD(regulator_list); static LIST_HEAD(regulator_map_list); static LIST_HEAD(regulator_ena_gpio_list); static bool has_full_constraints; -static bool board_wants_dummy_regulator; static struct dentry *debugfs_root; @@ -3615,22 +3614,6 @@ void regulator_has_full_constraints(void) } EXPORT_SYMBOL_GPL(regulator_has_full_constraints); -/** - * regulator_use_dummy_regulator - Provide a dummy regulator when none is found - * - * Calling this function will cause the regulator API to provide a - * dummy regulator to consumers if no physical regulator is found, - * allowing most consumers to proceed as though a regulator were - * configured. This allows systems such as those with software - * controllable regulators for the CPU core only to be brought up more - * readily. - */ -void regulator_use_dummy_regulator(void) -{ - board_wants_dummy_regulator = true; -} -EXPORT_SYMBOL_GPL(regulator_use_dummy_regulator); - /** * rdev_get_drvdata - get rdev regulator driver data * @rdev: regulator diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index 999b20ce06cf..a9f7c55a4d4d 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -193,15 +193,10 @@ int regulator_suspend_finish(void); #ifdef CONFIG_REGULATOR void regulator_has_full_constraints(void); -void regulator_use_dummy_regulator(void); #else static inline void regulator_has_full_constraints(void) { } - -static inline void regulator_use_dummy_regulator(void) -{ -} #endif #endif -- cgit v1.2.3-70-g09d2 From 9b92da1f1205bd2591487051a93624dd6c258eef Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 20 Sep 2013 12:23:30 +0100 Subject: regulator: core: Fix default return value for _get() Now that we are defaulting to providing dummy regulators fix the logic for substituting a dummy by making the default return code -EPROBE_DEFER. Reported-by: Thierry Reding Tested-by: Thierry Reding Signed-off-by: Mark Brown --- drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index ac3a864d3635..088b41ac9506 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1247,7 +1247,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, struct regulator_dev *rdev; struct regulator *regulator = ERR_PTR(-EPROBE_DEFER); const char *devname = NULL; - int ret = 0; + int ret = -EPROBE_DEFER; if (id == NULL) { pr_err("get() with no identifier\n"); -- cgit v1.2.3-70-g09d2 From ef60abbb6b406389245225ab4acfe73f66e7d92c Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 23 Sep 2013 16:12:52 +0100 Subject: regulator: core: Always use return value when regulator_dev_lookup() fails Ensure that the return value is always set when we return now that the logic has changed for regulator_get_optional() so we don't get missing codes leaking out. Reported-by: Thierry Reding Tested-by: Thierry Reding Signed-off-by: Mark Brown --- drivers/regulator/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 088b41ac9506..a40055edaae4 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1263,12 +1263,13 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, if (rdev) goto found; + regulator = ERR_PTR(ret); + /* * If we have return value from dev_lookup fail, we do not expect to * succeed, so, quit with appropriate error value */ if (ret && ret != -ENODEV) { - regulator = ERR_PTR(ret); goto out; } -- cgit v1.2.3-70-g09d2 From 4040394e12cb1eed21d1306cacdc8a6f0464c8e2 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 4 Oct 2013 11:42:53 +0100 Subject: regulator: core: Always warn when using a dummy regulator This helps people spot if they have missed a supply from a device tree or equivalent data structure. Suggested-by: Stephen Warren Signed-off-by: Mark Brown --- drivers/regulator/core.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'drivers/regulator') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index a40055edaae4..82805e2d8a64 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1281,13 +1281,8 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, * even if it isn't hooked up and just provide a dummy. */ if (has_full_constraints && allow_dummy) { - /* - * Log the substitution if regulator configuration is - * not complete to help development. - */ - if (!has_full_constraints) - pr_warn("%s supply %s not found, using dummy regulator\n", - devname, id); + pr_warn("%s supply %s not found, using dummy regulator\n", + devname, id); rdev = dummy_regulator_rdev; goto found; -- cgit v1.2.3-70-g09d2