DAI.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. ASoC currently supports the three main Digital Audio Interfaces (DAI) found on
  2. SoC controllers and portable audio CODECS today, namely AC97, I2S and PCM.
  3. AC97
  4. ====
  5. AC97 is a five wire interface commonly found on many PC sound cards. It is
  6. now also popular in many portable devices. This DAI has a reset line and time
  7. multiplexes its data on its SDATA_OUT (playback) and SDATA_IN (capture) lines.
  8. The bit clock (BCLK) is always driven by the CODEC (usually 12.288MHz) and the
  9. frame (FRAME) (usually 48kHz) is always driven by the controller. Each AC97
  10. frame is 21uS long and is divided into 13 time slots.
  11. The AC97 specification can be found at http://intel.com/
  12. I2S
  13. ===
  14. I2S is a common 4 wire DAI used in HiFi, STB and portable devices. The Tx and
  15. Rx lines are used for audio transmision, whilst the bit clock (BCLK) and
  16. left/right clock (LRC) synchronise the link. I2S is flexible in that either the
  17. controller or CODEC can drive (master) the BCLK and LRC clock lines. Bit clock
  18. usually varies depending on the sample rate and the master system clock
  19. (SYSCLK). LRCLK is the same as the sample rate. A few devices support separate
  20. ADC and DAC LRCLK's, this allows for similtanious capture and playback at
  21. different sample rates.
  22. I2S has several different operating modes:-
  23. o I2S - MSB is transmitted on the falling edge of the first BCLK after LRC
  24. transition.
  25. o Left Justified - MSB is transmitted on transition of LRC.
  26. o Right Justified - MSB is transmitted sample size BCLK's before LRC
  27. transition.
  28. PCM
  29. ===
  30. PCM is another 4 wire interface, very similar to I2S, that can support a more
  31. flexible protocol. It has bit clock (BCLK) and sync (SYNC) lines that are used
  32. to synchronise the link whilst the Tx and Rx lines are used to transmit and
  33. receive the audio data. Bit clock usually varies depending on sample rate
  34. whilst sync runs at the sample rate. PCM also supports Time Division
  35. Multiplexing (TDM) in that several devices can use the bus similtaniuosly (This
  36. is sometimes referred to as network mode).
  37. Common PCM operating modes:-
  38. o Mode A - MSB is transmitted on falling edge of first BCLK after FRAME/SYNC.
  39. o Mode B - MSB is transmitted on rising edge of FRAME/SYNC.
  40. ASoC DAI Configuration
  41. ======================
  42. Every CODEC DAI and SoC DAI must have their capabilities defined in order to
  43. be configured together at runtime when the audio and clocking parameters are
  44. known. This is achieved by creating an array of struct snd_soc_hw_mode in the
  45. the CODEC and SoC interface drivers. Each element in the array describes a DAI
  46. mode and each mode is usually based upon the DAI system clock to sample rate
  47. ratio (FS).
  48. i.e. 48k sample rate @ 256 FS = sytem clock of 12.288 MHz
  49. 48000 * 256 = 12288000
  50. The CPU and Codec DAI modes are then ANDed together at runtime to determine the
  51. rutime DAI configuration for both the Codec and CPU.
  52. When creating a new codec or SoC DAI it's probably best to start of with a few
  53. sample rates first and then test your interface.
  54. struct snd_soc_dai_mode is defined (in soc.h) as:-
  55. /* SoC DAI mode */
  56. struct snd_soc_hw_mode {
  57. unsigned int fmt:16; /* SND_SOC_DAIFMT_* */
  58. unsigned int tdm:16; /* SND_SOC_DAITDM_* */
  59. unsigned int pcmfmt:6; /* SNDRV_PCM_FORMAT_* */
  60. unsigned int pcmrate:16; /* SND_SOC_DAIRATE_* */
  61. unsigned int pcmdir:2; /* SND_SOC_DAIDIR_* */
  62. unsigned int flags:8; /* hw flags */
  63. unsigned int fs:32; /* mclk to rate dividers */
  64. unsigned int bfs:16; /* mclk to bclk dividers */
  65. unsigned long priv; /* private mode data */
  66. };
  67. fmt:
  68. ----
  69. This field defines the DAI mode hardware format (e.g. I2S settings) and
  70. supports the following settings:-
  71. 1) hardware DAI formats
  72. #define SND_SOC_DAIFMT_I2S (1 << 0) /* I2S mode */
  73. #define SND_SOC_DAIFMT_RIGHT_J (1 << 1) /* Right justified mode */
  74. #define SND_SOC_DAIFMT_LEFT_J (1 << 2) /* Left Justified mode */
  75. #define SND_SOC_DAIFMT_DSP_A (1 << 3) /* L data msb after FRM */
  76. #define SND_SOC_DAIFMT_DSP_B (1 << 4) /* L data msb during FRM */
  77. #define SND_SOC_DAIFMT_AC97 (1 << 5) /* AC97 */
  78. 2) hw DAI signal inversions
  79. #define SND_SOC_DAIFMT_NB_NF (1 << 8) /* normal bit clock + frame */
  80. #define SND_SOC_DAIFMT_NB_IF (1 << 9) /* normal bclk + inv frm */
  81. #define SND_SOC_DAIFMT_IB_NF (1 << 10) /* invert bclk + nor frm */
  82. #define SND_SOC_DAIFMT_IB_IF (1 << 11) /* invert bclk + frm */
  83. 3) hw clock masters
  84. This is wrt the codec, the inverse is true for the interface
  85. i.e. if the codec is clk and frm master then the interface is
  86. clk and frame slave.
  87. #define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & frm master */
  88. #define SND_SOC_DAIFMT_CBS_CFM (1 << 13) /* codec clk slave & frm master */
  89. #define SND_SOC_DAIFMT_CBM_CFS (1 << 14) /* codec clk master & frame slave */
  90. #define SND_SOC_DAIFMT_CBS_CFS (1 << 15) /* codec clk & frm slave */
  91. At least one option from each section must be selected. Multiple selections are
  92. also supported e.g.
  93. .fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_RIGHT_J | \
  94. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_NB_IF | SND_SOC_DAIFMT_IB_NF | \
  95. SND_SOC_DAIFMT_IB_IF
  96. tdm:
  97. ------
  98. This field defines the Time Division Multiplexing left and right word
  99. positions for the DAI mode if applicable. Set to SND_SOC_DAITDM_LRDW(0,0) for
  100. no TDM.
  101. pcmfmt:
  102. ---------
  103. The hardware PCM format. This describes the PCM formats supported by the DAI
  104. mode e.g.
  105. .hwpcmfmt = SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
  106. SNDRV_PCM_FORMAT_S24_3LE
  107. pcmrate:
  108. ----------
  109. The PCM sample rates supported by the DAI mode. e.g.
  110. .hwpcmrate = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  111. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  112. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000
  113. pcmdir:
  114. ---------
  115. The stream directions supported by this mode. e.g. playback and capture
  116. flags:
  117. --------
  118. The DAI hardware flags supported by the mode.
  119. SND_SOC_DAI_BFS_DIV
  120. This flag states that bit clock is generated by dividing MCLK in this mode, if
  121. this flag is absent the bitclock generated by mulitiplying sample rate.
  122. NOTE: Bitclock division and mulitiplication modes can be safely matched by the
  123. core logic.
  124. fs:
  125. -----
  126. The FS supported by this DAI mode FS is the ratio between the system clock and
  127. the sample rate. See above
  128. bfs:
  129. ------
  130. BFS is the ratio of BCLK to MCLK or the ratio of BCLK to sample rate (this
  131. depends on the codec or CPU DAI).
  132. The BFS supported by the DAI mode. This can either be the ratio between the
  133. bitclock (BCLK) and the sample rate OR the ratio between the system clock and
  134. the sample rate. Depends on the SND_SOC_DAI_BFS_DIV flag above.
  135. priv:
  136. -----
  137. private codec mode data.
  138. Examples
  139. ========
  140. Note that Codec DAI and CPU DAI examples are interchangeable in these examples
  141. as long as the bus master is reversed. i.e.
  142. SND_SOC_DAIFMT_CBM_CFM would become SND_SOC_DAIFMT_CBS_CFS
  143. and vice versa.
  144. This applies to all SND_SOC_DAIFMT_CB*_CF*.
  145. Example 1
  146. ---------
  147. Simple codec that only runs at 8k & 48k @ 256FS in master mode, can generate a
  148. BCLK of either MCLK/2 or MCLK/4.
  149. /* codec master */
  150. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, SND_SOC_DAITDM_LRDW(0,0),
  151. SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
  152. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, SND_SOC_DAI_BFS_DIV,
  153. 256, SND_SOC_FSBD(2) | SND_SOC_FSBD(4)},
  154. Example 2
  155. ---------
  156. Simple codec that only runs at 8k & 48k @ 256FS in master mode, can generate a
  157. BCLK of either Rate * 32 or Rate * 64.
  158. /* codec master */
  159. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, SND_SOC_DAITDM_LRDW(0,0),
  160. SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
  161. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, 0,
  162. 256, SND_SOC_FSB(32) | SND_SOC_FSB(64)},
  163. Example 3
  164. ---------
  165. Codec that only runs at 8k & 48k @ 256FS in master mode, can generate a
  166. BCLK of either Rate * 32 or Rate * 64. Codec can also run in slave mode as long
  167. as BCLK is rate * 32 or rate * 64.
  168. /* codec master */
  169. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, SND_SOC_DAITDM_LRDW(0,0),
  170. SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
  171. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, 0,
  172. 256, SND_SOC_FSB(32) | SND_SOC_FSB(64)},
  173. /* codec slave */
  174. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS, SND_SOC_DAITDM_LRDW(0,0),
  175. SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
  176. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, 0,
  177. SND_SOC_FS_ALL, SND_SOC_FSB(32) | SND_SOC_FSB(64)},
  178. Example 4
  179. ---------
  180. Codec that only runs at 8k, 16k, 32k, 48k, 96k @ 128FS, 192FS & 256FS in master
  181. mode and can generate a BCLK of MCLK / (1,2,4,8,16). Codec can also run in slave
  182. mode as and does not care about FS or BCLK (as long as there is enough bandwidth).
  183. #define CODEC_FSB \
  184. (SND_SOC_FSBD(1) | SND_SOC_FSBD(2) | SND_SOC_FSBD(4) | \
  185. SND_SOC_FSBD(8) | SND_SOC_FSBD(16))
  186. #define CODEC_RATES \
  187. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_32000 |\
  188. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
  189. /* codec master @ 128, 192 & 256 FS */
  190. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, SND_SOC_DAITDM_LRDW(0,0),
  191. SNDRV_PCM_FORMAT_S16_LE, CODEC_RATES,
  192. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, SND_SOC_DAI_BFS_DIV,
  193. 128, CODEC_FSB},
  194. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, SND_SOC_DAITDM_LRDW(0,0),
  195. SNDRV_PCM_FORMAT_S16_LE, CODEC_RATES,
  196. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, SND_SOC_DAI_BFS_DIV,
  197. 192, CODEC_FSB},
  198. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, SND_SOC_DAITDM_LRDW(0,0),
  199. SNDRV_PCM_FORMAT_S16_LE, CODEC_RATES,
  200. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, SND_SOC_DAI_BFS_DIV,
  201. 256, CODEC_FSB},
  202. /* codec slave */
  203. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS, SND_SOC_DAITDM_LRDW(0,0),
  204. SNDRV_PCM_FORMAT_S16_LE, CODEC_RATES,
  205. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, 0,
  206. SND_SOC_FS_ALL, SND_SOC_FSB_ALL},
  207. Example 5
  208. ---------
  209. Codec that only runs at 8k, 44.1k, 48k @ different FS in master mode (for use
  210. with a fixed MCLK) and can generate a BCLK of MCLK / (1,2,4,8,16).
  211. Codec can also run in slave mode as and does not care about FS or BCLK (as long
  212. as there is enough bandwidth). Codec can support 16, 24 and 32 bit PCM sample
  213. sizes.
  214. #define CODEC_FSB \
  215. (SND_SOC_FSBD(1) | SND_SOC_FSBD(2) | SND_SOC_FSBD(4) | \
  216. SND_SOC_FSBD(8) | SND_SOC_FSBD(16))
  217. #define CODEC_PCM_FORMATS \
  218. (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
  219. SNDRV_PCM_FORMAT_S24_3LE | SNDRV_PCM_FORMAT_S24_LE | SNDRV_PCM_FORMAT_S32_LE)
  220. /* codec master */
  221. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, SND_SOC_DAITDM_LRDW(0,0),
  222. SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_8000,
  223. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, SND_SOC_DAI_BFS_DIV,
  224. 1536, CODEC_FSB},
  225. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, SND_SOC_DAITDM_LRDW(0,0),
  226. SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_44100,
  227. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, SND_SOC_DAI_BFS_DIV,
  228. 272, CODEC_FSB},
  229. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM, SND_SOC_DAITDM_LRDW(0,0),
  230. SNDRV_PCM_FORMAT_S16_LE, SNDRV_PCM_RATE_48000,
  231. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, SND_SOC_DAI_BFS_DIV,
  232. 256, CODEC_FSB},
  233. /* codec slave */
  234. {SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS, SND_SOC_DAITDM_LRDW(0,0),
  235. SNDRV_PCM_FORMAT_S16_LE, CODEC_RATES,
  236. SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE, 0,
  237. SND_SOC_FS_ALL, SND_SOC_FSB_ALL},
  238. Example 6
  239. ---------
  240. AC97 Codec that does not support VRA (i.e only runs at 48k).
  241. #define AC97_DIR \
  242. (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE)
  243. #define AC97_PCM_FORMATS \
  244. (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S18_3LE | \
  245. SNDRV_PCM_FORMAT_S20_3LE)
  246. /* AC97 with no VRA */
  247. {0, 0, AC97_PCM_FORMATS, SNDRV_PCM_RATE_48000},
  248. Example 7
  249. ---------
  250. CPU DAI that supports 8k - 48k @ 256FS and BCLK = MCLK / 4 in master mode.
  251. Slave mode (CPU DAI is FRAME master) supports 8k - 96k at any FS as long as
  252. BCLK = 64 * rate. (Intel XScale I2S controller).
  253. #define PXA_I2S_DAIFMT \
  254. (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF)
  255. #define PXA_I2S_DIR \
  256. (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE)
  257. #define PXA_I2S_RATES \
  258. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  259. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  260. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  261. /* pxa2xx I2S frame and clock master modes */
  262. {PXA_I2S_DAIFMT | SND_SOC_DAIFMT_CBS_CFS, SND_SOC_DAITDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE,
  263. SNDRV_PCM_RATE_8000, PXA_I2S_DIR, SND_SOC_DAI_BFS_DIV, 256,
  264. SND_SOC_FSBD(4), 0x48},
  265. {PXA_I2S_DAIFMT | SND_SOC_DAIFMT_CBS_CFS, SND_SOC_DAITDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE,
  266. SNDRV_PCM_RATE_11025, PXA_I2S_DIR, SND_SOC_DAI_BFS_DIV, 256,
  267. SND_SOC_FSBD(4), 0x34},
  268. {PXA_I2S_DAIFMT | SND_SOC_DAIFMT_CBS_CFS, SND_SOC_DAITDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE,
  269. SNDRV_PCM_RATE_16000, PXA_I2S_DIR, SND_SOC_DAI_BFS_DIV, 256,
  270. SND_SOC_FSBD(4), 0x24},
  271. {PXA_I2S_DAIFMT | SND_SOC_DAIFMT_CBS_CFS, SND_SOC_DAITDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE,
  272. SNDRV_PCM_RATE_22050, PXA_I2S_DIR, SND_SOC_DAI_BFS_DIV, 256,
  273. SND_SOC_FSBD(4), 0x1a},
  274. {PXA_I2S_DAIFMT | SND_SOC_DAIFMT_CBS_CFS, SND_SOC_DAITDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE,
  275. SNDRV_PCM_RATE_44100, PXA_I2S_DIR, SND_SOC_DAI_BFS_DIV, 256,
  276. SND_SOC_FSBD(4), 0xd},
  277. {PXA_I2S_DAIFMT | SND_SOC_DAIFMT_CBS_CFS, SND_SOC_DAITDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE,
  278. SNDRV_PCM_RATE_48000, PXA_I2S_DIR, SND_SOC_DAI_BFS_DIV, 256,
  279. SND_SOC_FSBD(4), 0xc},
  280. /* pxa2xx I2S frame master and clock slave mode */
  281. {PXA_I2S_DAIFMT | SND_SOC_DAIFMT_CBM_CFS, SND_SOC_DAITDM_LRDW(0,0), SNDRV_PCM_FORMAT_S16_LE,
  282. PXA_I2S_RATES, PXA_I2S_DIR, 0, SND_SOC_FS_ALL, SND_SOC_FSB(64)},