brcmstb.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (C) 2016 Broadcom */
  3. #include <linux/serial_reg.h>
  4. #include <asm/cputype.h>
  5. /* Physical register offset and virtual register offset */
  6. #define REG_PHYS_BASE 0xf0000000
  7. #define REG_PHYS_BASE_V7 0x08000000
  8. #define REG_VIRT_BASE 0xfc000000
  9. #define REG_PHYS_ADDR(x) ((x) + REG_PHYS_BASE)
  10. #define REG_PHYS_ADDR_V7(x) ((x) + REG_PHYS_BASE_V7)
  11. /* Product id can be read from here */
  12. #define SUN_TOP_CTRL_BASE REG_PHYS_ADDR(0x404000)
  13. #define SUN_TOP_CTRL_BASE_V7 REG_PHYS_ADDR_V7(0x404000)
  14. #define UARTA_3390 REG_PHYS_ADDR(0x40a900)
  15. #define UARTA_72116 UARTA_7255
  16. #define UARTA_7250 REG_PHYS_ADDR(0x40b400)
  17. #define UARTA_7255 REG_PHYS_ADDR(0x40c000)
  18. #define UARTA_7260 UARTA_7255
  19. #define UARTA_7268 UARTA_7255
  20. #define UARTA_7271 UARTA_7268
  21. #define UARTA_7278 REG_PHYS_ADDR_V7(0x40c000)
  22. #define UARTA_7216 UARTA_7278
  23. #define UARTA_72164 UARTA_7278
  24. #define UARTA_72165 UARTA_7278
  25. #define UARTA_7364 REG_PHYS_ADDR(0x40b000)
  26. #define UARTA_7366 UARTA_7364
  27. #define UARTA_74165 UARTA_7278
  28. #define UARTA_74371 REG_PHYS_ADDR(0x406b00)
  29. #define UARTA_7439 REG_PHYS_ADDR(0x40a900)
  30. #define UARTA_7445 REG_PHYS_ADDR(0x40ab00)
  31. #define UART_SHIFT 2
  32. #define checkuart(rp, rv, family_id, family) \
  33. /* Load family id */ \
  34. ldr rp, =family_id ; \
  35. /* Compare SUN_TOP_CTRL value against it */ \
  36. cmp rp, rv ; \
  37. /* Passed test, load address */ \
  38. ldreq rp, =UARTA_##family ; \
  39. /* Jump to save UART address */ \
  40. beq 91f
  41. .macro addruart, rp, rv, tmp
  42. adr \rp, 99f @ actual addr of 99f
  43. ldr \rv, [\rp] @ linked addr is stored there
  44. sub \rv, \rv, \rp @ offset between the two
  45. ldr \rp, [\rp, #4] @ linked brcmstb_uart_config
  46. sub \tmp, \rp, \rv @ actual brcmstb_uart_config
  47. ldr \rp, [\tmp] @ Load brcmstb_uart_config
  48. cmp \rp, #1 @ needs initialization?
  49. bne 100f @ no; go load the addresses
  50. mov \rv, #0 @ yes; record init is done
  51. str \rv, [\tmp]
  52. /* Check for V7 memory map if B53 */
  53. mrc p15, 0, \rv, c0, c0, 0 @ get Main ID register
  54. ldr \rp, =ARM_CPU_PART_MASK
  55. and \rv, \rv, \rp
  56. ldr \rp, =ARM_CPU_PART_BRAHMA_B53 @ check for B53 CPU
  57. cmp \rv, \rp
  58. bne 10f
  59. /* if PERIPHBASE doesn't overlap REG_PHYS_BASE use V7 map */
  60. mrc p15, 1, \rv, c15, c3, 0 @ get PERIPHBASE from CBAR
  61. ands \rv, \rv, #REG_PHYS_BASE
  62. ldreq \rp, =SUN_TOP_CTRL_BASE_V7
  63. /* Check SUN_TOP_CTRL base */
  64. 10: ldrne \rp, =SUN_TOP_CTRL_BASE @ load SUN_TOP_CTRL PA
  65. ldr \rv, [\rp, #0] @ get register contents
  66. ARM_BE8( rev \rv, \rv )
  67. and \rv, \rv, #0xffffff00 @ strip revision bits [7:0]
  68. /* Chip specific detection starts here */
  69. 20: checkuart(\rp, \rv, 0x33900000, 3390)
  70. 21: checkuart(\rp, \rv, 0x07211600, 72116)
  71. 22: checkuart(\rp, \rv, 0x72160000, 7216)
  72. 23: checkuart(\rp, \rv, 0x07216400, 72164)
  73. 24: checkuart(\rp, \rv, 0x07216500, 72165)
  74. 25: checkuart(\rp, \rv, 0x72500000, 7250)
  75. 26: checkuart(\rp, \rv, 0x72550000, 7255)
  76. 27: checkuart(\rp, \rv, 0x72600000, 7260)
  77. 28: checkuart(\rp, \rv, 0x72680000, 7268)
  78. 29: checkuart(\rp, \rv, 0x72710000, 7271)
  79. 30: checkuart(\rp, \rv, 0x72780000, 7278)
  80. 31: checkuart(\rp, \rv, 0x73640000, 7364)
  81. 32: checkuart(\rp, \rv, 0x73660000, 7366)
  82. 33: checkuart(\rp, \rv, 0x07416500, 74165)
  83. 34: checkuart(\rp, \rv, 0x07437100, 74371)
  84. 35: checkuart(\rp, \rv, 0x74390000, 7439)
  85. 36: checkuart(\rp, \rv, 0x74450000, 7445)
  86. /* No valid UART found */
  87. 90: mov \rp, #0
  88. /* fall through */
  89. /* Record whichever UART we chose */
  90. 91: str \rp, [\tmp, #4] @ Store in brcmstb_uart_phys
  91. cmp \rp, #0 @ Valid UART address?
  92. bne 92f @ Yes, go process it
  93. str \rp, [\tmp, #8] @ Store 0 in brcmstb_uart_virt
  94. b 100f @ Done
  95. 92: and \rv, \rp, #0xffffff @ offset within 16MB section
  96. add \rv, \rv, #REG_VIRT_BASE
  97. str \rv, [\tmp, #8] @ Store in brcmstb_uart_virt
  98. b 100f
  99. .align
  100. 99: .word .
  101. .word brcmstb_uart_config
  102. .ltorg
  103. /* Load previously selected UART address */
  104. 100: ldr \rp, [\tmp, #4] @ Load brcmstb_uart_phys
  105. ldr \rv, [\tmp, #8] @ Load brcmstb_uart_virt
  106. .endm
  107. .macro store, rd, rx:vararg
  108. ARM_BE8( rev \rd, \rd )
  109. str \rd, \rx
  110. .endm
  111. .macro load, rd, rx:vararg
  112. ldr \rd, \rx
  113. ARM_BE8( rev \rd, \rd )
  114. .endm
  115. .macro senduart,rd,rx
  116. store \rd, [\rx, #UART_TX << UART_SHIFT]
  117. .endm
  118. .macro busyuart,rd,rx
  119. 1002: load \rd, [\rx, #UART_LSR << UART_SHIFT]
  120. and \rd, \rd, #UART_LSR_TEMT | UART_LSR_THRE
  121. teq \rd, #UART_LSR_TEMT | UART_LSR_THRE
  122. bne 1002b
  123. .endm
  124. .macro waituarttxrdy,rd,rx
  125. .endm
  126. .macro waituartcts,rd,rx
  127. .endm
  128. /*
  129. * Storage for the state maintained by the macros above.
  130. *
  131. * In the kernel proper, this data is located in arch/arm/mach-bcm/brcmstb.c.
  132. * That's because this header is included from multiple files, and we only
  133. * want a single copy of the data. In particular, the UART probing code above
  134. * assumes it's running using physical addresses. This is true when this file
  135. * is included from head.o, but not when included from debug.o. So we need
  136. * to share the probe results between the two copies, rather than having
  137. * to re-run the probing again later.
  138. *
  139. * In the decompressor, we put the symbol/storage right here, since common.c
  140. * isn't included in the decompressor build. This symbol gets put in .text
  141. * even though it's really data, since .data is discarded from the
  142. * decompressor. Luckily, .text is writeable in the decompressor, unless
  143. * CONFIG_ZBOOT_ROM. That dependency is handled in arch/arm/Kconfig.debug.
  144. */
  145. #if defined(ZIMAGE)
  146. brcmstb_uart_config:
  147. /* Debug UART initialization required */
  148. .word 1
  149. /* Debug UART physical address */
  150. .word 0
  151. /* Debug UART virtual address */
  152. .word 0
  153. #endif