raspi4.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #ifndef __RASPI4_H__
  2. #define __RASPI4_H__
  3. #include <rthw.h>
  4. #define __REG32(x) (*((volatile unsigned int *)(x)))
  5. //base address
  6. #define PER_BASE (0xFE000000)
  7. //gpio offset
  8. #define GPIO_BASE_OFFSET (0x00200000)
  9. //pl011 offset
  10. #define PL011_UART_BASE_OFFSET (0x00201000)
  11. //pactl cs offset
  12. #define PACTL_CS_OFFSET (0x00204E00)
  13. //aux offset
  14. #define AUX_BASE_OFFSET (0x00215000)
  15. //gpio
  16. #define GPIO_BASE (PER_BASE + GPIO_BASE_OFFSET)
  17. #define GPIO_IRQ_NUM (3) //40 pin mode
  18. #define IRQ_GPIO0 (96 + 49) //bank0 (0 to 27)
  19. #define IRQ_GPIO1 (96 + 50) //bank1 (28 to 45)
  20. #define IRQ_GPIO2 (96 + 51) //bank2 (46 to 57)
  21. #define IRQ_GPIO3 (96 + 52) //bank3
  22. //system timer
  23. #define ARM_TIMER_IRQ (64)
  24. #define ARM_TIMER_BASE (PER_BASE + 0xB000)
  25. #define ARM_TIMER_LOAD HWREG32(ARM_TIMER_BASE + 0x400)
  26. #define ARM_TIMER_VALUE HWREG32(ARM_TIMER_BASE + 0x404)
  27. #define ARM_TIMER_CTRL HWREG32(ARM_TIMER_BASE + 0x408)
  28. #define ARM_TIMER_IRQCLR HWREG32(ARM_TIMER_BASE + 0x40C)
  29. #define ARM_TIMER_RAWIRQ HWREG32(ARM_TIMER_BASE + 0x410)
  30. #define ARM_TIMER_MASKIRQ HWREG32(ARM_TIMER_BASE + 0x414)
  31. #define ARM_TIMER_RELOAD HWREG32(ARM_TIMER_BASE + 0x418)
  32. #define ARM_TIMER_PREDIV HWREG32(ARM_TIMER_BASE + 0x41C)
  33. #define ARM_TIMER_CNTR HWREG32(ARM_TIMER_BASE + 0x420)
  34. //uart
  35. #define UART_BASE (PER_BASE + PL011_UART_BASE_OFFSET)
  36. #define UART0_BASE (UART_BASE + 0x0)
  37. #define UART2_BASE (UART_BASE + 0x400)
  38. #define UART3_BASE (UART_BASE + 0x600)
  39. #define UART4_BASE (UART_BASE + 0x800)
  40. #define UART5_BASE (UART_BASE + 0xA00)
  41. #define IRQ_AUX_UART (96 + 29)
  42. #define UART_REFERENCE_CLOCK (48000000)
  43. //aux
  44. #define AUX_BASE (PER_BASE + AUX_BASE_OFFSET)
  45. #define IRQ_PL011 (96 + 57)
  46. //pactl cs
  47. #define PACTL_CS_ADDR (PER_BASE + PACTL_CS_OFFSET)
  48. #define PACTL_CS HWREG32(PACTL_CS_ADDR)
  49. typedef enum
  50. {
  51. IRQ_SPI0 = 0x00000000,
  52. IRQ_SPI1 = 0x00000002,
  53. IRQ_SPI2 = 0x00000004,
  54. IRQ_SPI3 = 0x00000008,
  55. IRQ_SPI4 = 0x00000010,
  56. IRQ_SPI5 = 0x00000020,
  57. IRQ_SPI6 = 0x00000040,
  58. IRQ_I2C0 = 0x00000100,
  59. IRQ_I2C1 = 0x00000200,
  60. IRQ_I2C2 = 0x00000400,
  61. IRQ_I2C3 = 0x00000800,
  62. IRQ_I2C4 = 0x00001000,
  63. IRQ_I2C5 = 0x00002000,
  64. IRQ_I2C6 = 0x00004000,
  65. IRQ_I2C7 = 0x00008000,
  66. IRQ_UART5 = 0x00010000,
  67. IRQ_UART4 = 0x00020000,
  68. IRQ_UART3 = 0x00040000,
  69. IRQ_UART2 = 0x00080000,
  70. IRQ_UART0 = 0x00100000
  71. } PACTL_CS_VAL;
  72. // 0x40, 0x44, 0x48, 0x4c: Core 0~3 Timers interrupt control
  73. #define CORE_TIMER_IRQ_CTRL(n) HWREG32((unsigned long)(0xFF800040 + (n) * 4))
  74. #define TIMER_IRQ 30
  75. #define NON_SECURE_TIMER_IRQ (1 << 1)
  76. rt_inline void core_timer_enable(int cpu_id)
  77. {
  78. CORE_TIMER_IRQ_CTRL(cpu_id) |= NON_SECURE_TIMER_IRQ;
  79. }
  80. //core timer
  81. #define ST_BASE_OFFSET (0x003000)
  82. #define STIMER_BASE (PER_BASE + ST_BASE_OFFSET)
  83. #define STIMER_CS HWREG32(STIMER_BASE + 0x0000)
  84. #define STIMER_CLO HWREG32(STIMER_BASE + 0x0004)
  85. #define STIMER_CHI HWREG32(STIMER_BASE + 0x0008)
  86. #define STIMER_C0 HWREG32(STIMER_BASE + 0x000C)
  87. #define STIMER_C1 HWREG32(STIMER_BASE + 0x0010)
  88. #define STIMER_C2 HWREG32(STIMER_BASE + 0x0014)
  89. #define STIMER_C3 HWREG32(STIMER_BASE + 0x0018)
  90. #define DELAY_MICROS(micros) \
  91. do { \
  92. rt_uint32_t compare = STIMER_CLO + micros * 25; \
  93. while (STIMER_CLO < compare); \
  94. } while (0) \
  95. //mmc
  96. #define MMC0_BASE_ADDR (PER_BASE + 0x300000)
  97. #define MMC2_BASE_ADDR (PER_BASE + 0x340000)
  98. //eth
  99. #define MAC_BASE_ADDR (0xfd580000)
  100. #define MAC_REG_BASE_ADDR (void *)(MAC_BASE_ADDR)
  101. #define ETH_IRQ (160 + 29)
  102. #define SEND_DATA_NO_CACHE (0x08200000)
  103. #define RECV_DATA_NO_CACHE (0x08400000)
  104. //watchdog
  105. #define WDT_BASE (PER_BASE + 0x00100000)
  106. #define PM_RSTC HWREG32(WDT_BASE + 0x0000001c)
  107. #define PM_RSTS HWREG32(WDT_BASE + 0x00000020)
  108. #define PM_WDOG HWREG32(WDT_BASE + 0x00000024)
  109. #define PM_PASSWORD (0x5A000000)
  110. #define PM_WDOG_TIME_SET (0x000fffff)
  111. #define PM_RSTS_HADWRH_SET (0x00000040)
  112. #define PM_RSTC_WRCFG_FULL_RESET (0x00000020)
  113. #define PM_RSTC_WRCFG_CLR (0xffffffcf)
  114. #define PM_RSTC_RESET (0x00000102)
  115. //gic max
  116. #define MAX_HANDLERS (256)
  117. #define ARM_GIC_NR_IRQS (512)
  118. #define INTC_BASE (0xff800000)
  119. #define ARM_GIC_MAX_NR (512)
  120. #define GIC_V2_BASE (INTC_BASE + 0x00040000)
  121. #define GIC_V2_DISTRIBUTOR_BASE (INTC_BASE + 0x00041000)
  122. #define GIC_V2_CPU_INTERFACE_BASE (INTC_BASE + 0x00042000)
  123. #define GIC_V2_HYPERVISOR_BASE (INTC_BASE + 0x00044000)
  124. #define GIC_V2_VIRTUAL_CPU_BASE (INTC_BASE + 0x00046000)
  125. /* ipi interrupt number */
  126. #define IRQ_ARM_IPI_KICK 0
  127. #define IRQ_ARM_IPI_CALL 1
  128. #define GIC_IRQ_START 0
  129. #define GIC_ACK_INTID_MASK 0x000003ff
  130. #define GIC_PL400_DISTRIBUTOR_PPTR GIC_V2_DISTRIBUTOR_BASE
  131. #define GIC_PL400_CONTROLLER_PPTR GIC_V2_CPU_INTERFACE_BASE
  132. /* the basic constants and interfaces needed by gic */
  133. rt_inline rt_uint32_t platform_get_gic_dist_base(void)
  134. {
  135. return GIC_PL400_DISTRIBUTOR_PPTR;
  136. }
  137. rt_inline rt_uint32_t platform_get_gic_cpu_base(void)
  138. {
  139. return GIC_PL400_CONTROLLER_PPTR;
  140. }
  141. #endif