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: 35493 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 21CDB20676 for ; Mon, 18 Aug 2014 13:10:58 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id y10sf40607590pdj.0 for ; Mon, 18 Aug 2014 06:10:53 -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=vEacwEOLTMVas7EDnj53dKKok/J2+Xmm/W+nqnyz578=; b=S0Dk45f2nilWGM6c8DaRJXyrT/34cb5OeNCpCZendU0Cl2WJLD3F1iT5jsfsz0CUuQ 6QIbMIgokjD7Ckw9IEi5Bb8yePKDhkQWLwENvQNmkI7pwfksDfvTkQEuzs+wrHLzcmpH VI1pp9Xft8NBixtLowmTzoaDKVTzPPyzDnk99ahm/EG5lwHJ5Xl9U641Ltjerhb+MYvP 7UUHqcSqqj3nGaGvdyNf52dvYwq4In8A/lCSocpdZrzu/UgHAmwgVndx0jhM5/XH04XB xZDsSL5ny7LIGnvN3pjOMZkomLq0uYxZlCOJpHd+XpVEd5ZtRwLP27+0zPjxtPs8AlaF jABA== X-Gm-Message-State: ALoCoQlTWCNDtvalBu1Tw+goYcgJ5hfZpWO1hmys5VPj0rK7GrGZr2lNzF/3+yCRJ1nCEheZ4BHT X-Received: by 10.66.66.170 with SMTP id g10mr16467623pat.12.1408367451757; Mon, 18 Aug 2014 06:10:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.35.197 with SMTP id n63ls2408206qgn.35.gmail; Mon, 18 Aug 2014 06:10:51 -0700 (PDT) X-Received: by 10.220.247.3 with SMTP id ma3mr22397591vcb.29.1408367451598; Mon, 18 Aug 2014 06:10:51 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id wt5si5369372vcb.61.2014.08.18.06.10.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 06:10:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so5606923vcb.5 for ; Mon, 18 Aug 2014 06:10:51 -0700 (PDT) X-Received: by 10.52.120.51 with SMTP id kz19mr14825vdb.95.1408367451521; Mon, 18 Aug 2014 06:10:51 -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 tc5csp150982vcb; Mon, 18 Aug 2014 06:10:51 -0700 (PDT) X-Received: by 10.70.54.164 with SMTP id k4mr17791449pdp.127.1408367450628; Mon, 18 Aug 2014 06:10:50 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u2si21664620pbz.202.2014.08.18.06.10.44 for ; Mon, 18 Aug 2014 06:10:44 -0700 (PDT) Received-SPF: none (google.com: devicetree-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 S1751546AbaHRNKk (ORCPT + 6 others); Mon, 18 Aug 2014 09:10:40 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:54679 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751490AbaHRNKj (ORCPT ); Mon, 18 Aug 2014 09:10:39 -0400 Received: by mail-pd0-f176.google.com with SMTP id y10so7401484pdj.35 for ; Mon, 18 Aug 2014 06:10:36 -0700 (PDT) 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 Cc: Guodong Xu 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> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@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.174 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 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));