1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21b93b3c3SWu Zhangjin /* 31b93b3c3SWu Zhangjin * 16550 compatible uart based serial debug support for zboot 41b93b3c3SWu Zhangjin */ 51b93b3c3SWu Zhangjin 61b93b3c3SWu Zhangjin #include <linux/types.h> 71b93b3c3SWu Zhangjin #include <linux/serial_reg.h> 81b93b3c3SWu Zhangjin 91b93b3c3SWu Zhangjin #include <asm/addrspace.h> 101b93b3c3SWu Zhangjin 1130ad29bbSHuacai Chen #if defined(CONFIG_MACH_LOONGSON64) || defined(CONFIG_MIPS_MALTA) 121b93b3c3SWu Zhangjin #define UART_BASE 0x1fd003f8 131b93b3c3SWu Zhangjin #define PORT(offset) (CKSEG1ADDR(UART_BASE) + (offset)) 141b93b3c3SWu Zhangjin #endif 151b93b3c3SWu Zhangjin 161b93b3c3SWu Zhangjin #ifdef CONFIG_AR7 171b93b3c3SWu Zhangjin #include <ar7.h> 181b93b3c3SWu Zhangjin #define PORT(offset) (CKSEG1ADDR(AR7_REGS_UART0) + (4 * offset)) 191b93b3c3SWu Zhangjin #endif 201b93b3c3SWu Zhangjin 21c60128ceSPaul Cercueil #ifdef CONFIG_MACH_INGENIC 22*f92a05b9SPaul Cercueil #define INGENIC_UART_BASE_ADDR (0x10030000 + 0x1000 * CONFIG_ZBOOT_INGENIC_UART) 23*f92a05b9SPaul Cercueil #define PORT(offset) (CKSEG1ADDR(INGENIC_UART_BASE_ADDR) + (4 * offset)) 24f9c9affcSLluís Batlle i Rossell #endif 25f9c9affcSLluís Batlle i Rossell 26d6a50784SJayachandran C #ifndef IOTYPE 27d6a50784SJayachandran C #define IOTYPE char 28d6a50784SJayachandran C #endif 29d6a50784SJayachandran C 301b93b3c3SWu Zhangjin #ifndef PORT 311b93b3c3SWu Zhangjin #error please define the serial port address for your own machine 321b93b3c3SWu Zhangjin #endif 331b93b3c3SWu Zhangjin serial_in(int offset)341b93b3c3SWu Zhangjinstatic inline unsigned int serial_in(int offset) 351b93b3c3SWu Zhangjin { 36d6a50784SJayachandran C return *((volatile IOTYPE *)PORT(offset)) & 0xFF; 371b93b3c3SWu Zhangjin } 381b93b3c3SWu Zhangjin serial_out(int offset,int value)391b93b3c3SWu Zhangjinstatic inline void serial_out(int offset, int value) 401b93b3c3SWu Zhangjin { 41d6a50784SJayachandran C *((volatile IOTYPE *)PORT(offset)) = value & 0xFF; 421b93b3c3SWu Zhangjin } 431b93b3c3SWu Zhangjin putc(char c)441b93b3c3SWu Zhangjinvoid putc(char c) 451b93b3c3SWu Zhangjin { 46d6a50784SJayachandran C int timeout = 1000000; 471b93b3c3SWu Zhangjin 481b93b3c3SWu Zhangjin while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0)) 491b93b3c3SWu Zhangjin ; 501b93b3c3SWu Zhangjin 511b93b3c3SWu Zhangjin serial_out(UART_TX, c); 521b93b3c3SWu Zhangjin } 53