raspi.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /*
  2. * File : rsapi.h
  3. * Copyright (c) 2006-2021, RT-Thread Development Team
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2019-07-29 zdzn first version
  10. */
  11. #ifndef __RASPI_H__
  12. #define __RASPI_H__
  13. #include <rthw.h>
  14. #define __REG32(x) (*((volatile unsigned int*)((rt_uint64_t)x)))
  15. typedef enum
  16. {
  17. BCM_GPIO_PIN_0 = 0,
  18. BCM_GPIO_PIN_1,
  19. BCM_GPIO_PIN_2,
  20. BCM_GPIO_PIN_3,
  21. BCM_GPIO_PIN_4,
  22. BCM_GPIO_PIN_5,
  23. BCM_GPIO_PIN_6,
  24. BCM_GPIO_PIN_7,
  25. BCM_GPIO_PIN_8,
  26. BCM_GPIO_PIN_9,
  27. BCM_GPIO_PIN_10,
  28. BCM_GPIO_PIN_11,
  29. BCM_GPIO_PIN_12,
  30. BCM_GPIO_PIN_13,
  31. BCM_GPIO_PIN_14,
  32. BCM_GPIO_PIN_15,
  33. BCM_GPIO_PIN_16,
  34. BCM_GPIO_PIN_17,
  35. BCM_GPIO_PIN_18,
  36. BCM_GPIO_PIN_19,
  37. BCM_GPIO_PIN_20,
  38. BCM_GPIO_PIN_21,
  39. BCM_GPIO_PIN_22,
  40. BCM_GPIO_PIN_23,
  41. BCM_GPIO_PIN_24,
  42. BCM_GPIO_PIN_25,
  43. BCM_GPIO_PIN_26,
  44. BCM_GPIO_PIN_27,
  45. BCM_GPIO_PIN_28,
  46. BCM_GPIO_PIN_29,
  47. BCM_GPIO_PIN_30,
  48. BCM_GPIO_PIN_31,
  49. BCM_GPIO_PIN_32,
  50. BCM_GPIO_PIN_33,
  51. BCM_GPIO_PIN_34,
  52. BCM_GPIO_PIN_35,
  53. BCM_GPIO_PIN_36,
  54. BCM_GPIO_PIN_37,
  55. BCM_GPIO_PIN_38,
  56. BCM_GPIO_PIN_39,
  57. BCM_GPIO_PIN_40,
  58. BCM_GPIO_PIN_41,
  59. BCM_GPIO_PIN_42,
  60. BCM_GPIO_PIN_43,
  61. BCM_GPIO_PIN_44,
  62. BCM_GPIO_PIN_45,
  63. BCM_GPIO_PIN_46,
  64. BCM_GPIO_PIN_47,
  65. BCM_GPIO_PIN_48,
  66. BCM_GPIO_PIN_49,
  67. BCM_GPIO_PIN_50,
  68. BCM_GPIO_PIN_51,
  69. BCM_GPIO_PIN_52,
  70. BCM_GPIO_PIN_53,
  71. BCM_GPIO_PIN_NULL,
  72. } bcm_gpio_pin;
  73. typedef enum
  74. {
  75. BCM283X_GPIO_FSEL_INPT = 0x00, /*!< Input 0b000 */
  76. BCM283X_GPIO_FSEL_OUTP = 0x01, /*!< Output 0b001 */
  77. BCM283X_GPIO_FSEL_ALT0 = 0x04, /*!< Alternate function 0 0b100 */
  78. BCM283X_GPIO_FSEL_ALT1 = 0x05, /*!< Alternate function 1 0b101 */
  79. BCM283X_GPIO_FSEL_ALT2 = 0x06, /*!< Alternate function 2 0b110, */
  80. BCM283X_GPIO_FSEL_ALT3 = 0x07, /*!< Alternate function 3 0b111 */
  81. BCM283X_GPIO_FSEL_ALT4 = 0x03, /*!< Alternate function 4 0b011 */
  82. BCM283X_GPIO_FSEL_ALT5 = 0x02, /*!< Alternate function 5 0b010 */
  83. BCM283X_GPIO_FSEL_MASK = 0x07 /*!< Function select bits mask 0b111 */
  84. } gpio_function_select;
  85. typedef enum
  86. {
  87. BCM283X_GPIO_PUD_OFF = 0x00, /*!< Off ? disable pull-up/down 0b00 */
  88. BCM283X_GPIO_PUD_DOWN = 0x01, /*!< Enable Pull Down control 0b01 */
  89. BCM283X_GPIO_PUD_UP = 0x02 /*!< Enable Pull Up control 0b10 */
  90. } gpio_pud_mode;
  91. #define BCM283X_CORE_CLK_HZ 250000000 /* 50 MHz */
  92. /* Base Address */
  93. #define PER_BASE (0x3F000000)
  94. #define PER_BASE_40000000 (0x40000000)
  95. //#define BCM283X_PERI_BASE (0x3F000000)
  96. //#define BCM283X_PER_BASE_40000000 (0x40000000)
  97. /* Base Address Registers Offset */
  98. #define ST_BASE_OFFSET (0x003000)
  99. #define GPIO_PAD_OFFSET (0x100000)
  100. #define CLOCK_BASE_OFFSET (0x101000)
  101. #define GPIO_BASE_OFFSET (0x200000)
  102. #define SPI0_BASE_OFFSET (0x204000)
  103. #define BSC0_BASE_OFFSET (0x205000)
  104. #define GPIO_PWM_OFFSET (0x20C000)
  105. #define AUX_BASE_OFFSET (0x215000)
  106. #define SPI1_BASE_OFFSET (0x215080)
  107. #define SPI2_BASE_OFFSET (0x2150C0)
  108. #define BSC1_BASE_OFFSET (0x804000)
  109. #define BSC2_BASE_OFFSET (0x805000)
  110. /* IRQ */
  111. #define MAX_HANDLERS 72
  112. #define IRQ_SYSTEM_TIMER_0 0
  113. #define IRQ_SYSTEM_TIMER_1 1
  114. #define IRQ_SYSTEM_TIMER_2 2
  115. #define IRQ_SYSTEM_TIMER_3 3
  116. #define IRQ_USB 9
  117. #define IRQ_AUX 29
  118. #define IRQ_PCM 55
  119. #define IRQ_ARM_TIMER 64
  120. #define IRQ_ARM_MAILBOX 65
  121. /* Interrupt Controler */
  122. #define IRQ_BASE (PER_BASE + 0xB200)
  123. #define IRQ_PEND_BASIC __REG32(IRQ_BASE + 0x0000)
  124. #define IRQ_PEND1 __REG32(IRQ_BASE + 0x0004)
  125. #define IRQ_PEND2 __REG32(IRQ_BASE + 0x0008)
  126. #define IRQ_FIQ_CONTROL __REG32(IRQ_BASE + 0x000C)
  127. #define IRQ_ENABLE1 __REG32(IRQ_BASE + 0x0010)
  128. #define IRQ_ENABLE2 __REG32(IRQ_BASE + 0x0014)
  129. #define IRQ_ENABLE_BASIC __REG32(IRQ_BASE + 0x0018)
  130. #define IRQ_DISABLE1 __REG32(IRQ_BASE + 0x001C)
  131. #define IRQ_DISABLE2 __REG32(IRQ_BASE + 0x0020)
  132. #define IRQ_DISABLE_BASIC __REG32(IRQ_BASE + 0x0024)
  133. /* Defines for WDT*/
  134. #define PM_BASE (PER_BASE + GPIO_PAD_OFFSET)
  135. #define PM_RSTC __REG32(PM_BASE + 0x001C)
  136. #define PM_RSTS __REG32(PM_BASE + 0x0020)
  137. #define PM_WDOG __REG32(PM_BASE + 0x0024)
  138. #define PM_PASSWORD 0x5a000000
  139. #define PM_WDOG_TIME_SET 0x000fffff
  140. #define PM_RSTC_WRCFG_CLR 0xffffffcf
  141. #define PM_RSTS_HADWRH_SET 0x00000040
  142. #define PM_RSTC_WRCFG_SET 0x00000030
  143. #define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  144. #define PM_RSTC_RESET 0x00000102
  145. #define PM_RSTS_PARTITION_CLR 0xfffffaaa
  146. /* Defines for System Timer */
  147. #define STIMER_BASE (PER_BASE + ST_BASE_OFFSET)
  148. #define STIMER_CS __REG32(STIMER_BASE + 0x0000)
  149. #define STIMER_CLO __REG32(STIMER_BASE + 0x0004)
  150. #define STIMER_CHI __REG32(STIMER_BASE + 0x0008)
  151. #define STIMER_C0 __REG32(STIMER_BASE + 0x000C)
  152. #define STIMER_C1 __REG32(STIMER_BASE + 0x0010)
  153. #define STIMER_C2 __REG32(STIMER_BASE + 0x0014)
  154. #define STIMER_C3 __REG32(STIMER_BASE + 0x0018)
  155. #define DELAY_MICROS(micros) \
  156. do{ \
  157. rt_uint32_t compare = STIMER_CLO + micros * 25; \
  158. while (STIMER_CLO < compare); \
  159. } while (0) \
  160. /* Defines for GPIO */
  161. #define BCM283X_GPIO_BASE (PER_BASE + GPIO_BASE_OFFSET)
  162. #define BCM283X_GPIO_GPFSEL(n) __REG32(BCM283X_GPIO_BASE + 0x0000 + 0x4 * n) /* GPIO Function Select 32bit R/W */
  163. #define BCM283X_GPIO_GPSET(n) __REG32(BCM283X_GPIO_BASE + 0x001C + 0x4 * n) /* GPIO Pin Output Set */
  164. #define BCM283X_GPIO_GPCLR(n) __REG32(BCM283X_GPIO_BASE + 0x0028 + 0x4 * n) /* GPIO Pin Output Clear */
  165. #define BCM2835_GPIO_GPLEV(n) __REG32(BCM283X_GPIO_BASE + 0x0034 + 0x4 * n) /* GPIO Pin Level */
  166. #define BCM283X_GPIO_GPEDS(n) __REG32(BCM283X_GPIO_BASE + 0x0040 + 0x4 * n) /* GPIO Pin Event Detect Status */
  167. #define BCM283X_GPIO_GPREN(n) __REG32(BCM283X_GPIO_BASE + 0x004c + 0x4 * n) /* GPIO Pin Rising Edge Detect Enable */
  168. #define BCM283X_GPIO_GPFEN(n) __REG32(BCM283X_GPIO_BASE + 0x0058 + 0x4 * n) /* GPIO Pin Falling Edge Detect Enable */
  169. #define BCM283X_GPIO_GPHEN(n) __REG32(BCM283X_GPIO_BASE + 0x0064 + 0x4 * n) /* GPIO Pin High Detect Enable */
  170. #define BCM283X_GPIO_GPLEN(n) __REG32(BCM283X_GPIO_BASE + 0x0070 + 0x4 * n) /* GPIO Pin Low Detect Enable */
  171. #define BCM283X_GPIO_GPAREN(n) __REG32(BCM283X_GPIO_BASE + 0x007C + 0x4 * n) /* GPIO Pin Async. Rising Edge Detect */
  172. #define BCM283X_GPIO_GPAFEN(n) __REG32(BCM283X_GPIO_BASE + 0x0088 + 0x4 * n) /* GPIO Pin Async. Falling Edge Detect */
  173. #define BCM283X_GPIO_GPPUD __REG32(BCM283X_GPIO_BASE + 0x0094) /* GPIO Pin Pull-up/down Enable */
  174. #define BCM283X_GPIO_GPPUDCLK(n) __REG32(BCM283X_GPIO_BASE + 0x0098 + 0x4 * n) /* GPIO Pin Pull-up/down Enable Clock */
  175. #define GPIO_FSEL_NUM(pin) (pin/10)
  176. #define GPIO_FSEL_SHIFT(pin) ((pin%10)*3)
  177. #define GPIO_FSEL(pin, mode) \
  178. do{ \
  179. __sync_synchronize(); \
  180. BCM283X_GPIO_GPFSEL(GPIO_FSEL_NUM(pin)) |= ((mode & BCM283X_GPIO_FSEL_MASK) << GPIO_FSEL_SHIFT(pin)); \
  181. } while (0) \
  182. /* Defines for I2C */
  183. #define BCM283X_BSC0_BASE (PER_BASE + BSC0_BASE_OFFSET) //for i2c0
  184. #define BCM283X_BSC1_BASE (PER_BASE + BSC1_BASE_OFFSET) //for i2c1
  185. #define BCM283X_BSC2_BASE (PER_BASE + BSC2_BASE_OFFSET) //for hdmi i2c not use
  186. #define BCM283X_BSC_C(BASE) __REG32(BASE + 0x0000) /* BSC Master Control */
  187. #define BCM283X_BSC_S(BASE) __REG32(BASE + 0x0004) /* BSC Master Status */
  188. #define BCM283X_BSC_DLEN(BASE) __REG32(BASE + 0x0008) /* BSC Master Data Length */
  189. #define BCM283X_BSC_A(BASE) __REG32(BASE + 0x000c) /* BSC Master Slave Address */
  190. #define BCM283X_BSC_FIFO(BASE) __REG32(BASE + 0x0010) /* BSC Master Data FIFO */
  191. #define BCM283X_BSC_DIV(BASE) __REG32(BASE + 0x0014) /* BSC Master Clock Divider */
  192. #define BCM283X_BSC_DEL(BASE) __REG32(BASE + 0x0018) /* BSC Master Data Delay */
  193. #define BCM283X_BSC_CLKT(BASE) __REG32(BASE + 0x001c) /* BSC Master Clock Stretch Timeout */
  194. /* Register masks for C Register */
  195. #define BSC_C_I2CEN 0x00008000 /* I2C Enable, 0 = disabled, 1 = enabled */
  196. #define BSC_C_INTR 0x00000400 /* Interrupt on RX */
  197. #define BSC_C_INTT 0x00000200 /* Interrupt on TX */
  198. #define BSC_C_INTD 0x00000100 /* Interrupt on DONE */
  199. #define BSC_C_ST 0x00000080 /* Start transfer, 1 = Start a new transfer */
  200. #define BSC_C_CLEAR_1 0x00000020 /* Clear FIFO Clear */
  201. #define BSC_C_CLEAR_2 0x00000010 /* Clear FIFO Clear */
  202. #define BSC_C_READ 0x00000001 /* Read transfer */
  203. /* Register masks for S Register */
  204. #define BSC_S_CLKT 0x00000200 /* Clock stretch timeout */
  205. #define BSC_S_ERR 0x00000100 /* ACK error */
  206. #define BSC_S_RXF 0x00000080 /* RXF FIFO full, 0 = FIFO is not full, 1 = FIFO is full */
  207. #define BSC_S_TXE 0x00000040 /* TXE FIFO full, 0 = FIFO is not full, 1 = FIFO is full */
  208. #define BSC_S_RXD 0x00000020 /* RXD FIFO contains data */
  209. #define BSC_S_TXD 0x00000010 /* TXD FIFO can accept data */
  210. #define BSC_S_RXR 0x00000008 /* RXR FIFO needs reading (full) */
  211. #define BSC_S_TXW 0x00000004 /* TXW FIFO needs writing (full) */
  212. #define BSC_S_DONE 0x00000002 /* Transfer DONE */
  213. #define BSC_S_TA 0x00000001 /* Transfer Active */
  214. #define BSC_FIFO_SIZE (16) /* BSC FIFO size */
  215. /* Defines for SPI */
  216. #define BCM283X_SPI0_BASE (PER_BASE + SPI0_BASE_OFFSET)
  217. #define BCM283X_SPI1_BASE (PER_BASE + SPI1_BASE_OFFSET)
  218. #define BCM283X_SPI2_BASE (PER_BASE + SPI2_BASE_OFFSET)
  219. #define BCM283X_SPI0_CS(BASE) __REG32(BASE + 0x0000) /* SPI Master Control and Status */
  220. #define BCM283X_SPI0_FIFO(BASE) __REG32(BASE + 0x0004) /* SPI Master TX and RX FIFOs */
  221. #define BCM283X_SPI0_CLK(BASE) __REG32(BASE + 0x0008) /* SPI Master Clock Divider */
  222. #define BCM283X_SPI0_DLEN(BASE) __REG32(BASE + 0x000c) /* SPI Master Data Length */
  223. #define BCM283X_SPI0_LTOH(BASE) __REG32(BASE + 0x0010) /* SPI LOSSI mode TOH */
  224. #define BCM283X_SPI0_DC(BASE) __REG32(BASE + 0x0014) /* SPI DMA DREQ Controls */
  225. /* Register masks for SPI0_CS */
  226. #define BCM283X_SPI0_CS_LEN_LONG 0x02000000 /* Enable Long data word in Lossi mode if DMA_LEN is set */
  227. #define BCM283X_SPI0_CS_DMA_LEN 0x01000000 /* Enable DMA mode in Lossi mode */
  228. #define BCM283X_SPI0_CS_CSPOL2 0x00800000 /* Chip Select 2 Polarity */
  229. #define BCM283X_SPI0_CS_CSPOL1 0x00400000 /* Chip Select 1 Polarity */
  230. #define BCM283X_SPI0_CS_CSPOL0 0x00200000 /* Chip Select 0 Polarity */
  231. #define BCM283X_SPI0_CS_RXF 0x00100000 /* RXF - RX FIFO Full */
  232. #define BCM283X_SPI0_CS_RXR 0x00080000 /* RXR RX FIFO needs Reading (full) */
  233. #define BCM283X_SPI0_CS_TXD 0x00040000 /* TXD TX FIFO can accept Data */
  234. #define BCM283X_SPI0_CS_RXD 0x00020000 /* RXD RX FIFO contains Data */
  235. #define BCM283X_SPI0_CS_DONE 0x00010000 /* Done transfer Done */
  236. #define BCM283X_SPI0_CS_TE_EN 0x00008000 /* Unused */
  237. #define BCM283X_SPI0_CS_LMONO 0x00004000 /* Unused */
  238. #define BCM283X_SPI0_CS_LEN 0x00002000 /* LEN LoSSI enable */
  239. #define BCM283X_SPI0_CS_REN 0x00001000 /* REN Read Enable */
  240. #define BCM283X_SPI0_CS_ADCS 0x00000800 /* ADCS Automatically Deassert Chip Select */
  241. #define BCM283X_SPI0_CS_INTR 0x00000400 /* INTR Interrupt on RXR */
  242. #define BCM283X_SPI0_CS_INTD 0x00000200 /* INTD Interrupt on Done */
  243. #define BCM283X_SPI0_CS_DMAEN 0x00000100 /* DMAEN DMA Enable */
  244. #define BCM283X_SPI0_CS_TA 0x00000080 /* Transfer Active */
  245. #define BCM283X_SPI0_CS_CSPOL 0x00000040 /* Chip Select Polarity */
  246. #define BCM283X_SPI0_CS_CLEAR 0x00000030 /* Clear FIFO Clear RX and TX */
  247. #define BCM283X_SPI0_CS_CLEAR_RX 0x00000020 /* Clear FIFO Clear RX */
  248. #define BCM283X_SPI0_CS_CLEAR_TX 0x00000010 /* Clear FIFO Clear TX */
  249. #define BCM283X_SPI0_CS_CPOL 0x00000008 /* Clock Polarity */
  250. #define BCM283X_SPI0_CS_CPHA 0x00000004 /* Clock Phase */
  251. #define BCM283X_SPI0_CS_CS 0x00000003 /* Chip Select */
  252. /* ARM Timer */
  253. #define ARM_TIMER_BASE (PER_BASE + 0xB000)
  254. #define ARM_TIMER_LOAD __REG32(ARM_TIMER_BASE + 0x400)
  255. #define ARM_TIMER_VALUE __REG32(ARM_TIMER_BASE + 0x404)
  256. #define ARM_TIMER_CTRL __REG32(ARM_TIMER_BASE + 0x408)
  257. #define ARM_TIMER_IRQCLR __REG32(ARM_TIMER_BASE + 0x40C)
  258. #define ARM_TIMER_RAWIRQ __REG32(ARM_TIMER_BASE + 0x410)
  259. #define ARM_TIMER_MASKIRQ __REG32(ARM_TIMER_BASE + 0x414)
  260. #define ARM_TIMER_RELOAD __REG32(ARM_TIMER_BASE + 0x418)
  261. #define ARM_TIMER_PREDIV __REG32(ARM_TIMER_BASE + 0x41C)
  262. #define ARM_TIMER_CNTR __REG32(ARM_TIMER_BASE + 0x420)
  263. /* ARM Core Timer */
  264. #define C0TIMER_INTCTL __REG32(PER_BASE_40000000 + 0x40) /* Core0 timers Interrupt control */
  265. #define C1TIMER_INTCTL __REG32(PER_BASE_40000000 + 0x44) /* Core1 timers Interrupt control */
  266. #define C2TIMER_INTCTL __REG32(PER_BASE_40000000 + 0x48) /* Core2 timers Interrupt control */
  267. #define C3TIMER_INTCTL __REG32(PER_BASE_40000000 + 0x4C) /* Core3 timers Interrupt control */
  268. #define CORETIMER_INTCTL(n) __REG32(PER_BASE_40000000 + 0x40 + n*4) /* Coren timers Interrupt control */
  269. /*
  270. * Gtimer IRQ flag
  271. */
  272. #define SYSTEM_TIMER_IRQ_0 (1 << 0)
  273. #define SYSTEM_TIMER_IRQ_1 (1 << 1)
  274. #define SYSTEM_TIMER_IRQ_2 (1 << 2)
  275. #define SYSTEM_TIMER_IRQ_3 (1 << 3)
  276. #define NON_SECURE_TIMER_IRQ (1 << 1)
  277. /* ARM Core Mailbox interrupt */
  278. #define C0MB_INTCTL __REG32(PER_BASE_40000000 + 0x50) /* Core0 Mailboxes Interrupt control */
  279. #define C1MB_INTCTL __REG32(PER_BASE_40000000 + 0x54) /* Core1 Mailboxes Interrupt control */
  280. #define C2MB_INTCTL __REG32(PER_BASE_40000000 + 0x58) /* Core2 Mailboxes Interrupt control */
  281. #define C3MB_INTCTL __REG32(PER_BASE_40000000 + 0x5C) /* Core3 Mailboxes Interrupt control */
  282. #define COREMB_INTCTL(n) __REG32(PER_BASE_40000000 + 0x50 + 4*n) /* Coren Mailboxes Interrupt control */
  283. /* ARM Core IRQ/FIQ status */
  284. #define C0_IRQSOURCE __REG32(PER_BASE_40000000 + 0x60) /* Core0 IRQ Source */
  285. #define C1_IRQSOURCE __REG32(PER_BASE_40000000 + 0x64) /* Core1 IRQ Source */
  286. #define C2_IRQSOURCE __REG32(PER_BASE_40000000 + 0x68) /* Core2 IRQ Source */
  287. #define C3_IRQSOURCE __REG32(PER_BASE_40000000 + 0x6C) /* Core3 IRQ Source */
  288. #define C0_FIQSOURCE __REG32(PER_BASE_40000000 + 0x70) /* Core0 FIQ Source */
  289. #define C1_FIQSOURCE __REG32(PER_BASE_40000000 + 0x74) /* Core1 FIQ Source */
  290. #define C2_FIQSOURCE __REG32(PER_BASE_40000000 + 0x78) /* Core2 FIQ Source */
  291. #define C3_FIQSOURCE __REG32(PER_BASE_40000000 + 0x7C) /* Core3 FIQ Source */
  292. #define CORE_IRQSOURCE(n) __REG32(PER_BASE_40000000 + 0x60+ n*0x4)
  293. #define CORE_FIQSOURCE(n) __REG32(PER_BASE_40000000 + 0x70+ n*0x4)
  294. #define CORE_MAILBOX3_SET(n) __REG32(PER_BASE_40000000 + 0x8C + n*0x10)
  295. #define CORE_MAILBOX3_CLEAR(n) __REG32(PER_BASE_40000000 + 0xCC + n*0x10)
  296. #define CORE_MAILBOX2_SET(n) __REG32(PER_BASE_40000000 + 0x88 + n*0x10)
  297. #define CORE_MAILBOX2_CLEAR(n) __REG32(PER_BASE_40000000 + 0xC8 + n*0x10)
  298. #define CORE_MAILBOX1_SET(n) __REG32(PER_BASE_40000000 + 0x84 + n*0x10)
  299. #define CORE_MAILBOX1_CLEAR(n) __REG32(PER_BASE_40000000 + 0xC4 + n*0x10)
  300. #define CORE_MAILBOX0_SET(n) __REG32(PER_BASE_40000000 + 0x80 + n*0x10)
  301. #define CORE_MAILBOX0_CLEAR(n) __REG32(PER_BASE_40000000 + 0xC0 + n*0x10)
  302. /* For SMP IPI use MailBox0 */
  303. #define IPI_MAILBOX_SET CORE_MAILBOX0_SET
  304. #define IPI_MAILBOX_CLEAR CORE_MAILBOX0_CLEAR
  305. #define IPI_MAILBOX_INT_MASK (0x01)
  306. enum spi_bit_order
  307. {
  308. BCM283X_SPI_BIT_ORDER_LSBFIRST = 0, /*!< LSB First */
  309. BCM283X_SPI_BIT_ORDER_MSBFIRST = 1 /*!< MSB First */
  310. };
  311. enum spi_mode
  312. {
  313. BCM283X_SPI_MODE0 = 0, /*!< CPOL = 0, CPHA = 0 */
  314. BCM283X_SPI_MODE1 = 1, /*!< CPOL = 0, CPHA = 1 */
  315. BCM283X_SPI_MODE2 = 2, /*!< CPOL = 1, CPHA = 0 */
  316. BCM283X_SPI_MODE3 = 3 /*!< CPOL = 1, CPHA = 1 */
  317. };
  318. enum spi_chip_select
  319. {
  320. BCM283X_SPI_CS0 = 0, /*!< Chip Select 0 */
  321. BCM283X_SPI_CS1 = 1, /*!< Chip Select 1 */
  322. BCM283X_SPI_CS2 = 2, /*!< Chip Select 2 (ie pins CS1 and CS2 are asserted) */
  323. BCM283X_SPI_CS_NONE = 3 /*!< No CS, control it yourself */
  324. };
  325. enum spi_clock_divider
  326. {
  327. BCM283X_SPI_CLOCK_DIVIDER_65536 = 0, /*!< 65536 = 3.814697260kHz on Rpi2, 6.1035156kHz on RPI3 */
  328. BCM283X_SPI_CLOCK_DIVIDER_32768 = 32768, /*!< 32768 = 7.629394531kHz on Rpi2, 12.20703125kHz on RPI3 */
  329. BCM283X_SPI_CLOCK_DIVIDER_16384 = 16384, /*!< 16384 = 15.25878906kHz on Rpi2, 24.4140625kHz on RPI3 */
  330. BCM283X_SPI_CLOCK_DIVIDER_8192 = 8192, /*!< 8192 = 30.51757813kHz on Rpi2, 48.828125kHz on RPI3 */
  331. BCM283X_SPI_CLOCK_DIVIDER_4096 = 4096, /*!< 4096 = 61.03515625kHz on Rpi2, 97.65625kHz on RPI3 */
  332. BCM283X_SPI_CLOCK_DIVIDER_2048 = 2048, /*!< 2048 = 122.0703125kHz on Rpi2, 195.3125kHz on RPI3 */
  333. BCM283X_SPI_CLOCK_DIVIDER_1024 = 1024, /*!< 1024 = 244.140625kHz on Rpi2, 390.625kHz on RPI3 */
  334. BCM283X_SPI_CLOCK_DIVIDER_512 = 512, /*!< 512 = 488.28125kHz on Rpi2, 781.25kHz on RPI3 */
  335. BCM283X_SPI_CLOCK_DIVIDER_256 = 256, /*!< 256 = 976.5625kHz on Rpi2, 1.5625MHz on RPI3 */
  336. BCM283X_SPI_CLOCK_DIVIDER_128 = 128, /*!< 128 = 1.953125MHz on Rpi2, 3.125MHz on RPI3 */
  337. BCM283X_SPI_CLOCK_DIVIDER_64 = 64, /*!< 64 = 3.90625MHz on Rpi2, 6.250MHz on RPI3 */
  338. BCM283X_SPI_CLOCK_DIVIDER_32 = 32, /*!< 32 = 7.8125MHz on Rpi2, 12.5MHz on RPI3 */
  339. BCM283X_SPI_CLOCK_DIVIDER_16 = 16, /*!< 16 = 15.625MHz on Rpi2, 25MHz on RPI3 */
  340. BCM283X_SPI_CLOCK_DIVIDER_8 = 8, /*!< 8 = 31.25MHz on Rpi2, 50MHz on RPI3 */
  341. BCM283X_SPI_CLOCK_DIVIDER_4 = 4, /*!< 4 = 62.5MHz on Rpi2, 100MHz on RPI3. Dont expect this speed to work reliably. */
  342. BCM283X_SPI_CLOCK_DIVIDER_2 = 2, /*!< 2 = 125MHz on Rpi2, 200MHz on RPI3, fastest you can get. Dont expect this speed to work reliably.*/
  343. BCM283X_SPI_CLOCK_DIVIDER_1 = 1 /*!< 1 = 3.814697260kHz on Rpi2, 6.1035156kHz on RPI3, same as 0/65536 */
  344. };
  345. /*redefine for raspi*/
  346. typedef gpio_function_select raspi_pin_select;
  347. typedef enum
  348. {
  349. RPI_GPIO_P1_01 = BCM_GPIO_PIN_NULL,
  350. RPI_GPIO_P1_02 = BCM_GPIO_PIN_NULL,
  351. RPI_GPIO_P1_03 = BCM_GPIO_PIN_2,
  352. RPI_GPIO_P1_04 = BCM_GPIO_PIN_NULL,
  353. RPI_GPIO_P1_05 = BCM_GPIO_PIN_3,
  354. RPI_GPIO_P1_06 = BCM_GPIO_PIN_NULL,
  355. RPI_GPIO_P1_07 = BCM_GPIO_PIN_4,
  356. RPI_GPIO_P1_08 = BCM_GPIO_PIN_14,
  357. RPI_GPIO_P1_09 = BCM_GPIO_PIN_NULL,
  358. RPI_GPIO_P1_10 = BCM_GPIO_PIN_15,
  359. RPI_GPIO_P1_11 = BCM_GPIO_PIN_17,
  360. RPI_GPIO_P1_12 = BCM_GPIO_PIN_18,
  361. RPI_GPIO_P1_13 = BCM_GPIO_PIN_27,
  362. RPI_GPIO_P1_14 = BCM_GPIO_PIN_NULL,
  363. RPI_GPIO_P1_15 = BCM_GPIO_PIN_22,
  364. RPI_GPIO_P1_16 = BCM_GPIO_PIN_23,
  365. RPI_GPIO_P1_17 = BCM_GPIO_PIN_NULL,
  366. RPI_GPIO_P1_18 = BCM_GPIO_PIN_24,
  367. RPI_GPIO_P1_19 = BCM_GPIO_PIN_10,
  368. RPI_GPIO_P1_20 = BCM_GPIO_PIN_NULL,
  369. RPI_GPIO_P1_21 = BCM_GPIO_PIN_9,
  370. RPI_GPIO_P1_22 = BCM_GPIO_PIN_25,
  371. RPI_GPIO_P1_23 = BCM_GPIO_PIN_11,
  372. RPI_GPIO_P1_24 = BCM_GPIO_PIN_8,
  373. RPI_GPIO_P1_25 = BCM_GPIO_PIN_NULL,
  374. RPI_GPIO_P1_26 = BCM_GPIO_PIN_7,
  375. RPI_GPIO_P1_27 = BCM_GPIO_PIN_0,
  376. RPI_GPIO_P1_28 = BCM_GPIO_PIN_1,
  377. RPI_GPIO_P1_29 = BCM_GPIO_PIN_5,
  378. RPI_GPIO_P1_30 = BCM_GPIO_PIN_NULL,
  379. RPI_GPIO_P1_31 = BCM_GPIO_PIN_6,
  380. RPI_GPIO_P1_32 = BCM_GPIO_PIN_12,
  381. RPI_GPIO_P1_33 = BCM_GPIO_PIN_13,
  382. RPI_GPIO_P1_34 = BCM_GPIO_PIN_NULL,
  383. RPI_GPIO_P1_35 = BCM_GPIO_PIN_19,
  384. RPI_GPIO_P1_36 = BCM_GPIO_PIN_16,
  385. RPI_GPIO_P1_37 = BCM_GPIO_PIN_26,
  386. RPI_GPIO_P1_38 = BCM_GPIO_PIN_20,
  387. RPI_GPIO_P1_39 = BCM_GPIO_PIN_NULL,
  388. RPI_GPIO_P1_40 = BCM_GPIO_PIN_21,
  389. } raspi_gpio_pin;
  390. typedef enum
  391. {
  392. BCM283X_I2C_CLOCK_DIVIDER_2500 = 2500, /* 2500 = 10us = 100 kHz */
  393. BCM283X_I2C_CLOCK_DIVIDER_626 = 626, /* 622 = 2.504us = 399.3610 kHz */
  394. BCM283X_I2C_CLOCK_DIVIDER_150 = 150, /* 150 = 60ns = 1.666 MHz (default at reset) */
  395. BCM283X_I2C_CLOCK_DIVIDER_148 = 148 /* 148 = 59ns = 1.689 MHz */
  396. } i2c_clock_divider;
  397. typedef enum
  398. {
  399. BCM283X_I2C_REASON_OK = 0x00, /* Success */
  400. BCM283X_I2C_REASON_ERROR_NACK = 0x01, /* Received a NACK */
  401. BCM283X_I2C_REASON_ERROR_CLKT = 0x02, /* Received Clock Stretch Timeout */
  402. BCM283X_I2C_REASON_ERROR_DATA = 0x04 /* Not all data is sent / received */
  403. } i2c_reason_codes;
  404. #endif