From patchwork Thu Aug 13 04:28:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11711657 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12800739 for ; Thu, 13 Aug 2020 04:29:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E382520768 for ; Thu, 13 Aug 2020 04:29:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cw5cxSfF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726107AbgHME3M (ORCPT ); Thu, 13 Aug 2020 00:29:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbgHME3L (ORCPT ); Thu, 13 Aug 2020 00:29:11 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36737C061384 for ; Wed, 12 Aug 2020 21:29:11 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id g7so936393plq.1 for ; Wed, 12 Aug 2020 21:29:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ir/TwzXKrJIx51xeXWtP2nIBfHcRYk10KeY/pHei49E=; b=cw5cxSfF05qeFRq/yk4IykzVTQKt+ejdPbbRjGsyg/WGZhkFrKF00uBXuRFmqkBWBm 98GqMuTdvn6Mtq462o7lNv0ssoRrhq5Zaqd+sPVDqifRhHFQMCB7ldDQtH38zcb8oicr c2TPJLMk56kk3nZFMw06Qc7bs3wnqYZw2wGnPNJ8QvhGJX/pLIktodr7y8ETRFwa+rK3 gFgwLS1CCmHfM7ZsfQNhSuuwymXv1An9GAZonvlgOcr/gen2W33MQX/ksR3PoVLxwTT3 5UugXjZLpAx8CUMMcrMtOtNVHhOAxRHoz+oBziu8uolZhrZ8iksDpxLOThUGpPgMo7ql +sww== 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; bh=Ir/TwzXKrJIx51xeXWtP2nIBfHcRYk10KeY/pHei49E=; b=EHKutfRFIfMfiYkNb2vlWrnKLCysQTYDNeLNC0zWxRUsPzZuLMTRA8TutiD8lJcFJ4 vN3uuUGWJ9p4cxPDVJkBzOdsP/5+JAjZ+ZWCLOBBIulm4929HjJHQzNJ6xFtPkpPNKWx sOVxxZKKmUn7sSaeIhpa+0y/AHYPRyt/agdF13bUw2rIAH0EKwwm/yWT0aZfK5Rz+TsO zQUsL4qfoAi/IBwtbs7aZnP3hvjBAKitVkoLf9OJH2MsRAYPrCQ/rmXlFsJ69+UZBimT 5OuBKWWrY+Vsg74Y7B73BKke8gd+bLhFy380372Q/+irwZFMfvep8qu9ByAu8ynbCSCL M4/g== X-Gm-Message-State: AOAM530mPLImjGCzxYvyzF675UXzo4Lj4Dff1q2sfXaBzKyOsUoRqRPC DEEKuuW7sMG2V26h2o3855J59Q== X-Google-Smtp-Source: ABdhPJw7kd7Nj7HnhrH5uzzC1xBDC35wPSobc/wx1hyTVReps59e9du1sKbdnJmSDTiVT+nD1YJs9A== X-Received: by 2002:a17:902:8b8b:: with SMTP id ay11mr2405922plb.241.1597292950502; Wed, 12 Aug 2020 21:29:10 -0700 (PDT) Received: from localhost ([171.79.32.211]) by smtp.gmail.com with ESMTPSA id w7sm4008522pfi.164.2020.08.12.21.29.08 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Aug 2020 21:29:09 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , Rajendra Nayak Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , mka@chromium.org, sibis@codeaurora.org, "v5 . 3+" , Sajida Bhanu , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH V2 1/4] opp: Enable resources again if they were disabled earlier Date: Thu, 13 Aug 2020 09:58:58 +0530 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: <1597043179-17903-1-git-send-email-rnayak@codeaurora.org> References: <1597043179-17903-1-git-send-email-rnayak@codeaurora.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rajendra Nayak dev_pm_opp_set_rate() can now be called with freq = 0 in order to either drop performance or bandwidth votes or to disable regulators on platforms which support them. In such cases, a subsequent call to dev_pm_opp_set_rate() with the same frequency ends up returning early because 'old_freq == freq' Instead make it fall through and put back the dropped performance and bandwidth votes and/or enable back the regulators. Cc: v5.3+ # v5.3+ Fixes: cd7ea582 ("opp: Make dev_pm_opp_set_rate() handle freq = 0 to drop performance votes") Reported-by: Sajida Bhanu Reviewed-by: Sibi Sankar Reported-by: Matthias Kaehlcke Tested-by: Matthias Kaehlcke Signed-off-by: Rajendra Nayak [ Viresh: Don't skip clk_set_rate() and massaged changelog ] Signed-off-by: Viresh Kumar --- Hi Rajendra, I wasn't able to test this stuff, please give it a try. I have simplified your patch and cleaned up a bunch of stuff as well. drivers/opp/core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index bdb028c7793d..9668ea04cc80 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -934,10 +934,13 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) /* Return early if nothing to do */ if (old_freq == freq) { - dev_dbg(dev, "%s: old/new frequencies (%lu Hz) are same, nothing to do\n", - __func__, freq); - ret = 0; - goto put_opp_table; + if (!opp_table->required_opp_tables && !opp_table->regulators && + !opp_table->paths) { + dev_dbg(dev, "%s: old/new frequencies (%lu Hz) are same, nothing to do\n", + __func__, freq); + ret = 0; + goto put_opp_table; + } } /* From patchwork Thu Aug 13 04:29:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11711661 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25D16913 for ; Thu, 13 Aug 2020 04:29:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CE7A20768 for ; Thu, 13 Aug 2020 04:29:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="BPdliqHQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726576AbgHME3W (ORCPT ); Thu, 13 Aug 2020 00:29:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726533AbgHME3V (ORCPT ); Thu, 13 Aug 2020 00:29:21 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64BE1C061757 for ; Wed, 12 Aug 2020 21:29:21 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id y206so2150379pfb.10 for ; Wed, 12 Aug 2020 21:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=FnqSmZl+R1cGEwJxsBmPrjhnE5qy7kpLT7a0PkymWnw=; b=BPdliqHQ2ac8a7pDlzzKWFbfJ7zncwNDnULEgX3wbaKLhjzg2QdF/0gtOmzTTYuAp3 8mTDmClt4jyQJN0kSTsNE7PoI6Re7qQWNqKIQtkHXtaFLeGx+g8KoXteYTQyONnYSWom fQXfY+X5oBNxy7r/JFqmEgje4ndjG0/J12iQVbhdgCJVPM7FX1EE64/dOhY/N6qmg686 YFf6Pu7Mj2gpfvmbQOM635n01REzkt/liLaHUJYO9EdoInCA+6RazqqkyRi95QI5ScF4 ehUCXXEaLTlyJT/7TzPmqiTfEfHuEzM87KvtXDSNKdBVO0b85ikaDYwKNXCBvJhCBp2o /FOw== 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:in-reply-to:references; bh=FnqSmZl+R1cGEwJxsBmPrjhnE5qy7kpLT7a0PkymWnw=; b=l92nVmqEGSOx/SwIZTNhvt12j7r55KYOk3KXJNTQwblPPsFO/LJH3tjeGR1fv2dQF+ ZSXqpp455QZbp6vU1jo1mfUXZvWOctFX2lyqw892KXuQqLRa0sjxD2dTKexMrUjtpjW+ t54LswfcRsR8dPjfrJkJQr6rUkMx5NI8eTEnVRUrS6xJK6vRpidOi995ZIyD/b9lvk/m P5TPkw2qQpDTl2RaSFwFiuVQ+t/xNl8+vL77BDfswNWqf2/VGDe1q5UuPYMyw7Nk0oPx xSl9eD9P8Fb/pZozjhsSJ+1hBkRd0ZIWgiY+WMbt51+4AnZOyDAL8kcXSbkkZC9E0mNf UMgg== X-Gm-Message-State: AOAM532NMuICCuevkTs0sfAiXC0MPam3/VEpUivkyqLHuRvziH6FaCSe VTZSNenFCjPCur+VErPdhz+7OQ== X-Google-Smtp-Source: ABdhPJwUbcNskbln7q39WGxW03eKYAk9xV7qDYQ5I9I07Olq3qBYZsAv3kh0cyi6vifbhkVL8zR9eg== X-Received: by 2002:a62:18c9:: with SMTP id 192mr2490337pfy.23.1597292960896; Wed, 12 Aug 2020 21:29:20 -0700 (PDT) Received: from localhost ([171.79.32.211]) by smtp.gmail.com with ESMTPSA id a17sm3792120pgi.26.2020.08.12.21.29.19 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Aug 2020 21:29:20 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , mka@chromium.org, sibis@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] opp: Reused enabled flag and remove regulator_enabled Date: Thu, 13 Aug 2020 09:59:00 +0530 Message-Id: <359b588928b7e58b009f786b17ddc088c6a7d18b.1597292833.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: <1597043179-17903-1-git-send-email-rnayak@codeaurora.org> In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The common "enabled" flag can be used here instead of "regulator_enabled" now. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 13 +++---------- drivers/opp/opp.h | 2 -- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index e8882e7fd8a5..5f5da257f58a 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -703,12 +703,10 @@ static int _generic_set_opp_regulator(struct opp_table *opp_table, * Enable the regulator after setting its voltages, otherwise it breaks * some boot-enabled regulators. */ - if (unlikely(!opp_table->regulator_enabled)) { + if (unlikely(!opp_table->enabled)) { ret = regulator_enable(reg); if (ret < 0) dev_warn(dev, "Failed to enable regulator: %d", ret); - else - opp_table->regulator_enabled = true; } return 0; @@ -905,10 +903,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) if (ret) goto put_opp_table; - if (opp_table->regulator_enabled) { - regulator_disable(opp_table->regulators[0]); - opp_table->regulator_enabled = false; - } + regulator_disable(opp_table->regulators[0]); ret = _set_required_opps(dev, opp_table, NULL); if (!ret) @@ -1795,11 +1790,9 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table) /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); - if (opp_table->regulator_enabled) { + if (opp_table->enabled) { for (i = opp_table->regulator_count - 1; i >= 0; i--) regulator_disable(opp_table->regulators[i]); - - opp_table->regulator_enabled = false; } for (i = opp_table->regulator_count - 1; i >= 0; i--) diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index bd35802acc6e..0c3de3f6db5c 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -147,7 +147,6 @@ enum opp_table_access { * @clk: Device's clock handle * @regulators: Supply regulators * @regulator_count: Number of power supply regulators. Its value can be -1 - * @regulator_enabled: Set to true if regulators were previously enabled. * (uninitialized), 0 (no opp-microvolt property) or > 0 (has opp-microvolt * property). * @paths: Interconnect path handles @@ -196,7 +195,6 @@ struct opp_table { struct clk *clk; struct regulator **regulators; int regulator_count; - bool regulator_enabled; struct icc_path **paths; unsigned int path_count; bool enabled; From patchwork Thu Aug 13 04:29:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11711663 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4591D16B1 for ; Thu, 13 Aug 2020 04:29:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B30320768 for ; Thu, 13 Aug 2020 04:29:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="H1n9tH4E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726596AbgHME30 (ORCPT ); Thu, 13 Aug 2020 00:29:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726587AbgHME30 (ORCPT ); Thu, 13 Aug 2020 00:29:26 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09A6FC061383 for ; Wed, 12 Aug 2020 21:29:26 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id y6so2078651plt.3 for ; Wed, 12 Aug 2020 21:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=R39mZXnsq0qTraesNliee1MsAVA33s9QnxlmS7GVZbI=; b=H1n9tH4E5LR0hLMncTHZa2OqXcJNGM/3MvpETAWc3xKJJ9siDUlT2ZUQURgpPlKa+J HmNGgAwmwoRAWO6F/0Qlx0qr2uy8Ou0s3fXMQKoOkwTYAHCuC+KQPUQzw6216SHg0e77 RMghBXdyNvyQ9Rnz+XnB5xM1BBL9L9cYbN+AUFMbmwsLkgjbtB3IPnG6JYQyWTh63eOj GDW6niGkwGcCDGMtHG6O98TsJtdMXPvxOFABUPHKrQm8YqX4InK55oS29bDncwbabq43 10SCYCle0cQ9QfVH4RGsUb6sIJKd7PiVwJhdnY2zhfZxfPlFLhaQRp7Wqc/s9LGz1IbS G1zg== 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:in-reply-to:references; bh=R39mZXnsq0qTraesNliee1MsAVA33s9QnxlmS7GVZbI=; b=goFS8HSRddZL/6qqTPzzZ8dJqgeVODtkmX6saB63zNeaI3T/n4HXZc18UqcKs/Mty8 VZ1kr4Y3JsFawjz6/PMK7c0AxhECcH+MELJz0bcXeXNItRCx1RSuXlB/1+knDgnhPkHr Fa/kRrBwib3/Py97KmizHvCGqtSVVnO33Lpz/L6Gc3aG+RUYNY7s5cbhFOgHK1Oi79gx 0zkT3fyFO21ww2bxqB6Y/sQi0gcBK2m1TwjK2FcAmyLhgpfhOvUoaooWK2nFu+jCc7BC Zssga2p7dipga2Sl6aJbHf04PhQpbqUNauvymMUWnBM5bswJxL9eWDf9LY6iyiaPkgu/ jqtw== X-Gm-Message-State: AOAM531cxabgQOYR6DPKPplnLsdLDjmipX21FhLbcTBvT7W7qudGv8dl DClnntLSffMLyljt1rkqecXYDw== X-Google-Smtp-Source: ABdhPJyiHs3lx6zA/+e4gEiWWHS7Z1ltMlLkHBMkgHHERccGq0Yjc56OGchqNhaTJkR9ZYmw4IVAUQ== X-Received: by 2002:a17:902:b788:: with SMTP id e8mr2354217pls.117.1597292965549; Wed, 12 Aug 2020 21:29:25 -0700 (PDT) Received: from localhost ([171.79.32.211]) by smtp.gmail.com with ESMTPSA id e26sm4100031pfj.197.2020.08.12.21.29.24 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Aug 2020 21:29:25 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , mka@chromium.org, sibis@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] opp: Split out _opp_set_rate_zero() Date: Thu, 13 Aug 2020 09:59:01 +0530 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: <1597043179-17903-1-git-send-email-rnayak@codeaurora.org> In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Create separate routine _opp_set_rate_zero() to handle !target_freq case. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 5f5da257f58a..e198b57efcf8 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -860,6 +860,34 @@ int dev_pm_opp_set_bw(struct device *dev, struct dev_pm_opp *opp) } EXPORT_SYMBOL_GPL(dev_pm_opp_set_bw); +static int _opp_set_rate_zero(struct device *dev, struct opp_table *opp_table) +{ + int ret; + + if (!opp_table->enabled) + return 0; + + /* + * Some drivers need to support cases where some platforms may + * have OPP table for the device, while others don't and + * opp_set_rate() just needs to behave like clk_set_rate(). + */ + if (!_get_opp_count(opp_table)) + return 0; + + ret = _set_opp_bw(opp_table, NULL, dev, true); + if (ret) + return ret; + + regulator_disable(opp_table->regulators[0]); + + ret = _set_required_opps(dev, opp_table, NULL); + if (!ret) + opp_table->enabled = false; + + return ret; +} + /** * dev_pm_opp_set_rate() - Configure new OPP based on frequency * @dev: device for which we do this operation @@ -886,29 +914,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) } if (unlikely(!target_freq)) { - ret = 0; - - if (!opp_table->enabled) - goto put_opp_table; - - /* - * Some drivers need to support cases where some platforms may - * have OPP table for the device, while others don't and - * opp_set_rate() just needs to behave like clk_set_rate(). - */ - if (!_get_opp_count(opp_table)) - goto put_opp_table; - - ret = _set_opp_bw(opp_table, NULL, dev, true); - if (ret) - goto put_opp_table; - - regulator_disable(opp_table->regulators[0]); - - ret = _set_required_opps(dev, opp_table, NULL); - if (!ret) - opp_table->enabled = false; - + ret = _opp_set_rate_zero(dev, opp_table); goto put_opp_table; }