aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/regulator/core.c59
-rw-r--r--include/linux/regulator/consumer.h18
2 files changed, 76 insertions, 1 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 288c75abc190..a27a5b6267dd 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1409,6 +1409,65 @@ struct regulator *regulator_get_exclusive(struct device *dev, const char *id)
1409} 1409}
1410EXPORT_SYMBOL_GPL(regulator_get_exclusive); 1410EXPORT_SYMBOL_GPL(regulator_get_exclusive);
1411 1411
1412/**
1413 * regulator_get_optional - obtain optional access to a regulator.
1414 * @dev: device for regulator "consumer"
1415 * @id: Supply name or regulator ID.
1416 *
1417 * Returns a struct regulator corresponding to the regulator producer,
1418 * or IS_ERR() condition containing errno. Other consumers will be
1419 * unable to obtain this reference is held and the use count for the
1420 * regulator will be initialised to reflect the current state of the
1421 * regulator.
1422 *
1423 * This is intended for use by consumers for devices which can have
1424 * some supplies unconnected in normal use, such as some MMC devices.
1425 * It can allow the regulator core to provide stub supplies for other
1426 * supplies requested using normal regulator_get() calls without
1427 * disrupting the operation of drivers that can handle absent
1428 * supplies.
1429 *
1430 * Use of supply names configured via regulator_set_device_supply() is
1431 * strongly encouraged. It is recommended that the supply name used
1432 * should match the name used for the supply and/or the relevant
1433 * device pins in the datasheet.
1434 */
1435struct regulator *regulator_get_optional(struct device *dev, const char *id)
1436{
1437 return _regulator_get(dev, id, 0);
1438}
1439EXPORT_SYMBOL_GPL(regulator_get_optional);
1440
1441/**
1442 * devm_regulator_get_optional - Resource managed regulator_get_optional()
1443 * @dev: device for regulator "consumer"
1444 * @id: Supply name or regulator ID.
1445 *
1446 * Managed regulator_get_optional(). Regulators returned from this
1447 * function are automatically regulator_put() on driver detach. See
1448 * regulator_get_optional() for more information.
1449 */
1450struct regulator *devm_regulator_get_optional(struct device *dev,
1451 const char *id)
1452{
1453 struct regulator **ptr, *regulator;
1454
1455 ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
1456 if (!ptr)
1457 return ERR_PTR(-ENOMEM);
1458
1459 regulator = regulator_get_optional(dev, id);
1460 if (!IS_ERR(regulator)) {
1461 *ptr = regulator;
1462 devres_add(dev, ptr);
1463 } else {
1464 devres_free(ptr);
1465 }
1466
1467 return regulator;
1468}
1469EXPORT_SYMBOL_GPL(devm_regulator_get_optional);
1470
1412/* Locks held by regulator_put() */ 1471/* Locks held by regulator_put() */
1413static void _regulator_put(struct regulator *regulator) 1472static void _regulator_put(struct regulator *regulator)
1414{ 1473{
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 60da4a62c402..e2bac6db4abc 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -137,6 +137,10 @@ struct regulator *__must_check devm_regulator_get(struct device *dev,
137 const char *id); 137 const char *id);
138struct regulator *__must_check regulator_get_exclusive(struct device *dev, 138struct regulator *__must_check regulator_get_exclusive(struct device *dev,
139 const char *id); 139 const char *id);
140struct regulator *__must_check regulator_get_optional(struct device *dev,
141 const char *id);
142struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
143 const char *id);
140void regulator_put(struct regulator *regulator); 144void regulator_put(struct regulator *regulator);
141void devm_regulator_put(struct regulator *regulator); 145void devm_regulator_put(struct regulator *regulator);
142 146
@@ -212,14 +216,26 @@ static inline struct regulator *__must_check regulator_get(struct device *dev,
212} 216}
213 217
214static inline struct regulator *__must_check 218static inline struct regulator *__must_check
219devm_regulator_get(struct device *dev, const char *id)
220{
221 return NULL;
222}
223
224static inline struct regulator *__must_check
215regulator_get_exclusive(struct device *dev, const char *id) 225regulator_get_exclusive(struct device *dev, const char *id)
216{ 226{
217 return NULL; 227 return NULL;
218} 228}
219 229
230static inline struct regulator *__must_check
231regulator_get_optional(struct device *dev, const char *id)
232{
233 return NULL;
234}
235
220 236
221static inline struct regulator *__must_check 237static inline struct regulator *__must_check
222devm_regulator_get(struct device *dev, const char *id) 238devm_regulator_get_optional(struct device *dev, const char *id)
223{ 239{
224 return NULL; 240 return NULL;
225} 241}