amt630h.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /***********************************************************************
  2. Copyright (c)2020 Arkmicro Technologies Inc. All Rights Reserved
  3. Filename: amt630h.h
  4. Version : 1.0
  5. Date : 2020.04.08
  6. Author : Sim. Huang
  7. History :
  8. ************************************************************************/
  9. #ifndef _AMT630H_H_
  10. #define _AMT630H_H_
  11. #define VECTOR_ENABLE 0 //if you want to change this value, please
  12. //change the Assemble logic valuable VECTOR_ENABLE //in file Boot.s
  13. #define CLK_24MHZ 24000000
  14. #define CLK_12MHZ 12000000
  15. #define SPINOR_BOOTER_SD 0
  16. #define BOOT_FROM_USB 1
  17. #define SPINAND_BOOTER_SD 2
  18. #define BOOT_FROM_SPI 3
  19. /* register base address */
  20. #define SDHC0_BASE 0x70400000
  21. #define USB_BASE 0x70300000//0x700C0000
  22. #define SSI1_BASE 0x60200000//0x48002000
  23. #define SSI0_BASE 0x60100000
  24. #define GPIO_BASE 0x60900000//0x40409000
  25. #define SYS_BASE 0x60000000//0x40408000
  26. #define TIMER_BASE 0x60a00000//0x40405000
  27. #define WDT_BASE 0x60c00000//0x40404000
  28. #define RTC_BASE 0x61000000//0x40406000
  29. #define UART0_BASE 0x60500000//0x4040B000
  30. //uart
  31. #define UART_BASE UART0_BASE
  32. #define rUART_DR *((volatile unsigned int *)(UART_BASE + 0x00))
  33. #define rUART_RSR *((volatile unsigned int *)(UART_BASE + 0x04))
  34. #define rUART_FR *((volatile unsigned int *)(UART_BASE + 0x18))
  35. #define rUART_ILPR *((volatile unsigned int *)(UART_BASE + 0x20))
  36. #define rUART_IBRD *((volatile unsigned int *)(UART_BASE + 0x24))
  37. #define rUART_FBRD *((volatile unsigned int *)(UART_BASE + 0x28))
  38. #define rUART_LCR_H *((volatile unsigned int *)(UART_BASE + 0x2C))
  39. #define rUART_CR *((volatile unsigned int *)(UART_BASE + 0x30))
  40. #define rUART_IFLS *((volatile unsigned int *)(UART_BASE + 0x34))
  41. #define rUART_IMSC *((volatile unsigned int *)(UART_BASE + 0x38))
  42. #define rUART_RIS *((volatile unsigned int *)(UART_BASE + 0x3C))
  43. #define rUART_MIS *((volatile unsigned int *)(UART_BASE + 0x40))
  44. #define rUART_ICR *((volatile unsigned int *)(UART_BASE + 0x44))
  45. #define rUART_DMACR *((volatile unsigned int *)(UART_BASE + 0x48))
  46. /***************************************************************
  47. AHB slave interface registers definition
  48. ****************************************************************/
  49. /* AHB system */
  50. #define rSYS_BOOT_SAMPLE *((volatile unsigned int *)(SYS_BASE+0x0))
  51. #define rSYS_BUS_CLK_SEL *((volatile unsigned int *)(SYS_BASE+0x40))
  52. #define rSYS_PLLRFCK_CTL *((volatile unsigned int *)(SYS_BASE+0x44))
  53. #define rSYS_SDMMC_CLK_CFG *((volatile unsigned int *)(SYS_BASE+0x48))
  54. #define rSYS_VOU_CLK_CFG *((volatile unsigned int *)(SYS_BASE+0x4c))
  55. #define rSYS_PER_CLK_EN *((volatile unsigned int *)(SYS_BASE+0x50))
  56. #define rSYS_LCD_CLK_CFG *((volatile unsigned int *)(SYS_BASE+0x54))
  57. #define rSYS_SD_CLK_CFG *((volatile unsigned int *)(SYS_BASE+0x58))
  58. #define rSYS_SOFT_RST *((volatile unsigned int *)(SYS_BASE+0x5c))
  59. #define rSYS_SOFT1_RST *((volatile unsigned int *)(SYS_BASE+0x60))
  60. #define rSYS_SSP_CLK_CFG *((volatile unsigned int *)(SYS_BASE+0x64))
  61. #define rSYS_TIMER_CLK_CFG *((volatile unsigned int *)(SYS_BASE+0x68))
  62. #define rSYS_I2S_NCO_CFG *((volatile unsigned int *)(SYS_BASE+0x6c))
  63. #define rSYS_DDRCTL_CFG *((volatile unsigned int *)(SYS_BASE+0x70))
  64. #define rSYS_DDRCTL1_CFG *((volatile unsigned int *)(SYS_BASE+0x74))
  65. #define rSYS_PERCTL_CFG *((volatile unsigned int *)(SYS_BASE+0x78))
  66. #define rSYS_TIMER1_CLK_CFG *((volatile unsigned int *)(SYS_BASE+0x7c))
  67. #define rSYS_ANA_CFG *((volatile unsigned int *)(SYS_BASE+0x80))
  68. #define rSYS_ANA1_CFG *((volatile unsigned int *)(SYS_BASE+0x84))
  69. #define rSYS_CPUPLL_CFG *((volatile unsigned int *)(SYS_BASE+0x88))
  70. #define rSYS_SYSPLL_CFG *((volatile unsigned int *)(SYS_BASE+0x8c))
  71. #define rSYS_ANA2_CFG *((volatile unsigned int *)(SYS_BASE+0x98))
  72. #define rSYS_ANA3_CFG *((volatile unsigned int *)(SYS_BASE+0x9c))
  73. #define rSYS_PAD_CTRL00 *((volatile unsigned int *)(SYS_BASE+0x30*4))
  74. #define rSYS_PAD_CTRL01 *((volatile unsigned int *)(SYS_BASE+0x31*4))
  75. #define rSYS_PAD_CTRL02 *((volatile unsigned int *)(SYS_BASE+0x32*4))
  76. #define rSYS_PAD_CTRL03 *((volatile unsigned int *)(SYS_BASE+0x33*4))
  77. #define rSYS_PAD_CTRL04 *((volatile unsigned int *)(SYS_BASE+0x34*4))
  78. #define rSYS_PAD_CTRL05 *((volatile unsigned int *)(SYS_BASE+0xD4))
  79. #define rSYS_PAD_CTRL06 *((volatile unsigned int *)(SYS_BASE+0x36*4))
  80. #define rSYS_PAD_CTRL07 *((volatile unsigned int *)(SYS_BASE+0x37*4))
  81. #define rSYS_PAD_CTRL08 *((volatile unsigned int *)(SYS_BASE+0x38*4))
  82. #define rSYS_PAD_CTRL09 *((volatile unsigned int *)(SYS_BASE+0x39*4))
  83. #define rSYS_PAD_CTRL0A *((volatile unsigned int *)(SYS_BASE+0x3A*4))
  84. #define rSYS_PAD_CTRL0B *((volatile unsigned int *)(SYS_BASE+0x3B*4))
  85. #define rSYS_PAD_CTRL0C *((volatile unsigned int *)(SYS_BASE+0x3C*4))
  86. #define rSYS_PAD_CTRL0D *((volatile unsigned int *)(SYS_BASE+0x3D*4))
  87. /* Timer */
  88. #define rTIMER0_LOAD_COUNT (*(volatile unsigned int *)(TIMER_BASE + 0x00))
  89. #define rTIMER0_CURRENT_VALUE (*(volatile unsigned int *)(TIMER_BASE + 0x04))
  90. #define rTIMER0_CONTROL (*(volatile unsigned int *)(TIMER_BASE + 0x08))
  91. #define rTIMER0_EOI (*(volatile unsigned int *)(TIMER_BASE + 0x0C))
  92. #define rTIMER0_INT_STATUS (*(volatile unsigned int *)(TIMER_BASE + 0x10))
  93. /* WDT */
  94. #define rWDT_CR (*(volatile unsigned int *)(WDT_BASE + 0x00))
  95. #define rWDT_PSR (*(volatile unsigned int *)(WDT_BASE + 0x04))
  96. #define rWDT_LDR (*(volatile unsigned int *)(WDT_BASE + 0x08))
  97. #define rWDT_VLR (*(volatile unsigned int *)(WDT_BASE + 0x0C))
  98. #define rWDT_ISR (*(volatile unsigned int *)(WDT_BASE + 0x10))
  99. #define rWDT_RCR (*(volatile unsigned int *)(WDT_BASE + 0x14))
  100. #define rWDT_TMR (*(volatile unsigned int *)(WDT_BASE + 0x18))
  101. #define rWDT_TCR (*(volatile unsigned int *)(WDT_BASE + 0x1C))
  102. /* RTC */
  103. #define rRTC_CTL (*(volatile unsigned int *)(RTC_BASE + 0x00)) /*control register*/
  104. #define rRTC_ANAWEN (*(volatile unsigned int *)(RTC_BASE + 0x04)) /*analog block write enable register*/
  105. #define rRTC_ANACTL (*(volatile unsigned int *)(RTC_BASE + 0x08)) /*analog block control register*/
  106. #define rRTC_IM (*(volatile unsigned int *)(RTC_BASE + 0x0C)) /*interrupt mode register*/
  107. #define rRTC_STA (*(volatile unsigned int *)(RTC_BASE + 0x10)) /*rtc status register*/
  108. #define rRTC_ALMDAT (*(volatile unsigned int *)(RTC_BASE + 0x14)) /*alarm data register*/
  109. #define rRTC_DONT (*(volatile unsigned int *)(RTC_BASE + 0x18)) /*delay on timer register*/
  110. #define rRTC_RAM (*(volatile unsigned int *)(RTC_BASE + 0x1C)) /*ram bit register*/
  111. #define rRTC_CNTL (*(volatile unsigned int *)(RTC_BASE + 0x20)) /*rtc counter register*/
  112. #define rRTC_CNTH (*(volatile unsigned int *)(RTC_BASE + 0x24)) /*rtc sec counter register*/
  113. /* UART0 */
  114. #define rUART0_DR (*(volatile unsigned int *)(UART0_BASE + 0x00))
  115. #define rUART0_RSR (*(volatile unsigned int *)(UART0_BASE + 0x04))
  116. #define rUART0_FR (*(volatile unsigned int *)(UART0_BASE + 0x18))
  117. #define rUART0_ILPR (*(volatile unsigned int *)(UART0_BASE + 0x20))
  118. #define rUART0_IBRD (*(volatile unsigned int *)(UART0_BASE + 0x24))
  119. #define rUART0_FBRD (*(volatile unsigned int *)(UART0_BASE + 0x28))
  120. #define rUART0_LCR_H (*(volatile unsigned int *)(UART0_BASE + 0x2C))
  121. #define rUART0_CR (*(volatile unsigned int *)(UART0_BASE + 0x30))
  122. #define rUART0_IFLS (*(volatile unsigned int *)(UART0_BASE + 0x34))
  123. #define rUART0_IMSC (*(volatile unsigned int *)(UART0_BASE + 0x38))
  124. #define rUART0_RIS (*(volatile unsigned int *)(UART0_BASE + 0x3C))
  125. #define rUART0_MIS (*(volatile unsigned int *)(UART0_BASE + 0x40))
  126. #define rUART0_ICR (*(volatile unsigned int *)(UART0_BASE + 0x44))
  127. #define rUART0_DMACR (*(volatile unsigned int *)(UART0_BASE + 0x48))
  128. /* SSI */
  129. #define rSPI_CONTROLREG (*(volatile unsigned int *)(SSI1_BASE + 0x08))
  130. #define rSPI_CONFIGREG (*(volatile unsigned int *)(SSI1_BASE + 0x0C))
  131. #define rSPI_INTREG (*(volatile unsigned int *)(SSI1_BASE + 0x10))
  132. #define rSPI_DMAREG (*(volatile unsigned int *)(SSI1_BASE + 0x14))
  133. #define rSPI_STATUSREG (*(volatile unsigned int *)(SSI1_BASE + 0x18))
  134. #define rSPI_PERIODREG (*(volatile unsigned int *)(SSI1_BASE + 0x1C))
  135. #define rSPI_TESTREG (*(volatile unsigned int *)(SSI1_BASE + 0x20))
  136. #define rSPI_MSGREG (*(volatile unsigned int *)(SSI1_BASE + 0x40))
  137. #define rSPI_RXDATA (*(volatile unsigned int *)(SSI1_BASE + 0x50))
  138. #define rSPI_TXDATA (*(volatile unsigned int *)(SSI1_BASE + 0x460))
  139. #define rSPI_TXFIFO (SSI_BASE + 0x460)
  140. #define rSPI_RXFIFO (SSI_BASE + 0x50)
  141. /* SSI0 */
  142. #define rSPI_CTLR0 (*(volatile unsigned int *)(SSI0_BASE + 0x00))
  143. #define rSPI_CTLR1 (*(volatile unsigned int *)(SSI0_BASE + 0x04))
  144. #define rSPI_SSIENR (*(volatile unsigned int *)(SSI0_BASE + 0x08))
  145. #define rSPI_MWCR (*(volatile unsigned int *)(SSI0_BASE + 0x0c))
  146. #define rSPI_SER (*(volatile unsigned int *)(SSI0_BASE + 0x10))
  147. #define rSPI_BAUDR (*(volatile unsigned int *)(SSI0_BASE + 0x14))
  148. #define rSPI_TXFTLR (*(volatile unsigned int *)(SSI0_BASE + 0x18))
  149. #define rSPI_RXFTLR (*(volatile unsigned int *)(SSI0_BASE + 0x1C))
  150. #define rSPI_TXFLR (*(volatile unsigned int *)(SSI0_BASE + 0x20))
  151. #define rSPI_RXFLR (*(volatile unsigned int *)(SSI0_BASE + 0x24))
  152. #define rSPI_SR (*(volatile unsigned int *)(SSI0_BASE + 0x28))
  153. #define rSPI_IMR (*(volatile unsigned int *)(SSI0_BASE + 0x2C))
  154. #define rSPI_ISR (*(volatile unsigned int *)(SSI0_BASE + 0x30))
  155. #define rSPI_RISR (*(volatile unsigned int *)(SSI0_BASE + 0x34))
  156. #define rSPI_TXOICR (*(volatile unsigned int *)(SSI0_BASE + 0x38))
  157. #define rSPI_RXOICR (*(volatile unsigned int *)(SSI0_BASE + 0x3C))
  158. #define rSPI_RXUICR (*(volatile unsigned int *)(SSI0_BASE + 0x40))
  159. #define rSPI_MSTICR (*(volatile unsigned int *)(SSI0_BASE + 0x44))
  160. #define rSPI_ICR (*(volatile unsigned int *)(SSI0_BASE + 0x48))
  161. #define rSPI_DMACR (*(volatile unsigned int *)(SSI0_BASE + 0x4C))
  162. #define rSPI_DMATDLR (*(volatile unsigned int *)(SSI0_BASE + 0x50))
  163. #define rSPI_DMARDLR (*(volatile unsigned int *)(SSI0_BASE + 0x54))
  164. #define rSPI_IDR (*(volatile unsigned int *)(SSI0_BASE + 0x58))
  165. #define rSPI_SSI_COMP_VERSION (*(volatile unsigned int *)(SSI0_BASE + 0x5C))
  166. #define rSPI_DR (*(volatile unsigned int *)(SSI0_BASE + 0x60))
  167. #define SPI_DR (SSI0_BASE + 0x60)
  168. #define rSPI_RX_SAMPLE_DLY (*(volatile unsigned int *)(SSI0_BASE + 0xf0))
  169. #define rSPI_SPI_CTRLR0 (*(volatile unsigned int *)(SSI0_BASE + 0xf4))
  170. //#define rSPI_RSVD_1 (*(volatile unsigned int *)(SSI0_BASE + 0xf8))
  171. //#define rSPI_RSVD_1 (*(volatile unsigned int *)(SSI0_BASE + 0xfC))
  172. /* GPIO */
  173. #define rGPIO_PA_MOD (*(volatile unsigned int *)(GPIO_BASE + 0x00))
  174. #define rGPIO_PA_RDATA (*(volatile unsigned int *)(GPIO_BASE + 0x04))
  175. #define rGPIO_PA_INTEN (*(volatile unsigned int *)(GPIO_BASE + 0x08))
  176. #define rGPIO_PA_LEVEL (*(volatile unsigned int *)(GPIO_BASE + 0x0C))
  177. #define rGPIO_PA_PEND (*(volatile unsigned int *)(GPIO_BASE + 0x10))
  178. #define rGPIO_PB_MOD (*(volatile unsigned int *)(GPIO_BASE + 0x20))
  179. #define rGPIO_PB_RDATA (*(volatile unsigned int *)(GPIO_BASE + 0x24))
  180. #define rGPIO_PB_INTEN (*(volatile unsigned int *)(GPIO_BASE + 0x28))
  181. #define rGPIO_PB_LEVEL (*(volatile unsigned int *)(GPIO_BASE + 0x2C))
  182. #define rGPIO_PB_PEND (*(volatile unsigned int *)(GPIO_BASE + 0x30))
  183. #define rGPIO_PC_MOD (*(volatile unsigned int *)(GPIO_BASE + 0x40))
  184. #define rGPIO_PC_RDATA (*(volatile unsigned int *)(GPIO_BASE + 0x44))
  185. #define rGPIO_PC_INTEN (*(volatile unsigned int *)(GPIO_BASE + 0x48))
  186. #define rGPIO_PC_LEVEL (*(volatile unsigned int *)(GPIO_BASE + 0x4C))
  187. #define rGPIO_PC_PEND (*(volatile unsigned int *)(GPIO_BASE + 0x50))
  188. #define rGPIO_PD_MOD (*(volatile unsigned int *)(GPIO_BASE + 0x60))
  189. #define rGPIO_PD_RDATA (*(volatile unsigned int *)(GPIO_BASE + 0x64))
  190. #define rGPIO_PD_INTEN (*(volatile unsigned int *)(GPIO_BASE + 0x68))
  191. #define rGPIO_PD_LEVEL (*(volatile unsigned int *)(GPIO_BASE + 0x6C))
  192. #define rGPIO_PD_PEND (*(volatile unsigned int *)(GPIO_BASE + 0x70))
  193. //DDR Reg
  194. #define DDR_BASE 0x71300000
  195. #define MEM_STA_REG *(volatile unsigned int *)(DDR_BASE + 0x00)
  196. #define MEM_CMD_REG *(volatile unsigned int *)(DDR_BASE + 0x04)
  197. #define DIR_CMD_REG *(volatile unsigned int *)(DDR_BASE + 0x08)
  198. #define MEM_CFG_REG *(volatile unsigned int *)(DDR_BASE + 0x0C)
  199. #define REF_PRD_REG *(volatile unsigned int *)(DDR_BASE + 0x10)
  200. #define TCAS_REG *(volatile unsigned int *)(DDR_BASE + 0x14)
  201. #define TDQSS_REG *(volatile unsigned int *)(DDR_BASE + 0x18)
  202. #define TMRD_REG *(volatile unsigned int *)(DDR_BASE + 0x1C)
  203. #define TRAS_REG *(volatile unsigned int *)(DDR_BASE + 0x20)
  204. #define TRC_REG *(volatile unsigned int *)(DDR_BASE + 0x24)
  205. #define TRCD_REG *(volatile unsigned int *)(DDR_BASE + 0x28)
  206. #define TRFC_REG *(volatile unsigned int *)(DDR_BASE + 0x2C)
  207. #define TRP_REG *(volatile unsigned int *)(DDR_BASE + 0x30)
  208. #define TRRD_REG *(volatile unsigned int *)(DDR_BASE + 0x34)
  209. #define TWR_REG *(volatile unsigned int *)(DDR_BASE + 0x38)
  210. #define TWTR_REG *(volatile unsigned int *)(DDR_BASE + 0x3C)
  211. #define TXP_REG *(volatile unsigned int *)(DDR_BASE + 0x40)
  212. #define TXSR_REG *(volatile unsigned int *)(DDR_BASE + 0x44)
  213. #define TESR_REG *(volatile unsigned int *)(DDR_BASE + 0x48)
  214. #define MEM_CFG2_REG *(volatile unsigned int *)(DDR_BASE + 0x4C)
  215. #define CHIP_CFG_REG *(volatile unsigned int *)(DDR_BASE + 0x200)
  216. #define FEA_CTL_REG *(volatile unsigned int *)(DDR_BASE + 0x30C)
  217. //#define MMU_ENABLE
  218. #define LOADER_OFFSET 0x0
  219. #define LOADER_MAX_SIZE 0x4000
  220. #define STEPLDRA_OFFSET 0x4000
  221. #define STEPLDRB_OFFSET 0x14000
  222. #define STEPLDR_MAX_SIZE 0x10000
  223. #define SYSINFOA_OFFSET 0x24000
  224. #define SYSINFOB_OFFSET 0x25000
  225. #define SYSINFO_MAX_SIZE 0x1000
  226. #define IMAGE_OFFSET 0x40000
  227. #define IMAGE_MAX_SIZE 0xf00000
  228. #define LOADER_FILE_NAME "spildr.bin"
  229. #define STEPLDR_FILE_NAME "stepldr.bin"
  230. #define APP_FILE_NAME "update.bin"
  231. #define IMAGE_ENTRY 0x20000000
  232. #define STEPLDR_ENTRY 0x20f00000
  233. #define CheckImageValid (*((volatile unsigned int *)(IMAGE_ENTRY+IMAGE_FLAG_OFFSET)) == IMAGE_FLAG)
  234. typedef struct {
  235. unsigned int magic;
  236. unsigned int offset;
  237. unsigned int size;
  238. } UpFileInfo;
  239. typedef struct {
  240. unsigned int magic;
  241. unsigned int filenum;
  242. unsigned int size;
  243. unsigned int checksum;
  244. unsigned int reserved1;
  245. unsigned int reserved2;
  246. UpFileInfo files[];
  247. } UpFileHeader;
  248. #define ENOENT 2 /* No such file or directory */
  249. #define EIO 5 /* I/O error */
  250. #define ENXIO 6 /* No such device or address */
  251. #define ENOMEM 12 /* Out of memory */
  252. #define ENODEV 19 /* No such device */
  253. #define EINVAL 22 /* Invalid argument */
  254. #define EFBIG 27 /* File too large */
  255. #define ENOSPC 28 /* No space left on device */
  256. #define ENOTCONN 107 /* Transport endpoint is not connected */
  257. #define min(x,y) ((x) < (y) ? x : y)
  258. #define max(x,y) ((x) > (y) ? x : y)
  259. #define min3(x, y, z) min(min(x, y), z)
  260. #define max3(x, y, z) max(max(x, y), z)
  261. #define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1))
  262. #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  263. #define ALIGN(x,a) __ALIGN_MASK((x),(uintptr_t)(a)-1)
  264. #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
  265. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  266. #define ARCH_DMA_MINALIGN 32//64
  267. #define USB_DMA_MINALIGN ARCH_DMA_MINALIGN
  268. //typedef unsigned long uintptr_t;
  269. #define PAD_COUNT(s, pad) (((s) - 1) / (pad) + 1)
  270. #define PAD_SIZE(s, pad) (PAD_COUNT(s, pad) * pad)
  271. #define ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, pad) \
  272. char __##name[ROUND(PAD_SIZE((size) * sizeof(type), pad), align) \
  273. + (align - 1)]; \
  274. \
  275. type *name = (type *)ALIGN((uintptr_t)__##name, align)
  276. #define ALLOC_ALIGN_BUFFER(type, name, size, align) \
  277. ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, 1)
  278. #define ALLOC_CACHE_ALIGN_BUFFER_PAD(type, name, size, pad) \
  279. ALLOC_ALIGN_BUFFER_PAD(type, name, size, ARCH_DMA_MINALIGN, pad)
  280. #define ALLOC_CACHE_ALIGN_BUFFER(type, name, size) \
  281. ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
  282. static inline int ffs(int x)
  283. {
  284. int r = 1;
  285. if (!x)
  286. return 0;
  287. if (!(x & 0xffff)) {
  288. x >>= 16;
  289. r += 16;
  290. }
  291. if (!(x & 0xff)) {
  292. x >>= 8;
  293. r += 8;
  294. }
  295. if (!(x & 0xf)) {
  296. x >>= 4;
  297. r += 4;
  298. }
  299. if (!(x & 3)) {
  300. x >>= 2;
  301. r += 2;
  302. }
  303. if (!(x & 1)) {
  304. x >>= 1;
  305. r += 1;
  306. }
  307. return r;
  308. }
  309. /*
  310. static void writeb(unsigned char val, void *ptr)
  311. {
  312. *(volatile unsigned char*)ptr = val;
  313. }
  314. static unsigned char readb(void *ptr)
  315. {
  316. return *(volatile unsigned char*)ptr;
  317. }
  318. static void writew(unsigned short val, void *ptr)
  319. {
  320. *(volatile unsigned short*)ptr = val;
  321. }
  322. static unsigned short readw(void *ptr)
  323. {
  324. return *(volatile unsigned short*)ptr;
  325. }
  326. */
  327. #define reg32_read(addr) *((volatile unsigned int *)(addr))
  328. #define reg32_write(addr,val) *((volatile unsigned int *)(addr)) = (val)
  329. #define readl(a) reg32_read(a)
  330. #define writel(v, a) reg32_write(a, v)
  331. #endif // _AMT630H_H_