Merge tag 'pm-6.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[linux-block.git] / arch / mips / boot / compressed / uart-16550.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1b93b3c3
WZ
2/*
3 * 16550 compatible uart based serial debug support for zboot
4 */
5
6#include <linux/types.h>
7#include <linux/serial_reg.h>
1b93b3c3
WZ
8
9#include <asm/addrspace.h>
10
6d778f61
SS
11#include "decompress.h"
12
30ad29bb 13#if defined(CONFIG_MACH_LOONGSON64) || defined(CONFIG_MIPS_MALTA)
1b93b3c3
WZ
14#define UART_BASE 0x1fd003f8
15#define PORT(offset) (CKSEG1ADDR(UART_BASE) + (offset))
16#endif
17
c60128ce 18#ifdef CONFIG_MACH_INGENIC
f92a05b9
PC
19#define INGENIC_UART_BASE_ADDR (0x10030000 + 0x1000 * CONFIG_ZBOOT_INGENIC_UART)
20#define PORT(offset) (CKSEG1ADDR(INGENIC_UART_BASE_ADDR) + (4 * offset))
f9c9affc
LBR
21#endif
22
35fb26f9
CJD
23#ifdef CONFIG_ECONET
24#define EN75_UART_BASE 0x1fbf0003
25#define PORT(offset) (CKSEG1ADDR(EN75_UART_BASE) + (4 * (offset)))
26#endif
27
d6a50784
J
28#ifndef IOTYPE
29#define IOTYPE char
30#endif
31
1b93b3c3
WZ
32#ifndef PORT
33#error please define the serial port address for your own machine
34#endif
35
36static inline unsigned int serial_in(int offset)
37{
d6a50784 38 return *((volatile IOTYPE *)PORT(offset)) & 0xFF;
1b93b3c3
WZ
39}
40
41static inline void serial_out(int offset, int value)
42{
d6a50784 43 *((volatile IOTYPE *)PORT(offset)) = value & 0xFF;
1b93b3c3
WZ
44}
45
46void putc(char c)
47{
d6a50784 48 int timeout = 1000000;
1b93b3c3
WZ
49
50 while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0))
51 ;
52
53 serial_out(UART_TX, c);
54}