From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24884C47437 for ; Thu, 17 Dec 2020 18:14:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0AEFB23977 for ; Thu, 17 Dec 2020 18:14:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731091AbgLQSN5 (ORCPT ); Thu, 17 Dec 2020 13:13:57 -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-Google-Smtp-Source: ABdhPJxdOm63SmKECVhD/Ri1mq2T3tx66jApca+i51NwPxJdgmqEwm5XIsXzuInwJ0NSw6phFVcb5Q== 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-tegra@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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52B95C2BB9A for ; Thu, 17 Dec 2020 18:07:38 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F404D2396F for ; Thu, 17 Dec 2020 18:07:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F404D2396F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=driverdev-devel-bounces@linuxdriverproject.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id D442687639; Thu, 17 Dec 2020 18:07:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OhUikxK_hilp; Thu, 17 Dec 2020 18:07:37 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 5369287637; Thu, 17 Dec 2020 18:07:37 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 3020C1BF477 for ; Thu, 17 Dec 2020 18:07:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2D3CC8764E for ; Thu, 17 Dec 2020 18:07:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B6lK_iQ0rtRe for ; Thu, 17 Dec 2020 18:07:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 4693F8762A for ; Thu, 17 Dec 2020 18:07:33 +0000 (UTC) Received: by mail-lf1-f41.google.com with SMTP id m12so59848144lfo.7 for ; Thu, 17 Dec 2020 10:07:33 -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=paL6ghyW74I3yjNKOZ+E/TzkPvchCSkXXpS5m0q7/L/8ZlTJkaogJ541PSmCjpu3gV cfhCx4erX6VKT2oKoEZ3YYYQm+r55VpfIdd3VlDjdAPK6cEbbPELwYuP/AUOBFpJP/fn bIiUr9u/ato1MjUl5soUKJNfMTT0wSLD9Iu6Xvg0SvHA5ncNaarzWJPEd654eSSThMTS ACJBD0YcsPBWmaaL2mi8QvL26WlnkTumvkYKObctO+rApdQQVfEvqNckycxpJqOcMvE8 MvJXu6VC+YSXY5dl0/v7TOeJbDyrbgHll0QqNYjXfEv7HDQb18xo42Utg2xMtra/gfBO 1IPQ== X-Gm-Message-State: AOAM5312cRXmXpSYVGWXzUbtSb2E/OBdgMjc0SZvWUfIyqDQtG0xf8dH dOF1N3X5ICnZZ97KGXU/cV8= X-Google-Smtp-Source: ABdhPJxdOm63SmKECVhD/Ri1mq2T3tx66jApca+i51NwPxJdgmqEwm5XIsXzuInwJ0NSw6phFVcb5Q== 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 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 X-BeenThere: driverdev-devel@linuxdriverproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-clk@vger.kernel.org, linux-media@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" 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 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4996FC4361B for ; Fri, 18 Dec 2020 08:34:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C7C323B46 for ; Fri, 18 Dec 2020 08:34:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C7C323B46 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 258A46E027; Fri, 18 Dec 2020 08:34:10 +0000 (UTC) Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1228B6E1F2 for ; Thu, 17 Dec 2020 18:07:33 +0000 (UTC) Received: by mail-lf1-x12e.google.com with SMTP id o17so56899275lfg.4 for ; 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=HE5DcNQ/kEackqR9LkvBVz9iAArr+wZKJGZ+AJvjPguc2j7eFp6f2K1fWkemZTWqfG HIG149EcuTeLtXGlaR4mIEvLcjf6SKJgZR2oZ4BrWxAEGBadDB+Do410TUy2d46C/xBE WKwz8IyAsEZXn35svvXdufZIhVRAFRNpWz55D+xcr8zaedtN6uHdNH4679rCHJ3eyPaK Nbp5t1vFkhyEO1hI0qSF7HtN3waWWQx/NKAXZ2oRPRh/E/MgAtfGsK1ReD8Gok1NPTAZ iP+hfyaD7BWXIFPmFCjR9xJ4Ymkwkb3BYBT4lUKd8vzOInU8uQ1W3Fc8r/YGtG0mWilP ik6w== X-Gm-Message-State: AOAM5313bD4BHnUvsKAv9wvYI6muOhSKZ5iQH3DM3nakvNdnW/vIVOyo 6nAmg4HHSXZ8jSAm7XhifH4= X-Google-Smtp-Source: ABdhPJxdOm63SmKECVhD/Ri1mq2T3tx66jApca+i51NwPxJdgmqEwm5XIsXzuInwJ0NSw6phFVcb5Q== 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 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 X-Mailman-Approved-At: Fri, 18 Dec 2020 08:31:48 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-clk@vger.kernel.org, linux-media@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel