brcmstb.S 5.4 KB

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