drv_pl041.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-25 RT-Thread the first version
  9. */
  10. #ifndef __DRV_PL041_H__
  11. #define __DRV_PL041_H__
  12. #define PL041_BASE_ADDR (0x10004000)
  13. /* offsets in CTRL_CH */
  14. #define AACI_RXCR 0x00 /* 29 bits Control Rx FIFO */
  15. #define AACI_TXCR 0x04 /* 17 bits Control Tx FIFO */
  16. #define AACI_SR 0x08 /* 12 bits Status */
  17. #define AACI_ISR 0x0C /* 7 bits Int Status */
  18. #define AACI_IE 0x10 /* 7 bits Int Enable */
  19. /* both for AACI_RXCR and AACI_TXCR */
  20. #define AACI_CR_FEN (1 << 16) /* fifo enable */
  21. #define AACI_CR_COMPACT (1 << 15) /* compact mode */
  22. #define AACI_CR_SZ16 (0 << 13) /* 16 bits */
  23. #define AACI_CR_SZ18 (1 << 13) /* 18 bits */
  24. #define AACI_CR_SZ20 (2 << 13) /* 20 bits */
  25. #define AACI_CR_SZ12 (3 << 13) /* 12 bits */
  26. #define AACI_CR_SL12 (1 << 12)
  27. #define AACI_CR_SL11 (1 << 11)
  28. #define AACI_CR_SL10 (1 << 10)
  29. #define AACI_CR_SL9 (1 << 9)
  30. #define AACI_CR_SL8 (1 << 8)
  31. #define AACI_CR_SL7 (1 << 7)
  32. #define AACI_CR_SL6 (1 << 6)
  33. #define AACI_CR_SL5 (1 << 5)
  34. #define AACI_CR_SL4 (1 << 4)
  35. #define AACI_CR_SL3 (1 << 3)
  36. #define AACI_CR_SL2 (1 << 2)
  37. #define AACI_CR_SL1 (1 << 1)
  38. #define AACI_CR_EN (1 << 0) /* receive enable */
  39. /* status register bits */
  40. #define AACI_SR_RXTOFE (1 << 11) /* rx timeout fifo empty */
  41. #define AACI_SR_TXTO (1 << 10) /* rx timeout fifo nonempty */
  42. #define AACI_SR_TXU (1 << 9) /* tx underrun */
  43. #define AACI_SR_RXO (1 << 8) /* rx overrun */
  44. #define AACI_SR_TXB (1 << 7) /* tx busy */
  45. #define AACI_SR_RXB (1 << 6) /* rx busy */
  46. #define AACI_SR_TXFF (1 << 5) /* tx fifo full */
  47. #define AACI_SR_RXFF (1 << 4) /* rx fifo full */
  48. #define AACI_SR_TXHE (1 << 3) /* tx fifo half empty */
  49. #define AACI_SR_RXHF (1 << 2) /* rx fifo half full */
  50. #define AACI_SR_TXFE (1 << 1) /* tx fifo empty */
  51. #define AACI_SR_RXFE (1 << 0) /* rx fifo empty */
  52. #define AACI_ISR_RXTOFEINTR (1 << 6) /* rx fifo empty */
  53. #define AACI_ISR_URINTR (1 << 5) /* tx underflow */
  54. #define AACI_ISR_ORINTR (1 << 4) /* rx overflow */
  55. #define AACI_ISR_RXINTR (1 << 3) /* rx fifo */
  56. #define AACI_ISR_TXINTR (1 << 2) /* tx fifo intr */
  57. #define AACI_ISR_RXTOINTR (1 << 1) /* rx timeout */
  58. #define AACI_ISR_TXCINTR (1 << 0) /* tx complete */
  59. /* interrupt enable */
  60. #define AACI_IE_RXTOIE (1 << 6) /*rx timeout interrupt enable*/
  61. #define AACI_IE_URIE (1 << 5) /*Transmit underrun interrupt enable*/
  62. #define AACI_IE_ORIE (1 << 4) /*Overrun receive interrupt enable*/
  63. #define AACI_IE_RXIE (1 << 3) /*Receive interrupt enable*/
  64. #define AACI_IE_TXIE (1 << 2) /*Transmit interrupt enable*/
  65. #define AACI_IE_RXTIE (1 << 1) /*Receive timeout interrupt enable*/
  66. #define AACI_IE_TXCIE (1 << 0) /*Transmit complete interrupt enable*/
  67. /* interrupt status */
  68. #define AACI_ISR_RXTOFE (1 << 6) /* rx timeout fifo empty */
  69. #define AACI_ISR_UR (1 << 5) /* tx fifo underrun */
  70. #define AACI_ISR_OR (1 << 4) /* rx fifo overrun */
  71. #define AACI_ISR_RX (1 << 3) /* rx interrupt status */
  72. #define AACI_ISR_TX (1 << 2) /* tx interrupt status */
  73. #define AACI_ISR_RXTO (1 << 1) /* rx timeout */
  74. #define AACI_ISR_TXC (1 << 0) /* tx complete */
  75. /* interrupt enable */
  76. #define AACI_IE_RXTOFE (1 << 6) /* rx timeout fifo empty */
  77. #define AACI_IE_UR (1 << 5) /* tx fifo underrun */
  78. #define AACI_IE_OR (1 << 4) /* rx fifo overrun */
  79. #define AACI_IE_RX (1 << 3) /* rx interrupt status */
  80. #define AACI_IE_TX (1 << 2) /* tx interrupt status */
  81. #define AACI_IE_RXTO (1 << 1) /* rx timeout */
  82. #define AACI_IE_TXC (1 << 0) /* tx complete */
  83. /* slot flag register bits */
  84. #define AACI_SLFR_RWIS (1 << 13) /* raw wake-up interrupt status */
  85. #define AACI_SLFR_RGPIOINTR (1 << 12) /* raw gpio interrupt */
  86. #define AACI_SLFR_12TXE (1 << 11) /* slot 12 tx empty */
  87. #define AACI_SLFR_12RXV (1 << 10) /* slot 12 rx valid */
  88. #define AACI_SLFR_2TXE (1 << 9) /* slot 2 tx empty */
  89. #define AACI_SLFR_2RXV (1 << 8) /* slot 2 rx valid */
  90. #define AACI_SLFR_1TXE (1 << 7) /* slot 1 tx empty */
  91. #define AACI_SLFR_1RXV (1 << 6) /* slot 1 rx valid */
  92. #define AACI_SLFR_12TXB (1 << 5) /* slot 12 tx busy */
  93. #define AACI_SLFR_12RXB (1 << 4) /* slot 12 rx busy */
  94. #define AACI_SLFR_2TXB (1 << 3) /* slot 2 tx busy */
  95. #define AACI_SLFR_2RXB (1 << 2) /* slot 2 rx busy */
  96. #define AACI_SLFR_1TXB (1 << 1) /* slot 1 tx busy */
  97. #define AACI_SLFR_1RXB (1 << 0) /* slot 1 rx busy */
  98. /* Interrupt clear register */
  99. #define AACI_ICLR_RXTOFEC4 (1 << 12) /* Receive timeout FIFO empty clear */
  100. #define AACI_ICLR_RXTOFEC3 (1 << 11) /* Receive timeout FIFO empty clear */
  101. #define AACI_ICLR_RXTOFEC2 (1 << 10) /* Receive timeout FIFO empty clear */
  102. #define AACI_ICLR_RXTOFEC1 (1 << 9) /* Receive timeout FIFO empty clear */
  103. #define AACI_ICLR_TXUEC4 (1 << 8) /* Transmit underrun error clear */
  104. #define AACI_ICLR_TXUEC3 (1 << 7) /* Transmit underrun error clear */
  105. #define AACI_ICLR_TXUEC2 (1 << 6) /* Transmit underrun error clear*/
  106. #define AACI_ICLR_TXUEC1 (1 << 5) /* Transmit underrun error clear */
  107. #define AACI_ICLR_RXOEC4 (1 << 4) /* Receive overrun error clear */
  108. #define AACI_ICLR_RXOEC3 (1 << 3) /* Receive overrun error clear */
  109. #define AACI_ICLR_RXOEC2 (1 << 2) /* Receive overrun error clear */
  110. #define AACI_ICLR_RXOEC1 (1 << 1) /* Receive overrun error clear */
  111. #define AACI_ICLR_WISC (1 << 0) /* Wake-up interrupt status clear */
  112. /* Main control register bits AACI_MAINCR */
  113. #define AACI_MAINCR_SCRA(x) ((x) << 10) /* secondary codec reg access */
  114. #define AACI_MAINCR_DMAEN (1 << 9) /* dma enable */
  115. #define AACI_MAINCR_SL12TXEN (1 << 8) /* slot 12 transmit enable */
  116. #define AACI_MAINCR_SL12RXEN (1 << 7) /* slot 12 receive enable */
  117. #define AACI_MAINCR_SL2TXEN (1 << 6) /* slot 2 transmit enable */
  118. #define AACI_MAINCR_SL2RXEN (1 << 5) /* slot 2 receive enable */
  119. #define AACI_MAINCR_SL1TXEN (1 << 4) /* slot 1 transmit enable */
  120. #define AACI_MAINCR_SL1RXEN (1 << 3) /* slot 1 receive enable */
  121. #define AACI_MAINCR_LPM (1 << 2) /* low power mode */
  122. #define AACI_MAINCR_LOOPBK (1 << 1) /* loopback */
  123. #define AACI_MAINCR_IE (1 << 0) /* aaci interface enable */
  124. /* Reset register bits. P65 */
  125. #define RESET_NRST (1 << 0)
  126. /* Sync register bits. P65 */
  127. #define SYNC_FORCE (1 << 0)
  128. /* Main flag register bits. P66 */
  129. #define MAINFR_TXB (1 << 1) /* transmit busy */
  130. #define MAINFR_RXB (1 << 0) /* receive busy */
  131. #define PL041_CHANNEL_LEFT_DAC (0x1 << 3)
  132. #define PL041_CHANNEL_RIGHT_DAC (0x1 << 3)
  133. #define PL041_CHANNEL_LEFT_ADC (0x1 << 3)
  134. #define PL041_CHANNEL_RIGHT_ADC (0x1 << 3)
  135. struct reg_pl041
  136. {
  137. volatile rt_uint32_t rxcr1; /* 0x000 */
  138. volatile rt_uint32_t txcr1; /* 0x004 */
  139. volatile rt_uint32_t sr1; /* 0x008 */
  140. volatile rt_uint32_t isr1; /* 0x00c */
  141. volatile rt_uint32_t iie1; /* 0x010 */
  142. volatile rt_uint32_t rxcr2; /* 0x014 */
  143. volatile rt_uint32_t txcr2; /* 0x018 */
  144. volatile rt_uint32_t sr2; /* 0x01c */
  145. volatile rt_uint32_t isr2; /* 0x020 */
  146. volatile rt_uint32_t iie2; /* 0x024 */
  147. volatile rt_uint32_t rxcr3; /* 0x028 */
  148. volatile rt_uint32_t txcr3; /* 0x02c */
  149. volatile rt_uint32_t sr3; /* 0x030 */
  150. volatile rt_uint32_t isr3; /* 0x034 */
  151. volatile rt_uint32_t iie3; /* 0x038 */
  152. volatile rt_uint32_t rxcr4; /* 0x03c */
  153. volatile rt_uint32_t txcr4; /* 0x040 */
  154. volatile rt_uint32_t sr4; /* 0x044 */
  155. volatile rt_uint32_t isr4; /* 0x048 */
  156. volatile rt_uint32_t iie4; /* 0x04c */
  157. volatile rt_uint32_t sl1rx; /* 0x050 */
  158. volatile rt_uint32_t sl1tx; /* 0x054 */
  159. volatile rt_uint32_t sl2rx; /* 0x058 */
  160. volatile rt_uint32_t sl2tx; /* 0x05c */
  161. volatile rt_uint32_t sl12rx; /* 0x060 */
  162. volatile rt_uint32_t sl12tx; /* 0x064 */
  163. volatile rt_uint32_t slfr; /* 0x068 */
  164. volatile rt_uint32_t slistat; /* 0x06c */
  165. volatile rt_uint32_t slien; /* 0x070 */
  166. volatile rt_uint32_t intclr; /* 0x074 */
  167. volatile rt_uint32_t maincr; /* 0x078 */
  168. volatile rt_uint32_t reset; /* 0x07c */
  169. volatile rt_uint32_t sync; /* 0x080 */
  170. volatile rt_uint32_t allints; /* 0x084 */
  171. volatile rt_uint32_t mainfr; /* 0x088 */
  172. volatile rt_uint32_t res08c;
  173. volatile rt_uint32_t dr1[8]; /* 0x090 */
  174. volatile rt_uint32_t dr2[8]; /* 0x0b0 */
  175. volatile rt_uint32_t dr3[8]; /* 0x0d0 */
  176. volatile rt_uint32_t dr4[8]; /* 0x0f0 */
  177. };
  178. typedef struct reg_pl041 *reg_pl041_t;
  179. #define PL041 ((reg_pl041_t)PL041_BASE_ADDR)
  180. struct pl041_cfg
  181. {
  182. rt_uint32_t itype;
  183. rt_uint32_t otype;
  184. int vol;
  185. int rate;
  186. };
  187. typedef struct pl041_cfg *pl041_cfg_t;
  188. typedef void (*pl041_irq_fun_t)(rt_uint32_t status, void * user_data);
  189. rt_err_t aaci_pl041_init(void);
  190. void aaci_ac97_write(rt_uint16_t reg, rt_uint16_t val);
  191. rt_uint16_t aaci_ac97_read(rt_uint16_t reg);
  192. int aaci_pl041_channel_cfg(int channel, pl041_cfg_t cfg);
  193. int aaci_pl041_channel_write(int channel, rt_uint16_t *buff, int count);
  194. int aaci_pl041_channel_read(int channel, rt_uint16_t *buff, int count);
  195. int aaci_pl041_channel_enable(int channel);
  196. int aaci_pl041_channel_disable(int channel);
  197. rt_err_t aaci_pl041_irq_register(int channel, pl041_irq_fun_t fun, void *user_data);
  198. rt_err_t aaci_pl041_irq_unregister(int channel);
  199. void aaci_pl041_irq_disable(int channel, rt_uint32_t vector);
  200. void aaci_pl041_irq_enable(int channel, rt_uint32_t vector);
  201. #endif