aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuodong Xu <guodong.xu@linaro.org>2014-08-13 07:33:39 -0400
committerMark Brown <broonie@linaro.org>2014-08-16 17:55:42 -0400
commit79fd114161a764dfa456191af89358b3f5201c87 (patch)
treea9e16d36afbf25ffa2c5d05648ee92bee982d127
parent272e2315fac3bfca0edfa3252b8a643c425602af (diff)
regulator: core: factor out delay function from _regulator_do_enable
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> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--drivers/regulator/core.c74
1 files changed, 40 insertions, 34 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 052e7f1f011d..dc0e9813b62d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1759,6 +1759,45 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
1759 return 0; 1759 return 0;
1760} 1760}
1761 1761
1762/**
1763 * _regulator_enable_delay - a delay helper function
1764 * @delay: time to delay in microseconds
1765 *
1766 * Delay for the requested amount of time as per the guidelines in:
1767 *
1768 * Documentation/timers/timers-howto.txt
1769 *
1770 * The assumption here is that regulators will never be enabled in
1771 * atomic context and therefore sleeping functions can be used.
1772 */
1773static void _regulator_enable_delay(unsigned int delay)
1774{
1775 unsigned int ms = delay / 1000;
1776 unsigned int us = delay % 1000;
1777
1778 if (ms > 0) {
1779 /*
1780 * For small enough values, handle super-millisecond
1781 * delays in the usleep_range() call below.
1782 */
1783 if (ms < 20)
1784 us += ms * 1000;
1785 else
1786 msleep(ms);
1787 }
1788
1789 /*
1790 * Give the scheduler some room to coalesce with any other
1791 * wakeup sources. For delays shorter than 10 us, don't even
1792 * bother setting up high-resolution timers and just busy-
1793 * loop.
1794 */
1795 if (us >= 10)
1796 usleep_range(us, us + 100);
1797 else
1798 udelay(us);
1799}
1800
1762static int _regulator_do_enable(struct regulator_dev *rdev) 1801static int _regulator_do_enable(struct regulator_dev *rdev)
1763{ 1802{
1764 int ret, delay; 1803 int ret, delay;
@@ -1792,40 +1831,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
1792 * together. */ 1831 * together. */
1793 trace_regulator_enable_delay(rdev_get_name(rdev)); 1832 trace_regulator_enable_delay(rdev_get_name(rdev));
1794 1833
1795 /* 1834 _regulator_enable_delay(delay);
1796 * Delay for the requested amount of time as per the guidelines in:
1797 *
1798 * Documentation/timers/timers-howto.txt
1799 *
1800 * The assumption here is that regulators will never be enabled in
1801 * atomic context and therefore sleeping functions can be used.
1802 */
1803 if (delay) {
1804 unsigned int ms = delay / 1000;
1805 unsigned int us = delay % 1000;
1806
1807 if (ms > 0) {
1808 /*
1809 * For small enough values, handle super-millisecond
1810 * delays in the usleep_range() call below.
1811 */
1812 if (ms < 20)
1813 us += ms * 1000;
1814 else
1815 msleep(ms);
1816 }
1817
1818 /*
1819 * Give the scheduler some room to coalesce with any other
1820 * wakeup sources. For delays shorter than 10 us, don't even
1821 * bother setting up high-resolution timers and just busy-
1822 * loop.
1823 */
1824 if (us >= 10)
1825 usleep_range(us, us + 100);
1826 else
1827 udelay(us);
1828 }
1829 1835
1830 trace_regulator_enable_complete(rdev_get_name(rdev)); 1836 trace_regulator_enable_complete(rdev_get_name(rdev));
1831 1837