From patchwork Fri Oct 18 10:00:55 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: 13841488 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2080.outbound.protection.outlook.com [40.107.21.80]) (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 43D6F20100A; Fri, 18 Oct 2024 09:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729245158; cv=fail; b=fJIqEKHwbtPpgHGS077KO9AU6HDe6WQ5Gl/bD9cNTA6+WYD9Yh/PFrseqMbOB42/2zxuhmqf1zKtwhanAF8gP97hrXWs3jmqsGLTdON24NxVDxgeHms/t6In7m4hKy6a7elmrXDT+pmPy4SuyqWs40+TrNvKecs5pGRYmRn4Shw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729245158; c=relaxed/simple; bh=WYkMqcmzSQqssu3iTqvUC9FUZ6QanVNIu6veJiyDpHk=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=sBp2CBsQ3Mb2Gp3bJZLXwdyQj6XoCQKQsiexNhq9xandUV/19xAiheBF5RGP3jr53AnKn0o2gQjjEIDSmbErnCWUQAdEI7/a4B/spj4CCHkFUn8Npv4xoan/Fgv3/mTVNUFo5iPiiZap01OaFEBuGWduHtElGZ1YE7Yoc0fimNs= 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=thqzPscw; arc=fail smtp.client-ip=40.107.21.80 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="thqzPscw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=io5TKuDedAetOXwvKm0oAH/oLTSa5acKAqGG4RRyGRJDnL0d0SIa78IVN+mtB+T1DWWm9ZTVJHltWaYfGX0jBK2v7Yp3oVoXcBFnSvewUsg9+3KcaGy0nPVNjb873bWk4iiThw5V6gyxVfgTggLV52uwUtFwFkmrlUH3Hsxu/KpFNE8aVtIazfpwNDHM67GEW8V2YeTZJhKETZe41413WphexNANor6PNzwQIe2Ij3PlehlchPyiHWkRSsY6jCUih6UMchQqkrjBvFgn+5PHMzrzGsAT7QbGZnjPS1tLWWg+53TNBRo439+TGZoAWdpg3S0z62S1u8HbVtaecy57XA== 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=n45sX0jlW0hUXc+CXKLrG3U7xIQumx5jCDpKYVho75s=; b=reZI6rubg7cBePb7xzp7TEn7/qjDhZKlDHKnW6e3Bjp2DM5GRnB6LWjCFLDlELLN8fJjO2jpJNzqsqRB0uk/JzC+gzeQsNk1z7hlb6IjAiWKyjTh5J6aWf8vg8I6AswTc0NZmJCNyQaRz0zpylPHMGubkILUakddYNjrN0XCR1u06BTaVi4cL/7WKRh5MLTPjPUre6MEVRa5Kdm0GEwgKDPzHVwQagW9Nej7ibVmn7Kt0cSm/d3urDzmvW2PRkmHqPv+PBooHY1EVI9VQTawv4PF3OGOrymOQd3xqNWHAhYlIpqjHFAArF3pigfr9sm1EVW42tkkN7i5wFTqV+BIXw== 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=n45sX0jlW0hUXc+CXKLrG3U7xIQumx5jCDpKYVho75s=; b=thqzPscwV1B4Fh3hW7IfSIlgO+Z4WF2uOJxX+kK5B2AcFQTnWP1QKMk0IM6RZXGP+eU6vNaNaz6csJmYBjvuorHRwVrKnOPGWPCc/LM1x7M844R+hQ30GMyCq+/yXq6RNUBxt+jNY4OuvtMZ0tzXCsSkTEw7F43yF5TtKl9sdyjS6lD/QcZ8EDQCWMb/McISQKc9fhiYFYphDrsAaqEHTZHT5zXrew+MQ2AzwBkn9uy+4ItzVvnj0lO5X9zfIb8P2AHjSdonkEMQeY+wV82CJKhkgymV/Nuf7O51F8F00kR80C1On0xBrauj05ajS5QWjH5a9A/W1CSXbWCSPXTPMg== 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:32 +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:32 +0000 From: "Peng Fan (OSS)" Date: Fri, 18 Oct 2024 18:00:55 +0800 Subject: [PATCH v2 1/4] clk: imx: lpcg-scu: SW workaround for errata (e10858) Message-Id: <20241018-imx-clk-v1-v2-1-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 X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729245675; l=3168; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=5lV6Fnymwi08mNJOqfNiqBqacUaEGvCOefJyeSXwdDg=; b=zldSwAASvzZPp+4QoKIdmyOjLYUE2CgIaCB5H/e+itCHrvZX2WNvv45/rbzX3una65nJkJhP7 SxJMK9swp/RDf3AB1+IxJRCpmiDz0ARmD8gDN1bRNKXlEpkflEubfU7 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: linux-clk@vger.kernel.org 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: d05c2861-10d0-4168-dd45-08dcef5a961c 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?s6tBmlZAmZ/gjZd3rXEGdZkm/3qPh53?= =?utf-8?q?66M3Qboh346j/1dNlcA8tOQfj0HrUrs6PxMBXjpaddkB6T+3a5Y7gZefIyrVW34bV?= =?utf-8?q?q9oQ77qL17IzmZoc88kvSZi03i8lyOgjoAm67lRIksMZD2wDTgnq9y2t4+zERz3RN?= =?utf-8?q?M9oVhfyud3lU0V/qUQjY5MznGCzzIIFVkH05tDTm75ehleohLWroUpboXaExQ/QZJ?= =?utf-8?q?TG+KOfwmpm80cQ6MgBZ7PrdFke811PmSdXGkbXT9Q1CQY6E+9ruy1D/32O7r7RiRg?= =?utf-8?q?4JnGw/FEXiOUZGUcAkCB0OIqC/5m5X8G3oOky87dIUAPl36K8rvD6zpWIvCCuyf6B?= =?utf-8?q?UBBzJzoCX/ClFQiGOBV7EMqe/OnFqU0P6x/ZRDvaJAe2JoVqvqgj0ENvC9Tin8ooE?= =?utf-8?q?paIgRxj7M6pMPf2yyDoF0aOHADqmN1resb9xbjWRfUnRc4MgOQ6uB3IiBdE1RxewS?= =?utf-8?q?FfTZwM7LGRsZhJ9k0GFkFDyzr0qM0I6nr5jJ4RIY1gWicb7YZ9Q5fSMvGxA+ol8MC?= =?utf-8?q?wdNOqE+jI7b0TEUmX+W7rvq9IRjTkiZlIkC3G7Dyk/FkDmcaq4tzyEKPGfLl3QqwX?= =?utf-8?q?Rs94+eNqK3Eb3ECBrD6+woRlFKcqIWuEOpIAD6MOrW20CygiaYyx1gD6HNeCNMOEF?= =?utf-8?q?8gbKP0Z92MXm23hQgTVqpw3zmJ8+1tmtj6z1emn5e18RxawFT9+LJTPsinKSuAgZr?= =?utf-8?q?o9LS20benw4ySBH9irvhCcJDE1DdVgklyip9rJ9tG8h/C2DyF8Kx0/DdKzj7Dcfb5?= =?utf-8?q?yL+rTc5/3vY2BsMutlFb+m2fS9aNTTiSdfKrGAO2F+JYpIvUFXaR9QJjCLcNB32iK?= =?utf-8?q?ZoAImEQAAw9eWjhwGshI6X/cd+6Oab6wDPVfGPfRsgw5BKkj2JW/1Sz6EM6uRbpwz?= =?utf-8?q?bV5l9sEeNTGC3btllf8IXgQ0z1t9Hh0rrKKY67drKNtAIIFtHWQSUaW0obGX2Dykf?= =?utf-8?q?stW3UffFu4wWJJWRLFAPdkpzMajqWjRLngt1Lv3LlZFS+qmWasfIFRUTk50QMx5S5?= =?utf-8?q?4z4SJQys7fsCUYnaSXqr89AtOCM5StZws/RUmeX+cQ48gWsRPi1CsfYXtRJn2+gl0?= =?utf-8?q?wv0AWKGaJlr4q5XPanvIzfX4bYu1ffFw2TKKcC38qP2LF8PwaI6r7K7f5ZsxwS+SE?= =?utf-8?q?FxoRrFRcfYEUDjy5X7fzjTS3uxrWFgSWwKgffQwDwtMbPSgq4SGBkB59nrieQJ/74?= =?utf-8?q?26sdTThL2im7AtyNO9CRe1kLBaH4BpUFp0N5tsAfnisJ4hX7suCcg4+nuGHfi4jv/?= =?utf-8?q?eoGkZxt7v2rN7?= 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?Ttbf1zsYoOOlcz0+FhG0HIiD5dCT?= =?utf-8?q?vmLwX2AaY84KvMn3PjP0GY6LHwixLmScsi6VwwXKAqn8/fhH54e4eT0VSujytk/mi?= =?utf-8?q?z/pscJMGjQOduF3X9dI7HGlSSeZmoL+830pLJ2EAT6/OJ05UnxfrMpftZB3PREHHP?= =?utf-8?q?mB6Sk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8I/KCgyKRpjEjCHgK3pyYWZlYHbzSAWzggfFDjKglbh5erO9y6ta0iozOZpwQos?= =?utf-8?q?SZxKUF0a1TDskvNziyplxGorcuZoN3vbw7nbSQcnpCp+QohHiS5QsGT7KHOnOhdvO?= =?utf-8?q?Rfgs0Bf5k1yaIqFLR7yZVwmGgcd6vkTQaSOIUghoaci3BTiiPnNX2Qu3C22eQOEHG?= =?utf-8?q?nQ1g9XHbXphriqfYyqqayVBLcCqRR0Q/os5vTBmeCr+r/gVX4+2H8d9RSgnjfNg2c?= =?utf-8?q?r1SypEVLM0pvHaW8Vs8RTc+UUzh6muQbB0a0vKz37DuutfQdLRXUrjzQb8VLl5Gbu?= =?utf-8?q?TfYP5AHXEVfVgq1PFUTouRw6WEaCednrQeyBQ85oP9GHkMhb4MwGkF911oFNlzH4M?= =?utf-8?q?04IxMM2YGvjYyia7HjdN5bA3FiZ+tuxxWygLvm+YZ6EsJNo0b7BgNcYiYero2ez8z?= =?utf-8?q?D5M6fQaPvcXHsvsJtkM9kcOaH1v/uIA1ZY8q4Gqtnwkr+zzWeqJ/blAlM3yadEztJ?= =?utf-8?q?Qcz9TfCIh7ak?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d05c2861-10d0-4168-dd45-08dcef5a961c 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:32.5843 (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: BlJNxB6c06PDt+XxCWxMk4Bni+t3v45/nI+hxnTJdrus3UNqvfrwDcz4hEAloQ0a5UfY8IEx0MSc0Sb+sWYVcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7285 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 --- drivers/clk/imx/clk-lpcg-scu.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/clk/imx/clk-lpcg-scu.c b/drivers/clk/imx/clk-lpcg-scu.c index dd5abd09f3e206a5073767561b517d5b3320b28c..cd42190233662c66f2c354f0a2eee3a2531eeb3a 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,31 @@ 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) +{ + u32 reg1; + + 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. + */ + reg1 = 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 +84,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 +102,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); } @@ -149,9 +177,8 @@ static int __maybe_unused imx_clk_lpcg_scu_resume(struct device *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;