Wu Zhangjin | 1b93b3c | 2009-10-14 18:12:16 +0800 | [diff] [blame] | 1 | /* |
| 2 | * 16550 compatible uart based serial debug support for zboot |
| 3 | */ |
| 4 | |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/serial_reg.h> |
| 7 | #include <linux/init.h> |
| 8 | |
| 9 | #include <asm/addrspace.h> |
| 10 | |
| 11 | #if defined(CONFIG_MACH_LOONGSON) || defined(CONFIG_MIPS_MALTA) |
| 12 | #define UART_BASE 0x1fd003f8 |
| 13 | #define PORT(offset) (CKSEG1ADDR(UART_BASE) + (offset)) |
| 14 | #endif |
| 15 | |
| 16 | #ifdef CONFIG_AR7 |
| 17 | #include <ar7.h> |
| 18 | #define PORT(offset) (CKSEG1ADDR(AR7_REGS_UART0) + (4 * offset)) |
| 19 | #endif |
| 20 | |
LluĂs Batlle i Rossell | f9c9aff | 2012-03-30 16:48:05 +0200 | [diff] [blame] | 21 | #ifdef CONFIG_MACH_JZ4740 |
| 22 | #define UART0_BASE 0xB0030000 |
| 23 | #define PORT(offset) (UART0_BASE + (4 * offset)) |
| 24 | #endif |
| 25 | |
Jayachandran C | 8f0b043 | 2013-06-10 06:33:26 +0000 | [diff] [blame^] | 26 | #ifdef CONFIG_CPU_XLR |
| 27 | #define UART0_BASE 0x1EF14000 |
| 28 | #define PORT(offset) (CKSEG1ADDR(UART0_BASE) + (4 * offset)) |
| 29 | #define IOTYPE unsigned int |
| 30 | #endif |
| 31 | |
| 32 | #ifdef CONFIG_CPU_XLP |
| 33 | #define UART0_BASE 0x18030100 |
| 34 | #define PORT(offset) (CKSEG1ADDR(UART0_BASE) + (4 * offset)) |
| 35 | #define IOTYPE unsigned int |
| 36 | #endif |
| 37 | |
Jayachandran C | d6a5078 | 2013-06-10 06:33:25 +0000 | [diff] [blame] | 38 | #ifndef IOTYPE |
| 39 | #define IOTYPE char |
| 40 | #endif |
| 41 | |
Wu Zhangjin | 1b93b3c | 2009-10-14 18:12:16 +0800 | [diff] [blame] | 42 | #ifndef PORT |
| 43 | #error please define the serial port address for your own machine |
| 44 | #endif |
| 45 | |
| 46 | static inline unsigned int serial_in(int offset) |
| 47 | { |
Jayachandran C | d6a5078 | 2013-06-10 06:33:25 +0000 | [diff] [blame] | 48 | return *((volatile IOTYPE *)PORT(offset)) & 0xFF; |
Wu Zhangjin | 1b93b3c | 2009-10-14 18:12:16 +0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static inline void serial_out(int offset, int value) |
| 52 | { |
Jayachandran C | d6a5078 | 2013-06-10 06:33:25 +0000 | [diff] [blame] | 53 | *((volatile IOTYPE *)PORT(offset)) = value & 0xFF; |
Wu Zhangjin | 1b93b3c | 2009-10-14 18:12:16 +0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void putc(char c) |
| 57 | { |
Jayachandran C | d6a5078 | 2013-06-10 06:33:25 +0000 | [diff] [blame] | 58 | int timeout = 1000000; |
Wu Zhangjin | 1b93b3c | 2009-10-14 18:12:16 +0800 | [diff] [blame] | 59 | |
| 60 | while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0)) |
| 61 | ; |
| 62 | |
| 63 | serial_out(UART_TX, c); |
| 64 | } |