From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933015AbbENOiV (ORCPT ); Thu, 14 May 2015 10:38:21 -0400 Received: from mail-bn1bon0130.outbound.protection.outlook.com ([157.56.111.130]:3439 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753269AbbENOiO (ORCPT ); Thu, 14 May 2015 10:38:14 -0400 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; From: Dong Aisheng To: CC: , , , , , , , , , 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 Content-Type: text/plain 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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 1.9.1