From patchwork Mon Oct 14 09:11:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13834419 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2069.outbound.protection.outlook.com [40.107.22.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24EB315575B for ; Mon, 14 Oct 2024 09:03:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896588; cv=fail; b=LvMzaq4dUiE/CnQt6OvQmJoBIOA7p/IHDmZ0iXFZu887gK9UTXIxqnKNWR6RD07AecSIPChArNtGOn6BqOHh7S3t+gi074UrzMe0lPpCw1LBYJh24Z6Y1c/wCCZ3ZC1IxTNqhGVXidx7AmanGh8k4k+2iAP5C+/IHsRl3varlhE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896588; c=relaxed/simple; bh=NMaixJesrwjgxBT4NT5looPIkUt0ihb+TNQ2+BNtgIw=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=lMcoDQo1iaQ4RZjFBMV9RCj0GkF3ihSDgf0/kJwJ8b0eMXi4cSUgQ7s5K5KdeliHVv5wDYz6PGCwwQhMphXebe0kSOBpihXAM4zcxzseK6KhWknGkJKpTRDNPyF+ADajrYIK1u72Aapwvbq1vpSekSfXUXThTAOQ8jrujXdGNJY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=S1KD4wRk; arc=fail smtp.client-ip=40.107.22.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="S1KD4wRk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MMrCnwgRSiwplz/dcLLVYrtVzhyX4m66vvCLXIo+CbK4tKUkHjsAgb7QjEDIy/63/0bqfAKzRjtuE8Z73iBAmJLzu/IF9GhCBPopYFFMmUGlKLu1F2aumS40MK69Yq+GFnkG8yxQRHO1wxyYXnN6whmmjDDpUlLCWNwPXuq6Gvq4DBS8uJ9WodfZ7dGwQNQ0KxEKO3ATUhS8ph6FKvZ7zeS/xWkzVy3k3vZp48Ik7SBmgJV0bQzclVZFuqGxvNOAUljWX5njzy2YCYuyan3pwpTMHQJQPfyxZXWziv37VhhhYLesWF7G3HA5XDoINhZIJgvpiBNJrY9p4n/TpuUBmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=d2X07okjtdl9vOjnNmLbOm2lrZztvIEIJlDlOPNZ4ds=; b=rlpJ2HLOeS/KFRIKjxm7QtrtuwiCJrkMsWseds+d9aa1GFaEJFFxMk7yoaAwW+G4SK4jCQDVX8h0zFPine4NMRGPID7nsmqFfQ1d68TDFSur4ki3pLsjX6FbIUPX/oih8ab2lBmyJSA5IVML/KnMxzfNR0eIheSQg0YsxPpUgNjguS68StOg9c86Id/9K/++otYOj+pAq9/ZpjymhG7nwXOZaHD6ZzrZyVowZL83Xf6WbvtDHiZsJBRoch9Yy694ow1BseDHuG4jhaNFt12FVXhCNkmoFIqCiw3ib4wfZAfLUbR1HiA2PayHblShPxsuYuCLos4W11L91RsEhvlkOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d2X07okjtdl9vOjnNmLbOm2lrZztvIEIJlDlOPNZ4ds=; b=S1KD4wRkDU6UTXdvnfJrWWbNWneNvOuDZBLmdO5R8jFiNiXaaSmtKi2qpk0hyC/PMWPs/B3mcQqw/zwxJwilrzdx5bTv4v9FtBtfWm0u2BVGAMsC5unNiOlprmVonEWyXYnzWwxhPWg7/HTsPq50NFc1DIylGb7oHodwsYs7UIditm0R0wf7F6Cp31isFE5REAu35t51T4t96JwcElHjL1K4bcueAyev91PCNXx9ANmMPqWcDnbniLpLU+k3xFR08jeXRHG3/57yfNqbfDJpOZ8DWInPTYyPwvfDCVKkwmnlDSQ7Dx7caCSewT+HWYS4rb0WEYv51ev2G2v2YFNsNg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DB9PR04MB8461.eurprd04.prod.outlook.com (2603:10a6:10:2cf::20) by AM9PR04MB8292.eurprd04.prod.outlook.com (2603:10a6:20b:3ef::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.26; Mon, 14 Oct 2024 09:03:02 +0000 Received: from DB9PR04MB8461.eurprd04.prod.outlook.com ([fe80::b1b9:faa9:901b:c197]) by DB9PR04MB8461.eurprd04.prod.outlook.com ([fe80::b1b9:faa9:901b:c197%3]) with mapi id 15.20.8048.020; Mon, 14 Oct 2024 09:03:02 +0000 From: "Peng Fan (OSS)" Date: Mon, 14 Oct 2024 17:11:25 +0800 Subject: [PATCH 4/4] clk: imx: fracn-gppll: fix pll power up Message-Id: <20241014-imx-clk-v1-v1-4-ee75876d3102@nxp.com> References: <20241014-imx-clk-v1-v1-0-ee75876d3102@nxp.com> In-Reply-To: <20241014-imx-clk-v1-v1-0-ee75876d3102@nxp.com> To: Abel Vesa , Michael Turquette , Stephen Boyd , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Aisheng Dong Cc: linux-clk@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Peng Fan , Jacky Bai X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728897092; l=3465; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=0FRtVJRoldZWhrjsnYMTTv4H4lNFEH+cZfZjwCflnCg=; b=8NTWCY5GXXjje1CkaoW6y/mFO1bx+tz2QgAgzl7GsiW3xX6ovzrYy+mMu0oUsXnSMEZ/O29R6 YrXBlhmXuYKA3h+FU2nsAxCb4vuPpegjyLNUzG6wGlbJXiHAL6msu32 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI1PR02CA0019.apcprd02.prod.outlook.com (2603:1096:4:1f4::15) To DB9PR04MB8461.eurprd04.prod.outlook.com (2603:10a6:10:2cf::20) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR04MB8461:EE_|AM9PR04MB8292:EE_ X-MS-Office365-Filtering-Correlation-Id: 406ee9bb-5e03-440e-920b-08dcec2f01dc X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?ZP5NLjJJh9gdbOMcUg0DnAvTGZ64isD?= =?utf-8?q?9o0b2vxuKns5XER1hYA2cfKZy5OIsd5bLAYBFICYZFmKEdPc7JbGy+JmGxuZwC9YG?= =?utf-8?q?HZ7TL36dwi/GSmnKubFoowKjwkuMDVVjSPxux/R+EV0b/kIPC8r1eYiuxRYrjXqgb?= =?utf-8?q?7uRPnPaJTB2WtEYuKosJ48wz2XcYlbvf8FkZvOuvLMJe9Vb95rLcZT+IaOKX3ukcj?= =?utf-8?q?ceDtZI/+RUDisTHiB6kKYdRZKqC8yY9cfg69HeUEJHFwv74BV2CMe3FFvxV4FHjC3?= =?utf-8?q?OdytVSaO9uMnErmmsQh+DYKkq8HmzJPPhYAcjNWGrrsZSsiUZXYlQ4fhH0a5CeNGp?= =?utf-8?q?VQE9Rl9SDicfi8bRYwviqIKxTtAsjmNKtpaVIzlBhCftQ/AzanZrr/8POYqsTU5MD?= =?utf-8?q?g9ZyoBy0RqGCgweNSoYd9DhaONMBjciYeJnHpdL3Kr3Kil1nf2Zkse0QHluxifhcB?= =?utf-8?q?sPYfX6YTj3J5wgMH/jfEhMdUNDTAYjQY7odbj7gVUvvz+QlZV0YkFaVZI0yt67E9s?= =?utf-8?q?jpEs/LpygAE/z7tvyUkqHRFXx0t7WFvGeZxSkaxUErwCWwZuQLixnTK/Rh3j7JhF3?= =?utf-8?q?FdI2V4gZq6pzDCwd5pmz2Iku/R9Cs+MZNbBj6uXdOOYHYCpAJvyGmR7fzo0vlw55F?= =?utf-8?q?oGZqC0sy1GJxSQNkbOai+nO1OEIi9s8lEyAOe+sqil9sGRINiMcdZNc8XVYDT5f3H?= =?utf-8?q?dEV6O8xVJByR0fX8ukveMfLNTUAihdiJ8Al651OyzF3XmR9B+9Q4l9ea+iGSk4UAg?= =?utf-8?q?t6fStZ/Se3NKtftQzAunH1bQTAxVI8h75p9qPGdbaQtblWO9Lhvtqpll98eEPAEvk?= =?utf-8?q?NxvNIyVfyDDmq+wozmiRgwlMqLrShBNYW0Sodbndfck830q1BoDqAWcYwIxqnFziI?= =?utf-8?q?IUDTV+qPXQK1thNqIBU/jT8ajOlRHsW8XhFiUaoPwTt4hEo6bt9rcf4A99tzu2ZeQ?= =?utf-8?q?Cc0VRe9YCgKt55ynYQWGnUgEd5v88afV9rq7VlklnxikK7quessqvMPM8LoebabUy?= =?utf-8?q?hoBdSj1gyCo7xBLbLY/TB+vTi7g649IG/9f9r29ezA9fTZCH8dm+bHeLKuWwRvsPm?= =?utf-8?q?ISdjAsHflFpolMK/+zrZfElXtR6PmYfbV81bYqPBgdvDP9Gq1PS3Shm9+7Hol8L95?= =?utf-8?q?wo7uiIe90x5TzeHyZpbQ742BMN/WNTCT2B8Kws+4Ri2Ti1LhSakbcDhqrLwWYLRpQ?= =?utf-8?q?kA/5ByjwEzEmm7ZZVU/kaKhOZzkdKhewRGNEH+x4whyvUzRj/kZW0kAAqVCGUWA2N?= =?utf-8?q?jsG0c0HRWDUUm00g1ESyb01zJ/r3UNHHTWA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR04MB8461.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?EFEP8bFbsNgxJbGfUW5C/KWvR6rO?= =?utf-8?q?QLFV0tHGu8SVaH9/vvXM4M6U4cnuQgFQIYSB1HfQBUG+KBB/qk4BtrDV3MN53qcoH?= =?utf-8?q?9MvtA2HtshEvV3MLpMY+4EyJ3OjJN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OJDXxGoY/XsDx1ksc4FC?= =?utf-8?q?gtaNowuddjmyRCRUq25n2bVp6jipahA38q87HPSMkWy3sZhnipxe4BDABOHSIQ3u1?= =?utf-8?q?M6sacSvhgJFPzUg9f4h5gupHzeXc7qEmEuXft/h9OOt3j3fRz5j7vwu7d5z32jb5O?= =?utf-8?q?wxR7c0X+TgSYpPzy+9PJAR0PD4iMSnFy0s44+S18u9PLMmhbIJHUIavlXwgnPUgpP?= =?utf-8?q?DDs9ogyahdkNe/J9mQPHijdqVJJ3ETd/X45R6omFtWuJOnzwpNqvN290P4UyM4guq?= =?utf-8?q?7h6qTHXrQL7OGH5Cf65WKNgO++G7BcDRbImahWrZvFVQ3A2TiSp7kIrKBCx2jcMRk?= =?utf-8?q?3jU8+rF9j4LdVnJ8uk8ceNZZSPCFon4urxhN23YFkgj9XFNFSm8P51u34AzXP/aBC?= =?utf-8?q?mBN3QpNy7PXg1Xe0ULxv6s6Q7jsHRQs4bsSRwfNg9hO/qBKVQDpIO5l5Eot1gM1CJ?= =?utf-8?q?FryegKfnM7jbN23xPARNpsNhsrMBci41NEZgncbbXwjK0BP0VhLQal6dUtOGgrua6?= =?utf-8?q?CAusqshx85gQ?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 406ee9bb-5e03-440e-920b-08dcec2f01dc X-MS-Exchange-CrossTenant-AuthSource: DB9PR04MB8461.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2024 09:03:01.9321 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ei540PbxXxQN/EWN6gjYUk/jjqlVrkCOc0OgriF+Xo3+dSvh/sUlKUsJbY4yfqlZRtqs1ptY6a+n0wn8wNxiYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8292 From: Peng Fan To i.MX93 which features dual Cortex-A55 cores and DSU, when using writel_relaxed to write value to PLL registers, the value might be buffered. To make sure the value has been written into the hardware, using readl to read back the register could make sure the value written into hardware. current PLL power up flow can be simplified as below: 1. writel_relaxed to set the PLL POWERUP bit; 2. readl_poll_timeout to check the PLL lock bit: a). timeout = ktime_add_us(ktime_get(), timeout_us); b). readl the pll the lock reg; c). check if the pll lock bit ready d). check if timeout But in some corner cases, both the write in step 1 and read in step 2 will be blocked by other bus transaction in the SoC for a long time, saying the value into real hardware is just before step b). That means the timeout counting has begins for quite sometime since step a), but value still not written into real hardware until bus released just at a point before step b). Then there maybe chances that the pll lock bit is not ready when readl done but the timeout happens. readl_poll_timeout will err return due to timeout. To avoid such unexpected failure, read back the reg to make sure the write has been done in HW reg. Introduce fence_write for this purpose. Since we are here, to avoid udelay to run before writel_relaxed, use fence_write before udelay. Fixes: 1b26cb8a77a4 ("clk: imx: support fracn gppll") Co-developed-by: Jacky Bai Signed-off-by: Jacky Bai Signed-off-by: Peng Fan --- drivers/clk/imx/clk-fracn-gppll.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/clk/imx/clk-fracn-gppll.c b/drivers/clk/imx/clk-fracn-gppll.c index 4749c3e0b7051cf53876664808aa28742f6861f7..6a4b3745d3d9aa1b583c9bd390c884bcb689e4c7 100644 --- a/drivers/clk/imx/clk-fracn-gppll.c +++ b/drivers/clk/imx/clk-fracn-gppll.c @@ -63,6 +63,12 @@ .odiv = (_odiv), \ } +#define fence_write(val, reg) \ + do { \ + writel_relaxed(val, reg); \ + readl(reg); \ + } while (0) + struct clk_fracn_gppll { struct clk_hw hw; void __iomem *base; @@ -253,10 +259,10 @@ static int clk_fracn_gppll_set_rate(struct clk_hw *hw, unsigned long drate, pll_div = FIELD_PREP(PLL_RDIV_MASK, rate->rdiv) | rate->odiv | FIELD_PREP(PLL_MFI_MASK, rate->mfi); - writel_relaxed(pll_div, pll->base + PLL_DIV); + fence_write(pll_div, pll->base + PLL_DIV); if (pll->flags & CLK_FRACN_GPPLL_FRACN) { writel_relaxed(rate->mfd, pll->base + PLL_DENOMINATOR); - writel_relaxed(FIELD_PREP(PLL_MFN_MASK, rate->mfn), pll->base + PLL_NUMERATOR); + fence_write(FIELD_PREP(PLL_MFN_MASK, rate->mfn), pll->base + PLL_NUMERATOR); } /* Wait for 5us according to fracn mode pll doc */ @@ -264,7 +270,7 @@ static int clk_fracn_gppll_set_rate(struct clk_hw *hw, unsigned long drate, /* Enable Powerup */ tmp |= POWERUP_MASK; - writel_relaxed(tmp, pll->base + PLL_CTRL); + fence_write(tmp, pll->base + PLL_CTRL); /* Wait Lock */ ret = clk_fracn_gppll_wait_lock(pll); @@ -301,7 +307,7 @@ static int clk_fracn_gppll_prepare(struct clk_hw *hw) writel_relaxed(val, pll->base + PLL_CTRL); val |= POWERUP_MASK; - writel_relaxed(val, pll->base + PLL_CTRL); + fence_write(val, pll->base + PLL_CTRL); ret = clk_fracn_gppll_wait_lock(pll); if (ret)