Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * 16550 compatible uart based serial debug support for zboot
0004  */
0005 
0006 #include <linux/types.h>
0007 #include <linux/serial_reg.h>
0008 
0009 #include <asm/addrspace.h>
0010 
0011 #if defined(CONFIG_MACH_LOONGSON64) || defined(CONFIG_MIPS_MALTA)
0012 #define UART_BASE 0x1fd003f8
0013 #define PORT(offset) (CKSEG1ADDR(UART_BASE) + (offset))
0014 #endif
0015 
0016 #ifdef CONFIG_AR7
0017 #include <ar7.h>
0018 #define PORT(offset) (CKSEG1ADDR(AR7_REGS_UART0) + (4 * offset))
0019 #endif
0020 
0021 #ifdef CONFIG_MACH_INGENIC
0022 #define INGENIC_UART_BASE_ADDR  (0x10030000 + 0x1000 * CONFIG_ZBOOT_INGENIC_UART)
0023 #define PORT(offset) (CKSEG1ADDR(INGENIC_UART_BASE_ADDR) + (4 * offset))
0024 #endif
0025 
0026 #ifndef IOTYPE
0027 #define IOTYPE char
0028 #endif
0029 
0030 #ifndef PORT
0031 #error please define the serial port address for your own machine
0032 #endif
0033 
0034 static inline unsigned int serial_in(int offset)
0035 {
0036     return *((volatile IOTYPE *)PORT(offset)) & 0xFF;
0037 }
0038 
0039 static inline void serial_out(int offset, int value)
0040 {
0041     *((volatile IOTYPE *)PORT(offset)) = value & 0xFF;
0042 }
0043 
0044 void putc(char c)
0045 {
0046     int timeout = 1000000;
0047 
0048     while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0))
0049         ;
0050 
0051     serial_out(UART_TX, c);
0052 }