From patchwork Fri Jul 1 08:34:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 586451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84006C43334 for ; Fri, 1 Jul 2022 08:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235693AbiGAIfT (ORCPT ); Fri, 1 Jul 2022 04:35:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235227AbiGAIfK (ORCPT ); Fri, 1 Jul 2022 04:35:10 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A190270E7C for ; Fri, 1 Jul 2022 01:35:07 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id jh14so1759394plb.1 for ; Fri, 01 Jul 2022 01:35:07 -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 :mime-version:content-transfer-encoding; bh=lRM1PjazghlAlPXD7tv2+SDz7O4GVNObgvkudXkk8IM=; b=dQcvYUX3d0Hc0/3/lPi3x4cea9DpxT15pkG7XJcV/dRQwLiCxhr2Xy2LgqoLzItyej zzKQPqreKgGzKukt5sLNtRRhy3aFjlf5ekppgoSU04aLj0/JlX5XcRByJ9d9nRmIFCo4 rc7FLitPNQPGO/3DrtFeyB5VoGynlR/kV8HnUbUPoMq1zupRxXfbRlk5wx9AJohtE7vV sakRnduEheX83YXsAudn/QPLOuPTh08lUjMVGflTR6LRRb0endklvEI7oyZYIDtuLcgH I3ziaBt2snD7ovzFYLq8MJBSiKQszyoRkM2D+fxEWbHk6CScZ/29a+wBeEcTvaFqv3fB FgLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lRM1PjazghlAlPXD7tv2+SDz7O4GVNObgvkudXkk8IM=; b=A189ba+GTCSxZaRQ9fxbMCzoiraHXmsB3yIQ1Dx0qd/NFNMQ5UheB6Ys1NmAWlGmo6 7qcXu6wvaQzFh0XdeSj7xBAjOQgfUndjTQ7IHaCAD9/b6M8rgOzve74fpyywMw20aOVf YX98XMp139S2u4UEqW9gBAN5cad4tpAqeun8oPBfFM8xb44n7FDWBBBx3DLzK6wfsgQX V7PbrYVHaGRUrRZXsu7iFXpcy9wHNuar6pOdx7+568yYxaHRDHW/OWNHjyeKQQl0U4Am igOx/73SyQEll4F6+zDxK19qvzrKxHS8dU6q75KiiSCOCfAr1WrPl0rvBzANQRjQgSwN ORpg== X-Gm-Message-State: AJIora+v0iW5DNI7YoJpydX7kEI/uYemo6LjB6KPV26kCcBwSC6WleQp wo+5jaJli60OgEYDAYTtpHy5TQ== X-Google-Smtp-Source: AGRyM1vWS4XhZQ2vX+0HfYDGexiYN0ySk/slaYykTQoF5+866XV74mzfPyfUvGl17A9dviN85hDFtg== X-Received: by 2002:a17:90b:895:b0:1ec:827c:ef0f with SMTP id bj21-20020a17090b089500b001ec827cef0fmr16875092pjb.10.1656664507206; Fri, 01 Jul 2022 01:35:07 -0700 (PDT) Received: from localhost ([122.172.201.58]) by smtp.gmail.com with ESMTPSA id d63-20020a621d42000000b0052532d9cb18sm14864102pfd.183.2022.07.01.01.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jul 2022 01:35:06 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V2 2/5] OPP: Make _generic_set_opp_regulator() a config_regulators() interface Date: Fri, 1 Jul 2022 14:04:52 +0530 Message-Id: <2d9786a0e2460d3c4ac94a147a8b7ff77d36f696.1656664183.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In order to reuse the same code path, i.e. clk_set_rate() from _set_opp(), migrate _generic_set_opp_regulator() to implement a config_regulators() interface. It is renamed to _opp_config_regulator_single() and is set as the preferred config_regulators() interface whenever we have a single regulator available. Note that this also drops code responsible for restoring the voltage/freq in case of errors. We aren't handling that properly currently, restoring only some of the resources while leaving others out (like bandwidth and required OPPs). It is better to drop all of it instead of partial restoration. Tested-by: Dmitry Osipenko Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 51 +++++++++++----------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index d5e1ae6f5ea1..df0135f2cfec 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -896,62 +896,34 @@ static inline int _generic_set_opp_clk_only(struct device *dev, struct clk *clk, return ret; } -static int _generic_set_opp_regulator(struct opp_table *opp_table, - struct device *dev, - struct dev_pm_opp *opp, - unsigned long freq, - int scaling_down) +static int _opp_config_regulator_single(struct device *dev, + struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp, + struct regulator **regulators, unsigned int count) { - struct regulator *reg = opp_table->regulators[0]; - struct dev_pm_opp *old_opp = opp_table->current_opp; + struct regulator *reg = regulators[0]; int ret; /* This function only supports single regulator per device */ - if (WARN_ON(opp_table->regulator_count > 1)) { + if (WARN_ON(count > 1)) { dev_err(dev, "multiple regulators are not supported\n"); return -EINVAL; } - /* Scaling up? Scale voltage before frequency */ - if (!scaling_down) { - ret = _set_opp_voltage(dev, reg, opp->supplies); - if (ret) - goto restore_voltage; - } - - /* Change frequency */ - ret = _generic_set_opp_clk_only(dev, opp_table->clk, freq); + ret = _set_opp_voltage(dev, reg, new_opp->supplies); if (ret) - goto restore_voltage; - - /* Scaling down? Scale voltage after frequency */ - if (scaling_down) { - ret = _set_opp_voltage(dev, reg, opp->supplies); - if (ret) - goto restore_freq; - } + return ret; /* * Enable the regulator after setting its voltages, otherwise it breaks * some boot-enabled regulators. */ - if (unlikely(!opp_table->enabled)) { + if (unlikely(!new_opp->opp_table->enabled)) { ret = regulator_enable(reg); if (ret < 0) dev_warn(dev, "Failed to enable regulator: %d", ret); } return 0; - -restore_freq: - if (_generic_set_opp_clk_only(dev, opp_table->clk, old_opp->rate)) - dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", - __func__, old_opp->rate); -restore_voltage: - /* This shouldn't harm even if the voltages weren't updated earlier */ - _set_opp_voltage(dev, reg, old_opp->supplies); - - return ret; } static int _set_opp_bw(const struct opp_table *opp_table, @@ -1200,9 +1172,6 @@ static int _set_opp(struct device *dev, struct opp_table *opp_table, if (opp_table->set_opp) { ret = _set_opp_custom(opp_table, dev, opp, freq); - } else if (opp_table->regulators) { - ret = _generic_set_opp_regulator(opp_table, dev, opp, freq, - scaling_down); } else { /* Only frequency scaling */ ret = _generic_set_opp_clk_only(dev, opp_table->clk, freq); @@ -2113,6 +2082,10 @@ static int _opp_set_regulators(struct opp_table *opp_table, struct device *dev, } mutex_unlock(&opp_table->lock); + /* Set generic config_regulators() for single regulators here */ + if (count == 1) + opp_table->config_regulators = _opp_config_regulator_single; + return 0; free_regulators: From patchwork Fri Jul 1 08:34:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 586450 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9422C43334 for ; Fri, 1 Jul 2022 08:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229609AbiGAIfW (ORCPT ); Fri, 1 Jul 2022 04:35:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236533AbiGAIfS (ORCPT ); Fri, 1 Jul 2022 04:35:18 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35EF07125D for ; Fri, 1 Jul 2022 01:35:13 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id c4so1727964plc.8 for ; Fri, 01 Jul 2022 01:35:13 -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 :mime-version:content-transfer-encoding; bh=/J/oGF74cDu8WRXcmEUoVqkWg7/dM3ieJV6SNHK5u2g=; b=wJ4YMZ6WLBdrditEkE5xr2++AgUlYr19Lh44vM2dqHRINpwTsz9a5gI65oTVGYkGb1 8LvT2VXuTws67upE08yWCsQhkV6JOw2/2ssORzbt2Ct5kDeyZpG5U6uiJigpF/bOWCr/ ZT9/u25NSfTCYll2z6hDsspxphpNLvoxBoUpZOhtfY9ZyspvXxfs3JZ2XEmxuHIRhdKp NjF4K1FG+mHrkTcRSZliV1Nwa6P8jSwp9ct9GP0rkV7b81VGaCGEcUOn0T231qrwPU45 JT84zDwuiSytd8Y8T5Omnj07CFYYTQ4EMqryDTgWIeAGtjI2RwdMiOIqNc3rJUz5A+cd e7Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/J/oGF74cDu8WRXcmEUoVqkWg7/dM3ieJV6SNHK5u2g=; b=pCdJ8tDtsl76CIofbO1yjyrhU1dA6V5ZLMhG05lK80FomREpppCL4Sgd1N1lp6Duug bbL6H427GVwhn7FBgRF9WFUmZYs8Cz3DTcEAaOor8AY4L6WcwbpPn0169HtpX50aPbCn dTU5mXeAzTkeeguiRG8Av82GxN4+BchgkzR4i+lRd0q/Nckr+U52rp4wz8+pPD3/se3L LlvBkvBgNyE918iaM1WiP/xqF41GP/WEzQ3RxTZylDIQfutj6qa19+IC2mpaCRFtNEOV zDsOvujhex/ponUpd6XNKgf1155SNfjuoE4Pk9EMtoGdYBJcNaKf+78oRpzd0s1slbvN 6TqA== X-Gm-Message-State: AJIora9n2q2RgyLIDstV+/uI93uTEwNezWn86uRtICqeg30fkCfCvdac 02jAAj3MK28NOX3FZxBjbcdAVA== X-Google-Smtp-Source: AGRyM1txuauuk+cj9pXaDTeqhWJALiBbIWHadKxSv+B6yXyhdhDAYGmVhHoteZsZIJRf8Xo3VM5MHQ== X-Received: by 2002:a17:902:6b8b:b0:14d:66c4:f704 with SMTP id p11-20020a1709026b8b00b0014d66c4f704mr20022449plk.53.1656664512730; Fri, 01 Jul 2022 01:35:12 -0700 (PDT) Received: from localhost ([122.172.201.58]) by smtp.gmail.com with ESMTPSA id t2-20020a1709027fc200b0016a581f9ac2sm14768963plb.234.2022.07.01.01.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jul 2022 01:35:12 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: [PATCH V2 4/5] OPP: ti: Migrate to config_regulators() Date: Fri, 1 Jul 2022 14:04:54 +0530 Message-Id: <5ca08d546dd7e03e290256b4530ab4e6266da72e.1656664183.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The OPP core now provides config_regulators() interface, which needs the platforms to just set the OPP voltages instead of both clk and voltage. The clock is set by the OPP core instead and hence reduces code redundancy. Migrate the only user of the custom set_opp() interface to config_regulators(). Signed-off-by: Viresh Kumar --- drivers/opp/ti-opp-supply.c | 74 +++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/drivers/opp/ti-opp-supply.c b/drivers/opp/ti-opp-supply.c index 26e929377ebd..f1f881140fa2 100644 --- a/drivers/opp/ti-opp-supply.c +++ b/drivers/opp/ti-opp-supply.c @@ -36,11 +36,15 @@ struct ti_opp_supply_optimum_voltage_table { * @vdd_table: Optimized voltage mapping table * @num_vdd_table: number of entries in vdd_table * @vdd_absolute_max_voltage_uv: absolute maximum voltage in UV for the supply + * @old_supplies: Placeholder for supplies information for old OPP. + * @new_supplies: Placeholder for supplies information for new OPP. */ struct ti_opp_supply_data { struct ti_opp_supply_optimum_voltage_table *vdd_table; u32 num_vdd_table; u32 vdd_absolute_max_voltage_uv; + struct dev_pm_opp_supply old_supplies[2]; + struct dev_pm_opp_supply new_supplies[2]; }; static struct ti_opp_supply_data opp_data; @@ -266,27 +270,32 @@ static int _opp_set_voltage(struct device *dev, return 0; } -/** - * ti_opp_supply_set_opp() - do the opp supply transition - * @data: information on regulators and new and old opps provided by - * opp core to use in transition - * - * Return: If successful, 0, else appropriate error value. - */ -static int ti_opp_supply_set_opp(struct dev_pm_set_opp_data *data) +/* Do the opp supply transition */ +static int ti_opp_config_regulators(struct device *dev, + struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp, + struct regulator **regulators, unsigned int count) { - struct dev_pm_opp_supply *old_supply_vdd = &data->old_opp.supplies[0]; - struct dev_pm_opp_supply *old_supply_vbb = &data->old_opp.supplies[1]; - struct dev_pm_opp_supply *new_supply_vdd = &data->new_opp.supplies[0]; - struct dev_pm_opp_supply *new_supply_vbb = &data->new_opp.supplies[1]; - struct device *dev = data->dev; - unsigned long old_freq = data->old_opp.rate, freq = data->new_opp.rate; - struct clk *clk = data->clk; - struct regulator *vdd_reg = data->regulators[0]; - struct regulator *vbb_reg = data->regulators[1]; + struct dev_pm_opp_supply *old_supply_vdd = &opp_data.old_supplies[0]; + struct dev_pm_opp_supply *old_supply_vbb = &opp_data.old_supplies[1]; + struct dev_pm_opp_supply *new_supply_vdd = &opp_data.new_supplies[0]; + struct dev_pm_opp_supply *new_supply_vbb = &opp_data.new_supplies[1]; + struct regulator *vdd_reg = regulators[0]; + struct regulator *vbb_reg = regulators[1]; + unsigned long old_freq, freq; int vdd_uv; int ret; + /* We must have two regulators here */ + WARN_ON(count != 2); + + /* Fetch supplies and freq information from OPP core */ + ret = dev_pm_opp_get_supplies(new_opp, opp_data.new_supplies); + WARN_ON(ret); + + old_freq = dev_pm_opp_get_freq(old_opp); + freq = dev_pm_opp_get_freq(new_opp); + WARN_ON(!old_freq || !freq); + vdd_uv = _get_optimal_vdd_voltage(dev, &opp_data, new_supply_vdd->u_volt); @@ -303,39 +312,24 @@ static int ti_opp_supply_set_opp(struct dev_pm_set_opp_data *data) ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb"); if (ret) goto restore_voltage; - } - - /* Change frequency */ - dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", - __func__, old_freq, freq); - - ret = clk_set_rate(clk, freq); - if (ret) { - dev_err(dev, "%s: failed to set clock rate: %d\n", __func__, - ret); - goto restore_voltage; - } - - /* Scaling down? Scale voltage after frequency */ - if (freq < old_freq) { + } else { ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb"); if (ret) - goto restore_freq; + goto restore_voltage; ret = _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg, "vdd"); if (ret) - goto restore_freq; + goto restore_voltage; } return 0; -restore_freq: - ret = clk_set_rate(clk, old_freq); - if (ret) - dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", - __func__, old_freq); restore_voltage: + /* Fetch old supplies information only if required */ + ret = dev_pm_opp_get_supplies(old_opp, opp_data.old_supplies); + WARN_ON(ret); + /* This shouldn't harm even if the voltages weren't updated earlier */ if (old_supply_vdd->u_volt) { ret = _opp_set_voltage(dev, old_supply_vbb, 0, vbb_reg, "vbb"); @@ -383,7 +377,7 @@ static int ti_opp_supply_probe(struct platform_device *pdev) const struct ti_opp_supply_of_data *of_data; int ret = 0; struct dev_pm_opp_config config = { - .set_opp = ti_opp_supply_set_opp, + .config_regulators = ti_opp_config_regulators, }; match = of_match_device(ti_opp_supply_of_match, dev);