From patchwork Tue Sep 19 22:32:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 113065 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp33886qgf; Tue, 19 Sep 2017 15:32:50 -0700 (PDT) X-Received: by 10.159.204.147 with SMTP id t19mr108565plo.7.1505860370143; Tue, 19 Sep 2017 15:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505860370; cv=none; d=google.com; s=arc-20160816; b=gJEZmEYOuBPTNKpIB9yKqJaxjBFfx0uyo2AlLhLgdGLXkLxv/yMnHMPlMxFpLmzIWR 9LJvaceVkeAF2RAtEeEfKcc+Sdkl2u9tPW9l6ws59FLqG9ArFZWnfAKEwVkqCEUl5rt3 QzgbVQOu3f1PmUXWCWlOcEZ6PKbBriHNWsctwJ6+ZU362nyM7f8kRnpG23XZUTarFvFV 5/bAbUE1fk9M9TEqdY5XsdtWX4qbV9Fn4s6+eemNBpYVdN8ddAxy40IDnhRhjlIa9+oH +wFdWwe7Q7OxLyUdmmNXsDTuCRPWx3iXmJYXZHTXL3KhpwP8WzdDxnTK0ShtF82e+6cD ULxQ== 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=i57D9fWP9Kp+I1ZmXQ0JvWo8eiljeI6SSp4Mn792sMA=; b=y23iC84/o6OQxiQewP/WgnerVOBxBDW/GrKNIQuVUk4Ld4zvPZztNbNwaLDyrsO0PL ZPlzOiWpeIr2zOL/jXuX6YWkcYtYBw37R3m07Duxwfo9YrgFOE/lM7EpeSVh3CuYxcIy tOjRlCqtmGJVNhHE95dmuugbz4raBmVBJSYljHcRtddgRuW8KO1vXZmXAOSFiX4VqxHe dpLLSdgkaV/ijnnQat9vowkBdbi9184bVfeDLFQFSuc/Sfhf79Kg1VtIU0KBjeqs/i5I S9z4s4F8cSxN8DIwNNl3RyTMG+LXXL6iEE3vC7RWXaIB8zGdldzTKLMz2PZrU3WmkZcG LkpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RKO7vygl; 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 k7si1967400pgp.676.2017.09.19.15.32.49; Tue, 19 Sep 2017 15:32:50 -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=RKO7vygl; 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 S1751763AbdISWcp (ORCPT + 26 others); Tue, 19 Sep 2017 18:32:45 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:48651 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751663AbdISWcl (ORCPT ); Tue, 19 Sep 2017 18:32:41 -0400 Received: by mail-pf0-f174.google.com with SMTP id n24so540903pfk.5 for ; Tue, 19 Sep 2017 15:32:40 -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=i57D9fWP9Kp+I1ZmXQ0JvWo8eiljeI6SSp4Mn792sMA=; b=RKO7vyglqRQmwn9lXpPfGf4xqZ29i3DxkeHGCS7Sfl+5GYPFqPN81Ktwyfu49UKDNF vEhAqK4Uo3CT96dpEBAonLXZoufILfhR2+h5XJioky5rny8BSS/tu1TEkfurfA8ZcA/p fnIPf/Wb9n7oqCHd7D3JiTmll4g8EOoYbKujM= 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=i57D9fWP9Kp+I1ZmXQ0JvWo8eiljeI6SSp4Mn792sMA=; b=lC/b17w+jjMdNOgbJQLc3YrKeWkall7d3y501K3pDZwFcHVVcFtPV3BxipplpW8sDe 7K5bHSDv672oYmyvuZVmJxcVCyDpqd+MvLNtuCIHoaK3AnB5j6QOYohJomGZ1kR1g2B/ fcCCaSrrFIAZQhnoMr8VhdoTCEGoNtj49m9W/3w6GgJPlf6/yu3y2XCn7f3dSKiBWfWG RMUBqnaZxgcvaY65o+WFkv63MejZJK4j8NVqyTiV9ffgiYwwaRnr+7zy4udq+7zz2o+S hryE+siywlekoOsNjGaokhBWEUoRScV4kzrOXlTVlFE7ylA3zlrVV0wR0VVfQSo+emAx znxA== X-Gm-Message-State: AHPjjUhxfQZOAYs3DNcSywCOLx5I0UlP68YUZxvIBu7bqfKehk6CzP0g SacnvbLIhEAHQZOJe+U+3ktS4w== X-Google-Smtp-Source: AOwi7QArOJrzoJytfbyu7RItwqEDBDRZ82tu4A3+JKY8znIwckb2ybDdRNscxZu3rOcZijxAoHv54w== X-Received: by 10.99.39.129 with SMTP id n123mr132934pgn.240.1505860360113; Tue, 19 Sep 2017 15:32:40 -0700 (PDT) Received: from localhost (cpe-172-88-64-62.socal.res.rr.com. [172.88.64.62]) by smtp.gmail.com with ESMTPSA id e27sm5538722pfk.41.2017.09.19.15.32.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Sep 2017 15:32:39 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ulf.hansson@linaro.org, Kevin Hilman Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , robh+dt@kernel.org, lina.iyer@linaro.org, rnayak@codeaurora.org, sudeep.holla@arm.com, linux-kernel@vger.kernel.org, Len Brown , Pavel Machek , Andy Gross , David Brown Subject: [PATCH V10 2/7] PM / OPP: Support updating performance state of device's power domains Date: Tue, 19 Sep 2017 15:32:18 -0700 Message-Id: <8850bb5088dc6fec4463247b0ec5040ce6415f2d.1505859768.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.4 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 genpd framework now provides an API to request device's power domain to update its performance state based on a particular target frequency for the device. Use that interface from the OPP core for devices whose power domains support performance states. Note that the current implementation is restricted to the case where the device doesn't have separate regulators for itself. We shouldn't over engineer the code before we have real use case for them. We can always come back and add more code to support such cases later on. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 48 ++++++++++++++++++++++++++++++++++++++++++- drivers/base/power/opp/opp.h | 2 ++ 2 files changed, 49 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index a8cc14fd8ae4..4360b4efcd4c 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "opp.h" @@ -535,6 +536,42 @@ _generic_set_opp_clk_only(struct device *dev, struct clk *clk, return ret; } +static inline int +_generic_set_opp_domain(struct device *dev, struct clk *clk, + unsigned long old_freq, unsigned long freq) +{ + int ret; + + /* Scaling up? Scale domain performance state before frequency */ + if (freq > old_freq) { + ret = dev_pm_genpd_update_performance_state(dev, freq); + if (ret) + return ret; + } + + ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq); + if (ret) + goto restore_domain_state; + + /* Scaling down? Scale domain performance state after frequency */ + if (freq < old_freq) { + ret = dev_pm_genpd_update_performance_state(dev, freq); + if (ret) + goto restore_freq; + } + + return 0; + +restore_freq: + if (_generic_set_opp_clk_only(dev, clk, freq, old_freq)) + dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", + __func__, old_freq); +restore_domain_state: + dev_pm_genpd_update_performance_state(dev, old_freq); + + return ret; +} + static int _generic_set_opp_regulator(const struct opp_table *opp_table, struct device *dev, unsigned long old_freq, @@ -653,7 +690,14 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) /* Only frequency scaling */ if (!opp_table->regulators) { - ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq); + /* + * We don't support devices with both regulator and + * domain performance-state for now. + */ + if (opp_table->genpd_performance_state) + ret = _generic_set_opp_domain(dev, clk, old_freq, freq); + 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, @@ -755,6 +799,8 @@ static struct opp_table *_allocate_opp_table(struct device *dev) ret); } + opp_table->genpd_performance_state = dev_pm_genpd_has_performance_state(dev); + BLOCKING_INIT_NOTIFIER_HEAD(&opp_table->head); INIT_LIST_HEAD(&opp_table->opp_list); mutex_init(&opp_table->lock); diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index 166eef990599..1efa253e1934 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -135,6 +135,7 @@ enum opp_table_access { * @clk: Device's clock handle * @regulators: Supply regulators * @regulator_count: Number of power supply regulators + * @genpd_performance_state: Device's power domain support performance state. * @set_opp: Platform specific set_opp callback * @set_opp_data: Data to be passed to set_opp callback * @dentry: debugfs dentry pointer of the real device directory (not links). @@ -170,6 +171,7 @@ struct opp_table { struct clk *clk; struct regulator **regulators; unsigned int regulator_count; + bool genpd_performance_state; int (*set_opp)(struct dev_pm_set_opp_data *data); struct dev_pm_set_opp_data *set_opp_data;