From: Michael Tretter <m.tretter@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: Michael Tretter <m.tretter@pengutronix.de>
Subject: [PATCH 1/3] arm: socfpga: replace custom UART with ns16550
Date: Fri, 05 Jun 2026 14:58:13 +0200 [thread overview]
Message-ID: <20260605-socfpga-debug-uart-v1-1-8454bfc709bf@pengutronix.de> (raw)
In-Reply-To: <20260605-socfpga-debug-uart-v1-0-8454bfc709bf@pengutronix.de>
There is nothing special in the SoCFPGA UART, but it is compatible with
an ns16550 uart. Remove the custom implementation.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
include/mach/socfpga/debug_ll.h | 104 ++++++++++++++--------------------------
1 file changed, 35 insertions(+), 69 deletions(-)
diff --git a/include/mach/socfpga/debug_ll.h b/include/mach/socfpga/debug_ll.h
index 698cca60373f..86f6256af995 100644
--- a/include/mach/socfpga/debug_ll.h
+++ b/include/mach/socfpga/debug_ll.h
@@ -4,97 +4,63 @@
#define __MACH_SOCFPGA_DEBUG_LL_H__
#include <io.h>
-#include <errno.h>
#ifdef CONFIG_DEBUG_LL
#define UART_BASE CONFIG_DEBUG_SOCFPGA_UART_PHYS_ADDR
+
+#if defined(CONFIG_ARCH_SOCFPGA_CYCLONE5)
+static inline uint8_t debug_ll_read_reg(void __iomem *base, int reg)
+{
+ return readb(base + (reg << 2));
+}
+
+static inline void debug_ll_write_reg(void __iomem *base, int reg, uint8_t val)
+{
+ writeb(val, base + (reg << 2));
+}
+#else
+static inline uint8_t debug_ll_read_reg(void __iomem *base, int reg)
+{
+ return readl(base + (reg << 2));
+}
+
+static inline void debug_ll_write_reg(void __iomem *base, int reg, uint8_t val)
+{
+ writel(val, base + (reg << 2));
+}
#endif
-#define LSR_THRE 0x20 /* Xmit holding register empty */
-#define LSR_TEMT 0x40
+#include <debug_ll/ns16550.h>
-#define LCR_BKSE 0x80 /* Bank select enable */
-#define LCRVAL 0x3
-#define MCRVAL 0x3
-#define FCRVAL 0xc1
-
-#define RBR 0x0
-#define DLL 0x0
-#define IER 0x4
-#define DLM 0x4
-#define FCR 0x8
-#define LCR 0xc
-#define MCR 0x10
-#define LSR 0x14
-#define MSR 0x18
-#define SCR 0x1c
-#define THR 0x30
-
-static inline void socfpga_gen5_uart_putc(void *base, int c)
+static inline void socfpga_uart_setup(void *base)
{
- /* Wait until there is space in the FIFO */
- while ((readb(base + LSR) & LSR_THRE) == 0);
- /* Send the character */
- writeb(c, base + THR);
- /* Wait to make sure it hits the line, in case we die too soon. */
- while ((readb(base + LSR) & LSR_THRE) == 0);
-}
+ unsigned int div;
-static inline void socfpga_uart_putc(void *base, int c)
-{
- /* Wait until there is space in the FIFO */
- while ((readl(base + LSR) & LSR_THRE) == 0);
- /* Send the character */
- writel(c, base + THR);
- /* Wait to make sure it hits the line, in case we die too soon. */
- while ((readl(base + LSR) & LSR_THRE) == 0);
-}
-
-#ifdef CONFIG_DEBUG_LL
-static inline unsigned int ns16550_calc_divisor(unsigned int clk,
- unsigned int baudrate)
-{
- return (clk / 16 / baudrate);
+ div = debug_ll_ns16550_calc_divisor(CONFIG_DEBUG_SOCFPGA_UART_CLOCK);
+ debug_ll_ns16550_init(base, div);
}
static inline void socfpga_uart_setup_ll(void)
-{
- unsigned int div = ns16550_calc_divisor(CONFIG_DEBUG_SOCFPGA_UART_CLOCK,
- 115200);
-
- writel(0x00, UART_BASE + IER);
-
- writel(LCR_BKSE, UART_BASE + LCR);
- writel(div & 0xff, UART_BASE + DLL);
- writel((div >> 8) & 0xff, UART_BASE + DLM);
- writel(LCRVAL, UART_BASE + LCR);
-
- writel(MCRVAL, UART_BASE + MCR);
- writel(FCRVAL, UART_BASE + FCR);
-}
-
-#if defined(CONFIG_ARCH_SOCFPGA_CYCLONE5)
-static inline void PUTC_LL(char c)
{
void __iomem *base = IOMEM(UART_BASE);
- socfpga_gen5_uart_putc(base, c);
+ socfpga_uart_setup(base);
}
-#else
+
+static inline void socfpga_uart_putc(void *base, int c)
+{
+ debug_ll_ns16550_putc(base, c);
+}
+
static inline void PUTC_LL(char c)
{
void __iomem *base = IOMEM(UART_BASE);
socfpga_uart_putc(base, c);
}
-#endif
-
#else
-static inline unsigned int ns16550_calc_divisor(unsigned int clk,
- unsigned int baudrate) {
- return -ENOSYS;
-}
static inline void socfpga_uart_setup_ll(void) {}
-static inline void PUTC_LL(char c) {}
+static inline void socfpga_uart_putc(void *base, int c) {}
+static inline void socfpga_uart_setup(void *base) {}
#endif
#endif /* __MACH_SOCFPGA_DEBUG_LL_H__ */
--
2.47.3
next prev parent reply other threads:[~2026-06-05 12:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 12:58 [PATCH 0/3] arm: socfpga: cleanup UART for serial console Michael Tretter
2026-06-05 12:58 ` Michael Tretter [this message]
2026-06-05 12:58 ` [PATCH 2/3] arm: socfpga: get rid of UART address for low-level debug Michael Tretter
2026-06-05 12:58 ` [PATCH 3/3] arm: socfpga: axe5-eagle: always use UART0 Michael Tretter
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=20260605-socfpga-debug-uart-v1-1-8454bfc709bf@pengutronix.de \
--to=m.tretter@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.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