From patchwork Mon Aug 18 13:09:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guodong Xu X-Patchwork-Id: 4736301 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4E408C0338 for ; Mon, 18 Aug 2014 13:16:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E4DB520123 for ; Mon, 18 Aug 2014 13:16:34 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 576032010B for ; Mon, 18 Aug 2014 13:16:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XJMiG-0007UG-QT; Mon, 18 Aug 2014 13:11:04 +0000 Received: from mail-pd0-f173.google.com ([209.85.192.173]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XJMiB-0007N2-A5 for linux-arm-kernel@lists.infradead.org; Mon, 18 Aug 2014 13:11:03 +0000 Received: by mail-pd0-f173.google.com with SMTP id w10so7546404pde.32 for ; Mon, 18 Aug 2014 06:10:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rztgzdUf8ctLly8n9ggsZArTawnvalojNrDX5CGKVQM=; b=HMS1oVv9KXnkJIiZ6K7p53WP9jNlnpayBUt7a9vnv+Oq+jnNSy0qlBhd9Ev7sE6qrH l25eB47BRvJ6aW4Ch4zrnZv0Fvtip9vluMfvadwZn1OjN07SHUMf8Ux5BA9xr5Poj+Sj AYLiHRKZdPvgRj5p+rMPWx2AGptD1GRKZQP/ct4Lww3CFkOhO9ybxLYNDxecyfxKRQAV L2VDqnCYToq3D9cL0v+Dyd4jrchtom8fa3uWp4nGoAfaanw2YMmADITHZ/modY3MW4rr SUVWzsGLQbwDHvZp1JZaV6RwhYFhKn+MEqXUuexxUoA3/slQMUKlJ7XG+SOcdTZpz6mX pb2A== X-Gm-Message-State: ALoCoQk9FyPxXpUj2Zf8yPsjNzj1HbH3a5bCGBkyfUk7ZX4TvzMR6YNo3lz+bgvTS48vMtv/iX5q X-Received: by 10.70.35.166 with SMTP id i6mr34252595pdj.60.1408367435343; Mon, 18 Aug 2014 06:10:35 -0700 (PDT) Received: from localhost.localdomain ([119.9.85.21]) by mx.google.com with ESMTPSA id q5sm24764968pdf.70.2014.08.18.06.10.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Aug 2014 06:10:34 -0700 (PDT) From: Guodong Xu To: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, linux@arm.linux.org.uk, sameo@linux.intel.com, lee.jones@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, grant.likely@linaro.org, khilman@linaro.org, haojian.zhuang@linaro.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, axel.lin@ingics.com, zhangnian@huawei.com Subject: [PATCH v6 2/6] regulator: core: factor out delay function from _regulator_do_enable Date: Mon, 18 Aug 2014 21:09:12 +0800 Message-Id: <1408367356-2628-3-git-send-email-guodong.xu@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1408367356-2628-1-git-send-email-guodong.xu@linaro.org> References: <1408367356-2628-1-git-send-email-guodong.xu@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140818_061059_369993_F9C5EE5A X-CRM114-Status: GOOD ( 15.31 ) X-Spam-Score: -1.4 (-) Cc: Guodong Xu X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A common delay function can be helpful when implementing new features. Factor it out to maximize code reusability. Signed-off-by: Guodong Xu --- 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 c4a13db..4976451 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) 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; @@ -1792,40 +1831,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));