[PATCH] debug_ll ns16550: Add base address argument to register functions

Sascha Hauer s.hauer at pengutronix.de
Mon Nov 20 06:23:43 PST 2023


Add base address argument to debug_ll_ns16550_init() and debug_ll_ns16550_putc().
With this we can use the ns16550 debug_ll functions not only for
debug_ll, but also for general use with pbl_set_putc().

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/debug_ll/ns16550.h         | 26 +++++++++++++-------------
 include/mach/bcm283x/debug_ll.h    | 27 ++++++++++++++++-----------
 include/mach/layerscape/debug_ll.h | 18 +++++++++---------
 include/mach/omap/debug_ll.h       | 19 +++++++++----------
 include/mach/rockchip/debug_ll.h   | 19 +++++++++----------
 5 files changed, 56 insertions(+), 53 deletions(-)

diff --git a/include/debug_ll/ns16550.h b/include/debug_ll/ns16550.h
index 373e1df32a..fce113574f 100644
--- a/include/debug_ll/ns16550.h
+++ b/include/debug_ll/ns16550.h
@@ -29,12 +29,12 @@
 
 #define NS16550_LCR_BKSE	0x80 /* Bank select enable */
 
-static inline void debug_ll_ns16550_putc(char ch)
+static inline void debug_ll_ns16550_putc(void __iomem *base, char ch)
 {
-        while (!(debug_ll_read_reg(NS16550_LSR) & NS16550_LSR_THRE))
+        while (!(debug_ll_read_reg(base, NS16550_LSR) & NS16550_LSR_THRE))
                 ;
 
-        debug_ll_write_reg(NS16550_THR, ch);
+        debug_ll_write_reg(base, NS16550_THR, ch);
 }
 
 static inline uint16_t debug_ll_ns16550_calc_divisor(unsigned long clk)
@@ -42,17 +42,17 @@ static inline uint16_t debug_ll_ns16550_calc_divisor(unsigned long clk)
 	return clk / (CONFIG_BAUDRATE * 16);
 }
 
-static inline void debug_ll_ns16550_init(uint16_t divisor)
+static inline void debug_ll_ns16550_init(void __iomem *base, uint16_t divisor)
 {
-	debug_ll_write_reg(NS16550_LCR, 0x0); /* select ier reg */
-	debug_ll_write_reg(NS16550_IER, 0x0); /* disable interrupts */
-
-	debug_ll_write_reg(NS16550_LCR, NS16550_LCR_BKSE);
-	debug_ll_write_reg(NS16550_DLL, divisor & 0xff);
-	debug_ll_write_reg(NS16550_DLM, (divisor >> 8) & 0xff);
-	debug_ll_write_reg(NS16550_LCR, NS16550_LCR_VAL);
-	debug_ll_write_reg(NS16550_MCR, NS16550_MCR_VAL);
-	debug_ll_write_reg(NS16550_FCR, NS16550_FCR_VAL);
+	debug_ll_write_reg(base, NS16550_LCR, 0x0); /* select ier reg */
+	debug_ll_write_reg(base, NS16550_IER, 0x0); /* disable interrupts */
+
+	debug_ll_write_reg(base, NS16550_LCR, NS16550_LCR_BKSE);
+	debug_ll_write_reg(base, NS16550_DLL, divisor & 0xff);
+	debug_ll_write_reg(base, NS16550_DLM, (divisor >> 8) & 0xff);
+	debug_ll_write_reg(base, NS16550_LCR, NS16550_LCR_VAL);
+	debug_ll_write_reg(base, NS16550_MCR, NS16550_MCR_VAL);
+	debug_ll_write_reg(base, NS16550_FCR, NS16550_FCR_VAL);
 }
 
 #endif
diff --git a/include/mach/bcm283x/debug_ll.h b/include/mach/bcm283x/debug_ll.h
index e89328340a..844305109a 100644
--- a/include/mach/bcm283x/debug_ll.h
+++ b/include/mach/bcm283x/debug_ll.h
@@ -42,14 +42,14 @@ static inline void debug_ll_init(void)
 
 #elif defined CONFIG_DEBUG_RPI3_MINI_UART
 
-static inline uint8_t debug_ll_read_reg(int reg)
+static inline uint8_t debug_ll_read_reg(void __iomem *base, int reg)
 {
-	return readb(BCM2836_MINIUART_BASE + (reg << 2));
+	return readb(base + (reg << 2));
 }
 
-static inline void debug_ll_write_reg(int reg, uint8_t val)
+static inline void debug_ll_write_reg(void __iomem *base, int reg, uint8_t val)
 {
-	writeb(val, BCM2836_MINIUART_BASE + (reg << 2));
+	writeb(val, base + (reg << 2));
 }
 
 #define BCM2836_AUX_CLOCK_ENB		0x3f215004 /* BCM2835 AUX Clock enable register */
@@ -60,28 +60,31 @@ static inline void debug_ll_write_reg(int reg, uint8_t val)
 static inline void debug_ll_init(void)
 {
 	uint16_t divisor;
+	void __iomem *base = IOMEM(BCM2836_MINIUART_BASE);
 
 	writeb(BCM2836_AUX_CLOCK_EN_UART, BCM2836_AUX_CLOCK_ENB);
 
 	divisor = debug_ll_ns16550_calc_divisor(250000000 * 2);
-	debug_ll_ns16550_init(divisor);
+	debug_ll_ns16550_init(base, divisor);
 }
 
 static inline void PUTC_LL(int c)
 {
-	debug_ll_ns16550_putc(c);
+	void __iomem  *base = IOMEM(BCM2836_MINIUART_BASE);
+
+	debug_ll_ns16550_putc(base, c);
 }
 
 #elif defined CONFIG_DEBUG_RPI4_MINI_UART
 
-static inline uint8_t debug_ll_read_reg(int reg)
+static inline uint8_t debug_ll_read_reg(void __iomem *base, int reg)
 {
-	return readb(BCM2711_MINIUART_BASE + (reg << 2));
+	return readb(base + (reg << 2));
 }
 
-static inline void debug_ll_write_reg(int reg, uint8_t val)
+static inline void debug_ll_write_reg(void __iomem *base, int reg, uint8_t val)
 {
-	writeb(val, BCM2711_MINIUART_BASE + (reg << 2));
+	writeb(val, base + (reg << 2));
 }
 
 #include <debug_ll/ns16550.h>
@@ -93,7 +96,9 @@ static inline void debug_ll_init(void)
 
 static inline void PUTC_LL(int c)
 {
-	debug_ll_ns16550_putc(c);
+	void __iomem *base = IOMEM(BCM2711_MINIUART_BASE);
+
+	debug_ll_ns16550_putc(base, c);
 }
 
 #else
diff --git a/include/mach/layerscape/debug_ll.h b/include/mach/layerscape/debug_ll.h
index 4c8137d1e1..23af0118cc 100644
--- a/include/mach/layerscape/debug_ll.h
+++ b/include/mach/layerscape/debug_ll.h
@@ -9,17 +9,13 @@
 #define __LS_UART_BASE(num)	LSCH2_NS16550_COM##num
 #define LS_UART_BASE(num) __LS_UART_BASE(num)
 
-static inline uint8_t debug_ll_read_reg(int reg)
+static inline uint8_t debug_ll_read_reg(void __iomem *base, int reg)
 {
-	void __iomem *base = IOMEM(LS_UART_BASE(CONFIG_DEBUG_LAYERSCAPE_UART_PORT));
-
 	return readb(base + reg);
 }
 
-static inline void debug_ll_write_reg(int reg, uint8_t val)
+static inline void debug_ll_write_reg(void __iomem *base, int reg, uint8_t val)
 {
-	void __iomem *base = IOMEM(LS_UART_BASE(CONFIG_DEBUG_LAYERSCAPE_UART_PORT));
-
 	writeb(val, base + reg);
 }
 
@@ -27,23 +23,27 @@ static inline void debug_ll_write_reg(int reg, uint8_t val)
 
 static inline void ls1046a_debug_ll_init(void)
 {
+	void __iomem *base = IOMEM(LS_UART_BASE(CONFIG_DEBUG_LAYERSCAPE_UART_PORT));
 	uint16_t divisor;
 
 	divisor = debug_ll_ns16550_calc_divisor(300000000);
-	debug_ll_ns16550_init(divisor);
+	debug_ll_ns16550_init(base, divisor);
 }
 
 static inline void ls102xa_debug_ll_init(void)
 {
+	void __iomem *base = IOMEM(LS_UART_BASE(CONFIG_DEBUG_LAYERSCAPE_UART_PORT));
 	uint16_t divisor;
 
 	divisor = debug_ll_ns16550_calc_divisor(150000000);
-	debug_ll_ns16550_init(divisor);
+	debug_ll_ns16550_init(base, divisor);
 }
 
 static inline void PUTC_LL(int c)
 {
-	debug_ll_ns16550_putc(c);
+	void __iomem *base = IOMEM(LS_UART_BASE(CONFIG_DEBUG_LAYERSCAPE_UART_PORT));
+
+	debug_ll_ns16550_putc(base, c);
 }
 
 #endif /* __MACH_LAYERSCAPE_DEBUG_LL_H__ */
diff --git a/include/mach/omap/debug_ll.h b/include/mach/omap/debug_ll.h
index a6cd9a77c4..b0650abf2d 100644
--- a/include/mach/omap/debug_ll.h
+++ b/include/mach/omap/debug_ll.h
@@ -37,19 +37,13 @@
 #define __OMAP_UART_BASE(soc, num) soc##_UART##num##_BASE
 #define OMAP_UART_BASE(soc, num) __OMAP_UART_BASE(soc, num)
 
-static inline uint8_t debug_ll_read_reg(int reg)
+static inline uint8_t debug_ll_read_reg(void __iomem *base, int reg)
 {
-	void __iomem *base = (void *)OMAP_UART_BASE(OMAP_DEBUG_SOC,
-			CONFIG_DEBUG_OMAP_UART_PORT);
-
 	return readb(base + (reg << 2));
 }
 
-static inline void debug_ll_write_reg(int reg, uint8_t val)
+static inline void debug_ll_write_reg(void __iomem *base, int reg, uint8_t val)
 {
-	void __iomem *base = (void *)OMAP_UART_BASE(OMAP_DEBUG_SOC,
-			CONFIG_DEBUG_OMAP_UART_PORT);
-
 	writeb(val, base + (reg << 2));
 }
 
@@ -57,15 +51,20 @@ static inline void debug_ll_write_reg(int reg, uint8_t val)
 
 static inline void omap_debug_ll_init(void)
 {
+	void __iomem *base = (void *)OMAP_UART_BASE(OMAP_DEBUG_SOC,
+			CONFIG_DEBUG_OMAP_UART_PORT);
 	unsigned int divisor;
 
 	divisor = debug_ll_ns16550_calc_divisor(48000000);
-	debug_ll_ns16550_init(divisor);
+	debug_ll_ns16550_init(base, divisor);
 }
 
 static inline void PUTC_LL(int c)
 {
-	debug_ll_ns16550_putc(c);
+	void __iomem *base = (void *)OMAP_UART_BASE(OMAP_DEBUG_SOC,
+			CONFIG_DEBUG_OMAP_UART_PORT);
+
+	debug_ll_ns16550_putc(base, c);
 }
 
 #else
diff --git a/include/mach/rockchip/debug_ll.h b/include/mach/rockchip/debug_ll.h
index b68d91165d..4a88113535 100644
--- a/include/mach/rockchip/debug_ll.h
+++ b/include/mach/rockchip/debug_ll.h
@@ -43,19 +43,13 @@
 #define __RK_UART_BASE(soc, num) soc##_UART##num##_BASE
 #define RK_UART_BASE(soc, num) __RK_UART_BASE(soc, num)
 
-static inline uint8_t debug_ll_read_reg(int reg)
+static inline uint8_t debug_ll_read_reg(void __iomem *base, int reg)
 {
-	void __iomem *base = IOMEM(RK_UART_BASE(RK_DEBUG_SOC,
-		CONFIG_DEBUG_ROCKCHIP_UART_PORT));
-
 	return readb(base + (reg << 2));
 }
 
-static inline void debug_ll_write_reg(int reg, uint8_t val)
+static inline void debug_ll_write_reg(void __iomem *base, int reg, uint8_t val)
 {
-	void __iomem *base = IOMEM(RK_UART_BASE(RK_DEBUG_SOC,
-		CONFIG_DEBUG_ROCKCHIP_UART_PORT));
-
 	writeb(val, base + (reg << 2));
 }
 
@@ -63,15 +57,20 @@ static inline void debug_ll_write_reg(int reg, uint8_t val)
 
 static inline void rockchip_debug_ll_init(void)
 {
+	void __iomem *base = IOMEM(RK_UART_BASE(RK_DEBUG_SOC,
+		CONFIG_DEBUG_ROCKCHIP_UART_PORT));
 	unsigned int divisor;
 
 	divisor = debug_ll_ns16550_calc_divisor(RK_DEBUG_UART_CLOCK * 2);
-	debug_ll_ns16550_init(divisor);
+	debug_ll_ns16550_init(base, divisor);
 }
 
 static inline void PUTC_LL(int c)
 {
-	debug_ll_ns16550_putc(c);
+	void __iomem *base = IOMEM(RK_UART_BASE(RK_DEBUG_SOC,
+		CONFIG_DEBUG_ROCKCHIP_UART_PORT));
+
+	debug_ll_ns16550_putc(base, c);
 }
 
 #else
-- 
2.39.2




More information about the barebox mailing list