[PATCH 1/4] ARM: imx: imx8m: Introduce and use UART_BASE_ADDR(n)

2022-05-20 Thread sbabic
> 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 
> Cc: Fabio Estevam 
> Cc: Peng Fan 
> Cc: Stefano Babic 
Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

-- 
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=


Re: [PATCH 1/4] ARM: imx: imx8m: Introduce and use UART_BASE_ADDR(n)

2022-04-25 Thread Tom Rini
On Mon, Apr 25, 2022 at 03:13:53PM +0200, Marek Vasut wrote:
> On 4/25/22 15:05, Tom Rini wrote:
> > On Mon, Apr 25, 2022 at 03:02:29PM +0200, Marek Vasut wrote:
> > > On 4/25/22 14:46, Fabio Estevam wrote:
> > > > Hi Marek,
> > > > 
> > > > On 24/04/2022 18:44, Marek Vasut wrote:
> > > > > 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.
> > > > 
> > > > As DM_SERIAL is mandatory now, we should get rid of 
> > > > CONFIG_MXC_UART_BASE.
> > > > 
> > > > I would prefer a patch that removes CONFIG_MXC_UART_BASE instead.
> > > 
> > > DM is mandatory in SPL too ? I doubt it.
> > 
> > It is strongly encouraged, but not mandatory.  It is not used on I guess
> > imx27/31/5, but is for all of the imx8 families.  So
> > CONFIG_MXC_UART_BASE still needs to be moved out of board.h files (and
> > perhaps out of CONFIG namespace since it's not configurable, it's part
> > of the SoC) and perhaps the path for imx8* is to drop the references
> > since it's all DM?
> 
> MX8M SPL is not DM serial either. But I think I will just postpone this
> cleanup until I have time to finish it.

Right, sorry, I meant DM enabled in SPL to start with.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/4] ARM: imx: imx8m: Introduce and use UART_BASE_ADDR(n)

2022-04-25 Thread Fabio Estevam

On 25/04/2022 10:05, Tom Rini wrote:


DM is mandatory in SPL too ? I doubt it.


It is strongly encouraged, but not mandatory.  It is not used on I 
guess

imx27/31/5, but is for all of the imx8 families.  So
CONFIG_MXC_UART_BASE still needs to be moved out of board.h files (and
perhaps out of CONFIG namespace since it's not configurable, it's part
of the SoC) and perhaps the path for imx8* is to drop the references
since it's all DM?


Correct. In the defconfigs where CONFIG_DM_SERIAL=y and CONFIG_SPL_DM=y
are selected the CONFIG_MXC_UART_BASE can be safely dropped.

Regards,

Fabio Estevam


Re: [PATCH 1/4] ARM: imx: imx8m: Introduce and use UART_BASE_ADDR(n)

2022-04-25 Thread Marek Vasut

On 4/25/22 15:05, Tom Rini wrote:

On Mon, Apr 25, 2022 at 03:02:29PM +0200, Marek Vasut wrote:

On 4/25/22 14:46, Fabio Estevam wrote:

Hi Marek,

On 24/04/2022 18:44, Marek Vasut wrote:

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.


As DM_SERIAL is mandatory now, we should get rid of CONFIG_MXC_UART_BASE.

I would prefer a patch that removes CONFIG_MXC_UART_BASE instead.


DM is mandatory in SPL too ? I doubt it.


It is strongly encouraged, but not mandatory.  It is not used on I guess
imx27/31/5, but is for all of the imx8 families.  So
CONFIG_MXC_UART_BASE still needs to be moved out of board.h files (and
perhaps out of CONFIG namespace since it's not configurable, it's part
of the SoC) and perhaps the path for imx8* is to drop the references
since it's all DM?


MX8M SPL is not DM serial either. But I think I will just postpone this 
cleanup until I have time to finish it.


Re: [PATCH 1/4] ARM: imx: imx8m: Introduce and use UART_BASE_ADDR(n)

2022-04-25 Thread Tom Rini
On Mon, Apr 25, 2022 at 03:02:29PM +0200, Marek Vasut wrote:
> On 4/25/22 14:46, Fabio Estevam wrote:
> > Hi Marek,
> > 
> > On 24/04/2022 18:44, Marek Vasut wrote:
> > > 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.
> > 
> > As DM_SERIAL is mandatory now, we should get rid of CONFIG_MXC_UART_BASE.
> > 
> > I would prefer a patch that removes CONFIG_MXC_UART_BASE instead.
> 
> DM is mandatory in SPL too ? I doubt it.

It is strongly encouraged, but not mandatory.  It is not used on I guess
imx27/31/5, but is for all of the imx8 families.  So
CONFIG_MXC_UART_BASE still needs to be moved out of board.h files (and
perhaps out of CONFIG namespace since it's not configurable, it's part
of the SoC) and perhaps the path for imx8* is to drop the references
since it's all DM?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/4] ARM: imx: imx8m: Introduce and use UART_BASE_ADDR(n)

2022-04-25 Thread Marek Vasut

On 4/25/22 14:46, Fabio Estevam wrote:

Hi Marek,

On 24/04/2022 18:44, Marek Vasut wrote:

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.


As DM_SERIAL is mandatory now, we should get rid of CONFIG_MXC_UART_BASE.

I would prefer a patch that removes CONFIG_MXC_UART_BASE instead.


DM is mandatory in SPL too ? I doubt it.


Re: [PATCH 1/4] ARM: imx: imx8m: Introduce and use UART_BASE_ADDR(n)

2022-04-25 Thread Fabio Estevam

Hi Marek,

On 24/04/2022 18:44, Marek Vasut wrote:

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.


As DM_SERIAL is mandatory now, we should get rid of 
CONFIG_MXC_UART_BASE.


I would prefer a patch that removes CONFIG_MXC_UART_BASE instead.

Regards,

Fabio Estevam


[PATCH 1/4] ARM: imx: imx8m: Introduce and use UART_BASE_ADDR(n)

2022-04-24 Thread Marek Vasut
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 
Cc: Fabio Estevam 
Cc: Peng Fan 
Cc: Stefano Babic 
---
 arch/arm/include/asm/arch-imx8m/imx-regs.h | 10 ++
 include/configs/imx8mm-cl-iot-gate.h   |  2 +-
 include/configs/imx8mm_beacon.h|  2 +-
 include/configs/imx8mm_evk.h   |  2 +-
 include/configs/imx8mm_icore_mx8mm.h   |  2 +-
 include/configs/imx8mm_venice.h|  2 +-
 include/configs/imx8mn_beacon.h|  2 +-
 include/configs/imx8mn_evk.h   |  2 +-
 include/configs/imx8mn_var_som.h   |  2 +-
 include/configs/imx8mn_venice.h|  2 +-
 include/configs/imx8mp_evk.h   |  2 +-
 include/configs/imx8mp_rsb3720.h   |  2 +-
 include/configs/imx8mq_cm.h|  2 +-
 include/configs/imx8mq_evk.h   |  2 +-
 include/configs/imx8mq_phanbell.h  |  2 +-
 include/configs/kontron-sl-mx8mm.h |  2 +-
 include/configs/kontron_pitx_imx8m.h   |  2 +-
 include/configs/phycore_imx8mm.h   |  2 +-
 include/configs/phycore_imx8mp.h   |  2 +-
 include/configs/pico-imx8mq.h  |  2 +-
 include/configs/verdin-imx8mm.h|  2 +-
 include/configs/verdin-imx8mp.h|  2 +-
 22 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/arch/arm/include/asm/arch-imx8m/imx-regs.h 
b/arch/arm/include/asm/arch-imx8m/imx-regs.h
index b2a8ad77ae1..1da75528d46 100644
--- a/arch/arm/include/asm/arch-imx8m/imx-regs.h
+++ b/arch/arm/include/asm/arch-imx8m/imx-regs.h
@@ -48,6 +48,16 @@
 #ifdef CONFIG_IMX8MM
 #define USDHC3_BASE_ADDR   0x30B6
 #endif
+#define UART_BASE_ADDR(n)  (   \
+   !!sizeof(struct {   \
+   static_assert((n) >= 1 && (n) <= 4);\
+   int pad;\
+   }) * (  \
+   (n) == 1 ? UART1_BASE_ADDR :\
+   (n) == 2 ? UART2_BASE_ADDR :\
+   (n) == 3 ? UART3_BASE_ADDR :\
+   UART4_BASE_ADDR)\
+   )
 
 #define TZASC_BASE_ADDR0x32F8
 
diff --git a/include/configs/imx8mm-cl-iot-gate.h 
b/include/configs/imx8mm-cl-iot-gate.h
index c20c32b6951..60746588b73 100644
--- a/include/configs/imx8mm-cl-iot-gate.h
+++ b/include/configs/imx8mm-cl-iot-gate.h
@@ -145,7 +145,7 @@
 #define PHYS_SDRAM 0x4000
 #define PHYS_SDRAM_SIZE0x8000 /* 2GB DDR */
 
-#define CONFIG_MXC_UART_BASE   UART3_BASE_ADDR
+#define CONFIG_MXC_UART_BASE   UART_BASE_ADDR(3)
 
 /* Monitor Command Prompt */
 #define CONFIG_SYS_CBSIZE  2048
diff --git a/include/configs/imx8mm_beacon.h b/include/configs/imx8mm_beacon.h
index 7c17f14964f..573ddaf2952 100644
--- a/include/configs/imx8mm_beacon.h
+++ b/include/configs/imx8mm_beacon.h
@@ -91,7 +91,7 @@
 #define PHYS_SDRAM 0x4000
 #define PHYS_SDRAM_SIZE0x8000 /* 2GB DDR */
 
-#define CONFIG_MXC_UART_BASE   UART2_BASE_ADDR
+#define CONFIG_MXC_UART_BASE   UART_BASE_ADDR(2)
 
 /* Monitor Command Prompt */
 #define CONFIG_SYS_CBSIZE  2048
diff --git a/include/configs/imx8mm_evk.h b/include/configs/imx8mm_evk.h
index 42b78485cfc..bd10406d79d 100644
--- a/include/configs/imx8mm_evk.h
+++ b/include/configs/imx8mm_evk.h
@@ -68,7 +68,7 @@
 #define PHYS_SDRAM  0x4000
 #define PHYS_SDRAM_SIZE0x8000 /* 2GB DDR */
 
-#define CONFIG_MXC_UART_BASE   UART2_BASE_ADDR
+#define CONFIG_MXC_UART_BASE   UART_BASE_ADDR(2)
 
 /* Monitor Command Prompt */
 #define CONFIG_SYS_CBSIZE  2048
diff --git a/include/configs/imx8mm_icore_mx8mm.h 
b/include/configs/imx8mm_icore_mx8mm.h
index f521add5b04..b9b24a8c51d 100644
--- a/include/configs/imx8mm_icore_mx8mm.h
+++ b/include/configs/imx8mm_icore_mx8mm.h
@@ -66,7 +66,7 @@
 #define CONFIG_SYS_BOOTM_LEN   SZ_256M
 
 /* UART */
-#define CONFIG_MXC_UART_BASE   UART2_BASE_ADDR
+#define