From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Cc: Marek Vasut <marex@denx.de>, Fabio Estevam <festevam@denx.de>,
Peng Fan <peng.fan@nxp.com>, Stefano Babic <sbabic@denx.de>
Subject: [PATCH 4/4] ARM: imx: imx5: Introduce and use UART_BASE_ADDR(n)
Date: Sun, 24 Apr 2022 23:44:06 +0200 [thread overview]
Message-ID: <20220424214406.52658-4-marex@denx.de> (raw)
In-Reply-To: <20220424214406.52658-1-marex@denx.de>
Introduce helper macro UART_BASE_ADDR(n), which returns Nth UART base
address. Convert all board configurations to this new macro. This is the
first step toward switching CONFIG_MXC_UART_BASE to Kconfig. This is a
clean up, no functional change.
The new macro contains compile-time test to verify N is in suitable
range. The test works such that it multiplies constant N by constant
double-negation of size of a non-empty structure, i.e. it multiplies
constant N by constant 1 in each successful compilation case.
The non-empty structure may contain C11 _Static_assert(), make use of
this and place the kernel variant of static assert in there, so that
it performs the compile-time check for N in the correct range. Note
that it is not possible to directly use static_assert in compound
statements, hence this convoluted construct.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Stefano Babic <sbabic@denx.de>
---
arch/arm/include/asm/arch-mx5/imx-regs.h | 23 +++++++++++++++++++++++
include/configs/mx51evk.h | 2 +-
include/configs/mx53cx9020.h | 2 +-
include/configs/mx53loco.h | 2 +-
include/configs/usbarmory.h | 2 +-
5 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/arch/arm/include/asm/arch-mx5/imx-regs.h b/arch/arm/include/asm/arch-mx5/imx-regs.h
index f763749b03c..856bc07e8ae 100644
--- a/arch/arm/include/asm/arch-mx5/imx-regs.h
+++ b/arch/arm/include/asm/arch-mx5/imx-regs.h
@@ -125,6 +125,29 @@
#if defined(CONFIG_MX53)
#define UART5_BASE_ADDR (AIPS2_BASE_ADDR + 0x00090000)
+
+#define UART_BASE_ADDR(n) ( \
+ !!sizeof(struct { \
+ static_assert((n) >= 1 && (n) <= 5); \
+ int pad; \
+ }) * ( \
+ (n) == 1 ? UART1_BASE : \
+ (n) == 2 ? UART2_BASE : \
+ (n) == 3 ? UART3_BASE : \
+ (n) == 4 ? UART4_BASE_ADDR : \
+ UART5_BASE_ADDR) \
+ )
+#else /* i.MX51 */
+#define UART_BASE_ADDR(n) ( \
+ !!sizeof(struct { \
+ static_assert((n) >= 1 && (n) <= 4); \
+ int pad; \
+ }) * ( \
+ (n) == 1 ? UART1_BASE : \
+ (n) == 2 ? UART2_BASE : \
+ (n) == 3 ? UART3_BASE : \
+ UART4_BASE_ADDR) \
+ )
#endif
/*
diff --git a/include/configs/mx51evk.h b/include/configs/mx51evk.h
index ccfe292f6c6..814202e48d0 100644
--- a/include/configs/mx51evk.h
+++ b/include/configs/mx51evk.h
@@ -19,7 +19,7 @@
*/
#define CONFIG_FSL_IIM
-#define CONFIG_MXC_UART_BASE UART1_BASE
+#define CONFIG_MXC_UART_BASE UART_BASE_ADDR(1)
/* PMIC Controller */
#define CONFIG_POWER_SPI
diff --git a/include/configs/mx53cx9020.h b/include/configs/mx53cx9020.h
index fafc5f1adcb..9f2259d2981 100644
--- a/include/configs/mx53cx9020.h
+++ b/include/configs/mx53cx9020.h
@@ -14,7 +14,7 @@
#include <asm/arch/imx-regs.h>
-#define CONFIG_MXC_UART_BASE UART2_BASE
+#define CONFIG_MXC_UART_BASE UART_BASE_ADDR(2)
#define CONFIG_FPGA_COUNT 1
diff --git a/include/configs/mx53loco.h b/include/configs/mx53loco.h
index 8b9f0a29017..9851f64ee9f 100644
--- a/include/configs/mx53loco.h
+++ b/include/configs/mx53loco.h
@@ -11,7 +11,7 @@
#include <asm/arch/imx-regs.h>
-#define CONFIG_MXC_UART_BASE UART1_BASE
+#define CONFIG_MXC_UART_BASE UART_BASE_ADDR(1)
/* MMC Configs */
#define CONFIG_SYS_FSL_ESDHC_ADDR 0
diff --git a/include/configs/usbarmory.h b/include/configs/usbarmory.h
index 0faa656bc63..98b289e7ff1 100644
--- a/include/configs/usbarmory.h
+++ b/include/configs/usbarmory.h
@@ -18,7 +18,7 @@
#define CONFIG_SYS_CBSIZE 512
/* UART */
-#define CONFIG_MXC_UART_BASE UART1_BASE
+#define CONFIG_MXC_UART_BASE UART_BASE_ADDR(1)
/* SD/MMC */
#define CONFIG_SYS_FSL_ESDHC_ADDR 0
--
2.35.1
next prev parent reply other threads:[~2022-04-24 21:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-24 21:44 [PATCH 1/4] ARM: imx: imx8m: Introduce and use UART_BASE_ADDR(n) Marek Vasut
2022-04-24 21:44 ` [PATCH 2/4] ARM: imx: imx27: " Marek Vasut
2022-05-20 13:41 ` sbabic
2022-04-24 21:44 ` [PATCH 3/4] ARM: imx: imx31: " Marek Vasut
2022-05-20 13:40 ` sbabic
2022-04-24 21:44 ` Marek Vasut [this message]
2022-05-20 7:30 ` [PATCH 4/4] ARM: imx: imx5: " Stefano Babic
2022-05-20 7:45 ` Marek Vasut
2022-05-20 8:11 ` Stefano Babic
2022-05-20 8:18 ` Stefano Babic
2022-04-25 12:46 ` [PATCH 1/4] ARM: imx: imx8m: " Fabio Estevam
2022-04-25 13:02 ` Marek Vasut
2022-04-25 13:05 ` Tom Rini
2022-04-25 13:13 ` Marek Vasut
2022-04-25 13:39 ` Tom Rini
2022-04-25 13:15 ` Fabio Estevam
2022-05-20 13:42 ` sbabic
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=20220424214406.52658-4-marex@denx.de \
--to=marex@denx.de \
--cc=festevam@denx.de \
--cc=peng.fan@nxp.com \
--cc=sbabic@denx.de \
--cc=u-boot@lists.denx.de \
/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