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