fsl_spdif.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * fsl_spdif.h - ALSA S/PDIF interface for the Freescale i.MX SoC
  3. *
  4. * Copyright (C) 2013 Freescale Semiconductor, Inc.
  5. *
  6. * Author: Nicolin Chen <b42378@freescale.com>
  7. *
  8. * Based on fsl_ssi.h
  9. * Author: Timur Tabi <timur@freescale.com>
  10. * Copyright 2007-2008 Freescale Semiconductor, Inc.
  11. *
  12. * This file is licensed under the terms of the GNU General Public License
  13. * version 2. This program is licensed "as is" without any warranty of any
  14. * kind, whether express or implied.
  15. */
  16. #ifndef _FSL_SPDIF_DAI_H
  17. #define _FSL_SPDIF_DAI_H
  18. /* S/PDIF Register Map */
  19. #define REG_SPDIF_SCR 0x0 /* SPDIF Configuration Register */
  20. #define REG_SPDIF_SRCD 0x4 /* CDText Control Register */
  21. #define REG_SPDIF_SRPC 0x8 /* PhaseConfig Register */
  22. #define REG_SPDIF_SIE 0xc /* InterruptEn Register */
  23. #define REG_SPDIF_SIS 0x10 /* InterruptStat Register */
  24. #define REG_SPDIF_SIC 0x10 /* InterruptClear Register */
  25. #define REG_SPDIF_SRL 0x14 /* SPDIFRxLeft Register */
  26. #define REG_SPDIF_SRR 0x18 /* SPDIFRxRight Register */
  27. #define REG_SPDIF_SRCSH 0x1c /* SPDIFRxCChannel_h Register */
  28. #define REG_SPDIF_SRCSL 0x20 /* SPDIFRxCChannel_l Register */
  29. #define REG_SPDIF_SRU 0x24 /* UchannelRx Register */
  30. #define REG_SPDIF_SRQ 0x28 /* QchannelRx Register */
  31. #define REG_SPDIF_STL 0x2C /* SPDIFTxLeft Register */
  32. #define REG_SPDIF_STR 0x30 /* SPDIFTxRight Register */
  33. #define REG_SPDIF_STCSCH 0x34 /* SPDIFTxCChannelCons_h Register */
  34. #define REG_SPDIF_STCSCL 0x38 /* SPDIFTxCChannelCons_l Register */
  35. #define REG_SPDIF_SRFM 0x44 /* FreqMeas Register */
  36. #define REG_SPDIF_STC 0x50 /* SPDIFTxClk Register */
  37. /* SPDIF Configuration register */
  38. #define SCR_RXFIFO_CTL_OFFSET 23
  39. #define SCR_RXFIFO_CTL_MASK (1 << SCR_RXFIFO_CTL_OFFSET)
  40. #define SCR_RXFIFO_CTL_ZERO (1 << SCR_RXFIFO_CTL_OFFSET)
  41. #define SCR_RXFIFO_OFF_OFFSET 22
  42. #define SCR_RXFIFO_OFF_MASK (1 << SCR_RXFIFO_OFF_OFFSET)
  43. #define SCR_RXFIFO_OFF (1 << SCR_RXFIFO_OFF_OFFSET)
  44. #define SCR_RXFIFO_RST_OFFSET 21
  45. #define SCR_RXFIFO_RST_MASK (1 << SCR_RXFIFO_RST_OFFSET)
  46. #define SCR_RXFIFO_RST (1 << SCR_RXFIFO_RST_OFFSET)
  47. #define SCR_RXFIFO_FSEL_OFFSET 19
  48. #define SCR_RXFIFO_FSEL_MASK (0x3 << SCR_RXFIFO_FSEL_OFFSET)
  49. #define SCR_RXFIFO_FSEL_IF0 (0x0 << SCR_RXFIFO_FSEL_OFFSET)
  50. #define SCR_RXFIFO_FSEL_IF4 (0x1 << SCR_RXFIFO_FSEL_OFFSET)
  51. #define SCR_RXFIFO_FSEL_IF8 (0x2 << SCR_RXFIFO_FSEL_OFFSET)
  52. #define SCR_RXFIFO_FSEL_IF12 (0x3 << SCR_RXFIFO_FSEL_OFFSET)
  53. #define SCR_RXFIFO_AUTOSYNC_OFFSET 18
  54. #define SCR_RXFIFO_AUTOSYNC_MASK (1 << SCR_RXFIFO_AUTOSYNC_OFFSET)
  55. #define SCR_RXFIFO_AUTOSYNC (1 << SCR_RXFIFO_AUTOSYNC_OFFSET)
  56. #define SCR_TXFIFO_AUTOSYNC_OFFSET 17
  57. #define SCR_TXFIFO_AUTOSYNC_MASK (1 << SCR_TXFIFO_AUTOSYNC_OFFSET)
  58. #define SCR_TXFIFO_AUTOSYNC (1 << SCR_TXFIFO_AUTOSYNC_OFFSET)
  59. #define SCR_TXFIFO_FSEL_OFFSET 15
  60. #define SCR_TXFIFO_FSEL_MASK (0x3 << SCR_TXFIFO_FSEL_OFFSET)
  61. #define SCR_TXFIFO_FSEL_IF0 (0x0 << SCR_TXFIFO_FSEL_OFFSET)
  62. #define SCR_TXFIFO_FSEL_IF4 (0x1 << SCR_TXFIFO_FSEL_OFFSET)
  63. #define SCR_TXFIFO_FSEL_IF8 (0x2 << SCR_TXFIFO_FSEL_OFFSET)
  64. #define SCR_TXFIFO_FSEL_IF12 (0x3 << SCR_TXFIFO_FSEL_OFFSET)
  65. #define SCR_LOW_POWER (1 << 13)
  66. #define SCR_SOFT_RESET (1 << 12)
  67. #define SCR_TXFIFO_CTRL_OFFSET 10
  68. #define SCR_TXFIFO_CTRL_MASK (0x3 << SCR_TXFIFO_CTRL_OFFSET)
  69. #define SCR_TXFIFO_CTRL_ZERO (0x0 << SCR_TXFIFO_CTRL_OFFSET)
  70. #define SCR_TXFIFO_CTRL_NORMAL (0x1 << SCR_TXFIFO_CTRL_OFFSET)
  71. #define SCR_TXFIFO_CTRL_ONESAMPLE (0x2 << SCR_TXFIFO_CTRL_OFFSET)
  72. #define SCR_DMA_RX_EN_OFFSET 9
  73. #define SCR_DMA_RX_EN_MASK (1 << SCR_DMA_RX_EN_OFFSET)
  74. #define SCR_DMA_RX_EN (1 << SCR_DMA_RX_EN_OFFSET)
  75. #define SCR_DMA_TX_EN_OFFSET 8
  76. #define SCR_DMA_TX_EN_MASK (1 << SCR_DMA_TX_EN_OFFSET)
  77. #define SCR_DMA_TX_EN (1 << SCR_DMA_TX_EN_OFFSET)
  78. #define SCR_VAL_OFFSET 5
  79. #define SCR_VAL_MASK (1 << SCR_VAL_OFFSET)
  80. #define SCR_VAL_CLEAR (1 << SCR_VAL_OFFSET)
  81. #define SCR_TXSEL_OFFSET 2
  82. #define SCR_TXSEL_MASK (0x7 << SCR_TXSEL_OFFSET)
  83. #define SCR_TXSEL_OFF (0 << SCR_TXSEL_OFFSET)
  84. #define SCR_TXSEL_RX (1 << SCR_TXSEL_OFFSET)
  85. #define SCR_TXSEL_NORMAL (0x5 << SCR_TXSEL_OFFSET)
  86. #define SCR_USRC_SEL_OFFSET 0x0
  87. #define SCR_USRC_SEL_MASK (0x3 << SCR_USRC_SEL_OFFSET)
  88. #define SCR_USRC_SEL_NONE (0x0 << SCR_USRC_SEL_OFFSET)
  89. #define SCR_USRC_SEL_RECV (0x1 << SCR_USRC_SEL_OFFSET)
  90. #define SCR_USRC_SEL_CHIP (0x3 << SCR_USRC_SEL_OFFSET)
  91. #define SCR_DMA_xX_EN(tx) (tx ? SCR_DMA_TX_EN : SCR_DMA_RX_EN)
  92. /* SPDIF CDText control */
  93. #define SRCD_CD_USER_OFFSET 1
  94. #define SRCD_CD_USER (1 << SRCD_CD_USER_OFFSET)
  95. /* SPDIF Phase Configuration register */
  96. #define SRPC_DPLL_LOCKED (1 << 6)
  97. #define SRPC_CLKSRC_SEL_OFFSET 7
  98. #define SRPC_CLKSRC_SEL_MASK (0xf << SRPC_CLKSRC_SEL_OFFSET)
  99. #define SRPC_CLKSRC_SEL_SET(x) ((x << SRPC_CLKSRC_SEL_OFFSET) & SRPC_CLKSRC_SEL_MASK)
  100. #define SRPC_CLKSRC_SEL_LOCKED_OFFSET1 5
  101. #define SRPC_CLKSRC_SEL_LOCKED_OFFSET2 2
  102. #define SRPC_GAINSEL_OFFSET 3
  103. #define SRPC_GAINSEL_MASK (0x7 << SRPC_GAINSEL_OFFSET)
  104. #define SRPC_GAINSEL_SET(x) ((x << SRPC_GAINSEL_OFFSET) & SRPC_GAINSEL_MASK)
  105. #define SRPC_CLKSRC_MAX 16
  106. enum spdif_gainsel {
  107. GAINSEL_MULTI_24 = 0,
  108. GAINSEL_MULTI_16,
  109. GAINSEL_MULTI_12,
  110. GAINSEL_MULTI_8,
  111. GAINSEL_MULTI_6,
  112. GAINSEL_MULTI_4,
  113. GAINSEL_MULTI_3,
  114. };
  115. #define GAINSEL_MULTI_MAX (GAINSEL_MULTI_3 + 1)
  116. #define SPDIF_DEFAULT_GAINSEL GAINSEL_MULTI_8
  117. /* SPDIF interrupt mask define */
  118. #define INT_DPLL_LOCKED (1 << 20)
  119. #define INT_TXFIFO_UNOV (1 << 19)
  120. #define INT_TXFIFO_RESYNC (1 << 18)
  121. #define INT_CNEW (1 << 17)
  122. #define INT_VAL_NOGOOD (1 << 16)
  123. #define INT_SYM_ERR (1 << 15)
  124. #define INT_BIT_ERR (1 << 14)
  125. #define INT_URX_FUL (1 << 10)
  126. #define INT_URX_OV (1 << 9)
  127. #define INT_QRX_FUL (1 << 8)
  128. #define INT_QRX_OV (1 << 7)
  129. #define INT_UQ_SYNC (1 << 6)
  130. #define INT_UQ_ERR (1 << 5)
  131. #define INT_RXFIFO_UNOV (1 << 4)
  132. #define INT_RXFIFO_RESYNC (1 << 3)
  133. #define INT_LOSS_LOCK (1 << 2)
  134. #define INT_TX_EM (1 << 1)
  135. #define INT_RXFIFO_FUL (1 << 0)
  136. /* SPDIF Clock register */
  137. #define STC_SYSCLK_DF_OFFSET 11
  138. #define STC_SYSCLK_DF_MASK (0x1ff << STC_SYSCLK_DF_OFFSET)
  139. #define STC_SYSCLK_DF(x) ((((x) - 1) << STC_SYSCLK_DF_OFFSET) & STC_SYSCLK_DF_MASK)
  140. #define STC_TXCLK_SRC_OFFSET 8
  141. #define STC_TXCLK_SRC_MASK (0x7 << STC_TXCLK_SRC_OFFSET)
  142. #define STC_TXCLK_SRC_SET(x) ((x << STC_TXCLK_SRC_OFFSET) & STC_TXCLK_SRC_MASK)
  143. #define STC_TXCLK_ALL_EN_OFFSET 7
  144. #define STC_TXCLK_ALL_EN_MASK (1 << STC_TXCLK_ALL_EN_OFFSET)
  145. #define STC_TXCLK_ALL_EN (1 << STC_TXCLK_ALL_EN_OFFSET)
  146. #define STC_TXCLK_DF_OFFSET 0
  147. #define STC_TXCLK_DF_MASK (0x7ff << STC_TXCLK_DF_OFFSET)
  148. #define STC_TXCLK_DF(x) ((((x) - 1) << STC_TXCLK_DF_OFFSET) & STC_TXCLK_DF_MASK)
  149. #define STC_TXCLK_SRC_MAX 8
  150. #define STC_TXCLK_SPDIF_ROOT 1
  151. /* SPDIF tx rate */
  152. enum spdif_txrate {
  153. SPDIF_TXRATE_32000 = 0,
  154. SPDIF_TXRATE_44100,
  155. SPDIF_TXRATE_48000,
  156. SPDIF_TXRATE_96000,
  157. SPDIF_TXRATE_192000,
  158. };
  159. #define SPDIF_TXRATE_MAX (SPDIF_TXRATE_192000 + 1)
  160. #define SPDIF_CSTATUS_BYTE 6
  161. #define SPDIF_UBITS_SIZE 96
  162. #define SPDIF_QSUB_SIZE (SPDIF_UBITS_SIZE / 8)
  163. #define FSL_SPDIF_RATES_PLAYBACK (SNDRV_PCM_RATE_32000 | \
  164. SNDRV_PCM_RATE_44100 | \
  165. SNDRV_PCM_RATE_48000 | \
  166. SNDRV_PCM_RATE_96000 | \
  167. SNDRV_PCM_RATE_192000)
  168. #define FSL_SPDIF_RATES_CAPTURE (SNDRV_PCM_RATE_16000 | \
  169. SNDRV_PCM_RATE_32000 | \
  170. SNDRV_PCM_RATE_44100 | \
  171. SNDRV_PCM_RATE_48000 | \
  172. SNDRV_PCM_RATE_64000 | \
  173. SNDRV_PCM_RATE_96000)
  174. #define FSL_SPDIF_FORMATS_PLAYBACK (SNDRV_PCM_FMTBIT_S16_LE | \
  175. SNDRV_PCM_FMTBIT_S20_3LE | \
  176. SNDRV_PCM_FMTBIT_S24_LE)
  177. #define FSL_SPDIF_FORMATS_CAPTURE (SNDRV_PCM_FMTBIT_S24_LE)
  178. #endif /* _FSL_SPDIF_DAI_H */