dbg_io.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  4. * Copyright (C) 2000, 2001 Ralf Baechle (ralf@gnu.org)
  5. *
  6. * Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology
  7. * Author: Fuxin Zhang, zhangfx@lemote.com
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  15. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  17. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  20. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. * You should have received a copy of the GNU General Public License along
  26. * with this program; if not, write to the Free Software Foundation, Inc.,
  27. * 675 Mass Ave, Cambridge, MA 02139, USA.
  28. *
  29. */
  30. #include <linux/io.h>
  31. #include <linux/init.h>
  32. #include <linux/types.h>
  33. #include <asm/serial.h>
  34. #define UART16550_BAUD_2400 2400
  35. #define UART16550_BAUD_4800 4800
  36. #define UART16550_BAUD_9600 9600
  37. #define UART16550_BAUD_19200 19200
  38. #define UART16550_BAUD_38400 38400
  39. #define UART16550_BAUD_57600 57600
  40. #define UART16550_BAUD_115200 115200
  41. #define UART16550_PARITY_NONE 0
  42. #define UART16550_PARITY_ODD 0x08
  43. #define UART16550_PARITY_EVEN 0x18
  44. #define UART16550_PARITY_MARK 0x28
  45. #define UART16550_PARITY_SPACE 0x38
  46. #define UART16550_DATA_5BIT 0x0
  47. #define UART16550_DATA_6BIT 0x1
  48. #define UART16550_DATA_7BIT 0x2
  49. #define UART16550_DATA_8BIT 0x3
  50. #define UART16550_STOP_1BIT 0x0
  51. #define UART16550_STOP_2BIT 0x4
  52. /* ----------------------------------------------------- */
  53. /* === CONFIG === */
  54. #ifdef CONFIG_64BIT
  55. #define BASE (0xffffffffbfd003f8)
  56. #else
  57. #define BASE (0xbfd003f8)
  58. #endif
  59. #define MAX_BAUD BASE_BAUD
  60. /* === END OF CONFIG === */
  61. #define REG_OFFSET 1
  62. /* register offset */
  63. #define OFS_RCV_BUFFER 0
  64. #define OFS_TRANS_HOLD 0
  65. #define OFS_SEND_BUFFER 0
  66. #define OFS_INTR_ENABLE (1*REG_OFFSET)
  67. #define OFS_INTR_ID (2*REG_OFFSET)
  68. #define OFS_DATA_FORMAT (3*REG_OFFSET)
  69. #define OFS_LINE_CONTROL (3*REG_OFFSET)
  70. #define OFS_MODEM_CONTROL (4*REG_OFFSET)
  71. #define OFS_RS232_OUTPUT (4*REG_OFFSET)
  72. #define OFS_LINE_STATUS (5*REG_OFFSET)
  73. #define OFS_MODEM_STATUS (6*REG_OFFSET)
  74. #define OFS_RS232_INPUT (6*REG_OFFSET)
  75. #define OFS_SCRATCH_PAD (7*REG_OFFSET)
  76. #define OFS_DIVISOR_LSB (0*REG_OFFSET)
  77. #define OFS_DIVISOR_MSB (1*REG_OFFSET)
  78. /* memory-mapped read/write of the port */
  79. #define UART16550_READ(y) readb((char *)BASE + (y))
  80. #define UART16550_WRITE(y, z) writeb(z, (char *)BASE + (y))
  81. void debugInit(u32 baud, u8 data, u8 parity, u8 stop)
  82. {
  83. u32 divisor;
  84. /* disable interrupts */
  85. UART16550_WRITE(OFS_INTR_ENABLE, 0);
  86. /* set up buad rate */
  87. /* set DIAB bit */
  88. UART16550_WRITE(OFS_LINE_CONTROL, 0x80);
  89. /* set divisor */
  90. divisor = MAX_BAUD / baud;
  91. UART16550_WRITE(OFS_DIVISOR_LSB, divisor & 0xff);
  92. UART16550_WRITE(OFS_DIVISOR_MSB, (divisor & 0xff00) >> 8);
  93. /* clear DIAB bit */
  94. UART16550_WRITE(OFS_LINE_CONTROL, 0x0);
  95. /* set data format */
  96. UART16550_WRITE(OFS_DATA_FORMAT, data | parity | stop);
  97. }
  98. static int remoteDebugInitialized;
  99. u8 getDebugChar(void)
  100. {
  101. if (!remoteDebugInitialized) {
  102. remoteDebugInitialized = 1;
  103. debugInit(UART16550_BAUD_115200,
  104. UART16550_DATA_8BIT,
  105. UART16550_PARITY_NONE, UART16550_STOP_1BIT);
  106. }
  107. while ((UART16550_READ(OFS_LINE_STATUS) & 0x1) == 0) ;
  108. return UART16550_READ(OFS_RCV_BUFFER);
  109. }
  110. int putDebugChar(u8 byte)
  111. {
  112. if (!remoteDebugInitialized) {
  113. remoteDebugInitialized = 1;
  114. /*
  115. debugInit(UART16550_BAUD_115200,
  116. UART16550_DATA_8BIT,
  117. UART16550_PARITY_NONE, UART16550_STOP_1BIT); */
  118. }
  119. while ((UART16550_READ(OFS_LINE_STATUS) & 0x20) == 0) ;
  120. UART16550_WRITE(OFS_SEND_BUFFER, byte);
  121. return 1;
  122. }