Linux-2.6.12-rc2
[deliverable/linux.git] / arch / mips / momentum / ocelot_c / dbg_io.c
1 #include <linux/config.h>
2
3 #ifdef CONFIG_KGDB
4
5 #include <asm/serial.h> /* For the serial port location and base baud */
6
7 /* --- CONFIG --- */
8
9 typedef unsigned char uint8;
10 typedef unsigned int uint32;
11
12 /* --- END OF CONFIG --- */
13
14 #define UART16550_BAUD_2400 2400
15 #define UART16550_BAUD_4800 4800
16 #define UART16550_BAUD_9600 9600
17 #define UART16550_BAUD_19200 19200
18 #define UART16550_BAUD_38400 38400
19 #define UART16550_BAUD_57600 57600
20 #define UART16550_BAUD_115200 115200
21
22 #define UART16550_PARITY_NONE 0
23 #define UART16550_PARITY_ODD 0x08
24 #define UART16550_PARITY_EVEN 0x18
25 #define UART16550_PARITY_MARK 0x28
26 #define UART16550_PARITY_SPACE 0x38
27
28 #define UART16550_DATA_5BIT 0x0
29 #define UART16550_DATA_6BIT 0x1
30 #define UART16550_DATA_7BIT 0x2
31 #define UART16550_DATA_8BIT 0x3
32
33 #define UART16550_STOP_1BIT 0x0
34 #define UART16550_STOP_2BIT 0x4
35
36 /* ----------------------------------------------------- */
37
38 /* === CONFIG === */
39
40 /* [jsun] we use the second serial port for kdb */
41 #define BASE OCELOT_SERIAL1_BASE
42 #define MAX_BAUD OCELOT_BASE_BAUD
43
44 /* === END OF CONFIG === */
45
46 #define REG_OFFSET 4
47
48 /* register offset */
49 #define OFS_RCV_BUFFER 0
50 #define OFS_TRANS_HOLD 0
51 #define OFS_SEND_BUFFER 0
52 #define OFS_INTR_ENABLE (1*REG_OFFSET)
53 #define OFS_INTR_ID (2*REG_OFFSET)
54 #define OFS_DATA_FORMAT (3*REG_OFFSET)
55 #define OFS_LINE_CONTROL (3*REG_OFFSET)
56 #define OFS_MODEM_CONTROL (4*REG_OFFSET)
57 #define OFS_RS232_OUTPUT (4*REG_OFFSET)
58 #define OFS_LINE_STATUS (5*REG_OFFSET)
59 #define OFS_MODEM_STATUS (6*REG_OFFSET)
60 #define OFS_RS232_INPUT (6*REG_OFFSET)
61 #define OFS_SCRATCH_PAD (7*REG_OFFSET)
62
63 #define OFS_DIVISOR_LSB (0*REG_OFFSET)
64 #define OFS_DIVISOR_MSB (1*REG_OFFSET)
65
66
67 /* memory-mapped read/write of the port */
68 #define UART16550_READ(y) (*((volatile uint8*)(BASE + y)))
69 #define UART16550_WRITE(y, z) ((*((volatile uint8*)(BASE + y))) = z)
70
71 void debugInit(uint32 baud, uint8 data, uint8 parity, uint8 stop)
72 {
73 /* disable interrupts */
74 UART16550_WRITE(OFS_INTR_ENABLE, 0);
75
76 /* set up buad rate */
77 {
78 uint32 divisor;
79
80 /* set DIAB bit */
81 UART16550_WRITE(OFS_LINE_CONTROL, 0x80);
82
83 /* set divisor */
84 divisor = MAX_BAUD / baud;
85 UART16550_WRITE(OFS_DIVISOR_LSB, divisor & 0xff);
86 UART16550_WRITE(OFS_DIVISOR_MSB, (divisor & 0xff00) >> 8);
87
88 /* clear DIAB bit */
89 UART16550_WRITE(OFS_LINE_CONTROL, 0x0);
90 }
91
92 /* set data format */
93 UART16550_WRITE(OFS_DATA_FORMAT, data | parity | stop);
94 }
95
96 static int remoteDebugInitialized = 0;
97
98 uint8 getDebugChar(void)
99 {
100 if (!remoteDebugInitialized) {
101 remoteDebugInitialized = 1;
102 debugInit(UART16550_BAUD_38400,
103 UART16550_DATA_8BIT,
104 UART16550_PARITY_NONE, UART16550_STOP_1BIT);
105 }
106
107 while ((UART16550_READ(OFS_LINE_STATUS) & 0x1) == 0);
108 return UART16550_READ(OFS_RCV_BUFFER);
109 }
110
111
112 int putDebugChar(uint8 byte)
113 {
114 if (!remoteDebugInitialized) {
115 remoteDebugInitialized = 1;
116 debugInit(UART16550_BAUD_38400,
117 UART16550_DATA_8BIT,
118 UART16550_PARITY_NONE, UART16550_STOP_1BIT);
119 }
120
121 while ((UART16550_READ(OFS_LINE_STATUS) & 0x20) == 0);
122 UART16550_WRITE(OFS_SEND_BUFFER, byte);
123 return 1;
124 }
125
126 #endif
This page took 0.040838 seconds and 5 git commands to generate.