Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932462AbdHWQKj (ORCPT ); Wed, 23 Aug 2017 12:10:39 -0400 Received: from mail-sn1nam02on0077.outbound.protection.outlook.com ([104.47.36.77]:24576 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932204AbdHWQKc (ORCPT ); Wed, 23 Aug 2017 12:10:32 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; From: Dong Aisheng To: CC: , , , , , , , , , Dong Aisheng Subject: [PATCH 4/7] PM / OPP: use OPP node clock to set CPU frequency Date: Thu, 24 Aug 2017 00:10:07 +0800 Message-ID: <1503504610-12880-5-git-send-email-aisheng.dong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503504610-12880-1-git-send-email-aisheng.dong@nxp.com> References: <1503504610-12880-1-git-send-email-aisheng.dong@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131479782308505216;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(336005)(39380400002)(39860400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(36756003)(5003940100001)(189998001)(7416002)(47776003)(77096006)(68736007)(6916009)(305945005)(2950100002)(626005)(86362001)(6666003)(104016004)(8676002)(5660300001)(85426001)(356003)(81166006)(81156014)(50466002)(4326008)(97736004)(76176999)(8656003)(2906002)(106466001)(50986999)(54906002)(105606002)(50226002)(2351001)(33646002)(48376002)(53936002)(110136004)(498600001)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR03MB3327;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD052;1:K+uC4iVcwn1uuXCVdRw+nkosO0Q8muqrQzkYYNIi4eRs+kP73e0KPU5Ah70R8sF27j+WwlX1ekyYzxbBy+Jf6NuSTyOWuo6HCNlh9ggh9PYsEgjSCZ2Y9fA+RZgbiYtr MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c9c08604-f575-48ea-8520-08d4ea417a19 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(2017052603031)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:MWHPR03MB3327; X-Microsoft-Exchange-Diagnostics: 1;MWHPR03MB3327;3:I9VET9BX0yaY1v1Aq3f3y8V0qtufCWhM2XvynGfLFY0RMJBonedEcCRN3JtXBs4xu1g8C+nuHVhys1cEFiUw9SCCiiW+x+FRdKS+RZXB0hXFvGDofjMCfJf9LC4/ftCDWzd+VCdpqHZgbL0WDcV9TWZQPK2GQ5ZaAqBIe19omb+ZzyZEct+4g/YhvTdlr49pPLhdHxlsN6z8mhDEzoYWkc6b4woEcDSuRVa3pW25yaed8UX+GMDWGkIrjyf+lIIfgB2A6KDeE/Nk3FGUVhUYjrr7nMV94d7NE7T2tYkY10PTZoOi5UzPrM0RPnFETCCvP7jJqZh3jeQhuLGIosCkW6NK/McaD+z2RlbrBu9TDV0=;25:5auno/E9mkV06bLHavqrbEsPhw1to5of5f2d9xLMh6wiRUbPAw3UvIt4eD4wh0CL8ZRXnzbDQt6IjRagBBKCu3gtZzsJGj6VAWvq7cv7bvwJVm599xWmOw/2DLW/ZmTkKfiDZr+iyn3681d1UOlnrzpjUHTrOdPhbFxi5fmlGrzQ9r4Aohgo315ETBClEdc0AGvLi35Pv3zf0DWsCzVqyH4cYAG/0xV34bhiCeEiCP/HTJrfnnjvgGWLZvImZm1GSrC4R2zMxk4PeDfA3s1auhZShE8kjstex5BiYhn/xVD+XsNmP1Rm3bR51T/DqTIak2LPKEJRp1TXitT1W7rr5A== X-MS-TrafficTypeDiagnostic: MWHPR03MB3327: X-Microsoft-Exchange-Diagnostics: 1;MWHPR03MB3327;31:4P21WQFAvwvwU3o3k9tIlzXnr20Fp1kq653ZOb3fYJ8CyELR4prYSK8G4MiaFPqDHO8r7GZVFEA8Ez7dIeE35X8Qz/YW0Re55ZLPze4vBRxcTqk5mseiyRDPJlfxI1nbGW0lZHTM0tBBnBCBaq9sdonF7Gq3+PxhCM+/MEnWj2aycgw0FyBy+8pE4NT8+M89D3pGrvUL+13xL1EXaN41nC2lrI+h93EMrIKtWNNZ708=;4:AdXyjT2b1JkiifC3YHbH+vtADIcu5RM/rHKjIG5Xtv51/SLFDvyt92xSsXoU/adX10Tv7153SLctH8UugX6hs4VNnDERseGX39IlTAEmSHKUo6yUqnbRbZ8yPPnzLMtRpAf1bjbZOpCyDnjZMLPdlPdPdlnzQG4p00hO+4T4YwXheM9wDFA6nHNt9Z26Z8VKJg2KUO5R/Y/VxyDsW2/uJOCBW0+XOauu7mLgxypcmpwsXDr/I4OHfqo4zHswRe3hljZGeSmyobPtf4UzdF6rCfY1CNbBMApgLK2qOQ5xe5dx7FVaDUYxJ0SKRUM1kGR2oUv8U8IY8wyz74yhcGxvRA== X-Exchange-Antispam-Report-Test: UriScan:(31051911155226)(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(601004)(2401047)(8121501046)(5005006)(13016025)(13018025)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6055026)(6096035)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(201703161259150)(20161123565025)(20161123559100)(20161123561025)(20161123563025)(20161123556025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR03MB3327;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR03MB3327; X-Forefront-PRVS: 040866B734 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;MWHPR03MB3327;23:XzvOyzE3zFqk5CLBR+yESltyB8Kqdg1T2HIv9y/uP?= =?us-ascii?Q?IpIqYlGSDBjpqawZW86eydY3zRs2B3PwsZyRDoinpfqTFNztSh256zxDRzmD?= =?us-ascii?Q?wvTtJVZb2z/z9qga/bs3AM4LCdmOmaUzBJ6SXA3lGl72xkMxjTNY8Jajsj8K?= =?us-ascii?Q?slH7I3yPIgxpz3zZTpiIHhmYntZWoH9HTPOvl4cnmUF9wGi8vNL9OeN0zx0l?= =?us-ascii?Q?0cm4um67ien64otfP4/Of0zuv2wjh7pPI0yO28aE7Z+n1otUJSjWiEBSVOkg?= =?us-ascii?Q?fccMnEghWXcvRQyfILi9uuI0iXZwLvxxmFKjG101hVyzVXuf4KaM7cucZzYF?= =?us-ascii?Q?1OgGavwpRBQGCI3kEISHrWx5NAW2io1ajXSLUwgWNSZDyKxVmaQv8L0QF3KS?= =?us-ascii?Q?H+bQ2P+tW7KtxOuxFCXy5R5SVumrMwVi18R0oZn4aZfeHntQuDdqzmlHMsQb?= =?us-ascii?Q?nbZTNgHbiIZcs+nlLIwU7kahG/faMMfMztGS66qiBbqf8p0Nn9OkpoN0Jnfv?= =?us-ascii?Q?h7zxFWcHRPkyt+IK6sLm/R6kqr7WfG/a5vYEOOnNTj/8QJD6HdwnRTOWtjJU?= =?us-ascii?Q?MDtyNC6tqdKKbxlcGTGLkDxtYeTrdEvZITUo3XYBc5WNvpOAVJhAUoH3qnpI?= =?us-ascii?Q?iKIwJvGmnoEJiX9vsMr74dNTNdiQqxqS32LEDdqxri27VxYxU+cF8gm9ZXeT?= =?us-ascii?Q?fL92B6h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Typ1yGvrdi4K3NkDrkB6GjC5CyErjA5T841qzhBTW9JjNQRdeqjJRyFecZUg75GLvtojbYQrRffRWGu/++cj4p+KDGa3ymuTCA=;7:hCTXGmEbXWdsMsRB7+zCTGn611Q9oWLMzCJ9XmvKBaOk1oHJFt3n0oXg9X6BGbTkROWUxQOHDjuVR8gNCLfUgh2z2k553elr7GZYxv42sJ0HBgpAXhNh6roVrCEnjJEsrksaf3OAPGBZg71xZtQN9c7nYp3BC9cQlqYu9sZdEx9248O0RqocTXWDPH0UqYZW7kBfwX/GW5kL7N9+AO1/C2gloBGHQQ4axmoQ2NOxt20= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 16:10:30.6633 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR03MB3327 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3119 Lines: 99 If OPP node has a valid clock, we use this corresponding OPP clock to set the device clock frequency instead of the default opp_table->clk which is shared by all OPPs. Cc: Viresh Kumar Cc: Nishanth Menon Cc: Stephen Boyd Cc: "Rafael J. Wysocki" Signed-off-by: Dong Aisheng --- drivers/base/power/opp/core.c | 10 +++++++++- drivers/base/power/opp/of.c | 8 ++++++++ drivers/base/power/opp/opp.h | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 2579401..d4656cc 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -600,7 +600,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) struct opp_table *opp_table; unsigned long freq, old_freq; struct dev_pm_opp *old_opp, *opp; - struct clk *clk; + struct clk *clk, *old_clk = NULL; int ret, size; if (unlikely(!target_freq)) { @@ -651,6 +651,11 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) goto put_old_opp; } + if (!IS_ERR_OR_NULL(opp->clk)) { + old_clk = opp_table->cur_clk; + opp_table->cur_clk = opp->clk; + } + dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", __func__, old_freq, freq); @@ -683,6 +688,9 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) ret = opp_table->set_opp(data); } + if (ret && !IS_ERR_OR_NULL(opp->clk)) + opp_table->cur_clk = old_clk; + dev_pm_opp_put(opp); put_old_opp: if (!IS_ERR(old_opp)) diff --git a/drivers/base/power/opp/of.c b/drivers/base/power/opp/of.c index 57eec1c..64909e7 100644 --- a/drivers/base/power/opp/of.c +++ b/drivers/base/power/opp/of.c @@ -13,6 +13,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -314,6 +315,13 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev, new_opp->dynamic = false; new_opp->available = true; + new_opp->clk = of_clk_get(np, 0); + if (IS_ERR(new_opp->clk)) { + ret = PTR_ERR(new_opp->clk); + if (ret == -EPROBE_DEFER) + return -EPROBE_DEFER; + } + if (!of_property_read_u32(np, "clock-latency-ns", &val)) new_opp->clock_latency_ns = val; diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index 30a637c..dbe8ec6 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -60,6 +60,7 @@ extern struct list_head opp_tables; * @suspend: true if suspend OPP * @rate: Frequency in hertz * @supplies: Power supplies voltage/current values + * @clk: Clock used for this OPP * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's * frequency from any other OPP's frequency. * @opp_table: points back to the opp_table struct this opp belongs to @@ -80,6 +81,8 @@ struct dev_pm_opp { struct dev_pm_opp_supply *supplies; + struct clk *clk; + unsigned long clock_latency_ns; struct opp_table *opp_table; -- 2.7.4