drv_pl041.h 11 KB

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