From patchwork Tue Jul 28 13:19:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Aisheng X-Patchwork-Id: 6886541 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A2334C05AC for ; Tue, 28 Jul 2015 14:33:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A050A2066F for ; Tue, 28 Jul 2015 14:33:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F49C20666 for ; Tue, 28 Jul 2015 14:33:54 +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 1ZK5vE-0006Sb-8p; Tue, 28 Jul 2015 14:32:00 +0000 Received: from mail-bl2on0143.outbound.protection.outlook.com ([65.55.169.143] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZK5td-0003dc-U2 for linux-arm-kernel@lists.infradead.org; Tue, 28 Jul 2015 14:30:23 +0000 Received: from BY2PR03CA008.namprd03.prod.outlook.com (10.255.93.25) by DM2PR0301MB1216.namprd03.prod.outlook.com (10.160.219.17) with Microsoft SMTP Server (TLS) id 15.1.225.19; Tue, 28 Jul 2015 14:30:00 +0000 Received: from BN1BFFO11FD006.protection.gbl (10.255.93.4) by BY2PR03CA008.outlook.office365.com (10.255.93.25) with Microsoft SMTP Server (TLS) id 15.1.225.19 via Frontend Transport; Tue, 28 Jul 2015 14:29:59 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) 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.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 BN1BFFO11FD006.mail.protection.outlook.com (10.58.144.69) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Tue, 28 Jul 2015 14:29:59 +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 t6SETZDL010845; Tue, 28 Jul 2015 07:29:56 -0700 From: Dong Aisheng To: Subject: [PATCH V3 5/5] clk: core: add CLK_OPS_PARENT_ON flags to support clocks require parent on Date: Tue, 28 Jul 2015 21:19:45 +0800 Message-ID: <1438089585-30103-6-git-send-email-aisheng.dong@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438089585-30103-1-git-send-email-aisheng.dong@freescale.com> References: <1438089585-30103-1-git-send-email-aisheng.dong@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD006; 1:cgpp7y7qXptBgR8IyULYr9IsIJyTxg+Qmrbb6M8kZwFQ1INo9Z8mfmEd6DzYu7WOe8/BVC1eeygTAnGIgDtZMqva1Ji6uk650NN1oE3E3QtCrfHTtF5UHB9D4Vz2MIvl4MwdLKLkkAtHTUfKVE9HA2ISvAeU7RI7NpuIECSJkTJkNVU/qCMAuirOk3JYfp+L3sfxYeCVpqZUq7OFHsrHnM8WkP1219BJqrahpBvBUaiEYPQv3YIEZU7LoQ1LhsR2VwwcnlrY4AV10omiSo5Hm8BqOLJSai0+QcT0KsIdrAp9AIVSKx6M75OAvFqIwWkVq3GTjzQai6LTVo+nBday8A== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(199003)(189002)(110136002)(92566002)(33646002)(107886002)(5001960100002)(2950100001)(36756003)(48376002)(77096005)(19580395003)(189998001)(19580405001)(104016003)(2351001)(86362001)(229853001)(106466001)(50986999)(62966003)(47776003)(85426001)(6806004)(76176999)(87936001)(50226001)(105606002)(77156002)(46102003)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB1216; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1216; 2:5MMRJX9DUT+/DOtwNC8ld+LldlUYbuzH6wLj8FuTZuhOCWXi4jzxcoD5QuXUbbnK4hymiuz8PWS9IEe+pkhegbV1X/TbYSsAnaGLN2Rp2ekDYaxWXG+ES087JWBZTaj4TpMvBKhv5xwfFzWa1C4OS5H7ff/L3xGNkznp1UnxuP4=; 3:S9uGQ61ajzHAlV6KG4Flja1vexc1hQ8PQIHb3Hk2tXlowIZoyREWHfdrFvYCqQPm/razVaKa2rwM0z6rILJDehlgZb6F8Wbh27OgJzmHDdrKxkyQq6wueNbrtw6LNm/voXwvCUNPaqveW3tmWW+GXPFwMIJOxSmpKo1m1tFqtkjoN7pyWQoLewidBcAgEyKDe8VACpO0sDCM5wsmXkvOlZx8/1L+mRHH6iiVFL1Iprs=; 25:vRLUXRpmrNJZnk+6rfghj3bkDZml2VpiSgdGYQgWerOl0Q9fMr6MIVt1bf7mYW/th6v/VMViNsqZBZlf0K/3xS5ey7TPqX/1k5Jd9A2KUBQW78Ts4drrRHozrVTtCIQNKrIu2BU2xR8CWVL4DZr9a07sQCRqvRa2AWlyuEd+b/u+hbmfzqZPwvieXVIKR0i+nDk9SosOLwLTK1pax485JHzGJS7o7O0W3ybf1198btyl1zvFUFRN/pl+xbz82Dcn3/UWiF0lTGmns7UoefgAoQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1216; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1216; 20:ZlyY0FFl63Usvd7SUktC8inzgT8I6/cA6ba6FF4hX4GGYTOBlrnTP0m81WjCh8TjplSByRKu79kCvACodPIRH4z3wM6b8GceLreV+mhuKuKYsCmlNG8xA8LIx62z0NBHYvfY+BE64eMHYGmA66aUx++RhRSNJpN3G5LW6b15iadrVcQszlgsStUfmVmPcsPkQJV/KBLevZod/FnLFwcBbnadhhkvIm9nCSqJ30/xd3/GpeXfScYdJ6fzS7E3pM5H2gEGuH2bdrxFkVDb9fu2t0MgjpnSgDIrrSxA4F6Vx6EOoZxWP1MZ5BYxrDT4A9nZgnBhgu7kvdtKK6LHoSWhN2EiCnQ8B1qWhluHjC1jCkY=; 4:8+07zYl7Kob5rhIMnutMxwkfIB+J6sC+GhgwWB8sTQ54o3Rb6uxS5NN+VK0M6QIt90ULPrgzXAESFbQ7lC7+jStN2/odFJlbNbzExgPwFZHTltEi+Zj24A/m8gSdlRUGTWYKa6s8fwW7CSIzhxk+hnA3D53Ifeitr2wSCOY8UUpJaYzSrgLCZzIP55UglK5frLTmNxu1WJcYugmhm3gnWWugzzLH0dyQOGnyR8xcZClrRjzEaCDsORKJSzFSfgvYj5yg04jDI0cXg5U/FsEUrA6zexcYwOGGnFIN/cyzu18= DM2PR0301MB1216: X-MS-Exchange-Organization-RulesExecuted 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:DM2PR0301MB1216; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1216; X-Forefront-PRVS: 06515DA04B X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB1216; 23:R8KZNjIdk2rggkH5ndE7ip0FEKtVOzmUQBwtKFweUGNY8qL0Cu6oMTy/sHrVs3lKmSTA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cj68mwV3jGMXM3GrcVtdsSidpaZ5CmWdnaEFeo+3wVGqqgHesGy2Sz5bwOyc=; 20:XuVsHnp5NgvVmC1XDslrMnSQwuPsSoYfVvYtuqA1puZMR8B6LQwWO+NZ62J4GVYlim2dKTllKV3CHwB9oTnUoQ== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2015 14:29:59.7263 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1216 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150728_073022_321314_B0FAC586 X-CRM114-Status: GOOD ( 22.53 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ranjani.Vaidyanathan@freescale.com, b20596@freescale.com, mturquette@linaro.org, shawnguo@kernel.org, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, r64343@freescale.com, b20788@freescale.com, b29396@freescale.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 cf31dc4..93eb9e3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1159,7 +1159,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 @@ -1174,13 +1174,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 */ @@ -1195,18 +1199,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); } } @@ -1453,13 +1455,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); @@ -1480,6 +1486,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); @@ -1487,6 +1496,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);