Skip to content

Commit 34abbd6

Browse files
broonieLiam Girdwood
authored andcommitted
regulator: Provide optional dummy regulator for consumers
In order to ease transitions with drivers are boards start using regulators provide an option to cause all regulator_get() calls to succeed, with a dummy always on regulator being supplied where one has not been configured. A warning is printed whenever the dummy regulator is used to aid system development. This regulator does not implement any regulator operations but will allow simple consumers which only do enable() and disable() calls to run. It is kept separate from the fixed voltage regulator to avoid Kconfig confusion on the part of users when it is extended to allow boards to explicitly use the dummy regulator to simplify cases where the majority of supplies are from fixed regulators without software control. This option is currently only effective for systems which do not specify full constriants. If required an override could also be provided to allow these systems to use the dummy regulator, though it is likely that unconfigured supplies on such systems will lead to error due to regulators being powered down more aggressively when not in use. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
1 parent 9a7f6a4 commit 34abbd6

5 files changed

Lines changed: 135 additions & 1 deletion

File tree

‎drivers/regulator/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ config REGULATOR_DEBUG
2727
help
2828
Say yes here to enable debugging support.
2929

30+
config REGULATOR_DUMMY
31+
bool "Provide a dummy regulator if regulator lookups fail"
32+
help
33+
If this option is enabled then when a regulator lookup fails
34+
and the board has not specified that it has provided full
35+
constraints then the regulator core will provide an always
36+
enabled dummy regulator will be provided, allowing consumer
37+
drivers to continue.
38+
39+
A warning will be generated when this substitution is done.
40+
3041
config REGULATOR_FIXED_VOLTAGE
3142
tristate "Fixed voltage regulator support"
3243
help

‎drivers/regulator/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
99
obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
1010

1111
obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
12+
obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o
1213
obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
1314
obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
1415
obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o

‎drivers/regulator/core.c‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <linux/regulator/driver.h>
2525
#include <linux/regulator/machine.h>
2626

27+
#include "dummy.h"
28+
2729
#define REGULATOR_VERSION "0.5"
2830

2931
static DEFINE_MUTEX(regulator_list_mutex);
@@ -1123,6 +1125,22 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
11231125
goto found;
11241126
}
11251127
}
1128+
1129+
#ifdef CONFIG_REGULATOR_DUMMY
1130+
if (!devname)
1131+
devname = "deviceless";
1132+
1133+
/* If the board didn't flag that it was fully constrained then
1134+
* substitute in a dummy regulator so consumers can continue.
1135+
*/
1136+
if (!has_full_constraints) {
1137+
pr_warning("%s supply %s not found, using dummy regulator\n",
1138+
devname, id);
1139+
rdev = dummy_regulator_rdev;
1140+
goto found;
1141+
}
1142+
#endif
1143+
11261144
mutex_unlock(&regulator_list_mutex);
11271145
return regulator;
11281146

@@ -2483,8 +2501,15 @@ EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
24832501

24842502
static int __init regulator_init(void)
24852503
{
2504+
int ret;
2505+
24862506
printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
2487-
return class_register(&regulator_class);
2507+
2508+
ret = class_register(&regulator_class);
2509+
2510+
regulator_dummy_init();
2511+
2512+
return ret;
24882513
}
24892514

24902515
/* init early to allow our consumers to complete system booting */

‎drivers/regulator/dummy.c‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* dummy.c
3+
*
4+
* Copyright 2010 Wolfson Microelectronics PLC.
5+
*
6+
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License as
10+
* published by the Free Software Foundation; either version 2 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This is useful for systems with mixed controllable and
14+
* non-controllable regulators, as well as for allowing testing on
15+
* systems with no controllable regulators.
16+
*/
17+
18+
#include <linux/err.h>
19+
#include <linux/platform_device.h>
20+
#include <linux/regulator/driver.h>
21+
#include <linux/regulator/machine.h>
22+
23+
#include "dummy.h"
24+
25+
struct regulator_dev *dummy_regulator_rdev;
26+
27+
static struct regulator_init_data dummy_initdata;
28+
29+
static struct regulator_ops dummy_ops;
30+
31+
static struct regulator_desc dummy_desc = {
32+
.name = "dummy",
33+
.id = -1,
34+
.type = REGULATOR_VOLTAGE,
35+
.owner = THIS_MODULE,
36+
.ops = &dummy_ops,
37+
};
38+
39+
static struct platform_device *dummy_pdev;
40+
41+
void __init regulator_dummy_init(void)
42+
{
43+
int ret;
44+
45+
dummy_pdev = platform_device_alloc("reg-dummy", -1);
46+
if (!dummy_pdev) {
47+
pr_err("Failed to allocate dummy regulator device\n");
48+
return;
49+
}
50+
51+
ret = platform_device_add(dummy_pdev);
52+
if (ret != 0) {
53+
pr_err("Failed to register dummy regulator device: %d\n", ret);
54+
platform_device_put(dummy_pdev);
55+
return;
56+
}
57+
58+
dummy_regulator_rdev = regulator_register(&dummy_desc, NULL,
59+
&dummy_initdata, NULL);
60+
if (IS_ERR(dummy_regulator_rdev)) {
61+
ret = PTR_ERR(dummy_regulator_rdev);
62+
pr_err("Failed to register regulator: %d\n", ret);
63+
platform_device_unregister(dummy_pdev);
64+
return;
65+
}
66+
}

‎drivers/regulator/dummy.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* dummy.h
3+
*
4+
* Copyright 2010 Wolfson Microelectronics PLC.
5+
*
6+
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License as
10+
* published by the Free Software Foundation; either version 2 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This is useful for systems with mixed controllable and
14+
* non-controllable regulators, as well as for allowing testing on
15+
* systems with no controllable regulators.
16+
*/
17+
18+
#ifndef _DUMMY_H
19+
#define _DUMMY_H
20+
21+
struct regulator_dev;
22+
23+
extern struct regulator_dev *dummy_regulator_rdev;
24+
25+
#ifdef CONFIG_REGULATOR_DUMMY
26+
void __init regulator_dummy_init(void);
27+
#else
28+
static inline void regulator_dummy_init(void) { }
29+
#endif
30+
31+
#endif

0 commit comments

Comments
 (0)