soc-dai.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * linux/sound/soc-dai.h -- ALSA SoC Layer
  3. *
  4. * Copyright: 2005-2008 Wolfson Microelectronics. PLC.
  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 version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Digital Audio Interface (DAI) API.
  11. */
  12. #ifndef __LINUX_SND_SOC_DAI_H
  13. #define __LINUX_SND_SOC_DAI_H
  14. #include <linux/list.h>
  15. struct snd_pcm_substream;
  16. struct snd_soc_dapm_widget;
  17. struct snd_compr_stream;
  18. /*
  19. * DAI hardware audio formats.
  20. *
  21. * Describes the physical PCM data formating and clocking. Add new formats
  22. * to the end.
  23. */
  24. #define SND_SOC_DAIFMT_I2S 1 /* I2S mode */
  25. #define SND_SOC_DAIFMT_RIGHT_J 2 /* Right Justified mode */
  26. #define SND_SOC_DAIFMT_LEFT_J 3 /* Left Justified mode */
  27. #define SND_SOC_DAIFMT_DSP_A 4 /* L data MSB after FRM LRC */
  28. #define SND_SOC_DAIFMT_DSP_B 5 /* L data MSB during FRM LRC */
  29. #define SND_SOC_DAIFMT_AC97 6 /* AC97 */
  30. #define SND_SOC_DAIFMT_PDM 7 /* Pulse density modulation */
  31. /* left and right justified also known as MSB and LSB respectively */
  32. #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
  33. #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
  34. /*
  35. * DAI Clock gating.
  36. *
  37. * DAI bit clocks can be be gated (disabled) when the DAI is not
  38. * sending or receiving PCM data in a frame. This can be used to save power.
  39. */
  40. #define SND_SOC_DAIFMT_CONT (1 << 4) /* continuous clock */
  41. #define SND_SOC_DAIFMT_GATED (0 << 4) /* clock is gated */
  42. /*
  43. * DAI hardware signal polarity.
  44. *
  45. * Specifies whether the DAI can also support inverted clocks for the specified
  46. * format.
  47. *
  48. * BCLK:
  49. * - "normal" polarity means signal is available at rising edge of BCLK
  50. * - "inverted" polarity means signal is available at falling edge of BCLK
  51. *
  52. * FSYNC "normal" polarity depends on the frame format:
  53. * - I2S: frame consists of left then right channel data. Left channel starts
  54. * with falling FSYNC edge, right channel starts with rising FSYNC edge.
  55. * - Left/Right Justified: frame consists of left then right channel data.
  56. * Left channel starts with rising FSYNC edge, right channel starts with
  57. * falling FSYNC edge.
  58. * - DSP A/B: Frame starts with rising FSYNC edge.
  59. * - AC97: Frame starts with rising FSYNC edge.
  60. *
  61. * "Negative" FSYNC polarity is the one opposite of "normal" polarity.
  62. */
  63. #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */
  64. #define SND_SOC_DAIFMT_NB_IF (2 << 8) /* normal BCLK + inv FRM */
  65. #define SND_SOC_DAIFMT_IB_NF (3 << 8) /* invert BCLK + nor FRM */
  66. #define SND_SOC_DAIFMT_IB_IF (4 << 8) /* invert BCLK + FRM */
  67. /*
  68. * DAI hardware clock masters.
  69. *
  70. * This is wrt the codec, the inverse is true for the interface
  71. * i.e. if the codec is clk and FRM master then the interface is
  72. * clk and frame slave.
  73. */
  74. #define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & FRM master */
  75. #define SND_SOC_DAIFMT_CBS_CFM (2 << 12) /* codec clk slave & FRM master */
  76. #define SND_SOC_DAIFMT_CBM_CFS (3 << 12) /* codec clk master & frame slave */
  77. #define SND_SOC_DAIFMT_CBS_CFS (4 << 12) /* codec clk & FRM slave */
  78. #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
  79. #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
  80. #define SND_SOC_DAIFMT_INV_MASK 0x0f00
  81. #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
  82. /*
  83. * Master Clock Directions
  84. */
  85. #define SND_SOC_CLOCK_IN 0
  86. #define SND_SOC_CLOCK_OUT 1
  87. #define SND_SOC_STD_AC97_FMTS (SNDRV_PCM_FMTBIT_S8 |\
  88. SNDRV_PCM_FMTBIT_S16_LE |\
  89. SNDRV_PCM_FMTBIT_S16_BE |\
  90. SNDRV_PCM_FMTBIT_S20_3LE |\
  91. SNDRV_PCM_FMTBIT_S20_3BE |\
  92. SNDRV_PCM_FMTBIT_S24_3LE |\
  93. SNDRV_PCM_FMTBIT_S24_3BE |\
  94. SNDRV_PCM_FMTBIT_S32_LE |\
  95. SNDRV_PCM_FMTBIT_S32_BE)
  96. struct snd_soc_dai_driver;
  97. struct snd_soc_dai;
  98. struct snd_ac97_bus_ops;
  99. /* Digital Audio Interface clocking API.*/
  100. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  101. unsigned int freq, int dir);
  102. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  103. int div_id, int div);
  104. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  105. int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
  106. int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
  107. /* Digital Audio interface formatting */
  108. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  109. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  110. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width);
  111. int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
  112. unsigned int tx_num, unsigned int *tx_slot,
  113. unsigned int rx_num, unsigned int *rx_slot);
  114. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
  115. /* Digital Audio Interface mute */
  116. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
  117. int direction);
  118. int snd_soc_dai_is_dummy(struct snd_soc_dai *dai);
  119. struct snd_soc_dai_ops {
  120. /*
  121. * DAI clocking configuration, all optional.
  122. * Called by soc_card drivers, normally in their hw_params.
  123. */
  124. int (*set_sysclk)(struct snd_soc_dai *dai,
  125. int clk_id, unsigned int freq, int dir);
  126. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  127. unsigned int freq_in, unsigned int freq_out);
  128. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  129. int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
  130. /*
  131. * DAI format configuration
  132. * Called by soc_card drivers, normally in their hw_params.
  133. */
  134. int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
  135. int (*xlate_tdm_slot_mask)(unsigned int slots,
  136. unsigned int *tx_mask, unsigned int *rx_mask);
  137. int (*set_tdm_slot)(struct snd_soc_dai *dai,
  138. unsigned int tx_mask, unsigned int rx_mask,
  139. int slots, int slot_width);
  140. int (*set_channel_map)(struct snd_soc_dai *dai,
  141. unsigned int tx_num, unsigned int *tx_slot,
  142. unsigned int rx_num, unsigned int *rx_slot);
  143. int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
  144. /*
  145. * DAI digital mute - optional.
  146. * Called by soc-core to minimise any pops.
  147. */
  148. int (*digital_mute)(struct snd_soc_dai *dai, int mute);
  149. int (*mute_stream)(struct snd_soc_dai *dai, int mute, int stream);
  150. /*
  151. * ALSA PCM audio operations - all optional.
  152. * Called by soc-core during audio PCM operations.
  153. */
  154. int (*startup)(struct snd_pcm_substream *,
  155. struct snd_soc_dai *);
  156. void (*shutdown)(struct snd_pcm_substream *,
  157. struct snd_soc_dai *);
  158. int (*hw_params)(struct snd_pcm_substream *,
  159. struct snd_pcm_hw_params *, struct snd_soc_dai *);
  160. int (*hw_free)(struct snd_pcm_substream *,
  161. struct snd_soc_dai *);
  162. int (*prepare)(struct snd_pcm_substream *,
  163. struct snd_soc_dai *);
  164. /*
  165. * NOTE: Commands passed to the trigger function are not necessarily
  166. * compatible with the current state of the dai. For example this
  167. * sequence of commands is possible: START STOP STOP.
  168. * So do not unconditionally use refcounting functions in the trigger
  169. * function, e.g. clk_enable/disable.
  170. */
  171. int (*trigger)(struct snd_pcm_substream *, int,
  172. struct snd_soc_dai *);
  173. int (*bespoke_trigger)(struct snd_pcm_substream *, int,
  174. struct snd_soc_dai *);
  175. /*
  176. * For hardware based FIFO caused delay reporting.
  177. * Optional.
  178. */
  179. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  180. struct snd_soc_dai *);
  181. };
  182. /*
  183. * Digital Audio Interface Driver.
  184. *
  185. * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97
  186. * operations and capabilities. Codec and platform drivers will register this
  187. * structure for every DAI they have.
  188. *
  189. * This structure covers the clocking, formating and ALSA operations for each
  190. * interface.
  191. */
  192. struct snd_soc_dai_driver {
  193. /* DAI description */
  194. const char *name;
  195. unsigned int id;
  196. unsigned int base;
  197. /* DAI driver callbacks */
  198. int (*probe)(struct snd_soc_dai *dai);
  199. int (*remove)(struct snd_soc_dai *dai);
  200. int (*suspend)(struct snd_soc_dai *dai);
  201. int (*resume)(struct snd_soc_dai *dai);
  202. /* compress dai */
  203. int (*compress_new)(struct snd_soc_pcm_runtime *rtd, int num);
  204. /* DAI is also used for the control bus */
  205. bool bus_control;
  206. /* ops */
  207. const struct snd_soc_dai_ops *ops;
  208. /* DAI capabilities */
  209. struct snd_soc_pcm_stream capture;
  210. struct snd_soc_pcm_stream playback;
  211. unsigned int symmetric_rates:1;
  212. unsigned int symmetric_channels:1;
  213. unsigned int symmetric_samplebits:1;
  214. /* probe ordering - for components with runtime dependencies */
  215. int probe_order;
  216. int remove_order;
  217. };
  218. /*
  219. * Digital Audio Interface runtime data.
  220. *
  221. * Holds runtime data for a DAI.
  222. */
  223. struct snd_soc_dai {
  224. const char *name;
  225. int id;
  226. struct device *dev;
  227. /* driver ops */
  228. struct snd_soc_dai_driver *driver;
  229. /* DAI runtime info */
  230. unsigned int capture_active:1; /* stream is in use */
  231. unsigned int playback_active:1; /* stream is in use */
  232. unsigned int symmetric_rates:1;
  233. unsigned int symmetric_channels:1;
  234. unsigned int symmetric_samplebits:1;
  235. unsigned int active;
  236. unsigned char probed:1;
  237. struct snd_soc_dapm_widget *playback_widget;
  238. struct snd_soc_dapm_widget *capture_widget;
  239. /* DAI DMA data */
  240. void *playback_dma_data;
  241. void *capture_dma_data;
  242. /* Symmetry data - only valid if symmetry is being enforced */
  243. unsigned int rate;
  244. unsigned int channels;
  245. unsigned int sample_bits;
  246. /* parent platform/codec */
  247. struct snd_soc_codec *codec;
  248. struct snd_soc_component *component;
  249. /* CODEC TDM slot masks and params (for fixup) */
  250. unsigned int tx_mask;
  251. unsigned int rx_mask;
  252. struct list_head list;
  253. };
  254. static inline void *snd_soc_dai_get_dma_data(const struct snd_soc_dai *dai,
  255. const struct snd_pcm_substream *ss)
  256. {
  257. return (ss->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  258. dai->playback_dma_data : dai->capture_dma_data;
  259. }
  260. static inline void snd_soc_dai_set_dma_data(struct snd_soc_dai *dai,
  261. const struct snd_pcm_substream *ss,
  262. void *data)
  263. {
  264. if (ss->stream == SNDRV_PCM_STREAM_PLAYBACK)
  265. dai->playback_dma_data = data;
  266. else
  267. dai->capture_dma_data = data;
  268. }
  269. static inline void snd_soc_dai_init_dma_data(struct snd_soc_dai *dai,
  270. void *playback, void *capture)
  271. {
  272. dai->playback_dma_data = playback;
  273. dai->capture_dma_data = capture;
  274. }
  275. static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai,
  276. void *data)
  277. {
  278. dev_set_drvdata(dai->dev, data);
  279. }
  280. static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai)
  281. {
  282. return dev_get_drvdata(dai->dev);
  283. }
  284. #endif