From patchwork Thu May 14 13:29:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Aisheng X-Patchwork-Id: 6406291 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C885A9F1CC for ; Thu, 14 May 2015 14:43:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 168BD2025A for ; Thu, 14 May 2015 14:43:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 065EE2021B for ; Thu, 14 May 2015 14:43:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YsuJD-0005QW-0X; Thu, 14 May 2015 14:40:23 +0000 Received: from mail-bn1bbn0105.outbound.protection.outlook.com ([157.56.111.105] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YsuHS-0003PP-R6 for linux-arm-kernel@lists.infradead.org; Thu, 14 May 2015 14:38:36 +0000 Received: from BY2PR03CA069.namprd03.prod.outlook.com (10.141.249.42) by CY1PR03MB1360.namprd03.prod.outlook.com (10.163.16.26) with Microsoft SMTP Server (TLS) id 15.1.160.19; Thu, 14 May 2015 14:38:12 +0000 Received: from BY2FFO11FD030.protection.gbl (2a01:111:f400:7c0c::104) by BY2PR03CA069.outlook.office365.com (2a01:111:e400:2c5d::42) with Microsoft SMTP Server (TLS) id 15.1.160.19 via Frontend Transport; Thu, 14 May 2015 14:38:11 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD030.mail.protection.outlook.com (10.1.14.211) with Microsoft SMTP Server (TLS) id 15.1.160.8 via Frontend Transport; Thu, 14 May 2015 14:38:11 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t4EEboxL007474; Thu, 14 May 2015 07:38:07 -0700 From: Dong Aisheng To: Subject: [PATCH v2 5/5] clk: core: add CLK_OPS_PARENT_ON flags to support clocks require parent on Date: Thu, 14 May 2015 21:29:03 +0800 Message-ID: <1431610143-21853-6-git-send-email-aisheng.dong@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431610143-21853-1-git-send-email-aisheng.dong@freescale.com> References: <1431610143-21853-1-git-send-email-aisheng.dong@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD030; 1:5iqmaCznf7E66xRf4XGtVRi6qp+s5p7obFU748QU/o1sromk7eHKCTJkz4cvHqL9YmsTfMYJ3+50Ybbz4LjVMin+M6TjhS/YPH2bqqPP8BSAtxSxTR+dSfboeQYBDCKhlNCPnfFJX78LevCA/ytSaVsPQPOZjy86f9Met+ho+3dxrmlIwfn78Me/tHl5DReVz9ROynVuCqhc6PhhHOnmWtjk1QA+NpDtm9QMIzSrhnFKFs9r/fLwTD2nH+YivFXHGdjgCbQz/gl68XOGMyuLMiMgA9Kj4YGLdsWnPPw/ASzktTbOFzDI0YXhL+X8STW9HkT3ckGUlggaXUdlA7cqWg== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(199003)(189002)(189998001)(104016003)(107886002)(110136002)(19580395003)(5001960100002)(19580405001)(48376002)(50466002)(33646002)(77096005)(105606002)(50226001)(6806004)(87936001)(2950100001)(106466001)(36756003)(76176999)(85426001)(46102003)(50986999)(92566002)(62966003)(77156002)(86362001)(47776003)(229853001)(2351001)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR03MB1360; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1360; 2:wxMnZNhebcUzfc5qNnO8WSYPNXLQk28xDdm9eXSvf1ZnSMMhcjSVzjs+LJWCNKmj; 2:u+uOZq4oCN2yIXcJh5WGfOHeo/gqlRU7bVLPJtTWK2m7gTsJkU4ZnlFEDmoImnvebOPrduayV5aa+F+3mUeu4VLV3GWblEmxoWgUXmZapHawdTVz1tK0XCoEjvfpFcu3Mf2FwlDlrZDp5sYqYyK/qDNClVd3Gk/BKpHsbP/MZ8NZRZKE9Em444qmgU+X+latN59Su35nQX9ymXL/LhjAfRM8PuIj48IthE5IQBxcSBc=; 6:R21rbWGRrxtYl0ALN5YRpRhZSSnXW8y/q/IYgli9VS5jIk0LkNhvsMBCTggCkroPsrSlhN7JnxtSOxHiH8033s+ll9NB9J/TSrWb2ELf74p5UayqjoS71MS4yt6xnx5el6oPchpioEGTOfLpFt8tzFLzHuY/4rI5hlTvtE0lgrrP4+z0olTIqYdocmahhiJJl8KoId0HNfUpCIk968GuC3gve5NXxNXN9lceKvLy86DqpXCNwWAxZXzDXpRCrTuULudL1i4nW1sl1K1b9VNYk6X83/rtU/uihOP88HW9L0BDjKyiqPDHnBcSjmNadu4kQ+F59aYGdud5K1G44XUgWw==; 3:HiHZd/R16Jd/KY/XVtoE8ugEoQC6viFFjWO4JWFm07sr8dwvs8dhD6TmwPhBgKdLf7jTR+iYzTjJWLdQZxVZcLyzQ3UmNSp9xOe20fY1dm7OK+Vd6FeQnYFi+USHlWzAIQ9dOXzfDHGAFvjXka2/mH+fG9Qb65ESUecaTMncH1TL0+14w5/5kRBCWzaKASajkD61URLOqZ1DwGgmzubPo3xPeV8CioNBqO4VGQf3ZOOJ9FHzAD3KZZNITJCsv0Wo0CbXcGd/PIF4zFPqNB6KP+MoE9B0t583JUR4JitBlrU= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB1360; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:CY1PR03MB1360; BCL:0; PCL:0; RULEID:; SRVR:CY1PR03MB1360; X-Forefront-PRVS: 0576145E86 X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1360; 9:js+9MG0l9xWMPNdXZXSFXWo9VFgserBOKp9R7gmo6JdHmfYW67f8qNw+cAzcrL0rY1s6o9ywtdD7Lre4mHlJ797Nlj97G5A6HUsXg/QErZXsbXVnpasUk/bwoQNvgJJw+ynE0aa83HArW+OkDFjaVwYJX06SqotFZSGq8duciGF4HXwgIXe4GJaymF4ohiA+YnqnG8zIgfCl++mSCsZnGVpgr1Xvt/JVdyNoN4AECXIKPd9CxanGNMmRyOiZ5hcZO2Ax0ZVJ1wgUlxtHYft67+Wh7MUlG3PxvXYXEPmVWuDz2F5XQqe0290NvBItSKueKvKPwK6YL9B5RPnpqwwE+CsCngPhsw+OquLqM4/WWAqr8z0VficRWO4IxMjaGmEDrLXTMfD88CwAvVVkT3nYbdXLG3/g6IWz8+YJI2lx61elONnL+ZygKdrRGO19e4muLXXBA7NqbNkjRONCu1Uz/akm4kMEeuWHxKmu1SqprDK1h0QTUsLqB6pboS+8ky/dWxZt3LmJC/JC3OHlJjnL2pMqn+InKEtyPBig+CId1AyacEm5xUh3IoZ1ZexTJACysaWL5Je5DCe+iLBiVPxLFymqkmCJuuRZMRfvJAwxF5w0UPvsV0x6PYgGhM86LQIBcil+X2nB5JTPzrgzWK+U2mkD8XPxLCxg+/dV8SxudtRHPQAtqX1+ftKxsxlnAgFpG9k5q5DWSrAnrcX4W/5NR28R0r88D/FbkG48z/DrB/iQvnxuQ96S4og765Snc8vPRU9WwGHy3t4wOZ5joIal6Db9TaNM06SeDZntfY41gdIf8BiHQfFNESUGIGh3K46YE6SllWCconfiHum1fxPIeT411a37PnXL1DltNBO7WnTYcn9Oq2xVrfmJX4xz36AI59pi9ytxYwkzCrGgG2VuZQ== X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1360; 3:09m3ABn1H34vWKpYAtXzjtUOaXCrYL2+zY/toXAwaLzy5dE7fo4qR6jhkE7DLlrnU5KFHV3bhVaSD7DNWcdoI/7985MPDE0Z8IWDXOOoA9h255H1NBUIAILhuH3ZWH0k9LLrdPOXD3lptcoSrZwW+Q==; 10:lht4AqcFL5p+RcVPHHpx/kDVx60l27FDMQ5y76nv4VZiKgehsKFljQYV2Xvtk0ZHi/yDU3J+TcmEUkkyB46ZBT+shXgiNIfwzXVmBcbL/bY=; 6:VqeZGvRiIOrfNfnfNzFe72UMMwK59Vn8qW58pxgCl0Hhz2D6Cjp27lcswLXdfdXU X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2015 14:38:11.1392 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB1360 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150514_073835_244147_6CA70A3F X-CRM114-Status: GOOD ( 12.17 ) X-Spam-Score: -0.0 (/) Cc: Ranjani.Vaidyanathan@freescale.com, b20596@freescale.com, mturquette@linaro.org, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, r64343@freescale.com, b20788@freescale.com, shawn.guo@linaro.org, b29396@freescale.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Freescale i.MX7D platform, all clocks operations, including enable/disable, rate change and re-parent, requires its parent clock on. Current clock core can not support it well. This patch adding flag CLK_OPS_PARENT_ON to handle this special case in clock core that enable its parent clock firstly for each operation and disable it later after operation complete. This patch fixes changing clock rate and switch parent while its parent is off. The most special case is for set_parent() operation which requires both parent, including old one and new one, to be enabled at the same time during the operation. Cc: Mike Turquette Cc: Stephen Boyd Signed-off-by: Dong Aisheng --- drivers/clk/clk.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 44a2f55..348f371 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1133,7 +1133,7 @@ static struct clk_core *__clk_set_parent_before(struct clk_core *core, struct clk_core *old_parent = core->parent; /* - * Migrate prepare state between parents and prevent race with + * 1. Migrate prepare state between parents and prevent race with * clk_enable(). * * If the clock is not prepared, then a race with @@ -1148,13 +1148,17 @@ static struct clk_core *__clk_set_parent_before(struct clk_core *core, * hardware and software states. * * See also: Comment for clk_set_parent() below. + * + * 2. enable two parents clock for .set_parent() operation if finding + * flag CLK_OPS_PARENT_ON */ - if (core->prepare_count) { - clk_core_prepare(parent); - flags = clk_enable_lock(); - clk_core_enable(parent); - clk_core_enable(core); - clk_enable_unlock(flags); + if (core->prepare_count || core->flags & CLK_OPS_PARENT_ON) { + clk_core_prepare_enable(parent); + if (core->prepare_count) + clk_core_enable_lock(core); + else + clk_core_prepare_enable(old_parent); + } /* update the clk tree topology */ @@ -1169,18 +1173,16 @@ static void __clk_set_parent_after(struct clk_core *core, struct clk_core *parent, struct clk_core *old_parent) { - unsigned long flags; - /* * Finish the migration of prepare state and undo the changes done * for preventing a race with clk_enable(). */ - if (core->prepare_count) { - flags = clk_enable_lock(); - clk_core_disable(core); - clk_core_disable(old_parent); - clk_enable_unlock(flags); - clk_core_unprepare(old_parent); + if (core->prepare_count || core->flags & CLK_OPS_PARENT_ON) { + clk_core_disable_unprepare(old_parent); + if (core->prepare_count) + clk_core_disable_lock(core); + else + clk_core_disable_unprepare(parent); } } @@ -1419,13 +1421,17 @@ static void clk_change_rate(struct clk_core *core) unsigned long best_parent_rate = 0; bool skip_set_rate = false; struct clk_core *old_parent; + struct clk_core *parent = NULL; old_rate = core->rate; - if (core->new_parent) + if (core->new_parent) { + parent = core->new_parent; best_parent_rate = core->new_parent->rate; - else if (core->parent) + } else if (core->parent) { + parent = core->parent; best_parent_rate = core->parent->rate; + } if (core->new_parent && core->new_parent != core->parent) { old_parent = __clk_set_parent_before(core, core->new_parent); @@ -1446,6 +1452,9 @@ static void clk_change_rate(struct clk_core *core) trace_clk_set_rate(core, core->new_rate); + if (core->flags & CLK_OPS_PARENT_ON) + clk_core_prepare_enable(parent); + if (!skip_set_rate && core->ops->set_rate) core->ops->set_rate(core->hw, core->new_rate, best_parent_rate); @@ -1453,6 +1462,9 @@ static void clk_change_rate(struct clk_core *core) core->rate = clk_recalc(core, best_parent_rate); + if (core->flags & CLK_OPS_PARENT_ON) + clk_core_disable_unprepare(parent); + if (core->notifier_count && old_rate != core->rate) __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate);