Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Mark Brown and committed by
Liam Girdwood
34abbd68 9a7f6a4c

+135 -1
+11
drivers/regulator/Kconfig
··· 27 27 help 28 28 Say yes here to enable debugging support. 29 29 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 + 30 41 config REGULATOR_FIXED_VOLTAGE 31 42 tristate "Fixed voltage regulator support" 32 43 help
+1
drivers/regulator/Makefile
··· 9 9 obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o 10 10 11 11 obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o 12 + obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o 12 13 obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o 13 14 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 14 15 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o
+26 -1
drivers/regulator/core.c
··· 24 24 #include <linux/regulator/driver.h> 25 25 #include <linux/regulator/machine.h> 26 26 27 + #include "dummy.h" 28 + 27 29 #define REGULATOR_VERSION "0.5" 28 30 29 31 static DEFINE_MUTEX(regulator_list_mutex); ··· 1125 1123 goto found; 1126 1124 } 1127 1125 } 1126 + 1127 + #ifdef CONFIG_REGULATOR_DUMMY 1128 + if (!devname) 1129 + devname = "deviceless"; 1130 + 1131 + /* If the board didn't flag that it was fully constrained then 1132 + * substitute in a dummy regulator so consumers can continue. 1133 + */ 1134 + if (!has_full_constraints) { 1135 + pr_warning("%s supply %s not found, using dummy regulator\n", 1136 + devname, id); 1137 + rdev = dummy_regulator_rdev; 1138 + goto found; 1139 + } 1140 + #endif 1141 + 1128 1142 mutex_unlock(&regulator_list_mutex); 1129 1143 return regulator; 1130 1144 ··· 2501 2483 2502 2484 static int __init regulator_init(void) 2503 2485 { 2486 + int ret; 2487 + 2504 2488 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); 2505 - return class_register(&regulator_class); 2489 + 2490 + ret = class_register(&regulator_class); 2491 + 2492 + regulator_dummy_init(); 2493 + 2494 + return ret; 2506 2495 } 2507 2496 2508 2497 /* init early to allow our consumers to complete system booting */
+66
drivers/regulator/dummy.c
··· 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 + }
+31
drivers/regulator/dummy.h
··· 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