dbg_io.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include <linux/config.h>
  2. #ifdef CONFIG_KGDB
  3. /* --- CONFIG --- */
  4. /* we need uint32 uint8 */
  5. /* #include "types.h" */
  6. typedef unsigned char uint8;
  7. typedef unsigned int uint32;
  8. /* --- END OF CONFIG --- */
  9. #define UART16550_BAUD_2400 2400
  10. #define UART16550_BAUD_4800 4800
  11. #define UART16550_BAUD_9600 9600
  12. #define UART16550_BAUD_19200 19200
  13. #define UART16550_BAUD_38400 38400
  14. #define UART16550_BAUD_57600 57600
  15. #define UART16550_BAUD_115200 115200
  16. #define UART16550_PARITY_NONE 0
  17. #define UART16550_PARITY_ODD 0x08
  18. #define UART16550_PARITY_EVEN 0x18
  19. #define UART16550_PARITY_MARK 0x28
  20. #define UART16550_PARITY_SPACE 0x38
  21. #define UART16550_DATA_5BIT 0x0
  22. #define UART16550_DATA_6BIT 0x1
  23. #define UART16550_DATA_7BIT 0x2
  24. #define UART16550_DATA_8BIT 0x3
  25. #define UART16550_STOP_1BIT 0x0
  26. #define UART16550_STOP_2BIT 0x4
  27. /* ----------------------------------------------------- */
  28. /* === CONFIG === */
  29. /* [stevel] we use the IT8712 serial port for kgdb */
  30. #define DEBUG_BASE 0xB40003F8 /* 8712 serial port 1 base address */
  31. #define MAX_BAUD 115200
  32. /* === END OF CONFIG === */
  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
  38. #define OFS_INTR_ID 2
  39. #define OFS_DATA_FORMAT 3
  40. #define OFS_LINE_CONTROL 3
  41. #define OFS_MODEM_CONTROL 4
  42. #define OFS_RS232_OUTPUT 4
  43. #define OFS_LINE_STATUS 5
  44. #define OFS_MODEM_STATUS 6
  45. #define OFS_RS232_INPUT 6
  46. #define OFS_SCRATCH_PAD 7
  47. #define OFS_DIVISOR_LSB 0
  48. #define OFS_DIVISOR_MSB 1
  49. /* memory-mapped read/write of the port */
  50. #define UART16550_READ(y) (*((volatile uint8*)(DEBUG_BASE + y)))
  51. #define UART16550_WRITE(y,z) ((*((volatile uint8*)(DEBUG_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_115200,
  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_115200,
  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