ae210p_regs.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*****************************************************************************
  2. *
  3. * Copyright Andes Technology Corporation 2014
  4. * All Rights Reserved.
  5. *
  6. ****************************************************************************/
  7. #ifndef __AE210P_REGS_H__
  8. #define __AE210P_REGS_H__
  9. #ifndef __ASSEMBLER__
  10. #include <inttypes.h>
  11. #include <nds32_intrinsic.h>
  12. #endif
  13. #if (defined(CONFIG_CPU_ICACHE_ENABLE) || defined(CONFIG_CPU_DCACHE_ENABLE))
  14. /*
  15. * The NTC1 is set to noncache region and NTM1 is mapped to partition 0 (I/O region).
  16. * Map the I/O address to NTC1 to be uncachable.
  17. */
  18. #define UNCACHE_MAP(addr) ((addr) | 0x40000000)
  19. #else
  20. #define UNCACHE_MAP(addr) (addr)
  21. #endif
  22. #define _IO_(addr) UNCACHE_MAP(addr)
  23. /*****************************************************************************
  24. * ExLM - AE210P AHB
  25. * **************************************************************************/
  26. #define EILM_BASE 0x00000000
  27. #ifdef CONFIG_OSC_SUPPORT
  28. #define EDLM_BASE 0x00100000
  29. #else
  30. #define EDLM_BASE 0x00200000
  31. #endif
  32. #define SPIAHBMEM_BASE 0x00800000
  33. /*****************************************************************************
  34. * AHBC - AE210P AHB
  35. ****************************************************************************/
  36. #define AHBC_BASE_4_7 _IO_(0x00400000) /* Vendor AHB Slave 8~9 */
  37. #define AHBC_BASE_0_3 _IO_(0x00E20000) /* Vendor AHB Slave 0~7 */
  38. /*****************************************************************************
  39. * BMC - AE210P AHB
  40. ****************************************************************************/
  41. #define BMC_BASE _IO_(0x00E00000) /* Device base address */
  42. /*****************************************************************************
  43. * OSC - AE210P OSC
  44. ****************************************************************************/
  45. #define OSC_BASE _IO_(0x00E01000)
  46. /* OSC register */
  47. #define OSC_CTRL (OSC_BASE + 0x00)
  48. #define OSC_OVLFS (OSC_BASE + 0x04)
  49. #define OSC_OVLBASE (OSC_BASE + 0x08)
  50. #define OSC_OVLEND (OSC_BASE + 0x0C)
  51. #define OSC_DMAST (OSC_BASE + 0x10)
  52. /*****************************************************************************
  53. * DMAC - AE210P AHB
  54. ****************************************************************************/
  55. #define DMAC_BASE _IO_(0x00E0E000) /* Device base address */
  56. /*****************************************************************************
  57. * APBBRG - AE210P APB
  58. ****************************************************************************/
  59. #define APBBR_BASE _IO_(0x00F00000) /* Device base address */
  60. /*****************************************************************************
  61. * SMU - AE210P
  62. ****************************************************************************/
  63. #define SMU_BASE _IO_(0x00F01000) /* Device base address */
  64. /*****************************************************************************
  65. * UARTx - AE210P
  66. ****************************************************************************/
  67. #define UART1_BASE _IO_(0x00F02000) /* Device base address */
  68. #define UART2_BASE _IO_(0x00F03000) /* Device base address */
  69. #define STUARTC_BASE UART2_BASE /* standard/IR UART */
  70. /* UART register offsets (4~8-bit width) */
  71. /* SD_LCR_DLAB == 0 */
  72. #define UARTC_RBR_OFFSET 0x20 /* receiver biffer register */
  73. #define UARTC_THR_OFFSET 0x20 /* transmitter holding register */
  74. #define UARTC_IER_OFFSET 0x24 /* interrupt enable register */
  75. #define UARTC_IIR_OFFSET 0x28 /* interrupt identification register */
  76. #define UARTC_FCR_OFFSET 0x28 /* FIFO control register */
  77. #define UARTC_LCR_OFFSET 0x2c /* line control regitser */
  78. #define UARTC_MCR_OFFSET 0x30 /* modem control register */
  79. #define UARTC_LSR_OFFSET 0x34 /* line status register */
  80. #define UARTC_TST_OFFSET 0x34 /* testing register */
  81. #define UARTC_MSR_OFFSET 0x38 /* modem status register */
  82. #define UARTC_SPR_OFFSET 0x3c /* scratch pad register */
  83. /* SD_LCR_DLAB == 0 */
  84. #define UARTC_DLL_OFFSET 0x20 /* baudrate divisor latch LSB */
  85. #define UARTC_DLM_OFFSET 0x24 /* baudrate divisor latch MSB */
  86. #define UARTC_PSR_OFFSET 0x28 /* prescaler register */
  87. /*****************************************************************************
  88. * PIT - AE210P
  89. ****************************************************************************/
  90. #define PIT_BASE _IO_(0x00F04000) /* Device base address */
  91. /* PIT register (32-bit width) */
  92. #define PIT_ID_REV (PIT_BASE + 0x00 ) /* (ro) PIT ID and Revision Register */
  93. #define PIT_CFG (PIT_BASE + 0x10 ) /* (ro) PIT Configuration Register */
  94. #define PIT_INT_EN (PIT_BASE + 0x14 ) /* (rw) PIT Interrupt Enable Register*/
  95. #define PIT_INT_ST (PIT_BASE + 0x18 ) /* (w1c) PIT Interrupt Status Register*/
  96. #define PIT_CH_EN (PIT_BASE + 0x1C ) /* (rw) PIT Channel Enable Register */
  97. /* _chn_ from 0 to 3*/
  98. /* (rw) PIT Channel x Control Register (32-bit width) */
  99. #define PIT_CHNx_CTL(_chn_) ( PIT_BASE + 0x20 + ( (_chn_)* 0x10) )
  100. /* (rw) PIT Channel x Reload Register (32-bit width) */
  101. #define PIT_CHNx_LOAD(_chn_) ( PIT_BASE + 0x24 + ( (_chn_)* 0x10) )
  102. /* (ro) PIT Channel x Counter Register (32-bit width) */
  103. #define PIT_CHNx_COUNT(_chn_) ( PIT_BASE + 0x28 + ( (_chn_)* 0x10) )
  104. /*****************************************************************************
  105. * WDT - AE210P
  106. ****************************************************************************/
  107. #define WDTC_BASE _IO_(0x00F05000) /* Device base address */
  108. /*****************************************************************************
  109. * RTC - AE210P
  110. ****************************************************************************/
  111. #define RTC_BASE _IO_(0x00F06000) /* Device base address */
  112. /*****************************************************************************
  113. * GPIO - AE210P
  114. ****************************************************************************/
  115. #define GPIOC_BASE _IO_(0x00F07000) /* Device base address */
  116. /*****************************************************************************
  117. * I2C - AE210P
  118. ****************************************************************************/
  119. #define I2C_BASE _IO_(0x00F0A000) /* Device base address */
  120. /*****************************************************************************
  121. * SPI1 - AE210P
  122. ****************************************************************************/
  123. #define SPI1_BASE _IO_(0x00F0B000) /* Device base address */
  124. /*****************************************************************************
  125. * I2S/AC97 - AE210P (SSP2)
  126. ****************************************************************************/
  127. #define SPI2_BASE _IO_(0x00F0F000) /* Device base address */
  128. /*****************************************************************************
  129. * APB_SLAVE - AE210P Vender APB Slave 0~4
  130. ****************************************************************************/
  131. #define APB_SLAVE_BASE _IO_(0x00F19000) /* Device base address */
  132. /*****************************************************************************
  133. * Macros for Register Access
  134. ****************************************************************************/
  135. #define REG32(reg) ( *( (volatile uint32_t *) (reg) ) )
  136. #ifdef REG_IO_HACK
  137. /* 8 bit access */
  138. //#define IN8(reg) ( *( (volatile uint8_t *) (reg) ) )
  139. #define OUT8(reg, data) ( (*( (volatile uint8_t *) (reg) ) ) = (uint8_t)(data) )
  140. #define CLR8(reg) ( *( (volatile uint8_t *) (reg) ) = (uint8_t)0 )
  141. #define MASK8(reg, mask) ( *( (volatile uint8_t *) (reg) ) & (uint8_t)(mask) )
  142. #define UMSK8(reg, mask) ( *( (volatile uint8_t *) (reg) ) & ~( (uint8_t)(mask) ) )
  143. #define SETR8SHL(reg, mask, shift, v) ( *( (volatile uint8_t *) (reg) ) = \
  144. ( ( *( (volatile uint8_t *) (reg) ) & ~( (uint8_t)(mask) ) ) | \
  145. ( ( (uint8_t)(v) << (shift) ) & (uint8_t)(mask) ) ) )
  146. #define SETR8(reg, mask) ( *( (volatile uint8_t *) (reg) ) = \
  147. ( ( *( (volatile uint8_t *) (reg) ) & ~( (uint8_t)(mask) ) ) | (uint8_t)(mask) ) )
  148. #define CLRR8(reg, mask) ( *( (volatile uint8_t *) (reg) ) &= ~( (uint8_t)(mask) ) )
  149. #define SETB8(reg, bit) ( *( (volatile uint8_t *) (reg) ) |= (uint8_t)( (uint8_t)1 << (bit) ) )
  150. #define CLRB8(reg, bit) ( *( (volatile uint8_t *) (reg) ) &= ( ~( (uint8_t) ( (uint8_t)1 << (bit) ) ) ) )
  151. #define GETB8(reg, bit) ( *( (volatile uint8_t *) (reg) ) & (uint8_t) ( (uint8_t)1 << (bit) ) )
  152. #define GETB8SHR(reg, bit) ( (*( (volatile uint8_t *) (reg) ) & (uint8_t) ( (uint8_t)1 << (bit) )) >> (bit) )
  153. /* 16 bit access */
  154. #define IN16(reg) ( *( (volatile uint16_t *) (reg) ) )
  155. #define OUT16(reg, data) ( (*( (volatile uint16_t *) (reg) ) ) = (uint16_t)(data) )
  156. #define CLR16(reg) ( *( (volatile uint16_t *) (reg) ) = (uint16_t)0 )
  157. #define MASK16(reg, mask) ( *( (volatile uint16_t *) (reg) ) & (uint16_t)(mask) )
  158. #define UMSK16(reg, mask) ( *( (volatile uint16_t *) (reg) ) & ~( (uint16_t)(mask) ) )
  159. #define SETR16SHL(reg, mask, shift, v) ( *( (volatile uint16_t *) (reg) ) = \
  160. ( ( *( (volatile uint16_t *) (reg) ) & ~( (uint16_t)(mask) ) ) | \
  161. ( ( (uint16_t)(v) << (shift) ) & (uint16_t)(mask) ) ) )
  162. #define SETR16(reg, mask) ( *( (volatile uint16_t *) (reg) ) = \
  163. ( ( *( (volatile uint16_t *) (reg) ) & ~( (uint16_t)(mask) ) ) | (uint16_t)(mask) ) )
  164. #define CLRR16(reg, mask) ( *( (volatile uint16_t *) (reg) ) &= ~( (uint16_t)(mask) ) )
  165. #define SETB16(reg, bit) ( *( (volatile uint16_t *) (reg) ) |= (uint16_t)( (uint16_t)1 << (bit) ) )
  166. #define CLRB16(reg, bit) ( *( (volatile uint16_t *) (reg) ) &= ( ~( (uint16_t) ( (uint16_t)1 << (bit) ) ) ) )
  167. #define GETB16(reg, bit) ( *( (volatile uint16_t *) (reg) ) & (uint16_t) ( (uint16_t)1 << (bit) ) )
  168. #define GETB16SHR(reg, bit) ( (*( (volatile uint16_t *) (reg) ) & (uint16_t) ( (uint16_t)1 << (bit) )) >> (bit) )
  169. /* 32 bit access */
  170. #define IN32(reg) _IN32((uint32_t)(reg))
  171. #define OUT32(reg, data) _OUT32((uint32_t)(reg), (uint32_t)(data))
  172. #define CLR32(reg) _CLR32((uint32_t)(reg))
  173. #define MASK32(reg, mask) _MASK32((uint32_t)(reg), (uint32_t)(mask))
  174. #define UMSK32(reg, mask) _UMSK32((uint32_t)(reg), (uint32_t)(mask))
  175. #define SETR32SHL(reg, mask, shift, v) _SETR32SHL((uint32_t)(reg), (uint32_t)(mask), (uint32_t)(shift), (uint32_t)(v))
  176. #define SETR32(reg, mask) _SETR32((uint32_t)(reg), (uint32_t)(mask))
  177. #define CLRR32(reg, mask) _CLRR32((uint32_t)(reg), (uint32_t)(mask))
  178. #define SETB32(reg, bit) _SETB32((uint32_t)(reg), (uint32_t)(bit))
  179. #define CLRB32(reg, bit) _CLRB32((uint32_t)(reg), (uint32_t)(bit))
  180. #define GETB32(reg, bit) _GETB32((uint32_t)(reg), (uint32_t)(bit))
  181. #define GETB32SHR(reg, bit) _GETB32SHR((uint32_t)(reg), (uint32_t)(bit))
  182. #else /* REG_IO_HACK */
  183. /* 8 bit access */
  184. //#define IN8(reg) ( *( (volatile uint8_t *) (reg) ) )
  185. #define OUT8(reg, data) ( (*( (volatile uint8_t *) (reg) ) ) = (uint8_t)(data) )
  186. #define CLR8(reg) ( *( (volatile uint8_t *) (reg) ) = (uint8_t)0 )
  187. #define MASK8(reg, mask) ( *( (volatile uint8_t *) (reg) ) & (uint8_t)(mask) )
  188. #define UMSK8(reg, mask) ( *( (volatile uint8_t *) (reg) ) & ~( (uint8_t)(mask) ) )
  189. #define SETR8SHL(reg, mask, shift, v) ( *( (volatile uint8_t *) (reg) ) = \
  190. ( ( *( (volatile uint8_t *) (reg) ) & ~( (uint8_t)(mask) ) ) | \
  191. ( ( (uint8_t)(v) << (shift) ) & (uint8_t)(mask) ) ) )
  192. #define SETR8(reg, mask) ( *( (volatile uint8_t *) (reg) ) = \
  193. ( ( *( (volatile uint8_t *) (reg) ) & ~( (uint8_t)(mask) ) ) | (uint8_t)(mask) ) )
  194. #define CLRR8(reg, mask) ( *( (volatile uint8_t *) (reg) ) &= ~( (uint8_t)(mask) ) )
  195. #define SETB8(reg, bit) ( *( (volatile uint8_t *) (reg) ) |= (uint8_t)( (uint8_t)1 << (bit) ) )
  196. #define CLRB8(reg, bit) ( *( (volatile uint8_t *) (reg) ) &= ( ~( (uint8_t) ( (uint8_t)1 << (bit) ) ) ) )
  197. #define GETB8(reg, bit) ( *( (volatile uint8_t *) (reg) ) & (uint8_t) ( (uint8_t)1 << (bit) ) )
  198. #define GETB8SHR(reg, bit) ( (*( (volatile uint8_t *) (reg) ) & (uint8_t) ( (uint8_t)1 << (bit) )) >> (bit) )
  199. /* 16 bit access */
  200. #define IN16(reg) ( *( (volatile uint16_t *) (reg) ) )
  201. #define OUT16(reg, data) ( (*( (volatile uint16_t *) (reg) ) ) = (uint16_t)(data) )
  202. #define CLR16(reg) ( *( (volatile uint16_t *) (reg) ) = (uint16_t)0 )
  203. #define MASK16(reg, mask) ( *( (volatile uint16_t *) (reg) ) & (uint16_t)(mask) )
  204. #define UMSK16(reg, mask) ( *( (volatile uint16_t *) (reg) ) & ~( (uint16_t)(mask) ) )
  205. #define SETR16SHL(reg, mask, shift, v) ( *( (volatile uint16_t *) (reg) ) = \
  206. ( ( *( (volatile uint16_t *) (reg) ) & ~( (uint16_t)(mask) ) ) | \
  207. ( ( (uint16_t)(v) << (shift) ) & (uint16_t)(mask) ) ) )
  208. #define SETR16(reg, mask) ( *( (volatile uint16_t *) (reg) ) = \
  209. ( ( *( (volatile uint16_t *) (reg) ) & ~( (uint16_t)(mask) ) ) | (uint16_t)(mask) ) )
  210. #define CLRR16(reg, mask) ( *( (volatile uint16_t *) (reg) ) &= ~( (uint16_t)(mask) ) )
  211. #define SETB16(reg, bit) ( *( (volatile uint16_t *) (reg) ) |= (uint16_t)( (uint16_t)1 << (bit) ) )
  212. #define CLRB16(reg, bit) ( *( (volatile uint16_t *) (reg) ) &= ( ~( (uint16_t) ( (uint16_t)1 << (bit) ) ) ) )
  213. #define GETB16(reg, bit) ( *( (volatile uint16_t *) (reg) ) & (uint16_t) ( (uint16_t)1 << (bit) ) )
  214. #define GETB16SHR(reg, bit) ( (*( (volatile uint16_t *) (reg) ) & (uint16_t) ( (uint16_t)1 << (bit) )) >> (bit) )
  215. /* 32 bit access */
  216. #define IN32(reg) ( *( (volatile uint32_t *) (reg) ) )
  217. #define OUT32(reg, data) ( (*( (volatile uint32_t *) (reg) ) ) = (uint32_t)(data) )
  218. #define CLR32(reg) ( *( (volatile uint32_t *) (reg) ) = (uint32_t)0 )
  219. #define MASK32(reg, mask) ( *( (volatile uint32_t *) (reg) ) & (uint32_t)(mask) )
  220. #define UMSK32(reg, mask) ( *( (volatile uint32_t *) (reg) ) & ~( (uint32_t)(mask) ) )
  221. #define SETR32SHL(reg, mask, shift, v) ( *( (volatile uint32_t *) (reg) ) = \
  222. ( ( *( (volatile uint32_t *) (reg) ) & ~( (uint32_t)(mask) ) ) | \
  223. ( ( (uint32_t)(v) << (shift) ) & (uint32_t)(mask) ) ) )
  224. #define SETR32(reg, mask) ( *( (volatile uint32_t *) (reg) ) = \
  225. ( ( *( (volatile uint32_t *) (reg) ) & ~( (uint32_t)(mask) ) ) | (uint32_t)(mask) ) )
  226. #define CLRR32(reg, mask) ( *( (volatile uint32_t *) (reg) ) &= ~( (uint32_t)(mask) ) )
  227. #define SETB32(reg, bit) ( *( (volatile uint32_t *) (reg) ) |= (uint32_t)( (uint32_t)1 << (bit) ) )
  228. #define CLRB32(reg, bit) ( *( (volatile uint32_t *) (reg) ) &= ( ~( (uint32_t) ( (uint32_t)1 << (bit) ) ) ) )
  229. #define GETB32(reg, bit) ( *( (volatile uint32_t *) (reg) ) & (uint32_t) ( (uint32_t)1 << (bit) ) )
  230. #define GETB32SHR(reg, bit) ( (*( (volatile uint32_t *) (reg) ) & (uint32_t) ( (uint32_t)1 << (bit) )) >> (bit) )
  231. #endif /* REG_IO_HACK */
  232. #define SR_CLRB32(reg, bit) \
  233. { \
  234. int mask = __nds32__mfsr(reg)& ~(1<<bit);\
  235. __nds32__mtsr(mask, reg); \
  236. __nds32__dsb(); \
  237. }
  238. #define SR_SETB32(reg,bit)\
  239. {\
  240. int mask = __nds32__mfsr(reg)|(1<<bit);\
  241. __nds32__mtsr(mask, reg); \
  242. __nds32__dsb(); \
  243. }
  244. #endif /* __AE210P_REGS_H__ */