dbg_io.c 3.7 KB

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