From patchwork Fri Oct 12 11:11:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148749 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp598779lji; Fri, 12 Oct 2018 04:11:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV6234ZmMqiYuorSHnC5p4artiYMss+Qa/mGLZe55F29hfl5YAJiUvEirmqTRMyidWcTYLZWo X-Received: by 2002:a63:6c84:: with SMTP id h126-v6mr5130452pgc.237.1539342711079; Fri, 12 Oct 2018 04:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342711; cv=none; d=google.com; s=arc-20160816; b=HEbCPYuG69v/rmhx8SJTjAODqcT9hmyJE7TCow+eCB8JPDcNIkOAeKo7TtooiwWTCa Hmt681YiA79Nhm1hlp1cqPGZ+uqWmPR6Q67juuQkJ0TpKyrqoE3PlOUsiEEhUSlRKkos VJfvsjYjcj04KjRN22tmGE60z7QXa8dW8q9h6llcxAg7wLL0Y8I4imAu9RdMXlpDDZ/Z 8SiVQjlSS78sYe3nZLw3QWZJ24AN8JRKtfa/Oz45PaE8NNL9q/IsSe3HKh2j0Z3Ct7aw IXOiN0WhsSdb/+P1H2IwNXo5b6K2I3MOT9e8Lxd33ZqDL6ZZvHVaVabeiNYGyEjdWOjd Gvyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=dZWt165qFows+A3EqmCPCjuilwFrmrgPBXoI72INlkQ=; b=YEqmN4lRHYDHSwbCHT8akkoPWrL9zTp9UJ9Qd2rcjtffFZmTHFN7cV5KW4aOkD8tN1 Iba5UedH/WiVSD/gqnhyFSCeYFXcDe5JBItUuioXHsNqE4XdXCtWBzSy/uLomj24bD/e hHnm6eyySdZgTkTocdpV/YTy2HmNYDASkx3id4mxDgzs4QU5bAVN8MlgRQzemSzfUf/H kGJTaWXGnPsQ3SH5cE1NAK9V9P/A0THqvS5PY79aCKk/6/Aj6BOYXm2wWVFV0eG3xrtr Qdxxs5nxeC3LpAA8s6rMRsDmOgvuuWHhscpWutg+AT4QPq5bYmeHx0lwSSRHvJnIXpWX RTUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jLEMJjEJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2-v6si933143pgc.570.2018.10.12.04.11.50; Fri, 12 Oct 2018 04:11:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jLEMJjEJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728320AbeJLSnn (ORCPT + 32 others); Fri, 12 Oct 2018 14:43:43 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:41514 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728221AbeJLSnn (ORCPT ); Fri, 12 Oct 2018 14:43:43 -0400 Received: by mail-pl1-f193.google.com with SMTP id q17-v6so5787915plr.8 for ; Fri, 12 Oct 2018 04:11:47 -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=dZWt165qFows+A3EqmCPCjuilwFrmrgPBXoI72INlkQ=; b=jLEMJjEJtVoUw+m3NYfSuCyvfKiPricSPiHvbQ6DACLinWU3X2w6qfwBEfL6QcFz26 PALTeRPjNUZP3d5/A7t3rA6WkInsG4knVYYiQYM7EoMDcLgHpsDyaA8XHy8pUKpWSIZJ e7SuN/yly+Bmj+rZ6qsQ6A+uvDo/tzofozhHM= 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=dZWt165qFows+A3EqmCPCjuilwFrmrgPBXoI72INlkQ=; b=KCxndOEqqAp/CEn1kxfoEc0YoHVckKNc23xocwzY3VqtiV+wV8vQgldlHu71wFb+mA BHwZUtWJ7zYVP1/z9bSoimH6Sh0QYrhMxh12LhhUKEBA37T8hWUiq4tWJf2WO5zXSeM9 XWdBgoFBXJS42XA6DF5WcS4LnwrgjIBeBTpSWCOsmNk0mwCR3w+Kad9Z+mS1Js+jdZjX eubf/ny9UrX2/57XL0XMDUXuPItG0kysBvZ2oq80D/1B5ZWnq5SIJ5w+qMC2FrUSa9UT uXgToBrPZrN6SvVPC6JA8gVcSdbti2ji90ixZSkbNg15WONOgg6IFD/wAM8iN3DJNQHJ 8/bA== X-Gm-Message-State: ABuFfojL1KtBX3qP7ixbUNdxTCGC9wpyy+HrdFZUVf2htjBUHq32hRK2 lwJ6HfR//Fvyfj6t/6iRUR9log== X-Received: by 2002:a17:902:b182:: with SMTP id s2-v6mr5466352plr.84.1539342707459; Fri, 12 Oct 2018 04:11:47 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id c8-v6sm1561084pfi.142.2018.10.12.04.11.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:11:46 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 2/9] OPP: Separate out custom OPP handler specific code Date: Fri, 12 Oct 2018 16:41:10 +0530 Message-Id: <8e654324f879a04eb0c93493402520f024d2bc17.1539341929.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create a separate routine to take care of custom set_opp() handler specific stuff. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 67 +++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 27 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c Reviewed-by: Ulf Hansson diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 2c2df4e4fc14..ebb3b648e0fd 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -635,6 +635,34 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table, return ret; } +static int _set_opp_custom(const struct opp_table *opp_table, + struct device *dev, unsigned long old_freq, + unsigned long freq, + struct dev_pm_opp_supply *old_supply, + struct dev_pm_opp_supply *new_supply) +{ + struct dev_pm_set_opp_data *data; + int size; + + data = opp_table->set_opp_data; + data->regulators = opp_table->regulators; + data->regulator_count = opp_table->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 (IS_ERR(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); + + return opp_table->set_opp(data); +} + /** * dev_pm_opp_set_rate() - Configure new OPP based on frequency * @dev: device for which we do this operation @@ -649,7 +677,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) unsigned long freq, old_freq; struct dev_pm_opp *old_opp, *opp; struct clk *clk; - int ret, size; + int ret; if (unlikely(!target_freq)) { dev_err(dev, "%s: Invalid target frequency %lu\n", __func__, @@ -702,8 +730,17 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", __func__, old_freq, freq); - /* Only frequency scaling */ - if (!opp_table->regulators) { + if (opp_table->set_opp) { + ret = _set_opp_custom(opp_table, dev, old_freq, freq, + IS_ERR(old_opp) ? NULL : old_opp->supplies, + opp->supplies); + } else if (opp_table->regulators) { + ret = _generic_set_opp_regulator(opp_table, dev, old_freq, freq, + IS_ERR(old_opp) ? NULL : old_opp->supplies, + opp->supplies); + } else { + /* Only frequency scaling */ + /* * We don't support devices with both regulator and * domain performance-state for now. @@ -714,30 +751,6 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) opp->pstate); else ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq); - } else if (!opp_table->set_opp) { - ret = _generic_set_opp_regulator(opp_table, dev, old_freq, freq, - IS_ERR(old_opp) ? NULL : old_opp->supplies, - opp->supplies); - } else { - struct dev_pm_set_opp_data *data; - - data = opp_table->set_opp_data; - data->regulators = opp_table->regulators; - data->regulator_count = opp_table->regulator_count; - data->clk = clk; - data->dev = dev; - - data->old_opp.rate = old_freq; - size = sizeof(*opp->supplies) * opp_table->regulator_count; - if (IS_ERR(old_opp)) - memset(data->old_opp.supplies, 0, size); - else - memcpy(data->old_opp.supplies, old_opp->supplies, size); - - data->new_opp.rate = freq; - memcpy(data->new_opp.supplies, opp->supplies, size); - - ret = opp_table->set_opp(data); } dev_pm_opp_put(opp);