drv_aic.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * File : drv_i2s.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2012, 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. * 2015-11-19 Urey the first version
  23. */
  24. #ifndef _DRV_I2S_H_
  25. #define _DRV_I2S_H_
  26. /*********************************************************************************************************
  27. ** 头文件
  28. *********************************************************************************************************/
  29. #include "x1000.h"
  30. #include "drv_clock.h"
  31. #include "drv_dma.h"
  32. /*********************************************************************************************************
  33. ** CODEC 配置
  34. *********************************************************************************************************/
  35. #define JZ_I2S_USE_INNER_CODEC
  36. #undef JZ_I2S_USE_EX_CODEC
  37. /*********************************************************************************************************
  38. ** AIC 数据结构
  39. *********************************************************************************************************/
  40. enum aic_mode {
  41. AIC_NO_MODE = 0,
  42. AIC_I2S_MODE,
  43. AIC_SPDIF_MODE,
  44. AIC_AC97_MODE
  45. };
  46. struct jz_aic_device;
  47. struct jz_aic
  48. {
  49. struct rt_device parent;
  50. uint32_t base;
  51. struct clk *clk;
  52. struct clk *clk_gate;
  53. uint32_t clk_rate;
  54. /* for interrupt */
  55. int irqno;
  56. int irqflags;
  57. uint32_t ror; /*counter for debug*/
  58. uint32_t tur;
  59. uint32_t mask;
  60. /* for AIC work mode protect */
  61. enum aic_mode aic_working_mode;
  62. /* for sub device */
  63. uint32_t dma_addr;
  64. struct jz_aic_device *aic_dev;
  65. };
  66. struct jz_aic_device
  67. {
  68. struct rt_device parent;
  69. };
  70. /*********************************************************************************************************
  71. ** AIC 指令
  72. *********************************************************************************************************/
  73. #define AIC_CMD_SET_MODE 0x20
  74. #define AIC_CMD_SET_RATE 0x21
  75. #define AIC_CMD_SET_SUBDEV 0x22
  76. /*********************************************************************************************************
  77. ** AIC 寄存器操作
  78. ***********************************************************************************************************/
  79. static void inline jz_aic_write_reg(struct jz_aic *aic,uint32_t reg, uint32_t val)
  80. {
  81. writel(val, aic->base + reg);
  82. }
  83. static uint32_t inline jz_aic_read_reg(struct jz_aic *aic,uint32_t reg)
  84. {
  85. return readl(aic->base + reg);
  86. }
  87. /* For AC97 and I2S */
  88. #define AICFR (0x00)
  89. #define AICCR (0x04)
  90. #define ACCR1 (0x08)
  91. #define ACCR2 (0x0c)
  92. #define I2SCR (0x10)
  93. #define AICSR (0x14)
  94. #define ACSR (0x18)
  95. #define I2SSR (0x1c)
  96. #define ACCAR (0x20)
  97. #define ACCDR (0x24)
  98. #define ACSAR (0x28)
  99. #define ACSDR (0x2c)
  100. #define I2SDIV (0x30)
  101. #define AICDR (0x34)
  102. /* For SPDIF */
  103. #define SPENA (0x80)
  104. #define SPCTRL (0x84)
  105. #define SPSTATE (0x88)
  106. #define SPCFG1 (0x8c)
  107. #define SPCFG2 (0x90)
  108. #define SPFIFO (0x94)
  109. #define I2S_CPM_VALID 0xb0000070
  110. /* For AICFR */
  111. #define AICFR_ENB_BIT (0)
  112. #define AICFR_ENB_MASK (1 << AICFR_ENB_BIT)
  113. #define AICFR_SYNCD_BIT (1)
  114. #define AICFR_SYNCD_MASK (1 << AICFR_SYNCD_BIT)
  115. #define AICFR_BCKD_BIT (2)
  116. #define AICFR_BCKD_MASK (1 << AICFR_BCKD_BIT)
  117. #define AICFR_RST_BIT (3)
  118. #define AICFR_RST_MASK (1 << AICFR_RST_BIT)
  119. #define AICFR_AUSEL_BIT (4)
  120. #define AICFR_AUSEL_MASK (1 << AICFR_AUSEL_BIT)
  121. #define AICFR_ICDC_BIT (5)
  122. #define AICFR_ICDC_MASK (1 << AICFR_ICDC_BIT)
  123. #define AICFR_LSMP_BIT (6)
  124. #define AICFR_LSMP_MASK (1 << AICFR_LSMP_BIT)
  125. #define AICFR_CDC_SLV_BIT (7)
  126. #define AICFR_CDC_SLV_MASK (1 << AICFR_CDC_SLV_BIT)
  127. #define AICFR_DMODE_BIT (8)
  128. #define AICFR_DMODE_MASK (1 << AICFR_DMODE_BIT)
  129. #define AICFR_ISYNCD_BIT (9)
  130. #define AICFR_ISYNCD_MASK (1 << AICFR_ISYNCD_BIT)
  131. #define AICFR_IBCKD_BIT (10)
  132. #define AICFR_IBCKD_MASK (1 << AICFR_IBCKD_BIT)
  133. #define AICFR_SYSCLKD_BIT (11)
  134. #define AICFR_SYSCLKD_MASK (1 << AICFR_SYSCLKD_BIT)
  135. #define AICFR_MSB_BIT (12)
  136. #define AICFR_MSB_MASK (1 << AICFR_MSB_BIT)
  137. #define AICFR_TFTH_BIT (16)
  138. #define AICFR_TFTH_MASK (0x1f << AICFR_TFTH_BIT)
  139. #define AICFR_RFTH_BIT (24)
  140. #define AICFR_RFTH_MASK (0x1f << AICFR_RFTH_BIT)
  141. /* For AICCR */
  142. #define AICCR_EREC_BIT (0)
  143. #define AICCR_EREC_MASK (1 << AICCR_EREC_BIT)
  144. #define AICCR_ERPL_BIT (1)
  145. #define AICCR_ERPL_MASK (1 << AICCR_ERPL_BIT)
  146. #define AICCR_ENLBF_BIT (2)
  147. #define AICCR_ENLBF_MASK (1 << AICCR_ENLBF_BIT)
  148. #define AICCR_ETFS_BIT (3)
  149. #define AICCR_ETFS_MASK (1 << AICCR_ETFS_BIT)
  150. #define AICCR_ERFS_BIT (4)
  151. #define AICCR_ERFS_MASK (1 << AICCR_ERFS_BIT)
  152. #define AICCR_ETUR_BIT (5)
  153. #define AICCR_ETUR_MASK (1 << AICCR_ETUR_BIT)
  154. #define AICCR_EROR_BIT (6)
  155. #define AICCR_EROR_MASK (1 << AICCR_EROR_BIT)
  156. #define AICCR_EALL_INT_MASK (AICCR_EROR_MASK|AICCR_ETUR_MASK|AICCR_ERFS_MASK|AICCR_ETFS_MASK)
  157. #define AICCR_RFLUSH_BIT (7)
  158. #define AICCR_RFLUSH_MASK (1 << AICCR_RFLUSH_BIT)
  159. #define AICCR_TFLUSH_BIT (8)
  160. #define AICCR_TFLUSH_MASK (1 << AICCR_TFLUSH_BIT)
  161. #define AICCR_ASVTSU_BIT (9)
  162. #define AICCR_ASVTSU_MASK (1 << AICCR_ASVTSU_BIT)
  163. #define AICCR_ENDSW_BIT (10)
  164. #define AICCR_ENDSW_MASK (1 << AICCR_ENDSW_BIT)
  165. #define AICCR_M2S_BIT (11)
  166. #define AICCR_M2S_MASK (1 << AICCR_M2S_BIT)
  167. #define AICCR_TDMS_BIT (14)
  168. #define AICCR_TDMS_MASK (1 << AICCR_TDMS_BIT)
  169. #define AICCR_RDMS_BIT (15)
  170. #define AICCR_RDMS_MASK (1 << AICCR_RDMS_BIT)
  171. #define AICCR_ISS_BIT (16)
  172. #define AICCR_ISS_MASK (0x7 << AICCR_ISS_BIT)
  173. #define AICCR_OSS_BIT (19)
  174. #define AICCR_OSS_MASK (0x7 << AICCR_OSS_BIT)
  175. #define AICCR_CHANNEL_BIT (24)
  176. #define AICCR_CHANNEL_MASK (0x7 << AICCR_CHANNEL_BIT)
  177. #define AICCR_PACK16_BIT (28)
  178. #define AICCR_PACK16_MASK (1 << AICCR_PACK16_BIT)
  179. /* For ACCR1 */
  180. #define ACCR1_XS_BIT (0)
  181. #define ACCR1_XS_MASK (0x3ff << ACCR1_XS_BIT)
  182. #define ACCR1_RS_BIT (16)
  183. #define ACCR1_RS_MASK (0x3ff << ACCR1_RS_BIT)
  184. /* For ACCR2 */
  185. #define ACCR2_SA_BIT (0)
  186. #define ACCR2_SA_MASK (1 << ACCR2_SA_BIT)
  187. #define ACCR2_SS_BIT (1)
  188. #define ACCR2_SS_MASK (1 << ACCR2_SS_BIT)
  189. #define ACCR2_SR_BIT (2)
  190. #define ACCR2_SR_MASK (1 << ACCR2_SR_BIT)
  191. #define ACCR2_SO_BIT (3)
  192. #define ACCR2_SO_MASK (1 << ACCR2_SO_BIT)
  193. #define ACCR2_ECADT_BIT (16)
  194. #define ACCR2_ECADT_MASK (1 << ACCR2_ECADT_BIT)
  195. #define ACCR2_ECADR_BIT (17)
  196. #define ACCR2_ECADR_MASK (1 << ACCR2_ECADR_BIT)
  197. #define ACCR2_ERSTO_BIT (18)
  198. #define ACCR2_ERSTO_MASK (1 << ACCR2_ERSTO_BIT)
  199. /* For I2SCR */
  200. #define I2SCR_AMSL_BIT (0)
  201. #define I2SCR_AMSL_MASK (1 << I2SCR_AMSL_BIT)
  202. #define I2SCR_ESCLK_BIT (4)
  203. #define I2SCR_ESCLK_MASK (1 << I2SCR_ESCLK_BIT)
  204. #define I2SCR_STPBK_BIT (12)
  205. #define I2SCR_STPBK_MASK (1 << I2SCR_STPBK_BIT)
  206. #define I2SCR_ISTPBK_BIT (13)
  207. #define I2SCR_ISTPBK_MASK (1 << I2SCR_ISTPBK_BIT)
  208. #define I2SCR_SWLH_BIT (16)
  209. #define I2SCR_SWLH_MASK (1 << I2SCR_SWLH_BIT)
  210. #define I2SCR_RFIRST_BIT (17)
  211. #define I2SCR_RFIRST_MASK (1 << I2SCR_RFIRST_BIT)
  212. /* For AICSR */
  213. #define AICSR_TFS_BIT (3)
  214. #define AICSR_TFS_MASK (1 << AICSR_TFS_BIT)
  215. #define AICSR_RFS_BIT (4)
  216. #define AICSR_RFS_MASK (1 << AICSR_RFS_BIT)
  217. #define AICSR_TUR_BIT (5)
  218. #define AICSR_TUR_MASK (1 << AICSR_TUR_BIT)
  219. #define AICSR_ROR_BIT (6)
  220. #define AICSR_ROR_MASK (1 << AICSR_ROR_BIT)
  221. #define AICSR_ALL_INT_MASK (AICSR_TFS_MASK|AICSR_RFS_MASK|AICSR_TUR_MASK|AICSR_ROR_MASK)
  222. #define AICSR_TFL_BIT (8)
  223. #define AICSR_TFL_MASK (0x3f << AICSR_TFL_BIT)
  224. #define AICSR_RFL_BIT (24)
  225. #define AICSR_RFL_MASK (0x3f << AICSR_RFL_BIT)
  226. /* For ACSR */
  227. #define ACSR_CADT_BIT (16)
  228. #define ACSR_CADT_MASK (1 << ACSR_CADT_BIT)
  229. #define ACSR_SADR_BIT (17)
  230. #define ACSR_SADR_MASK (1 << ACSR_SADR_BIT)
  231. #define ACSR_RSTO_BIT (18)
  232. #define ACSR_RSTO_MASK (1 << ACSR_RSTO_BIT)
  233. #define ACSR_CLPM_BIT (19)
  234. #define ACSR_CLPM_MASK (1 << ACSR_CLPM_BIT)
  235. #define ACSR_CRDY_BIT (20)
  236. #define ACSR_CRDY_MASK (1 << ACSR_CRDY_BIT)
  237. #define ACSR_SLTERR_BIT (21)
  238. #define ACSR_SLTERR_MASK (1 << ACSR_SLTERR_BIT)
  239. /* For I2SSR */
  240. #define I2SSR_BSY_BIT (2)
  241. #define I2SSR_BSY_MASK (1 << I2SSR_BSY_BIT)
  242. #define I2SSR_RBSY_BIT (3)
  243. #define I2SSR_RBSY_MASK (1 << I2SSR_RBSY_BIT)
  244. #define I2SSR_TBSY_BIT (4)
  245. #define I2SSR_TBSY_MASK (1 << I2SSR_TBSY_BIT)
  246. #define I2SSR_CHBSY_BIT (5)
  247. #define I2SSR_CHBSY_MASK (1 << I2SSR_CHBSY_BIT)
  248. /* For ACCAR */
  249. #define ACCAR_CAR_BIT (0)
  250. #define ACCAR_CAR_MASK (0xfffff << ACCAR_CAR_BIT)
  251. /* For ACCDR */
  252. #define ACCDR_CDR_BIT (0)
  253. #define ACCDR_CDR_MASK (0xfffff << ACCDR_CDR_BIT)
  254. /* For ACSAR */
  255. #define ACSAR_SAR_BIT (0)
  256. #define ACSAR_SAR_MASK (0xfffff << ACSAR_SAR_BIT)
  257. /* For ACSDR */
  258. #define ACSDR_SDR_BIT (0)
  259. #define ACSDR_SDR_MASK (0xfffff << ACSDR_SDR_BIT)
  260. /* For I2SDIV */
  261. #define I2SDIV_DV_BIT (0)
  262. #define I2SDIV_DV_MASK (0x1ff << I2SDIV_DV_BIT)
  263. #define I2SDIV_IDV_BIT (16)
  264. #define I2SDIV_IDV_MASK (0x1ff << I2SDIV_IDV_BIT)
  265. /* For AICDR */
  266. #define AICDR_DATA_BIT (0)
  267. #define AICDR_DATA_MASK (0xfffffff << AICDR_DATA_BIT)
  268. /* For SPENA */
  269. #define SPENA_SPEN_BIT (0)
  270. #define SPENA_SPEN_MASK (1 << SPENA_SPEN_BIT)
  271. /* For SPCTRL */
  272. #define SPCTRL_M_FFUR_BIT (0)
  273. #define SPCTRL_M_FFUR_MASK (1 << SPCTRL_M_FFUR_BIT)
  274. #define SPCTRL_M_TRIG_BIT (1)
  275. #define SPCTRL_M_TRIG_MASK (1 << SPCTRL_M_TRIG_BIT)
  276. #define SPCTRL_SPDIF_I2S_BIT (10)
  277. #define SPCTRL_SPDIF_I2S_MASK (1 << SPCTRL_SPDIF_I2S_BIT)
  278. #define SPCTRL_SFT_RST_BIT (11)
  279. #define SPCTRL_SFT_RST_MASK (1 << SPCTRL_SFT_RST_BIT)
  280. #define SPCTRL_INVALID_BIT (12)
  281. #define SPCTRL_INVALID_MASK (1 << SPCTRL_INVALID_BIT)
  282. #define SPCTRL_SIGN_N_BIT (13)
  283. #define SPCTRL_SIGN_N_MASK (1 << SPCTRL_SIGN_N_BIT)
  284. #define SPCTRL_D_TYPE_BIT (14)
  285. #define SPCTRL_D_TYPE_MASK (1 << SPCTRL_D_TYPE_BIT)
  286. #define SPCTRL_DMA_EN_BIT (15)
  287. #define SPCTRL_DMA_EN_MASK (1 << SPCTRL_DMA_EN_BIT)
  288. /* For SPSTATE */
  289. #define SPSTATE_F_FFUR_BIT (0)
  290. #define SPSTATE_F_FFUR_MASK (1 << SPSTATE_F_FFUR_BIT)
  291. #define SPSTATE_F_TRIG_BIT (1)
  292. #define SPSTATE_F_TRIG_MASK (1 << SPSTATE_F_TRIG_BIT)
  293. #define SPSTATE_BUSY_BIT (7)
  294. #define SPSTATE_BUSY_MASK (1 << SPSTATE_BUSY_BIT)
  295. #define SPSTATE_FIFO_LVL_BIT (8)
  296. #define SPSTATE_FIFO_LVL_MASK (0x7f << SPSTATE_FIFO_LVL_BIT)
  297. /* For SPCFG1 */
  298. #define SPCFG1_CH2_NUM_BIT (0)
  299. #define SPCFG1_CH2_NUM_MASK (0xf << SPCFG1_CH2_NUM_BIT)
  300. #define SPCFG1_CH1_NUM_BIT (4)
  301. #define SPCFG1_CH1_NUM_MASK (0xf << SPCFG1_CH1_NUM_BIT)
  302. #define SPCFG1_SRC_NUM_BIT (8)
  303. #define SPCFG1_SRC_NUM_MASK (0xf << SPCFG1_SRC_NUM_BIT)
  304. #define SPCFG1_TRIG_BIT (12)
  305. #define SPCFG1_TRIG_MASK (0x3 << SPCFG1_TRIG_BIT)
  306. #define SPCFG1_ZRO_VLD_BIT (16)
  307. #define SPCFG1_ZRO_VLD_MASK (1 << SPCFG1_ZRO_VLD_BIT)
  308. #define SPCFG1_INIT_LVL_BIT (17)
  309. #define SPCFG1_INIT_LVL_MASK (1 << SPCFG1_INIT_LVL_BIT)
  310. /* For SPCFG2 */
  311. #define SPCFG2_CON_PRO_BIT (0)
  312. #define SPCFG2_CON_PRO_MASK (1 << SPCFG2_CON_PRO_BIT)
  313. #define SPCFG2_AUDIO_N_BIT (1)
  314. #define SPCFG2_AUDIO_N_MASK (1 << SPCFG2_AUDIO_N_BIT)
  315. #define SPCFG2_COPY_N_BIT (2)
  316. #define SPCFG2_COPY_N_MASK (1 << SPCFG2_COPY_N_BIT)
  317. #define SPCFG2_PRE_BIT (3)
  318. #define SPCFG2_PRE_MASK (1 << SPCFG2_PRE_BIT)
  319. #define SPCFG2_CH_MD_BIT (6)
  320. #define SPCFG2_CH_MD_MASK (0x3 << SPCFG2_CH_MD_BIT)
  321. #define SPCFG2_CAT_CODE_BIT (8)
  322. #define SPCFG2_CAT_CODE_MASK (0xff << SPCFG2_CAT_CODE_BIT)
  323. #define SPCFG2_CLK_ACU_BIT (16)
  324. #define SPCFG2_CLK_ACU_MASK (0x3 << SPCFG2_CLK_ACU_BIT)
  325. #define SPCFG2_MAX_WL_BIT (18)
  326. #define SPCFG2_MAX_WL_MASK (1 << SPCFG2_MAX_WL_BIT)
  327. #define SPCFG2_SAMPL_WL_BIT (19)
  328. #define SPCFG2_SAMPL_WL_MASK (0x7 << SPCFG2_SAMPL_WL_BIT)
  329. #define SPCFG2_SAMPL_WL_20BITM (0x1 << SPCFG2_SAMPL_WL_BIT)
  330. #define SPCFG2_SAMPL_WL_21BIT (0x6 << SPCFG2_SAMPL_WL_BIT)
  331. #define SPCFG2_SAMPL_WL_22BIT (0x2 << SPCFG2_SAMPL_WL_BIT)
  332. #define SPCFG2_SAMPL_WL_23BIT (0x4 << SPCFG2_SAMPL_WL_BIT)
  333. #define SPCFG2_SAMPL_WL_24BIT (0x5 << SPCFG2_SAMPL_WL_BIT)
  334. #define SPCFG2_SAMPL_WL_16BIT (0x1 << SPCFG2_SAMPL_WL_BIT)
  335. #define SPCFG2_SAMPL_WL_17BIT (0x6 << SPCFG2_SAMPL_WL_BIT)
  336. #define SPCFG2_SAMPL_WL_18BIT (0x2 << SPCFG2_SAMPL_WL_BIT)
  337. #define SPCFG2_SAMPL_WL_19BIT (0x4 << SPCFG2_SAMPL_WL_BIT)
  338. #define SPCFG2_SAMPL_WL_20BITL (0x5 << SPCFG2_SAMPL_WL_BIT)
  339. #define SPCFG2_ORG_FRQ_BIT (22)
  340. #define SPCFG2_ORG_FRQ_MASK (0xf << SPCFG2_ORG_FRQ_BIT)
  341. #define SPCFG2_FS_BIT (26)
  342. #define SPCFG2_FS_MASK (0xf << SPCFG2_FS_BIT)
  343. #define SPFIFO_DATA_BIT (0)
  344. #define SPFIFO_DATA_MASK (0xffffff << SPFIFO_DATA_BIT)
  345. #define jz_aic_set_reg(parent, addr, val, mask, offset) \
  346. do { \
  347. volatile unsigned int reg_tmp; \
  348. reg_tmp = jz_aic_read_reg(parent, addr); \
  349. reg_tmp &= ~(mask); \
  350. reg_tmp |= (val << offset) & mask; \
  351. jz_aic_write_reg(parent, addr, reg_tmp); \
  352. } while(0)
  353. #define jz_aic_get_reg(parent, addr, mask, offset) \
  354. ((jz_aic_read_reg(parent, addr) & mask) >> offset)
  355. /*For ALL*/
  356. /*aic fr*/
  357. #define __aic_enable_msb(parent) \
  358. jz_aic_set_reg(parent, AICFR, 1, AICFR_MSB_MASK, AICFR_MSB_BIT)
  359. #define __aic_disable_msb(parent) \
  360. jz_aic_set_reg(parent, AICFR, 0, AICFR_MSB_MASK, AICFR_MSB_BIT)
  361. #define __aic_reset(parent) \
  362. jz_aic_set_reg(parent, AICFR, 1, AICFR_RST_MASK, AICFR_RST_BIT)
  363. /*aic cr*/
  364. #define __aic_flush_rxfifo(parent) \
  365. jz_aic_set_reg(parent, AICCR, 1, AICCR_RFLUSH_MASK, AICCR_RFLUSH_BIT)
  366. #define __aic_flush_txfifo(parent) \
  367. jz_aic_set_reg(parent, AICCR, 1, AICCR_TFLUSH_MASK, AICCR_TFLUSH_BIT)
  368. #define __aic_en_ror_int(parent) \
  369. jz_aic_set_reg(parent, AICCR, 1, AICCR_EROR_MASK, AICCR_EROR_BIT)
  370. #define __aic_dis_ror_int(parent) \
  371. jz_aic_set_reg(parent, AICCR, 0, AICCR_EROR_MASK, AICCR_EROR_BIT)
  372. #define __aic_en_tur_int(parent) \
  373. jz_aic_set_reg(parent, AICCR, 1, AICCR_ETUR_MASK, AICCR_ETUR_BIT)
  374. #define __aic_dis_tur_int(parent) \
  375. jz_aic_set_reg(parent, AICCR, 0, AICCR_ETUR_MASK, AICCR_ETUR_BIT)
  376. #define __aic_en_rfs_int(parent) \
  377. jz_aic_set_reg(parent, AICCR, 1, AICCR_ERFS_MASK, AICCR_ERFS_BIT)
  378. #define __aic_dis_rfs_int(parent) \
  379. jz_aic_set_reg(parent, AICCR, 0, AICCR_ERFS_MASK, AICCR_ERFS_BIT)
  380. #define __aic_en_tfs_int(parent) \
  381. jz_aic_set_reg(parent, AICCR, 1, AICCR_ETFS_MASK, AICCR_ETFS_BIT)
  382. #define __aic_dis_tfs_int(parent) \
  383. jz_aic_set_reg(parent, AICCR, 0, AICCR_ETFS_MASK, AICCR_ETFS_BIT)
  384. #define __aic_get_irq_enmask(parent) \
  385. jz_aic_get_reg(parent, AICCR, AICCR_EALL_INT_MASK, AICCR_ETFS_BIT)
  386. #define __aic_set_irq_enmask(parent, mask) \
  387. jz_aic_set_reg(parent, AICCR, mask, AICCR_EALL_INT_MASK, AICCR_ETFS_BIT)
  388. /*aic sr*/
  389. #define __aic_read_rfl(parent) \
  390. jz_aic_get_reg(parent, AICSR ,AICSR_RFL_MASK, AICSR_RFL_BIT)
  391. #define __aic_read_tfl(parent) \
  392. jz_aic_get_reg(parent, AICSR, AICSR_TFL_MASK, AICSR_TFL_BIT)
  393. #define __aic_clear_ror(parent) \
  394. jz_aic_set_reg(parent, AICSR, 0, AICSR_ROR_MASK, AICSR_ROR_BIT)
  395. #define __aic_test_ror(parent) \
  396. jz_aic_get_reg(parent, AICSR, AICSR_ROR_MASK, AICSR_ROR_BIT)
  397. #define __aic_clear_tur(parent) \
  398. jz_aic_set_reg(parent, AICSR, 0, AICSR_TUR_MASK, AICSR_TUR_BIT)
  399. #define __aic_test_tur(parent) \
  400. jz_aic_get_reg(parent, AICSR, AICSR_TUR_MASK, AICSR_TUR_BIT)
  401. #define __aic_clear_rfs(parent) \
  402. jz_aic_set_reg(parent, AICSR, 0, AICSR_RFS_MASK, AICSR_RFS_BIT)
  403. #define __aic_test_rfs(parent) \
  404. jz_aic_get_reg(parent, AICSR, AICSR_RFS_MASK, AICSR_RFS_BIT)
  405. #define __aic_clear_tfs(parent) \
  406. jz_aic_set_reg(parent, AICSR, 0, AICSR_TFS_MASK, AICSR_TFS_BIT)
  407. #define __aic_test_tfs(parent) \
  408. jz_aic_get_reg(parent, AICSR, AICSR_TFS_MASK, AICSR_TFS_BIT)
  409. #define __aic_get_irq_flag(parent) \
  410. jz_aic_get_reg(parent, AICSR, AICSR_ALL_INT_MASK, AICSR_TFS_BIT)
  411. #define __aic_clear_all_irq_flag(parent) \
  412. jz_aic_set_reg(parent, AICSR, AICSR_ALL_INT_MASK, AICSR_ALL_INT_MASK, AICSR_TFS_BIT)
  413. /* aic dr*/
  414. #define __aic_write_txfifo(parent, n) \
  415. jz_aic_write_reg(parent, AICDR, (n))
  416. /* For SPFIFO */
  417. #define __spdif_test_underrun(parent) \
  418. jz_aic_get_reg(parent, SPSTATE, SPSTATE_F_FFUR_MASK, SPSTATE_F_FFUR_BIT)
  419. #define __spdif_clear_underrun(parent) \
  420. jz_aic_set_reg(parent, SPSTATE, 0, SPSTATE_F_FFUR_MASK, SPSTATE_F_FFUR_BIT)
  421. #define __spdif_is_enable_transmit_dma(parent) \
  422. jz_aic_get_reg(parent, SPCTRL, SPCTRL_DMA_EN_MASK, SPCTRL_DMA_EN_BIT)
  423. #define __spdif_enable_transmit_dma(parent) \
  424. jz_aic_set_reg(parent, SPCTRL, 1, SPCTRL_DMA_EN_MASK, SPCTRL_DMA_EN_BIT)
  425. #define __spdif_disable_transmit_dma(parent) \
  426. jz_aic_set_reg(parent, SPCTRL, 0, SPCTRL_DMA_EN_MASK, SPCTRL_DMA_EN_BIT)
  427. #define __spdif_reset(parent) \
  428. jz_aic_set_reg(parent, SPCTRL, 1, SPCTRL_SFT_RST_MASK, SPCTRL_SFT_RST_BIT)
  429. #define __spdif_get_reset(parent) \
  430. jz_aic_get_reg(parent, SPCTRL,SPCTRL_SFT_RST_MASK, SPCTRL_SFT_RST_BIT)
  431. #define __spdif_enable(parent) \
  432. jz_aic_set_reg(parent, SPENA, 1, SPENA_SPEN_MASK, SPENA_SPEN_BIT)
  433. #define __spdif_disable(parent) \
  434. jz_aic_set_reg(parent, SPENA, 0, SPENA_SPEN_MASK, SPENA_SPEN_BIT)
  435. #define __spdif_set_dtype(parent, n) \
  436. jz_aic_set_reg(parent, SPCTRL, n, SPCTRL_D_TYPE_MASK, SPCTRL_D_TYPE_BIT)
  437. #define __spdif_set_trigger(parent, n) \
  438. jz_aic_set_reg(parent, SPCFG1, n, SPCFG1_TRIG_MASK, SPCFG1_TRIG_BIT)
  439. #define __spdif_set_ch1num(parent, n) \
  440. jz_aic_set_reg(parent, SPCFG1, n, SPCFG1_CH1_NUM_MASK, SPCFG1_CH1_NUM_BIT)
  441. #define __spdif_set_ch2num(parent, n) \
  442. jz_aic_set_reg(parent, SPCFG1, n, SPCFG1_CH2_NUM_MASK, SPCFG1_CH2_NUM_BIT)
  443. #define __spdif_set_srcnum(parent, n) \
  444. jz_aic_set_reg(parent, SPCFG1, n, SPCFG1_SRC_NUM_MASK, SPCFG1_SRC_NUM_BIT)
  445. #define __interface_select_spdif(parent) \
  446. jz_aic_set_reg(parent, SPCTRL, 1, SPCTRL_SPDIF_I2S_MASK, SPCTRL_SPDIF_I2S_BIT)
  447. #define __spdif_play_lastsample(parent) \
  448. jz_aic_set_reg(parent, SPCFG1, 1, SPCFG1_ZRO_VLD_MASK, SPCFG1_ZRO_VLD_BIT)
  449. #define __spdif_init_set_low(parent) \
  450. jz_aic_set_reg(parent, SPCFG1, 0, SPCFG1_INIT_LVL_MASK, SPCFG1_INIT_LVL_BIT)
  451. #define __spdif_choose_consumer(parent) \
  452. jz_aic_set_reg(parent, SPCFG2, 0, SPCFG2_CON_PRO_MASK, SPCFG2_CON_PRO_BIT)
  453. #define __spdif_clear_audion(parent) \
  454. jz_aic_set_reg(parent, SPCFG2, 0, SPCFG2_AUDIO_N_MASK, SPCFG2_AUDIO_N_BIT)
  455. #define __spdif_set_copyn(parent) \
  456. jz_aic_set_reg(parent, SPCFG2, 1, SPCFG2_COPY_N_MASK, SPCFG2_COPY_N_BIT)
  457. #define __spdif_clear_pre(parent) \
  458. jz_aic_set_reg(parent, SPCFG2, 0, SPCFG2_PRE_MASK, SPCFG2_PRE_BIT)
  459. #define __spdif_choose_chmd(parent) \
  460. jz_aic_set_reg(parent, SPCFG2, 0, SPCFG2_CH_MD_MASK, SPCFG2_CH_MD_BIT)
  461. #define __spdif_set_category_code_normal(parent) \
  462. jz_aic_set_reg(parent, SPCFG2, 0, SPCFG2_CAT_CODE_MASK, SPCFG2_CAT_CODE_BIT)
  463. #define __spdif_set_clkacu(parent, n) \
  464. jz_aic_set_reg(parent, SPCFG2, n, SPCFG2_CLK_ACU_MASK, SPCFG2_CLK_ACU_BIT)
  465. #define __spdif_set_sample_size(parent, n) \
  466. jz_aic_set_reg(parent, SPCFG2, n, SPCFG2_SAMPL_WL_MASK, SPCFG2_SAMPL_WL_BIT)
  467. #define __spdif_set_max_wl(parent, n) \
  468. jz_aic_set_reg(parent, SPCFG2, n, SPCFG2_MAX_WL_MASK, SPCFG2_MAX_WL_BIT)
  469. #define __spdif_set_ori_sample_freq(parent, org_frq_tmp) \
  470. jz_aic_set_reg(parent, SPCFG2, org_frq_tmp, SPCFG2_ORG_FRQ_MASK, SPCFG2_ORG_FRQ_BIT)
  471. #define __spdif_set_sample_freq(parent, fs_tmp) \
  472. jz_aic_set_reg(parent, SPCFG2, fs_tmp, SPCFG2_FS_MASK, SPCFG2_FS_BIT)
  473. #define __spdif_set_valid(parent) \
  474. jz_aic_set_reg(parent, SPCTRL, 0, SPCTRL_INVALID_MASK, SPCTRL_INVALID_BIT)
  475. #define __spdif_mask_trig(parent) \
  476. jz_aic_set_reg(parent, SPCTRL, 1, SPCTRL_M_TRIG_MASK, SPCTRL_M_TRIG_BIT)
  477. #define __spdif_disable_underrun_intr(parent) \
  478. jz_aic_set_reg(parent, SPCTRL, 1, SPCTRL_M_FFUR_MASK, SPCTRL_M_FFUR_BIT)
  479. #define __spdif_set_signn(parent) \
  480. jz_aic_set_reg(parent, SPCTRL, 1, SPCTRL_SIGN_N_MASK, SPCTRL_SIGN_N_BIT)
  481. #define __spdif_clear_signn(parent) \
  482. jz_aic_set_reg(parent, SPCTRL, 0, SPCTRL_SIGN_N_MASK, SPCTRL_SIGN_N_BIT)
  483. /* For I2S */
  484. /*aic fr*/
  485. #define __i2s_is_enable(parent) \
  486. jz_aic_get_reg(parent, AICFR, AICFR_ENB_MASK, AICFR_ENB_BIT)
  487. #define __aic_enable(parent) \
  488. jz_aic_set_reg(parent, AICFR, 1, AICFR_ENB_MASK, AICFR_ENB_BIT)
  489. #define __aic_disable(parent) \
  490. jz_aic_set_reg(parent, AICFR, 0, AICFR_ENB_MASK, AICFR_ENB_BIT)
  491. #define __i2s_external_codec(parent) \
  492. jz_aic_set_reg(parent, AICFR, 0, AICFR_ICDC_MASK, AICFR_ICDC_BIT)
  493. #define __i2s_bclk_output(parent) \
  494. jz_aic_set_reg(parent, AICFR, 1, AICFR_BCKD_MASK, AICFR_BCKD_BIT)
  495. #define __i2s_bclk_input(parent) \
  496. jz_aic_set_reg(parent, AICFR, 0, AICFR_BCKD_MASK, AICFR_BCKD_BIT)
  497. #define __i2s_sync_output(parent) \
  498. jz_aic_set_reg(parent, AICFR, 1, AICFR_SYNCD_MASK, AICFR_SYNCD_BIT)
  499. #define __i2s_sync_input(parent) \
  500. jz_aic_set_reg(parent, AICFR, 0, AICFR_SYNCD_MASK, AICFR_SYNCD_BIT)
  501. #define __aic_select_i2s(parent) \
  502. jz_aic_set_reg(parent, AICFR, 1, AICFR_AUSEL_MASK, AICFR_AUSEL_BIT)
  503. #define __aic_select_internal_codec(parent) \
  504. jz_aic_set_reg(parent, AICFR, 1, AICFR_ICDC_MASK, AICFR_ICDC_BIT)
  505. #define __aic_select_external_codec(parent) \
  506. jz_aic_set_reg(parent, AICFR, 0, AICFR_ICDC_MASK, AICFR_ICDC_BIT)
  507. #define __i2s_play_zero(parent) \
  508. jz_aic_set_reg(parent, AICFR, 0, AICFR_LSMP_MASK, AICFR_LSMP_BIT)
  509. #define __i2s_play_lastsample(parent) \
  510. jz_aic_set_reg(parent, AICFR, 1, AICFR_LSMP_MASK, AICFR_LSMP_BIT)
  511. #define __i2s_codec_slave(parent) \
  512. jz_aic_set_reg(parent, AICFR, 1, AICFR_CDC_SLV_MASK, AICFR_CDC_SLV_BIT)
  513. #define __i2s_codec_master(parent) \
  514. jz_aic_set_reg(parent, AICFR, 0, AICFR_CDC_SLV_MASK, AICFR_CDC_SLV_BIT)
  515. #define __i2s_select_sysclk_output(parent) \
  516. jz_aic_set_reg(parent, AICFR, 0, AICFR_SYSCLKD_MASK, AICFR_SYSCLKD_BIT)
  517. #define __i2s_select_sysclk_input(parent) \
  518. jz_aic_set_reg(parent, AICFR, 1, AICFR_SYSCLKD_MASK, AICFR_SYSCLKD_BIT)
  519. #define __i2s_set_transmit_trigger(parent, n) \
  520. jz_aic_set_reg(parent, AICFR, n, AICFR_TFTH_MASK, AICFR_TFTH_BIT)
  521. #define __i2s_set_receive_trigger(parent, n) \
  522. jz_aic_set_reg(parent, AICFR, n, AICFR_RFTH_MASK, AICFR_RFTH_BIT)
  523. /*aiccr*/
  524. #define I2S_SS2REG(n) (((n) > 18 ? (n)/6 : (n)/9)) /* n = 8, 16, 18, 20, 24 */
  525. #define __i2s_aic_packet16(parent) \
  526. jz_aic_set_reg(parent, AICCR, 1, AICCR_PACK16_MASK, AICCR_PACK16_BIT)
  527. #define __i2s_aic_unpacket16(parent) \
  528. jz_aic_set_reg(parent, AICCR, 0, AICCR_PACK16_MASK, AICCR_PACK16_BIT)
  529. #define __i2s_channel(parent, n) \
  530. jz_aic_set_reg(parent, AICCR, ((n) - 1), AICCR_CHANNEL_MASK, AICCR_CHANNEL_BIT)
  531. #define __i2s_set_oss(parent, n) \
  532. jz_aic_set_reg(parent, AICCR, I2S_SS2REG(n) , AICCR_OSS_MASK, AICCR_OSS_BIT)
  533. #define __i2s_set_iss(parent, n) \
  534. jz_aic_set_reg(parent, AICCR, I2S_SS2REG(n) , AICCR_ISS_MASK, AICCR_ISS_BIT)
  535. #define __i2s_transmit_dma_is_enable(parent) \
  536. jz_aic_get_reg(parent, AICCR, AICCR_TDMS_MASK,AICCR_TDMS_BIT)
  537. #define __i2s_disable_transmit_dma(parent) \
  538. jz_aic_set_reg(parent, AICCR, 0, AICCR_TDMS_MASK, AICCR_TDMS_BIT)
  539. #define __i2s_enable_transmit_dma(parent) \
  540. jz_aic_set_reg(parent, AICCR, 1, AICCR_TDMS_MASK, AICCR_TDMS_BIT)
  541. #define __i2s_receive_dma_is_enable(parent) \
  542. jz_aic_get_reg(parent, AICCR, AICCR_RDMS_MASK,AICCR_RDMS_BIT)
  543. #define __i2s_disable_receive_dma(parent) \
  544. jz_aic_set_reg(parent, AICCR, 0, AICCR_RDMS_MASK, AICCR_RDMS_BIT)
  545. #define __i2s_enable_receive_dma(parent) \
  546. jz_aic_set_reg(parent, AICCR, 1, AICCR_RDMS_MASK, AICCR_RDMS_BIT)
  547. #define __i2s_m2s_enable(parent) \
  548. jz_aic_set_reg(parent, AICCR, 1, AICCR_M2S_MASK, AICCR_M2S_BIT)
  549. #define __i2s_m2s_disable(parent) \
  550. jz_aic_set_reg(parent, AICCR, 0, AICCR_M2S_MASK, AICCR_M2S_BIT)
  551. #define __i2s_endsw_enable(parent) \
  552. jz_aic_set_reg(parent, AICCR, 1, AICCR_ENDSW_MASK, AICCR_ENDSW_BIT)
  553. #define __i2s_endsw_disable(parent) \
  554. jz_aic_set_reg(parent, AICCR, 0, AICCR_ENDSW_MASK, AICCR_ENDSW_BIT)
  555. #define __i2s_asvtsu_enable(parent) \
  556. jz_aic_set_reg(parent, AICCR, 1, AICCR_ASVTSU_MASK, AICCR_ASVTSU_BIT)
  557. #define __i2s_asvtsu_disable(parent) \
  558. jz_aic_set_reg(parent, AICCR, 0, AICCR_ASVTSU_MASK, AICCR_ASVTSU_BIT)
  559. #define __i2s_enable_replay(parent) \
  560. jz_aic_set_reg(parent, AICCR, 1, AICCR_ERPL_MASK, AICCR_ERPL_BIT)
  561. #define __i2s_enable_record(parent) \
  562. jz_aic_set_reg(parent, AICCR, 1, AICCR_EREC_MASK, AICCR_EREC_BIT)
  563. #define __i2s_enable_loopback(parent) \
  564. jz_aic_set_reg(parent, AICCR, 1, AICCR_ENLBF_MASK, AICCR_ENLBF_BIT)
  565. #define __i2s_disable_replay(parent) \
  566. jz_aic_set_reg(parent, AICCR, 0, AICCR_ERPL_MASK, AICCR_ERPL_BIT)
  567. #define __i2s_disable_record(parent) \
  568. jz_aic_set_reg(parent, AICCR, 0, AICCR_EREC_MASK, AICCR_EREC_BIT)
  569. #define __i2s_disable_loopback(parent) \
  570. jz_aic_set_reg(parent, AICCR, 0, AICCR_ENLBF_MASK, AICCR_ENLBF_BIT)
  571. /*i2scr*/
  572. #define __i2s_select_i2s_fmt(parent) \
  573. jz_aic_set_reg(parent, I2SCR, 0, I2SCR_AMSL_MASK, I2SCR_AMSL_BIT)
  574. #define __i2s_select_msb_fmt(parent) \
  575. jz_aic_set_reg(parent, I2SCR, 1, I2SCR_AMSL_MASK, I2SCR_AMSL_BIT)
  576. #define __i2s_enable_sysclk_output(parent) \
  577. jz_aic_set_reg(parent, I2SCR, 1, I2SCR_ESCLK_MASK, I2SCR_ESCLK_BIT)
  578. #define __i2s_disable_sysclk_output(parent) \
  579. jz_aic_set_reg(parent, I2SCR, 0, I2SCR_ESCLK_MASK, I2SCR_ESCLK_BIT)
  580. #define __i2s_stop_bitclk(parent) \
  581. jz_aic_set_reg(parent, I2SCR, 1, I2SCR_STPBK_MASK, I2SCR_STPBK_BIT)
  582. #define __i2s_start_bitclk(parent) \
  583. jz_aic_set_reg(parent, I2SCR, 0, I2SCR_STPBK_MASK, I2SCR_STPBK_BIT)
  584. #define __i2s_select_packed_lrswap(parent) \
  585. jz_aic_set_reg(parent, I2SCR, 1, I2SCR_SWLH_MASK, I2SCR_SWLH_BIT)
  586. #define __i2s_select_packed_lrnorm(parent) \
  587. jz_aic_set_reg(parent, I2SCR, 0, I2SCR_SWLH_MASK, I2SCR_SWLH_BIT)
  588. #define __i2s_send_rfirst(parent) \
  589. jz_aic_set_reg(parent, I2SCR, 1, I2SCR_RFIRST_MASK, I2SCR_RFIRST_BIT)
  590. #define __i2s_send_lfirst(parent) \
  591. jz_aic_set_reg(parent, I2SCR, 0, I2SCR_RFIRST_MASK, I2SCR_RFIRST_BIT)
  592. /*i2ssr*/
  593. #define __i2s_transmiter_is_busy(parent) \
  594. (!!(jz_aic_read_reg(parent, I2SSR) & I2SSR_TBSY_MASK))
  595. #define __i2s_receiver_is_busy(parent) \
  596. (!!(jz_aic_read_reg(parent, I2SSR) & I2SSR_TBSY_MASK))
  597. /*i2s_div*/
  598. #define __i2s_set_idv(parent, div) \
  599. jz_aic_set_reg(parent, I2SDIV, div, I2SDIV_IDV_MASK, I2SDIV_IDV_BIT)
  600. #define __i2s_set_dv(parent, div) \
  601. jz_aic_set_reg(parent, I2SDIV, div, I2SDIV_DV_MASK, I2SDIV_DV_BIT)
  602. #endif /* _DRV_I2S_H_ */