From patchwork Sun Oct 27 12:00:07 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: 13852502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B1258D10C1B for ; Sun, 27 Oct 2024 11:53:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To: In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type: Subject:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WECvtFrL6i9TqWUnlboazsCz7Ojc7WJTFHkIjGGXBCM=; b=NEv78L7tTuiJXfD7DSmGe0fZMr kIPuSrNl+ci7gCTLpGq7nc7uA45WhXuOtvIxoCK8Otd23rQ2ooE4QZKeGApdcMn0XG4AstWV4wsuP nIZFd0UGfJK12b+QsRNZlfBd1Q0jcX/YvkHlua6EvzNhQkzvF7tfXfKPXazG4QOjqa0lYpp3uS7BL YmuLXj/MYB3Gv3cteiOp7HadPFKNIFSYJJoxX98X0ERKBVUd53wa9jabRZO2fYyI/q05Y3Yt3t7oW HbfTP4WntqqmW3vIDzAlFMqrkHlpUKaEX2HLnwrgarXwYojc1bN3HjyhqHCQY+5g9kpjNvG1n4Cix qU2ctayw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t51pe-00000008AlP-218e; Sun, 27 Oct 2024 11:53:18 +0000 Received: from mail-vi1eur05on20623.outbound.protection.outlook.com ([2a01:111:f403:2613::623] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t51mY-00000008AKw-1p9K for linux-arm-kernel@lists.infradead.org; Sun, 27 Oct 2024 11:50:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fQfIyI31tbIR2h4PvnWXf2jzWnblITkWffvtm1KKR2vI9oDWtYcQa4FNJQ/h8SdcRXrPjWNdhckGMWLGKj3367+J3ZiovjlbaQrR9Mnm9sSpgX3d5se99v5SVQDRtt4E7m0ad0Lb0/5JuQd23LsOcaL4rj+Q4dRPUCqyjhgTQ7A+i41OHWGS5Sudafr7bBPyAIHurMJFeRIYDEmdgBG3JkJnTZhguIGactvKEDJZa5IMoz64ah7U7JJUYGl5H6K4aXi7F7S+kMNWVMUR7xkKuYksZBSMqgOEeBHoL94jk8EWBQ3yLR0ndHK/RUoK2gnfdHjZlTBc1iZrGJVS1nlkig== 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=WECvtFrL6i9TqWUnlboazsCz7Ojc7WJTFHkIjGGXBCM=; b=XIHNcTlRoDpPr6/H2RKZmJuundhwLGE06gXt5kJbZVjcAFVZWY/fD3tAp9BSYemp9okGxWW3+lqfjzUNnfhc4HXf+w7eqj2tr/n2yU1z66nH5IGWE3/5urdG2mcEMfuND+kY9+rFiDORAPRrYz+mUqvxvhDT2MiTPjcLixxCjZijt7Geh/3W8NKj+BrJUPE+QVTiw2jFeLhjO/kWmnT81fyphmRpPR0hWacUU5IJqx0src4bNPzcG5lRQlgg9AQ+p09Uc2woAQFZgzgLN6/m2MYsyCru/lL7t4oXqP3xYKu5S+z9CYyvqjT7fzvKpuxNOIp3/S0CLjcJ5rOxjGjfgg== 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=WECvtFrL6i9TqWUnlboazsCz7Ojc7WJTFHkIjGGXBCM=; b=M9j3EllYFA2ryRC7kGReTtCHN7DEPMA86bEq2jw+sA2q7NW6JJZ0LNRDrm0rkvcWl9liJ/w3xw71ST+no96TONE1MMmjJl94TvGuZPLohHZQpcOG1Hccz3rUsQNBfzl/Koj6NIwYzou2x/DMr/+4v6SfXO2upIk5v5mr+r0dtdZtznS5Pue1ZNE3tujXc1WMlP3Yw6EhGeLEK1i2YOQKNdzS9ZWL1tJTIp3qytOfOwwM769RaLPAsZc3wJ5LCUmeF7oMVLBqICih/SkoXuQ01uBTKicI9mTLsaTswgdBm2GXUAVABCDYz0rbExtdalTJA7YtUf55rLoVWtZ5BuH8UQ== 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 AS8PR04MB8689.eurprd04.prod.outlook.com (2603:10a6:20b:428::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Sun, 27 Oct 2024 11:50: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%5]) with mapi id 15.20.8069.016; Sun, 27 Oct 2024 11:50:02 +0000 From: "Peng Fan (OSS)" Date: Sun, 27 Oct 2024 20:00:07 +0800 Subject: [PATCH v3 1/5] clk: imx: lpcg-scu: SW workaround for errata (e10858) Message-Id: <20241027-imx-clk-v1-v3-1-89152574d1d7@nxp.com> References: <20241027-imx-clk-v1-v3-0-89152574d1d7@nxp.com> In-Reply-To: <20241027-imx-clk-v1-v3-0-89152574d1d7@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, Abel Vesa , Peng Fan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730030419; l=3213; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=aeiGOFthGwsWpWxLMDzbGyOzHOzdaByvU+6qeurmvKg=; b=pw7m5MOW0uwLila30EbATDQCOC2ob55BW8uO/+dR89JpBKRdRawoiPz6suMqO9tJRGhf9Q2QI R9aIO/q1+o7DFU/L1BTJDNJwde1sovQt0emNa2dF3GdMiWGG4aI3VMH X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2P153CA0011.APCP153.PROD.OUTLOOK.COM (2603:1096::21) To DB9PR04MB8461.eurprd04.prod.outlook.com (2603:10a6:10:2cf::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR04MB8461:EE_|AS8PR04MB8689:EE_ X-MS-Office365-Filtering-Correlation-Id: 5edc3ae5-c936-45df-0d52-08dcf67d7dcc 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|52116014|7416014|1800799024|366016|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?XTlb7ywTnHqJbG4CQN+rLPqo5DJNVcI?= =?utf-8?q?IIDRgZPs802ayrLzxXduX2qgnCk0djk3Qhr+/KRLWbt64t1nUQnjPUMZP7FqTDpxK?= =?utf-8?q?KQiRaTOd9ifeUoBhN9am0NBR8vrQCSUpYPUaGwr4ljKGfrxdrzR76TGjwfOZxW60d?= =?utf-8?q?DTmrdplOYtNzbHNTaCmdtCkKUCvxFXbFRBH8YopmyCcKsZ5Uib8TO6ldfM2afGL4F?= =?utf-8?q?wyfqjaI9xeJhfb7do3QtobvH1MoRNalMgG2Vj9DmboQbOcD+QsyK8RgYGYSfrllMC?= =?utf-8?q?YIKL7KHVY4yf1lh9jEf7VMifnsDtJd0Gm+XG7vqIcErJIZElej7962UwIPQlkN4QU?= =?utf-8?q?m9NLO4fd9Pz8W/M6/5RWjeIqnC19gqNNsIGRIr0+kmNXYaV60aYvbMsqjUOMq+zc/?= =?utf-8?q?65HVfYxmM3OJkDYPxaQE/b8pxKMWuFFxaDXNVmjbBdrcfQ/IsgEWPEU78igDCgMtV?= =?utf-8?q?sISPWX6Occ9sF5QN3vkQK/HVcMVF/kCfkD3+SBELw14z5MqAn38P0EhuKXYoo0X7P?= =?utf-8?q?YIc6FnSH+0kdZ1hqZXFY/Zb1DNm9/8K04dOymABnXglXZu+n1C0rDqowH6ypcyDrK?= =?utf-8?q?uEZPRByqCN1zMp9Pba+AjV+654US8i6T47giyoYH8cpwbP5Os4LIoMgMVgC3uA9du?= =?utf-8?q?0RBqEOS5z2QO/5VdVyUxyDynfrR0WuT6fMFKKqlBo4z/aIU3Ld3zUrgIXI7jMrhs0?= =?utf-8?q?5gwMKq+w3JgQXRHSy8OlfsusLja0dc1ChV3/KcSSL5F7//OaeRIzXRZhvJvmhYms/?= =?utf-8?q?oASoIpOT4EY2YHkmxZcj3LKIP/q2XjWC+hvMcr9JZZ6Smn6DV3i8ReUr+qOTcuVlB?= =?utf-8?q?fHtACx14D37R9gmVDZjCFKOgADPYYes7ZMvaPrr3HRwT5k23QyeZBf8sUGtU7GgRe?= =?utf-8?q?xL4PCRHWqVEKi4DFpHw2FRPEWJhvQDn544ZYKG6NHMqbaPWgUHMswS97h1TtcIfo1?= =?utf-8?q?sxE2fnzap1/+PRrQzgoNLLqqCY0U9a8zOh2+4U1r6fvU8VOfL/gNEUfo2u8gceJYO?= =?utf-8?q?qb7okPqLbV62q6uKBgpK2zyQvxpfLPEEunheJs9b+oJFZbuIUUCIjZRF49E34ZnZK?= =?utf-8?q?qMOev4VO4AHRUketjVVVIDFAuYlKEynLyq2Mw9pRQAddkjUPXDKAmS58JfyMm0XoF?= =?utf-8?q?Qq+Vj/2KdQp0R8r55x/UilcBe0nXy2s1q1i4pF8y5ndT6EvZhsKOzJEyF2G1unIP5?= =?utf-8?q?Lqohrv1wJ8g3q6l3bW+8iYI39rvxT2o+nThRsNn819SK8D+sdZVS/SbKJ/CRXMl9t?= =?utf-8?q?VGO5twZT1cQUD?= 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)(52116014)(7416014)(1800799024)(366016)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?6qPhfoKKQZml8SqdeGXiMMZzWVJR?= =?utf-8?q?Tc5OR+JjZPDqqM3j9e/r9zup7ceExKhKqNWeBRbS/7S6zKB4DpAqYZmWOH1GMZfPs?= =?utf-8?q?ISfV8WbZjX5eTa2Grmx2baKwT2RgzUo9Exm5eXlvUq+o7EEQQjgHfpM/REtOPJH/M?= =?utf-8?q?VD6viJ+FG0eAxuzWOZODLUYRBnlNXd+w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87lMtt3lGm8ShHY8/el7+tobcuAHR9b?= =?utf-8?q?MO/JaobESHGinq94YZ2ZDsJ/39xTuCtVE0gm3x2JymIdoPMEfzeXVHQH3Uu/zoh7U?= =?utf-8?q?xYiO9zoXbArUW+utl36FmzL/O46sTu3E8yg+lhydKF8T6gaQZ+awI+V6b7mAV0o43?= =?utf-8?q?VxFa2ntJnu9zaeUh/zqJnVuTwINfsKnMaJjQLGf4qFDJbD0kwcU9J7bRu5X67jAVa?= =?utf-8?q?73ihSfBWa9wyL5t2lsSAcDW8+LctU14qUEEMWpmQaCenKMq/HfQSSQzfSsBZCw3xS?= =?utf-8?q?Syn2mLqwojojl/uWJdb0kUWCOMRXH6smFKAMEKpm+Wtn2eWGgkJPz1CErDwfBmLFw?= =?utf-8?q?UyIbXAu5/h93ALXyqpUDUw3MqJyrkC5L77Yc9PkotyeMSS+1UTCm7zd3HjIi/6Eek?= =?utf-8?q?LSnbporaDMP+K2iMkwk6W2PSYUQlMK9uXLvOBGUnhe2OIElug1f6UZbXOeHJgyUdP?= =?utf-8?q?+osTDrs6lNoZ?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5edc3ae5-c936-45df-0d52-08dcf67d7dcc X-MS-Exchange-CrossTenant-AuthSource: DB9PR04MB8461.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2024 11:50:02.2554 (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: 20iqOMZO8yp2NpUobal8ACgcrWJZLG088iEMr6zuWYa4Lid4p2hYyLhbcc1fgzSy9KIg4V9OdfyNboOJxzKWpg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8689 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241027_045006_522929_681ECDAE X-CRM114-Status: GOOD ( 16.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Peng Fan Back-to-back LPCG writes can be ignored by the LPCG register due to a HW bug. The writes need to be separated by at least 4 cycles of the gated clock. See https://www.nxp.com.cn/docs/en/errata/IMX8_1N94W.pdf The workaround is implemented as follows: 1. For clocks running greater than or equal to 24MHz, a read followed by the write will provide sufficient delay. 2. For clocks running below 24MHz, add a delay of 4 clock cylces after the write to the LPCG register. Fixes: 2f77296d3df9 ("clk: imx: add lpcg clock support") Signed-off-by: Peng Fan Reviewed-by: Abel Vesa --- drivers/clk/imx/clk-lpcg-scu.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/clk/imx/clk-lpcg-scu.c b/drivers/clk/imx/clk-lpcg-scu.c index dd5abd09f3e206a5073767561b517d5b3320b28c..620afdf8dc03e9564bb074ca879cf778f7fc6419 100644 --- a/drivers/clk/imx/clk-lpcg-scu.c +++ b/drivers/clk/imx/clk-lpcg-scu.c @@ -6,10 +6,12 @@ #include #include +#include #include #include #include #include +#include #include "clk-scu.h" @@ -41,6 +43,29 @@ struct clk_lpcg_scu { #define to_clk_lpcg_scu(_hw) container_of(_hw, struct clk_lpcg_scu, hw) +/* e10858 -LPCG clock gating register synchronization errata */ +static void lpcg_e10858_writel(unsigned long rate, void __iomem *reg, u32 val) +{ + writel(val, reg); + + if (rate >= 24 * HZ_PER_MHZ || rate == 0) { + /* + * The time taken to access the LPCG registers from the AP core + * through the interconnect is longer than the minimum delay + * of 4 clock cycles required by the errata. + * Adding a readl will provide sufficient delay to prevent + * back-to-back writes. + */ + readl(reg); + } else { + /* + * For clocks running below 24MHz, wait a minimum of + * 4 clock cycles. + */ + ndelay(4 * (DIV_ROUND_UP(1000 * HZ_PER_MHZ, rate))); + } +} + static int clk_lpcg_scu_enable(struct clk_hw *hw) { struct clk_lpcg_scu *clk = to_clk_lpcg_scu(hw); @@ -57,7 +82,8 @@ static int clk_lpcg_scu_enable(struct clk_hw *hw) val |= CLK_GATE_SCU_LPCG_HW_SEL; reg |= val << clk->bit_idx; - writel(reg, clk->reg); + + lpcg_e10858_writel(clk_hw_get_rate(hw), clk->reg, reg); spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags); @@ -74,7 +100,7 @@ static void clk_lpcg_scu_disable(struct clk_hw *hw) reg = readl_relaxed(clk->reg); reg &= ~(CLK_GATE_SCU_LPCG_MASK << clk->bit_idx); - writel(reg, clk->reg); + lpcg_e10858_writel(clk_hw_get_rate(hw), clk->reg, reg); spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags); } @@ -145,13 +171,8 @@ static int __maybe_unused imx_clk_lpcg_scu_resume(struct device *dev) { struct clk_lpcg_scu *clk = dev_get_drvdata(dev); - /* - * FIXME: Sometimes writes don't work unless the CPU issues - * them twice - */ - - writel(clk->state, clk->reg); writel(clk->state, clk->reg); + lpcg_e10858_writel(0, clk->reg, clk->state); dev_dbg(dev, "restore lpcg state 0x%x\n", clk->state); return 0;