soc-dai.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 inversions.
  44. *
  45. * Specifies whether the DAI can also support inverted clocks for the specified
  46. * format.
  47. */
  48. #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */
  49. #define SND_SOC_DAIFMT_NB_IF (2 << 8) /* normal BCLK + inv FRM */
  50. #define SND_SOC_DAIFMT_IB_NF (3 << 8) /* invert BCLK + nor FRM */
  51. #define SND_SOC_DAIFMT_IB_IF (4 << 8) /* invert BCLK + FRM */
  52. /*
  53. * DAI hardware clock masters.
  54. *
  55. * This is wrt the codec, the inverse is true for the interface
  56. * i.e. if the codec is clk and FRM master then the interface is
  57. * clk and frame slave.
  58. */
  59. #define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & FRM master */
  60. #define SND_SOC_DAIFMT_CBS_CFM (2 << 12) /* codec clk slave & FRM master */
  61. #define SND_SOC_DAIFMT_CBM_CFS (3 << 12) /* codec clk master & frame slave */
  62. #define SND_SOC_DAIFMT_CBS_CFS (4 << 12) /* codec clk & FRM slave */
  63. #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
  64. #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
  65. #define SND_SOC_DAIFMT_INV_MASK 0x0f00
  66. #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
  67. /*
  68. * Master Clock Directions
  69. */
  70. #define SND_SOC_CLOCK_IN 0
  71. #define SND_SOC_CLOCK_OUT 1
  72. #define SND_SOC_STD_AC97_FMTS (SNDRV_PCM_FMTBIT_S8 |\
  73. SNDRV_PCM_FMTBIT_S16_LE |\
  74. SNDRV_PCM_FMTBIT_S16_BE |\
  75. SNDRV_PCM_FMTBIT_S20_3LE |\
  76. SNDRV_PCM_FMTBIT_S20_3BE |\
  77. SNDRV_PCM_FMTBIT_S24_3LE |\
  78. SNDRV_PCM_FMTBIT_S24_3BE |\
  79. SNDRV_PCM_FMTBIT_S32_LE |\
  80. SNDRV_PCM_FMTBIT_S32_BE)
  81. struct snd_soc_dai_driver;
  82. struct snd_soc_dai;
  83. struct snd_ac97_bus_ops;
  84. /* Digital Audio Interface clocking API.*/
  85. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  86. unsigned int freq, int dir);
  87. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  88. int div_id, int div);
  89. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  90. int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
  91. int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
  92. /* Digital Audio interface formatting */
  93. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  94. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  95. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width);
  96. int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
  97. unsigned int tx_num, unsigned int *tx_slot,
  98. unsigned int rx_num, unsigned int *rx_slot);
  99. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
  100. /* Digital Audio Interface mute */
  101. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
  102. int direction);
  103. int snd_soc_dai_is_dummy(struct snd_soc_dai *dai);
  104. struct snd_soc_dai_ops {
  105. /*
  106. * DAI clocking configuration, all optional.
  107. * Called by soc_card drivers, normally in their hw_params.
  108. */
  109. int (*set_sysclk)(struct snd_soc_dai *dai,
  110. int clk_id, unsigned int freq, int dir);
  111. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  112. unsigned int freq_in, unsigned int freq_out);
  113. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  114. int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
  115. /*
  116. * DAI format configuration
  117. * Called by soc_card drivers, normally in their hw_params.
  118. */
  119. int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
  120. int (*xlate_tdm_slot_mask)(unsigned int slots,
  121. unsigned int *tx_mask, unsigned int *rx_mask);
  122. int (*set_tdm_slot)(struct snd_soc_dai *dai,
  123. unsigned int tx_mask, unsigned int rx_mask,
  124. int slots, int slot_width);
  125. int (*set_channel_map)(struct snd_soc_dai *dai,
  126. unsigned int tx_num, unsigned int *tx_slot,
  127. unsigned int rx_num, unsigned int *rx_slot);
  128. int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
  129. /*
  130. * DAI digital mute - optional.
  131. * Called by soc-core to minimise any pops.
  132. */
  133. int (*digital_mute)(struct snd_soc_dai *dai, int mute);
  134. int (*mute_stream)(struct snd_soc_dai *dai, int mute, int stream);
  135. /*
  136. * ALSA PCM audio operations - all optional.
  137. * Called by soc-core during audio PCM operations.
  138. */
  139. int (*startup)(struct snd_pcm_substream *,
  140. struct snd_soc_dai *);
  141. void (*shutdown)(struct snd_pcm_substream *,
  142. struct snd_soc_dai *);
  143. int (*hw_params)(struct snd_pcm_substream *,
  144. struct snd_pcm_hw_params *, struct snd_soc_dai *);
  145. int (*hw_free)(struct snd_pcm_substream *,
  146. struct snd_soc_dai *);
  147. int (*prepare)(struct snd_pcm_substream *,
  148. struct snd_soc_dai *);
  149. /*
  150. * NOTE: Commands passed to the trigger function are not necessarily
  151. * compatible with the current state of the dai. For example this
  152. * sequence of commands is possible: START STOP STOP.
  153. * So do not unconditionally use refcounting functions in the trigger
  154. * function, e.g. clk_enable/disable.
  155. */
  156. int (*trigger)(struct snd_pcm_substream *, int,
  157. struct snd_soc_dai *);
  158. int (*bespoke_trigger)(struct snd_pcm_substream *, int,
  159. struct snd_soc_dai *);
  160. /*
  161. * For hardware based FIFO caused delay reporting.
  162. * Optional.
  163. */
  164. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  165. struct snd_soc_dai *);
  166. };
  167. /*
  168. * Digital Audio Interface Driver.
  169. *
  170. * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97
  171. * operations and capabilities. Codec and platform drivers will register this
  172. * structure for every DAI they have.
  173. *
  174. * This structure covers the clocking, formating and ALSA operations for each
  175. * interface.
  176. */
  177. struct snd_soc_dai_driver {
  178. /* DAI description */
  179. const char *name;
  180. unsigned int id;
  181. unsigned int base;
  182. /* DAI driver callbacks */
  183. int (*probe)(struct snd_soc_dai *dai);
  184. int (*remove)(struct snd_soc_dai *dai);
  185. int (*suspend)(struct snd_soc_dai *dai);
  186. int (*resume)(struct snd_soc_dai *dai);
  187. /* compress dai */
  188. bool compress_dai;
  189. /* DAI is also used for the control bus */
  190. bool bus_control;
  191. /* ops */
  192. const struct snd_soc_dai_ops *ops;
  193. /* DAI capabilities */
  194. struct snd_soc_pcm_stream capture;
  195. struct snd_soc_pcm_stream playback;
  196. unsigned int symmetric_rates:1;
  197. unsigned int symmetric_channels:1;
  198. unsigned int symmetric_samplebits:1;
  199. /* probe ordering - for components with runtime dependencies */
  200. int probe_order;
  201. int remove_order;
  202. };
  203. /*
  204. * Digital Audio Interface runtime data.
  205. *
  206. * Holds runtime data for a DAI.
  207. */
  208. struct snd_soc_dai {
  209. const char *name;
  210. int id;
  211. struct device *dev;
  212. /* driver ops */
  213. struct snd_soc_dai_driver *driver;
  214. /* DAI runtime info */
  215. unsigned int capture_active:1; /* stream is in use */
  216. unsigned int playback_active:1; /* stream is in use */
  217. unsigned int symmetric_rates:1;
  218. unsigned int symmetric_channels:1;
  219. unsigned int symmetric_samplebits:1;
  220. unsigned int active;
  221. unsigned char probed:1;
  222. struct snd_soc_dapm_widget *playback_widget;
  223. struct snd_soc_dapm_widget *capture_widget;
  224. /* DAI DMA data */
  225. void *playback_dma_data;
  226. void *capture_dma_data;
  227. /* Symmetry data - only valid if symmetry is being enforced */
  228. unsigned int rate;
  229. unsigned int channels;
  230. unsigned int sample_bits;
  231. /* parent platform/codec */
  232. struct snd_soc_codec *codec;
  233. struct snd_soc_component *component;
  234. /* CODEC TDM slot masks and params (for fixup) */
  235. unsigned int tx_mask;
  236. unsigned int rx_mask;
  237. struct list_head list;
  238. };
  239. static inline void *snd_soc_dai_get_dma_data(const struct snd_soc_dai *dai,
  240. const struct snd_pcm_substream *ss)
  241. {
  242. return (ss->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  243. dai->playback_dma_data : dai->capture_dma_data;
  244. }
  245. static inline void snd_soc_dai_set_dma_data(struct snd_soc_dai *dai,
  246. const struct snd_pcm_substream *ss,
  247. void *data)
  248. {
  249. if (ss->stream == SNDRV_PCM_STREAM_PLAYBACK)
  250. dai->playback_dma_data = data;
  251. else
  252. dai->capture_dma_data = data;
  253. }
  254. static inline void snd_soc_dai_init_dma_data(struct snd_soc_dai *dai,
  255. void *playback, void *capture)
  256. {
  257. dai->playback_dma_data = playback;
  258. dai->capture_dma_data = capture;
  259. }
  260. static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai,
  261. void *data)
  262. {
  263. dev_set_drvdata(dai->dev, data);
  264. }
  265. static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai)
  266. {
  267. return dev_get_drvdata(dai->dev);
  268. }
  269. #endif