From patchwork Wed Jun 29 13:52:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 9205305 X-Patchwork-Delegate: sboyd@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 06C55607D8 for ; Wed, 29 Jun 2016 14:01:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E85362865A for ; Wed, 29 Jun 2016 14:01:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8E372865C; Wed, 29 Jun 2016 14:01:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED0812865A for ; Wed, 29 Jun 2016 14:01:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752910AbcF2N7g (ORCPT ); Wed, 29 Jun 2016 09:59:36 -0400 Received: from mail-bn1on0083.outbound.protection.outlook.com ([157.56.110.83]:6416 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752891AbcF2N7b (ORCPT ); Wed, 29 Jun 2016 09:59:31 -0400 Received: from BN3PR0301CA0035.namprd03.prod.outlook.com (10.160.180.173) by BY2PR03MB1927.namprd03.prod.outlook.com (10.164.114.31) with Microsoft SMTP Server (TLS) id 15.1.447.15; Wed, 29 Jun 2016 13:59:24 +0000 Received: from BN1AFFO11FD019.protection.gbl (2a01:111:f400:7c10::120) by BN3PR0301CA0035.outlook.office365.com (2a01:111:e400:4000::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.528.16 via Frontend Transport; Wed, 29 Jun 2016 13:59:24 +0000 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; nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD019.mail.protection.outlook.com (10.58.52.79) with Microsoft SMTP Server (TLS) id 15.1.523.9 via Frontend Transport; Wed, 29 Jun 2016 13:59:24 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u5TDx9x5014881; Wed, 29 Jun 2016 06:59:20 -0700 From: Dong Aisheng To: CC: , , , , , , , , , , , Subject: [PATCH RFC 2/7] clk: add set_rate_hw and set_rate_done Date: Wed, 29 Jun 2016 21:52:10 +0800 Message-ID: <1467208335-29876-3-git-send-email-aisheng.dong@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467208335-29876-1-git-send-email-aisheng.dong@nxp.com> References: <1467208335-29876-1-git-send-email-aisheng.dong@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131116823643219325; (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)(7916002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(86362001)(85426001)(50226002)(33646002)(36756003)(229853001)(11100500001)(6806005)(586003)(68736007)(189998001)(356003)(7846002)(305945005)(77096005)(92566002)(48376002)(2950100001)(97736004)(50466002)(105606002)(2351001)(5003940100001)(106466001)(76176999)(87936001)(50986999)(8676002)(47776003)(8666005)(81156014)(19580405001)(2906002)(4326007)(81166006)(19580395003)(8936002)(110136002)(104016004)(7059030)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR03MB1927; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD019; 1:QHEZ8bzWrTKEZAOdqop77NmXRTExyWaWHy+s59+iTYFvA9Sk2taPWwOzcGB3XZZy4m40c2c0gj62IUX238YcdcsnTGfPl680cTqglydKT0sDcBbIMGIQaMVuu+LcSLCcmlvar2wFZMbUUp+KelU4AO3q7y69JG9whidGqur54+QChwIrt5miPNOh8qjqY4iLolRRmt/azk36NN0Boz64aYx7+8lQgzu7aqalBalGdr0JfpSFbx2O+WDiGp4NSKyGB2hFIXmfDqEVKvhfHGWfXsyQpNX7izD38Zc31DEP4CrdpGt+tWQ+7/r0Zu79LQrsgX4AQGCcXb7RxAvFJ2UxOqDzhzq5K1GRFvxyUT2VF7rSom6HfoozLYMuyzPgTYuV8MVxnw2b2+oyAElBaJErp9PtKZHAXCreHoQdBw9rS11ZEI/6DLP3uW5fccDOOJeCBAdxtEQQbLj9pELfe0mLGx4KPDzSk+6yNJzrrIP6Aqve2Z9ZFG1IqZ7w0wyRPJkVCft4LXschWljovdGqH68OC6Z4JogryP0AYuhKGbylif/IqTdzcPOkDYb0Auz1+QxM/NofGuvdgxhhUPqdzsVvsY/bhIfT+E90swOLTLAk0NccXJ7QCkInYHUXKP59R67t5IOEtmujKS2DqaDZQOZBVsdawRoZ/RMWeXpJXqAA842VbVUrG0cjRneMfJQK8YIV4VKSWz7H3mpyZzMsR7XYNM0DZjzNPGkow2evTzNDZc= MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: e90b3343-7a3e-46e8-841d-08d3a02593c9 X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB1927; 2:pcV2gjTEvUQV4fdBeRJDq6C1d1rJ8z9VeIiCOZbwJL71Sba/8Psi9Yi+NMINQpZPsCmFt60RsbdfuJ5szR321EI9g/un4faUTg6JqSDrHwrZiryOydMJGiKDglTtJjWu9TrVGVwX+JSlYPjp2XikJbbZocmWVlLh1w6OtyJic3EaKLAFMrztPxJ6ABd7d2UR; 3:32PE5LsTJliDNfSeZ7L0CXUOGkhCGnNP/Q2CYPm3hyYfo7sbmdK4szYpQG+nxLEMB8F7HsRs1ojUq2jzmVWvp1TmpIXMmYKS7n92B2M6GZthRlGkwErWWqFk6PUohEgjs0Up33zAP/SapFHiqyut90jF6nvFfEj1x6XQWKmfmP1Zw7eMbBesv0zKUmjNaE6fMYL/fEXzrmPoskn2QW/4Tp3wqX4cjsjsjqVZEsdTm2A= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB1927; X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB1927; 25:P9Pr5KLBAjlt6AMrNIWgAi1xPkVxoiIVQTh65qbpUpZj2RQY3M+C99HLx37Qgyb2z2cO6H8N4gt7xo1IWXq3CtpwMvhyVSL8pr9EmSrw4ZTMfRZCKQF/chKr9EOtflpe++6xRyadoz1HtK8pgBj/ONo6KcVLCRgUYXMzVMpGypJWpTsln+KQcymcQE5+uqEbvUK87xxD1yDEvHeYZtuYSsOPJJxRRr0RbJ+yQufT6Rb3uFOjQ3iq5b79oAQ/IbK0fzg/qrviEU6PpBsfe362uqcGQ7p0VPpGskOiJ8wAI0cAD1AFq0shjsD79JGhsk1CuuQ+ODlvit6zwBuk4DqeDDV9hEEfhtLX39tplVyeAPwf3fMlEeY0UT65Cod2B6pJxhtXDrAGPiEVPe8LWIaiNTdz+fW9W923bVP0YAK4liTcDoBDAGwYG0x5BXM998GHVMaCw1f2IY9118n1slfzQutKNPLA/SfI8/0uwZTFIvtGrbxgx+/s1/ikn82CynH/FDpr3A39wvxFlfgewGJajG0a5k/wN+0aE2iW0kmMRaTW+W8v5MpGnTanA+qM3YTi X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(13018025)(8121501046)(13015025)(13023025)(13024025)(13017025)(3002001)(10201501046)(6055026); SRVR:BY2PR03MB1927; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR03MB1927; X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB1927; 4:ZWEXxsN5HB10oKRUyuOe5EWyRjavopO2bikunDWdqjdTHWolxblArrkmPyaRUVYKJOIWlTFKQbPSU04/uwRjwANkmd+2lwZ0V8fesacQxg4d3ZFDAFIsuX2bltHPHZPCxTAi7jaeFcXjicyA+AnXkZpnRDjGPE2qfh6D4l4YZ0KjRjwo9wuoZEW1j1nqluf3yv+LBUESPlddAJkHw9U661Z0VH2J/DIFmlMO+qGUuTNFalOkCIj3MBrsmD4BMCSZz6DZOR1MOX25NTkFubYodjPbf2vkGbFRpTsr1tvZX2ewSc8NnZeNXjz8Zda5vRnyPXGhaEYSyjHlsZu88ZeTpTkNpaVi/D9sSnclMt3MvgycWSquPL2UPx7AGWJS22ltNpfKMbfYs2TABeJ8gpGkx4Yj5PglR8RWdM+tHXIWZc41djT1ijnsFF3TIxReUwTIjZGgTTfNF9gYI0t5h5tRtW4diIQZjoWVMY/7FFwqFCJKpf2K1Cz53Tmji1V8rQrvqKU2O7RimraGO98T9kI47Q== X-Forefront-PRVS: 09888BC01D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR03MB1927; 23:4WK1hSaFeA2/CWSC7f1O5stf16pIudkpjFWLc8Y/d?= =?us-ascii?Q?5UcpWi9LEwy2clg9RwjCQaqfHPD052t1bcRcrvm0YjwiUcc7/lmNd2vPlj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ml/JU3Jr0u3Dswx7yQgMC86pSYKmM5V7rG6?= =?us-ascii?Q?LC55HEseZN/Ib+4W+PBB87vAxzJnvf0EP07fF+8Phfbp9h5WFTMyLwdLk/6J?= =?us-ascii?Q?bsemVZJZTWXgv+oWYCMmOo+4nJ/icVcAfVXEMfAWkeUeopA+G8xu1b06nCtI?= =?us-ascii?Q?vEQqt14ueVvYxvD7nbytRfHO8SUyu+P5hZTZAl8lWfZQ06/5Ik63kEskl7sl?= =?us-ascii?Q?0U4F7ovgJjc+ty+vqZ3B837Djhl5gYHdqiF?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB1927; 5:JgvXdaw32uNxre8k5he1uxem0s5NrLcssfsGO3oFY2oSFtQpcHHnsB8WMLrK/PDrMEbqTHK9PGNchCpOMxbhl2KUg/UsL00Q9TYNgdDHGgk0kNg6/tTjOqw+YvhaNxHAWfx54XKkybtX+qoyH5GzIjELchGXcpvnkdSsajtyNhM=; 24:iQiFVb6ESPlFqa6Lk1v6hO+qlIeRhouIREjsPeyQrbGCXaVAuu2jocKOeY2BdwLR0IQv7xHxD3ohvSI+dThCTHV1ypRRu5+XDigefb0bqe8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2016 13:59:24.1347 (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: BY2PR03MB1927 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce set_rate_hw and set_rate_done to support setting rate in early kernel booting where we still can't schedule. Change the rate of this clock hw. This callback is intended to do the hw part setting of @set_rate work. It should cooperate with @set_rate_done callback to do the whole set rate work. The clock core will check @set_rate_done in either sleep or polling way according to system state to decide whether the whole set rate work is done. Suggested-by: Thomas Gleixner Signed-off-by: Dong Aisheng --- drivers/clk/clk.c | 32 ++++++++++++++++++++++++++++++-- include/linux/clk-provider.h | 15 +++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 7dcb34c75a9f..0d031b280c9a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1471,8 +1471,10 @@ static void clk_change_rate(struct clk_core *core) struct hlist_node *tmp; unsigned long old_rate; unsigned long best_parent_rate = 0; + unsigned long timeout; bool skip_set_rate = false; struct clk_core *old_parent; + int ret; old_rate = core->rate; @@ -1509,8 +1511,34 @@ static void clk_change_rate(struct clk_core *core) trace_clk_set_rate(core, core->new_rate); - if (!skip_set_rate && core->ops->set_rate) - core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); + if (!skip_set_rate) { + if (core->ops->set_rate) { + core->ops->set_rate(core->hw, core->new_rate, + best_parent_rate); + } else if (core->ops->set_rate_hw) { + ret = core->ops->set_rate_hw(core->hw, core->new_rate, + best_parent_rate); + if (!ret && core->ops->set_rate_done) { + timeout = jiffies + msecs_to_jiffies(10); + while (!core->ops->set_rate_done(core->hw)) { + if (time_after(jiffies, timeout)) { + pr_err("%s: clock %s set rate timeout\n", + __func__, core->name); + break; + } + if (system_state == SYSTEM_BOOTING) + /* + * Busy loop as we can't + * schedule in early boot + */ + continue; + else + usleep_range(core->delay_min, + core->delay_max); + } + } + } + } trace_clk_set_rate_complete(core, core->new_rate); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index b37174360f1c..3dcb99ad6bd2 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -162,6 +162,18 @@ struct clk_rate_request { * which is likely helpful for most .set_rate implementation. * Returns 0 on success, -EERROR otherwise. * + * @set_rate_hw: Change the rate of this clock hw. This callback is intended + * to do the hw part setting of @set_rate work. It should + * cooperate with @set_rate_done callback to do the whole + * set rate work. The clock core will check @set_rate_done in + * either sleep or polling way according to system state to + * decide whether the whole set rate work is done. Optional + * if @set_rate is used. This function must not sleep. + * + * @set_rate_done: Queries the hardware to determine if the clock hw is + * prepared. Optional, if this op is not set then the set rate + * simply return. This function must not sleep. + * * @set_rate_and_parent: Change the rate and the parent of this clock. The * requested rate is specified by the second argument, which * should typically be the return of .round_rate call. The @@ -234,6 +246,9 @@ struct clk_ops { u8 (*get_parent)(struct clk_hw *hw); int (*set_rate)(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate); + int (*set_rate_hw)(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate); + int (*set_rate_done)(struct clk_hw *hw); int (*set_rate_and_parent)(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate, u8 index);