2 #include <asm/mach-au1x00/au1000.h>
7 * FIXME the user should be able to select the
8 * uart to be used for debugging.
10 #define DEBUG_BASE UART_DEBUG_BASE
13 /* we need uint32 uint8 */
14 /* #include "types.h" */
15 typedef unsigned char uint8;
16 typedef unsigned int uint32;
18 #define UART16550_BAUD_2400 2400
19 #define UART16550_BAUD_4800 4800
20 #define UART16550_BAUD_9600 9600
21 #define UART16550_BAUD_19200 19200
22 #define UART16550_BAUD_38400 38400
23 #define UART16550_BAUD_57600 57600
24 #define UART16550_BAUD_115200 115200
26 #define UART16550_PARITY_NONE 0
27 #define UART16550_PARITY_ODD 0x08
28 #define UART16550_PARITY_EVEN 0x18
29 #define UART16550_PARITY_MARK 0x28
30 #define UART16550_PARITY_SPACE 0x38
32 #define UART16550_DATA_5BIT 0x0
33 #define UART16550_DATA_6BIT 0x1
34 #define UART16550_DATA_7BIT 0x2
35 #define UART16550_DATA_8BIT 0x3
37 #define UART16550_STOP_1BIT 0x0
38 #define UART16550_STOP_2BIT 0x4
41 #define UART_RX 0 /* Receive buffer */
42 #define UART_TX 4 /* Transmit buffer */
43 #define UART_IER 8 /* Interrupt Enable Register */
44 #define UART_IIR 0xC /* Interrupt ID Register */
45 #define UART_FCR 0x10 /* FIFO Control Register */
46 #define UART_LCR 0x14 /* Line Control Register */
47 #define UART_MCR 0x18 /* Modem Control Register */
48 #define UART_LSR 0x1C /* Line Status Register */
49 #define UART_MSR 0x20 /* Modem Status Register */
50 #define UART_CLK 0x28 /* Baud Rat4e Clock Divider */
51 #define UART_MOD_CNTRL 0x100 /* Module Control */
53 /* memory-mapped read/write of the port */
54 #define UART16550_READ(y) (au_readl(DEBUG_BASE + y) & 0xff)
55 #define UART16550_WRITE(y, z) (au_writel(z&0xff, DEBUG_BASE + y))
57 extern unsigned long calc_clock(void);
59 void debugInit(uint32 baud, uint8 data, uint8 parity, uint8 stop)
62 if (UART16550_READ(UART_MOD_CNTRL) != 0x3) {
63 UART16550_WRITE(UART_MOD_CNTRL, 3);
67 /* disable interrupts */
68 UART16550_WRITE(UART_IER, 0);
70 /* set up baud rate */
75 divisor = get_au1x00_uart_baud_base() / baud;
76 UART16550_WRITE(UART_CLK, divisor & 0xffff);
80 UART16550_WRITE(UART_LCR, (data | parity | stop));
83 static int remoteDebugInitialized = 0;
85 uint8 getDebugChar(void)
87 if (!remoteDebugInitialized) {
88 remoteDebugInitialized = 1;
89 debugInit(UART16550_BAUD_115200,
91 UART16550_PARITY_NONE,
95 while((UART16550_READ(UART_LSR) & 0x1) == 0);
96 return UART16550_READ(UART_RX);
100 int putDebugChar(uint8 byte)
104 if (!remoteDebugInitialized) {
105 remoteDebugInitialized = 1;
106 debugInit(UART16550_BAUD_115200,
108 UART16550_PARITY_NONE,
109 UART16550_STOP_1BIT);
112 while ((UART16550_READ(UART_LSR)&0x40) == 0);
113 UART16550_WRITE(UART_TX, byte);
114 //for (i=0;i<0xfff;i++);