Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755891AbbG1Opn (ORCPT ); Tue, 28 Jul 2015 10:45:43 -0400 Received: from mail-by2on0132.outbound.protection.outlook.com ([207.46.100.132]:39168 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755717AbbG1Oph (ORCPT ); Tue, 28 Jul 2015 10:45:37 -0400 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; From: Dong Aisheng To: CC: , , , , , , , , , 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 Content-Type: text/plain 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/sHrVs3lKmSTAf8WODl83oo765eI6S/SkOim1/pyrtIjxryvuSoFZCYRwEMf3XgVVo0BA76IqH7p/ZLoYddYhSxPc1ef2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mC1XDslrMnSQwuPsSoYfVvYtuqA1puZMR8B6LQwWO+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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4313 Lines: 129 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); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/