2 #include <asm/serial.h> /* For the serial port location and base baud */
6 typedef unsigned char uint8
;
7 typedef unsigned int uint32
;
9 /* --- END OF CONFIG --- */
11 #define UART16550_BAUD_2400 2400
12 #define UART16550_BAUD_4800 4800
13 #define UART16550_BAUD_9600 9600
14 #define UART16550_BAUD_19200 19200
15 #define UART16550_BAUD_38400 38400
16 #define UART16550_BAUD_57600 57600
17 #define UART16550_BAUD_115200 115200
19 #define UART16550_PARITY_NONE 0
20 #define UART16550_PARITY_ODD 0x08
21 #define UART16550_PARITY_EVEN 0x18
22 #define UART16550_PARITY_MARK 0x28
23 #define UART16550_PARITY_SPACE 0x38
25 #define UART16550_DATA_5BIT 0x0
26 #define UART16550_DATA_6BIT 0x1
27 #define UART16550_DATA_7BIT 0x2
28 #define UART16550_DATA_8BIT 0x3
30 #define UART16550_STOP_1BIT 0x0
31 #define UART16550_STOP_2BIT 0x4
33 /* ----------------------------------------------------- */
37 /* [jsun] we use the second serial port for kdb */
38 #define BASE OCELOT_SERIAL1_BASE
39 #define MAX_BAUD OCELOT_BASE_BAUD
41 /* === END OF CONFIG === */
46 #define OFS_RCV_BUFFER 0
47 #define OFS_TRANS_HOLD 0
48 #define OFS_SEND_BUFFER 0
49 #define OFS_INTR_ENABLE (1*REG_OFFSET)
50 #define OFS_INTR_ID (2*REG_OFFSET)
51 #define OFS_DATA_FORMAT (3*REG_OFFSET)
52 #define OFS_LINE_CONTROL (3*REG_OFFSET)
53 #define OFS_MODEM_CONTROL (4*REG_OFFSET)
54 #define OFS_RS232_OUTPUT (4*REG_OFFSET)
55 #define OFS_LINE_STATUS (5*REG_OFFSET)
56 #define OFS_MODEM_STATUS (6*REG_OFFSET)
57 #define OFS_RS232_INPUT (6*REG_OFFSET)
58 #define OFS_SCRATCH_PAD (7*REG_OFFSET)
60 #define OFS_DIVISOR_LSB (0*REG_OFFSET)
61 #define OFS_DIVISOR_MSB (1*REG_OFFSET)
64 /* memory-mapped read/write of the port */
65 #define UART16550_READ(y) (*((volatile uint8*)(BASE + y)))
66 #define UART16550_WRITE(y, z) ((*((volatile uint8*)(BASE + y))) = z)
68 void debugInit(uint32 baud
, uint8 data
, uint8 parity
, uint8 stop
)
70 /* disable interrupts */
71 UART16550_WRITE(OFS_INTR_ENABLE
, 0);
73 /* set up baud rate */
78 UART16550_WRITE(OFS_LINE_CONTROL
, 0x80);
81 divisor
= MAX_BAUD
/ baud
;
82 UART16550_WRITE(OFS_DIVISOR_LSB
, divisor
& 0xff);
83 UART16550_WRITE(OFS_DIVISOR_MSB
, (divisor
& 0xff00) >> 8);
86 UART16550_WRITE(OFS_LINE_CONTROL
, 0x0);
90 UART16550_WRITE(OFS_DATA_FORMAT
, data
| parity
| stop
);
93 static int remoteDebugInitialized
= 0;
95 uint8
getDebugChar(void)
97 if (!remoteDebugInitialized
) {
98 remoteDebugInitialized
= 1;
99 debugInit(UART16550_BAUD_38400
,
101 UART16550_PARITY_NONE
, UART16550_STOP_1BIT
);
104 while ((UART16550_READ(OFS_LINE_STATUS
) & 0x1) == 0);
105 return UART16550_READ(OFS_RCV_BUFFER
);
109 int putDebugChar(uint8 byte
)
111 if (!remoteDebugInitialized
) {
112 remoteDebugInitialized
= 1;
113 debugInit(UART16550_BAUD_38400
,
115 UART16550_PARITY_NONE
, UART16550_STOP_1BIT
);
118 while ((UART16550_READ(OFS_LINE_STATUS
) & 0x20) == 0);
119 UART16550_WRITE(OFS_SEND_BUFFER
, byte
);