debug-macro.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * arch/arm/mach-tegra/include/mach/debug-macro.S
  3. *
  4. * Copyright (C) 2010,2011 Google, Inc.
  5. * Copyright (C) 2011-2012 NVIDIA CORPORATION. All Rights Reserved.
  6. *
  7. * Author:
  8. * Colin Cross <ccross@google.com>
  9. * Erik Gilling <konkers@google.com>
  10. * Doug Anderson <dianders@chromium.org>
  11. * Stephen Warren <swarren@nvidia.com>
  12. *
  13. * Portions based on mach-omap2's debug-macro.S
  14. * Copyright (C) 1994-1999 Russell King
  15. *
  16. * This software is licensed under the terms of the GNU General Public
  17. * License version 2, as published by the Free Software Foundation, and
  18. * may be copied, distributed, and modified under those terms.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. */
  26. #include <linux/serial_reg.h>
  27. #define UART_SHIFT 2
  28. /* Physical addresses */
  29. #define TEGRA_CLK_RESET_BASE 0x60006000
  30. #define TEGRA_APB_MISC_BASE 0x70000000
  31. #define TEGRA_UARTA_BASE 0x70006000
  32. #define TEGRA_UARTB_BASE 0x70006040
  33. #define TEGRA_UARTC_BASE 0x70006200
  34. #define TEGRA_UARTD_BASE 0x70006300
  35. #define TEGRA_UARTE_BASE 0x70006400
  36. #define TEGRA_PMC_BASE 0x7000e400
  37. #define TEGRA_CLK_RST_DEVICES_L (TEGRA_CLK_RESET_BASE + 0x04)
  38. #define TEGRA_CLK_RST_DEVICES_H (TEGRA_CLK_RESET_BASE + 0x08)
  39. #define TEGRA_CLK_RST_DEVICES_U (TEGRA_CLK_RESET_BASE + 0x0c)
  40. #define TEGRA_CLK_OUT_ENB_L (TEGRA_CLK_RESET_BASE + 0x10)
  41. #define TEGRA_CLK_OUT_ENB_H (TEGRA_CLK_RESET_BASE + 0x14)
  42. #define TEGRA_CLK_OUT_ENB_U (TEGRA_CLK_RESET_BASE + 0x18)
  43. #define TEGRA_PMC_SCRATCH20 (TEGRA_PMC_BASE + 0xa0)
  44. #define TEGRA_APB_MISC_GP_HIDREV (TEGRA_APB_MISC_BASE + 0x804)
  45. /*
  46. * Must be 1MB-aligned since a 1MB mapping is used early on.
  47. * Must not overlap with regions in mach-tegra/io.c:tegra_io_desc[].
  48. */
  49. #define UART_VIRTUAL_BASE 0xfe100000
  50. #define checkuart(rp, rv, lhu, bit, uart) \
  51. /* Load address of CLK_RST register */ \
  52. movw rp, #TEGRA_CLK_RST_DEVICES_##lhu & 0xffff ; \
  53. movt rp, #TEGRA_CLK_RST_DEVICES_##lhu >> 16 ; \
  54. /* Load value from CLK_RST register */ \
  55. ldr rp, [rp, #0] ; \
  56. /* Test UART's reset bit */ \
  57. tst rp, #(1 << bit) ; \
  58. /* If set, can't use UART; jump to save no UART */ \
  59. bne 90f ; \
  60. /* Load address of CLK_OUT_ENB register */ \
  61. movw rp, #TEGRA_CLK_OUT_ENB_##lhu & 0xffff ; \
  62. movt rp, #TEGRA_CLK_OUT_ENB_##lhu >> 16 ; \
  63. /* Load value from CLK_OUT_ENB register */ \
  64. ldr rp, [rp, #0] ; \
  65. /* Test UART's clock enable bit */ \
  66. tst rp, #(1 << bit) ; \
  67. /* If clear, can't use UART; jump to save no UART */ \
  68. beq 90f ; \
  69. /* Passed all tests, load address of UART registers */ \
  70. movw rp, #TEGRA_UART##uart##_BASE & 0xffff ; \
  71. movt rp, #TEGRA_UART##uart##_BASE >> 16 ; \
  72. /* Jump to save UART address */ \
  73. b 91f
  74. .macro addruart, rp, rv, tmp
  75. adr \rp, 99f @ actual addr of 99f
  76. ldr \rv, [\rp] @ linked addr is stored there
  77. sub \rv, \rv, \rp @ offset between the two
  78. ldr \rp, [\rp, #4] @ linked tegra_uart_config
  79. sub \tmp, \rp, \rv @ actual tegra_uart_config
  80. ldr \rp, [\tmp] @ Load tegra_uart_config
  81. cmp \rp, #1 @ needs initialization?
  82. bne 100f @ no; go load the addresses
  83. mov \rv, #0 @ yes; record init is done
  84. str \rv, [\tmp]
  85. #ifdef CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA
  86. /* Check ODMDATA */
  87. 10: movw \rp, #TEGRA_PMC_SCRATCH20 & 0xffff
  88. movt \rp, #TEGRA_PMC_SCRATCH20 >> 16
  89. ldr \rp, [\rp, #0] @ Load PMC_SCRATCH20
  90. ubfx \rv, \rp, #18, #2 @ 19:18 are console type
  91. cmp \rv, #2 @ 2 and 3 mean DCC, UART
  92. beq 11f @ some boards swap the meaning
  93. cmp \rv, #3 @ so accept either
  94. bne 90f
  95. 11: ubfx \rv, \rp, #15, #3 @ 17:15 are UART ID
  96. cmp \rv, #0 @ UART 0?
  97. beq 20f
  98. cmp \rv, #1 @ UART 1?
  99. beq 21f
  100. cmp \rv, #2 @ UART 2?
  101. beq 22f
  102. cmp \rv, #3 @ UART 3?
  103. beq 23f
  104. cmp \rv, #4 @ UART 4?
  105. beq 24f
  106. b 90f @ invalid
  107. #endif
  108. #if defined(CONFIG_TEGRA_DEBUG_UARTA) || \
  109. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  110. /* Check UART A validity */
  111. 20: checkuart(\rp, \rv, L, 6, A)
  112. #endif
  113. #if defined(CONFIG_TEGRA_DEBUG_UARTB) || \
  114. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  115. /* Check UART B validity */
  116. 21: checkuart(\rp, \rv, L, 7, B)
  117. #endif
  118. #if defined(CONFIG_TEGRA_DEBUG_UARTC) || \
  119. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  120. /* Check UART C validity */
  121. 22: checkuart(\rp, \rv, H, 23, C)
  122. #endif
  123. #if defined(CONFIG_TEGRA_DEBUG_UARTD) || \
  124. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  125. /* Check UART D validity */
  126. 23: checkuart(\rp, \rv, U, 1, D)
  127. #endif
  128. #if defined(CONFIG_TEGRA_DEBUG_UARTE) || \
  129. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  130. /* Check UART E validity */
  131. 24:
  132. checkuart(\rp, \rv, U, 2, E)
  133. #endif
  134. /* No valid UART found */
  135. 90: mov \rp, #0
  136. /* fall through */
  137. /* Record whichever UART we chose */
  138. 91: str \rp, [\tmp, #4] @ Store in tegra_uart_phys
  139. cmp \rp, #0 @ Valid UART address?
  140. bne 92f @ Yes, go process it
  141. str \rp, [\tmp, #8] @ Store 0 in tegra_uart_virt
  142. b 100f @ Done
  143. 92: and \rv, \rp, #0xffffff @ offset within 1MB section
  144. add \rv, \rv, #UART_VIRTUAL_BASE
  145. str \rv, [\tmp, #8] @ Store in tegra_uart_virt
  146. movw \rv, #TEGRA_APB_MISC_GP_HIDREV & 0xffff
  147. movt \rv, #TEGRA_APB_MISC_GP_HIDREV >> 16
  148. ldr \rv, [\rv, #0] @ Load HIDREV
  149. ubfx \rv, \rv, #8, #8 @ 15:8 are SoC version
  150. cmp \rv, #0x20 @ Tegra20?
  151. moveq \rv, #0x75 @ Tegra20 divisor
  152. movne \rv, #0xdd @ Tegra30 divisor
  153. str \rv, [\tmp, #12] @ Save divisor to scratch
  154. /* uart[UART_LCR] = UART_LCR_WLEN8 | UART_LCR_DLAB; */
  155. mov \rv, #UART_LCR_WLEN8 | UART_LCR_DLAB
  156. str \rv, [\rp, #UART_LCR << UART_SHIFT]
  157. /* uart[UART_DLL] = div & 0xff; */
  158. ldr \rv, [\tmp, #12]
  159. and \rv, \rv, #0xff
  160. str \rv, [\rp, #UART_DLL << UART_SHIFT]
  161. /* uart[UART_DLM] = div >> 8; */
  162. ldr \rv, [\tmp, #12]
  163. lsr \rv, \rv, #8
  164. str \rv, [\rp, #UART_DLM << UART_SHIFT]
  165. /* uart[UART_LCR] = UART_LCR_WLEN8; */
  166. mov \rv, #UART_LCR_WLEN8
  167. str \rv, [\rp, #UART_LCR << UART_SHIFT]
  168. b 100f
  169. .align
  170. 99: .word .
  171. .word tegra_uart_config
  172. .ltorg
  173. /* Load previously selected UART address */
  174. 100: ldr \rp, [\tmp, #4] @ Load tegra_uart_phys
  175. ldr \rv, [\tmp, #8] @ Load tegra_uart_virt
  176. .endm
  177. /*
  178. * Code below is swiped from <asm/hardware/debug-8250.S>, but add an extra
  179. * check to make sure that the UART address is actually valid.
  180. */
  181. .macro senduart, rd, rx
  182. cmp \rx, #0
  183. strneb \rd, [\rx, #UART_TX << UART_SHIFT]
  184. 1001:
  185. .endm
  186. .macro busyuart, rd, rx
  187. cmp \rx, #0
  188. beq 1002f
  189. 1001: ldrb \rd, [\rx, #UART_LSR << UART_SHIFT]
  190. and \rd, \rd, #UART_LSR_TEMT | UART_LSR_THRE
  191. teq \rd, #UART_LSR_TEMT | UART_LSR_THRE
  192. bne 1001b
  193. 1002:
  194. .endm
  195. .macro waituart, rd, rx
  196. #ifdef FLOW_CONTROL
  197. cmp \rx, #0
  198. beq 1002f
  199. 1001: ldrb \rd, [\rx, #UART_MSR << UART_SHIFT]
  200. tst \rd, #UART_MSR_CTS
  201. beq 1001b
  202. 1002:
  203. #endif
  204. .endm