From: Jiawen Liu <liu1298662399@gmail.com>
To: Russell King <linux@armlinux.org.uk>, Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Abel Vesa <abelvesa@kernel.org>, Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>, Peng Fan <peng.fan@nxp.com>,
linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev,
linux-clk@vger.kernel.org
Subject: [PATCH] clk: imx: Check the i.MX51 IIM clock before reading the revision
Date: Sun, 29 Nov 2026 19:25:33 +0000 [thread overview]
Message-ID: <179598033589.2.9243721461155150068.pattern-ext-063.5@gmail.com> (raw)
During i.MX51 device-tree boot, mx51_clocks_init() enables the IIM
clock to read the silicon revision. If IIM gate registration fails,
clk_prepare() dereferences the error pointer and can fault during boot.
If preparing or enabling a valid clock fails, the code still reads the
IIM register and releases a clock reference it never acquired.
Check the clock handle and cache the revision only after a successful
enable. Release the clock after the read. On clock failure, leave the
revision unknown and continue CCM and UART initialization. Make the late
NEON fixup use the cached revision and disable NEON when the revision
is unknown.
Verification included source and
ARM object inspection, targeted ARM builds with CONFIG_NEON enabled
and disabled, git diff --check, and checkpatch. Runtime and hardware
reproduction were not performed.
Fixes: b8d4176fa59e ("ARM i.MX5: implement clocks using common clock framework")
Signed-off-by: Jiawen Liu <liu1298662399@gmail.com>
---
arch/arm/mach-imx/cpu-imx5.c | 41 ++++++++++++++++++++++++++----------
drivers/clk/imx/clk-imx5.c | 3 +--
include/soc/imx/revision.h | 3 +++
3 files changed, 34 insertions(+), 13 deletions(-)
diff --git a/arch/arm/mach-imx/cpu-imx5.c b/arch/arm/mach-imx/cpu-imx5.c
index a67c89bf155dd..a7c48e3e4e7f2 100644
--- a/arch/arm/mach-imx/cpu-imx5.c
+++ b/arch/arm/mach-imx/cpu-imx5.c
@@ -5,6 +5,8 @@
* This file contains the CPU initialization code.
*/
+#include <linux/clk.h>
+#include <linux/err.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/init.h>
@@ -16,7 +18,8 @@
#include "hardware.h"
#include "common.h"
-static int mx5_cpu_rev = -1;
+static int mx51_cpu_rev = IMX_CHIP_REVISION_UNKNOWN;
+static int mx53_cpu_rev = -1;
#define IIM_SREV 0x24
@@ -58,13 +61,27 @@ static int get_mx51_srev(void)
*/
int mx51_revision(void)
{
- if (mx5_cpu_rev == -1)
- mx5_cpu_rev = get_mx51_srev();
-
- return mx5_cpu_rev;
+ return mx51_cpu_rev;
}
EXPORT_SYMBOL(mx51_revision);
+void __init mx51_revision_init(struct clk *iim_clk)
+{
+ int ret;
+
+ if (IS_ERR(iim_clk))
+ return;
+
+ ret = clk_prepare_enable(iim_clk);
+ if (ret) {
+ pr_err("i.MX51: failed to enable IIM clock: %d\n", ret);
+ return;
+ }
+
+ mx51_cpu_rev = get_mx51_srev();
+ clk_disable_unprepare(iim_clk);
+}
+
#ifdef CONFIG_NEON
/*
@@ -74,10 +91,12 @@ EXPORT_SYMBOL(mx51_revision);
*/
int __init mx51_neon_fixup(void)
{
- if (mx51_revision() < IMX_CHIP_REVISION_3_0 &&
- (elf_hwcap & HWCAP_NEON)) {
+ int rev = mx51_revision();
+
+ if ((rev == IMX_CHIP_REVISION_UNKNOWN || rev < IMX_CHIP_REVISION_3_0) &&
+ (elf_hwcap & HWCAP_NEON)) {
elf_hwcap &= ~HWCAP_NEON;
- pr_info("Turning off NEON support, detected broken NEON implementation\n");
+ pr_info("Turning off NEON support on i.MX51\n");
}
return 0;
}
@@ -106,10 +125,10 @@ static int get_mx53_srev(void)
*/
int mx53_revision(void)
{
- if (mx5_cpu_rev == -1)
- mx5_cpu_rev = get_mx53_srev();
+ if (mx53_cpu_rev == -1)
+ mx53_cpu_rev = get_mx53_srev();
- return mx5_cpu_rev;
+ return mx53_cpu_rev;
}
EXPORT_SYMBOL(mx53_revision);
diff --git a/drivers/clk/imx/clk-imx5.c b/drivers/clk/imx/clk-imx5.c
index 9c5f489b3975d..fa7c4d698bd30 100644
--- a/drivers/clk/imx/clk-imx5.c
+++ b/drivers/clk/imx/clk-imx5.c
@@ -445,9 +445,8 @@ static void __init mx51_clocks_init(struct device_node *np)
clk_set_rate(clk[IMX5_CLK_ESDHC_A_PODF], 166250000);
clk_set_rate(clk[IMX5_CLK_ESDHC_B_PODF], 166250000);
- clk_prepare_enable(clk[IMX5_CLK_IIM_GATE]);
+ mx51_revision_init(clk[IMX5_CLK_IIM_GATE]);
imx_print_silicon_rev("i.MX51", mx51_revision());
- clk_disable_unprepare(clk[IMX5_CLK_IIM_GATE]);
/*
* Reference Manual says: Functionality of CCDR[18] and CLPCR[23] is no
diff --git a/include/soc/imx/revision.h b/include/soc/imx/revision.h
index b122d2fc88812..d92a8f0bbaecf 100644
--- a/include/soc/imx/revision.h
+++ b/include/soc/imx/revision.h
@@ -6,6 +6,8 @@
#ifndef __SOC_IMX_REVISION_H__
#define __SOC_IMX_REVISION_H__
+struct clk;
+
#define IMX_CHIP_REVISION_1_0 0x10
#define IMX_CHIP_REVISION_1_1 0x11
#define IMX_CHIP_REVISION_1_2 0x12
@@ -27,6 +29,7 @@ int mx27_revision(void);
int mx31_revision(void);
int mx35_revision(void);
int mx51_revision(void);
+void mx51_revision_init(struct clk *iim_clk);
int mx53_revision(void);
unsigned int imx_get_soc_revision(void);
--
2.34.1
reply other threads:[~2026-11-29 19:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179598033589.2.9243721461155150068.pattern-ext-063.5@gmail.com \
--to=liu1298662399@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=abelvesa@kernel.org \
--cc=bmasney+clk@redhat.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=jbrunet+clk@baylibre.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=peng.fan@nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox