From patchwork Mon Aug 17 02:46:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 52466 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by patches.linaro.org (Postfix) with ESMTPS id 54DC422B12 for ; Mon, 17 Aug 2015 02:47:06 +0000 (UTC) Received: by labth1 with SMTP id th1sf43342602lab.2 for ; Sun, 16 Aug 2015 19:47:05 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=oglM3i6xFo2hHnaQssAcwZjJUeqW47Zzbzgprg+tsNE=; b=l5dbd25D2emmlnlXxHc/A1meW8wOGj7unThPxBBNHkTqs773LtS5I0JzoC4Lvlz28I YSna3EAUhPificreEb9tNwYuncS8XX25CsV29ZsptSsIA1iEY+3fN/qyboQjqOdCMM3n h9whqkQQ4Z2tsPQDsUL1Cm3uKcO088N7QWUGWbF8sPjxxWSWVSu+E71D2AtrnsVg+8r1 S4vtM7vAlzC2Y1tO7dZCOBz+vh/jruSZcwEz1ymHQE34smmDrIMV0/4bPFresPuXJglZ +VJr+JIBeseY+b3H6rtGH2ulvVPTrEX+MbOv4CYq9SitHRKlkPbEcO+u8AbxN7VBeJtU sXkQ== X-Gm-Message-State: ALoCoQlAlaNkMzpUHo9C3Zal+KxK1iNjEOoge7rdIY7rF6T3xIbEdCtCfXjzxItycFQ+2n6sX8rJ X-Received: by 10.180.98.133 with SMTP id ei5mr4281382wib.2.1439779625282; Sun, 16 Aug 2015 19:47:05 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.195 with SMTP id ao3ls676866lac.53.gmail; Sun, 16 Aug 2015 19:47:04 -0700 (PDT) X-Received: by 10.112.77.168 with SMTP id t8mr53939936lbw.70.1439779624960; Sun, 16 Aug 2015 19:47:04 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id ci5si10826706lad.29.2015.08.16.19.47.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Aug 2015 19:47:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by lagz9 with SMTP id z9so70814146lag.3 for ; Sun, 16 Aug 2015 19:47:04 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr53403652lbc.112.1439779624870; Sun, 16 Aug 2015 19:47: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.112.7.198 with SMTP id l6csp1167636lba; Sun, 16 Aug 2015 19:47:02 -0700 (PDT) X-Received: by 10.70.3.98 with SMTP id b2mr111860026pdb.107.1439779621979; Sun, 16 Aug 2015 19:47:01 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ie1si22156039pbb.199.2015.08.16.19.47.01; Sun, 16 Aug 2015 19:47:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753755AbbHQCq6 (ORCPT + 28 others); Sun, 16 Aug 2015 22:46:58 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:33728 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752117AbbHQCq4 (ORCPT ); Sun, 16 Aug 2015 22:46:56 -0400 Received: by pabyb7 with SMTP id yb7so97936481pab.0 for ; Sun, 16 Aug 2015 19:46:56 -0700 (PDT) X-Received: by 10.69.11.5 with SMTP id ee5mr112639813pbd.89.1439779616165; Sun, 16 Aug 2015 19:46:56 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id im2sm12677730pbc.34.2015.08.16.19.46.54 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 16 Aug 2015 19:46:55 -0700 (PDT) From: Viresh Kumar To: broonie@kernel.org Cc: linaro-kernel@lists.linaro.org, sboyd@codeaurora.org, nm@ti.com, Viresh Kumar , Liam Girdwood , linux-kernel@vger.kernel.org (open list:VOLTAGE AND CURRENT REGULATOR FRAMEWORK) Subject: [PATCH V3] regulator: core: Define regulator_set_voltage_triplet() Date: Mon, 17 Aug 2015 08:16:51 +0530 Message-Id: <5f42eb06c47a316cd7138e4f75a4176eea4fb202.1439779404.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 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: viresh.kumar@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.215.54 as permitted sender) smtp.mailfrom=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: , Voltage tolerance isn't necessarily same on both sides of the target voltage and regulator_set_voltage_tol() wouldn't be suitable in such cases. Add another routine regulator_set_voltage_triplet(), which accepts target, min and max voltages as arguments. This first tries to set the voltage between the target voltage and the upper limit, then fall back on the full range. The idea behind this is to set regulator's voltage as close to the target voltage, as possible. Based on regulator_set_voltage_tol(). Signed-off-by: Viresh Kumar --- V2->V3: - Improve commit log, with how its useful at regulator API level. - Compare regulator_set_voltage() == 0, instead of !regulator_set_voltage(). V1->V2: - Change the order of arguments to regulator_set_voltage_triplet() to min/target/max instead of target/min/max. include/linux/regulator/consumer.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index f8a689ed62a5..e325d4606b62 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -552,6 +552,16 @@ static inline int regulator_count_voltages(struct regulator *regulator) } #endif +static inline int regulator_set_voltage_triplet(struct regulator *regulator, + int min_uV, int target_uV, + int max_uV) +{ + if (regulator_set_voltage(regulator, target_uV, max_uV) == 0) + return 0; + + return regulator_set_voltage(regulator, min_uV, max_uV); +} + static inline int regulator_set_voltage_tol(struct regulator *regulator, int new_uV, int tol_uV) {