dbg_io.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright 2003 PMC-Sierra
  3. * Author: Manish Lachwani (lachwani@pmc-sierra.com)
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  11. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  13. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  14. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  15. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  16. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  17. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  18. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  19. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*
  26. * Support for KGDB for the Yosemite board. We make use of single serial
  27. * port to be used for KGDB as well as console. The second serial port
  28. * seems to be having a problem. Single IRQ is allocated for both the
  29. * ports. Hence, the interrupt routing code needs to figure out whether
  30. * the interrupt came from channel A or B.
  31. */
  32. #include <asm/serial.h>
  33. /*
  34. * Baud rate, Parity, Data and Stop bit settings for the
  35. * serial port on the Yosemite. Note that the Early printk
  36. * patch has been added. So, we should be all set to go
  37. */
  38. #define YOSEMITE_BAUD_2400 2400
  39. #define YOSEMITE_BAUD_4800 4800
  40. #define YOSEMITE_BAUD_9600 9600
  41. #define YOSEMITE_BAUD_19200 19200
  42. #define YOSEMITE_BAUD_38400 38400
  43. #define YOSEMITE_BAUD_57600 57600
  44. #define YOSEMITE_BAUD_115200 115200
  45. #define YOSEMITE_PARITY_NONE 0
  46. #define YOSEMITE_PARITY_ODD 0x08
  47. #define YOSEMITE_PARITY_EVEN 0x18
  48. #define YOSEMITE_PARITY_MARK 0x28
  49. #define YOSEMITE_PARITY_SPACE 0x38
  50. #define YOSEMITE_DATA_5BIT 0x0
  51. #define YOSEMITE_DATA_6BIT 0x1
  52. #define YOSEMITE_DATA_7BIT 0x2
  53. #define YOSEMITE_DATA_8BIT 0x3
  54. #define YOSEMITE_STOP_1BIT 0x0
  55. #define YOSEMITE_STOP_2BIT 0x4
  56. /* This is crucial */
  57. #define SERIAL_REG_OFS 0x1
  58. #define SERIAL_RCV_BUFFER 0x0
  59. #define SERIAL_TRANS_HOLD 0x0
  60. #define SERIAL_SEND_BUFFER 0x0
  61. #define SERIAL_INTR_ENABLE (1 * SERIAL_REG_OFS)
  62. #define SERIAL_INTR_ID (2 * SERIAL_REG_OFS)
  63. #define SERIAL_DATA_FORMAT (3 * SERIAL_REG_OFS)
  64. #define SERIAL_LINE_CONTROL (3 * SERIAL_REG_OFS)
  65. #define SERIAL_MODEM_CONTROL (4 * SERIAL_REG_OFS)
  66. #define SERIAL_RS232_OUTPUT (4 * SERIAL_REG_OFS)
  67. #define SERIAL_LINE_STATUS (5 * SERIAL_REG_OFS)
  68. #define SERIAL_MODEM_STATUS (6 * SERIAL_REG_OFS)
  69. #define SERIAL_RS232_INPUT (6 * SERIAL_REG_OFS)
  70. #define SERIAL_SCRATCH_PAD (7 * SERIAL_REG_OFS)
  71. #define SERIAL_DIVISOR_LSB (0 * SERIAL_REG_OFS)
  72. #define SERIAL_DIVISOR_MSB (1 * SERIAL_REG_OFS)
  73. /*
  74. * Functions to READ and WRITE to serial port 0
  75. */
  76. #define SERIAL_READ(ofs) (*((volatile unsigned char*) \
  77. (TITAN_SERIAL_BASE + ofs)))
  78. #define SERIAL_WRITE(ofs, val) ((*((volatile unsigned char*) \
  79. (TITAN_SERIAL_BASE + ofs))) = val)
  80. /*
  81. * Functions to READ and WRITE to serial port 1
  82. */
  83. #define SERIAL_READ_1(ofs) (*((volatile unsigned char*) \
  84. (TITAN_SERIAL_BASE_1 + ofs)
  85. #define SERIAL_WRITE_1(ofs, val) ((*((volatile unsigned char*) \
  86. (TITAN_SERIAL_BASE_1 + ofs))) = val)
  87. /*
  88. * Second serial port initialization
  89. */
  90. void init_second_port(void)
  91. {
  92. /* Disable Interrupts */
  93. SERIAL_WRITE_1(SERIAL_LINE_CONTROL, 0x0);
  94. SERIAL_WRITE_1(SERIAL_INTR_ENABLE, 0x0);
  95. {
  96. unsigned int divisor;
  97. SERIAL_WRITE_1(SERIAL_LINE_CONTROL, 0x80);
  98. divisor = TITAN_SERIAL_BASE_BAUD / YOSEMITE_BAUD_115200;
  99. SERIAL_WRITE_1(SERIAL_DIVISOR_LSB, divisor & 0xff);
  100. SERIAL_WRITE_1(SERIAL_DIVISOR_MSB,
  101. (divisor & 0xff00) >> 8);
  102. SERIAL_WRITE_1(SERIAL_LINE_CONTROL, 0x0);
  103. }
  104. SERIAL_WRITE_1(SERIAL_DATA_FORMAT, YOSEMITE_DATA_8BIT |
  105. YOSEMITE_PARITY_NONE | YOSEMITE_STOP_1BIT);
  106. /* Enable Interrupts */
  107. SERIAL_WRITE_1(SERIAL_INTR_ENABLE, 0xf);
  108. }
  109. /* Initialize the serial port for KGDB debugging */
  110. void debugInit(unsigned int baud, unsigned char data, unsigned char parity,
  111. unsigned char stop)
  112. {
  113. /* Disable Interrupts */
  114. SERIAL_WRITE(SERIAL_LINE_CONTROL, 0x0);
  115. SERIAL_WRITE(SERIAL_INTR_ENABLE, 0x0);
  116. {
  117. unsigned int divisor;
  118. SERIAL_WRITE(SERIAL_LINE_CONTROL, 0x80);
  119. divisor = TITAN_SERIAL_BASE_BAUD / baud;
  120. SERIAL_WRITE(SERIAL_DIVISOR_LSB, divisor & 0xff);
  121. SERIAL_WRITE(SERIAL_DIVISOR_MSB, (divisor & 0xff00) >> 8);
  122. SERIAL_WRITE(SERIAL_LINE_CONTROL, 0x0);
  123. }
  124. SERIAL_WRITE(SERIAL_DATA_FORMAT, data | parity | stop);
  125. }
  126. static int remoteDebugInitialized = 0;
  127. unsigned char getDebugChar(void)
  128. {
  129. if (!remoteDebugInitialized) {
  130. remoteDebugInitialized = 1;
  131. debugInit(YOSEMITE_BAUD_115200,
  132. YOSEMITE_DATA_8BIT,
  133. YOSEMITE_PARITY_NONE, YOSEMITE_STOP_1BIT);
  134. }
  135. while ((SERIAL_READ(SERIAL_LINE_STATUS) & 0x1) == 0);
  136. return SERIAL_READ(SERIAL_RCV_BUFFER);
  137. }
  138. int putDebugChar(unsigned char byte)
  139. {
  140. if (!remoteDebugInitialized) {
  141. remoteDebugInitialized = 1;
  142. debugInit(YOSEMITE_BAUD_115200,
  143. YOSEMITE_DATA_8BIT,
  144. YOSEMITE_PARITY_NONE, YOSEMITE_STOP_1BIT);
  145. }
  146. while ((SERIAL_READ(SERIAL_LINE_STATUS) & 0x20) == 0);
  147. SERIAL_WRITE(SERIAL_SEND_BUFFER, byte);
  148. return 1;
  149. }