tegra.S 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2010,2011 Google, Inc.
  4. * Copyright (C) 2011-2012 NVIDIA CORPORATION. All Rights Reserved.
  5. *
  6. * Author:
  7. * Colin Cross <[email protected]>
  8. * Erik Gilling <[email protected]>
  9. * Doug Anderson <[email protected]>
  10. * Stephen Warren <[email protected]>
  11. *
  12. * Portions based on mach-omap2's debug-macro.S
  13. * Copyright (C) 1994-1999 Russell King
  14. */
  15. #include <linux/serial_reg.h>
  16. #define UART_SHIFT 2
  17. /* Physical addresses */
  18. #define TEGRA_CLK_RESET_BASE 0x60006000
  19. #define TEGRA_APB_MISC_BASE 0x70000000
  20. #define TEGRA_UARTA_BASE 0x70006000
  21. #define TEGRA_UARTB_BASE 0x70006040
  22. #define TEGRA_UARTC_BASE 0x70006200
  23. #define TEGRA_UARTD_BASE 0x70006300
  24. #define TEGRA_UARTE_BASE 0x70006400
  25. #define TEGRA_PMC_BASE 0x7000e400
  26. #define TEGRA_CLK_RST_DEVICES_L (TEGRA_CLK_RESET_BASE + 0x04)
  27. #define TEGRA_CLK_RST_DEVICES_H (TEGRA_CLK_RESET_BASE + 0x08)
  28. #define TEGRA_CLK_RST_DEVICES_U (TEGRA_CLK_RESET_BASE + 0x0c)
  29. #define TEGRA_CLK_OUT_ENB_L (TEGRA_CLK_RESET_BASE + 0x10)
  30. #define TEGRA_CLK_OUT_ENB_H (TEGRA_CLK_RESET_BASE + 0x14)
  31. #define TEGRA_CLK_OUT_ENB_U (TEGRA_CLK_RESET_BASE + 0x18)
  32. #define TEGRA_PMC_SCRATCH20 (TEGRA_PMC_BASE + 0xa0)
  33. #define TEGRA_APB_MISC_GP_HIDREV (TEGRA_APB_MISC_BASE + 0x804)
  34. /*
  35. * Must be section-aligned since a section mapping is used early on.
  36. * Must not overlap with regions in mach-tegra/io.c:tegra_io_desc[].
  37. */
  38. #define UART_VIRTUAL_BASE 0xfe800000
  39. #define checkuart(rp, rv, lhu, bit, uart) \
  40. /* Load address of CLK_RST register */ \
  41. ldr rp, =TEGRA_CLK_RST_DEVICES_##lhu ; \
  42. /* Load value from CLK_RST register */ \
  43. ldr rp, [rp, #0] ; \
  44. /* Test UART's reset bit */ \
  45. tst rp, #(1 << bit) ; \
  46. /* If set, can't use UART; jump to save no UART */ \
  47. bne 90f ; \
  48. /* Load address of CLK_OUT_ENB register */ \
  49. ldr rp, =TEGRA_CLK_OUT_ENB_##lhu ; \
  50. /* Load value from CLK_OUT_ENB register */ \
  51. ldr rp, [rp, #0] ; \
  52. /* Test UART's clock enable bit */ \
  53. tst rp, #(1 << bit) ; \
  54. /* If clear, can't use UART; jump to save no UART */ \
  55. beq 90f ; \
  56. /* Passed all tests, load address of UART registers */ \
  57. ldr rp, =TEGRA_UART##uart##_BASE ; \
  58. /* Jump to save UART address */ \
  59. b 91f
  60. .macro addruart, rp, rv, tmp
  61. adr \rp, 99f @ actual addr of 99f
  62. ldr \rv, [\rp] @ linked addr is stored there
  63. sub \rv, \rv, \rp @ offset between the two
  64. ldr \rp, [\rp, #4] @ linked tegra_uart_config
  65. sub \tmp, \rp, \rv @ actual tegra_uart_config
  66. ldr \rp, [\tmp] @ Load tegra_uart_config
  67. cmp \rp, #1 @ needs initialization?
  68. bne 100f @ no; go load the addresses
  69. mov \rv, #0 @ yes; record init is done
  70. str \rv, [\tmp]
  71. #ifdef CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA
  72. /* Check ODMDATA */
  73. 10: ldr \rp, =TEGRA_PMC_SCRATCH20
  74. ldr \rp, [\rp, #0] @ Load PMC_SCRATCH20
  75. lsr \rv, \rp, #18 @ 19:18 are console type
  76. and \rv, \rv, #3
  77. cmp \rv, #2 @ 2 and 3 mean DCC, UART
  78. beq 11f @ some boards swap the meaning
  79. cmp \rv, #3 @ so accept either
  80. bne 90f
  81. 11: lsr \rv, \rp, #15 @ 17:15 are UART ID
  82. and \rv, #7
  83. cmp \rv, #0 @ UART 0?
  84. beq 20f
  85. cmp \rv, #1 @ UART 1?
  86. beq 21f
  87. cmp \rv, #2 @ UART 2?
  88. beq 22f
  89. cmp \rv, #3 @ UART 3?
  90. beq 23f
  91. cmp \rv, #4 @ UART 4?
  92. beq 24f
  93. b 90f @ invalid
  94. #endif
  95. #if defined(CONFIG_TEGRA_DEBUG_UARTA) || \
  96. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  97. /* Check UART A validity */
  98. 20: checkuart(\rp, \rv, L, 6, A)
  99. #endif
  100. #if defined(CONFIG_TEGRA_DEBUG_UARTB) || \
  101. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  102. /* Check UART B validity */
  103. 21: checkuart(\rp, \rv, L, 7, B)
  104. #endif
  105. #if defined(CONFIG_TEGRA_DEBUG_UARTC) || \
  106. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  107. /* Check UART C validity */
  108. 22: checkuart(\rp, \rv, H, 23, C)
  109. #endif
  110. #if defined(CONFIG_TEGRA_DEBUG_UARTD) || \
  111. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  112. /* Check UART D validity */
  113. 23: checkuart(\rp, \rv, U, 1, D)
  114. #endif
  115. #if defined(CONFIG_TEGRA_DEBUG_UARTE) || \
  116. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  117. /* Check UART E validity */
  118. 24:
  119. checkuart(\rp, \rv, U, 2, E)
  120. #endif
  121. /* No valid UART found */
  122. 90: mov \rp, #0
  123. /* fall through */
  124. /* Record whichever UART we chose */
  125. 91: str \rp, [\tmp, #4] @ Store in tegra_uart_phys
  126. cmp \rp, #0 @ Valid UART address?
  127. bne 92f @ Yes, go process it
  128. str \rp, [\tmp, #8] @ Store 0 in tegra_uart_virt
  129. b 100f @ Done
  130. 92: and \rv, \rp, #0xffffff @ offset within 1MB section
  131. add \rv, \rv, #UART_VIRTUAL_BASE
  132. str \rv, [\tmp, #8] @ Store in tegra_uart_virt
  133. b 100f
  134. .align
  135. 99: .word .
  136. #if defined(ZIMAGE)
  137. .word . + 4
  138. /*
  139. * Storage for the state maintained by the macro.
  140. *
  141. * In the kernel proper, this data is located in arch/arm/mach-tegra/tegra.c.
  142. * That's because this header is included from multiple files, and we only
  143. * want a single copy of the data. In particular, the UART probing code above
  144. * assumes it's running using physical addresses. This is true when this file
  145. * is included from head.o, but not when included from debug.o. So we need
  146. * to share the probe results between the two copies, rather than having
  147. * to re-run the probing again later.
  148. *
  149. * In the decompressor, we put the storage right here, since common.c
  150. * isn't included in the decompressor build. This storage data gets put in
  151. * .text even though it's really data, since .data is discarded from the
  152. * decompressor. Luckily, .text is writeable in the decompressor, unless
  153. * CONFIG_ZBOOT_ROM. That dependency is handled in arch/arm/Kconfig.debug.
  154. */
  155. /* Debug UART initialization required */
  156. .word 1
  157. /* Debug UART physical address */
  158. .word 0
  159. /* Debug UART virtual address */
  160. .word 0
  161. #else
  162. .word tegra_uart_config
  163. #endif
  164. .ltorg
  165. /* Load previously selected UART address */
  166. 100: ldr \rp, [\tmp, #4] @ Load tegra_uart_phys
  167. ldr \rv, [\tmp, #8] @ Load tegra_uart_virt
  168. .endm
  169. /*
  170. * Code below is swiped from <asm/hardware/debug-8250.S>, but add an extra
  171. * check to make sure that the UART address is actually valid.
  172. */
  173. .macro senduart, rd, rx
  174. cmp \rx, #0
  175. strbne \rd, [\rx, #UART_TX << UART_SHIFT]
  176. 1001:
  177. .endm
  178. .macro busyuart, rd, rx
  179. cmp \rx, #0
  180. beq 1002f
  181. 1001: ldrb \rd, [\rx, #UART_LSR << UART_SHIFT]
  182. and \rd, \rd, #UART_LSR_THRE
  183. teq \rd, #UART_LSR_THRE
  184. bne 1001b
  185. 1002:
  186. .endm
  187. .macro waituartcts, rd, rx
  188. cmp \rx, #0
  189. beq 1002f
  190. 1001: ldrb \rd, [\rx, #UART_MSR << UART_SHIFT]
  191. tst \rd, #UART_MSR_CTS
  192. beq 1001b
  193. 1002:
  194. .endm
  195. .macro waituarttxrdy,rd,rx
  196. .endm