tegra.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 1MB-aligned since a 1MB 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 0xfe100000
  48. #define checkuart(rp, rv, lhu, bit, uart) \
  49. /* Load address of CLK_RST register */ \
  50. movw rp, #TEGRA_CLK_RST_DEVICES_##lhu & 0xffff ; \
  51. movt rp, #TEGRA_CLK_RST_DEVICES_##lhu >> 16 ; \
  52. /* Load value from CLK_RST register */ \
  53. ldr rp, [rp, #0] ; \
  54. /* Test UART's reset bit */ \
  55. tst rp, #(1 << bit) ; \
  56. /* If set, can't use UART; jump to save no UART */ \
  57. bne 90f ; \
  58. /* Load address of CLK_OUT_ENB register */ \
  59. movw rp, #TEGRA_CLK_OUT_ENB_##lhu & 0xffff ; \
  60. movt rp, #TEGRA_CLK_OUT_ENB_##lhu >> 16 ; \
  61. /* Load value from CLK_OUT_ENB register */ \
  62. ldr rp, [rp, #0] ; \
  63. /* Test UART's clock enable bit */ \
  64. tst rp, #(1 << bit) ; \
  65. /* If clear, can't use UART; jump to save no UART */ \
  66. beq 90f ; \
  67. /* Passed all tests, load address of UART registers */ \
  68. movw rp, #TEGRA_UART##uart##_BASE & 0xffff ; \
  69. movt rp, #TEGRA_UART##uart##_BASE >> 16 ; \
  70. /* Jump to save UART address */ \
  71. b 91f
  72. .macro addruart, rp, rv, tmp
  73. adr \rp, 99f @ actual addr of 99f
  74. ldr \rv, [\rp] @ linked addr is stored there
  75. sub \rv, \rv, \rp @ offset between the two
  76. ldr \rp, [\rp, #4] @ linked tegra_uart_config
  77. sub \tmp, \rp, \rv @ actual tegra_uart_config
  78. ldr \rp, [\tmp] @ Load tegra_uart_config
  79. cmp \rp, #1 @ needs initialization?
  80. bne 100f @ no; go load the addresses
  81. mov \rv, #0 @ yes; record init is done
  82. str \rv, [\tmp]
  83. #ifdef CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA
  84. /* Check ODMDATA */
  85. 10: movw \rp, #TEGRA_PMC_SCRATCH20 & 0xffff
  86. movt \rp, #TEGRA_PMC_SCRATCH20 >> 16
  87. ldr \rp, [\rp, #0] @ Load PMC_SCRATCH20
  88. ubfx \rv, \rp, #18, #2 @ 19:18 are console type
  89. cmp \rv, #2 @ 2 and 3 mean DCC, UART
  90. beq 11f @ some boards swap the meaning
  91. cmp \rv, #3 @ so accept either
  92. bne 90f
  93. 11: ubfx \rv, \rp, #15, #3 @ 17:15 are UART ID
  94. cmp \rv, #0 @ UART 0?
  95. beq 20f
  96. cmp \rv, #1 @ UART 1?
  97. beq 21f
  98. cmp \rv, #2 @ UART 2?
  99. beq 22f
  100. cmp \rv, #3 @ UART 3?
  101. beq 23f
  102. cmp \rv, #4 @ UART 4?
  103. beq 24f
  104. b 90f @ invalid
  105. #endif
  106. #if defined(CONFIG_TEGRA_DEBUG_UARTA) || \
  107. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  108. /* Check UART A validity */
  109. 20: checkuart(\rp, \rv, L, 6, A)
  110. #endif
  111. #if defined(CONFIG_TEGRA_DEBUG_UARTB) || \
  112. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  113. /* Check UART B validity */
  114. 21: checkuart(\rp, \rv, L, 7, B)
  115. #endif
  116. #if defined(CONFIG_TEGRA_DEBUG_UARTC) || \
  117. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  118. /* Check UART C validity */
  119. 22: checkuart(\rp, \rv, H, 23, C)
  120. #endif
  121. #if defined(CONFIG_TEGRA_DEBUG_UARTD) || \
  122. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  123. /* Check UART D validity */
  124. 23: checkuart(\rp, \rv, U, 1, D)
  125. #endif
  126. #if defined(CONFIG_TEGRA_DEBUG_UARTE) || \
  127. defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)
  128. /* Check UART E validity */
  129. 24:
  130. checkuart(\rp, \rv, U, 2, E)
  131. #endif
  132. /* No valid UART found */
  133. 90: mov \rp, #0
  134. /* fall through */
  135. /* Record whichever UART we chose */
  136. 91: str \rp, [\tmp, #4] @ Store in tegra_uart_phys
  137. cmp \rp, #0 @ Valid UART address?
  138. bne 92f @ Yes, go process it
  139. str \rp, [\tmp, #8] @ Store 0 in tegra_uart_virt
  140. b 100f @ Done
  141. 92: and \rv, \rp, #0xffffff @ offset within 1MB section
  142. add \rv, \rv, #UART_VIRTUAL_BASE
  143. str \rv, [\tmp, #8] @ Store in tegra_uart_virt
  144. movw \rv, #TEGRA_APB_MISC_GP_HIDREV & 0xffff
  145. movt \rv, #TEGRA_APB_MISC_GP_HIDREV >> 16
  146. ldr \rv, [\rv, #0] @ Load HIDREV
  147. ubfx \rv, \rv, #8, #8 @ 15:8 are SoC version
  148. cmp \rv, #0x20 @ Tegra20?
  149. moveq \rv, #0x75 @ Tegra20 divisor
  150. movne \rv, #0xdd @ Tegra30 divisor
  151. str \rv, [\tmp, #12] @ Save divisor to scratch
  152. /* uart[UART_LCR] = UART_LCR_WLEN8 | UART_LCR_DLAB; */
  153. mov \rv, #UART_LCR_WLEN8 | UART_LCR_DLAB
  154. str \rv, [\rp, #UART_LCR << UART_SHIFT]
  155. /* uart[UART_DLL] = div & 0xff; */
  156. ldr \rv, [\tmp, #12]
  157. and \rv, \rv, #0xff
  158. str \rv, [\rp, #UART_DLL << UART_SHIFT]
  159. /* uart[UART_DLM] = div >> 8; */
  160. ldr \rv, [\tmp, #12]
  161. lsr \rv, \rv, #8
  162. str \rv, [\rp, #UART_DLM << UART_SHIFT]
  163. /* uart[UART_LCR] = UART_LCR_WLEN8; */
  164. mov \rv, #UART_LCR_WLEN8
  165. str \rv, [\rp, #UART_LCR << UART_SHIFT]
  166. b 100f
  167. .align
  168. 99: .word .
  169. .word tegra_uart_config
  170. .ltorg
  171. /* Load previously selected UART address */
  172. 100: ldr \rp, [\tmp, #4] @ Load tegra_uart_phys
  173. ldr \rv, [\tmp, #8] @ Load tegra_uart_virt
  174. .endm
  175. /*
  176. * Code below is swiped from <asm/hardware/debug-8250.S>, but add an extra
  177. * check to make sure that the UART address is actually valid.
  178. */
  179. .macro senduart, rd, rx
  180. cmp \rx, #0
  181. strneb \rd, [\rx, #UART_TX << UART_SHIFT]
  182. 1001:
  183. .endm
  184. .macro busyuart, rd, rx
  185. cmp \rx, #0
  186. beq 1002f
  187. 1001: ldrb \rd, [\rx, #UART_LSR << UART_SHIFT]
  188. and \rd, \rd, #UART_LSR_TEMT | UART_LSR_THRE
  189. teq \rd, #UART_LSR_TEMT | UART_LSR_THRE
  190. bne 1001b
  191. 1002:
  192. .endm
  193. .macro waituart, rd, rx
  194. #ifdef FLOW_CONTROL
  195. cmp \rx, #0
  196. beq 1002f
  197. 1001: ldrb \rd, [\rx, #UART_MSR << UART_SHIFT]
  198. tst \rd, #UART_MSR_CTS
  199. beq 1001b
  200. 1002:
  201. #endif
  202. .endm