1// SPDX-License-Identifier: GPL-2.0
2/*
3 * 16550 compatible uart based serial debug support for zboot
4 */
5
6#include <linux/types.h>
7#include <linux/serial_reg.h>
8
9#include <asm/addrspace.h>
10
11#define UART_BASE 0x1fe001e0
12#define PORT(offset) (TO_UNCACHE(UART_BASE) + (offset))
13
14#ifndef IOTYPE
15#define IOTYPE char
16#endif
17
18#ifndef PORT
19#error please define the serial port address for your own machine
20#endif
21
22static inline unsigned int serial_in(int offset)
23{
24	return *((volatile IOTYPE *)PORT(offset)) & 0xFF;
25}
26
27static inline void serial_out(int offset, int value)
28{
29	*((volatile IOTYPE *)PORT(offset)) = value & 0xFF;
30}
31
32void putc(char c)
33{
34	int timeout = 1000000;
35
36	while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0))
37		;
38
39	serial_out(UART_TX, c);
40}
41