[PATCH 2/2] ARM: i.MX7: don't hardcode UART1 in imx7_early_setup_uart_clock

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Oct 17 00:07:02 PDT 2022


imx7_early_setup_uart_clock() has a very generic sounding name, but so
far only set up clocks for UART1. This can lead board code authors
astray that intend to user a different UART for DEBUG_LL.

This issue affects board code for kamstrup-mx7-concentrator, meerkat96
and zii-imx7d-dev, which use UART4, UART6 and UART2 respectively.

As I don't have this boards available to test and clock changes may have
adverse effect elsewhere, we have all existing users setup UART1 as
before, but note with a comment that this may not be the original
author's intention.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/boards/ac-sxb/lowlevel.c                |  2 +-
 arch/arm/boards/freescale-mx7-sabresd/lowlevel.c |  2 +-
 .../boards/kamstrup-mx7-concentrator/lowlevel.c  |  3 ++-
 arch/arm/boards/meerkat96/lowlevel.c             |  3 ++-
 arch/arm/boards/zii-imx7d-dev/lowlevel.c         |  3 ++-
 arch/arm/mach-imx/include/mach/imx7-ccm-regs.h   | 16 ++++++++++++----
 6 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/arch/arm/boards/ac-sxb/lowlevel.c b/arch/arm/boards/ac-sxb/lowlevel.c
index a910555f9bd7..a26454968304 100644
--- a/arch/arm/boards/ac-sxb/lowlevel.c
+++ b/arch/arm/boards/ac-sxb/lowlevel.c
@@ -93,7 +93,7 @@ extern char __dtb_z_ac_sxb_start[];
 
 static inline void setup_uart(void)
 {
-	imx7_early_setup_uart_clock();
+	imx7_early_setup_uart_clock(1);
 
 	imx7_setup_pad(MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX);
 
diff --git a/arch/arm/boards/freescale-mx7-sabresd/lowlevel.c b/arch/arm/boards/freescale-mx7-sabresd/lowlevel.c
index a8733d62091f..6d393bf2b10e 100644
--- a/arch/arm/boards/freescale-mx7-sabresd/lowlevel.c
+++ b/arch/arm/boards/freescale-mx7-sabresd/lowlevel.c
@@ -17,7 +17,7 @@ extern char __dtb_imx7d_sdb_start[];
 
 static inline void setup_uart(void)
 {
-	imx7_early_setup_uart_clock();
+	imx7_early_setup_uart_clock(1);
 
 	imx7_setup_pad(MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX);
 
diff --git a/arch/arm/boards/kamstrup-mx7-concentrator/lowlevel.c b/arch/arm/boards/kamstrup-mx7-concentrator/lowlevel.c
index 4a9eae80d153..511f01757c46 100644
--- a/arch/arm/boards/kamstrup-mx7-concentrator/lowlevel.c
+++ b/arch/arm/boards/kamstrup-mx7-concentrator/lowlevel.c
@@ -17,7 +17,8 @@ extern char __dtb_z_imx7d_flex_concentrator_mfg_start[];
 
 static inline void setup_uart(void)
 {
-	imx7_early_setup_uart_clock();
+	/* FIXME: Below UART4 is muxed, not UART1 */
+	imx7_early_setup_uart_clock(1);
 
 	imx7_setup_pad(MX7D_PAD_SAI2_TX_BCLK__UART4_DCE_TX);
 
diff --git a/arch/arm/boards/meerkat96/lowlevel.c b/arch/arm/boards/meerkat96/lowlevel.c
index 1c9baeacfb2a..e65726ef1c27 100644
--- a/arch/arm/boards/meerkat96/lowlevel.c
+++ b/arch/arm/boards/meerkat96/lowlevel.c
@@ -14,7 +14,8 @@ extern char __dtb_z_imx7d_meerkat96_start[];
 
 static void setup_uart(void)
 {
-	imx7_early_setup_uart_clock();
+	/* FIXME: Below UART6 is muxed, not UART1 */
+	imx7_early_setup_uart_clock(1);
 	imx7_setup_pad(MX7D_PAD_SD1_WP__UART6_DCE_TX);
 	imx7_uart_setup_ll();
 	putc_ll('>');
diff --git a/arch/arm/boards/zii-imx7d-dev/lowlevel.c b/arch/arm/boards/zii-imx7d-dev/lowlevel.c
index 7579a2a8a050..0e316b602436 100644
--- a/arch/arm/boards/zii-imx7d-dev/lowlevel.c
+++ b/arch/arm/boards/zii-imx7d-dev/lowlevel.c
@@ -23,7 +23,8 @@ extern char __dtb_z_imx7d_zii_rmu2_start[];
 
 static inline void setup_uart(void)
 {
-	imx7_early_setup_uart_clock();
+	/* FIXME: Below UART2 is muxed, not UART1 */
+	imx7_early_setup_uart_clock(1);
 
 	imx7_setup_pad(MX7D_PAD_UART2_TX_DATA__UART2_DCE_TX);
 
diff --git a/arch/arm/mach-imx/include/mach/imx7-ccm-regs.h b/arch/arm/mach-imx/include/mach/imx7-ccm-regs.h
index 89a41156cd6a..96fad868fa30 100644
--- a/arch/arm/mach-imx/include/mach/imx7-ccm-regs.h
+++ b/arch/arm/mach-imx/include/mach/imx7-ccm-regs.h
@@ -3,6 +3,9 @@
 #ifndef __MACH_IMX7_CCM_REGS_H__
 #define __MACH_IMX7_CCM_REGS_H__
 
+#include <io.h>
+#include <linux/build_bug.h>
+
 #define IMX7_CLOCK_ROOT_INDEX(x)	(((x) - 0x8000) / 128)
 
 /*
@@ -34,16 +37,21 @@
 
 /* UART counting starts for 1, like in the datasheet/dt-bindings */
 
-static inline void imx7_early_setup_uart_clock(void)
+static inline void __imx7_early_setup_uart_clock(int uart)
 {
 	void __iomem *ccm   = IOMEM(MX7_CCM_BASE_ADDR);
 
 	writel(IMX7_CCM_CCGR_SETTINGn_NEEDED(0),
-	       ccm + IMX7_CCM_CCGRn_CLR(IMX7_CCM_CCGR_UART(1)));
+	       ccm + IMX7_CCM_CCGRn_CLR(IMX7_CCM_CCGR_UART(uart)));
 	writel(IMX7_CCM_TARGET_ROOTn_ENABLE | IMX7_UART_CLK_ROOT__OSC_24M,
-	       ccm + IMX7_CCM_TARGET_ROOTn(IMX7_UART_CLK_ROOT(1)));
+	       ccm + IMX7_CCM_TARGET_ROOTn(IMX7_UART_CLK_ROOT(uart)));
 	writel(IMX7_CCM_CCGR_SETTINGn_NEEDED(0),
-	       ccm + IMX7_CCM_CCGRn_SET(IMX7_CCM_CCGR_UART(1)));
+	       ccm + IMX7_CCM_CCGRn_SET(IMX7_CCM_CCGR_UART(uart)));
 }
 
+#define imx7_early_setup_uart_clock(uart) do {	\
+	static_assert(1 <= (uart) && (uart) <= 6, "ID out of UART1-6 range"); \
+	__imx7_early_setup_uart_clock(uart); \
+} while (0)
+
 #endif
-- 
2.30.2




More information about the barebox mailing list