blob: 90ae4400c40c84c189d289c6e03e2a94f1b16488 [file] [log] [blame]
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +08001/*
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 Rossellf9c9aff2012-03-30 16:48:05 +020021#ifdef CONFIG_MACH_JZ4740
22#define UART0_BASE 0xB0030000
23#define PORT(offset) (UART0_BASE + (4 * offset))
24#endif
25
Jayachandran Cd6a50782013-06-10 06:33:25 +000026#ifndef IOTYPE
27#define IOTYPE char
28#endif
29
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080030#ifndef PORT
31#error please define the serial port address for your own machine
32#endif
33
34static inline unsigned int serial_in(int offset)
35{
Jayachandran Cd6a50782013-06-10 06:33:25 +000036 return *((volatile IOTYPE *)PORT(offset)) & 0xFF;
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080037}
38
39static inline void serial_out(int offset, int value)
40{
Jayachandran Cd6a50782013-06-10 06:33:25 +000041 *((volatile IOTYPE *)PORT(offset)) = value & 0xFF;
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080042}
43
44void putc(char c)
45{
Jayachandran Cd6a50782013-06-10 06:33:25 +000046 int timeout = 1000000;
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080047
48 while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0))
49 ;
50
51 serial_out(UART_TX, c);
52}