From patchwork Wed Aug 13 11:33:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guodong Xu X-Patchwork-Id: 35345 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F1880203C5 for ; Wed, 13 Aug 2014 11:35:22 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id eu11sf79914197pac.11 for ; Wed, 13 Aug 2014 04:35:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=3CZJci898yJN88N5LCKQZdEOcWQpDjEaZSYrkHBQ8BA=; b=O5hTpKa9jkfZDMAXtoT0EAltHGF1bD4XgLKLwCi6sTI5HjQRR+jajs9B4Gq7FtBcuE snQCRtdRGiJD3tzn8jFso3Tm1EZa8ZuAU1CUaroKfgYKM+1h7vO3kOYwwvLpk0pMw8DD 9umFJcYfouX7vNrfL8K+msF/l8yJgh/Zi7oXoK+PkizzVirKtPKOZTP2C/5tG+RRoxin 1rimgZPcmdVqtz+DVDK15rYEbXwbsviWqC9hxVhYTStlUpSf+Hfscnb2pA7ev9LTIc/w NzKVPggGLI1GGoPI4soePwHthCI8hYvuo1qnF2PJeOi0ztxUQk86cqSzd0N89SUD1MOA 1ksw== X-Gm-Message-State: ALoCoQlO1TIMO5AQBROt2e3WQk5tl2hOdSZxXS42NWD9U9XffS1clepxM3c/TirETitTv/9bo/o9 X-Received: by 10.66.228.70 with SMTP id sg6mr2023889pac.2.1407929722190; Wed, 13 Aug 2014 04:35:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.100.242 with SMTP id s105ls482755qge.42.gmail; Wed, 13 Aug 2014 04:35:22 -0700 (PDT) X-Received: by 10.52.240.135 with SMTP id wa7mr63556vdc.82.1407929722064; Wed, 13 Aug 2014 04:35:22 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id xi6si896268vdb.85.2014.08.13.04.35.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Aug 2014 04:35:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id le20so15026086vcb.0 for ; Wed, 13 Aug 2014 04:35:22 -0700 (PDT) X-Received: by 10.220.7.131 with SMTP id d3mr94475vcd.49.1407929721962; Wed, 13 Aug 2014 04:35:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp323187vcb; Wed, 13 Aug 2014 04:35:21 -0700 (PDT) X-Received: by 10.67.23.70 with SMTP id hy6mr3675610pad.30.1407929721001; Wed, 13 Aug 2014 04:35:21 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ic5si1314719pbc.59.2014.08.13.04.35.18 for ; Wed, 13 Aug 2014 04:35:20 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752501AbaHMLfO (ORCPT + 23 others); Wed, 13 Aug 2014 07:35:14 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:59719 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752358AbaHMLfJ (ORCPT ); Wed, 13 Aug 2014 07:35:09 -0400 Received: by mail-pa0-f42.google.com with SMTP id lf10so14896546pab.29 for ; Wed, 13 Aug 2014 04:35:08 -0700 (PDT) X-Received: by 10.68.138.13 with SMTP id qm13mr3616346pbb.46.1407929708688; Wed, 13 Aug 2014 04:35:08 -0700 (PDT) Received: from localhost.localdomain ([120.136.45.59]) by mx.google.com with ESMTPSA id ya1sm1832872pbb.91.2014.08.13.04.35.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Aug 2014 04:35:07 -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 Cc: Guodong Xu Subject: [PATCH v5 2/7] regulator: core: factor out delay function from _regulator_do_enable Date: Wed, 13 Aug 2014 19:33:39 +0800 Message-Id: <1407929624-8737-3-git-send-email-guodong.xu@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1407929624-8737-1-git-send-email-guodong.xu@linaro.org> References: <1407929624-8737-1-git-send-email-guodong.xu@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: guodong.xu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 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));