Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1453792pxu; Thu, 17 Dec 2020 10:15:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzL3yuz6ktiCe71LClTBDndcqWuAZbde7WIXFEiXZhCN2c2sVaO+puGaezgGaWdx72lHE9J X-Received: by 2002:a17:906:b307:: with SMTP id n7mr289209ejz.102.1608228952038; Thu, 17 Dec 2020 10:15:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608228952; cv=none; d=google.com; s=arc-20160816; b=tgIwmriPtdtdrSbv598MUkJmq/5a6bMWit5mKskOQY/AXPMz9H5Wh3eOwprQbSAx1b RGJrqn8cv+CantIVarzaHbLqriuQSUHNkkPUhnIHYyhkT64WQXs5aR+6wiZ59P8eOnHw N/Zmt0NxpRLQPi2xcNjClIfvlTqbdKdC7xXK4jGio/QEybHTm8oCk7DrDX2bVcQj4B3x sThdbtZdFxuSgOdpq5wRBZz7HTPrPwzDSe/9mg44h3SWXGSL7+j7twL5t10KdGAYkYTt 5OotQwpXWz50YCHqRpbA19UmullpGEfyXEInWHvG/0qcNFfoJsJWq0EfpUyJV9+O9hOp Wbcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3UVBePDvj8+JPmPnd9lky7oATp5P2thSWicPxP1xnR8=; b=oUGGD4QqxlnRbKPZVwVNprQZCWL5aSUBsOn3tlJBgGPpz8IIjQfyroKlx7oHhuWLpo gatj/XqVWrvv1WZddbrp7i8ODRmclVjCbfvC5JWRDDcAGu3BtXF7+5NGwOG4JvYs9ZnF T37oUaGVR7H6dqBfNqVIWFqWm44k4AR7vqAoiVOVJEg0ErjyweaDdqW4ZTqq4MHiM1aU Jod5vRrcKz7TmVeX3AWLqMVejGYHxB+6OyBYRE1cRZHWRpBzN+1/X711iKNL3yIepGmf tAhM0SkA5prCw5JaMZuHZTRSjI60KRInTlR24aoqaYSzP/xL2v04xEkVlANaT90ohsfv aLaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aJbEbbQC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq15si4691522edb.15.2020.12.17.10.15.27; Thu, 17 Dec 2020 10:15:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aJbEbbQC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731458AbgLQSN6 (ORCPT + 99 others); Thu, 17 Dec 2020 13:13:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730069AbgLQSIl (ORCPT ); Thu, 17 Dec 2020 13:08:41 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02423C0611CD; Thu, 17 Dec 2020 10:07:33 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id a9so59799079lfh.2; Thu, 17 Dec 2020 10:07:32 -0800 (PST) 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=3UVBePDvj8+JPmPnd9lky7oATp5P2thSWicPxP1xnR8=; b=aJbEbbQC/He+JGwsqe9/kWlEHU6l6eJbWVOB+YDfBF2TKFMQVztNRBn7FxxkGhbddC ev33yPj1MSIMzyO+TFiwew5f4KfWulf7oFRaBTCyv3TgOFe4ujYEo+I+Z7tTL1KNM9jb L13m6ejsc71Ofyfwl85z3HfWqR+upQ0tPHMikLcTSLd2xpjYhAO714ZZLJjjJnGvqT4l ZJNGw47xKKIA1sXCEKL2oXmxaJWoioML4IYpvBFET5w2EnSIPfL+gc3dMvbdCqforTUn zZEu2tnDe+CPvHNGmkMFDxfxv13NlKEVcT6f5P2yfM4ci6lqceo5M9extORpjM92O5sn CBKQ== 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=3UVBePDvj8+JPmPnd9lky7oATp5P2thSWicPxP1xnR8=; b=abLPPF+BQ+ab9fwr9HtoacCnwBq5lJnJ6nYuKwGEWeFDX9h5nNXofSJ1UAanqgknlG m9Z5XLTp+3QgqKPofOm4ZJDD+hGVxNSCcPKdBKDyKbGcovcW7mvnZdXZB6a/uaU7lWdF 7b1AbKOpEio5O8hgmXqJ/IDqBd4FRoGtQnxWt5BX3gyofq6JokgJ0ATm82Rc1+nbbqCu X9JxZ3jKX4wHwbojqfOJcG6NVEJTl5kK/2ljyPbg1oJBII47uVKhKlMH3N0VpBmuRE8g BMnXyYv4V1mGbeRer7Ro9ll5MzrOhz5/F8v9ttebPvlAHj7r/zQ7aSEvpYxXD+/4Tl7p 2rWA== X-Gm-Message-State: AOAM530UE/715L1GzqLnejaNkEizlPUCasnSLG0AZ3tzCqncIo66spkH K7KhTMZlQhXWi9tXe53q8+Q= X-Received: by 2002:a05:6512:3054:: with SMTP id b20mr15125654lfb.45.1608228451555; Thu, 17 Dec 2020 10:07:31 -0800 (PST) Received: from localhost.localdomain (109-252-192-57.dynamic.spd-mgts.ru. [109.252.192.57]) by smtp.gmail.com with ESMTPSA id u5sm655596lff.78.2020.12.17.10.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Dec 2020 10:07:31 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Liam Girdwood , Ulf Hansson , Mauro Carvalho Chehab , Rob Herring , Peter Geis , Nicolas Chauvet , Krzysztof Kozlowski , "Rafael J. Wysocki" , Kevin Hilman , Peter De Schrijver , Viresh Kumar , Stephen Boyd , Michael Turquette Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, linux-clk@vger.kernel.org Subject: [PATCH v2 10/48] opp: Add dev_pm_opp_set_voltage() Date: Thu, 17 Dec 2020 21:06:00 +0300 Message-Id: <20201217180638.22748-11-digetx@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201217180638.22748-1-digetx@gmail.com> References: <20201217180638.22748-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add dev_pm_opp_set_voltage() which allows OPP table users to set voltage in accordance to a given OPP. In particular this is needed for driving voltage of a generic power domain which uses OPPs and doesn't have a clock. Signed-off-by: Dmitry Osipenko --- drivers/opp/core.c | 52 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 11 +++++---- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 500d6c716283..eab37b3a27bb 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2541,3 +2541,55 @@ int dev_pm_opp_sync_regulators(struct device *dev) return ret; } EXPORT_SYMBOL_GPL(dev_pm_opp_sync_regulators); + +/** + * dev_pm_opp_set_voltage() - Change voltage of regulators + * @dev: device for which we do this operation + * @opp: opp based on which the voltages are to be configured + * + * Change voltage of the OPP table regulators. + * + * Return: 0 on success or a negative error value. + */ +int dev_pm_opp_set_voltage(struct device *dev, struct dev_pm_opp *opp) +{ + struct opp_table *opp_table; + struct regulator *reg; + int ret = 0; + + /* Device may not have OPP table */ + opp_table = _find_opp_table(dev); + if (IS_ERR(opp_table)) + return 0; + + /* Regulator may not be required for the device */ + if (!opp_table->regulators) + goto put_table; + + /* This function only supports single regulator per device */ + if (WARN_ON(opp_table->regulator_count > 1)) { + dev_err(dev, "multiple regulators are not supported\n"); + ret = -EINVAL; + goto put_table; + } + + reg = opp_table->regulators[0]; + ret = _set_opp_voltage(dev, reg, opp->supplies); + + if (!opp_table->enabled) { + ret = regulator_enable(reg); + if (ret < 0) { + dev_warn(dev, "Failed to enable regulator: %d", ret); + goto put_table; + } + + opp_table->enabled = true; + } + +put_table: + /* Drop reference taken by _find_opp_table() */ + dev_pm_opp_put_opp_table(opp_table); + + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_set_voltage); diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 4c79faa2025e..f311a8b2ca04 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -157,6 +157,7 @@ int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) void dev_pm_opp_remove_table(struct device *dev); void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask); int dev_pm_opp_sync_regulators(struct device *dev); +int dev_pm_opp_set_voltage(struct device *dev, struct dev_pm_opp *opp); #else static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) { @@ -372,6 +373,11 @@ static inline int dev_pm_opp_sync_regulators(struct device *dev) return -ENOTSUPP; } +static inline int dev_pm_opp_set_voltage(struct device *dev, struct dev_pm_opp *opp) +{ + return -ENOTSUPP; +} + #endif /* CONFIG_PM_OPP */ #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) @@ -448,11 +454,6 @@ static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_ta { return -ENOTSUPP; } - -static inline int dev_pm_opp_sync_regulators(struct device *dev) -{ - return -ENOTSUPP; -} #endif #endif /* __LINUX_OPP_H__ */ -- 2.29.2