From patchwork Sun Apr 14 17:59:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1085339 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cAIF2Sxh"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44j01G01M3z9sBV for ; Mon, 15 Apr 2019 04:05:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727032AbfDNSFx (ORCPT ); Sun, 14 Apr 2019 14:05:53 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39914 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbfDNSFw (ORCPT ); Sun, 14 Apr 2019 14:05:52 -0400 Received: by mail-pg1-f195.google.com with SMTP id k3so7471430pga.6; Sun, 14 Apr 2019 11:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gB//55n8L81QHySU4Rumr2vNcZinl2RY4UOA+QeaZEo=; b=cAIF2SxhZbsfckrOlZqqE+aLqHVl6WCL07E71Hl52pBbuNmjQuEvQ/SupTgqxEbU2M Wh6TYW53ml9+rlUYTE1eZlKLI5VfNok+RhgJljOQ67Lc5DZjRFyZ2j7LoEIsOCi1slME Wn1B+2V7rMRoLaadrTILdJ+vTBR7lw5Z8ZsmfsNTVz7+6KKS9KIAIwAaUBJTxHyK1bH/ xuJ389Keh0R9W3tNPPj1eznj3sZ29rmiE4MN8JMgr19RrUU7SkG9N0bPhWNEZHPf1WX8 pdU/5TFDdUw7ETXGXWMSAu3Pop+0t3rjy5i2XQ1GaKJi4uvBMYWcJ/4UeEDyqDM32d5W A3KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gB//55n8L81QHySU4Rumr2vNcZinl2RY4UOA+QeaZEo=; b=IlG6dcecv6/NEvQSisBlBIH3uZ53q0jWAkJlULIVZIFMvCsNk3NPF2VyfzaAdSIjNb Kbow2n1nKu7Z1uMOwDkh4lgjcMywHGhJOBqd5PyqYZ0wqaJCJ9Ozkhlzqgq9qk7b59lc tKe+88oIK/Bd/GVxLs7bC1GNjVZx1XPi9gIdyGbjqYoyck6J9+pG/7RwV5I6SEXUFxTS d2IhXCTaAhG4/9/yeTp1KazhAKyIGcxg3ASSrX13uYwwqaaMxygogIQ//F7JFOzbqXbX 1s64Gy6QegJq532VKT+1xyz4MduBTAM2gwtthzUBItULs5vNhuZr67YLYFO9J5mLbBsn qILg== X-Gm-Message-State: APjAAAVn28JcPjt14apPBy9qdgc08rNRJBW6XHbElEwdLo1KxM8EMO3c wykhGuCT7JFatViBTJSDQ4EwtTSQ X-Google-Smtp-Source: APXvYqzVG62rq00uqy5vNFinsdNUpOa6//8LudPdMJJcKUlWBkw/Ocs1HY8qjilzu5tj5OWGVa7bLg== X-Received: by 2002:a62:cfc4:: with SMTP id b187mr69632257pfg.130.1555265152002; Sun, 14 Apr 2019 11:05:52 -0700 (PDT) Received: from localhost.localdomain (ppp94-29-35-107.pppoe.spdop.ru. [94.29.35.107]) by smtp.gmail.com with ESMTPSA id e7sm43359712pfc.132.2019.04.14.11.05.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Apr 2019 11:05:51 -0700 (PDT) From: Dmitry Osipenko To: Liam Girdwood , Mark Brown , Thierry Reding , Jonathan Hunter , Peter De Schrijver Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 1/6] regulator: core: Introduce API for machine-specific regulators coupling Date: Sun, 14 Apr 2019 20:59:34 +0300 Message-Id: <20190414175939.12368-2-digetx@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190414175939.12368-1-digetx@gmail.com> References: <20190414175939.12368-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Right now regulator core supports only one type of regulators coupling, the "voltage max-spread" which keeps voltages of coupled regulators in a given range. A more sophisticated coupling may be required in practice, one example is the NVIDIA Tegra SoC's which besides the max-spreading have other restrictions that must be adhered. Introduce API that allow platforms to provide their own custom coupling algorithms. Signed-off-by: Dmitry Osipenko --- drivers/regulator/core.c | 18 ++++++++++++++++++ include/linux/regulator/machine.h | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 186a37675b50..a98af47e0feb 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -59,6 +59,8 @@ static bool has_full_constraints; static struct dentry *debugfs_root; +static struct regulators_coupler *machine_regulators_coupler; + /* * struct regulator_map * @@ -3596,6 +3598,12 @@ static int regulator_balance_voltage(struct regulator_dev *rdev, return -EPERM; } + if (n_coupled > 1 && + machine_regulators_coupler && + machine_regulators_coupler->balance_voltage) + return machine_regulators_coupler->balance_voltage( + machine_regulators_coupler, rdev, state); + for (i = 0; i < n_coupled; i++) c_rdev_done[i] = false; @@ -4706,6 +4714,16 @@ static int regulator_register_resolve_supply(struct device *dev, void *data) return 0; } +int regulators_coupler_register(struct regulators_coupler *coupler) +{ + if (WARN_ON(machine_regulators_coupler)) + return -EBUSY; + + machine_regulators_coupler = coupler; + + return 0; +} + static void regulator_resolve_coupling(struct regulator_dev *rdev) { struct coupling_desc *c_desc = &rdev->coupling_desc; diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index 1d34a70ffda2..f15c8c5f7f6c 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -19,6 +19,7 @@ #include struct regulator; +struct regulator_dev; /* * Regulator operation constraint flags. These flags are used to enable @@ -265,4 +266,22 @@ static inline int regulator_suspend_finish(void) return 0; } +/** + * struct regulators_coupler - machine-specific regulators coupler + * + * A custom regulators coupler allows platform to customize coupling + * algorithm. + * + * @balance_voltage: Callback invoked when voltage of a coupled regulator is + * changing. The callee should perform voltage balancing + * and change voltage of the coupled regulators. + */ +struct regulators_coupler { + int (*balance_voltage)(struct regulators_coupler *coupler, + struct regulator_dev *rdev, + suspend_state_t state); +}; + +int regulators_coupler_register(struct regulators_coupler *coupler); + #endif From patchwork Sun Apr 14 17:59:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1085340 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="avzx//De"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44j01M61CNz9sBV for ; Mon, 15 Apr 2019 04:05:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727141AbfDNSF6 (ORCPT ); Sun, 14 Apr 2019 14:05:58 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35702 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbfDNSF6 (ORCPT ); Sun, 14 Apr 2019 14:05:58 -0400 Received: by mail-pf1-f196.google.com with SMTP id t21so7467058pfh.2; Sun, 14 Apr 2019 11:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o+Y23+vC9B4RqCaEcK8mExSN5AW1iCVVFid4qSNM/+w=; b=avzx//De6wvvPnmqoVGEfs/cCMo95YEi031OH7Dl+AzyCCpv2l6+Y1v7M1/H2E6UvT /8uY1uXCymoSaDKjT0sCKt+RJyt06DlAqOysjI9OVTp+luJA2as9hlpVU7gECxkIJ1uv QB+bGNDOOg5Wa+6EVg1CnFL25eEywmeuS1FPfsRd3jwmo5zOXfU1z8lds7htBhJ3p7/V 5JN4cZz1UqmU0DoLU5zMKttjMwaiHyVO34Vc2kU0Wg00kHpdVsIh29Dub/PVX8WUlrtL baV/pJoCU03qVAwub/4pw++cMNL6EQZ3vGd7h1I+huFQmLeTw/7ROhMVEsMUmaRM3Hws l7hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o+Y23+vC9B4RqCaEcK8mExSN5AW1iCVVFid4qSNM/+w=; b=XexkC+PtfN//kAFQTgHM0FZyDvU/uu6RgzO3fm9+SKVIGkrDA+jYLxfCkGRZBseVx0 LVRQlCFn+BIbRnps0BMkmLeVNNNAWt4nOFep06siSGXNqP8/qZTOwz/pq97T79luQV1a bsdgqmhwOhAgaLev+KlaqcDr5tjT/DDg4i2qF0nSMebOWJH4QH92ge6Ouq2/OFKkYVTW oYFmrji8zQHuhfwty5XhA+YcRvN0sMeRp2JyhJBynpMEtcoukyGR8yfVHqoWpVrA97GF 06Ntf2Z959VuOoMa/z57j+MFFIgPRkcztj4vSe3O/YXhS/iuCcgb5eZH45tyjqS+6qMF 7BFg== X-Gm-Message-State: APjAAAVaP3yuXmk2KXwBtI6Z3X/vgydexIeBlaI4ago6OeFfFKO8e3O7 5KJHs+jD2udqNI7aq55L+lc= X-Google-Smtp-Source: APXvYqwasMKAu+/HVD/sM4rgvzkkBNhQFTTvm1KSGcQeGJJmIgrl64tDOgzrNhQlSv7Roime8M5Fzw== X-Received: by 2002:aa7:9294:: with SMTP id j20mr6958756pfa.64.1555265157759; Sun, 14 Apr 2019 11:05:57 -0700 (PDT) Received: from localhost.localdomain (ppp94-29-35-107.pppoe.spdop.ru. [94.29.35.107]) by smtp.gmail.com with ESMTPSA id e7sm43359712pfc.132.2019.04.14.11.05.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Apr 2019 11:05:57 -0700 (PDT) From: Dmitry Osipenko To: Liam Girdwood , Mark Brown , Thierry Reding , Jonathan Hunter , Peter De Schrijver Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 2/6] regulator: core: Parse max-spread value per regulator couple Date: Sun, 14 Apr 2019 20:59:35 +0300 Message-Id: <20190414175939.12368-3-digetx@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190414175939.12368-1-digetx@gmail.com> References: <20190414175939.12368-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Parse and validate max-spread value per regulator couple. Now regulator core can take multiple regulator couples, although balancing is still limited to a single couple. Signed-off-by: Dmitry Osipenko --- drivers/regulator/core.c | 13 ++++---- drivers/regulator/of_regulator.c | 49 +++++++++++++++++++++---------- include/linux/regulator/machine.h | 3 +- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index a98af47e0feb..cdb25bbee631 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3440,7 +3440,7 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev, struct coupling_desc *c_desc = &rdev->coupling_desc; struct regulator_dev **c_rdevs = c_desc->coupled_rdevs; struct regulation_constraints *constraints = rdev->constraints; - int max_spread = constraints->max_spread; + int max_spread = constraints->max_spread[0]; int desired_min_uV = 0, desired_max_uV = INT_MAX; int max_current_uV = 0, min_current_uV = INT_MAX; int highest_min_uV = 0, target_uV, possible_uV; @@ -3604,6 +3604,12 @@ static int regulator_balance_voltage(struct regulator_dev *rdev, return machine_regulators_coupler->balance_voltage( machine_regulators_coupler, rdev, state); + if (n_coupled > 2) { + rdev_err(rdev, + "Voltage balancing for multiple regulator couples is unimplemented\n"); + return -EPERM; + } + for (i = 0; i < n_coupled; i++) c_rdev_done[i] = false; @@ -4821,11 +4827,6 @@ static int regulator_init_coupling(struct regulator_dev *rdev) return -EPERM; } - if (rdev->constraints->max_spread <= 0) { - rdev_err(rdev, "wrong max_spread value\n"); - return -EPERM; - } - if (!of_check_coupling_data(rdev)) return -EPERM; diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 6dca0ba044d8..ccca09de92d6 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -34,8 +34,14 @@ static void of_get_regulation_constraints(struct device_node *np, struct device_node *suspend_np; unsigned int mode; int ret, i, len; + int n_phandles; + u32 pvals[MAX_COUPLED]; u32 pval; + n_phandles = of_count_phandle_with_args(np, "regulator-coupled-with", + NULL); + n_phandles = max(n_phandles, 0); + constraints->name = of_get_property(np, "regulator-name", NULL); if (!of_property_read_u32(np, "regulator-min-microvolt", &pval)) @@ -167,9 +173,12 @@ static void of_get_regulation_constraints(struct device_node *np, if (!of_property_read_u32(np, "regulator-system-load", &pval)) constraints->system_load = pval; - if (!of_property_read_u32(np, "regulator-coupled-max-spread", - &pval)) - constraints->max_spread = pval; + if (!of_property_read_u32_array(np, "regulator-coupled-max-spread", + pvals, n_phandles)) { + + for (i = 0; i < n_phandles; i++) + constraints->max_spread[i] = pvals[i]; + } if (!of_property_read_u32(np, "regulator-max-step-microvolt", &pval)) @@ -477,7 +486,8 @@ int of_get_n_coupled(struct regulator_dev *rdev) /* Looks for "to_find" device_node in src's "regulator-coupled-with" property */ static bool of_coupling_find_node(struct device_node *src, - struct device_node *to_find) + struct device_node *to_find, + int *index) { int n_phandles, i; bool found = false; @@ -499,8 +509,10 @@ static bool of_coupling_find_node(struct device_node *src, of_node_put(tmp); - if (found) + if (found) { + *index = i; break; + } } return found; @@ -521,22 +533,28 @@ static bool of_coupling_find_node(struct device_node *src, */ bool of_check_coupling_data(struct regulator_dev *rdev) { - int max_spread = rdev->constraints->max_spread; struct device_node *node = rdev->dev.of_node; int n_phandles = of_get_n_coupled(rdev); struct device_node *c_node; + int index; int i; bool ret = true; - if (max_spread <= 0) { - dev_err(&rdev->dev, "max_spread value invalid\n"); + if (n_phandles >= MAX_COUPLED) { + dev_err(&rdev->dev, "please bump MAX_COUPLED number\n"); return false; } /* iterate over rdev's phandles */ for (i = 0; i < n_phandles; i++) { + int max_spread = rdev->constraints->max_spread[i]; int c_max_spread, c_n_phandles; + if (max_spread <= 0) { + dev_err(&rdev->dev, "max_spread value invalid\n"); + return false; + } + c_node = of_parse_phandle(node, "regulator-coupled-with", i); @@ -553,22 +571,23 @@ bool of_check_coupling_data(struct regulator_dev *rdev) goto clean; } - if (of_property_read_u32(c_node, "regulator-coupled-max-spread", - &c_max_spread)) { + if (!of_coupling_find_node(c_node, node, &index)) { + dev_err(&rdev->dev, "missing 2-way linking for coupled regulators\n"); ret = false; goto clean; } - if (c_max_spread != max_spread) { - dev_err(&rdev->dev, - "coupled regulators max_spread mismatch\n"); + if (of_property_read_u32_index(c_node, "regulator-coupled-max-spread", + index, &c_max_spread)) { ret = false; goto clean; } - if (!of_coupling_find_node(c_node, node)) { - dev_err(&rdev->dev, "missing 2-way linking for coupled regulators\n"); + if (c_max_spread != max_spread) { + dev_err(&rdev->dev, + "coupled regulators max_spread mismatch\n"); ret = false; + goto clean; } clean: diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index f15c8c5f7f6c..0ade1247d3f6 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -15,6 +15,7 @@ #ifndef __LINUX_REGULATOR_MACHINE_H_ #define __LINUX_REGULATOR_MACHINE_H_ +#include #include #include @@ -157,7 +158,7 @@ struct regulation_constraints { int system_load; /* used for coupled regulators */ - int max_spread; + int max_spread[MAX_COUPLED]; /* used for changing voltage in steps */ int max_uV_step; From patchwork Sun Apr 14 17:59:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1085341 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jCQ01NMb"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44j01V01pwz9sCF for ; Mon, 15 Apr 2019 04:06:06 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727186AbfDNSGF (ORCPT ); Sun, 14 Apr 2019 14:06:05 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35706 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbfDNSGE (ORCPT ); Sun, 14 Apr 2019 14:06:04 -0400 Received: by mail-pf1-f194.google.com with SMTP id t21so7467116pfh.2; Sun, 14 Apr 2019 11:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aFVqBZT5v8ld4sa186wu1NMMQzFASES6pQkfldZHoxw=; b=jCQ01NMb799os4ZD7pZMrLxvCXVhN9cKuXiO5c0l02OtvHk8VigTeqUKpr8j0qv3tV 1fs3qGTg5LHYPiySQpbytfnwDLnUI/DmbKX9uXEWYhwzdKDLZdMaF1I3llx3lUGILgtp AykvMrUnk2IrR870zU8aKUha/v+xB2o5afXJFUbxTNca6FUy9XAeKXjLs2PfDXZFGheL 9+D1Sq4seLsivKJMrJtRaBJVJ9ZW96D4PiJVgq2+v7kLHRlR+bPNZoB8oiR93jm2nunk 5OVqhj5kK88n4mp+QO9/zVtesbyc7EuPmznN4sL6OeQrf5f/Eav+c/6dSQn9YbH/Y3aB O4DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aFVqBZT5v8ld4sa186wu1NMMQzFASES6pQkfldZHoxw=; b=KeQ6lHm94RHKXCnnPsKH1+HAO1E/mGNKhw1H05sv+M1czqeEEUutMd6wef2w+JtYvZ FhWZ7FbPjMBEzGBSfo4P6rOSCnXOhelOuoolHOX2KBKQJy9p6qMMRB8gzlqoWaHCP0fh /BnYv+iECf/r7AiRVL8HKJaMQ+wy85fS9D74eBVbf+TPRDa91Q96WzXWtD42o7CKy/WS urcL8ekVzVqnL70PNXQDLcJny9omLBC6fhYG2H9mN/sSZc6KC3irYmV/mt26g4gb592V JvK8ATRsrGffLMcDMqAELApE7BILjr/VGeQkgEQmNFJv/0G0bfIIUOqlSTOohvDGd0aV YY3w== X-Gm-Message-State: APjAAAUOcLFJcwyPNTlKnycl6nECM6mA9ph1iexCwmQ7XfzWq3XRnPB7 ClpAHGqn7L8fUhint08vRek= X-Google-Smtp-Source: APXvYqzIftvpM/y0hmuTkRfkaaq10WZVKQjRZgnvIoAdh+aUd0kdt4pXhz3i39b8NblCpFRvaiSFdA== X-Received: by 2002:a62:47d0:: with SMTP id p77mr70628328pfi.95.1555265163626; Sun, 14 Apr 2019 11:06:03 -0700 (PDT) Received: from localhost.localdomain (ppp94-29-35-107.pppoe.spdop.ru. [94.29.35.107]) by smtp.gmail.com with ESMTPSA id e7sm43359712pfc.132.2019.04.14.11.05.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Apr 2019 11:06:03 -0700 (PDT) From: Dmitry Osipenko To: Liam Girdwood , Mark Brown , Thierry Reding , Jonathan Hunter , Peter De Schrijver Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 3/6] regulator: core: Expose some of core functions Date: Sun, 14 Apr 2019 20:59:36 +0300 Message-Id: <20190414175939.12368-4-digetx@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190414175939.12368-1-digetx@gmail.com> References: <20190414175939.12368-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Expose some of internal functions that are required for implementing machine-specific regulators coupling for NVIDIA Tegra. Signed-off-by: Dmitry Osipenko --- drivers/regulator/core.c | 58 +++++++++++++++----------------- include/linux/regulator/driver.h | 12 +++++++ 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index cdb25bbee631..fa2f4e9e8bcd 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -100,7 +100,6 @@ struct regulator_supply_alias { static int _regulator_is_enabled(struct regulator_dev *rdev); static int _regulator_disable(struct regulator *regulator); -static int _regulator_get_voltage(struct regulator_dev *rdev); static int _regulator_get_current_limit(struct regulator_dev *rdev); static unsigned int _regulator_get_mode(struct regulator_dev *rdev); static int _notifier_call_chain(struct regulator_dev *rdev, @@ -109,15 +108,12 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV); static int regulator_balance_voltage(struct regulator_dev *rdev, suspend_state_t state); -static int regulator_set_voltage_rdev(struct regulator_dev *rdev, - int min_uV, int max_uV, - suspend_state_t state); static struct regulator *create_regulator(struct regulator_dev *rdev, struct device *dev, const char *supply_name); static void _regulator_put(struct regulator *regulator); -static const char *rdev_get_name(struct regulator_dev *rdev) +const char *rdev_get_name(struct regulator_dev *rdev) { if (rdev->constraints && rdev->constraints->name) return rdev->constraints->name; @@ -431,8 +427,8 @@ static struct device_node *of_get_regulator(struct device *dev, const char *supp } /* Platform voltage constraint check */ -static int regulator_check_voltage(struct regulator_dev *rdev, - int *min_uV, int *max_uV) +int regulator_check_voltage(struct regulator_dev *rdev, + int *min_uV, int *max_uV) { BUG_ON(*min_uV > *max_uV); @@ -464,9 +460,9 @@ static int regulator_check_states(suspend_state_t state) /* Make sure we select a voltage that suits the needs of all * regulator consumers */ -static int regulator_check_consumers(struct regulator_dev *rdev, - int *min_uV, int *max_uV, - suspend_state_t state) +int regulator_check_consumers(struct regulator_dev *rdev, + int *min_uV, int *max_uV, + suspend_state_t state) { struct regulator *regulator; struct regulator_voltage *voltage; @@ -577,7 +573,7 @@ static ssize_t regulator_uV_show(struct device *dev, ssize_t ret; regulator_lock(rdev); - ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev)); + ret = sprintf(buf, "%d\n", regulator_get_voltage_rdev(rdev)); regulator_unlock(rdev); return ret; @@ -948,7 +944,7 @@ static int drms_uA_update(struct regulator_dev *rdev) rdev_err(rdev, "failed to set load %d\n", current_uA); } else { /* get output voltage */ - output_uV = _regulator_get_voltage(rdev); + output_uV = regulator_get_voltage_rdev(rdev); if (output_uV <= 0) { rdev_err(rdev, "invalid output voltage found\n"); return -EINVAL; @@ -1061,7 +1057,7 @@ static void print_constraints(struct regulator_dev *rdev) if (!constraints->min_uV || constraints->min_uV != constraints->max_uV) { - ret = _regulator_get_voltage(rdev); + ret = regulator_get_voltage_rdev(rdev); if (ret > 0) count += scnprintf(buf + count, len - count, "at %d mV ", ret / 1000); @@ -1120,7 +1116,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev, if (rdev->constraints->apply_uV && rdev->constraints->min_uV && rdev->constraints->max_uV) { int target_min, target_max; - int current_uV = _regulator_get_voltage(rdev); + int current_uV = regulator_get_voltage_rdev(rdev); if (current_uV == -ENOTRECOVERABLE) { /* This regulator can't be read and must be initialized */ @@ -1130,7 +1126,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev, _regulator_do_set_voltage(rdev, rdev->constraints->min_uV, rdev->constraints->max_uV); - current_uV = _regulator_get_voltage(rdev); + current_uV = regulator_get_voltage_rdev(rdev); } if (current_uV < 0) { @@ -3071,7 +3067,7 @@ static int _regulator_call_set_voltage(struct regulator_dev *rdev, struct pre_voltage_change_data data; int ret; - data.old_uV = _regulator_get_voltage(rdev); + data.old_uV = regulator_get_voltage_rdev(rdev); data.min_uV = min_uV; data.max_uV = max_uV; ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, @@ -3095,7 +3091,7 @@ static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev, struct pre_voltage_change_data data; int ret; - data.old_uV = _regulator_get_voltage(rdev); + data.old_uV = regulator_get_voltage_rdev(rdev); data.min_uV = uV; data.max_uV = uV; ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, @@ -3148,7 +3144,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, unsigned int selector; int old_selector = -1; const struct regulator_ops *ops = rdev->desc->ops; - int old_uV = _regulator_get_voltage(rdev); + int old_uV = regulator_get_voltage_rdev(rdev); trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); @@ -3175,7 +3171,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, best_val = ops->list_voltage(rdev, selector); else - best_val = _regulator_get_voltage(rdev); + best_val = regulator_get_voltage_rdev(rdev); } } else if (ops->set_voltage_sel) { @@ -3294,7 +3290,7 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, * changing the voltage. */ if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) { - current_uV = _regulator_get_voltage(rdev); + current_uV = regulator_get_voltage_rdev(rdev); if (min_uV <= current_uV && current_uV <= max_uV) { voltage->min_uV = min_uV; voltage->max_uV = max_uV; @@ -3331,8 +3327,8 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, return ret; } -static int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, - int max_uV, suspend_state_t state) +int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, + int max_uV, suspend_state_t state) { int best_supply_uV = 0; int supply_change_uV = 0; @@ -3360,7 +3356,7 @@ static int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, best_supply_uV += rdev->desc->min_dropout_uV; - current_supply_uV = _regulator_get_voltage(rdev->supply->rdev); + current_supply_uV = regulator_get_voltage_rdev(rdev->supply->rdev); if (current_supply_uV < 0) { ret = current_supply_uV; goto out; @@ -3411,7 +3407,7 @@ static int regulator_limit_voltage_step(struct regulator_dev *rdev, return 1; if (*current_uV < 0) { - *current_uV = _regulator_get_voltage(rdev); + *current_uV = regulator_get_voltage_rdev(rdev); if (*current_uV < 0) return *current_uV; @@ -3515,7 +3511,7 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev, if (!_regulator_is_enabled(c_rdevs[i])) continue; - tmp_act = _regulator_get_voltage(c_rdevs[i]); + tmp_act = regulator_get_voltage_rdev(c_rdevs[i]); if (tmp_act < 0) return tmp_act; @@ -3557,7 +3553,7 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev, if (n_coupled > 1 && *current_uV == -1) { if (_regulator_is_enabled(rdev)) { - ret = _regulator_get_voltage(rdev); + ret = regulator_get_voltage_rdev(rdev); if (ret < 0) return ret; @@ -3929,7 +3925,7 @@ int regulator_sync_voltage(struct regulator *regulator) } EXPORT_SYMBOL_GPL(regulator_sync_voltage); -static int _regulator_get_voltage(struct regulator_dev *rdev) +int regulator_get_voltage_rdev(struct regulator_dev *rdev) { int sel, ret; bool bypassed; @@ -3946,7 +3942,7 @@ static int _regulator_get_voltage(struct regulator_dev *rdev) return -EPROBE_DEFER; } - return _regulator_get_voltage(rdev->supply->rdev); + return regulator_get_voltage_rdev(rdev->supply->rdev); } } @@ -3962,7 +3958,7 @@ static int _regulator_get_voltage(struct regulator_dev *rdev) } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { ret = rdev->desc->fixed_uV; } else if (rdev->supply) { - ret = _regulator_get_voltage(rdev->supply->rdev); + ret = regulator_get_voltage_rdev(rdev->supply->rdev); } else { return -EINVAL; } @@ -3987,7 +3983,7 @@ int regulator_get_voltage(struct regulator *regulator) int ret; regulator_lock_dependent(regulator->rdev, &ww_ctx); - ret = _regulator_get_voltage(regulator->rdev); + ret = regulator_get_voltage_rdev(regulator->rdev); regulator_unlock_dependent(regulator->rdev, &ww_ctx); return ret; @@ -5296,7 +5292,7 @@ static void regulator_summary_show_subtree(struct seq_file *s, rdev->use_count, rdev->open_count, rdev->bypass_count, regulator_opmode_to_str(opmode)); - seq_printf(s, "%5dmV ", _regulator_get_voltage(rdev) / 1000); + seq_printf(s, "%5dmV ", regulator_get_voltage_rdev(rdev) / 1000); seq_printf(s, "%5dmA ", _regulator_get_current_limit_unlocked(rdev) / 1000); diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 377da2357118..25c5a1862af2 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -20,6 +20,7 @@ #include #include #include +#include #include struct gpio_desc; @@ -552,4 +553,15 @@ void regulator_unlock(struct regulator_dev *rdev); */ int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc, unsigned int selector); + +const char *rdev_get_name(struct regulator_dev *rdev); +int regulator_check_consumers(struct regulator_dev *rdev, + int *min_uV, int *max_uV, + suspend_state_t state); +int regulator_check_voltage(struct regulator_dev *rdev, + int *min_uV, int *max_uV); +int regulator_get_voltage_rdev(struct regulator_dev *rdev); +int regulator_set_voltage_rdev(struct regulator_dev *rdev, + int min_uV, int max_uV, + suspend_state_t state); #endif From patchwork Sun Apr 14 17:59:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1085342 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Jn4km8bE"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44j01b2zpHz9sBV for ; Mon, 15 Apr 2019 04:06:11 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727222AbfDNSGK (ORCPT ); Sun, 14 Apr 2019 14:06:10 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:44653 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbfDNSGK (ORCPT ); Sun, 14 Apr 2019 14:06:10 -0400 Received: by mail-pl1-f195.google.com with SMTP id g12so7423887pll.11; Sun, 14 Apr 2019 11:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4Wp9ZX4IrDtvv191nSQHNek0qy8aM14PPdz/DGwaRqw=; b=Jn4km8bEyVSa/GSNPQfTxL2VtM2UGH2BW5cP8LqdbkCHOer9MZtckcTLjnevSHR+B6 AVJ92NF0vmXJX4qvr1J6dR6pLrVs0BF5AJl3nScD6sxSjd/PwArlgjRrXIdmiRcni/i8 +PJnm4fxvBqwICcxyRHtae2E3oFlGsskC0YM5FW9Oa/8xZAISIyu590Kn1ebGPuGZEWG JK9PDHXd3ziTMRhYtet25oD30Fz0MTIhYcqeBG8AzhcJ374p7T2ZWjKhoBoR5KDdpkQT tM0l1zh30Z9b9wBRkm1U9dk0eTQy8NRee14QSXglu3QJMchaYtHfWQZULOSTrmjZjys/ tjMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Wp9ZX4IrDtvv191nSQHNek0qy8aM14PPdz/DGwaRqw=; b=n0OlOlLs1AWhe1yqdPwLpqCHcz6YcxThFwj17TepXKrQKuD0/pigLcXdP8QU28TfKO 6xLYidwakAQ5pi/8SaUiskBAIrsTAFWpJIzSoildV3/iPymQ6H4UNvsA04MmIyYAOmlr m89TiSDTZTw4ifgFCgLoq4UPhFKtKbvcpnDj+nbzDjAFT2Hq5MaC15GoeLUdziBAAd6/ DFctLNQ9IoLtYhSAqNwGs4sUzraSkYNvqbL14zvDs8qmb9uOK+LCfj+J1NjY3yWkBGdY Az3CiGAr8/L2WAzD/dgHXneCKjBxgkwiN5LKU6xVQEVbDBbW8oPO6DBudaCKpsiZcZ6a Qfpw== X-Gm-Message-State: APjAAAW2H0rrb6Vu4QwdByUzhUu1jT8GgPT6HVfSQLj513agVkqplz4x Kq06WcLlKiMb1ssgbtxy1A4= X-Google-Smtp-Source: APXvYqyx1LKs5dsK0RofeD/yNfbOJIc+3HKTwVjSw7EnSwVVelSty02wgHRzLibNZTng75TRiBLdyA== X-Received: by 2002:a17:902:8b8c:: with SMTP id ay12mr21580007plb.192.1555265169312; Sun, 14 Apr 2019 11:06:09 -0700 (PDT) Received: from localhost.localdomain (ppp94-29-35-107.pppoe.spdop.ru. [94.29.35.107]) by smtp.gmail.com with ESMTPSA id e7sm43359712pfc.132.2019.04.14.11.06.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Apr 2019 11:06:08 -0700 (PDT) From: Dmitry Osipenko To: Liam Girdwood , Mark Brown , Thierry Reding , Jonathan Hunter , Peter De Schrijver Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 4/6] regulator: core Bump MAX_COUPLED to 3 Date: Sun, 14 Apr 2019 20:59:37 +0300 Message-Id: <20190414175939.12368-5-digetx@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190414175939.12368-1-digetx@gmail.com> References: <20190414175939.12368-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org NVIDIA Tegra20 SoC's couple 3 regulators, bump the MAX_COUPLED accordingly to support that case of coupling. Signed-off-by: Dmitry Osipenko --- include/linux/regulator/driver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 25c5a1862af2..25826f2b0ceb 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -15,7 +15,7 @@ #ifndef __LINUX_REGULATOR_DRIVER_H_ #define __LINUX_REGULATOR_DRIVER_H_ -#define MAX_COUPLED 2 +#define MAX_COUPLED 3 #include #include From patchwork Sun Apr 14 17:59:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1085343 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rrqUcffK"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44j01j3NmFz9sCF for ; Mon, 15 Apr 2019 04:06:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727245AbfDNSGQ (ORCPT ); Sun, 14 Apr 2019 14:06:16 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35448 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbfDNSGQ (ORCPT ); Sun, 14 Apr 2019 14:06:16 -0400 Received: by mail-pl1-f193.google.com with SMTP id w24so7445124plp.2; Sun, 14 Apr 2019 11:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qVBW97awzTJKhYXGwIHgWUzej8z/IQ3WOFtKKwxPxG8=; b=rrqUcffKwK+WKPWcxDM7TD3WvL1Y644lis3o9UKiu7B/ojqp4gEpiLBoQd8HRAlWXC d2R+bf1vVM2hN70HHoCKmIv/rImAv3eYBf2OA0mcHOB+8f9lQI3ALlFi+4nUEOPY9lK5 0C10xtiWucyt5AFgrD1rVH8Yw00rSlw7Q4clmFYfjUtGuxy3FcLT55YrTmiOqbQCSLNK 5e8V+Bg7COBWkBnF2rmEoHB9QF4iaKbzxva4nl9P0kT7JoV5FHCnAm5fF0g8NAScTNiV 496z4DitxxJTToCyeVVP0wSchP998AmrO3oGRPQOBsHC4OSSseFWbrKAb/bk3eMFjmAX OwDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qVBW97awzTJKhYXGwIHgWUzej8z/IQ3WOFtKKwxPxG8=; b=JYEcc7Xv163YULqlPoHfmWI+9+kBqGGKkrw+Vqv1iWGIHc2j0mbCfJv29rDN0fcmYa d6rLi6xRn1ChMmNhyl0zh/o0ZI/flM34OLmB9zCXjsTF7ErhgaoHPS1wT3ffqtJa4jB3 4f55BnQvrRd68iP97nuFQmUrS9z9hz2OuqXnC4VxTtZfVL5utUXUplH4hMlVgCg9/s0V ZROQKq+6cSuZeqnLgyQ+EQ5Gl+e0UpiPh067qyEwUxKvw6gQx2kzYI715leyZrXa2QPJ pIBPFVO90aYDj2qllbeKe6H4UTQw2ce+nNYZS83SaCmIDgG3C/MERtYWDOLpKFxT5gzb UvzA== X-Gm-Message-State: APjAAAV7bTIUlXyh/Outxe5560gG8/jknnck2Hbz019E0l1j+6AJDipo 5mCh13yIwt7+sMLCuBUC7LU= X-Google-Smtp-Source: APXvYqwhxJqvcMcgYn3oOM4MjedIfUauTtG8NOcgbhQx+YY3l5AFBv1b1hx7lu9GtYo8HE5y4aCZ3g== X-Received: by 2002:a17:902:e48c:: with SMTP id cj12mr69088976plb.93.1555265175382; Sun, 14 Apr 2019 11:06:15 -0700 (PDT) Received: from localhost.localdomain (ppp94-29-35-107.pppoe.spdop.ru. [94.29.35.107]) by smtp.gmail.com with ESMTPSA id e7sm43359712pfc.132.2019.04.14.11.06.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Apr 2019 11:06:14 -0700 (PDT) From: Dmitry Osipenko To: Liam Girdwood , Mark Brown , Thierry Reding , Jonathan Hunter , Peter De Schrijver Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 5/6] soc/tegra: regulators: Add regulators coupler for Tegra20 Date: Sun, 14 Apr 2019 20:59:38 +0300 Message-Id: <20190414175939.12368-6-digetx@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190414175939.12368-1-digetx@gmail.com> References: <20190414175939.12368-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Add regulators coupler for Tegra20 SoC's that performs voltage balancing of a coupled regulators and thus provides voltage scaling functionality. Signed-off-by: Dmitry Osipenko --- drivers/soc/tegra/Kconfig | 6 + drivers/soc/tegra/Makefile | 1 + drivers/soc/tegra/regulators-tegra20.c | 304 +++++++++++++++++++++++++ 3 files changed, 311 insertions(+) create mode 100644 drivers/soc/tegra/regulators-tegra20.c diff --git a/drivers/soc/tegra/Kconfig b/drivers/soc/tegra/Kconfig index a0b03443d8c1..545c0da2e069 100644 --- a/drivers/soc/tegra/Kconfig +++ b/drivers/soc/tegra/Kconfig @@ -133,3 +133,9 @@ config SOC_TEGRA_POWERGATE_BPMP def_bool y depends on PM_GENERIC_DOMAINS depends on TEGRA_BPMP + +config SOC_TEGRA20_VOLTAGE_COUPLER + bool "Voltage scaling support for Tegra20 SoC's" + def_bool y + depends on ARCH_TEGRA_2x_SOC + depends on REGULATOR diff --git a/drivers/soc/tegra/Makefile b/drivers/soc/tegra/Makefile index 902759fe5f4d..9f0bdd53bef8 100644 --- a/drivers/soc/tegra/Makefile +++ b/drivers/soc/tegra/Makefile @@ -5,3 +5,4 @@ obj-y += common.o obj-$(CONFIG_SOC_TEGRA_FLOWCTRL) += flowctrl.o obj-$(CONFIG_SOC_TEGRA_PMC) += pmc.o obj-$(CONFIG_SOC_TEGRA_POWERGATE_BPMP) += powergate-bpmp.o +obj-$(CONFIG_SOC_TEGRA20_VOLTAGE_COUPLER) += regulators-tegra20.o diff --git a/drivers/soc/tegra/regulators-tegra20.c b/drivers/soc/tegra/regulators-tegra20.c new file mode 100644 index 000000000000..3f005b804af3 --- /dev/null +++ b/drivers/soc/tegra/regulators-tegra20.c @@ -0,0 +1,304 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Voltage regulators coupling resolver for NVIDIA Tegra20 + * + * Author: Dmitry Osipenko + */ + +#define pr_fmt(fmt) "tegra voltage-coupler: " fmt + +#include +#include +#include +#include +#include + +struct tegra_regulators_coupler { + struct regulators_coupler coupler; + int core_min_uV; +}; + +static const char * const cpu_names[] = { + "vdd_sys_sm0,vdd_core", + "+1.0vs_sm1,vdd_cpu", + "vdd_sm1,vdd_cpu", + "VDD_CPU_1.0V", + "vdd_cpu", +}; + +static const char * const core_names[] = { + "vdd_sys_sm1,vdd_cpu", + "+1.2vs_sm0,vdd_core", + "vdd_sm0,vdd_core", + "VDD_CORE_1.2V", + "vdd_core", +}; + +static const char * const rtc_names[] = { + "+1.2vs_ldo2,vdd_rtc", + "vdd_ldo2,vdd_rtc", + "VDD_RTC_1.2V", + "vdd_rtc", +}; + +static inline struct tegra_regulators_coupler * +to_tegra_coupler(struct regulators_coupler *coupler) +{ + return container_of(coupler, struct tegra_regulators_coupler, coupler); +} + +static int tegra20_core_limit(struct tegra_regulators_coupler *tegra, + struct regulator_dev *core_rdev, + struct regulator_dev *rtc_rdev) +{ + int core_min_uV; + + if (tegra->core_min_uV > 0) + return tegra->core_min_uV; + + core_min_uV = regulator_get_voltage_rdev(core_rdev); + if (core_min_uV > 0) { + pr_info("core minimum voltage limited to %duV\n", core_min_uV); + tegra->core_min_uV = core_min_uV; + } + + return core_min_uV; +} + +static int tegra20_core_rtc_update(struct tegra_regulators_coupler *tegra, + struct regulator_dev *core_rdev, + struct regulator_dev *rtc_rdev, + int cpu_uV, int cpu_min_uV) +{ + int core_min_uV, core_max_uV = INT_MAX; + int rtc_min_uV, rtc_max_uV = INT_MAX; + int core_target_uV; + int rtc_target_uV; + int core_uV; + int rtc_uV; + int err; + + /* + * The core voltage scaling is currently not hooked up in drivers, + * hence we will limit the minimum core voltage to the initial value. + * This should be good enough for the time being. + */ + core_min_uV = tegra20_core_limit(tegra, core_rdev, rtc_rdev); + if (core_min_uV < 0) + return core_min_uV; + + err = regulator_check_voltage(core_rdev, &core_min_uV, &core_max_uV); + if (err) + return err; + + err = regulator_check_consumers(core_rdev, &core_min_uV, &core_max_uV, + PM_SUSPEND_ON); + if (err) + return err; + + core_min_uV = max(cpu_min_uV + 125000, core_min_uV); + if (core_min_uV > core_max_uV) + return -EINVAL; + + core_uV = regulator_get_voltage_rdev(core_rdev); + if (core_uV < 0) + return core_uV; + + if (cpu_uV + 120000 > core_uV) + pr_err("core-cpu voltage constraint violated: %d %d\n", + core_uV, cpu_uV + 120000); + + rtc_uV = regulator_get_voltage_rdev(rtc_rdev); + if (rtc_uV < 0) + return rtc_uV; + + if (cpu_uV + 120000 > rtc_uV) + pr_err("rtc-cpu voltage constraint violated: %d %d\n", + rtc_uV, cpu_uV + 120000); + + if (abs(core_uV - rtc_uV) > 170000) + pr_err("core-rtc voltage constraint violated: %d %d\n", + core_uV, rtc_uV); + + rtc_min_uV = max(cpu_min_uV + 125000, core_min_uV - 150000); + + err = regulator_check_voltage(rtc_rdev, &rtc_min_uV, &rtc_max_uV); + if (err) + return err; + + while (core_uV != core_min_uV || rtc_uV != rtc_min_uV) { + if (core_uV < core_min_uV) { + core_target_uV = min(core_uV + 150000, core_min_uV); + core_target_uV = min(rtc_uV + 150000, core_target_uV); + } else { + core_target_uV = max(core_uV - 150000, core_min_uV); + core_target_uV = max(rtc_uV - 150000, core_target_uV); + } + + err = regulator_set_voltage_rdev(core_rdev, + core_target_uV, + core_max_uV, + PM_SUSPEND_ON); + if (err) + return err; + + core_uV = core_target_uV; + + if (rtc_uV < rtc_min_uV) { + rtc_target_uV = min(rtc_uV + 150000, rtc_min_uV); + rtc_target_uV = min(core_uV + 150000, rtc_target_uV); + } else { + rtc_target_uV = max(rtc_uV - 150000, rtc_min_uV); + rtc_target_uV = max(core_uV - 150000, rtc_target_uV); + } + + err = regulator_set_voltage_rdev(rtc_rdev, + rtc_target_uV, + rtc_max_uV, + PM_SUSPEND_ON); + if (err) + return err; + + rtc_uV = rtc_target_uV; + } + + return 0; +} + +static int tegra20_core_voltage_update(struct tegra_regulators_coupler *tegra, + struct regulator_dev *cpu_rdev, + struct regulator_dev *core_rdev, + struct regulator_dev *rtc_rdev) +{ + int cpu_uV; + + cpu_uV = regulator_get_voltage_rdev(cpu_rdev); + if (cpu_uV < 0) + return cpu_uV; + + return tegra20_core_rtc_update(tegra, core_rdev, rtc_rdev, + cpu_uV, cpu_uV); +} + +static int tegra20_cpu_voltage_update(struct tegra_regulators_coupler *tegra, + struct regulator_dev *cpu_rdev, + struct regulator_dev *core_rdev, + struct regulator_dev *rtc_rdev) +{ + int cpu_min_uV = 0; + int cpu_max_uV = INT_MAX; + int cpu_uV; + int err; + + err = regulator_check_voltage(cpu_rdev, &cpu_min_uV, &cpu_max_uV); + if (err) + return err; + + err = regulator_check_consumers(cpu_rdev, &cpu_min_uV, &cpu_max_uV, + PM_SUSPEND_ON); + if (err) + return err; + + cpu_uV = regulator_get_voltage_rdev(cpu_rdev); + if (cpu_uV < 0) + return cpu_uV; + + if (cpu_min_uV > cpu_uV) { + err = tegra20_core_rtc_update(tegra, core_rdev, rtc_rdev, + cpu_uV, cpu_min_uV); + if (err) + return err; + + err = regulator_set_voltage_rdev(cpu_rdev, cpu_min_uV, + cpu_max_uV, PM_SUSPEND_ON); + if (err) + return err; + } else if (cpu_min_uV < cpu_uV) { + err = regulator_set_voltage_rdev(cpu_rdev, cpu_min_uV, + cpu_max_uV, PM_SUSPEND_ON); + if (err) + return err; + + err = tegra20_core_rtc_update(tegra, core_rdev, rtc_rdev, + cpu_uV, cpu_min_uV); + if (err) + return err; + } + + return 0; +} + +static struct regulator_dev *lookup_rdev(struct regulator_dev *rdev, + const char * const *names, + unsigned int num_names) +{ + struct coupling_desc *c_desc = &rdev->coupling_desc; + unsigned int i, k; + + for (i = 0; i < num_names; i++) { + if (!strcmp(names[i], rdev_get_name(rdev))) + return rdev; + } + + for (k = 0; k < c_desc->n_coupled; k++) { + rdev = c_desc->coupled_rdevs[k]; + + for (i = 0; i < num_names; i++) { + if (!strcmp(names[i], rdev_get_name(rdev))) + return rdev; + } + } + + pr_err_once("%s: failed for %s\n", __func__, rdev_get_name(rdev)); + + for (i = 0; i < num_names; i++) + pr_err_once("%s: entry%u: %s\n", __func__, i, names[i]); + + return NULL; +} + +static int tegra20_regulator_balance_voltage(struct regulators_coupler *coupler, + struct regulator_dev *rdev, + suspend_state_t state) +{ + struct tegra_regulators_coupler *tegra = to_tegra_coupler(coupler); + struct regulator_dev *core_rdev; + struct regulator_dev *cpu_rdev; + struct regulator_dev *rtc_rdev; + + core_rdev = lookup_rdev(rdev, core_names, ARRAY_SIZE(core_names)); + cpu_rdev = lookup_rdev(rdev, cpu_names, ARRAY_SIZE(cpu_names)); + rtc_rdev = lookup_rdev(rdev, rtc_names, ARRAY_SIZE(rtc_names)); + + if (!core_rdev || !cpu_rdev || !rtc_rdev || state != PM_SUSPEND_ON) { + pr_err("regulators are not coupled properly\n"); + return -EINVAL; + } + + if (rdev == cpu_rdev) + return tegra20_cpu_voltage_update(tegra, cpu_rdev, + core_rdev, rtc_rdev); + + if (rdev == core_rdev) + return tegra20_core_voltage_update(tegra, cpu_rdev, + core_rdev, rtc_rdev); + + pr_err("driving %s voltage not permitted\n", rdev_get_name(rtc_rdev)); + + return -EPERM; +} + +static struct tegra_regulators_coupler tegra20_coupler = { + .coupler = { + .balance_voltage = tegra20_regulator_balance_voltage, + }, +}; + +static int __init tegra_regulators_coupler_init(void) +{ + if (!of_machine_is_compatible("nvidia,tegra20")) + return 0; + + return regulators_coupler_register(&tegra20_coupler.coupler); +} +arch_initcall(tegra_regulators_coupler_init); From patchwork Sun Apr 14 17:59:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1085344 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WNFCAOfn"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44j01q5C74z9sBV for ; Mon, 15 Apr 2019 04:06:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727272AbfDNSGW (ORCPT ); Sun, 14 Apr 2019 14:06:22 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:43167 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725780AbfDNSGW (ORCPT ); Sun, 14 Apr 2019 14:06:22 -0400 Received: by mail-pf1-f196.google.com with SMTP id c8so7444590pfd.10; Sun, 14 Apr 2019 11:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eyeyE30t3+QkNeGEJDj6X4cHeIUYKsd28+MRNW6dPlE=; b=WNFCAOfncHPYIhxyKuHaPJIjuIjk8hYRd6NsO+vanH1eYr2YVfR5JPpazSYc/NT/9F R9kF7bINdAIfRax1ykGfnzjBW6PjGQ4zGI/+bVmu6Vn4gnAnnPViE5/tzxzmhUtTOsKI zcoe28PjRkZfm6lNJYwnxdtUyxNmwnpmouUbym1MzoaBqkBO9Ls43r9OyGlM3QqAx35x IXY0ctQNTmR8TWx/yJenxutW+1knDRbAlHWcxIkSYHm7Z3EuUGEQOeuHiHdZNLgJLFXU wFROTAYaYdyamsoy1+7JEcxlIh+Migg1O7/IMoXGoucvkZaS4YqzK4SHUWuJE2HhljdV qTjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eyeyE30t3+QkNeGEJDj6X4cHeIUYKsd28+MRNW6dPlE=; b=sA7b0TG0ZWOvfVXbtrgi4JdOt5di0+jZwKM5GoMlje/5lDW4rUushpvTeCp53ssIyO xI7/C83cimyxqT81TbtmAvR3tiNEb3oUEK6QPwjYLtwq2iqxY+Ot+jEwXo3n19I4OsVs uQ0plfxTiwHJZNXLWtRinLgmsGGK2MkWakPGWcyB45RzpMkpixBCrd+oB2wS0cGU1Itz RwLCCDMaJAlsjIyBtX1atKGDkthluaY27rBhMrWmd322YiGRViClCEKk9zpx9TjC9E33 TYDZZxd8DrpHmL++Gnm0tkpoenunqo1yG0r3jcEKtwkVXZTKP7y+TuGSOh3ky0KP3MgZ qLHg== X-Gm-Message-State: APjAAAXFk2109/Ts5SmxTyd3ZbG0Sr3VKhS1L8jRfFPlGNPZUrMEaoFS +ucFBL9OCIXyls3kudRgBvA= X-Google-Smtp-Source: APXvYqz1KY2XMNv4I+uLKKoYmOKU9/A/hha3VmXnCVfrzc4Uikh9kNiAlywvB3mb60y6bz6e0PT6PA== X-Received: by 2002:a65:408b:: with SMTP id t11mr61973250pgp.372.1555265181127; Sun, 14 Apr 2019 11:06:21 -0700 (PDT) Received: from localhost.localdomain (ppp94-29-35-107.pppoe.spdop.ru. [94.29.35.107]) by smtp.gmail.com with ESMTPSA id e7sm43359712pfc.132.2019.04.14.11.06.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Apr 2019 11:06:20 -0700 (PDT) From: Dmitry Osipenko To: Liam Girdwood , Mark Brown , Thierry Reding , Jonathan Hunter , Peter De Schrijver Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 6/6] soc/tegra: regulators: Add regulators coupler for Tegra30 Date: Sun, 14 Apr 2019 20:59:39 +0300 Message-Id: <20190414175939.12368-7-digetx@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190414175939.12368-1-digetx@gmail.com> References: <20190414175939.12368-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Add regulators coupler for Tegra30 SoC's that performs voltage balancing of a coupled regulators and thus provides voltage scaling functionality. Signed-off-by: Dmitry Osipenko --- drivers/soc/tegra/Kconfig | 6 + drivers/soc/tegra/Makefile | 1 + drivers/soc/tegra/regulators-tegra30.c | 256 +++++++++++++++++++++++++ 3 files changed, 263 insertions(+) create mode 100644 drivers/soc/tegra/regulators-tegra30.c diff --git a/drivers/soc/tegra/Kconfig b/drivers/soc/tegra/Kconfig index 545c0da2e069..a5235af27644 100644 --- a/drivers/soc/tegra/Kconfig +++ b/drivers/soc/tegra/Kconfig @@ -139,3 +139,9 @@ config SOC_TEGRA20_VOLTAGE_COUPLER def_bool y depends on ARCH_TEGRA_2x_SOC depends on REGULATOR + +config SOC_TEGRA30_VOLTAGE_COUPLER + bool "Voltage scaling support for Tegra30 SoC's" + def_bool y + depends on ARCH_TEGRA_3x_SOC + depends on REGULATOR diff --git a/drivers/soc/tegra/Makefile b/drivers/soc/tegra/Makefile index 9f0bdd53bef8..9c809c1814bd 100644 --- a/drivers/soc/tegra/Makefile +++ b/drivers/soc/tegra/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_SOC_TEGRA_FLOWCTRL) += flowctrl.o obj-$(CONFIG_SOC_TEGRA_PMC) += pmc.o obj-$(CONFIG_SOC_TEGRA_POWERGATE_BPMP) += powergate-bpmp.o obj-$(CONFIG_SOC_TEGRA20_VOLTAGE_COUPLER) += regulators-tegra20.o +obj-$(CONFIG_SOC_TEGRA30_VOLTAGE_COUPLER) += regulators-tegra30.o diff --git a/drivers/soc/tegra/regulators-tegra30.c b/drivers/soc/tegra/regulators-tegra30.c new file mode 100644 index 000000000000..ecd6a984e045 --- /dev/null +++ b/drivers/soc/tegra/regulators-tegra30.c @@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Voltage regulators coupling resolver for NVIDIA Tegra30 + * + * Author: Dmitry Osipenko + */ + +#define pr_fmt(fmt) "tegra voltage-coupler: " fmt + +#include +#include +#include +#include +#include + +#include + +struct tegra_regulators_coupler { + struct regulators_coupler coupler; + int core_min_uV; +}; + +static const char * const cpu_names[] = { + "vdd_cpu,vdd_sys", + "+V1.0_VDD_CPU", + "vdd_cpu", +}; + +static const char * const core_names[] = { + "tps62361-vout", + "tps62362-vout", + "vdd_core", +}; + +static inline struct tegra_regulators_coupler * +to_tegra_coupler(struct regulators_coupler *coupler) +{ + return container_of(coupler, struct tegra_regulators_coupler, coupler); +} + +static int tegra30_core_limit(struct tegra_regulators_coupler *tegra, + struct regulator_dev *core_rdev) +{ + if (tegra->core_min_uV > 0) + return tegra->core_min_uV; + + tegra->core_min_uV = regulator_get_voltage_rdev(core_rdev); + if (tegra->core_min_uV > 0) + pr_info("core minimum voltage limited to %duV\n", + tegra->core_min_uV); + + return tegra->core_min_uV; +} + +static int tegra30_core_cpu_limit(int cpu_uV) +{ + if (cpu_uV < 800000) + return 950000; + + if (cpu_uV < 900000) + return 1000000; + + if (cpu_uV < 1000000) + return 1100000; + + if (cpu_uV < 1100000) + return 1200000; + + if (cpu_uV < 1250000) { + switch (tegra_sku_info.cpu_speedo_id) { + case 0 ... 1: + case 4: + case 7: + case 8: + return 1200000; + + default: + return 1300000; + } + } + + return -EINVAL; +} + +static int tegra30_voltage_update(struct tegra_regulators_coupler *tegra, + struct regulator_dev *cpu_rdev, + struct regulator_dev *core_rdev) +{ + int cpu_min_uV, cpu_max_uV = INT_MAX; + int core_min_uV, core_max_uV = INT_MAX; + int core_min_limited_uV; + int core_target_uV; + int cpu_target_uV; + int core_uV; + int cpu_uV; + int err; + + /* + * The CORE voltage scaling is currently not hooked up in drivers, + * hence we will limit the minimum CORE voltage to the initial value. + * This should be good enough for the time being. + */ + core_min_uV = tegra30_core_limit(tegra, core_rdev); + if (core_min_uV < 0) + return core_min_uV; + + err = regulator_check_consumers(core_rdev, &core_min_uV, &core_max_uV, + PM_SUSPEND_ON); + if (err) + return err; + + cpu_min_uV = core_min_uV - 300000; + + err = regulator_check_consumers(cpu_rdev, &cpu_min_uV, &cpu_max_uV, + PM_SUSPEND_ON); + if (err) + return err; + + err = regulator_check_voltage(cpu_rdev, &cpu_min_uV, &cpu_max_uV); + if (err) + return err; + + cpu_uV = regulator_get_voltage_rdev(cpu_rdev); + if (cpu_uV < 0) + return cpu_uV; + + core_uV = regulator_get_voltage_rdev(core_rdev); + if (core_uV < 0) + return core_uV; + + /* + * Bootloader shall set up voltages correctly, but if it + * happens that there is a violation, then try to fix it + * at first. + */ + core_min_limited_uV = tegra30_core_cpu_limit(cpu_uV); + if (core_min_limited_uV < 0) + return core_min_limited_uV; + + core_min_uV = max(core_min_uV, tegra30_core_cpu_limit(cpu_min_uV)); + + err = regulator_check_voltage(core_rdev, &core_min_uV, &core_max_uV); + if (err) + return err; + + if (core_min_limited_uV > core_uV) { + pr_err("core voltage constraint violated: %d %d %d\n", + core_uV, core_min_limited_uV, cpu_uV); + goto update_core; + } + + while (cpu_uV != cpu_min_uV || core_uV != core_min_uV) { + if (cpu_uV < cpu_min_uV) { + cpu_target_uV = min(cpu_uV + 100000, cpu_min_uV); + } else { + cpu_target_uV = max(cpu_uV - 100000, cpu_min_uV); + cpu_target_uV = max(core_uV - 300000, cpu_target_uV); + } + + err = regulator_set_voltage_rdev(cpu_rdev, + cpu_target_uV, + cpu_max_uV, + PM_SUSPEND_ON); + if (err) + return err; + + cpu_uV = cpu_target_uV; +update_core: + core_min_limited_uV = tegra30_core_cpu_limit(cpu_uV); + if (core_min_limited_uV < 0) + return core_min_limited_uV; + + core_target_uV = max(core_min_limited_uV, core_min_uV); + + if (core_uV < core_target_uV) { + core_target_uV = min(core_target_uV, core_uV + 100000); + core_target_uV = min(core_target_uV, cpu_uV + 300000); + } else { + core_target_uV = max(core_target_uV, core_uV - 100000); + } + + err = regulator_set_voltage_rdev(core_rdev, + core_target_uV, + core_max_uV, + PM_SUSPEND_ON); + if (err) + return err; + + core_uV = core_target_uV; + } + + return 0; +} + +static struct regulator_dev *lookup_rdev(struct regulator_dev *rdev, + const char * const *names, + unsigned int num_names) +{ + struct coupling_desc *c_desc = &rdev->coupling_desc; + unsigned int i, k; + + for (i = 0; i < num_names; i++) { + if (!strcmp(names[i], rdev_get_name(rdev))) + return rdev; + } + + for (k = 0; k < c_desc->n_coupled; k++) { + rdev = c_desc->coupled_rdevs[k]; + + for (i = 0; i < num_names; i++) { + if (!strcmp(names[i], rdev_get_name(rdev))) + return rdev; + } + } + + pr_err_once("%s: failed for %s\n", __func__, rdev_get_name(rdev)); + + for (i = 0; i < num_names; i++) + pr_err_once("%s: entry%u: %s\n", __func__, i, names[i]); + + return NULL; +} + +static int tegra30_regulator_balance_voltage(struct regulators_coupler *coupler, + struct regulator_dev *rdev, + suspend_state_t state) +{ + struct tegra_regulators_coupler *tegra = to_tegra_coupler(coupler); + struct regulator_dev *core_rdev; + struct regulator_dev *cpu_rdev; + + core_rdev = lookup_rdev(rdev, core_names, ARRAY_SIZE(core_names)); + cpu_rdev = lookup_rdev(rdev, cpu_names, ARRAY_SIZE(cpu_names)); + + if (!core_rdev || !cpu_rdev || state != PM_SUSPEND_ON) { + pr_err("regulators are not coupled properly\n"); + return -EINVAL; + } + + return tegra30_voltage_update(tegra, cpu_rdev, core_rdev); +} + +static struct tegra_regulators_coupler tegra30_coupler = { + .coupler = { + .balance_voltage = tegra30_regulator_balance_voltage, + }, +}; + +static int __init tegra_regulators_coupler_init(void) +{ + if (!of_machine_is_compatible("nvidia,tegra30")) + return 0; + + return regulators_coupler_register(&tegra30_coupler.coupler); +} +arch_initcall(tegra_regulators_coupler_init);