From patchwork Wed Jan 20 22:26:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12033801 X-Patchwork-Delegate: viresh.linux@gmail.com 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.8 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=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 AA5ECC433DB for ; Wed, 20 Jan 2021 22:32:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A147235E4 for ; Wed, 20 Jan 2021 22:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728920AbhATWbo (ORCPT ); Wed, 20 Jan 2021 17:31:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387520AbhATW1o (ORCPT ); Wed, 20 Jan 2021 17:27:44 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BD36C061757; Wed, 20 Jan 2021 14:27:03 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id l12so19345721wry.2; Wed, 20 Jan 2021 14:27:03 -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=n+YYPxYgIaXaJZpbVcLE+s+aMMIfmEVlIGclm9I+uGo=; b=jWDK5lkswMxFB5eDSywZJkZnnjT1+XRgOnMTr2hqt5W6G+5IGqI3QqX1kWVZHD3Q5Y HAxAKqu8v9KK/dAIm6xL5tNTLPn6VppSZCF6Kahpzly/AEbtelgNjuq+xVbNA/4Rlscq Y5oRecBmc+UMufl1gZZjhWofYJ0qBnJ+uMqnMwNucrDbnRIKvfpjezDP05HU4E6C5wHM /s8vcMqQjPxoO3X7hXd2t1zcaexwrC4hvpV4kQ6VbLCGVrw5fo/4CV4AySEqb5rpZRr/ +e4Kca1/mgUveyl/mMEJdZi4bNOUNz4qZPexBDSRzH2P7b8KFgEys/bqeV/WD7KZc6bh wMZQ== 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=n+YYPxYgIaXaJZpbVcLE+s+aMMIfmEVlIGclm9I+uGo=; b=pflOE2VLxcJMlG5/E0oCZMoDeusOKXKQQ1lF3VjZn1vx5gdand/e5t+imGQ9nVvYwc XtZrJieCORz48a7rXS2ZxdA/HztMNMsZAVPY0v59cWQop+9PlBVIqsdaJdVTQVv7H1QD i1xi9oTyCSWjvDPgSVGAScCwgTmgmPoHir6bFBGqBiGq8J5jh1nzxPNF5t5NEaT75aHl 92iERZ0MfD7M9ZpOQq0RkdPBqNjtePp8b2wzqgxPYggDFwVONcFLtJTvh8mHTFiGgIja bOJMOzaifteDYp2MUFMqtuY0FHv6KytUIBcXJkAKJD0/r/akS2mX/q6YHnvfzTv1k0OE JpQg== X-Gm-Message-State: AOAM532zVpcJTN8NUcSRb+50VtHRxoAcVbPmOkcGo/obtyMewxMwSXQC UxsIeWMNriaATNI4RydesIs= X-Google-Smtp-Source: ABdhPJyrZQPB3Ey0eDn6/hzyTw+mqhkHR/gqn+t/H8qUzNN0aJvK4qP5fvE8ZBW10NjAHqsqO7KpKw== X-Received: by 2002:adf:fdcb:: with SMTP id i11mr11401188wrs.349.1611181622424; Wed, 20 Jan 2021 14:27:02 -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 i131sm5663710wmi.25.2021.01.20.14.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 14:27:02 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Liam Girdwood , Ulf Hansson , Peter Geis , Nicolas Chauvet , "Rafael J. Wysocki" , Kevin Hilman , Peter De Schrijver , Viresh Kumar , Stephen Boyd , Nishanth Menon , Yangtao Li , Matt Merhar Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 1/4] opp: Export devm_pm_opp_attach_genpd() Date: Thu, 21 Jan 2021 01:26:46 +0300 Message-Id: <20210120222649.28149-2-digetx@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210120222649.28149-1-digetx@gmail.com> References: <20210120222649.28149-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The devm_pm_opp_attach_genpd() lost its export by accident when it was merged. Re-add the missing export, Tegra DRM driver now works when compiled as a loadable kernel module since it uses the exported function. Fixes: 22300b8fd92a ("opp: Add devm_pm_opp_attach_genpd") Reported-by: Nicolas Chauvet Signed-off-by: Dmitry Osipenko --- drivers/opp/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index f80b6f1ca108..6049b17f99d6 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2297,6 +2297,7 @@ devm_pm_opp_attach_genpd(struct device *dev, const char **names, return opp_table; } +EXPORT_SYMBOL_GPL(devm_pm_opp_attach_genpd); /** * dev_pm_opp_xlate_performance_state() - Find required OPP's pstate for src_table. From patchwork Wed Jan 20 22:26:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12033807 X-Patchwork-Delegate: viresh.linux@gmail.com 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.8 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,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 A451EC433E0 for ; Wed, 20 Jan 2021 22:34:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5166723437 for ; Wed, 20 Jan 2021 22:34:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732209AbhATWbu (ORCPT ); Wed, 20 Jan 2021 17:31:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387537AbhATW1p (ORCPT ); Wed, 20 Jan 2021 17:27:45 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1357FC0613C1; Wed, 20 Jan 2021 14:27:05 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id m4so24558708wrx.9; Wed, 20 Jan 2021 14:27:05 -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=4sp7b1NkfUJTCMUO91JmNlpsU6mJZQVutgbbdE6RDGY=; b=aUke85VsKCiPdz0Alc+YVwiQ0D4OI3iN5Q/Ft5p4OGNth9UBoPyxKCjWVccoJDPdQD 2xYsS/Ad1rMamkETdZCN7KobY1i6BY7N4PdnqimTfhKA5xdCKuZMMT7mAq+xWWO8etZx yoLyG4tpxW0gttL2py33fOhMJNJIJvb44mp3HSa8miGwftaFdn5v4cyG9G/e8InCzOWb MlL8C9t886/SfzTV92Y9oCLdIhVSyDVuDsxj9xRzpVnSojas25y0LQBY+TM6QoMmbqYD 4+jGnIb/57fKBM/Zn4ogILKlQ6I2bgKCi80H8ldygDZsVQPiP1AuBSXfA+zObYKoi7D1 4zdw== 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=4sp7b1NkfUJTCMUO91JmNlpsU6mJZQVutgbbdE6RDGY=; b=VpCeW/U4NRW2qciTvQhluOySDezGOgqwtT9BpkEdNZ0iGW6SNWlcJXAmksfAvUMRFH eTRRFhlHnv8L/eMR1LypgybXuQ64eWC7ucz8FoPRzRUoItQs7CreK95UQI3A0MxJkYvB 20R41Xb7jBjdh3HppUm5qabln2mcHuXr5q6aUsDUfbJM6etDX4kq8Y10SM1paGMIDo+l Ll2PtHLgdRS/i2wIlVjjia/dRadtW3fUBk5RIKgvv02IXjdexNg7ftZ/YyHcQm41xY3i NyYD4MhiTzN7ELtUEwtNqSBYxgRwoDy6MklCHTPOPmWRbhak1lOpw/a0goi5q2oH1exN vL7w== X-Gm-Message-State: AOAM532+MSVbmAxPn1b4NYwUSh+dD8tnNz2IZ0iiKCAUg38wdcLBrlK/ wIqzEYKFywwJVsnsPW/aAY2mO3ebUog= X-Google-Smtp-Source: ABdhPJy8G4MQ/SRCrPj6NJeeBTZe5Zq2RrOu/W40d2elBko46pfsfliw+dQ5Aq24ftgBdjkzluMy8g== X-Received: by 2002:adf:f8d2:: with SMTP id f18mr4353685wrq.238.1611181623894; Wed, 20 Jan 2021 14:27:03 -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 i131sm5663710wmi.25.2021.01.20.14.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 14:27:03 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Liam Girdwood , Ulf Hansson , Peter Geis , Nicolas Chauvet , "Rafael J. Wysocki" , Kevin Hilman , Peter De Schrijver , Viresh Kumar , Stephen Boyd , Nishanth Menon , Yangtao Li , Matt Merhar Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 2/4] opp: Add dev_pm_opp_sync_regulators() Date: Thu, 21 Jan 2021 01:26:47 +0300 Message-Id: <20210120222649.28149-3-digetx@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210120222649.28149-1-digetx@gmail.com> References: <20210120222649.28149-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Extend OPP API with dev_pm_opp_sync_regulators() function, which syncs voltage state of regulators. Tested-by: Peter Geis Tested-by: Nicolas Chauvet Tested-by: Matt Merhar Signed-off-by: Dmitry Osipenko --- drivers/opp/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 6 ++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 6049b17f99d6..43e62e0e3d5b 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2659,3 +2659,44 @@ void dev_pm_opp_remove_table(struct device *dev) dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_remove_table); + +/** + * dev_pm_opp_sync_regulators() - Sync state of voltage regulators + * @dev: device for which we do this operation + * + * Sync voltage state of the OPP table regulators. + * + * Return: 0 on success or a negative error value. + */ +int dev_pm_opp_sync_regulators(struct device *dev) +{ + struct opp_table *opp_table; + struct regulator *reg; + int i, 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; + + /* Nothing to sync if voltage wasn't changed */ + if (!opp_table->enabled) + goto put_table; + + for (i = 0; i < opp_table->regulator_count; i++) { + reg = opp_table->regulators[i]; + ret = regulator_sync_voltage(reg); + if (ret) + break; + } +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_sync_regulators); diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index f8e9a8e3eb59..80cdb9af8268 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -163,6 +163,7 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cp 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); #else static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) { @@ -399,6 +400,11 @@ static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask { } +static inline int dev_pm_opp_sync_regulators(struct device *dev) +{ + return -ENOTSUPP; +} + #endif /* CONFIG_PM_OPP */ #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) From patchwork Wed Jan 20 22:26:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12033803 X-Patchwork-Delegate: viresh.linux@gmail.com 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.8 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,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 9BBCFC433E0 for ; Wed, 20 Jan 2021 22:32:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61E8123437 for ; Wed, 20 Jan 2021 22:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730157AbhATWbf (ORCPT ); Wed, 20 Jan 2021 17:31:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387562AbhATW1r (ORCPT ); Wed, 20 Jan 2021 17:27:47 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BC26C0613CF; Wed, 20 Jan 2021 14:27:06 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id 7so17324474wrz.0; Wed, 20 Jan 2021 14:27:06 -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=qAjqiq2dwbDskT9XOWElQP0slOUTW1tc29GpHVtC6mo=; b=mB5594KRNwJjZ8ATsswKkpqvGkCiHsAGRjjozSmbKq+q9aBNATyNc2yrt1FbVQewUi ahMzU4OateHBTd/MwjJBj3zcsvNlE0kSf7dNdCvSHAaJ7nn74Kh4fnUOV9C1IBqC2ZO+ iMCmGyRJzasA4puZKAQtzZ3KEjgOvofWHrkzJYtZWQoUqUw/vgVmqMeK53EFX3iN+Bj2 t0U3KoeZ2xQ9qg8koz7UFwnDvwy3yIb9ucCtRSG0fR06FZbTamoudTvB1C1lLZPyviXQ eAvjZPiD29QTBf80YhkGj4NauPFGjoNc9LKZevRfLwnnizkMNvg78BHleEe10ACiXy0B NfEQ== 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=qAjqiq2dwbDskT9XOWElQP0slOUTW1tc29GpHVtC6mo=; b=nctAq7NXF2IEzSVlsH54I2xqIGT5ZnYBCuTuuBS0goBv9PCLCsoxUVhGgOZc1+Y4VH 22pJ0myOPrBa9+Wr+sMyzQT8uW4wf2j05Cp8MYNVOUCYpEtl4WaK/PPyd8L5tdvOn8jb JP/3ThDDJ//I0zPxANR8EEvnVrrWlsz1lU7j95Vz6fGoYBEPbzt8+FlPdLxf1LILqHQU x9i+UZdxAXcPpJgd2MKBv1Q+UUf/MJw63HNEYowC84+txJpmGP92a2KEm4+cIAHnC/QA DwUcQo616iB4fr0t+8Rgu7ZYQzn/OIwTE94+ewUI6jUJRA8PJY5NY+xygEVllvMcKUHL 7mRw== X-Gm-Message-State: AOAM5306OLyNQu7dWIHOKAhhIFYFOne/kwhC3hkv5wle6eNQyxoSM+el wxrHG7CIB7B3OgaRxakpKgA= X-Google-Smtp-Source: ABdhPJyvP5W6Ie4sqxA/nRGNlsEqLrqfipTD3XiTtnE/z+QGnkZeRSYoTmGxCyn8TXAtziifOignpQ== X-Received: by 2002:a05:6000:1a8c:: with SMTP id f12mr243408wry.173.1611181625358; Wed, 20 Jan 2021 14:27:05 -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 i131sm5663710wmi.25.2021.01.20.14.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 14:27:04 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Liam Girdwood , Ulf Hansson , Peter Geis , Nicolas Chauvet , "Rafael J. Wysocki" , Kevin Hilman , Peter De Schrijver , Viresh Kumar , Stephen Boyd , Nishanth Menon , Yangtao Li , Matt Merhar Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 3/4] opp: Add dev_pm_opp_set_voltage() Date: Thu, 21 Jan 2021 01:26:48 +0300 Message-Id: <20210120222649.28149-4-digetx@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210120222649.28149-1-digetx@gmail.com> References: <20210120222649.28149-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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. Tested-by: Peter Geis Tested-by: Nicolas Chauvet Tested-by: Matt Merhar Signed-off-by: Dmitry Osipenko --- drivers/opp/core.c | 51 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 6 +++++ 2 files changed, 57 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 43e62e0e3d5b..08d205a55c07 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2700,3 +2700,54 @@ 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 80cdb9af8268..d8f412dfc03a 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -164,6 +164,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) { @@ -405,6 +406,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) From patchwork Wed Jan 20 22:26:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12033805 X-Patchwork-Delegate: viresh.linux@gmail.com 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.8 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=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 CDE12C433E6 for ; Wed, 20 Jan 2021 22:32:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8ECB323731 for ; Wed, 20 Jan 2021 22:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731532AbhATWbs (ORCPT ); Wed, 20 Jan 2021 17:31:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387592AbhATW1t (ORCPT ); Wed, 20 Jan 2021 17:27:49 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E4DC0613D3; Wed, 20 Jan 2021 14:27:08 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id j18so4110556wmi.3; Wed, 20 Jan 2021 14:27:08 -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=h2RhxkAG+uWAbxkgUJeC5MykXJe6T4j02mxuLjKdXRQ=; b=REnxKbz0huwqlEYZ3Lht12zcAp9m9NJo0l6vOBvaq7V71JJ0R3Yn28L2OIGtecdU20 /sMYeF2+mSC1B0LXmYdIpB5TfrdH/2YA9h57Jsto34DV1Hsu1oohiXNfKbJb0zYm2Gty cVNcjrpqZgNoBrnYpa6OHifIfFYFkGhk3fmidM3qYevQO9COiwMj7/Hr8WtG8RurPzpc NXHZRFbk2LcQ+jFksfDnIlZExIAlG1vUMxxU//YCJdIjMjhhKrG1hU2Vg2dfQbJ/tsj2 Md/x5R059pUUlkQSSRuRmFZh1y9SODC7836qyMOennaBn6SChqhMiQ2+VCOpJTiZ9ehb iZCA== 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=h2RhxkAG+uWAbxkgUJeC5MykXJe6T4j02mxuLjKdXRQ=; b=ZHMLj98K1vsvRoZBoMzjinf3Kbu98BlFCgD/UrzxqTNGqXbI/Wl24z6B+XAtyv2gm4 8lATcJ6jHhzZcLUTk0vATvTHjwpMpHitzJqdw7bPXTxNSnYyNBRjKXtTwHsTZSvD7DH5 Sx9mKK8pWmG55Vz40F2hFnogRxN5RdCs+peBmI/f4jQ8pn9S9Ds+/kLyStcCxonttIeZ oxO2xPIM9y8p1LJt20B8RJu+BP08IT61gCR6lgh0KsuVZzI20TA4w+QmUN8flmKgA3cU kOsII0JH+XALZuxFy3Wr5Jg+V92FluCt72nMQ9ssH+9dpJ0qbHnR55I8PlH7wXXb34zd 805A== X-Gm-Message-State: AOAM532PjtYSVJrpkzYuX09ZXFunShjsWfsYSXVWqrLi18Y01631ngtL WGVKT7keSBg3b3O8ajaXFpxA2BnfGtc= X-Google-Smtp-Source: ABdhPJxNDBPK2Y2x5COb32K+ebOByafJ2EuEbGc9z2peneZUOPgKhmjjgKYmwumg+YemQnVV4Jq4Vw== X-Received: by 2002:a1c:6089:: with SMTP id u131mr6146036wmb.99.1611181626987; Wed, 20 Jan 2021 14:27:06 -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 i131sm5663710wmi.25.2021.01.20.14.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 14:27:06 -0800 (PST) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Liam Girdwood , Ulf Hansson , Peter Geis , Nicolas Chauvet , "Rafael J. Wysocki" , Kevin Hilman , Peter De Schrijver , Viresh Kumar , Stephen Boyd , Nishanth Menon , Yangtao Li , Matt Merhar Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 4/4] opp: Make _set_opp_custom() work without regulators Date: Thu, 21 Jan 2021 01:26:49 +0300 Message-Id: <20210120222649.28149-5-digetx@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210120222649.28149-1-digetx@gmail.com> References: <20210120222649.28149-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Check whether OPP table has regulators in _set_opp_custom() and set up dev_pm_set_opp_data accordingly. Now _set_opp_custom() works properly, i.e. it doesn't crash if OPP table doesn't have assigned regulators. Signed-off-by: Dmitry Osipenko --- drivers/opp/core.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 08d205a55c07..c38ac1cf62ac 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -829,23 +829,31 @@ static int _set_opp_custom(const struct opp_table *opp_table, struct dev_pm_opp_supply *new_supply) { struct dev_pm_set_opp_data *data; - int size; + int size, regulator_count; + + if (opp_table->sod_supplies) + regulator_count = opp_table->regulator_count; + else + regulator_count = 0; data = opp_table->set_opp_data; data->regulators = opp_table->regulators; - data->regulator_count = opp_table->regulator_count; + data->regulator_count = regulator_count; data->clk = opp_table->clk; data->dev = dev; data->old_opp.rate = old_freq; - size = sizeof(*old_supply) * opp_table->regulator_count; - if (!old_supply) - memset(data->old_opp.supplies, 0, size); - else - memcpy(data->old_opp.supplies, old_supply, size); - data->new_opp.rate = freq; - memcpy(data->new_opp.supplies, new_supply, size); + + if (regulator_count) { + size = sizeof(*old_supply) * opp_table->regulator_count; + if (!old_supply) + memset(data->old_opp.supplies, 0, size); + else + memcpy(data->old_opp.supplies, old_supply, size); + + memcpy(data->new_opp.supplies, new_supply, size); + } return opp_table->set_opp(data); }