[AGPGART] VIA and SiS AGP chipsets are x86-only
[linux-drm-fsl-dcu.git] / arch / mips / ite-boards / generic / dbg_io.c
1
2
3 #ifdef CONFIG_KGDB
4
5 /* --- CONFIG --- */
6
7 /* we need uint32 uint8 */
8 /* #include "types.h" */
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 /* [stevel] we use the IT8712 serial port for kgdb */
41 #define DEBUG_BASE  0xB40003F8  /* 8712 serial port 1 base address */
42 #define MAX_BAUD    115200
43
44 /* === END OF CONFIG === */
45
46 /* register offset */
47 #define         OFS_RCV_BUFFER          0
48 #define         OFS_TRANS_HOLD          0
49 #define         OFS_SEND_BUFFER         0
50 #define         OFS_INTR_ENABLE         1
51 #define         OFS_INTR_ID             2
52 #define         OFS_DATA_FORMAT         3
53 #define         OFS_LINE_CONTROL        3
54 #define         OFS_MODEM_CONTROL       4
55 #define         OFS_RS232_OUTPUT        4
56 #define         OFS_LINE_STATUS         5
57 #define         OFS_MODEM_STATUS        6
58 #define         OFS_RS232_INPUT         6
59 #define         OFS_SCRATCH_PAD         7
60
61 #define         OFS_DIVISOR_LSB         0
62 #define         OFS_DIVISOR_MSB         1
63
64
65 /* memory-mapped read/write of the port */
66 #define UART16550_READ(y)    (*((volatile uint8*)(DEBUG_BASE + y)))
67 #define UART16550_WRITE(y,z) ((*((volatile uint8*)(DEBUG_BASE + y))) = z)
68
69 void debugInit(uint32 baud, uint8 data, uint8 parity, uint8 stop)
70 {
71         /* disable interrupts */
72         UART16550_WRITE(OFS_INTR_ENABLE, 0);
73
74         /* set up baud rate */
75         {
76                 uint32 divisor;
77
78                 /* set DIAB bit */
79                 UART16550_WRITE(OFS_LINE_CONTROL, 0x80);
80
81                 /* set divisor */
82                 divisor = MAX_BAUD / baud;
83                 UART16550_WRITE(OFS_DIVISOR_LSB, divisor & 0xff);
84                 UART16550_WRITE(OFS_DIVISOR_MSB, (divisor & 0xff00) >> 8);
85
86                 /* clear DIAB bit */
87                 UART16550_WRITE(OFS_LINE_CONTROL, 0x0);
88         }
89
90         /* set data format */
91         UART16550_WRITE(OFS_DATA_FORMAT, data | parity | stop);
92 }
93
94 static int remoteDebugInitialized = 0;
95
96 uint8 getDebugChar(void)
97 {
98         if (!remoteDebugInitialized) {
99                 remoteDebugInitialized = 1;
100                 debugInit(UART16550_BAUD_115200,
101                           UART16550_DATA_8BIT,
102                           UART16550_PARITY_NONE, UART16550_STOP_1BIT);
103         }
104
105         while ((UART16550_READ(OFS_LINE_STATUS) & 0x1) == 0);
106         return UART16550_READ(OFS_RCV_BUFFER);
107 }
108
109
110 int putDebugChar(uint8 byte)
111 {
112         if (!remoteDebugInitialized) {
113                 remoteDebugInitialized = 1;
114                 debugInit(UART16550_BAUD_115200,
115                           UART16550_DATA_8BIT,
116                           UART16550_PARITY_NONE, UART16550_STOP_1BIT);
117         }
118
119         while ((UART16550_READ(OFS_LINE_STATUS) & 0x20) == 0);
120         UART16550_WRITE(OFS_SEND_BUFFER, byte);
121         return 1;
122 }
123
124 #endif