x1000_aic.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /**
  2. ******************************************************************************
  3. * @file x1000_aic.h
  4. * @author Urey
  5. * @version V1.0.0
  6. * @date 2017Äê2ÔÂ20ÈÕ
  7. * @brief TODO
  8. ******************************************************************************
  9. **/
  10. #ifndef _X1000_AIC_H_
  11. #define _X1000_AIC_H_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #define AIC_FR (AIC_BASE + 0x00)
  16. #define AIC_CR (AIC_BASE + 0x04)
  17. #define AIC_ACCR1 (AIC_BASE + 0x08)
  18. #define AIC_ACCR2 (AIC_BASE + 0x0c)
  19. #define AIC_I2SCR (AIC_BASE + 0x10)
  20. #define AIC_SR (AIC_BASE + 0x14)
  21. #define AIC_ACSR (AIC_BASE + 0x18)
  22. #define AIC_I2SSR (AIC_BASE + 0x1c)
  23. #define AIC_ACCAR (AIC_BASE + 0x20)
  24. #define AIC_ACCDR (AIC_BASE + 0x24)
  25. #define AIC_ACSAR (AIC_BASE + 0x28)
  26. #define AIC_ACSDR (AIC_BASE + 0x2c)
  27. #define AIC_I2SDIV (AIC_BASE + 0x30)
  28. #define AIC_DR (AIC_BASE + 0x34)
  29. #define SPDIF_ENA (AIC_BASE + 0x80)
  30. #define SPDIF_CTRL (AIC_BASE + 0x84)
  31. #define SPDIF_STATE (AIC_BASE + 0x88)
  32. #define SPDIF_CFG1 (AIC_BASE + 0x8c)
  33. #define SPDIF_CFG2 (AIC_BASE + 0x90)
  34. #define SPDIF_FIFO (AIC_BASE + 0x94)
  35. #define ICDC_CKCFG (AIC_BASE + 0xa0)
  36. #define ICDC_RGADW (AIC_BASE + 0xa4)
  37. #define ICDC_RGDATA (AIC_BASE + 0xa8)
  38. /* AIC_FR definition */
  39. #define AIC_FR_RFTH_LSB 24
  40. #define AIC_FR_RFTH(x) ( ( (x)/2 - 1 ) << AIC_FR_RFTH_LSB) // 2, 4, ..., 32
  41. #define AIC_FR_RFTH_MASK BITS_H2L(27, AIC_FR_RFTH_LSB)
  42. #define AIC_FR_TFTH_LSB 16
  43. #define AIC_FR_TFTH(x) ( ( (x)/2 ) << AIC_FR_TFTH_LSB) // 2, 4, ..., 32
  44. #define AIC_FR_TFTH_MASK BITS_H2L(20, AIC_FR_TFTH_LSB)
  45. /* new@4770 */
  46. #define AIC_FR_IBCKD BIT10
  47. /* new@4770 */
  48. #define AIC_FR_ISYNCD BIT9
  49. /* new@4770 */
  50. #define IC_FR_DMODE BIT8
  51. #define AIC_FR_LSMP BIT6
  52. #define AIC_FR_ICDC BIT5
  53. #define AIC_FR_AUSEL BIT4
  54. #define AIC_FR_RST BIT3
  55. #define AIC_FR_BCKD BIT2
  56. #define AIC_FR_SYNCD BIT1
  57. #define AIC_FR_ENB BIT0
  58. /* AIC_CR definition */
  59. #define AIC_CR_PACK16 BIT28
  60. #define AIC_CR_CHANNEL_LSB 24
  61. #define AIC_CR_CHANNEL_MASK BITS_H2L(26, 24)
  62. #define AIC_CR_CHANNEL_MONO (0x0 << AIC_CR_CHANNEL_LSB)
  63. #define AIC_CR_CHANNEL_STEREO (0x1 << AIC_CR_CHANNEL_LSB)
  64. #define AIC_CR_CHANNEL_4CHNL (0x3 << AIC_CR_CHANNEL_LSB)
  65. #define AIC_CR_CHANNEL_6CHNL (0x5 << AIC_CR_CHANNEL_LSB)
  66. #define AIC_CR_CHANNEL_8CHNL (0x7 << AIC_CR_CHANNEL_LSB)
  67. #define AIC_CR_OSS_LSB 19
  68. #define AIC_CR_OSS_MASK BITS_H2L(21, AIC_CR_OSS_LSB)
  69. #define AIC_CR_OSS(n) (((n) > 18 ? (n)/6 : (n)/9) << AIC_CR_OSS_LSB) /* n = 8, 16, 18, 20, 24 */
  70. #define AIC_CR_ISS_LSB 16
  71. #define AIC_CR_ISS_MASK BITS_H2L(18, AIC_CR_ISS_LSB)
  72. #define AIC_CR_ISS(n) (((n) > 18 ? (n)/6 : (n)/9) << AIC_CR_ISS_LSB) /* n = 8, 16, 18, 20, 24 */
  73. #define AIC_CR_RDMS BIT15
  74. #define AIC_CR_TDMS BIT14
  75. #define AIC_CR_M2S BIT11
  76. #define AIC_CR_ENDSW BIT10
  77. #define AIC_CR_AVSTSU BIT9
  78. #define AIC_CR_TFLUSH BIT8
  79. #define AIC_CR_RFLUSH BIT7
  80. #define AIC_CR_EROR BIT6
  81. #define AIC_CR_ETUR BIT5
  82. #define AIC_CR_ERFS BIT4
  83. #define AIC_CR_ETFS BIT3
  84. #define AIC_CR_ENLBF BIT2
  85. #define AIC_CR_ERPL BIT1
  86. #define AIC_CR_EREC BIT0
  87. /* AIC controller AC-link control register 1(ACCR1) */
  88. #define AIC_ACCR1_RS_LSB 16
  89. #define AIC_ACCR1_RS_MASK BITS_H2L(25, AIC_ACCR1_RS_LSB)
  90. #define AIC_ACCR1_RS_SLOT(n) ((1 << ((n) - 3)) << AIC_ACCR1_RS_LSB) /* n = 3 .. 12 */
  91. #define AIC_ACCR1_XS_LSB 0
  92. #define AIC_ACCR1_XS_MASK BITS_H2L(9, AIC_ACCR1_XS_LSB)
  93. #define AIC_ACCR1_XS_SLOT(n) ((1 << ((n) - 3)) << AIC_ACCR1_XS_LSB) /* n = 3 .. 12 */
  94. /* AIC controller AC-link control register 2 (ACCR2) */
  95. #define AIC_ACCR2_ERSTO BIT18
  96. #define AIC_ACCR2_ESADR BIT17
  97. #define AIC_ACCR2_ECADT BIT16
  98. #define AIC_ACCR2_SO BIT3
  99. #define AIC_ACCR2_SR BIT2
  100. #define AIC_ACCR2_SS BIT1
  101. #define AIC_ACCR2_SA BIT0
  102. /* AIC controller i2s/msb-justified control register (I2SCR) */
  103. #define AIC_I2SCR_RFIRST BIT17
  104. #define AIC_I2SCR_SWLH BIT16
  105. #define AIC_I2SCR_ISTPBK BIT13
  106. #define AIC_I2SCR_STPBK BIT12
  107. #define AIC_I2SCR_ESCLK BIT4
  108. #define AIC_I2SCR_AMSL BIT0
  109. /* AIC controller FIFO status register (AICSR) */
  110. #define AIC_SR_RFL_LSB 24
  111. #define AIC_SR_RFL_MASK BITS_H2L(29, AIC_SR_RFL_LSB)
  112. #define AIC_SR_TFL_LSB 8
  113. #define AIC_SR_TFL_MASK BITS_H2L(13, AIC_SR_TFL_LSB)
  114. #define AIC_SR_ROR BIT6
  115. #define AIC_SR_TUR BIT5
  116. #define AIC_SR_RFS BIT4
  117. #define AIC_SR_TFS BIT3
  118. /* AIC controller AC-link status register (ACSR) */
  119. #define AIC_ACSR_SLTERR BIT21
  120. #define AIC_ACSR_CRDY BIT20
  121. #define AIC_ACSR_CLPM BIT19
  122. #define AIC_ACSR_RSTO BIT18
  123. #define AIC_ACSR_SADR BIT17
  124. #define AIC_ACSR_CADT BIT16
  125. /* AIC controller I2S/MSB-justified status register (I2SSR) */
  126. #define AIC_I2SSR_CHBSY BIT5
  127. #define AIC_I2SSR_TBSY BIT4
  128. #define AIC_I2SSR_RBSY BIT3
  129. #define AIC_I2SSR_BSY BIT2
  130. /* AIC controller AC97 codec command address register (ACCAR) */
  131. #define AIC_ACCAR_CAR_LSB 0
  132. #define AIC_ACCAR_CAR_MASK BITS_H2L(19, AIC_ACCAR_CAR_LSB)
  133. /* AIC controller AC97 codec command data register (ACCDR) */
  134. #define AIC_ACCDR_CDR_LSB 0
  135. #define AIC_ACCDR_CDR_MASK BITS_H2L(19, AIC_ACCDR_CDR_LSB)
  136. /* AC97 read and write macro based on ACCAR and ACCDR */
  137. #define AC97_READ_CMD BIT19
  138. #define AC97_WRITE_CMD (BIT19 & ~BIT19)
  139. #define AC97_INDEX_LSB 12
  140. #define AC97_INDEX_MASK BITS_H2L(18, AC97_INDEX_LSB)
  141. #define AC97_DATA_LSB 4
  142. #define AC97_DATA_MASK BITS_H2L(19, AC97_DATA_LSB)
  143. /* AIC controller AC97 codec status address register (ACSAR) */
  144. #define AIC_ACSAR_SAR_LSB 0
  145. #define AIC_ACSAR_SAR_MASK BITS_H2L(19, AIC_ACSAR_SAR_LSB)
  146. /* AIC controller AC97 codec status data register (ACSDR) */
  147. #define AIC_ACSDR_SDR_LSB 0
  148. #define AIC_ACSDR_SDR_MASK BITS_H2L(19, AIC_ACSDR_SDR_LSB)
  149. /* AIC controller I2S/MSB-justified clock divider register (I2SDIV) */
  150. #define AIC_I2SDIV_IDIV_LSB 16
  151. #define AIC_I2SDIV_IDIV_MASK BITS_H2L(24, AIC_I2SDIV_IDIV_LSB)
  152. #define AIC_I2SDIV_DIV_LSB 0
  153. #define AIC_I2SDIV_DIV_MASK BITS_H2L(8, AIC_I2SDIV_DIV_LSB)
  154. /* SPDIF enable register (SPDIF_ENA) */
  155. #define SPDIF_ENA_SPEN BIT0
  156. /* SPDIF control register (SPDIF_CTRL) */
  157. #define SPDIF_CTRL_DMAEN BIT15
  158. #define SPDIF_CTRL_DTYPE BIT14
  159. #define SPDIF_CTRL_SIGN BIT13
  160. #define SPDIF_CTRL_INVALID BIT12
  161. #define SPDIF_CTRL_RST BIT11
  162. #define SPDIF_CTRL_SPDIFI2S BIT10
  163. #define SPDIF_CTRL_MTRIG BIT1
  164. #define SPDIF_CTRL_MFFUR BIT0
  165. /* SPDIF state register (SPDIF_STAT) */
  166. #define SPDIF_STAT_BUSY BIT7
  167. #define SPDIF_STAT_FTRIG BIT1
  168. #define SPDIF_STAT_FUR BIT0
  169. #define SPDIF_STAT_FLVL_LSB 8
  170. #define SPDIF_STAT_FLVL_MASK BITS_H2L(14, SPDIF_STAT_FLVL_LSB)
  171. /* SPDIF configure 1 register (SPDIF_CFG1) */
  172. #define SPDIF_CFG1_INITLVL BIT17
  173. #define SPDIF_CFG1_ZROVLD BIT16
  174. #define SPDIF_CFG1_TRIG_LSB 12
  175. #define SPDIF_CFG1_TRIG_MASK BITS_H2L(13, SPDIF_CFG1_TRIG_LSB)
  176. #define SPDIF_CFG1_TRIG(n) (((n) > 16 ? 3 : (n)/8) << SPDIF_CFG1_TRIG_LSB) /* n = 4, 8, 16, 32 */
  177. #define SPDIF_CFG1_SRCNUM_LSB 8
  178. #define SPDIF_CFG1_SRCNUM_MASK BITS_H2L(11, SPDIF_CFG1_SRCNUM_LSB)
  179. #define SPDIF_CFG1_CH1NUM_LSB 4
  180. #define SPDIF_CFG1_CH1NUM_MASK BITS_H2L(7, SPDIF_CFG1_CH1NUM_LSB)
  181. #define SPDIF_CFG1_CH2NUM_LSB 0
  182. #define SPDIF_CFG1_CH2NUM_MASK BITS_H2L(3, SPDIF_CFG1_CH2NUM_LSB)
  183. /* SPDIF configure 2 register (SPDIF_CFG2) */
  184. #define SPDIF_CFG2_MAXWL BIT18
  185. #define SPDIF_CFG2_PRE BIT3
  186. #define SPDIF_CFG2_COPYN BIT2
  187. #define SPDIF_CFG2_AUDION BIT1
  188. #define SPDIF_CFG2_CONPRO BIT0
  189. #define SPDIF_CFG2_FS_LSB 26
  190. #define SPDIF_CFG2_FS_MASK BITS_H2L(29, SPDIF_CFG2_FS_LSB)
  191. #define SPDIF_CFG2_ORGFRQ_LSB 22
  192. #define SPDIF_CFG2_ORGFRQ_MASK BITS_H2L(25, SPDIF_CFG2_ORGFRQ_LSB)
  193. #define SPDIF_CFG2_SAMWL_LSB 19
  194. #define SPDIF_CFG2_SAMWL_MASK BITS_H2L(21, SPDIF_CFG2_SAMWL_LSB)
  195. #define SPDIF_CFG2_CLKACU_LSB 16
  196. #define SPDIF_CFG2_CLKACU_MASK BITS_H2L(17, SPDIF_CFG2_CLKACU_LSB)
  197. #define SPDIF_CFG2_CATCODE_LSB 8
  198. #define SPDIF_CFG2_CATCODE_MASK BITS_H2L(15, SPDIF_CFG2_CATCODE_LSB)
  199. #define SPDIF_CFG2_CHMD_LSB 6
  200. #define SPDIF_CFG2_CHMD_MASK BITS_H2L(7, SPDIF_CFG2_CHMD_LSB)
  201. /* ICDC internal register access control register(RGADW) */
  202. #define ICDC_RGADW_RGWR BIT16
  203. #define ICDC_RGADW_RGADDR_LSB 8
  204. #define ICDC_RGADW_RGADDR_MASK BITS_H2L(14, ICDC_RGADW_RGADDR_LSB)
  205. #define ICDC_RGADW_RGDIN_LSB 0
  206. #define ICDC_RGADW_RGDIN_MASK BITS_H2L(7, ICDC_RGADW_RGDIN_LSB)
  207. /* ICDC internal register data output register (RGDATA)*/
  208. #define ICDC_RGDATA_IRQ BIT8
  209. #define ICDC_RGDATA_RGDOUT_LSB 0
  210. #define ICDC_RGDATA_RGDOUT_MASK BITS_H2L(7, ICDC_RGDATA_RGDOUT_LSB)
  211. #ifndef __MIPS_ASSEMBLER
  212. #define REG_AIC_FR REG32(AIC_FR)
  213. #define REG_AIC0_FR REG32(AIC0_FR)
  214. #define REG_AIC_CR REG32(AIC_CR)
  215. #define REG_AIC_ACCR1 REG32(AIC_ACCR1)
  216. #define REG_AIC_ACCR2 REG32(AIC_ACCR2)
  217. #define REG_AIC_I2SCR REG32(AIC_I2SCR)
  218. #define REG_AIC_SR REG32(AIC_SR)
  219. #define REG_AIC_ACSR REG32(AIC_ACSR)
  220. #define REG_AIC_I2SSR REG32(AIC_I2SSR)
  221. #define REG_AIC_ACCAR REG32(AIC_ACCAR)
  222. #define REG_AIC_ACCDR REG32(AIC_ACCDR)
  223. #define REG_AIC_ACSAR REG32(AIC_ACSAR)
  224. #define REG_AIC_ACSDR REG32(AIC_ACSDR)
  225. #define REG_AIC_I2SDIV REG32(AIC_I2SDIV)
  226. #define REG_AIC_DR REG32(AIC_DR)
  227. #define REG_SPDIF_ENA REG32(SPDIF_ENA)
  228. #define REG_SPDIF_CTRL REG32(SPDIF_CTRL)
  229. #define REG_SPDIF_STATE REG32(SPDIF_STATE)
  230. #define REG_SPDIF_CFG1 REG32(SPDIF_CFG1)
  231. #define REG_SPDIF_CFG2 REG32(SPDIF_CFG2)
  232. #define REG_SPDIF_FIFO REG32(SPDIF_FIFO)
  233. #define REG_ICDC_RGADW REG32(ICDC_RGADW)
  234. #define REG_ICDC_RGDATA REG32(ICDC_RGDATA)
  235. #if 0
  236. #define __aic_enable() ( REG_AIC_FR |= AIC_FR_ENB )
  237. #define __aic_disable() ( REG_AIC_FR &= ~AIC_FR_ENB )
  238. #define __aic_select_ac97() ( REG_AIC_FR &= ~AIC_FR_AUSEL )
  239. #define __aic_select_i2s() ( REG_AIC_FR |= AIC_FR_AUSEL )
  240. #define __aic_play_zero() ( REG_AIC_FR &= ~AIC_FR_LSMP )
  241. #define __aic_play_lastsample() ( REG_AIC_FR |= AIC_FR_LSMP )
  242. #define __i2s_as_master() ( REG_AIC_FR |= AIC_FR_BCKD | AIC_FR_SYNCD )
  243. #define __i2s_as_slave() ( REG_AIC_FR &= ~(AIC_FR_BCKD | AIC_FR_SYNCD) )
  244. #define jz_aic_ibck_in (CLRREG32(AIC_FR, AIC_FR_IBCKD))
  245. #define jz_aic_ibck_out (SETREG32(AIC_FR, AIC_FR_IBCKD))
  246. #define jz_aic_isync_in (CLRREG32(AIC_FR, AIC_FR_ISYNCD))
  247. #define jz_aic_isync_out (SETREG32(AIC_FR, AIC_FR_ISYNCD))
  248. #define jz_aic_enable_dmode (SETREG32(AIC_FR, AIC_FR_DMODE))
  249. #define jz_aic_disable_dmode (CLRREG32(AIC_FR, AIC_FR_DMODE))
  250. #define __aic_reset_status() ( REG_AIC_FR & AIC_FR_RST )
  251. #define __aic_reset() \
  252. do { \
  253. REG_AIC_FR |= AIC_FR_RST; \
  254. } while(0)
  255. #define __aic_set_transmit_trigger(n) \
  256. do { \
  257. REG_AIC_FR &= ~AIC_FR_TFTH_MASK; \
  258. REG_AIC_FR |= ((n) << AIC_FR_TFTH_LSB); \
  259. } while(0)
  260. #define __aic_set_receive_trigger(n) \
  261. do { \
  262. REG_AIC_FR &= ~AIC_FR_RFTH_MASK; \
  263. REG_AIC_FR |= ((n) << AIC_FR_RFTH_LSB); \
  264. } while(0)
  265. #define __aic_enable_oldstyle()
  266. #define __aic_enable_newstyle()
  267. #define __aic_enable_pack16() ( REG_AIC_CR |= AIC_CR_PACK16 )
  268. #define __aic_enable_unpack16() ( REG_AIC_CR &= ~AIC_CR_PACK16)
  269. #define jz_aic_set_channel(n) \
  270. do { \
  271. switch((n)) { \
  272. case 1: \
  273. case 2: \
  274. case 4: \
  275. case 6: \
  276. case 8: \
  277. CLRREG32(AIC_CR, AIC_CR_CHANNEL_MASK); \
  278. SETREG32(AIC_CR, ((((n) - 1) << 24) & AIC_CR_CHANNEL_MASK)); \
  279. break; \
  280. default: \
  281. printk("invalid aic channel, must be 1, 2, 4, 6, or 8\n"); \
  282. break; \
  283. } \
  284. } while(0)
  285. /* n = AIC_CR_CHANNEL_MONO,AIC_CR_CHANNEL_STEREO ... */
  286. #define __aic_out_channel_select(n) \
  287. do { \
  288. REG_AIC_CR &= ~AIC_CR_CHANNEL_MASK; \
  289. REG_AIC_CR |= ((n) << AIC_CR_CHANNEL_LSB ); \
  290. } while(0)
  291. #define __aic_enable_record() ( REG_AIC_CR |= AIC_CR_EREC )
  292. #define __aic_disable_record() ( REG_AIC_CR &= ~AIC_CR_EREC )
  293. #define __aic_enable_replay() ( REG_AIC_CR |= AIC_CR_ERPL )
  294. #define __aic_disable_replay() ( REG_AIC_CR &= ~AIC_CR_ERPL )
  295. #define __aic_enable_loopback() ( REG_AIC_CR |= AIC_CR_ENLBF )
  296. #define __aic_disable_loopback() ( REG_AIC_CR &= ~AIC_CR_ENLBF )
  297. #define __aic_flush_tfifo() ( REG_AIC_CR |= AIC_CR_TFLUSH )
  298. #define __aic_unflush_tfifo() ( REG_AIC_CR &= ~AIC_CR_TFLUSH )
  299. #define __aic_flush_rfifo() ( REG_AIC_CR |= AIC_CR_RFLUSH )
  300. #define __aic_unflush_rfifo() ( REG_AIC_CR &= ~AIC_CR_RFLUSH )
  301. #define __aic_enable_transmit_intr() \
  302. ( REG_AIC_CR |= (AIC_CR_ETFS | AIC_CR_ETUR) )
  303. #define __aic_disable_transmit_intr() \
  304. ( REG_AIC_CR &= ~(AIC_CR_ETFS | AIC_CR_ETUR) )
  305. #define __aic_enable_receive_intr() \
  306. ( REG_AIC_CR |= (AIC_CR_ERFS | AIC_CR_EROR) )
  307. #define __aic_disable_receive_intr() \
  308. ( REG_AIC_CR &= ~(AIC_CR_ERFS | AIC_CR_EROR) )
  309. #define __aic_enable_transmit_dma() ( REG_AIC_CR |= AIC_CR_TDMS )
  310. #define __aic_disable_transmit_dma() ( REG_AIC_CR &= ~AIC_CR_TDMS )
  311. #define __aic_enable_receive_dma() ( REG_AIC_CR |= AIC_CR_RDMS )
  312. #define __aic_disable_receive_dma() ( REG_AIC_CR &= ~AIC_CR_RDMS )
  313. #define __aic_enable_mono2stereo() ( REG_AIC_CR |= AIC_CR_M2S )
  314. #define __aic_disable_mono2stereo() ( REG_AIC_CR &= ~AIC_CR_M2S )
  315. #define __aic_enable_byteswap() ( REG_AIC_CR |= AIC_CR_ENDSW )
  316. #define __aic_disable_byteswap() ( REG_AIC_CR &= ~AIC_CR_ENDSW )
  317. #define __aic_enable_unsignadj() ( REG_AIC_CR |= AIC_CR_AVSTSU )
  318. #define __aic_disable_unsignadj() ( REG_AIC_CR &= ~AIC_CR_AVSTSU )
  319. #define AC97_PCM_XS_L_FRONT AIC_ACCR1_XS_SLOT(3)
  320. #define AC97_PCM_XS_R_FRONT AIC_ACCR1_XS_SLOT(4)
  321. #define AC97_PCM_XS_CENTER AIC_ACCR1_XS_SLOT(6)
  322. #define AC97_PCM_XS_L_SURR AIC_ACCR1_XS_SLOT(7)
  323. #define AC97_PCM_XS_R_SURR AIC_ACCR1_XS_SLOT(8)
  324. #define AC97_PCM_XS_LFE AIC_ACCR1_XS_SLOT(9)
  325. #define AC97_PCM_RS_L_FRONT AIC_ACCR1_RS_SLOT(3)
  326. #define AC97_PCM_RS_R_FRONT AIC_ACCR1_RS_SLOT(4)
  327. #define AC97_PCM_RS_CENTER AIC_ACCR1_RS_SLOT(6)
  328. #define AC97_PCM_RS_L_SURR AIC_ACCR1_RS_SLOT(7)
  329. #define AC97_PCM_RS_R_SURR AIC_ACCR1_RS_SLOT(8)
  330. #define AC97_PCM_RS_LFE AIC_ACCR1_RS_SLOT(9)
  331. #define __ac97_set_xs_none() ( REG_AIC_ACCR1 &= ~AIC_ACCR1_XS_MASK )
  332. #define __ac97_set_xs_mono() \
  333. do { \
  334. REG_AIC_ACCR1 &= ~AIC_ACCR1_XS_MASK; \
  335. REG_AIC_ACCR1 |= AC97_PCM_XS_R_FRONT; \
  336. } while(0)
  337. #define __ac97_set_xs_stereo() \
  338. do { \
  339. REG_AIC_ACCR1 &= ~AIC_ACCR1_XS_MASK; \
  340. REG_AIC_ACCR1 |= AC97_PCM_XS_L_FRONT | AC97_PCM_XS_R_FRONT; \
  341. } while(0)
  342. /* In fact, only stereo is support now. */
  343. #define __ac97_set_rs_none() ( REG_AIC_ACCR1 &= ~AIC_ACCR1_RS_MASK )
  344. #define __ac97_set_rs_mono() \
  345. do { \
  346. REG_AIC_ACCR1 &= ~AIC_ACCR1_RS_MASK; \
  347. REG_AIC_ACCR1 |= AC97_PCM_RS_R_FRONT; \
  348. } while(0)
  349. #define __ac97_set_rs_stereo() \
  350. do { \
  351. REG_AIC_ACCR1 &= ~AIC_ACCR1_RS_MASK; \
  352. REG_AIC_ACCR1 |= AC97_PCM_RS_L_FRONT | AC97_PCM_RS_R_FRONT; \
  353. } while(0)
  354. #define __ac97_warm_reset_codec() \
  355. do { \
  356. REG_AIC_ACCR2 |= AIC_ACCR2_SA; \
  357. REG_AIC_ACCR2 |= AIC_ACCR2_SS; \
  358. udelay(2); \
  359. REG_AIC_ACCR2 &= ~AIC_ACCR2_SS; \
  360. REG_AIC_ACCR2 &= ~AIC_ACCR2_SA; \
  361. } while (0)
  362. #define __ac97_cold_reset_codec() \
  363. do { \
  364. REG_AIC_ACCR2 |= AIC_ACCR2_SR; \
  365. udelay(2); \
  366. REG_AIC_ACCR2 &= ~AIC_ACCR2_SR; \
  367. } while (0)
  368. /* n=8,16,18,20 */
  369. #define __ac97_set_iass(n) \
  370. ( REG_AIC_ACCR2 = (REG_AIC_ACCR2 & ~AIC_ACCR2_IASS_MASK) | AIC_ACCR2_IASS_##n##BIT )
  371. #define __ac97_set_oass(n) \
  372. ( REG_AIC_ACCR2 = (REG_AIC_ACCR2 & ~AIC_ACCR2_OASS_MASK) | AIC_ACCR2_OASS_##n##BIT )
  373. /* This bit should only be set in 2 channels configuration */
  374. #define __i2s_send_rfirst() ( REG_AIC_I2SCR |= AIC_I2SCR_RFIRST ) /* RL */
  375. #define __i2s_send_lfirst() ( REG_AIC_I2SCR &= ~AIC_I2SCR_RFIRST ) /* LR */
  376. /* This bit should only be set in 2 channels configuration and 16bit-packed mode */
  377. #define __i2s_switch_lr() ( REG_AIC_I2SCR |= AIC_I2SCR_SWLH )
  378. #define __i2s_unswitch_lr() ( REG_AIC_I2SCR &= ~AIC_I2SCR_SWLH )
  379. #define __i2s_select_i2s() ( REG_AIC_I2SCR &= ~AIC_I2SCR_AMSL )
  380. #define __i2s_select_msbjustified() ( REG_AIC_I2SCR |= AIC_I2SCR_AMSL )
  381. /* n=8,16,18,20,24 */
  382. /*#define __i2s_set_sample_size(n) \
  383. ( REG_AIC_I2SCR |= (REG_AIC_I2SCR & ~AIC_I2SCR_WL_MASK) | AIC_I2SCR_WL_##n##BIT )*/
  384. #define __i2s_out_channel_select(n) __aic_out_channel_select(n)
  385. #define __i2s_set_oss_sample_size(n) \
  386. ( REG_AIC_CR = (REG_AIC_CR & ~AIC_CR_OSS_MASK) | AIC_CR_OSS(n))
  387. #define __i2s_set_iss_sample_size(n) \
  388. ( REG_AIC_CR = (REG_AIC_CR & ~AIC_CR_ISS_MASK) | AIC_CR_ISS(n))
  389. #define __i2s_stop_bitclk() ( REG_AIC_I2SCR |= AIC_I2SCR_STPBK )
  390. #define __i2s_start_bitclk() ( REG_AIC_I2SCR &= ~AIC_I2SCR_STPBK )
  391. #define __i2s_stop_ibitclk() ( REG_AIC_I2SCR |= AIC_I2SCR_ISTPBK )
  392. #define __i2s_start_ibitclk() ( REG_AIC_I2SCR &= ~AIC_I2SCR_ISTPBK )
  393. #define __aic_transmit_request() ( REG_AIC_SR & AIC_SR_TFS )
  394. #define __aic_receive_request() ( REG_AIC_SR & AIC_SR_RFS )
  395. #define __aic_transmit_underrun() ( REG_AIC_SR & AIC_SR_TUR )
  396. #define __aic_receive_overrun() ( REG_AIC_SR & AIC_SR_ROR )
  397. #define __aic_clear_errors() ( REG_AIC_SR &= ~(AIC_SR_TUR | AIC_SR_ROR) )
  398. #define __aic_get_transmit_resident() \
  399. ( (REG_AIC_SR & AIC_SR_TFL_MASK) >> AIC_SR_TFL_LSB )
  400. #define __aic_get_receive_count() \
  401. ( (REG_AIC_SR & AIC_SR_RFL_MASK) >> AIC_SR_RFL_LSB )
  402. #define __ac97_command_transmitted() ( REG_AIC_ACSR & AIC_ACSR_CADT )
  403. #define __ac97_status_received() ( REG_AIC_ACSR & AIC_ACSR_SADR )
  404. #define __ac97_status_receive_timeout() ( REG_AIC_ACSR & AIC_ACSR_RSTO )
  405. #define __ac97_codec_is_low_power_mode() ( REG_AIC_ACSR & AIC_ACSR_CLPM )
  406. #define __ac97_codec_is_ready() ( REG_AIC_ACSR & AIC_ACSR_CRDY )
  407. #define __ac97_slot_error_detected() ( REG_AIC_ACSR & AIC_ACSR_SLTERR )
  408. #define __ac97_clear_slot_error() ( REG_AIC_ACSR &= ~AIC_ACSR_SLTERR )
  409. #define __i2s_is_busy() ( REG_AIC_I2SSR & AIC_I2SSR_BSY )
  410. #define __ac97_out_rcmd_addr(reg) \
  411. do { \
  412. REG_AIC_ACCAR = AC97_READ_CMD | ((reg) << AC97_INDEX_LSB); \
  413. } while (0)
  414. #define __ac97_out_wcmd_addr(reg) \
  415. do { \
  416. REG_AIC_ACCAR = AC97_WRITE_CMD | ((reg) << AC97_INDEX_LSB); \
  417. } while (0)
  418. #define __ac97_out_data(value) \
  419. do { \
  420. REG_AIC_ACCDR = ((value) << AC97_DATA_LSB); \
  421. } while (0)
  422. #define __ac97_in_data() \
  423. ( (REG_AIC_ACSDR & CODEC_REG_DATA_MASK) >> AC97_DATA_LSB )
  424. #define __ac97_in_status_addr() \
  425. ( (REG_AIC_ACSAR & AC97_INDEX_MASK) >> AC97_INDEX_LSB )
  426. #define __i2s_set_sample_rate(i2sclk, sync) \
  427. ( REG_AIC_I2SDIV = ((i2sclk) / (4*64)) / (sync) )
  428. #define __aic_write_tfifo(v) ( REG_AIC_DR = (v) )
  429. #define __aic_read_rfifo() ( REG_AIC_DR )
  430. #define __aic_internal_codec() ( REG_AIC_FR |= AIC_FR_ICDC )
  431. #define __aic_external_codec() ( REG_AIC_FR &= ~AIC_FR_ICDC )
  432. #define __aic0_internal_codec() ( REG_AIC0_FR |= AIC_FR_ICDC )
  433. #define __aic0_external_codec() ( REG_AIC0_FR &= ~AIC_FR_ICDC )
  434. //
  435. // Define next ops for AC97 compatible
  436. //
  437. #define AC97_ACSR AIC_ACSR
  438. #define __ac97_enable() __aic_enable(); __aic_select_ac97()
  439. #define __ac97_disable() __aic_disable()
  440. #define __ac97_reset() __aic_reset()
  441. #define __ac97_set_transmit_trigger(n) __aic_set_transmit_trigger(n)
  442. #define __ac97_set_receive_trigger(n) __aic_set_receive_trigger(n)
  443. #define __ac97_enable_record() __aic_enable_record()
  444. #define __ac97_disable_record() __aic_disable_record()
  445. #define __ac97_enable_replay() __aic_enable_replay()
  446. #define __ac97_disable_replay() __aic_disable_replay()
  447. #define __ac97_enable_loopback() __aic_enable_loopback()
  448. #define __ac97_disable_loopback() __aic_disable_loopback()
  449. #define __ac97_enable_transmit_dma() __aic_enable_transmit_dma()
  450. #define __ac97_disable_transmit_dma() __aic_disable_transmit_dma()
  451. #define __ac97_enable_receive_dma() __aic_enable_receive_dma()
  452. #define __ac97_disable_receive_dma() __aic_disable_receive_dma()
  453. #define __ac97_transmit_request() __aic_transmit_request()
  454. #define __ac97_receive_request() __aic_receive_request()
  455. #define __ac97_transmit_underrun() __aic_transmit_underrun()
  456. #define __ac97_receive_overrun() __aic_receive_overrun()
  457. #define __ac97_clear_errors() __aic_clear_errors()
  458. #define __ac97_get_transmit_resident() __aic_get_transmit_resident()
  459. #define __ac97_get_receive_count() __aic_get_receive_count()
  460. #define __ac97_enable_transmit_intr() __aic_enable_transmit_intr()
  461. #define __ac97_disable_transmit_intr() __aic_disable_transmit_intr()
  462. #define __ac97_enable_receive_intr() __aic_enable_receive_intr()
  463. #define __ac97_disable_receive_intr() __aic_disable_receive_intr()
  464. #define __ac97_write_tfifo(v) __aic_write_tfifo(v)
  465. #define __ac97_read_rfifo() __aic_read_rfifo()
  466. //
  467. // Define next ops for I2S compatible
  468. //
  469. #define I2S_ACSR AIC_I2SSR
  470. #define __i2s_enable() __aic_enable(); __aic_select_i2s()
  471. #define __i2s_disable() __aic_disable()
  472. #define __i2s_reset() __aic_reset()
  473. #define __i2s_set_transmit_trigger(n) __aic_set_transmit_trigger(n)
  474. #define __i2s_set_receive_trigger(n) __aic_set_receive_trigger(n)
  475. #define __i2s_enable_record() __aic_enable_record()
  476. #define __i2s_disable_record() __aic_disable_record()
  477. #define __i2s_enable_replay() __aic_enable_replay()
  478. #define __i2s_disable_replay() __aic_disable_replay()
  479. #define __i2s_enable_loopback() __aic_enable_loopback()
  480. #define __i2s_disable_loopback() __aic_disable_loopback()
  481. #define __i2s_enable_transmit_dma() __aic_enable_transmit_dma()
  482. #define __i2s_disable_transmit_dma() __aic_disable_transmit_dma()
  483. #define __i2s_enable_receive_dma() __aic_enable_receive_dma()
  484. #define __i2s_disable_receive_dma() __aic_disable_receive_dma()
  485. #define __i2s_transmit_request() __aic_transmit_request()
  486. #define __i2s_receive_request() __aic_receive_request()
  487. #define __i2s_transmit_underrun() __aic_transmit_underrun()
  488. #define __i2s_receive_overrun() __aic_receive_overrun()
  489. #define __i2s_clear_errors() __aic_clear_errors()
  490. #define __i2s_get_transmit_resident() __aic_get_transmit_resident()
  491. #define __i2s_get_receive_count() __aic_get_receive_count()
  492. #define __i2s_enable_transmit_intr() __aic_enable_transmit_intr()
  493. #define __i2s_disable_transmit_intr() __aic_disable_transmit_intr()
  494. #define __i2s_enable_receive_intr() __aic_enable_receive_intr()
  495. #define __i2s_disable_receive_intr() __aic_disable_receive_intr()
  496. #define __i2s_write_tfifo(v) __aic_write_tfifo(v)
  497. #define __i2s_read_rfifo() __aic_read_rfifo()
  498. #define __i2s_reset_codec() \
  499. do { \
  500. } while (0)
  501. /*************************************************************************
  502. * SPDIF INTERFACE in AIC Controller
  503. *************************************************************************/
  504. #define __spdif_enable() ( REG_SPDIF_ENA |= SPDIF_ENA_SPEN )
  505. #define __spdif_disable() ( REG_SPDIF_ENA &= ~SPDIF_ENA_SPEN )
  506. #define __spdif_enable_transmit_dma() ( REG_SPDIF_CTRL |= SPDIF_CTRL_DMAEN )
  507. #define __spdif_disable_transmit_dma() ( REG_SPDIF_CTRL &= ~SPDIF_CTRL_DMAEN )
  508. #define __spdif_enable_dtype() ( REG_SPDIF_CTRL |= SPDIF_CTRL_DTYPE )
  509. #define __spdif_disable_dtype() ( REG_SPDIF_CTRL &= ~SPDIF_CTRL_DTYPE )
  510. #define __spdif_enable_sign() ( REG_SPDIF_CTRL |= SPDIF_CTRL_SIGN )
  511. #define __spdif_disable_sign() ( REG_SPDIF_CTRL &= ~SPDIF_CTRL_SIGN )
  512. #define __spdif_enable_invalid() ( REG_SPDIF_CTRL |= SPDIF_CTRL_INVALID )
  513. #define __spdif_disable_invalid() ( REG_SPDIF_CTRL &= ~SPDIF_CTRL_INVALID )
  514. #define __spdif_enable_reset() ( REG_SPDIF_CTRL |= SPDIF_CTRL_RST )
  515. #define __spdif_select_spdif() ( REG_SPDIF_CTRL |= SPDIF_CTRL_SPDIFI2S )
  516. #define __spdif_select_i2s() ( REG_SPDIF_CTRL &= ~SPDIF_CTRL_SPDIFI2S )
  517. #define __spdif_enable_MTRIGmask() ( REG_SPDIF_CTRL |= SPDIF_CTRL_MTRIG )
  518. #define __spdif_disable_MTRIGmask() ( REG_SPDIF_CTRL &= ~SPDIF_CTRL_MTRIG )
  519. #define __spdif_enable_MFFURmask() ( REG_SPDIF_CTRL |= SPDIF_CTRL_MFFUR )
  520. #define __spdif_disable_MFFURmask() ( REG_SPDIF_CTRL &= ~SPDIF_CTRL_MFFUR )
  521. #define __spdif_enable_initlvl_high() ( REG_SPDIF_CFG1 |= SPDIF_CFG1_INITLVL )
  522. #define __spdif_enable_initlvl_low() ( REG_SPDIF_CFG1 &= ~SPDIF_CFG1_INITLVL )
  523. #define __spdif_enable_zrovld_invald() ( REG_SPDIF_CFG1 |= SPDIF_CFG1_ZROVLD )
  524. #define __spdif_enable_zrovld_vald() ( REG_SPDIF_CFG1 &= ~SPDIF_CFG1_ZROVLD )
  525. /* 0, 1, 2, 3 */
  526. #define __spdif_set_transmit_trigger(n) \
  527. do { \
  528. REG_SPDIF_CFG1 &= ~SPDIF_CFG1_TRIG_MASK; \
  529. REG_SPDIF_CFG1 |= SPDIF_CFG1_TRIG(n); \
  530. } while(0)
  531. /* 1 ~ 15 */
  532. #define __spdif_set_srcnum(n) \
  533. do { \
  534. REG_SPDIF_CFG1 &= ~SPDIF_CFG1_SRCNUM_MASK; \
  535. REG_SPDIF_CFG1 |= ((n) << SPDIF_CFG1_SRCNUM_LSB); \
  536. } while(0)
  537. /* 1 ~ 15 */
  538. #define __spdif_set_ch1num(n) \
  539. do { \
  540. REG_SPDIF_CFG1 &= ~SPDIF_CFG1_CH1NUM_MASK; \
  541. REG_SPDIF_CFG1 |= ((n) << SPDIF_CFG1_CH1NUM_LSB); \
  542. } while(0)
  543. /* 1 ~ 15 */
  544. #define __spdif_set_ch2num(n) \
  545. do { \
  546. REG_SPDIF_CFG1 &= ~SPDIF_CFG1_CH2NUM_MASK; \
  547. REG_SPDIF_CFG1 |= ((n) << SPDIF_CFG1_CH2NUM_LSB); \
  548. } while(0)
  549. /* 0x0, 0x2, 0x3, 0xa, 0xe */
  550. #define __spdif_set_fs(n) \
  551. do { \
  552. REG_SPDIF_CFG2 &= ~SPDIF_CFG2_FS_MASK; \
  553. REG_SPDIF_CFG2 |= ((n) << SPDIF_CFG2_FS_LSB); \
  554. } while(0)
  555. /* 0xd, 0xc, 0x5, 0x1 */
  556. #define __spdif_set_orgfrq(n) \
  557. do { \
  558. REG_SPDIF_CFG2 &= ~SPDIF_CFG2_ORGFRQ_MASK; \
  559. REG_SPDIF_CFG2 |= ((n) << SPDIF_CFG2_ORGFRQ_LSB); \
  560. } while(0)
  561. /* 0x1, 0x6, 0x2, 0x4, 0x5 */
  562. #define __spdif_set_samwl(n) \
  563. do { \
  564. REG_SPDIF_CFG2 &= ~SPDIF_CFG2_SAMWL_MASK; \
  565. REG_SPDIF_CFG2 |= ((n) << SPDIF_CFG2_SAMWL_LSB); \
  566. } while(0)
  567. #define __spdif_enable_samwl_24() ( REG_SPDIF_CFG2 |= SPDIF_CFG2_MAXWL )
  568. #define __spdif_enable_samwl_20() ( REG_SPDIF_CFG1 &= ~SPDIF_CFG2_MAXWL )
  569. /* 0x1, 0x1, 0x2, 0x3 */
  570. #define __spdif_set_clkacu(n) \
  571. do { \
  572. REG_SPDIF_CFG2 &= ~SPDIF_CFG2_CLKACU_MASK; \
  573. REG_SPDIF_CFG2 |= ((n) << SPDIF_CFG2_CLKACU_LSB); \
  574. } while(0)
  575. /* see IEC60958-3 */
  576. #define __spdif_set_catcode(n) \
  577. do { \
  578. REG_SPDIF_CFG2 &= ~SPDIF_CFG2_CATCODE_MASK; \
  579. REG_SPDIF_CFG2 |= ((n) << SPDIF_CFG2_CATCODE_LSB); \
  580. } while(0)
  581. /* n = 0x0, */
  582. #define __spdif_set_chmode(n) \
  583. do { \
  584. REG_SPDIF_CFG2 &= ~SPDIF_CFG2_CHMD_MASK; \
  585. REG_SPDIF_CFG2 |= ((n) << SPDIF_CFG2_CHMD_LSB); \
  586. } while(0)
  587. #define __spdif_enable_pre() ( REG_SPDIF_CFG2 |= SPDIF_CFG2_PRE )
  588. #define __spdif_disable_pre() ( REG_SPDIF_CFG2 &= ~SPDIF_CFG2_PRE )
  589. #define __spdif_enable_copyn() ( REG_SPDIF_CFG2 |= SPDIF_CFG2_COPYN )
  590. #define __spdif_disable_copyn() ( REG_SPDIF_CFG2 &= ~SPDIF_CFG2_COPYN )
  591. /* audio sample word represents linear PCM samples */
  592. #define __spdif_enable_audion() ( REG_SPDIF_CFG2 &= ~SPDIF_CFG2_AUDION )
  593. /* udio sample word used for other purpose */
  594. #define __spdif_disable_audion() ( REG_SPDIF_CFG2 |= SPDIF_CFG2_AUDION )
  595. #define __spdif_enable_conpro() ( REG_SPDIF_CFG2 &= ~SPDIF_CFG2_CONPRO )
  596. #define __spdif_disable_conpro() ( REG_SPDIF_CFG2 |= SPDIF_CFG2_CONPRO )
  597. /***************************************************************************
  598. * ICDC
  599. ***************************************************************************/
  600. #define __i2s_internal_codec() __aic_internal_codec()
  601. #define __i2s_external_codec() __aic_external_codec()
  602. #define __icdc_clk_ready() ( REG_ICDC_CKCFG & ICDC_CKCFG_CKRDY )
  603. #define __icdc_sel_adc() ( REG_ICDC_CKCFG |= ICDC_CKCFG_SELAD )
  604. #define __icdc_sel_dac() ( REG_ICDC_CKCFG &= ~ICDC_CKCFG_SELAD )
  605. #define __icdc_set_rgwr() ( REG_ICDC_RGADW |= ICDC_RGADW_RGWR )
  606. #define __icdc_clear_rgwr() ( REG_ICDC_RGADW &= ~ICDC_RGADW_RGWR )
  607. #define __icdc_rgwr_ready() ( REG_ICDC_RGADW & ICDC_RGADW_RGWR )
  608. #define AIC_RW_CODEC_START() while (INREG32(ICDC_RGADW) & ICDC_RGADW_RGWR)
  609. #define AIC_RW_CODEC_STOP() while (INREG32(ICDC_RGADW) & ICDC_RGADW_RGWR)
  610. #define __icdc_set_addr(n) \
  611. do { \
  612. REG_ICDC_RGADW &= ~ICDC_RGADW_RGADDR_MASK; \
  613. REG_ICDC_RGADW |= (n) << ICDC_RGADW_RGADDR_LSB; \
  614. } while(0)
  615. #define __icdc_set_cmd(n) \
  616. do { \
  617. REG_ICDC_RGADW &= ~ICDC_RGADW_RGDIN_MASK; \
  618. REG_ICDC_RGADW |= (n) << ICDC_RGADW_RGDIN_LSB; \
  619. } while(0)
  620. #define __icdc_irq_pending() ( REG_ICDC_RGDATA & ICDC_RGDATA_IRQ )
  621. #define __icdc_get_value() ( REG_ICDC_RGDATA & ICDC_RGDATA_RGDOUT_MASK )
  622. #endif /* __MIPS_ASSEMBLER */
  623. #endif
  624. #ifdef __cplusplus
  625. }
  626. #endif
  627. #endif /* _X1000_AIC_H_ */