From patchwork Wed Aug 13 11:33:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guodong Xu X-Patchwork-Id: 35346 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f69.google.com (mail-oi0-f69.google.com [209.85.218.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BEDAC203C5 for ; Wed, 13 Aug 2014 11:35:31 +0000 (UTC) Received: by mail-oi0-f69.google.com with SMTP id h136sf46088442oig.8 for ; Wed, 13 Aug 2014 04:35:31 -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=l6NvS56co0gr7Mw+Y82LP1bJcHkU9ITvDw79VVuhaNw=; b=agaojlLo9iR+5R3pyknCYojTxglvTA97J1l7yM6FXEHYfeVO1EACQqguVctCXx/rMu 0hi4vOCEFFEg0lbg0YMWQoY93RfoW5vbio5u7HgXaE/iBZDVUlczrZ+el2KUko/vLw6v TN+aQv3HvyP5VfJp3OpTTKW5Xfrrci1726TkOrGT4jj8N/rGnoxzRoruJZtMgWW8U+VE Lzusca9Hj3qegzY6ZzYr/o/8taKjTem5Zrcz5KBP/VLu9pJGYVUgM+josgCSE9sSj9Hz MTqBxu3ySKdEVk4M8U7j0cocO80u+cEiAy3pAd2WN+tWxX+lyR570rNHAvD5+Avd9W5t kHzg== X-Gm-Message-State: ALoCoQnGNlN8+NaNCbV0ryHOInhANkmC8NxzvUbXBSRKBwXUpB5WI1S1BRHCTN9Y5Zo2laOZ0vUp X-Received: by 10.42.10.66 with SMTP id p2mr2777704icp.28.1407929731391; Wed, 13 Aug 2014 04:35:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.202 with SMTP id w68ls572307qge.4.gmail; Wed, 13 Aug 2014 04:35:31 -0700 (PDT) X-Received: by 10.220.119.8 with SMTP id x8mr85727vcq.62.1407929731161; Wed, 13 Aug 2014 04:35:31 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id wz7si899708vdc.65.2014.08.13.04.35.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Aug 2014 04:35:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id im17so14946074vcb.3 for ; Wed, 13 Aug 2014 04:35:31 -0700 (PDT) X-Received: by 10.220.182.1 with SMTP id ca1mr2963043vcb.21.1407929731080; Wed, 13 Aug 2014 04:35:31 -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 tc5csp323203vcb; Wed, 13 Aug 2014 04:35:30 -0700 (PDT) X-Received: by 10.70.96.102 with SMTP id dr6mr3598058pdb.86.1407929730114; Wed, 13 Aug 2014 04:35:30 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7si1293159pat.194.2014.08.13.04.35.28 for ; Wed, 13 Aug 2014 04:35:30 -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 S1752578AbaHMLfY (ORCPT + 23 others); Wed, 13 Aug 2014 07:35:24 -0400 Received: from mail-pd0-f178.google.com ([209.85.192.178]:64619 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752516AbaHMLfT (ORCPT ); Wed, 13 Aug 2014 07:35:19 -0400 Received: by mail-pd0-f178.google.com with SMTP id w10so14397986pde.9 for ; Wed, 13 Aug 2014 04:35:19 -0700 (PDT) X-Received: by 10.66.151.194 with SMTP id us2mr3609899pab.15.1407929719199; Wed, 13 Aug 2014 04:35:19 -0700 (PDT) Received: from localhost.localdomain ([120.136.45.59]) by mx.google.com with ESMTPSA id ya1sm1832872pbb.91.2014.08.13.04.35.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Aug 2014 04:35:17 -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 3/7] regulator: core: add guard delay between calling regulator_disable and _enable Date: Wed, 13 Aug 2014 19:33:40 +0800 Message-Id: <1407929624-8737-4-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.172 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 67d4246..c218c62 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1807,6 +1807,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) @@ -1919,6 +1944,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 *