From patchwork Mon Aug 18 13:09:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guodong Xu X-Patchwork-Id: 35494 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A074620676 for ; Mon, 18 Aug 2014 13:11:04 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id eb12sf36431447oac.5 for ; Mon, 18 Aug 2014 06:11:04 -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=9VfuhO/oE5BaiHsMNtteKaMGZTvM02Y0fhpcJf4vX0k=; b=YpEgYAaTSUZBxNtNyY+ih+8F1VoSdNBj8Y2a2gsouPYW/SP3rFB2Ydojk7g/KdGwbS Ybg8MASUV5/nuNmkox/2LzfIR1zWmdnicsna67DqgYA018YhjnclH4WRV6FK2DeyX6cQ k0UGTXos7xo0kXyyXTIJCNhLo6RlyRdYOlLe1xqnOdBlDKSfUdwD7JKNZfzHtWnFygA7 wG6kNDJDzbyXOXc9hKcMQi+FeclE7opGNHCnq5ZwdBrKShdh/Wi92KWov8aurP5uzTgQ MHsdMHVshicOzYGkAyz3xdRy6NmtWVsM4WH+SeAxc83QDofDtI9FpO0bH5eYvxbjRPcT GaDw== X-Gm-Message-State: ALoCoQnEPN2Y7aAcndHI69E5H8KIzxOEj8g/1V1SRp4Q3gM7W/yHe2XJ3w00DNoUNdZtXE503fg8 X-Received: by 10.182.81.161 with SMTP id b1mr16993420oby.1.1408367464296; Mon, 18 Aug 2014 06:11:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.41.11 with SMTP id y11ls2350548qgy.23.gmail; Mon, 18 Aug 2014 06:11:04 -0700 (PDT) X-Received: by 10.220.250.142 with SMTP id mo14mr16943043vcb.26.1408367464186; Mon, 18 Aug 2014 06:11:04 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id l12si352037vcy.45.2014.08.18.06.11.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 06:11:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id hy4so5795895vcb.27 for ; Mon, 18 Aug 2014 06:11:04 -0700 (PDT) X-Received: by 10.220.15.8 with SMTP id i8mr661776vca.45.1408367464090; Mon, 18 Aug 2014 06:11:04 -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 tc5csp151002vcb; Mon, 18 Aug 2014 06:11:03 -0700 (PDT) X-Received: by 10.66.226.100 with SMTP id rr4mr36047777pac.48.1408367463114; Mon, 18 Aug 2014 06:11:03 -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.57 for ; Mon, 18 Aug 2014 06:10:57 -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 S1751905AbaHRNKt (ORCPT + 6 others); Mon, 18 Aug 2014 09:10:49 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:42751 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751903AbaHRNKs (ORCPT ); Mon, 18 Aug 2014 09:10:48 -0400 Received: by mail-pd0-f173.google.com with SMTP id w10so7546672pde.32 for ; Mon, 18 Aug 2014 06:10:45 -0700 (PDT) X-Received: by 10.70.90.76 with SMTP id bu12mr6440492pdb.31.1408367444724; Mon, 18 Aug 2014 06:10:44 -0700 (PDT) Received: from localhost.localdomain ([119.9.85.21]) by mx.google.com with ESMTPSA id q5sm24764968pdf.70.2014.08.18.06.10.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Aug 2014 06:10:43 -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 3/6] regulator: core: add guard delay between calling regulator_disable and _enable Date: Mon, 18 Aug 2014 21:09:13 +0800 Message-Id: <1408367356-2628-4-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.182 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: , Some regulator require a minimum delay between its disable and next enable. This is to avoid damages when out-of-range frequent disable/enable of a single regulator can bring to the regulator chip. Add @off_on_delay to struct regulator_desc. Device drivers' can use this field to set this guard time. Add @last_off_jiffy to struct regulator_dev. When @off_on_delay is set by driver, regulator core can store its last off (disable) time into this field. Signed-off-by: Guodong Xu --- drivers/regulator/core.c | 31 +++++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 4976451..7bce715 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1813,6 +1813,31 @@ static int _regulator_do_enable(struct regulator_dev *rdev) trace_regulator_enable(rdev_get_name(rdev)); + if (rdev->desc->off_on_delay) { + /* if needed, keep a distance of off_on_delay from last time + * this regulator was disabled. + */ + unsigned long start_jiffy = jiffies; + unsigned long intended, max_delay, remaining; + + max_delay = usecs_to_jiffies(rdev->desc->off_on_delay); + intended = rdev->last_off_jiffy + max_delay; + + if (time_before(start_jiffy, intended)) { + /* calc remaining jiffies to deal with one-time + * timer wrapping. + * in case of multiple timer wrapping, either it can be + * detected by out-of-range remaining, or it cannot be + * detected and we gets a panelty of + * _regulator_enable_delay(). + */ + remaining = intended - start_jiffy; + if (remaining <= max_delay) + _regulator_enable_delay( + jiffies_to_usecs(remaining)); + } + } + if (rdev->ena_pin) { ret = regulator_ena_gpio_ctrl(rdev, true); if (ret < 0) @@ -1925,6 +1950,12 @@ static int _regulator_do_disable(struct regulator_dev *rdev) return ret; } + /* cares about last_off_jiffy only if off_on_delay is required by + * device. + */ + if (rdev->desc->off_on_delay) + rdev->last_off_jiffy = jiffies; + trace_regulator_disable_complete(rdev_get_name(rdev)); return 0; diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 4b62813..efe058f 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -238,6 +238,7 @@ enum regulator_type { * @bypass_val_off: Disabling value for control when using regmap set_bypass * * @enable_time: Time taken for initial enable of regulator (in uS). + * @off_on_delay: guard time (in uS), before re-enabling a regulator */ struct regulator_desc { const char *name; @@ -276,6 +277,8 @@ struct regulator_desc { unsigned int bypass_val_off; unsigned int enable_time; + + unsigned int off_on_delay; }; /** @@ -348,6 +351,9 @@ struct regulator_dev { struct regulator_enable_gpio *ena_pin; unsigned int ena_gpio_state:1; + + /* time when this regulator was disabled last time */ + unsigned long last_off_jiffy; }; struct regulator_dev *