brcmstb.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C) 2016 Broadcom
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation version 2.
  7. *
  8. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  9. * kind, whether express or implied; without even the implied warranty
  10. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/serial_reg.h>
  14. #include <asm/cputype.h>
  15. /* Physical register offset and virtual register offset */
  16. #define REG_PHYS_BASE 0xf0000000
  17. #define REG_PHYS_BASE_V7 0x08000000
  18. #define REG_VIRT_BASE 0xfc000000
  19. #define REG_PHYS_ADDR(x) ((x) + REG_PHYS_BASE)
  20. #define REG_PHYS_ADDR_V7(x) ((x) + REG_PHYS_BASE_V7)
  21. /* Product id can be read from here */
  22. #define SUN_TOP_CTRL_BASE REG_PHYS_ADDR(0x404000)
  23. #define SUN_TOP_CTRL_BASE_V7 REG_PHYS_ADDR_V7(0x404000)
  24. #define UARTA_3390 REG_PHYS_ADDR(0x40a900)
  25. #define UARTA_7250 REG_PHYS_ADDR(0x40b400)
  26. #define UARTA_7260 REG_PHYS_ADDR(0x40c000)
  27. #define UARTA_7268 UARTA_7260
  28. #define UARTA_7271 UARTA_7268
  29. #define UARTA_7278 REG_PHYS_ADDR_V7(0x40c000)
  30. #define UARTA_7364 REG_PHYS_ADDR(0x40b000)
  31. #define UARTA_7366 UARTA_7364
  32. #define UARTA_74371 REG_PHYS_ADDR(0x406b00)
  33. #define UARTA_7439 REG_PHYS_ADDR(0x40a900)
  34. #define UARTA_7445 REG_PHYS_ADDR(0x40ab00)
  35. #define UART_SHIFT 2
  36. #define checkuart(rp, rv, family_id, family) \
  37. /* Load family id */ \
  38. ldr rp, =family_id ; \
  39. /* Compare SUN_TOP_CTRL value against it */ \
  40. cmp rp, rv ; \
  41. /* Passed test, load address */ \
  42. ldreq rp, =UARTA_##family ; \
  43. /* Jump to save UART address */ \
  44. beq 91f
  45. .macro addruart, rp, rv, tmp
  46. adr \rp, 99f @ actual addr of 99f
  47. ldr \rv, [\rp] @ linked addr is stored there
  48. sub \rv, \rv, \rp @ offset between the two
  49. ldr \rp, [\rp, #4] @ linked brcmstb_uart_config
  50. sub \tmp, \rp, \rv @ actual brcmstb_uart_config
  51. ldr \rp, [\tmp] @ Load brcmstb_uart_config
  52. cmp \rp, #1 @ needs initialization?
  53. bne 100f @ no; go load the addresses
  54. mov \rv, #0 @ yes; record init is done
  55. str \rv, [\tmp]
  56. /* Check for V7 memory map if B53 */
  57. mrc p15, 0, \rv, c0, c0, 0 @ get Main ID register
  58. ldr \rp, =ARM_CPU_PART_MASK
  59. and \rv, \rv, \rp
  60. ldr \rp, =ARM_CPU_PART_BRAHMA_B53 @ check for B53 CPU
  61. cmp \rv, \rp
  62. bne 10f
  63. /* if PERIPHBASE doesn't overlap REG_PHYS_BASE use V7 map */
  64. mrc p15, 1, \rv, c15, c3, 0 @ get PERIPHBASE from CBAR
  65. ands \rv, \rv, #REG_PHYS_BASE
  66. ldreq \rp, =SUN_TOP_CTRL_BASE_V7
  67. /* Check SUN_TOP_CTRL base */
  68. 10: ldrne \rp, =SUN_TOP_CTRL_BASE @ load SUN_TOP_CTRL PA
  69. ldr \rv, [\rp, #0] @ get register contents
  70. ARM_BE8( rev \rv, \rv )
  71. and \rv, \rv, #0xffffff00 @ strip revision bits [7:0]
  72. /* Chip specific detection starts here */
  73. 20: checkuart(\rp, \rv, 0x33900000, 3390)
  74. 21: checkuart(\rp, \rv, 0x72500000, 7250)
  75. 22: checkuart(\rp, \rv, 0x72600000, 7260)
  76. 23: checkuart(\rp, \rv, 0x72680000, 7268)
  77. 24: checkuart(\rp, \rv, 0x72710000, 7271)
  78. 25: checkuart(\rp, \rv, 0x73640000, 7364)
  79. 26: checkuart(\rp, \rv, 0x73660000, 7366)
  80. 27: checkuart(\rp, \rv, 0x07437100, 74371)
  81. 28: checkuart(\rp, \rv, 0x74390000, 7439)
  82. 29: checkuart(\rp, \rv, 0x74450000, 7445)
  83. 30: checkuart(\rp, \rv, 0x72780000, 7278)
  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 waituart,rd,rx
  123. .endm
  124. /*
  125. * Storage for the state maintained by the macros above.
  126. *
  127. * In the kernel proper, this data is located in arch/arm/mach-bcm/brcmstb.c.
  128. * That's because this header is included from multiple files, and we only
  129. * want a single copy of the data. In particular, the UART probing code above
  130. * assumes it's running using physical addresses. This is true when this file
  131. * is included from head.o, but not when included from debug.o. So we need
  132. * to share the probe results between the two copies, rather than having
  133. * to re-run the probing again later.
  134. *
  135. * In the decompressor, we put the symbol/storage right here, since common.c
  136. * isn't included in the decompressor build. This symbol gets put in .text
  137. * even though it's really data, since .data is discarded from the
  138. * decompressor. Luckily, .text is writeable in the decompressor, unless
  139. * CONFIG_ZBOOT_ROM. That dependency is handled in arch/arm/Kconfig.debug.
  140. */
  141. #if defined(ZIMAGE)
  142. brcmstb_uart_config:
  143. /* Debug UART initialization required */
  144. .word 1
  145. /* Debug UART physical address */
  146. .word 0
  147. /* Debug UART virtual address */
  148. .word 0
  149. #endif