bcm283x.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-07-15 RT-Thread the first version
  9. * 2019-07-29 zdzn add macro definition
  10. */
  11. #ifndef __BCM283X_H__
  12. #define __BCM283X_H__
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. #define PER_BASE (0x3F000000)
  16. #define PER_BASE_40000000 (0x40000000)
  17. #define HIGH 0x1
  18. #define LOW 0x0
  19. #define BCM283X_CORE_CLK_HZ 250000000 /* 50 MHz */
  20. /*! Offsets for the bases of various peripherals within the peripherals block
  21. * Base Address of the System Timer registers
  22. */
  23. /*! Base Address of the Pads registers */
  24. #define BCM283X_GPIO_PADS 0x100000
  25. /*! Base Address of the Clock/timer registers */
  26. #define BCM283X_CLOCK_BASE 0x101000
  27. /*! Base Address of the GPIO registers */
  28. //#define BCM283X_GPIO_BASE 0x200000
  29. /*! Base Address of the SPI0 registers */
  30. #define BCM283X_SPI0_BASE 0x204000
  31. /*! Base Address of the PWM registers */
  32. #define BCM283X_GPIO_PWM 0x20C000
  33. /*! Base Address of the AUX registers */
  34. #define BCM283X_AUX_BASE 0x215000
  35. /*! Base Address of the AUX_SPI1 registers */
  36. #define BCM283X_SPI1_BASE 0x215080
  37. /*! Base Address of the AUX_SPI2 registers */
  38. #define BCM283X_SPI2_BASE 0x2150C0
  39. /*! Base Address of the BSC0 registers */
  40. #define BCM283X_BSC0_BASE 0x205000 //for i2c0
  41. /*! Base Address of the BSC1 registers */
  42. #define BCM283X_BSC1_BASE 0x804000 //for i2c1
  43. /*! Base Address of the BSC1 registers */
  44. #define BCM283X_BSC2_BASE 0x805000 //for hdmi i2c not use
  45. /*
  46. * GPIO
  47. */
  48. #define GPIO_BASE (PER_BASE + 0x200000)
  49. #define GPIO_GPFSEL0 HWREG32(GPIO_BASE + 0x0000) /* GPIO Function Select 0 32bit R/W */
  50. #define GPIO_GPFSEL1 HWREG32(GPIO_BASE + 0x0004) /* GPIO Function Select 1 32bit R/W */
  51. #define GPIO_GPFSEL2 HWREG32(GPIO_BASE + 0x0008) /* GPIO Function Select 2 32bit R/W */
  52. #define GPIO_GPFSEL4 HWREG32(GPIO_BASE + 0x0010) /* GPIO Function Select 4 32bit R/W */
  53. #define GPIO_GPFSEL5 HWREG32(GPIO_BASE + 0x0014) /* GPIO Function Select 5 32bit R/W */
  54. #define GPIO_GPSET0 HWREG32(GPIO_BASE + 0x001C)
  55. #define GPIO_GPSET1 HWREG32(GPIO_BASE + 0x0020)
  56. #define GPIO_GPCLR0 HWREG32(GPIO_BASE + 0x0028)
  57. #define GPIO_GPCLR1 HWREG32(GPIO_BASE + 0x002C)
  58. #define GPIO_GPEDS0 HWREG32(GPIO_BASE + 0x0040) /* GPIO Pin Event Detect Status */
  59. #define GPIO_GPEDS1 HWREG32(GPIO_BASE + 0x0044)
  60. #define GPIO_GPREN0 HWREG32(GPIO_BASE + 0x004c) /* GPIO Pin Rising Edge Detect Enable */
  61. #define GPIO_GPREN1 HWREG32(GPIO_BASE + 0x0050)
  62. #define GPIO_GPFEN0 HWREG32(GPIO_BASE + 0x0058) /* GPIO Pin Falling Edge Detect Enable */
  63. #define GPIO_GPFEN1 HWREG32(GPIO_BASE + 0x005C)
  64. #define GPIO_GPHEN0 HWREG32(GPIO_BASE + 0x0064) /* GPIO Pin High Detect Enable */
  65. #define GPIO_GPHEN1 HWREG32(GPIO_BASE + 0x0068)
  66. #define GPIO_GPLEN0 HWREG32(GPIO_BASE + 0x0070) /* GPIO Pin Low Detect Enable 0 */
  67. #define GPIO_GPLEN1 HWREG32(GPIO_BASE + 0x0074)
  68. #define GPIO_GPAREN0 HWREG32(GPIO_BASE + 0x007C) /* GPIO Pin Async. Rising Edge Detect */
  69. #define GPIO_GPAREN1 HWREG32(GPIO_BASE + 0x0080)
  70. #define GPIO_GPAFEN0 HWREG32(GPIO_BASE + 0x0088) /* GPIO Pin Async. Falling Edge Detect */
  71. #define GPIO_GPAFEN1 HWREG32(GPIO_BASE + 0x008C)
  72. #define GPIO_GPPUD HWREG32(GPIO_BASE + 0x0094) /* GPIO Pin Pull-up/down Enable */
  73. #define GPIO_GPPUDCLK0 HWREG32(GPIO_BASE + 0x0098) /* GPIO Pin Pull-up/down Enable Clock 0 */
  74. #define GPIO_GPPUDCLK1 HWREG32(GPIO_BASE + 0x009C) /* GPIO Pin Pull-up/down Enable Clock 1 */
  75. #define BCM283X_GPIO_BASE (PER_BASE + 0x200000)
  76. #define BCM283X_GPIO_GPFSEL0 (0x0000) /* GPIO Function Select 0 32bit R/W */
  77. #define BCM283X_GPIO_GPFSEL1 (0x0004) /* GPIO Function Select 1 32bit R/W */
  78. #define BCM283X_GPIO_GPFSEL2 (0x0008) /* GPIO Function Select 2 32bit R/W */
  79. #define BCM283X_GPIO_GPFSEL4 (0x0010) /* GPIO Function Select 4 32bit R/W */
  80. #define BCM283X_GPIO_GPFSEL5 (0x0014) /* GPIO Function Select 5 32bit R/W */
  81. #define BCM283X_GPIO_GPSET0 (0x001C)
  82. #define BCM283X_GPIO_GPSET1 (0x0020)
  83. #define BCM283X_GPIO_GPCLR0 (0x0028)
  84. #define BCM283X_GPIO_GPCLR1 (0x002C)
  85. #define BCM2835_GPIO_GPLEV0 (0x0034) /*!< GPIO Pin Level 0 */
  86. #define BCM2835_GPIO_GPLEV1 (0x0038) /*!< GPIO Pin Level 1 */
  87. #define BCM283X_GPIO_GPEDS0 (0x0040) /* GPIO Pin Event Detect Status */
  88. #define BCM283X_GPIO_GPEDS1 (0x0044)
  89. #define BCM283X_GPIO_GPREN0 (0x004c) /* GPIO Pin Rising Edge Detect Enable */
  90. #define BCM283X_GPIO_GPREN1 (0x0050)
  91. #define BCM283X_GPIO_GPFEN0 (0x0058) /* GPIO Pin Falling Edge Detect Enable */
  92. #define BCM283X_GPIO_GPFEN1 (0x005C)
  93. #define BCM283X_GPIO_GPHEN0 (0x0064) /* GPIO Pin High Detect Enable */
  94. #define BCM283X_GPIO_GPHEN1 (0x0068)
  95. #define BCM283X_GPIO_GPLEN0 (0x0070) /* GPIO Pin Low Detect Enable 0 */
  96. #define BCM283X_GPIO_GPLEN1 (0x0074)
  97. #define BCM283X_GPIO_GPAREN0 (0x007C) /* GPIO Pin Async. Rising Edge Detect */
  98. #define BCM283X_GPIO_GPAREN1 (0x0080)
  99. #define BCM283X_GPIO_GPAFEN0 (0x0088) /* GPIO Pin Async. Falling Edge Detect */
  100. #define BCM283X_GPIO_GPAFEN1 (0x008C)
  101. #define BCM283X_GPIO_GPPUD (0x0094) /* GPIO Pin Pull-up/down Enable */
  102. #define BCM283X_GPIO_GPPUDCLK0 (0x0098) /* GPIO Pin Pull-up/down Enable Clock 0 */
  103. #define BCM283X_GPIO_GPPUDCLK1 (0x009C) /* GPIO Pin Pull-up/down Enable Clock 1 */
  104. enum gpio_function_select
  105. {
  106. BCM283X_GPIO_FSEL_INPT = 0x00, /*!< Input 0b000 */
  107. BCM283X_GPIO_FSEL_OUTP = 0x01, /*!< Output 0b001 */
  108. BCM283X_GPIO_FSEL_ALT0 = 0x04, /*!< Alternate function 0 0b100 */
  109. BCM283X_GPIO_FSEL_ALT1 = 0x05, /*!< Alternate function 1 0b101 */
  110. BCM283X_GPIO_FSEL_ALT2 = 0x06, /*!< Alternate function 2 0b110, */
  111. BCM283X_GPIO_FSEL_ALT3 = 0x07, /*!< Alternate function 3 0b111 */
  112. BCM283X_GPIO_FSEL_ALT4 = 0x03, /*!< Alternate function 4 0b011 */
  113. BCM283X_GPIO_FSEL_ALT5 = 0x02, /*!< Alternate function 5 0b010 */
  114. BCM283X_GPIO_FSEL_MASK = 0x07 /*!< Function select bits mask 0b111 */
  115. };
  116. enum gpio_pud_mode
  117. {
  118. BCM283X_GPIO_PUD_OFF = 0x00, /*!< Off ? disable pull-up/down 0b00 */
  119. BCM283X_GPIO_PUD_DOWN = 0x01, /*!< Enable Pull Down control 0b01 */
  120. BCM283X_GPIO_PUD_UP = 0x02 /*!< Enable Pull Up control 0b10 */
  121. };
  122. /* Defines for BSC I2C
  123. * GPIO register offsets from BCM283X_BSC*_BASE.
  124. * Offsets into the BSC Peripheral block in bytes per 3.1 BSC Register Map
  125. */
  126. /* I2C Address Map offset address */
  127. #define BCM283X_BSC_C 0x0000 /*!< BSC Master Control */
  128. #define BCM283X_BSC_S 0x0004 /*!< BSC Master Status */
  129. #define BCM283X_BSC_DLEN 0x0008 /*!< BSC Master Data Length */
  130. #define BCM283X_BSC_A 0x000c /*!< BSC Master Slave Address */
  131. #define BCM283X_BSC_FIFO 0x0010 /*!< BSC Master Data FIFO */
  132. #define BCM283X_BSC_DIV 0x0014 /*!< BSC Master Clock Divider */
  133. #define BCM283X_BSC_DEL 0x0018 /*!< BSC Master Data Delay */
  134. #define BCM283X_BSC_CLKT 0x001c /*!< BSC Master Clock Stretch Timeout */
  135. /* Register masks for C Register */
  136. #define BCM283X_BSC_C_I2CEN 0x00008000 /*!< I2C Enable, 0 = disabled, 1 = enabled */
  137. #define BCM283X_BSC_C_INTR 0x00000400 /*!< Interrupt on RX */
  138. #define BCM283X_BSC_C_INTT 0x00000200 /*!< Interrupt on TX */
  139. #define BCM283X_BSC_C_INTD 0x00000100 /*!< Interrupt on DONE */
  140. #define BCM283X_BSC_C_ST 0x00000080 /*!< Start transfer, 1 = Start a new transfer */
  141. #define BCM283X_BSC_C_CLEAR_1 0x00000020 /*!< Clear FIFO Clear */
  142. #define BCM283X_BSC_C_CLEAR_2 0x00000010 /*!< Clear FIFO Clear */
  143. #define BCM283X_BSC_C_READ 0x00000001 /*!< Read transfer */
  144. /* Register masks for S Register */
  145. #define BCM283X_BSC_S_CLKT 0x00000200 /*!< Clock stretch timeout */
  146. #define BCM283X_BSC_S_ERR 0x00000100 /*!< ACK error */
  147. #define BCM283X_BSC_S_RXF 0x00000080 /*!< RXF FIFO full, 0 = FIFO is not full, 1 = FIFO is full */
  148. #define BCM283X_BSC_S_TXE 0x00000040 /*!< TXE FIFO full, 0 = FIFO is not full, 1 = FIFO is full */
  149. #define BCM283X_BSC_S_RXD 0x00000020 /*!< RXD FIFO contains data */
  150. #define BCM283X_BSC_S_TXD 0x00000010 /*!< TXD FIFO can accept data */
  151. #define BCM283X_BSC_S_RXR 0x00000008 /*!< RXR FIFO needs reading (full) */
  152. #define BCM283X_BSC_S_TXW 0x00000004 /*!< TXW FIFO needs writing (full) */
  153. #define BCM283X_BSC_S_DONE 0x00000002 /*!< Transfer DONE */
  154. #define BCM283X_BSC_S_TA 0x00000001 /*!< Transfer Active */
  155. #define BCM283X_BSC_FIFO_SIZE 16 /*!< BSC FIFO size */
  156. enum i2c_clock_divider
  157. {
  158. BCM283X_I2C_CLOCK_DIVIDER_2500 = 2500, /*!< 2500 = 10us = 100 kHz */
  159. BCM283X_I2C_CLOCK_DIVIDER_626 = 626, /*!< 622 = 2.504us = 399.3610 kHz */
  160. BCM283X_I2C_CLOCK_DIVIDER_150 = 150, /*!< 150 = 60ns = 1.666 MHz (default at reset) */
  161. BCM283X_I2C_CLOCK_DIVIDER_148 = 148 /*!< 148 = 59ns = 1.689 MHz */
  162. };
  163. enum i2c_reason_codes
  164. {
  165. BCM283X_I2C_REASON_OK = 0x00, /*!< Success */
  166. BCM283X_I2C_REASON_ERROR_NACK = 0x01, /*!< Received a NACK */
  167. BCM283X_I2C_REASON_ERROR_CLKT = 0x02, /*!< Received Clock Stretch Timeout */
  168. BCM283X_I2C_REASON_ERROR_DATA = 0x04 /*!< Not all data is sent / received */
  169. };
  170. /*
  171. * Interrupt Controler
  172. */
  173. #define IRQ_BASE (PER_BASE + 0xB200)
  174. #define IRQ_PEND_BASIC HWREG32(IRQ_BASE + 0x00)
  175. #define IRQ_PEND1 HWREG32(IRQ_BASE + 0x04)
  176. #define IRQ_PEND2 HWREG32(IRQ_BASE + 0x08)
  177. #define IRQ_FIQ_CONTROL HWREG32(IRQ_BASE + 0x0C)
  178. #define IRQ_ENABLE1 HWREG32(IRQ_BASE + 0x10)
  179. #define IRQ_ENABLE2 HWREG32(IRQ_BASE + 0x14)
  180. #define IRQ_ENABLE_BASIC HWREG32(IRQ_BASE + 0x18)
  181. #define IRQ_DISABLE1 HWREG32(IRQ_BASE + 0x1C)
  182. #define IRQ_DISABLE2 HWREG32(IRQ_BASE + 0x20)
  183. #define IRQ_DISABLE_BASIC HWREG32(IRQ_BASE + 0x24)
  184. /*
  185. * System Timer
  186. */
  187. #define STIMER_BASE (PER_BASE + 0x3000)
  188. #define STIMER_CS HWREG32(STIMER_BASE + 0x00)
  189. #define STIMER_CLO HWREG32(STIMER_BASE + 0x04)
  190. #define STIMER_CHI HWREG32(STIMER_BASE + 0x08)
  191. #define STIMER_C0 HWREG32(STIMER_BASE + 0x0C)
  192. #define STIMER_C1 HWREG32(STIMER_BASE + 0x10)
  193. #define STIMER_C2 HWREG32(STIMER_BASE + 0x14)
  194. #define STIMER_C3 HWREG32(STIMER_BASE + 0x18)
  195. /* Defines for ST */
  196. #define BCM283X_ST_BASE (PER_BASE + 0x3000)
  197. #define BCM283X_ST_CS 0x0000 /*!< System Timer Control/Status */
  198. #define BCM283X_ST_CLO 0x0004 /*!< System Timer Counter Lower 32 bits */
  199. #define BCM283X_ST_CHI 0x0008 /*!< System Timer Counter Upper 32 bits */
  200. #define BCM283X_ST_C0 0x000C
  201. #define BCM283X_ST_C1 0x0010
  202. #define BCM283X_ST_C2 0x0014
  203. #define BCM283X_ST_C3 0x0018
  204. /*
  205. * ARM Timer
  206. */
  207. #define ARM_TIMER_BASE (PER_BASE + 0xB000)
  208. #define ARM_TIMER_LOAD HWREG32(ARM_TIMER_BASE + 0x400)
  209. #define ARM_TIMER_VALUE HWREG32(ARM_TIMER_BASE + 0x404)
  210. #define ARM_TIMER_CTRL HWREG32(ARM_TIMER_BASE + 0x408)
  211. #define ARM_TIMER_IRQCLR HWREG32(ARM_TIMER_BASE + 0x40C)
  212. #define ARM_TIMER_RAWIRQ HWREG32(ARM_TIMER_BASE + 0x410)
  213. #define ARM_TIMER_MASKIRQ HWREG32(ARM_TIMER_BASE + 0x414)
  214. #define ARM_TIMER_RELOAD HWREG32(ARM_TIMER_BASE + 0x418)
  215. #define ARM_TIMER_PREDIV HWREG32(ARM_TIMER_BASE + 0x41C)
  216. #define ARM_TIMER_CNTR HWREG32(ARM_TIMER_BASE + 0x420)
  217. /*
  218. * Core Timer
  219. */
  220. #define CTIMER_CTL HWREG32(PER_BASE_40000000 + 0x00) /* Control register */
  221. #define CTIMER_PRE HWREG32(PER_BASE_40000000 + 0x08) /* Core timer prescaler */
  222. #define CTIMER_LS32B HWREG32(PER_BASE_40000000 + 0x1C) /* Core timer access LS 32 bits */
  223. #define CTIMER_MS32B HWREG32(PER_BASE_40000000 + 0x20) /* Core timer access MS 32 bits */
  224. /*
  225. * ARM Core Timer
  226. */
  227. #define C0TIMER_INTCTL HWREG32(PER_BASE_40000000 + 0x40) /* Core0 timers Interrupt control */
  228. #define C1TIMER_INTCTL HWREG32(PER_BASE_40000000 + 0x44) /* Core1 timers Interrupt control */
  229. #define C2TIMER_INTCTL HWREG32(PER_BASE_40000000 + 0x48) /* Core2 timers Interrupt control */
  230. #define C3TIMER_INTCTL HWREG32(PER_BASE_40000000 + 0x4C) /* Core3 timers Interrupt control */
  231. #define CORETIMER_INTCTL(n) HWREG32(PER_BASE_40000000 + 0x40 + n*4) /* Core3 timers Interrupt control */
  232. /*
  233. * ARM Core Mailbox interrupt
  234. */
  235. #define C0MB_INTCTL HWREG32(PER_BASE_40000000 + 0x50) /* Core0 Mailboxes Interrupt control */
  236. #define C1MB_INTCTL HWREG32(PER_BASE_40000000 + 0x54) /* Core1 Mailboxes Interrupt control */
  237. #define C2MB_INTCTL HWREG32(PER_BASE_40000000 + 0x58) /* Core2 Mailboxes Interrupt control */
  238. #define C3MB_INTCTL HWREG32(PER_BASE_40000000 + 0x5C) /* Core3 Mailboxes Interrupt control */
  239. #define COREMB_INTCTL(n) HWREG32(PER_BASE_40000000 + 0x50 + 4*n) /* Core3 Mailboxes Interrupt control */
  240. /*
  241. * ARM Core IRQ/FIQ status
  242. */
  243. #define C0_IRQSOURCE HWREG32(PER_BASE_40000000 + 0x60) /* Core0 IRQ Source */
  244. #define C1_IRQSOURCE HWREG32(PER_BASE_40000000 + 0x64) /* Core1 IRQ Source */
  245. #define C2_IRQSOURCE HWREG32(PER_BASE_40000000 + 0x68) /* Core2 IRQ Source */
  246. #define C3_IRQSOURCE HWREG32(PER_BASE_40000000 + 0x6C) /* Core3 IRQ Source */
  247. #define C0_FIQSOURCE HWREG32(PER_BASE_40000000 + 0x70) /* Core0 FIQ Source */
  248. #define C1_FIQSOURCE HWREG32(PER_BASE_40000000 + 0x74) /* Core1 FIQ Source */
  249. #define C2_FIQSOURCE HWREG32(PER_BASE_40000000 + 0x78) /* Core2 FIQ Source */
  250. #define C3_FIQSOURCE HWREG32(PER_BASE_40000000 + 0x7C) /* Core3 FIQ Source */
  251. #define CORE_IRQSOURCE(n) HWREG32(PER_BASE_40000000 + 0x60+ n*0x4)
  252. #define CORE_FIQSOURCE(n) HWREG32(PER_BASE_40000000 + 0x70+ n*0x4)
  253. #define CORE_MAILBOX3_SET(n) HWREG32(PER_BASE_40000000 + 0x8C + n*0x10)
  254. #define CORE_MAILBOX3_CLEAR(n) HWREG32(PER_BASE_40000000 + 0xCC + n*0x10)
  255. #define CORE_MAILBOX2_SET(n) HWREG32(PER_BASE_40000000 + 0x88 + n*0x10)
  256. #define CORE_MAILBOX2_CLEAR(n) HWREG32(PER_BASE_40000000 + 0xC8 + n*0x10)
  257. #define CORE_MAILBOX1_SET(n) HWREG32(PER_BASE_40000000 + 0x84 + n*0x10)
  258. #define CORE_MAILBOX1_CLEAR(n) HWREG32(PER_BASE_40000000 + 0xC4 + n*0x10)
  259. #define CORE_MAILBOX0_SET(n) HWREG32(PER_BASE_40000000 + 0x80 + n*0x10)
  260. #define CORE_MAILBOX0_CLEAR(n) HWREG32(PER_BASE_40000000 + 0xC0 + n*0x10)
  261. /* for smp ipi using mailbox0 */
  262. #define IPI_MAILBOX_SET CORE_MAILBOX0_SET
  263. #define IPI_MAILBOX_CLEAR CORE_MAILBOX0_CLEAR
  264. #define IPI_MAILBOX_INT_MASK (0x01)
  265. #define IRQ_ARM_TIMER 64
  266. #define IRQ_ARM_MAILBOX 65
  267. #define IRQ_ARM_DB0 66
  268. #define IRQ_ARM_DB1 67
  269. #define IRQ_ARM_GPU0_HALT 68
  270. #define IRQ_ARM_GPU1_HALT 69
  271. #define IRQ_ARM_ILLEGAL_ACC1 70
  272. #define IRQ_ARM_ILLEGAL_ACC0 71
  273. #define IRQ_SYSTIMER_MATCH_1 1
  274. #define IRQ_SYSTIMER_MATCH_3 3
  275. #define IRQ_AUX 29
  276. #define IRQ_IIC_SPI_SLV 43
  277. #define IRQ_PWA0 45
  278. #define IRQ_PWA1 46
  279. #define IRQ_SMI 48
  280. #define IRQ_GPIO0 49
  281. #define IRQ_GPIO1 50
  282. #define IRQ_GPIO2 51
  283. #define IRQ_GPIO3 52
  284. #define IRQ_IIC 53
  285. #define IRQ_SPI 54
  286. #define IRQ_PCM 55
  287. #define IRQ_UART 57
  288. /* CLOCK */
  289. #define BCM283X_PLLA 0
  290. #define BCM283X_PLLB 1
  291. #define BCM283X_PLLC 2
  292. #define BCM283X_PLLD 3
  293. #define BCM283X_PLLH 4
  294. #define BCM283X_PLLA_CORE 5
  295. #define BCM283X_PLLA_PER 6
  296. #define BCM283X_PLLB_ARM 7
  297. #define BCM283X_PLLC_CORE0 8
  298. #define BCM283X_PLLC_CORE1 9
  299. #define BCM283X_PLLC_CORE2 10
  300. #define BCM283X_PLLC_PER 11
  301. #define BCM283X_PLLD_CORE 12
  302. #define BCM283X_PLLD_PER 13
  303. #define BCM283X_PLLH_RCAL 14
  304. #define BCM283X_PLLH_AUX 15
  305. #define BCM283X_PLLH_PIX 16
  306. #define BCM283X_CLOCK_TIMER 17
  307. #define BCM283X_CLOCK_OTP 18
  308. #define BCM283X_CLOCK_UART 19
  309. #define BCM283X_CLOCK_VPU 20
  310. #define BCM283X_CLOCK_V3D 21
  311. #define BCM283X_CLOCK_ISP 22
  312. #define BCM283X_CLOCK_H264 23
  313. #define BCM283X_CLOCK_VEC 24
  314. #define BCM283X_CLOCK_HSM 25
  315. #define BCM283X_CLOCK_SDRAM 26
  316. #define BCM283X_CLOCK_TSENS 27
  317. #define BCM283X_CLOCK_EMMC 28
  318. #define BCM283X_CLOCK_PERI_IMAGE 29
  319. #define BCM283X_CLOCK_COUNT 30
  320. #define CM_PASSWORD 0x5a000000
  321. #define CM_GNRICCTL 0x000
  322. #define CM_GNRICDIV 0x004
  323. #define CM_VPUCTL 0x008
  324. #define CM_VPUDIV 0x00c
  325. #define CM_SYSCTL 0x010
  326. #define CM_SYSDIV 0x014
  327. #define CM_PERIACTL 0x018
  328. #define CM_PERIADIV 0x01c
  329. #define CM_PERIICTL 0x020
  330. #define CM_PERIIDIV 0x024
  331. #define CM_H264CTL 0x028
  332. #define CM_H264DIV 0x02c
  333. #define CM_ISPCTL 0x030
  334. #define CM_ISPDIV 0x034
  335. #define CM_V3DCTL 0x038
  336. #define CM_V3DDIV 0x03c
  337. #define CM_CAM0CTL 0x040
  338. #define CM_CAM0DIV 0x044
  339. #define CM_CAM1CTL 0x048
  340. #define CM_CAM1DIV 0x04c
  341. #define CM_CCP2CTL 0x050
  342. #define CM_CCP2DIV 0x054
  343. #define CM_DSI0ECTL 0x058
  344. #define CM_DSI0EDIV 0x05c
  345. #define CM_DSI0PCTL 0x060
  346. #define CM_DSI0PDIV 0x064
  347. #define CM_DPICTL 0x068
  348. #define CM_DPIDIV 0x06c
  349. #define CM_GP0CTL 0x070
  350. #define CM_GP0DIV 0x074
  351. #define CM_GP1CTL 0x078
  352. #define CM_GP1DIV 0x07c
  353. #define CM_GP2CTL 0x080
  354. #define CM_GP2DIV 0x084
  355. #define CM_HSMCTL 0x088
  356. #define CM_HSMDIV 0x08c
  357. #define CM_OTPCTL 0x090
  358. #define CM_OTPDIV 0x094
  359. #define CM_PWMCTL 0x0a0
  360. #define CM_PWMDIV 0x0a4
  361. #define CM_SMICTL 0x0b0
  362. #define CM_SMIDIV 0x0b4
  363. #define CM_TSENSCTL 0x0e0
  364. #define CM_TSENSDIV 0x0e4
  365. #define CM_TIMERCTL 0x0e8
  366. #define CM_TIMERDIV 0x0ec
  367. #define CM_UARTCTL 0x0f0
  368. #define CM_UARTDIV 0x0f4
  369. #define CM_VECCTL 0x0f8
  370. #define CM_VECDIV 0x0fc
  371. #define CM_PULSECTL 0x190
  372. #define CM_PULSEDIV 0x194
  373. #define CM_SDCCTL 0x1a8
  374. #define CM_SDCDIV 0x1ac
  375. #define CM_ARMCTL 0x1b0
  376. #define CM_EMMCCTL 0x1c0
  377. #define CM_EMMCDIV 0x1c4
  378. #define BCM283X_AUX_IRQ 0x0000 /*!< xxx */
  379. #define BCM283X_AUX_ENABLE 0x0004 /*!< */
  380. #define BCM283X_AUX_ENABLE_UART1 0x01 /*!< */
  381. #define BCM283X_AUX_ENABLE_SPI0 0x02 /*!< SPI0 (SPI1 in the device) */
  382. #define BCM283X_AUX_ENABLE_SPI1 0x04 /*!< SPI1 (SPI2 in the device) */
  383. #define BCM283X_AUX_SPI_CNTL0 0x0000 /*!< */
  384. #define BCM283X_AUX_SPI_CNTL1 0x0004 /*!< */
  385. #define BCM283X_AUX_SPI_STAT 0x0008 /*!< */
  386. #define BCM283X_AUX_SPI_PEEK 0x000C /*!< Read but do not take from FF */
  387. #define BCM283X_AUX_SPI_IO 0x0020 /*!< Write = TX, read=RX */
  388. #define BCM283X_AUX_SPI_TXHOLD 0x0030 /*!< Write = TX keep CS, read=RX */
  389. #define BCM283X_AUX_SPI_CLOCK_MIN 30500 /*!< 30,5kHz */
  390. #define BCM283X_AUX_SPI_CLOCK_MAX 125000000 /*!< 125Mhz */
  391. #define BCM283X_AUX_SPI_CNTL0_SPEED 0xFFF00000 /*!< */
  392. #define BCM283X_AUX_SPI_CNTL0_SPEED_MAX 0xFFF /*!< */
  393. #define BCM283X_AUX_SPI_CNTL0_SPEED_SHIFT 20 /*!< */
  394. #define BCM283X_AUX_SPI_CNTL0_CS0_N 0x000C0000 /*!< CS 0 low */
  395. #define BCM283X_AUX_SPI_CNTL0_CS1_N 0x000A0000 /*!< CS 1 low */
  396. #define BCM283X_AUX_SPI_CNTL0_CS2_N 0x00060000 /*!< CS 2 low */
  397. #define BCM283X_AUX_SPI_CNTL0_POSTINPUT 0x00010000 /*!< */
  398. #define BCM283X_AUX_SPI_CNTL0_VAR_CS 0x00008000 /*!< */
  399. #define BCM283X_AUX_SPI_CNTL0_VAR_WIDTH 0x00004000 /*!< */
  400. #define BCM283X_AUX_SPI_CNTL0_DOUTHOLD 0x00003000 /*!< */
  401. #define BCM283X_AUX_SPI_CNTL0_ENABLE 0x00000800 /*!< */
  402. #define BCM283X_AUX_SPI_CNTL0_CPHA_IN 0x00000400 /*!< */
  403. #define BCM283X_AUX_SPI_CNTL0_CLEARFIFO 0x00000200 /*!< */
  404. #define BCM283X_AUX_SPI_CNTL0_CPHA_OUT 0x00000100 /*!< */
  405. #define BCM283X_AUX_SPI_CNTL0_CPOL 0x00000080 /*!< */
  406. #define BCM283X_AUX_SPI_CNTL0_MSBF_OUT 0x00000040 /*!< */
  407. #define BCM283X_AUX_SPI_CNTL0_SHIFTLEN 0x0000003F /*!< */
  408. #define BCM283X_AUX_SPI_CNTL1_CSHIGH 0x00000700 /*!< */
  409. #define BCM283X_AUX_SPI_CNTL1_IDLE 0x00000080 /*!< */
  410. #define BCM283X_AUX_SPI_CNTL1_TXEMPTY 0x00000040 /*!< */
  411. #define BCM283X_AUX_SPI_CNTL1_MSBF_IN 0x00000002 /*!< */
  412. #define BCM283X_AUX_SPI_CNTL1_KEEP_IN 0x00000001 /*!< */
  413. #define BCM283X_AUX_SPI_STAT_TX_LVL 0xFF000000 /*!< */
  414. #define BCM283X_AUX_SPI_STAT_RX_LVL 0x00FF0000 /*!< */
  415. #define BCM283X_AUX_SPI_STAT_TX_FULL 0x00000400 /*!< */
  416. #define BCM283X_AUX_SPI_STAT_TX_EMPTY 0x00000200 /*!< */
  417. #define BCM283X_AUX_SPI_STAT_RX_FULL 0x00000100 /*!< */
  418. #define BCM283X_AUX_SPI_STAT_RX_EMPTY 0x00000080 /*!< */
  419. #define BCM283X_AUX_SPI_STAT_BUSY 0x00000040 /*!< */
  420. #define BCM283X_AUX_SPI_STAT_BITCOUNT 0x0000003F /*!< */
  421. /* Defines for SPI */
  422. #define BCM283X_SPI0_CS 0x0000 /*!< SPI Master Control and Status */
  423. #define BCM283X_SPI0_FIFO 0x0004 /*!< SPI Master TX and RX FIFOs */
  424. #define BCM283X_SPI0_CLK 0x0008 /*!< SPI Master Clock Divider */
  425. #define BCM283X_SPI0_DLEN 0x000c /*!< SPI Master Data Length */
  426. #define BCM283X_SPI0_LTOH 0x0010 /*!< SPI LOSSI mode TOH */
  427. #define BCM283X_SPI0_DC 0x0014 /*!< SPI DMA DREQ Controls */
  428. /* Register masks for SPI0_CS */
  429. #define BCM283X_SPI0_CS_LEN_LONG 0x02000000 /*!< Enable Long data word in Lossi mode if DMA_LEN is set */
  430. #define BCM283X_SPI0_CS_DMA_LEN 0x01000000 /*!< Enable DMA mode in Lossi mode */
  431. #define BCM283X_SPI0_CS_CSPOL2 0x00800000 /*!< Chip Select 2 Polarity */
  432. #define BCM283X_SPI0_CS_CSPOL1 0x00400000 /*!< Chip Select 1 Polarity */
  433. #define BCM283X_SPI0_CS_CSPOL0 0x00200000 /*!< Chip Select 0 Polarity */
  434. #define BCM283X_SPI0_CS_RXF 0x00100000 /*!< RXF - RX FIFO Full */
  435. #define BCM283X_SPI0_CS_RXR 0x00080000 /*!< RXR RX FIFO needs Reading (full) */
  436. #define BCM283X_SPI0_CS_TXD 0x00040000 /*!< TXD TX FIFO can accept Data */
  437. #define BCM283X_SPI0_CS_RXD 0x00020000 /*!< RXD RX FIFO contains Data */
  438. #define BCM283X_SPI0_CS_DONE 0x00010000 /*!< Done transfer Done */
  439. #define BCM283X_SPI0_CS_TE_EN 0x00008000 /*!< Unused */
  440. #define BCM283X_SPI0_CS_LMONO 0x00004000 /*!< Unused */
  441. #define BCM283X_SPI0_CS_LEN 0x00002000 /*!< LEN LoSSI enable */
  442. #define BCM283X_SPI0_CS_REN 0x00001000 /*!< REN Read Enable */
  443. #define BCM283X_SPI0_CS_ADCS 0x00000800 /*!< ADCS Automatically Deassert Chip Select */
  444. #define BCM283X_SPI0_CS_INTR 0x00000400 /*!< INTR Interrupt on RXR */
  445. #define BCM283X_SPI0_CS_INTD 0x00000200 /*!< INTD Interrupt on Done */
  446. #define BCM283X_SPI0_CS_DMAEN 0x00000100 /*!< DMAEN DMA Enable */
  447. #define BCM283X_SPI0_CS_TA 0x00000080 /*!< Transfer Active */
  448. #define BCM283X_SPI0_CS_CSPOL 0x00000040 /*!< Chip Select Polarity */
  449. #define BCM283X_SPI0_CS_CLEAR 0x00000030 /*!< Clear FIFO Clear RX and TX */
  450. #define BCM283X_SPI0_CS_CLEAR_RX 0x00000020 /*!< Clear FIFO Clear RX */
  451. #define BCM283X_SPI0_CS_CLEAR_TX 0x00000010 /*!< Clear FIFO Clear TX */
  452. #define BCM283X_SPI0_CS_CPOL 0x00000008 /*!< Clock Polarity */
  453. #define BCM283X_SPI0_CS_CPHA 0x00000004 /*!< Clock Phase */
  454. #define BCM283X_SPI0_CS_CS 0x00000003 /*!< Chip Select */
  455. enum spi_bit_order
  456. {
  457. BCM283X_SPI_BIT_ORDER_LSBFIRST = 0, /*!< LSB First */
  458. BCM283X_SPI_BIT_ORDER_MSBFIRST = 1 /*!< MSB First */
  459. };
  460. enum spi_mode
  461. {
  462. BCM283X_SPI_MODE0 = 0, /*!< CPOL = 0, CPHA = 0 */
  463. BCM283X_SPI_MODE1 = 1, /*!< CPOL = 0, CPHA = 1 */
  464. BCM283X_SPI_MODE2 = 2, /*!< CPOL = 1, CPHA = 0 */
  465. BCM283X_SPI_MODE3 = 3 /*!< CPOL = 1, CPHA = 1 */
  466. };
  467. enum spi_chip_select
  468. {
  469. BCM283X_SPI_CS0 = 0, /*!< Chip Select 0 */
  470. BCM283X_SPI_CS1 = 1, /*!< Chip Select 1 */
  471. BCM283X_SPI_CS2 = 2, /*!< Chip Select 2 (ie pins CS1 and CS2 are asserted) */
  472. BCM283X_SPI_CS_NONE = 3 /*!< No CS, control it yourself */
  473. };
  474. enum spi_clock_divider
  475. {
  476. BCM283X_SPI_CLOCK_DIVIDER_65536 = 0, /*!< 65536 = 3.814697260kHz on Rpi2, 6.1035156kHz on RPI3 */
  477. BCM283X_SPI_CLOCK_DIVIDER_32768 = 32768, /*!< 32768 = 7.629394531kHz on Rpi2, 12.20703125kHz on RPI3 */
  478. BCM283X_SPI_CLOCK_DIVIDER_16384 = 16384, /*!< 16384 = 15.25878906kHz on Rpi2, 24.4140625kHz on RPI3 */
  479. BCM283X_SPI_CLOCK_DIVIDER_8192 = 8192, /*!< 8192 = 30.51757813kHz on Rpi2, 48.828125kHz on RPI3 */
  480. BCM283X_SPI_CLOCK_DIVIDER_4096 = 4096, /*!< 4096 = 61.03515625kHz on Rpi2, 97.65625kHz on RPI3 */
  481. BCM283X_SPI_CLOCK_DIVIDER_2048 = 2048, /*!< 2048 = 122.0703125kHz on Rpi2, 195.3125kHz on RPI3 */
  482. BCM283X_SPI_CLOCK_DIVIDER_1024 = 1024, /*!< 1024 = 244.140625kHz on Rpi2, 390.625kHz on RPI3 */
  483. BCM283X_SPI_CLOCK_DIVIDER_512 = 512, /*!< 512 = 488.28125kHz on Rpi2, 781.25kHz on RPI3 */
  484. BCM283X_SPI_CLOCK_DIVIDER_256 = 256, /*!< 256 = 976.5625kHz on Rpi2, 1.5625MHz on RPI3 */
  485. BCM283X_SPI_CLOCK_DIVIDER_128 = 128, /*!< 128 = 1.953125MHz on Rpi2, 3.125MHz on RPI3 */
  486. BCM283X_SPI_CLOCK_DIVIDER_64 = 64, /*!< 64 = 3.90625MHz on Rpi2, 6.250MHz on RPI3 */
  487. BCM283X_SPI_CLOCK_DIVIDER_32 = 32, /*!< 32 = 7.8125MHz on Rpi2, 12.5MHz on RPI3 */
  488. BCM283X_SPI_CLOCK_DIVIDER_16 = 16, /*!< 16 = 15.625MHz on Rpi2, 25MHz on RPI3 */
  489. BCM283X_SPI_CLOCK_DIVIDER_8 = 8, /*!< 8 = 31.25MHz on Rpi2, 50MHz on RPI3 */
  490. BCM283X_SPI_CLOCK_DIVIDER_4 = 4, /*!< 4 = 62.5MHz on Rpi2, 100MHz on RPI3. Dont expect this speed to work reliably. */
  491. BCM283X_SPI_CLOCK_DIVIDER_2 = 2, /*!< 2 = 125MHz on Rpi2, 200MHz on RPI3, fastest you can get. Dont expect this speed to work reliably.*/
  492. BCM283X_SPI_CLOCK_DIVIDER_1 = 1 /*!< 1 = 3.814697260kHz on Rpi2, 6.1035156kHz on RPI3, same as 0/65536 */
  493. };
  494. /* BCM IO pin */
  495. enum bcm_gpio_pin
  496. {
  497. BCM_GPIO_PIN_0 = 0,
  498. BCM_GPIO_PIN_1,
  499. BCM_GPIO_PIN_2,
  500. BCM_GPIO_PIN_3,
  501. BCM_GPIO_PIN_4,
  502. BCM_GPIO_PIN_5,
  503. BCM_GPIO_PIN_6,
  504. BCM_GPIO_PIN_7,
  505. BCM_GPIO_PIN_8,
  506. BCM_GPIO_PIN_9,
  507. BCM_GPIO_PIN_10,
  508. BCM_GPIO_PIN_11,
  509. BCM_GPIO_PIN_12,
  510. BCM_GPIO_PIN_13,
  511. BCM_GPIO_PIN_14,
  512. BCM_GPIO_PIN_15,
  513. BCM_GPIO_PIN_16,
  514. BCM_GPIO_PIN_17,
  515. BCM_GPIO_PIN_18,
  516. BCM_GPIO_PIN_19,
  517. BCM_GPIO_PIN_20,
  518. BCM_GPIO_PIN_21,
  519. BCM_GPIO_PIN_22,
  520. BCM_GPIO_PIN_23,
  521. BCM_GPIO_PIN_24,
  522. BCM_GPIO_PIN_25,
  523. BCM_GPIO_PIN_26,
  524. BCM_GPIO_PIN_27,
  525. BCM_GPIO_PIN_28,
  526. BCM_GPIO_PIN_29,
  527. BCM_GPIO_PIN_30,
  528. BCM_GPIO_PIN_31,
  529. BCM_GPIO_PIN_32,
  530. BCM_GPIO_PIN_33,
  531. BCM_GPIO_PIN_34,
  532. BCM_GPIO_PIN_35,
  533. BCM_GPIO_PIN_36,
  534. BCM_GPIO_PIN_37,
  535. BCM_GPIO_PIN_38,
  536. BCM_GPIO_PIN_39,
  537. BCM_GPIO_PIN_40,
  538. BCM_GPIO_PIN_41,
  539. BCM_GPIO_PIN_42,
  540. BCM_GPIO_PIN_43,
  541. BCM_GPIO_PIN_44,
  542. BCM_GPIO_PIN_45,
  543. BCM_GPIO_PIN_46,
  544. BCM_GPIO_PIN_47,
  545. BCM_GPIO_PIN_48,
  546. BCM_GPIO_PIN_49,
  547. BCM_GPIO_PIN_50,
  548. BCM_GPIO_PIN_51,
  549. BCM_GPIO_PIN_52,
  550. BCM_GPIO_PIN_53,
  551. BCM_GPIO_PIN_NUM,
  552. };
  553. rt_uint32_t bcm283x_peri_read(volatile rt_ubase_t addr);
  554. rt_uint32_t bcm283x_peri_read_nb(volatile rt_ubase_t addr);
  555. void bcm283x_peri_write(volatile rt_ubase_t addr, rt_uint32_t value);
  556. void bcm283x_peri_write_nb(volatile rt_ubase_t addr, rt_uint32_t value);
  557. void bcm283x_peri_set_bits(volatile rt_ubase_t addr, rt_uint32_t value, rt_uint32_t mask);
  558. void bcm283x_gpio_fsel(rt_uint8_t pin, rt_uint8_t mode);
  559. void bcm283x_gpio_set(rt_uint8_t pin);
  560. void bcm283x_gpio_clr(rt_uint8_t pin);
  561. rt_uint8_t bcm283x_gpio_lev(rt_uint8_t pin);
  562. rt_uint8_t bcm283x_gpio_eds(rt_uint8_t pin);
  563. void bcm283x_gpio_set_eds(rt_uint8_t pin);
  564. void bcm283x_gpio_ren(rt_uint8_t pin);
  565. void bcm283x_gpio_clr_ren(rt_uint8_t pin);
  566. void bcm283x_gpio_fen(rt_uint8_t pin);
  567. void bcm283x_gpio_clr_fen(rt_uint8_t pin);
  568. void bcm283x_gpio_hen(rt_uint8_t pin);
  569. void bcm283x_gpio_clr_hen(rt_uint8_t pin);
  570. void bcm283x_gpio_len(rt_uint8_t pin);
  571. void bcm283x_gpio_clr_len(rt_uint8_t pin);
  572. void bcm283x_gpio_aren(rt_uint8_t pin);
  573. void bcm283x_gpio_clr_aren(rt_uint8_t pin);
  574. void bcm283x_gpio_afen(rt_uint8_t pin);
  575. void bcm283x_gpio_clr_afen(rt_uint8_t pin);
  576. void bcm283x_gpio_pud(rt_uint8_t pud);
  577. void bcm283x_gpio_pudclk(rt_uint8_t pin, rt_uint8_t on);
  578. void bcm283x_gpio_set_pud(rt_uint8_t pin, rt_uint8_t pud);
  579. void bcm283x_gpio_write(rt_uint8_t pin, rt_uint8_t val);
  580. void bcm283x_st_delay(rt_uint64_t offset_micros, rt_uint64_t micros);
  581. rt_uint64_t bcm283x_st_read(void);
  582. void bcm283x_delayMicroseconds(rt_uint64_t micros);
  583. void bcm283x_clo_delayMicros(rt_uint32_t micros);
  584. int bcm283x_i2c_begin(int no);
  585. void bcm283x_i2c_end(int no);
  586. void bcm283x_i2c_setSlaveAddress(int no, rt_uint8_t saddr);
  587. void bcm283x_i2c_setClockDivider(int no, rt_uint16_t divider);
  588. void bcm283x_i2c_set_baudrate(int no, rt_uint32_t baudrate);
  589. rt_uint8_t bcm283x_i2c_read(rt_uint32_t base, rt_uint8_t* buf, rt_uint32_t len);
  590. rt_uint8_t bcm283x_i2c_write(rt_uint32_t base, const rt_uint8_t * buf, rt_uint32_t len);
  591. rt_uint8_t bcm283x_i2c_write_read_rs(char* cmds, rt_uint32_t cmds_len, char* buf, rt_uint32_t buf_len);
  592. #endif