From patchwork Wed Jun 29 13:52:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 9205287 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 B1153607D8 for ; Wed, 29 Jun 2016 13:59:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A34372865A for ; Wed, 29 Jun 2016 13:59:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97FAE2866A; Wed, 29 Jun 2016 13:59:52 +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=ham 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 4F9502865C for ; Wed, 29 Jun 2016 13:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752935AbcF2N7j (ORCPT ); Wed, 29 Jun 2016 09:59:39 -0400 Received: from mail-bn1bon0057.outbound.protection.outlook.com ([157.56.111.57]:23876 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752914AbcF2N7h (ORCPT ); Wed, 29 Jun 2016 09:59:37 -0400 Received: from BLUPR0301CA0019.namprd03.prod.outlook.com (10.162.113.157) by SN2PR03MB1933.namprd03.prod.outlook.com (10.164.114.157) with Microsoft SMTP Server (TLS) id 15.1.447.15; Wed, 29 Jun 2016 13:59:29 +0000 Received: from BY2FFO11FD056.protection.gbl (2a01:111:f400:7c0c::161) by BLUPR0301CA0019.outlook.office365.com (2a01:111:e400:5259::29) 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:29 +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 BY2FFO11FD056.mail.protection.outlook.com (10.1.15.193) with Microsoft SMTP Server (TLS) id 15.1.523.9 via Frontend Transport; Wed, 29 Jun 2016 13:59:28 +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 u5TDx9x6014881; Wed, 29 Jun 2016 06:59:24 -0700 From: Dong Aisheng To: CC: , , , , , , , , , , , Subject: [PATCH RFC 3/7] clk: add set_parent_hw and set_parent_done Date: Wed, 29 Jun 2016 21:52:11 +0800 Message-ID: <1467208335-29876-4-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: 131116823686447665; (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)(1110001)(1109001)(339900001)(199003)(189002)(2351001)(97736004)(36756003)(86362001)(50226002)(229853001)(68736007)(6806005)(110136002)(33646002)(11100500001)(189998001)(356003)(48376002)(8676002)(305945005)(76176999)(81156014)(81166006)(2950100001)(586003)(50986999)(5003940100001)(2906002)(47776003)(8666005)(77096005)(4326007)(19580405001)(7846002)(105606002)(85426001)(19580395003)(8936002)(92566002)(106466001)(50466002)(104016004)(87936001)(7059030)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR03MB1933; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD056; 1:JSFalIMf2ZCKPtw1i7iI06qSVzCpZ3w8Duvzf2q4QTaUMZHw4FMQ6vNRr/g7VkgMBa3JeDQEI+w03D4ZhV/2sI7yDDUJLHPXB5zy2UEJTgXmjfAQ7X4bVTiKOhb4SVw2ap2GODCZVlV+VzYrkMHXuUDNhCz7nhrGq1mgyqNiEphtzG2zLkU2E0TOvIum0aCRbXmUYKleJFppXFYHarXSS0/zX/BxJohKmi7jTUN/hkB/MITrqnvKAm1qM7R3u4DqBsFCkkGiruHFeqN0RDUHiu30KAFU2VtPFSCAXq45f+yPxyrixYODsoDQ9iNAw0K8bgFr9eZjPD+X2sdQCsHPalEw4wL2JA1+f6yUoUNMLWc7WZ+9HOrNBs6i4H7BTFWkof2NRO1c4MSU3G4WW2PtVctLyiw3IAbRg7rCvOPmXp872eTIxmcQYoiwFlXYivihqmQeR2hQgsjMaPQdiaVxfMRY+pqJisfXzmh4zhLZ9YWVuZbbfDRO2pPgpmCNwVsm0jRE64hd380Baw2XRXXU1/I4Ap9J1fRdwqNJESUSsDnM4L550Pm4XJHqMio2R/EGzJQzwkK1Ng4bl8ML1B85Y2CvEJC/zmKlYBRirD7wjxjT6EX3STTZdFW2LO5XFcJPwAS+Za1aEQvBl+zBZ8YFh3hwPN8c2ZFlfKPeEOIg7iKa2QFI8DKENxeqUj3gQs4t/93/8KcB3B3NKrf4/XKAtlrUonXK9l1/GE1J4BVsVyA= MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 07bcc753-72ab-44e3-7739-08d3a025964c X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB1933; 2:cgQjW4OJCAiNbIlVRCIYzd91R/2M88greKWdH6K3U6Uh/XzGoa7jjzdLxdwgOQM1ca6w3H6zLLsB4JgA+S/2iVkxnByeilquna4na0UfBw3UPhPGx53casa2BmKF0mgbdBGmRbCoXFpg7JztQveSQKypJ1jiHjI/KG5A5X3yWmK0YdSUIIXzQG0bxdSV7PAb; 3:rSSBNabAiMmWof2hqvh/54M4blXMnBhXK3tVEIPiY0Xf5Kzy0yVEI/P+f7eFvAh8KdV5jRygCocxADpVVNG0zKXM1TNL4+lweImiMjMinRyS7CAcneiq/Dn7Hyq2EjsefAjTfT4Ls8KG0IjC84B65n+c+UArAc1oRGtBBeBvTnc+8xvbLfhBCwDx9Ikhv3Bkcx6qvEmTFSRTnZWL4oUpV62DKNNPd3RkSunL4JLgV60=; 25:7vw0ID4AWMaO6aaaeSvzk+AqESaOQ7ZTNvvR9YKGkJe1YpaTYwZUFZLrV7kHQwr7hHlZEO5yg9SIxOy80wX7v3PS5/uk7PLnsPSpK7/e5R5YNlTi9nTL5G1hCYpG/js59dIv7pxfa2LrOYWtZ0zxjkfZsQSLr+YzMaIfQ2P0sT8yP6TZ+omZD3Iei5ht+T+qyQJrFfn0ZiayxU59fmDaPfzJiPPtV6WBjFhssxsLW64WeEAEzuIrQn4Zt1E7c4jo X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR03MB1933; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13018025)(5005006)(13023025)(8121501046)(13017025)(13024025)(13015025)(10201501046)(3002001)(6055026); SRVR:SN2PR03MB1933; BCL:0; PCL:0; RULEID:(400006); SRVR:SN2PR03MB1933; X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB1933; 4:FCHmIwwWWLE8/nDCOu8qN0Dmxdw4DtI0Eid+hxw8ufe040xW//C415i+3Da9LcEWfWMwB2sqE8QtqgcW0vUGIDJCREhTdNNWk8/sLgEY/c4tToQ5TaEOS5keIQYOkeXkdl+vXWM8KVVFP/f5FSliJHP6It3oy55fzMWJxzh13JA9VhTwg3hrE/KGAcy6hCa0TGAjfn7qs2/1cG2B5g0T7tHcrKrXjNCI/nnnujNUYDwvyPiFxdB8EIhisZHwLCB0zl2MshhVz1Lzl/aY9waDpynr+e7kra+6JMSbu2GmmlnpTlbCaxcbCBKFwjNaa1LK7ukdIlrxNcEoCl7XA3+t6586k2K9/B80Eu1vQ7nYBNLD4t/W0tnxDHecQtYQJ57gKR9UQAxK7yYRvLyTZ3mo9Wx34JT1xf2+pyh1XflPG6tOZexbXKUR5xVs9dB0/mGuOtG25iWXvnvG+N+WNaMbQsgeZN1pborbr6js8nZW4akqxS6zVD6YwXwDcxYjlqXbZKozNWg45IDk7sY1wiZnsg== X-Forefront-PRVS: 09888BC01D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN2PR03MB1933; 23:WJdLe+Lcm4y2Fj7ifxA2O/+yNSTcpP+duLFpwqn3X?= =?us-ascii?Q?8lVZ/9ZIXnMBNn1310261iNZcsFdDoGtQFhZu9Nn4gCA4RCpg6mc5ta7DAfS?= =?us-ascii?Q?Er69vuCkXBdu2lw067lnplRingzbgr22gFRK7wYTmQCEmfnq+SMZpgMGA8U+?= =?us-ascii?Q?AjjadgIJrPEXaD+WaTVX9lHPexjrGRBbOiW3TJFwj3Ueltq/nqOqL6RHOA2Y?= =?us-ascii?Q?mthucr239aeTQrJ3UztaE9TcBQAGrbvsRfGV3S1Z4s6/2VaX9ogk5MaWk0d5?= =?us-ascii?Q?1NOnDJzPpL3S3S0YwXjD5+vlELQJAkte961lVqL1Qt072OfNllc0y1h64PcG?= =?us-ascii?Q?pQKXgVRZA/X58/n5QIvAoDg00u8wTsQJ1a5O4sx2fGzaNEduv3y6Kspg3LT+?= =?us-ascii?Q?/aKQ9UWyYMGB7dQImWrqIaQRoMhX30G7ToAmQwkAElawX4CoZmTIAvQcsSCY?= =?us-ascii?Q?clt5IpBMQo06aBN6xs9Ov7Pca+9xCQjbCkinpSjvDvQ4PTmHcq1W2Wd4gK/J?= =?us-ascii?Q?32UVVaDzqmgMHDb4WXN3tUr6bP/Oa7PStidUpZGhYyQiemnW5REz8eq7KbJ6?= =?us-ascii?Q?8Lr6gE1LgYNxrssllRFDsNbBKbxhkQNXx5pp7FYs3H3rR1oXPnxHXLpyGg0X?= =?us-ascii?Q?pasG4u2jrXzA08e3FCyV+O9dB60s4FSMzBJW3zu/xidlI0rkUPRgaMrwoT/s?= =?us-ascii?Q?s0oILL6jBXUCno1pOHAWpqGwzI00R3/hxiOziCdN5TEEcicXFX0s/LzrPbm8?= =?us-ascii?Q?RPzU6D7dv/oNE1886MkhOkf7p0VJPQnDOYk91AuUkVWCLTpdegWqAP9/KFgN?= =?us-ascii?Q?vLjPSwJ4F3DcTDebB7es44B7gjIWqfA2na0lQc/RY3AFedtghlgfoMzYZbTO?= =?us-ascii?Q?A5v/UA2BfUgHtAd+e1TtSxmXuqV7vuIKKqrTKKwvSzznymHLghIWCaEugxHl?= =?us-ascii?Q?aFA595vzOwxF908jQLK/Df0NMJcCIcRK9JylPzMzJWDv6rbfwbWz+MFajBcC?= =?us-ascii?Q?iy3wjDJGZ3JeBuR96CJipfs3fggg4sZowDH2+OQoAmnkkeXa+aTYt1OHA9iE?= =?us-ascii?Q?j1vKwk63pj2CAXjiSzxP8Ej4gE+FOf/Vxx7GEamtf3e3jVElcJzxRslPUBOn?= =?us-ascii?Q?M4hoL+EsknGFOeITt0gcirqbTYWkgg2hvbmQf3QhTJCGNTjeUhi+c5K+YjRV?= =?us-ascii?Q?YD1GZErlB+uXo/gDm8r5+OL/02qogSM0IX1?= X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB1933; 5:6RvAdfyPWsgrvwXUAkWJaFLWWelTHxMhucksC7d4tIdW2/SdIhvOZBEu0yDqnSUyy/1iyC0az7j40byA3JAAmjsuvdU5JpVo8xBojclQ/1VBLZOe+TUThnYkMAsP16sIIh4saC6yW6B/EuG/w8eDa0zvSVKwiR7RyQGSBAPuJFs=; 24:Nv/JELHHtr9SlzuctS6j12bb9Pg3at0qBfXPPGGAQyo+GCAJ/1mvdfjoguXC0QETkRDT4igJmOV7Iq9xFGPBROhPA26H3Yr5wQwxHLnojgM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2016 13:59:28.3171 (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: SN2PR03MB1933 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_parent_hw and set_parent_done to support setting parent in early kernel booting where we still can't schedule. Change the input source of this clock hw; This callback is intended to do the hw part setting of @set_parent work. It should cooperate with @set_parent_done callback to do the whole set parent work. The clock core will check @set_parent_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 | 26 +++++++++++++++++++++++++- include/linux/clk-provider.h | 14 ++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 0d031b280c9a..9369dbb71118 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1236,14 +1236,38 @@ static int __clk_set_parent(struct clk_core *core, struct clk_core *parent, unsigned long flags; int ret = 0; struct clk_core *old_parent; + unsigned long timeout; old_parent = __clk_set_parent_before(core, parent); trace_clk_set_parent(core, parent); /* change clock input source */ - if (parent && core->ops->set_parent) + if (parent && core->ops->set_parent) { ret = core->ops->set_parent(core->hw, p_index); + } else if (parent && core->ops->set_parent_hw) { + ret = core->ops->set_parent_hw(core->hw, p_index); + if (!ret && core->ops->set_parent_done) { + timeout = jiffies + msecs_to_jiffies(10); + while (!core->ops->set_parent_done(core->hw)) { + if (time_after(jiffies, timeout)) { + pr_err("%s: clock %s set parent timeout\n", + __func__, core->name); + ret = -ETIMEDOUT; + 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_parent_complete(core, parent); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 3dcb99ad6bd2..16fa75cdd656 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -146,6 +146,18 @@ struct clk_rate_request { * array index into the value programmed into the hardware. * Returns 0 on success, -EERROR otherwise. * + * @set_parent_hw: Change the input source of this clock hw; This callback + * is intended to do the hw part setting of @set_parent work. It + * should cooperate with @set_parent_done callback to do the whole + * set parent work. The clock core will check @set_parent_done + * in either sleep or polling way according to system state to + * decide whether the whole set rate work is done. Optional + * if @set_parent is used. This function must not sleep. + * + * @set_parent_done: Queries the hardware to determine if the set parent is + * done. Optional, if this op is not set then the set parent + * simply return. This function must not sleep. + * * @get_parent: Queries the hardware to determine the parent of a clock. The * return value is a u8 which specifies the index corresponding to * the parent clock. This index can be applied to either the @@ -243,6 +255,8 @@ struct clk_ops { int (*determine_rate)(struct clk_hw *hw, struct clk_rate_request *req); int (*set_parent)(struct clk_hw *hw, u8 index); + int (*set_parent_hw)(struct clk_hw *hw, u8 index); + int (*set_parent_done)(struct clk_hw *hw); u8 (*get_parent)(struct clk_hw *hw); int (*set_rate)(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate);