aboutsummaryrefslogtreecommitdiff
path: root/drivers/regulator/core.c
diff options
context:
space:
mode:
authorGravatar Thierry Reding <thierry.reding@gmail.com> 2013-09-20 13:51:56 +0200
committerGravatar Mark Brown <broonie@linaro.org> 2013-09-30 11:43:12 +0100
commit5df529d440aa4f0e67be9af3718e7edf05db7d02 (patch)
tree4ea23e91d0a270ba4bcea67882b1c4f331b4bf69 /drivers/regulator/core.c
parentregulator: core: Fix return code for invalid parameters (diff)
downloadlinux-5df529d440aa4f0e67be9af3718e7edf05db7d02.tar.gz
linux-5df529d440aa4f0e67be9af3718e7edf05db7d02.tar.bz2
linux-5df529d440aa4f0e67be9af3718e7edf05db7d02.zip
regulator: core: Reduce busy-wait looping
Keep busy-wait looping to a minimum while waiting for a regulator to ramp-up to the target voltage. This follows the guidelines set forth in Documentation/timers/timers-howto.txt and assumes that regulators are never enabled in atomic context. Signed-off-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r--drivers/regulator/core.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index ad154247bb90..5075ed1e94a6 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1740,11 +1740,39 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
* together. */
trace_regulator_enable_delay(rdev_get_name(rdev));
- if (delay >= 1000) {
- mdelay(delay / 1000);
- udelay(delay % 1000);
- } else if (delay) {
- udelay(delay);
+ /*
+ * Delay for the requested amount of time as per the guidelines in:
+ *
+ * Documentation/timers/timers-howto.txt
+ *
+ * The assumption here is that regulators will never be enabled in
+ * atomic context and therefore sleeping functions can be used.
+ */
+ if (delay) {
+ unsigned int ms = delay / 1000;
+ unsigned int us = delay % 1000;
+
+ if (ms > 0) {
+ /*
+ * For small enough values, handle super-millisecond
+ * delays in the usleep_range() call below.
+ */
+ if (ms < 20)
+ us += ms * 1000;
+ else
+ msleep(ms);
+ }
+
+ /*
+ * Give the scheduler some room to coalesce with any other
+ * wakeup sources. For delays shorter than 10 us, don't even
+ * bother setting up high-resolution timers and just busy-
+ * loop.
+ */
+ if (us >= 10)
+ usleep_range(us, us + 100);
+ else
+ udelay(us);
}
trace_regulator_enable_complete(rdev_get_name(rdev));