regulator: core: Provide hints to the core about optional supplies
Subsystems (4)
Mark Brown
maintainerPATCH 1/5 regulator: core: Provide hints to the core about optional supplies
From: Mark Brown <[email protected]>
While the majority of supplies on devices are mandatory and can't be physically omitted for electrical reasons some devices do have optional supplies and need to know if they are missing, MMC being the most common of these.
Currently the core accurately reports all errors when regulators are requested since it does not know if the supply is one that must be provided even if by a regulator software does not know about or if it is one that may genuinely be disconnected. In order to allow this behaviour to be changed and stub regulators to be provided in the former case add a new regulator request function regulator_get_optional() which provides a hint to the core that the regulator may genuinely not be connected.
Currently the implementation is identical to the current behaviour, future patches will add support in the core for returning stub regulators in the case where normal regulator_get() fails and the board has requested it.
--- drivers/regulator/core.c | 59 ++++++++++++++++++++++++++++++++++++++ include/linux/regulator/consumer.h | 18 +++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-)
drivers/regulator/core.c +59 -0
@@ -1414,6 +1414,65 @@ struct regulator *regulator_get_exclusive(struct device *dev, const char *id) }EXPORT_SYMBOL_GPL (regulator_get_exclusive); +/** +* regulator_get_optional - obtain optional access to a regulator. +* @dev: device for regulator "consumer" +* @id: Supply name or regulator ID. +* +* Returns a struct regulator corresponding to the regulator producer, +* or IS_ERR() condition containing errno. Other consumers will be +* unable to obtain this reference is held and the use count for the +* regulator will be initialised to reflect the current state of the +* regulator. +* +* This is intended for use by consumers for devices which can have +* some supplies unconnected in normal use, such as some MMC devices. +* It can allow the regulator core to provide stub supplies for other +* supplies requested using normal regulator_get() calls without +* disrupting the operation of drivers that can handle absent +* supplies. +* +* Use of supply names configured via regulator_set_device_supply() is +* strongly encouraged. It is recommended that the supply name used +* should match the name used for the supply and/or the relevant +* device pins in the datasheet. +*/ +struct regulator *regulator_get_optional (struct device *dev,const char *id) +{ +return _regulator_get (dev, id,0 ); +} +EXPORT_SYMBOL_GPL (regulator_get_optional); + +/** +* devm_regulator_get_optional - Resource managed regulator_get_optional() +* @dev: device for regulator "consumer" +* @id: Supply name or regulator ID. +* +* Managed regulator_get_optional(). Regulators returned from this +* function are automatically regulator_put() on driver detach. See +* regulator_get_optional() for more information. +*/ +struct regulator *devm_regulator_get_optional (struct device *dev, +const char *id) +{ +struct regulator **ptr, *regulator; + + ptr =devres_alloc (devm_regulator_release,sizeof (*ptr),GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + regulator =regulator_get_optional (dev, id); +if (!IS_ERR (regulator)) { + *ptr = regulator; +devres_add (dev, ptr); + }else { +devres_free (ptr); + } + +return regulator; +} +EXPORT_SYMBOL_GPL (devm_regulator_get_optional); +/* Locks held by regulator_put() */ static void _regulator_put (struct regulator *regulator) {
include/linux/regulator/consumer.h +17 -1
@@ -137,6 +137,10 @@ struct regulator *__must_check devm_regulator_get(struct device *dev, const char *id);struct regulator *__must_check regulator_get_exclusive (struct device *dev,const char *id); +struct regulator *__must_check regulator_get_optional (struct device *dev, +const char *id); +struct regulator *__must_check devm_regulator_get_optional (struct device *dev, +const char *id);void regulator_put (struct regulator *regulator);void devm_regulator_put (struct regulator *regulator);
@@ -212,14 +216,26 @@ static inline struct regulator *__must_check regulator_get(struct device *dev, }static inline struct regulator *__must_check +devm_regulator_get (struct device *dev,const char *id) +{ +return NULL ; +} + +static inline struct regulator *__must_check regulator_get_exclusive (struct device *dev,const char *id) {return NULL ; } +static inline struct regulator *__must_check +regulator_get_optional (struct device *dev,const char *id) +{ +return NULL ; +} +static inline struct regulator *__must_check -devm_regulator_get (struct device *dev,const char *id) +devm_regulator_get_optional (struct device *dev,const char *id) {return NULL ; }
Signature · 1 line
1.8.3.2
Mark Brown
maintainerPATCH 2/5 mmc: core: Indicate that vmmcq may be absent
From: Mark Brown <[email protected]>
Use regulator_get_optional() to tell the core that requests for the vmmcq regulator can fail in a real system.
--- drivers/mmc/core/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/core.c +1 -1
@@ -1313,7 +1313,7 @@ int mmc_regulator_get_supply(struct mmc_host *mmc) supply =devm_regulator_get (dev,"vmmc" ); mmc->supply.vmmc = supply; - mmc->supply.vqmmc =devm_regulator_get (dev,"vqmmc" ); + mmc->supply.vqmmc =devm_regulator_get_optional (dev,"vqmmc" );if (IS_ERR (supply))return PTR_ERR (supply);
Signature · 1 line
1.8.3.2
Mark Brown
maintainerPATCH 3/5 mmc: sdhci: Indicate that regulators may be absent
In reply to Mark BrownFrom: Mark Brown <[email protected]>
Use regulator_get_optional() to tell the core that requests for regulators can fail in a real system.
--- drivers/mmc/host/sdhci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +2 -2
@@ -2966,7 +2966,7 @@ int sdhci_add_host(struct sdhci_host *host) mmc->caps |=MMC_CAP_NEEDS_POLL ;/* If vqmmc regulator and no 1.8V signalling, then there's no UHS */ - host->vqmmc =regulator_get (mmc_dev (mmc),"vqmmc" ); + host->vqmmc =regulator_get_optional (mmc_dev (mmc),"vqmmc" );if (IS_ERR_OR_NULL (host->vqmmc)) {if (PTR_ERR (host->vqmmc) <0 ) { pr_info("%s: no vqmmc regulator found\n",
@@ -3042,7 +3042,7 @@ int sdhci_add_host(struct sdhci_host *host) ocr_avail =0 ; - host->vmmc =regulator_get (mmc_dev (mmc),"vmmc" ); + host->vmmc =regulator_get_optional (mmc_dev (mmc),"vmmc" );if (IS_ERR_OR_NULL (host->vmmc)) {if (PTR_ERR (host->vmmc) <0 ) { pr_info("%s: no vmmc regulator found\n",
Signature · 1 line
1.8.3.2
Mark Brown
maintainerPATCH 4/5 mmc: dw_mmc: Indicate that regulators may be absent
In reply to Mark BrownFrom: Mark Brown <[email protected]>
Use regulator_get_optional() to tell the core that requests for regulators can fail in a real system.
--- drivers/mmc/host/dw_mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/dw_mmc.c +1 -1
@@ -2231,7 +2231,7 @@ int dw_mci_probe(struct dw_mci *host) } } - host->vmmc =devm_regulator_get (host->dev,"vmmc" ); + host->vmmc =devm_regulator_get_optional (host->dev,"vmmc" );if (IS_ERR (host->vmmc)) { ret =PTR_ERR (host->vmmc);if (ret == -EPROBE_DEFER )
Signature · 1 line
1.8.3.2
RE: [PATCH 4/5] mmc: dw_mmc: Indicate that regulators may be absent
Quoted 6 lines · Mark Brown
From: Mark Brown <[email protected]>
Use
regulator_get_optional()to tell the core that requests for regulators can fail in a real system.Signed-off-by Mark Brown <[email protected]>
Thanks,
Seungwon Jeon
Re: [PATCH 4/5] mmc: dw_mmc: Indicate that regulators may be absent
Best Regards,
Jaehoon Chung
Quoted 17 lines · Seungwon Jeon
Quoted 6 lines · Mark Brown
From: Mark Brown <[email protected]>
Use
regulator_get_optional()to tell the core that requests for regulators can fail in a real system.Signed-off-by Mark Brown <[email protected]>Acked-by Seungwon Jeon <[email protected]>Thanks,
Seungwon Jeon--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Brown
maintainerPATCH 5/5 mmc: pxamci: Indicate that regulators may be absent
In reply to Mark BrownFrom: Mark Brown <[email protected]>
Use regulator_get_optional() to tell the core that requests for regulators can fail in a real system.
--- drivers/mmc/host/pxamci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/pxamci.c +1 -1
@@ -83,7 +83,7 @@ struct pxamci_host {static inline void pxamci_init_ocr (struct pxamci_host *host) {#ifdef CONFIG_REGULATOR - host->vcc =regulator_get (mmc_dev (host->mmc),"vmmc" ); + host->vcc =regulator_get_optional (mmc_dev (host->mmc),"vmmc" );if (IS_ERR (host->vcc)) host->vcc =NULL ;
Signature · 1 line
1.8.3.2