Skip to content

Commit f27a5fb

Browse files
committed
Merge remote-tracking branch 'regulator/topic/optional' into regulator-next
2 parents 6979380 + 9efdd27 commit f27a5fb

8 files changed

Lines changed: 121 additions & 7 deletions

File tree

‎drivers/cpufreq/cpufreq-cpu0.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev)
197197
cpu_dev = &pdev->dev;
198198
cpu_dev->of_node = np;
199199

200-
cpu_reg = devm_regulator_get(cpu_dev, "cpu0");
200+
cpu_reg = devm_regulator_get_optional(cpu_dev, "cpu0");
201201
if (IS_ERR(cpu_reg)) {
202202
/*
203203
* If cpu0 regulator supply node is present, but regulator is

‎drivers/hwmon/sht15.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ static int sht15_probe(struct platform_device *pdev)
957957
* If a regulator is available,
958958
* query what the supply voltage actually is!
959959
*/
960-
data->reg = devm_regulator_get(data->dev, "vcc");
960+
data->reg = devm_regulator_get_optional(data->dev, "vcc");
961961
if (!IS_ERR(data->reg)) {
962962
int voltage;
963963

‎drivers/mmc/core/core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ int mmc_regulator_get_supply(struct mmc_host *mmc)
13131313

13141314
supply = devm_regulator_get(dev, "vmmc");
13151315
mmc->supply.vmmc = supply;
1316-
mmc->supply.vqmmc = devm_regulator_get(dev, "vqmmc");
1316+
mmc->supply.vqmmc = devm_regulator_get_optional(dev, "vqmmc");
13171317

13181318
if (IS_ERR(supply))
13191319
return PTR_ERR(supply);

‎drivers/mmc/host/dw_mmc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,7 @@ int dw_mci_probe(struct dw_mci *host)
22312231
}
22322232
}
22332233

2234-
host->vmmc = devm_regulator_get(host->dev, "vmmc");
2234+
host->vmmc = devm_regulator_get_optional(host->dev, "vmmc");
22352235
if (IS_ERR(host->vmmc)) {
22362236
ret = PTR_ERR(host->vmmc);
22372237
if (ret == -EPROBE_DEFER)

‎drivers/mmc/host/pxamci.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct pxamci_host {
8383
static inline void pxamci_init_ocr(struct pxamci_host *host)
8484
{
8585
#ifdef CONFIG_REGULATOR
86-
host->vcc = regulator_get(mmc_dev(host->mmc), "vmmc");
86+
host->vcc = regulator_get_optional(mmc_dev(host->mmc), "vmmc");
8787

8888
if (IS_ERR(host->vcc))
8989
host->vcc = NULL;

‎drivers/mmc/host/sdhci.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,7 +2966,7 @@ int sdhci_add_host(struct sdhci_host *host)
29662966
mmc->caps |= MMC_CAP_NEEDS_POLL;
29672967

29682968
/* If vqmmc regulator and no 1.8V signalling, then there's no UHS */
2969-
host->vqmmc = regulator_get(mmc_dev(mmc), "vqmmc");
2969+
host->vqmmc = regulator_get_optional(mmc_dev(mmc), "vqmmc");
29702970
if (IS_ERR_OR_NULL(host->vqmmc)) {
29712971
if (PTR_ERR(host->vqmmc) < 0) {
29722972
pr_info("%s: no vqmmc regulator found\n",
@@ -3042,7 +3042,7 @@ int sdhci_add_host(struct sdhci_host *host)
30423042

30433043
ocr_avail = 0;
30443044

3045-
host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
3045+
host->vmmc = regulator_get_optional(mmc_dev(mmc), "vmmc");
30463046
if (IS_ERR_OR_NULL(host->vmmc)) {
30473047
if (PTR_ERR(host->vmmc) < 0) {
30483048
pr_info("%s: no vmmc regulator found\n",

‎drivers/regulator/core.c‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,65 @@ struct regulator *regulator_get_exclusive(struct device *dev, const char *id)
14131413
}
14141414
EXPORT_SYMBOL_GPL(regulator_get_exclusive);
14151415

1416+
/**
1417+
* regulator_get_optional - obtain optional access to a regulator.
1418+
* @dev: device for regulator "consumer"
1419+
* @id: Supply name or regulator ID.
1420+
*
1421+
* Returns a struct regulator corresponding to the regulator producer,
1422+
* or IS_ERR() condition containing errno. Other consumers will be
1423+
* unable to obtain this reference is held and the use count for the
1424+
* regulator will be initialised to reflect the current state of the
1425+
* regulator.
1426+
*
1427+
* This is intended for use by consumers for devices which can have
1428+
* some supplies unconnected in normal use, such as some MMC devices.
1429+
* It can allow the regulator core to provide stub supplies for other
1430+
* supplies requested using normal regulator_get() calls without
1431+
* disrupting the operation of drivers that can handle absent
1432+
* supplies.
1433+
*
1434+
* Use of supply names configured via regulator_set_device_supply() is
1435+
* strongly encouraged. It is recommended that the supply name used
1436+
* should match the name used for the supply and/or the relevant
1437+
* device pins in the datasheet.
1438+
*/
1439+
struct regulator *regulator_get_optional(struct device *dev, const char *id)
1440+
{
1441+
return _regulator_get(dev, id, 0);
1442+
}
1443+
EXPORT_SYMBOL_GPL(regulator_get_optional);
1444+
1445+
/**
1446+
* devm_regulator_get_optional - Resource managed regulator_get_optional()
1447+
* @dev: device for regulator "consumer"
1448+
* @id: Supply name or regulator ID.
1449+
*
1450+
* Managed regulator_get_optional(). Regulators returned from this
1451+
* function are automatically regulator_put() on driver detach. See
1452+
* regulator_get_optional() for more information.
1453+
*/
1454+
struct regulator *devm_regulator_get_optional(struct device *dev,
1455+
const char *id)
1456+
{
1457+
struct regulator **ptr, *regulator;
1458+
1459+
ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
1460+
if (!ptr)
1461+
return ERR_PTR(-ENOMEM);
1462+
1463+
regulator = regulator_get_optional(dev, id);
1464+
if (!IS_ERR(regulator)) {
1465+
*ptr = regulator;
1466+
devres_add(dev, ptr);
1467+
} else {
1468+
devres_free(ptr);
1469+
}
1470+
1471+
return regulator;
1472+
}
1473+
EXPORT_SYMBOL_GPL(devm_regulator_get_optional);
1474+
14161475
/* Locks held by regulator_put() */
14171476
static void _regulator_put(struct regulator *regulator)
14181477
{
@@ -1438,6 +1497,36 @@ static void _regulator_put(struct regulator *regulator)
14381497
module_put(rdev->owner);
14391498
}
14401499

1500+
/**
1501+
* devm_regulator_get_exclusive - Resource managed regulator_get_exclusive()
1502+
* @dev: device for regulator "consumer"
1503+
* @id: Supply name or regulator ID.
1504+
*
1505+
* Managed regulator_get_exclusive(). Regulators returned from this function
1506+
* are automatically regulator_put() on driver detach. See regulator_get() for
1507+
* more information.
1508+
*/
1509+
struct regulator *devm_regulator_get_exclusive(struct device *dev,
1510+
const char *id)
1511+
{
1512+
struct regulator **ptr, *regulator;
1513+
1514+
ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
1515+
if (!ptr)
1516+
return ERR_PTR(-ENOMEM);
1517+
1518+
regulator = _regulator_get(dev, id, 1);
1519+
if (!IS_ERR(regulator)) {
1520+
*ptr = regulator;
1521+
devres_add(dev, ptr);
1522+
} else {
1523+
devres_free(ptr);
1524+
}
1525+
1526+
return regulator;
1527+
}
1528+
EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive);
1529+
14411530
/**
14421531
* regulator_put - "free" the regulator source
14431532
* @regulator: regulator source

‎include/linux/regulator/consumer.h‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ struct regulator *__must_check devm_regulator_get(struct device *dev,
137137
const char *id);
138138
struct regulator *__must_check regulator_get_exclusive(struct device *dev,
139139
const char *id);
140+
struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
141+
const char *id);
142+
struct regulator *__must_check regulator_get_optional(struct device *dev,
143+
const char *id);
144+
struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
145+
const char *id);
140146
void regulator_put(struct regulator *regulator);
141147
void devm_regulator_put(struct regulator *regulator);
142148

@@ -217,6 +223,25 @@ devm_regulator_get(struct device *dev, const char *id)
217223
return NULL;
218224
}
219225

226+
static inline struct regulator *__must_check
227+
regulator_get_exclusive(struct device *dev, const char *id)
228+
{
229+
return NULL;
230+
}
231+
232+
static inline struct regulator *__must_check
233+
regulator_get_optional(struct device *dev, const char *id)
234+
{
235+
return NULL;
236+
}
237+
238+
239+
static inline struct regulator *__must_check
240+
devm_regulator_get_optional(struct device *dev, const char *id)
241+
{
242+
return NULL;
243+
}
244+
220245
static inline void regulator_put(struct regulator *regulator)
221246
{
222247
}

0 commit comments

Comments
 (0)