linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: guodong.xu@linaro.org (Guodong Xu)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 2/7] regulator: core: factor out delay function from _regulator_do_enable
Date: Wed, 13 Aug 2014 19:33:39 +0800	[thread overview]
Message-ID: <1407929624-8737-3-git-send-email-guodong.xu@linaro.org> (raw)
In-Reply-To: <1407929624-8737-1-git-send-email-guodong.xu@linaro.org>

A common delay function can be helpful when implementing new features. Factor
it out to maximize code reusability.

Signed-off-by: Guodong Xu <guodong.xu@linaro.org>
---
 drivers/regulator/core.c | 74 ++++++++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 34 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index eb6f172..67d4246 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1753,6 +1753,45 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
 	return 0;
 }
 
+/**
+ * _regulator_enable_delay - a delay helper function
+ * @delay: time to delay in microseconds
+ *
+ * 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.
+ */
+static void _regulator_enable_delay(unsigned int 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);
+}
+
 static int _regulator_do_enable(struct regulator_dev *rdev)
 {
 	int ret, delay;
@@ -1786,40 +1825,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
 	 * together.  */
 	trace_regulator_enable_delay(rdev_get_name(rdev));
 
-	/*
-	 * 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);
-	}
+	_regulator_enable_delay(delay);
 
 	trace_regulator_enable_complete(rdev_get_name(rdev));
 
-- 
1.9.1

  parent reply	other threads:[~2014-08-13 11:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-13 11:33 [PATCH v5 0/7] Add MFD and regulator drivers for Hi6421 PMIC SoC Guodong Xu
2014-08-13 11:33 ` [PATCH v5 1/7] regulator: core: add const qualifier to ops in struct regulator_desc Guodong Xu
2014-08-13 11:33 ` Guodong Xu [this message]
2014-08-13 11:33 ` [PATCH v5 3/7] regulator: core: add guard delay between calling regulator_disable and _enable Guodong Xu
2014-08-13 11:33 ` [PATCH v5 4/7] mfd: Add hi6421 PMIC core driver Guodong Xu
2014-08-13 11:33 ` [PATCH v5 5/7] regulator: add driver for hi6421 voltage regulator Guodong Xu
2014-08-13 11:33 ` [PATCH v5 6/7] ARM: dts: hi3620-hi4511: Add HI6421 MFD and regulator nodes Guodong Xu
2014-08-13 11:33 ` [PATCH v5 7/7] ARM: hi3xxx_defconfig: Enable HI6421 MFD and Regulators Guodong Xu
2014-08-13 18:53 ` [PATCH v5 0/7] Add MFD and regulator drivers for Hi6421 PMIC SoC Mark Brown
2014-08-14  0:51   ` Haojian Zhuang
2014-08-14 16:40     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1407929624-8737-3-git-send-email-guodong.xu@linaro.org \
    --to=guodong.xu@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).