From patchwork Mon Jul 4 12:07:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 12905202 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 580ABC43334 for ; Mon, 4 Jul 2022 12:10:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233736AbiGDMKW (ORCPT ); Mon, 4 Jul 2022 08:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234020AbiGDMJl (ORCPT ); Mon, 4 Jul 2022 08:09:41 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F09BA12752 for ; Mon, 4 Jul 2022 05:09:00 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id g20-20020a17090a579400b001ed52939d72so9390296pji.4 for ; Mon, 04 Jul 2022 05:09:00 -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=6OTH+s35Nt1rHwpbqRf4JhwqpF3oRIrQNAJMgMK39Yw=; b=zK04P3GaT+VUUatklviMx3RQPZ5FH4TAUHEC4agKXqi44pxINk1fo5Jz3fI4kka5wP FVZ8LEHy2jmA8cI3F8F+DDM+bIzgfMq2cumMWrieLIQP1VzdBp3WLiPbweQhTDpnYnOY fJuNzYwYkE0zxtQLYbh/hHHdJ94RNnYbi0S5lSwzhpli60Rwg7LuEXW2SbLGnCgw+mD1 XhqR8v9gAm2hbx1QMSYujHzvpcfyQTQs5XGj1UVAJoacNonaIj4k3mgdqzFGreidzuNO CLqkkyVdzko/02shRWuLvLcgY2BsDIrb0DCxmf1UurwWgUlmAvH6SvQslFxVioLCi4ux e4QQ== 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=6OTH+s35Nt1rHwpbqRf4JhwqpF3oRIrQNAJMgMK39Yw=; b=vs6BaIRBlBvyzLDqzh8ZNBsIl98XNjcccvg5EcT2LhZdL0oAXnsILAdzxHQEEv21xC tE17Cfj+IcXVtYiSt5FS1/FGO6lc8/b11jMwi/8r1Fzyekhu1Nkbf7hidK2La2eyOafD TcVMYamXTPMsNkNYvwuL8fgxclzL0Ar+CWzpUAcrVp3WrSFALJamdD0fO2JmFuHrSJQ/ zAW6FqgQBUaWcB6Zy8xQcoVswnl/DnEYKp5e2niO3BEG/Fdeu/XC2ipEcg8/Bn13tjLw 8Sot0vOhcE9Hok6oNALWLXHpgIFPk7TKK4cg2JFreuTyi7pmpTELjJvBMM4k2DjnAVUf AxDw== X-Gm-Message-State: AJIora+sU1ZYfnnan0c3xpzpG32B21lL0JuLnTI4WDHHFRmsOuYSNwH2 uIZuiN/nVwGHzypsMvnE5k7glA== X-Google-Smtp-Source: AGRyM1uQhX7ZSS88GaMyGgQj5OKjal1s7Chv2oZ0wsNkkPyfPZUdJGO+kmKzgoWtdsXc2I/AeAYgXQ== X-Received: by 2002:a17:90a:fa01:b0:1ef:6e6a:4ff0 with SMTP id cm1-20020a17090afa0100b001ef6e6a4ff0mr15376041pjb.35.1656936539792; Mon, 04 Jul 2022 05:08:59 -0700 (PDT) Received: from localhost ([122.171.18.80]) by smtp.gmail.com with ESMTPSA id z2-20020a17090a66c200b001ece55b938asm10020809pjl.32.2022.07.04.05.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 05:08:59 -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 V3 17/20] OPP: Make _generic_set_opp_regulator() a config_regulators() interface Date: Mon, 4 Jul 2022 17:37:55 +0530 Message-Id: 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 12bae79564f1..5ecf077b6b17 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); @@ -2121,6 +2090,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: