From patchwork Fri Oct 18 10:00:58 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: 13841483 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2089.outbound.protection.outlook.com [40.107.241.89]) (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 E874618872A for ; Fri, 18 Oct 2024 09:52:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729245177; cv=fail; b=A90cNflmpDrDrTp2Hq/Q5K1a9canZhiU8u4xDdlmu8CvwiWTB4zucYXffzmq+r9IzzrIoeLG3pM+BHuqLn5T+hawF1Tpq3i6p5UTxeKs+dACMX0DdGaKDmegRZm+oiIqHqNYMpXatQYNgMKoS0lJ6Hgmq3odIBfcgbkxz+FT4Mg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729245177; c=relaxed/simple; bh=YZFP2ut1ozz6BeuzTp96FlzaXbQr4fqELBEGph/16b0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=UgvqD20jYH8QsDN1YVcSAlqXdYKYH0PsTU3uO1LTG+NvBwGJ6uXkJy5JmN1b40noqH8cNwmT1DYyDL3Cd/XeGf7t8NMDm5jy+Eb0LkPJ4AYdpQmAGjjtdIP/pD/9uRT8iJpyJCW4C4b+mHsl/+6bMOBClu7rRzn84+Ta5uE8Etk= 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=HiinE3L8; arc=fail smtp.client-ip=40.107.241.89 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="HiinE3L8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=O+DcYc3Y7wPAHJnCmyaIrNUA65vtUSQS7QhDdR8mZYZmhv+1gMgp71QJD+Z/LLf8SM/WswNhrlTtXHIARST+P/2YRuh3Z1OZv1WHJa9xFiMWXjrrsyrs1wsFXrDhbDqD/AXWfanPDxwMycMxGdOMyd5NrhVJhUVdUXntWxMcVwi7XMEHa1qudrAFxT3VwdeWAYv0Ba7s9lm0wUN++G0J5n2qEh5utkl/aaSbYbHKEQePmakf4DmnJ+rz8EBi0Hr+y89mDxO63nOzYL3Jj4dumPpY/lRLdRcZwVAe3+NBcoYhDgi1zK1U5qlIEcsa7ma77zo8quRf9ZRrpY+Ncfkn/w== 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=B+kcPrphzLGA7BGzbN1UZPB/S9IXEYPjoakvnz0Egv0=; b=XL9KuMBL8IQsy8nNkOYBiZ49tp2ytk0jY1ghIqqy0u5v0Wk5i0GHgAa9gwjrEFxIDH39Akx8QZX6YoyqHEUK0yw4Lpueknv1CtiNVVlklLym++af8CWAhVpxSX1ABtHOITco38r/b1LYniiI0uM5N1g8aXGmKlyQJsl5nQrFWBS/IyBtJjxZpl9FBFjrQ9wgeNti/NKXfL6y5Vb8N+R751/WillIGo/lvL3U/PmEty77uLbH6PB29HfCeIcaAQ8Bvs6XzYtkQzmPO72GbmUmRsiSq/w8MA0Ts6rxPBGdrYkC9s0UTksYLFmTllYRZmpdGzh/YW0KznJCm1uwwO8yNg== 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=B+kcPrphzLGA7BGzbN1UZPB/S9IXEYPjoakvnz0Egv0=; b=HiinE3L8YSDl59ZzScWCpuGOlFuUIg3gQcXFirtcjR5tY1AjPKkPVUUdQFE7qUjtUcuwnVFLFvIMEcy0Rh2jVGptn5n9SHIYrp4Jzi9bd+9G1l7gPNf3epKLmwOGNM/EyAI/OCSTI5BXcPdkVojy0HOxysIqar6mvCDGJVmltP8TIrNiUCB21SedSr4Qat+S0/hqFKYQtJMdCqoyO1K8GNpeYiNpgo3Bg7HD1S95+kWCgjhgWeOyxWBWWd5GVAzIu16UoHVvF/jac0eY3h+BaK8DmUfubLk6GtXjMdISgdE4h/ewVJHffqav/VIAwyXPJu8GuVDgLaQqxpGrAVLAuQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by DBAPR04MB7285.eurprd04.prod.outlook.com (2603:10a6:10:1ac::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.20; Fri, 18 Oct 2024 09:52:49 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%6]) with mapi id 15.20.8069.016; Fri, 18 Oct 2024 09:52:49 +0000 From: "Peng Fan (OSS)" Date: Fri, 18 Oct 2024 18:00:58 +0800 Subject: [PATCH v2 4/4] clk: imx: fracn-gppll: fix pll power up Message-Id: <20241018-imx-clk-v1-v2-4-92c0b66ca970@nxp.com> References: <20241018-imx-clk-v1-v2-0-92c0b66ca970@nxp.com> In-Reply-To: <20241018-imx-clk-v1-v2-0-92c0b66ca970@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=1729245675; l=3036; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=84M7E9SFxBK3SAqAyey+G62IZbKKHtL8RhiilZogEI0=; b=xlHiWobNppTS/0cbCmCuEwUr+/L3eCAQYme3vG5dICODTaDLGrODTHTveR3ajfiDB6IK1yx+4 dMR5jtNcE0bA31D2oR+01venJIBsdiN0oypLD9J9f0rXeZtqzSrHOwR X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR01CA0028.apcprd01.prod.exchangelabs.com (2603:1096:4:192::21) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) 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: PAXPR04MB8459:EE_|DBAPR04MB7285:EE_ X-MS-Office365-Filtering-Correlation-Id: e60789e4-a748-4db4-228c-08dcef5a9d62 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|366016|52116014|7416014|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?/Rbe2xiG9HUfM2f0zP4oGeFE+6v8+dq?= =?utf-8?q?NdtsSsmzhjvVfLn5bskHS1+HvTiH7w0pHCplH2WXQiqaLLwG2mray7CZk8rFOZVWw?= =?utf-8?q?V7ATgDK01OVhvvKs/UY/3RNKSy/msJ6fWyPaGS0NAEdIMukmWf566B0tTbF5VpweM?= =?utf-8?q?7x7edwQ68RUq6Kb1wkrKHOzcAijsBYojzNWCWUJ8zOGcluWqDiGpm8jDPczw6vHyg?= =?utf-8?q?tzs3UQBMv7oF/FY04PB94M+MiTNwPrjoMeO9Hjcr8d6LVtVtVDBffCmSi7DPMzW7t?= =?utf-8?q?csrWv+lBmKtzTMT4QkUcc/mUWWdkxzMrbcLNxGbhuvP1DM1fezhxNd8zSAlIiIfco?= =?utf-8?q?j/iR9+V6K6aY91PSEC0oxrs2guYl8g9SOL977lzqgVKxX79a+sytI5KKsYWcenEOw?= =?utf-8?q?HQDld1wK3ASWCuFVovIZsmKzlGkozNETT4w4aZknjN+EiMfIAbSomfPgqrNxvn8Wo?= =?utf-8?q?Nxyeq/nNLtubHLtFP87VW/WS0gQ/qIYbPFWnUbCSKj4cyxIGpMYSAQcqHXXjaetrG?= =?utf-8?q?bVo+j/3FxEBM4aUkh6cRLPPu08Sko79hlbPC/P8uxeGzno87w5Ig7gKGClmpmeccx?= =?utf-8?q?ZJMqauESk9CHqqnBcHJyCwNRGYP8PzfiiT0BLboUFelP+QvplLAytGnu/TlWkzqpA?= =?utf-8?q?xPWe3oUZiSx2TO7WR/3bkfvcRumTgpjgyDQGEOnMk/91NgcAA/D9TyXs5ATxtWgjY?= =?utf-8?q?UdGx+tgcz6MArnzNOhwDknmKkou71tWP0d7TAn0UCttGGQiwDkGrg9xsuvI3j7P2s?= =?utf-8?q?36WwEBIC1hLJNnRg5ruhYf6VKRnJcQynHjHKmfznJ2ZHHflwTSq5nPhiq98nO1OJq?= =?utf-8?q?jMWqVPHGAWSV+O0jp3/Iv82ey8LV7g8WgFfTtCHaTdmOl96YibRLoEIVnBGpcE46t?= =?utf-8?q?FEQqQgRN6mKarcY6aRMjLfNeYXlWroGMp5dARnhSIlJSHLfEat4G4uhvkl7F3ISl/?= =?utf-8?q?nWC2+8Wey6UDbhgO89aKiyFHEGVIuCYvG4RU0GLhENt2QoP2HuhXjCAH9hCHEu0Z5?= =?utf-8?q?C6wzg+27tAauVnNPjWXt25KKfDhGAQTROqLO+6b0UKMO/6TLr9eW5r9nVME6Sgm4S?= =?utf-8?q?dUlrNJ7RWb7W+XAq+aeQ1nZPbsgkCvf2EQ+Z2xUrkfohexWZ7QjHOtU5j2FGY1y/t?= =?utf-8?q?TOaBZO46dYNWeEvFP3cYvEpCu5lxYZ6lQN2fX542GRs5R323amPhc0gW4y7HI8vTB?= =?utf-8?q?Rwx8RpLf68vAY3UY20u/ZcTMiL+FYzBl4pqGzBuOAC9S/FoV2mf2bmtCg6u7ncrY7?= =?utf-8?q?P/TsNKSZBGilJOb1sVOsYG0a2PcN9vyUW8lSlDBZVBlVdRimFqr+7vGs=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8459.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(52116014)(7416014)(376014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?VRMoO0dEAJ8ocomXppixvJzvfhCo?= =?utf-8?q?lYIgM3vfLCLfRogvxk4w8r4224bBQiEvEYgMwNJP9wN0u0KXyUdlKllVhUKRnGTFF?= =?utf-8?q?mRo+mzBodXnQLe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KXxWsiWBk5T69clHjKuWEflbVgQJXLHUVTw8aZ75UNrlhbOlA?= =?utf-8?q?D8Bm2mNKqlcZwPDSMvjDrzeAL5zGuvE6NuoX8bObBdUyEi8Ungmmq4dW9PPNY7Ixa?= =?utf-8?q?fSf2zC+MRhY4nIseiK/5hK2IJ166FLDZCYTzwuR+NkPNP46BjmniewhQFHbdwoliT?= =?utf-8?q?PwF5c3HQZ8UHsOjchs5LE8t2C1Qx6GF5hDWxlctOT9BYT/zDK7UCtEJehKJCT/Byw?= =?utf-8?q?09TSgKtIsK/QZ+wbv9S3bxxPt2UnX8s1yHfxzj1XfW24meBaLuM5qU6cA2Qk+sNR7?= =?utf-8?q?2GERIekjcF23bMt3Q+Y6NjyJxO5h4jl6KOpb8m1SVoOxRTpquEAKWg4obupC1ozoy?= =?utf-8?q?nM8vEqo4ovIpWNitCjZIuofY0DztAm9kpFqAY6gTGmAWWMeshomeLA2NEDedCbcd6?= =?utf-8?q?PfA3zD1YRPasdZ6XyoZHSC/d9TAssKsp2bpMzKrzgjtjYs17cquXUWQE4OIgZI3AY?= =?utf-8?q?ZR+4A7wJaGvR5wvJ8JfQl2Ny3EEM7xyo3U0DO/0rv23sGHWudqhO2KlvNhG7YTKLe?= =?utf-8?q?+p8icH01jgsW?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e60789e4-a748-4db4-228c-08dcef5a9d62 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2024 09:52:44.7693 (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: IhCTU/4TpMvf0fbmMxCfRwK0VtbIZCNb0aBNZTNPvxy3ZW8OYMv4CdUbKuAMzGUuznCLTLjdKuRk5SUfOwAwAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7285 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 achieve the goal. 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. So use readl after writel_relaxed to fix the issue. Since we are here, to avoid udelay to run before writel_relaxed, use readl 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/clk/imx/clk-fracn-gppll.c b/drivers/clk/imx/clk-fracn-gppll.c index 4749c3e0b7051cf53876664808aa28742f6861f7..85771afd4698ae6a0d8a7e82193301e187049255 100644 --- a/drivers/clk/imx/clk-fracn-gppll.c +++ b/drivers/clk/imx/clk-fracn-gppll.c @@ -254,9 +254,11 @@ 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); + readl(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); + readl(pll->base + PLL_NUMERATOR); } /* Wait for 5us according to fracn mode pll doc */ @@ -265,6 +267,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); + readl(pll->base + PLL_CTRL); /* Wait Lock */ ret = clk_fracn_gppll_wait_lock(pll); @@ -302,6 +305,7 @@ static int clk_fracn_gppll_prepare(struct clk_hw *hw) val |= POWERUP_MASK; writel_relaxed(val, pll->base + PLL_CTRL); + readl(pll->base + PLL_CTRL); ret = clk_fracn_gppll_wait_lock(pll); if (ret)