tegra.S 6.7 KB

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