fsl_asrc.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /*
  2. * fsl_asrc.h - Freescale ASRC ALSA SoC header file
  3. *
  4. * Copyright (C) 2014 Freescale Semiconductor, Inc.
  5. *
  6. * Author: Nicolin Chen <nicoleotsuka@gmail.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public License
  9. * version 2. This program is licensed "as is" without any warranty of any
  10. * kind, whether express or implied.
  11. */
  12. #ifndef _FSL_ASRC_H
  13. #define _FSL_ASRC_H
  14. #define IN 0
  15. #define OUT 1
  16. #define ASRC_DMA_BUFFER_NUM 2
  17. #define ASRC_INPUTFIFO_THRESHOLD 32
  18. #define ASRC_OUTPUTFIFO_THRESHOLD 32
  19. #define ASRC_FIFO_THRESHOLD_MIN 0
  20. #define ASRC_FIFO_THRESHOLD_MAX 63
  21. #define ASRC_DMA_BUFFER_SIZE (1024 * 48 * 4)
  22. #define ASRC_MAX_BUFFER_SIZE (1024 * 48)
  23. #define ASRC_OUTPUT_LAST_SAMPLE 8
  24. #define IDEAL_RATIO_RATE 1000000
  25. #define REG_ASRCTR 0x00
  26. #define REG_ASRIER 0x04
  27. #define REG_ASRCNCR 0x0C
  28. #define REG_ASRCFG 0x10
  29. #define REG_ASRCSR 0x14
  30. #define REG_ASRCDR1 0x18
  31. #define REG_ASRCDR2 0x1C
  32. #define REG_ASRCDR(i) ((i < 2) ? REG_ASRCDR1 : REG_ASRCDR2)
  33. #define REG_ASRSTR 0x20
  34. #define REG_ASRRA 0x24
  35. #define REG_ASRRB 0x28
  36. #define REG_ASRRC 0x2C
  37. #define REG_ASRPM1 0x40
  38. #define REG_ASRPM2 0x44
  39. #define REG_ASRPM3 0x48
  40. #define REG_ASRPM4 0x4C
  41. #define REG_ASRPM5 0x50
  42. #define REG_ASRTFR1 0x54
  43. #define REG_ASRCCR 0x5C
  44. #define REG_ASRDIA 0x60
  45. #define REG_ASRDOA 0x64
  46. #define REG_ASRDIB 0x68
  47. #define REG_ASRDOB 0x6C
  48. #define REG_ASRDIC 0x70
  49. #define REG_ASRDOC 0x74
  50. #define REG_ASRDI(i) (REG_ASRDIA + (i << 3))
  51. #define REG_ASRDO(i) (REG_ASRDOA + (i << 3))
  52. #define REG_ASRDx(x, i) (x == IN ? REG_ASRDI(i) : REG_ASRDO(i))
  53. #define REG_ASRIDRHA 0x80
  54. #define REG_ASRIDRLA 0x84
  55. #define REG_ASRIDRHB 0x88
  56. #define REG_ASRIDRLB 0x8C
  57. #define REG_ASRIDRHC 0x90
  58. #define REG_ASRIDRLC 0x94
  59. #define REG_ASRIDRH(i) (REG_ASRIDRHA + (i << 3))
  60. #define REG_ASRIDRL(i) (REG_ASRIDRLA + (i << 3))
  61. #define REG_ASR76K 0x98
  62. #define REG_ASR56K 0x9C
  63. #define REG_ASRMCRA 0xA0
  64. #define REG_ASRFSTA 0xA4
  65. #define REG_ASRMCRB 0xA8
  66. #define REG_ASRFSTB 0xAC
  67. #define REG_ASRMCRC 0xB0
  68. #define REG_ASRFSTC 0xB4
  69. #define REG_ASRMCR(i) (REG_ASRMCRA + (i << 3))
  70. #define REG_ASRFST(i) (REG_ASRFSTA + (i << 3))
  71. #define REG_ASRMCR1A 0xC0
  72. #define REG_ASRMCR1B 0xC4
  73. #define REG_ASRMCR1C 0xC8
  74. #define REG_ASRMCR1(i) (REG_ASRMCR1A + (i << 2))
  75. /* REG0 0x00 REG_ASRCTR */
  76. #define ASRCTR_ATSi_SHIFT(i) (20 + i)
  77. #define ASRCTR_ATSi_MASK(i) (1 << ASRCTR_ATSi_SHIFT(i))
  78. #define ASRCTR_ATS(i) (1 << ASRCTR_ATSi_SHIFT(i))
  79. #define ASRCTR_USRi_SHIFT(i) (14 + (i << 1))
  80. #define ASRCTR_USRi_MASK(i) (1 << ASRCTR_USRi_SHIFT(i))
  81. #define ASRCTR_USR(i) (1 << ASRCTR_USRi_SHIFT(i))
  82. #define ASRCTR_IDRi_SHIFT(i) (13 + (i << 1))
  83. #define ASRCTR_IDRi_MASK(i) (1 << ASRCTR_IDRi_SHIFT(i))
  84. #define ASRCTR_IDR(i) (1 << ASRCTR_IDRi_SHIFT(i))
  85. #define ASRCTR_SRST_SHIFT 4
  86. #define ASRCTR_SRST_MASK (1 << ASRCTR_SRST_SHIFT)
  87. #define ASRCTR_SRST (1 << ASRCTR_SRST_SHIFT)
  88. #define ASRCTR_ASRCEi_SHIFT(i) (1 + i)
  89. #define ASRCTR_ASRCEi_MASK(i) (1 << ASRCTR_ASRCEi_SHIFT(i))
  90. #define ASRCTR_ASRCE(i) (1 << ASRCTR_ASRCEi_SHIFT(i))
  91. #define ASRCTR_ASRCEi_ALL_MASK (0x7 << ASRCTR_ASRCEi_SHIFT(0))
  92. #define ASRCTR_ASRCEN_SHIFT 0
  93. #define ASRCTR_ASRCEN_MASK (1 << ASRCTR_ASRCEN_SHIFT)
  94. #define ASRCTR_ASRCEN (1 << ASRCTR_ASRCEN_SHIFT)
  95. /* REG1 0x04 REG_ASRIER */
  96. #define ASRIER_AFPWE_SHIFT 7
  97. #define ASRIER_AFPWE_MASK (1 << ASRIER_AFPWE_SHIFT)
  98. #define ASRIER_AFPWE (1 << ASRIER_AFPWE_SHIFT)
  99. #define ASRIER_AOLIE_SHIFT 6
  100. #define ASRIER_AOLIE_MASK (1 << ASRIER_AOLIE_SHIFT)
  101. #define ASRIER_AOLIE (1 << ASRIER_AOLIE_SHIFT)
  102. #define ASRIER_ADOEi_SHIFT(i) (3 + i)
  103. #define ASRIER_ADOEi_MASK(i) (1 << ASRIER_ADOEi_SHIFT(i))
  104. #define ASRIER_ADOE(i) (1 << ASRIER_ADOEi_SHIFT(i))
  105. #define ASRIER_ADIEi_SHIFT(i) (0 + i)
  106. #define ASRIER_ADIEi_MASK(i) (1 << ASRIER_ADIEi_SHIFT(i))
  107. #define ASRIER_ADIE(i) (1 << ASRIER_ADIEi_SHIFT(i))
  108. /* REG2 0x0C REG_ASRCNCR */
  109. #define ASRCNCR_ANCi_SHIFT(i, b) (b * i)
  110. #define ASRCNCR_ANCi_MASK(i, b) (((1 << b) - 1) << ASRCNCR_ANCi_SHIFT(i, b))
  111. #define ASRCNCR_ANCi(i, v, b) ((v << ASRCNCR_ANCi_SHIFT(i, b)) & ASRCNCR_ANCi_MASK(i, b))
  112. /* REG3 0x10 REG_ASRCFG */
  113. #define ASRCFG_INIRQi_SHIFT(i) (21 + i)
  114. #define ASRCFG_INIRQi_MASK(i) (1 << ASRCFG_INIRQi_SHIFT(i))
  115. #define ASRCFG_INIRQi (1 << ASRCFG_INIRQi_SHIFT(i))
  116. #define ASRCFG_NDPRi_SHIFT(i) (18 + i)
  117. #define ASRCFG_NDPRi_MASK(i) (1 << ASRCFG_NDPRi_SHIFT(i))
  118. #define ASRCFG_NDPRi (1 << ASRCFG_NDPRi_SHIFT(i))
  119. #define ASRCFG_POSTMODi_SHIFT(i) (8 + (i << 2))
  120. #define ASRCFG_POSTMODi_WIDTH 2
  121. #define ASRCFG_POSTMODi_MASK(i) (((1 << ASRCFG_POSTMODi_WIDTH) - 1) << ASRCFG_POSTMODi_SHIFT(i))
  122. #define ASRCFG_POSTMOD(i, v) ((v) << ASRCFG_POSTMODi_SHIFT(i))
  123. #define ASRCFG_POSTMODi_UP(i) (0 << ASRCFG_POSTMODi_SHIFT(i))
  124. #define ASRCFG_POSTMODi_DCON(i) (1 << ASRCFG_POSTMODi_SHIFT(i))
  125. #define ASRCFG_POSTMODi_DOWN(i) (2 << ASRCFG_POSTMODi_SHIFT(i))
  126. #define ASRCFG_PREMODi_SHIFT(i) (6 + (i << 2))
  127. #define ASRCFG_PREMODi_WIDTH 2
  128. #define ASRCFG_PREMODi_MASK(i) (((1 << ASRCFG_PREMODi_WIDTH) - 1) << ASRCFG_PREMODi_SHIFT(i))
  129. #define ASRCFG_PREMOD(i, v) ((v) << ASRCFG_PREMODi_SHIFT(i))
  130. #define ASRCFG_PREMODi_UP(i) (0 << ASRCFG_PREMODi_SHIFT(i))
  131. #define ASRCFG_PREMODi_DCON(i) (1 << ASRCFG_PREMODi_SHIFT(i))
  132. #define ASRCFG_PREMODi_DOWN(i) (2 << ASRCFG_PREMODi_SHIFT(i))
  133. #define ASRCFG_PREMODi_BYPASS(i) (3 << ASRCFG_PREMODi_SHIFT(i))
  134. /* REG4 0x14 REG_ASRCSR */
  135. #define ASRCSR_AxCSi_WIDTH 4
  136. #define ASRCSR_AxCSi_MASK ((1 << ASRCSR_AxCSi_WIDTH) - 1)
  137. #define ASRCSR_AOCSi_SHIFT(i) (12 + (i << 2))
  138. #define ASRCSR_AOCSi_MASK(i) (((1 << ASRCSR_AxCSi_WIDTH) - 1) << ASRCSR_AOCSi_SHIFT(i))
  139. #define ASRCSR_AOCS(i, v) ((v) << ASRCSR_AOCSi_SHIFT(i))
  140. #define ASRCSR_AICSi_SHIFT(i) (i << 2)
  141. #define ASRCSR_AICSi_MASK(i) (((1 << ASRCSR_AxCSi_WIDTH) - 1) << ASRCSR_AICSi_SHIFT(i))
  142. #define ASRCSR_AICS(i, v) ((v) << ASRCSR_AICSi_SHIFT(i))
  143. /* REG5&6 0x18 & 0x1C REG_ASRCDR1 & ASRCDR2 */
  144. #define ASRCDRi_AxCPi_WIDTH 3
  145. #define ASRCDRi_AICPi_SHIFT(i) (0 + (i % 2) * 6)
  146. #define ASRCDRi_AICPi_MASK(i) (((1 << ASRCDRi_AxCPi_WIDTH) - 1) << ASRCDRi_AICPi_SHIFT(i))
  147. #define ASRCDRi_AICP(i, v) ((v) << ASRCDRi_AICPi_SHIFT(i))
  148. #define ASRCDRi_AICDi_SHIFT(i) (3 + (i % 2) * 6)
  149. #define ASRCDRi_AICDi_MASK(i) (((1 << ASRCDRi_AxCPi_WIDTH) - 1) << ASRCDRi_AICDi_SHIFT(i))
  150. #define ASRCDRi_AICD(i, v) ((v) << ASRCDRi_AICDi_SHIFT(i))
  151. #define ASRCDRi_AOCPi_SHIFT(i) ((i < 2) ? 12 + i * 6 : 6)
  152. #define ASRCDRi_AOCPi_MASK(i) (((1 << ASRCDRi_AxCPi_WIDTH) - 1) << ASRCDRi_AOCPi_SHIFT(i))
  153. #define ASRCDRi_AOCP(i, v) ((v) << ASRCDRi_AOCPi_SHIFT(i))
  154. #define ASRCDRi_AOCDi_SHIFT(i) ((i < 2) ? 15 + i * 6 : 9)
  155. #define ASRCDRi_AOCDi_MASK(i) (((1 << ASRCDRi_AxCPi_WIDTH) - 1) << ASRCDRi_AOCDi_SHIFT(i))
  156. #define ASRCDRi_AOCD(i, v) ((v) << ASRCDRi_AOCDi_SHIFT(i))
  157. /* REG7 0x20 REG_ASRSTR */
  158. #define ASRSTR_DSLCNT_SHIFT 21
  159. #define ASRSTR_DSLCNT_MASK (1 << ASRSTR_DSLCNT_SHIFT)
  160. #define ASRSTR_DSLCNT (1 << ASRSTR_DSLCNT_SHIFT)
  161. #define ASRSTR_ATQOL_SHIFT 20
  162. #define ASRSTR_ATQOL_MASK (1 << ASRSTR_ATQOL_SHIFT)
  163. #define ASRSTR_ATQOL (1 << ASRSTR_ATQOL_SHIFT)
  164. #define ASRSTR_AOOLi_SHIFT(i) (17 + i)
  165. #define ASRSTR_AOOLi_MASK(i) (1 << ASRSTR_AOOLi_SHIFT(i))
  166. #define ASRSTR_AOOL(i) (1 << ASRSTR_AOOLi_SHIFT(i))
  167. #define ASRSTR_AIOLi_SHIFT(i) (14 + i)
  168. #define ASRSTR_AIOLi_MASK(i) (1 << ASRSTR_AIOLi_SHIFT(i))
  169. #define ASRSTR_AIOL(i) (1 << ASRSTR_AIOLi_SHIFT(i))
  170. #define ASRSTR_AODOi_SHIFT(i) (11 + i)
  171. #define ASRSTR_AODOi_MASK(i) (1 << ASRSTR_AODOi_SHIFT(i))
  172. #define ASRSTR_AODO(i) (1 << ASRSTR_AODOi_SHIFT(i))
  173. #define ASRSTR_AIDUi_SHIFT(i) (8 + i)
  174. #define ASRSTR_AIDUi_MASK(i) (1 << ASRSTR_AIDUi_SHIFT(i))
  175. #define ASRSTR_AIDU(i) (1 << ASRSTR_AIDUi_SHIFT(i))
  176. #define ASRSTR_FPWT_SHIFT 7
  177. #define ASRSTR_FPWT_MASK (1 << ASRSTR_FPWT_SHIFT)
  178. #define ASRSTR_FPWT (1 << ASRSTR_FPWT_SHIFT)
  179. #define ASRSTR_AOLE_SHIFT 6
  180. #define ASRSTR_AOLE_MASK (1 << ASRSTR_AOLE_SHIFT)
  181. #define ASRSTR_AOLE (1 << ASRSTR_AOLE_SHIFT)
  182. #define ASRSTR_AODEi_SHIFT(i) (3 + i)
  183. #define ASRSTR_AODFi_MASK(i) (1 << ASRSTR_AODEi_SHIFT(i))
  184. #define ASRSTR_AODF(i) (1 << ASRSTR_AODEi_SHIFT(i))
  185. #define ASRSTR_AIDEi_SHIFT(i) (0 + i)
  186. #define ASRSTR_AIDEi_MASK(i) (1 << ASRSTR_AIDEi_SHIFT(i))
  187. #define ASRSTR_AIDE(i) (1 << ASRSTR_AIDEi_SHIFT(i))
  188. /* REG10 0x54 REG_ASRTFR1 */
  189. #define ASRTFR1_TF_BASE_WIDTH 7
  190. #define ASRTFR1_TF_BASE_SHIFT 6
  191. #define ASRTFR1_TF_BASE_MASK (((1 << ASRTFR1_TF_BASE_WIDTH) - 1) << ASRTFR1_TF_BASE_SHIFT)
  192. #define ASRTFR1_TF_BASE(i) ((i) << ASRTFR1_TF_BASE_SHIFT)
  193. /*
  194. * REG22 0xA0 REG_ASRMCRA
  195. * REG24 0xA8 REG_ASRMCRB
  196. * REG26 0xB0 REG_ASRMCRC
  197. */
  198. #define ASRMCRi_ZEROBUFi_SHIFT 23
  199. #define ASRMCRi_ZEROBUFi_MASK (1 << ASRMCRi_ZEROBUFi_SHIFT)
  200. #define ASRMCRi_ZEROBUFi (1 << ASRMCRi_ZEROBUFi_SHIFT)
  201. #define ASRMCRi_EXTTHRSHi_SHIFT 22
  202. #define ASRMCRi_EXTTHRSHi_MASK (1 << ASRMCRi_EXTTHRSHi_SHIFT)
  203. #define ASRMCRi_EXTTHRSHi (1 << ASRMCRi_EXTTHRSHi_SHIFT)
  204. #define ASRMCRi_BUFSTALLi_SHIFT 21
  205. #define ASRMCRi_BUFSTALLi_MASK (1 << ASRMCRi_BUFSTALLi_SHIFT)
  206. #define ASRMCRi_BUFSTALLi (1 << ASRMCRi_BUFSTALLi_SHIFT)
  207. #define ASRMCRi_BYPASSPOLYi_SHIFT 20
  208. #define ASRMCRi_BYPASSPOLYi_MASK (1 << ASRMCRi_BYPASSPOLYi_SHIFT)
  209. #define ASRMCRi_BYPASSPOLYi (1 << ASRMCRi_BYPASSPOLYi_SHIFT)
  210. #define ASRMCRi_OUTFIFO_THRESHOLD_WIDTH 6
  211. #define ASRMCRi_OUTFIFO_THRESHOLD_SHIFT 12
  212. #define ASRMCRi_OUTFIFO_THRESHOLD_MASK (((1 << ASRMCRi_OUTFIFO_THRESHOLD_WIDTH) - 1) << ASRMCRi_OUTFIFO_THRESHOLD_SHIFT)
  213. #define ASRMCRi_OUTFIFO_THRESHOLD(v) (((v) << ASRMCRi_OUTFIFO_THRESHOLD_SHIFT) & ASRMCRi_OUTFIFO_THRESHOLD_MASK)
  214. #define ASRMCRi_RSYNIFi_SHIFT 11
  215. #define ASRMCRi_RSYNIFi_MASK (1 << ASRMCRi_RSYNIFi_SHIFT)
  216. #define ASRMCRi_RSYNIFi (1 << ASRMCRi_RSYNIFi_SHIFT)
  217. #define ASRMCRi_RSYNOFi_SHIFT 10
  218. #define ASRMCRi_RSYNOFi_MASK (1 << ASRMCRi_RSYNOFi_SHIFT)
  219. #define ASRMCRi_RSYNOFi (1 << ASRMCRi_RSYNOFi_SHIFT)
  220. #define ASRMCRi_INFIFO_THRESHOLD_WIDTH 6
  221. #define ASRMCRi_INFIFO_THRESHOLD_SHIFT 0
  222. #define ASRMCRi_INFIFO_THRESHOLD_MASK (((1 << ASRMCRi_INFIFO_THRESHOLD_WIDTH) - 1) << ASRMCRi_INFIFO_THRESHOLD_SHIFT)
  223. #define ASRMCRi_INFIFO_THRESHOLD(v) (((v) << ASRMCRi_INFIFO_THRESHOLD_SHIFT) & ASRMCRi_INFIFO_THRESHOLD_MASK)
  224. /*
  225. * REG23 0xA4 REG_ASRFSTA
  226. * REG25 0xAC REG_ASRFSTB
  227. * REG27 0xB4 REG_ASRFSTC
  228. */
  229. #define ASRFSTi_OAFi_SHIFT 23
  230. #define ASRFSTi_OAFi_MASK (1 << ASRFSTi_OAFi_SHIFT)
  231. #define ASRFSTi_OAFi (1 << ASRFSTi_OAFi_SHIFT)
  232. #define ASRFSTi_OUTPUT_FIFO_WIDTH 7
  233. #define ASRFSTi_OUTPUT_FIFO_SHIFT 12
  234. #define ASRFSTi_OUTPUT_FIFO_MASK (((1 << ASRFSTi_OUTPUT_FIFO_WIDTH) - 1) << ASRFSTi_OUTPUT_FIFO_SHIFT)
  235. #define ASRFSTi_IAEi_SHIFT 11
  236. #define ASRFSTi_IAEi_MASK (1 << ASRFSTi_OAFi_SHIFT)
  237. #define ASRFSTi_IAEi (1 << ASRFSTi_OAFi_SHIFT)
  238. #define ASRFSTi_INPUT_FIFO_WIDTH 7
  239. #define ASRFSTi_INPUT_FIFO_SHIFT 0
  240. #define ASRFSTi_INPUT_FIFO_MASK ((1 << ASRFSTi_INPUT_FIFO_WIDTH) - 1)
  241. /* REG28 0xC0 & 0xC4 & 0xC8 REG_ASRMCR1i */
  242. #define ASRMCR1i_IWD_WIDTH 3
  243. #define ASRMCR1i_IWD_SHIFT 9
  244. #define ASRMCR1i_IWD_MASK (((1 << ASRMCR1i_IWD_WIDTH) - 1) << ASRMCR1i_IWD_SHIFT)
  245. #define ASRMCR1i_IWD(v) ((v) << ASRMCR1i_IWD_SHIFT)
  246. #define ASRMCR1i_IMSB_SHIFT 8
  247. #define ASRMCR1i_IMSB_MASK (1 << ASRMCR1i_IMSB_SHIFT)
  248. #define ASRMCR1i_IMSB_MSB (1 << ASRMCR1i_IMSB_SHIFT)
  249. #define ASRMCR1i_IMSB_LSB (0 << ASRMCR1i_IMSB_SHIFT)
  250. #define ASRMCR1i_OMSB_SHIFT 2
  251. #define ASRMCR1i_OMSB_MASK (1 << ASRMCR1i_OMSB_SHIFT)
  252. #define ASRMCR1i_OMSB_MSB (1 << ASRMCR1i_OMSB_SHIFT)
  253. #define ASRMCR1i_OMSB_LSB (0 << ASRMCR1i_OMSB_SHIFT)
  254. #define ASRMCR1i_OSGN_SHIFT 1
  255. #define ASRMCR1i_OSGN_MASK (1 << ASRMCR1i_OSGN_SHIFT)
  256. #define ASRMCR1i_OSGN (1 << ASRMCR1i_OSGN_SHIFT)
  257. #define ASRMCR1i_OW16_SHIFT 0
  258. #define ASRMCR1i_OW16_MASK (1 << ASRMCR1i_OW16_SHIFT)
  259. #define ASRMCR1i_OW16(v) ((v) << ASRMCR1i_OW16_SHIFT)
  260. enum asrc_pair_index {
  261. ASRC_INVALID_PAIR = -1,
  262. ASRC_PAIR_A = 0,
  263. ASRC_PAIR_B = 1,
  264. ASRC_PAIR_C = 2,
  265. };
  266. #define ASRC_PAIR_MAX_NUM (ASRC_PAIR_C + 1)
  267. enum asrc_inclk {
  268. INCLK_NONE = 0x03,
  269. INCLK_ESAI_RX = 0x00,
  270. INCLK_SSI1_RX = 0x01,
  271. INCLK_SSI2_RX = 0x02,
  272. INCLK_SSI3_RX = 0x07,
  273. INCLK_SPDIF_RX = 0x04,
  274. INCLK_MLB_CLK = 0x05,
  275. INCLK_PAD = 0x06,
  276. INCLK_ESAI_TX = 0x08,
  277. INCLK_SSI1_TX = 0x09,
  278. INCLK_SSI2_TX = 0x0a,
  279. INCLK_SSI3_TX = 0x0b,
  280. INCLK_SPDIF_TX = 0x0c,
  281. INCLK_ASRCK1_CLK = 0x0f,
  282. };
  283. enum asrc_outclk {
  284. OUTCLK_NONE = 0x03,
  285. OUTCLK_ESAI_TX = 0x00,
  286. OUTCLK_SSI1_TX = 0x01,
  287. OUTCLK_SSI2_TX = 0x02,
  288. OUTCLK_SSI3_TX = 0x07,
  289. OUTCLK_SPDIF_TX = 0x04,
  290. OUTCLK_MLB_CLK = 0x05,
  291. OUTCLK_PAD = 0x06,
  292. OUTCLK_ESAI_RX = 0x08,
  293. OUTCLK_SSI1_RX = 0x09,
  294. OUTCLK_SSI2_RX = 0x0a,
  295. OUTCLK_SSI3_RX = 0x0b,
  296. OUTCLK_SPDIF_RX = 0x0c,
  297. OUTCLK_ASRCK1_CLK = 0x0f,
  298. };
  299. #define ASRC_CLK_MAX_NUM 16
  300. enum asrc_word_width {
  301. ASRC_WIDTH_24_BIT = 0,
  302. ASRC_WIDTH_16_BIT = 1,
  303. ASRC_WIDTH_8_BIT = 2,
  304. };
  305. struct asrc_config {
  306. enum asrc_pair_index pair;
  307. unsigned int channel_num;
  308. unsigned int buffer_num;
  309. unsigned int dma_buffer_size;
  310. unsigned int input_sample_rate;
  311. unsigned int output_sample_rate;
  312. enum asrc_word_width input_word_width;
  313. enum asrc_word_width output_word_width;
  314. enum asrc_inclk inclk;
  315. enum asrc_outclk outclk;
  316. };
  317. struct asrc_req {
  318. unsigned int chn_num;
  319. enum asrc_pair_index index;
  320. };
  321. struct asrc_querybuf {
  322. unsigned int buffer_index;
  323. unsigned int input_length;
  324. unsigned int output_length;
  325. unsigned long input_offset;
  326. unsigned long output_offset;
  327. };
  328. struct asrc_convert_buffer {
  329. void *input_buffer_vaddr;
  330. void *output_buffer_vaddr;
  331. unsigned int input_buffer_length;
  332. unsigned int output_buffer_length;
  333. };
  334. struct asrc_status_flags {
  335. enum asrc_pair_index index;
  336. unsigned int overload_error;
  337. };
  338. enum asrc_error_status {
  339. ASRC_TASK_Q_OVERLOAD = 0x01,
  340. ASRC_OUTPUT_TASK_OVERLOAD = 0x02,
  341. ASRC_INPUT_TASK_OVERLOAD = 0x04,
  342. ASRC_OUTPUT_BUFFER_OVERFLOW = 0x08,
  343. ASRC_INPUT_BUFFER_UNDERRUN = 0x10,
  344. };
  345. struct dma_block {
  346. dma_addr_t dma_paddr;
  347. void *dma_vaddr;
  348. unsigned int length;
  349. };
  350. /**
  351. * fsl_asrc_pair: ASRC Pair private data
  352. *
  353. * @asrc_priv: pointer to its parent module
  354. * @config: configuration profile
  355. * @error: error record
  356. * @index: pair index (ASRC_PAIR_A, ASRC_PAIR_B, ASRC_PAIR_C)
  357. * @channels: occupied channel number
  358. * @desc: input and output dma descriptors
  359. * @dma_chan: inputer and output DMA channels
  360. * @dma_data: private dma data
  361. * @pos: hardware pointer position
  362. * @private: pair private area
  363. */
  364. struct fsl_asrc_pair {
  365. struct fsl_asrc *asrc_priv;
  366. struct asrc_config *config;
  367. unsigned int error;
  368. enum asrc_pair_index index;
  369. unsigned int channels;
  370. struct dma_async_tx_descriptor *desc[2];
  371. struct dma_chan *dma_chan[2];
  372. struct imx_dma_data dma_data;
  373. unsigned int pos;
  374. void *private;
  375. };
  376. /**
  377. * fsl_asrc_pair: ASRC private data
  378. *
  379. * @dma_params_rx: DMA parameters for receive channel
  380. * @dma_params_tx: DMA parameters for transmit channel
  381. * @pdev: platform device pointer
  382. * @regmap: regmap handler
  383. * @paddr: physical address to the base address of registers
  384. * @mem_clk: clock source to access register
  385. * @ipg_clk: clock source to drive peripheral
  386. * @asrck_clk: clock sources to driver ASRC internal logic
  387. * @lock: spin lock for resource protection
  388. * @pair: pair pointers
  389. * @channel_bits: width of ASRCNCR register for each pair
  390. * @channel_avail: non-occupied channel numbers
  391. * @asrc_rate: default sample rate for ASoC Back-Ends
  392. * @asrc_width: default sample width for ASoC Back-Ends
  393. */
  394. struct fsl_asrc {
  395. struct snd_dmaengine_dai_dma_data dma_params_rx;
  396. struct snd_dmaengine_dai_dma_data dma_params_tx;
  397. struct platform_device *pdev;
  398. struct regmap *regmap;
  399. unsigned long paddr;
  400. struct clk *mem_clk;
  401. struct clk *ipg_clk;
  402. struct clk *asrck_clk[ASRC_CLK_MAX_NUM];
  403. spinlock_t lock;
  404. struct fsl_asrc_pair *pair[ASRC_PAIR_MAX_NUM];
  405. unsigned int channel_bits;
  406. unsigned int channel_avail;
  407. int asrc_rate;
  408. int asrc_width;
  409. };
  410. extern struct snd_soc_platform_driver fsl_asrc_platform;
  411. struct dma_chan *fsl_asrc_get_dma_channel(struct fsl_asrc_pair *pair, bool dir);
  412. #endif /* _FSL_ASRC_H */