Skip to content

Commit 8cd1964

Browse files
committed
uart: patch for ns8250 on arm
1 parent 3e13aae commit 8cd1964

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

sys/dev/uart/uart_dev_ns8250.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include <sys/kernel.h>
3838
#include <sys/sysctl.h>
3939
#include <machine/bus.h>
40+
#if (defined(__arm__) || defined(__aarch64__))
41+
#include <machine/machdep.h>
42+
#endif
4043

4144
#ifdef FDT
4245
#include <dev/fdt/fdt_common.h>
@@ -89,9 +92,7 @@ SYSCTL_INT(_hw, OID_AUTO, uart_noise_threshold, CTLFLAG_RWTUN,
8992
* options EARLY_PRINTF=ns8250
9093
*/
9194
#if CHECK_EARLY_PRINTF(ns8250)
92-
#if !(defined(__amd64__) || defined(__i386__))
93-
#error ns8250 early putc is x86 specific as it uses inb/outb
94-
#endif
95+
#if (defined(__amd64__) || defined(__i386__))
9596
static void
9697
uart_ns8250_early_putc(int c)
9798
{
@@ -103,6 +104,20 @@ uart_ns8250_early_putc(int c)
103104
continue;
104105
outb(tx, c);
105106
}
107+
#elif (defined(__arm__) || defined(__aarch64__))
108+
static void
109+
uart_ns8250_early_putc(int c)
110+
{
111+
volatile uint32_t *stat = (uint32_t *)(socdev_va + REG_LSR * 4);
112+
volatile uint32_t *tx = (uint32_t *)(socdev_va + REG_DATA * 4);
113+
int limit = 1000000;
114+
while ((*stat & LSR_THRE) == 0 && --limit > 0)
115+
continue;
116+
*tx = c & 0xff;
117+
}
118+
#else
119+
#error ns8250 early putc is not implemented for current architecture
120+
#endif
106121
early_putc_t *early_putc = uart_ns8250_early_putc;
107122
#endif /* EARLY_PRINTF */
108123

0 commit comments

Comments
 (0)