From patchwork Wed May 17 04:40:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 99900 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp63374qge; Tue, 16 May 2017 21:41:13 -0700 (PDT) X-Received: by 10.84.142.101 with SMTP id 92mr1946832plw.112.1494996073314; Tue, 16 May 2017 21:41:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494996073; cv=none; d=google.com; s=arc-20160816; b=AgF0jAN3JXcw1fBkudFri5ly9KJ/Ku4xHIe36cojm8FhG7sd4vrNafc2x0LBvOuJet SzoY8pBaBYwCV+TmOHT3c11zgpcTqgI4hkJaOY55zlBOX/kFPTcaxzolX9rSIIhrM+3l j59rMDIaPDtz2tv2l49NcYxvMgm83pWxan35wm8zmfdKmqbNOdjBd47o5hDM1V/rDj6h z7KHMvGbO2fGjUDwBDYmZvNMUSoyXl4KH+PVfKZTJih+s3ueyY1RrFSXz7O3RI6yw4Ti BpUxwImbUKpyyc+TlYOP4gj8mMyr0IJMQLtmjTc7bgdg4CMIOfBSDVzFHuuRknW7mYaA fxOA== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=I2swIN9NmV5cLUfcqIVX4E9JYQys81WZZ4fPQgMievg=; b=kW4oX02CBvk7q5gyvCTTrm8qOqSPLPW4l9xcpR7/bhF1DIJfIoi/JkKbaTQIVpWDlN JZjqS+GiY6N486dqoItAe4pRNtszaALOj9g07MDwcypMk2fSwjx112lQRFckh0Il2eE8 omVt18fERYRY7hYBGe+sgGJm1o1yOIuO9I61RyK/StCAcvLFeE10g0LgtHRWdxnpZBT6 SGFbIepm7jLMLSLe+wQalTUvBclHmyO8DSYTy1ck1Bp7qIyYaKFlfm2QL58p/kFoBwHt lhUiRsYR/YvPscPd9W57oXV+7QoQByNxhrDI/77WgvI5iutm6qrT9696yukkfhRSW3fP InoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; 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 h79si976926pfh.1.2017.05.16.21.41.13; Tue, 16 May 2017 21:41:13 -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; 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 S1752721AbdEQElB (ORCPT + 25 others); Wed, 17 May 2017 00:41:01 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:34349 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751464AbdEQEk4 (ORCPT ); Wed, 17 May 2017 00:40:56 -0400 Received: by mail-pg0-f44.google.com with SMTP id u28so1005292pgn.1 for ; Tue, 16 May 2017 21:40:55 -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=I2swIN9NmV5cLUfcqIVX4E9JYQys81WZZ4fPQgMievg=; b=JUWDlUCfFA3hI3e6IP+FrsC7HfOHPCjPfU22vb6DHJIA2vt1BCFuCijyB3iGmrnsxu dSTKD5ws2eT8WYkvXIlV/As5Nan0WN5nWxDJ/c2+H3g46krV3RNrlOnL9uniB++lboPC 3Lp1aRtZtHjrHMtxbZNPYjGeFuzvtbRi/G9JY= 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=I2swIN9NmV5cLUfcqIVX4E9JYQys81WZZ4fPQgMievg=; b=sU96Qw9P3aXdsgi4i6hzSHFYKkDikp3ovWb1dds2KRkoTklMuQFNyfqI2hDB59cCrp Je99rvR7IHsEVGurjNiE3iwBBnGvhBntVf63L1Jj2bC25lPXiQvVBwsR+zHJtykVkiVs D7l8qVvNbsNhZLReq90jeeeSvha53j250gRphnX+8l1mUhduv9/oP39P9QAHuJe3vXhG 2yStT5oBWFa40004DmKwk16qPtIP2O7EdHi2VRdeLYH1XPZ/k8lBGDpXs0kfm3ZZbdIX xXtd5qrso3GdUP9+HmqB68ACEjA0KOGskcF7hphFNYXubGad6AQBVTgkoBULB9d8IL7d LQTg== X-Gm-Message-State: AODbwcCm+UGZ/PybnTHnmKKOPV3k5zhuvXa6EFY8pHcbqduDy6N9a6Vd SopEmUnfIffFIPK8 X-Received: by 10.99.8.5 with SMTP id 5mr1669289pgi.220.1494996055372; Tue, 16 May 2017 21:40:55 -0700 (PDT) Received: from localhost ([122.172.129.253]) by smtp.gmail.com with ESMTPSA id e16sm1029883pfk.100.2017.05.16.21.40.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 May 2017 21:40:54 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Viresh Kumar Subject: [PATCH 1/4] PM / OPP: Reorganize _generic_set_opp_regulator() Date: Wed, 17 May 2017 10:10:32 +0530 Message-Id: <7b9df40efa69d646840c097c04c56c7f42f458c4.1494995911.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.13.0.303.g4ebf3021692d In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code was overly complicated here because of the limitations that we had with RCUs (Couldn't use opp-table and OPPs outside RCU protected section and can't call sleep-able routines from within that). But that is long gone now. Reorganize _generic_set_opp_regulator() in order to avoid using "struct dev_pm_set_opp_data" and copying data into it for the case where opp_table->set_opp is not set. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 73 ++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 39 deletions(-) -- 2.13.0.303.g4ebf3021692d diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index dae61720b314..402b9e86d77c 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -543,17 +543,18 @@ _generic_set_opp_clk_only(struct device *dev, struct clk *clk, return ret; } -static int _generic_set_opp(struct dev_pm_set_opp_data *data) +static int _generic_set_opp_regulator(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_opp_supply *old_supply = data->old_opp.supplies; - struct dev_pm_opp_supply *new_supply = data->new_opp.supplies; - unsigned long old_freq = data->old_opp.rate, freq = data->new_opp.rate; - struct regulator *reg = data->regulators[0]; - struct device *dev= data->dev; + struct regulator *reg = opp_table->regulators[0]; int ret; /* This function only supports single regulator per device */ - if (WARN_ON(data->regulator_count > 1)) { + if (WARN_ON(opp_table->regulator_count > 1)) { dev_err(dev, "multiple regulators are not supported\n"); return -EINVAL; } @@ -566,7 +567,7 @@ static int _generic_set_opp(struct dev_pm_set_opp_data *data) } /* Change frequency */ - ret = _generic_set_opp_clk_only(dev, data->clk, old_freq, freq); + ret = _generic_set_opp_clk_only(dev, opp_table->clk, old_freq, freq); if (ret) goto restore_voltage; @@ -580,12 +581,12 @@ static int _generic_set_opp(struct dev_pm_set_opp_data *data) return 0; restore_freq: - if (_generic_set_opp_clk_only(dev, data->clk, freq, old_freq)) + if (_generic_set_opp_clk_only(dev, opp_table->clk, freq, old_freq)) dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", __func__, old_freq); restore_voltage: /* This shouldn't harm even if the voltages weren't updated earlier */ - if (old_supply->u_volt) + if (old_supply) _set_opp_voltage(dev, reg, old_supply); return ret; @@ -603,10 +604,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) { struct opp_table *opp_table; unsigned long freq, old_freq; - int (*set_opp)(struct dev_pm_set_opp_data *data); struct dev_pm_opp *old_opp, *opp; - struct regulator **regulators; - struct dev_pm_set_opp_data *data; struct clk *clk; int ret, size; @@ -661,38 +659,35 @@ 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); - regulators = opp_table->regulators; - /* Only frequency scaling */ - if (!regulators) { + if (!opp_table->regulators) { ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq); - goto put_opps; - } + } 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; - if (opp_table->set_opp) - set_opp = opp_table->set_opp; - else - set_opp = _generic_set_opp; - - data = opp_table->set_opp_data; - data->regulators = 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 = opp_table->set_opp_data; + data->regulators = opp_table->regulators; + data->regulator_count = opp_table->regulator_count; + data->clk = clk; + data->dev = dev; - data->new_opp.rate = freq; - memcpy(data->new_opp.supplies, opp->supplies, size); + 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); - ret = set_opp(data); + data->new_opp.rate = freq; + memcpy(data->new_opp.supplies, opp->supplies, size); + + ret = opp_table->set_opp(data); + } -put_opps: dev_pm_opp_put(opp); put_old_opp: if (!IS_ERR(old_opp))