soc-dai.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. /*
  17. * DAI hardware audio formats.
  18. *
  19. * Describes the physical PCM data formating and clocking. Add new formats
  20. * to the end.
  21. */
  22. #define SND_SOC_DAIFMT_I2S 0 /* I2S mode */
  23. #define SND_SOC_DAIFMT_RIGHT_J 1 /* Right Justified mode */
  24. #define SND_SOC_DAIFMT_LEFT_J 2 /* Left Justified mode */
  25. #define SND_SOC_DAIFMT_DSP_A 3 /* L data MSB after FRM LRC */
  26. #define SND_SOC_DAIFMT_DSP_B 4 /* L data MSB during FRM LRC */
  27. #define SND_SOC_DAIFMT_AC97 5 /* AC97 */
  28. #define SND_SOC_DAIFMT_PDM 6 /* Pulse density modulation */
  29. /* left and right justified also known as MSB and LSB respectively */
  30. #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
  31. #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
  32. /*
  33. * DAI Clock gating.
  34. *
  35. * DAI bit clocks can be be gated (disabled) when the DAI is not
  36. * sending or receiving PCM data in a frame. This can be used to save power.
  37. */
  38. #define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */
  39. #define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated */
  40. /*
  41. * DAI hardware signal inversions.
  42. *
  43. * Specifies whether the DAI can also support inverted clocks for the specified
  44. * format.
  45. */
  46. #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */
  47. #define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal BCLK + inv FRM */
  48. #define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert BCLK + nor FRM */
  49. #define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert BCLK + FRM */
  50. /*
  51. * DAI hardware clock masters.
  52. *
  53. * This is wrt the codec, the inverse is true for the interface
  54. * i.e. if the codec is clk and FRM master then the interface is
  55. * clk and frame slave.
  56. */
  57. #define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & FRM master */
  58. #define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & FRM master */
  59. #define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */
  60. #define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & FRM slave */
  61. #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
  62. #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
  63. #define SND_SOC_DAIFMT_INV_MASK 0x0f00
  64. #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
  65. /*
  66. * Master Clock Directions
  67. */
  68. #define SND_SOC_CLOCK_IN 0
  69. #define SND_SOC_CLOCK_OUT 1
  70. #define SND_SOC_STD_AC97_FMTS (SNDRV_PCM_FMTBIT_S8 |\
  71. SNDRV_PCM_FMTBIT_S16_LE |\
  72. SNDRV_PCM_FMTBIT_S16_BE |\
  73. SNDRV_PCM_FMTBIT_S20_3LE |\
  74. SNDRV_PCM_FMTBIT_S20_3BE |\
  75. SNDRV_PCM_FMTBIT_S24_3LE |\
  76. SNDRV_PCM_FMTBIT_S24_3BE |\
  77. SNDRV_PCM_FMTBIT_S32_LE |\
  78. SNDRV_PCM_FMTBIT_S32_BE)
  79. struct snd_soc_dai_driver;
  80. struct snd_soc_dai;
  81. struct snd_ac97_bus_ops;
  82. /* Digital Audio Interface registration */
  83. int snd_soc_register_dai(struct device *dev,
  84. struct snd_soc_dai_driver *dai_drv);
  85. void snd_soc_unregister_dai(struct device *dev);
  86. int snd_soc_register_dais(struct device *dev,
  87. struct snd_soc_dai_driver *dai_drv, size_t count);
  88. void snd_soc_unregister_dais(struct device *dev, size_t count);
  89. /* Digital Audio Interface clocking API.*/
  90. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  91. unsigned int freq, int dir);
  92. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  93. int div_id, int div);
  94. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  95. int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
  96. /* Digital Audio interface formatting */
  97. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  98. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  99. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width);
  100. int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
  101. unsigned int tx_num, unsigned int *tx_slot,
  102. unsigned int rx_num, unsigned int *rx_slot);
  103. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
  104. /* Digital Audio Interface mute */
  105. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute);
  106. struct snd_soc_dai_ops {
  107. /*
  108. * DAI clocking configuration, all optional.
  109. * Called by soc_card drivers, normally in their hw_params.
  110. */
  111. int (*set_sysclk)(struct snd_soc_dai *dai,
  112. int clk_id, unsigned int freq, int dir);
  113. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  114. unsigned int freq_in, unsigned int freq_out);
  115. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  116. /*
  117. * DAI format configuration
  118. * Called by soc_card drivers, normally in their hw_params.
  119. */
  120. int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
  121. int (*set_tdm_slot)(struct snd_soc_dai *dai,
  122. unsigned int tx_mask, unsigned int rx_mask,
  123. int slots, int slot_width);
  124. int (*set_channel_map)(struct snd_soc_dai *dai,
  125. unsigned int tx_num, unsigned int *tx_slot,
  126. unsigned int rx_num, unsigned int *rx_slot);
  127. int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
  128. /*
  129. * DAI digital mute - optional.
  130. * Called by soc-core to minimise any pops.
  131. */
  132. int (*digital_mute)(struct snd_soc_dai *dai, int mute);
  133. /*
  134. * ALSA PCM audio operations - all optional.
  135. * Called by soc-core during audio PCM operations.
  136. */
  137. int (*startup)(struct snd_pcm_substream *,
  138. struct snd_soc_dai *);
  139. void (*shutdown)(struct snd_pcm_substream *,
  140. struct snd_soc_dai *);
  141. int (*hw_params)(struct snd_pcm_substream *,
  142. struct snd_pcm_hw_params *, struct snd_soc_dai *);
  143. int (*hw_free)(struct snd_pcm_substream *,
  144. struct snd_soc_dai *);
  145. int (*prepare)(struct snd_pcm_substream *,
  146. struct snd_soc_dai *);
  147. int (*trigger)(struct snd_pcm_substream *, int,
  148. struct snd_soc_dai *);
  149. /*
  150. * For hardware based FIFO caused delay reporting.
  151. * Optional.
  152. */
  153. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  154. struct snd_soc_dai *);
  155. };
  156. /*
  157. * Digital Audio Interface Driver.
  158. *
  159. * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97
  160. * operations and capabilities. Codec and platform drivers will register this
  161. * structure for every DAI they have.
  162. *
  163. * This structure covers the clocking, formating and ALSA operations for each
  164. * interface.
  165. */
  166. struct snd_soc_dai_driver {
  167. /* DAI description */
  168. const char *name;
  169. unsigned int id;
  170. int ac97_control;
  171. /* DAI driver callbacks */
  172. int (*probe)(struct snd_soc_dai *dai);
  173. int (*remove)(struct snd_soc_dai *dai);
  174. int (*suspend)(struct snd_soc_dai *dai);
  175. int (*resume)(struct snd_soc_dai *dai);
  176. /* ops */
  177. const struct snd_soc_dai_ops *ops;
  178. /* DAI capabilities */
  179. struct snd_soc_pcm_stream capture;
  180. struct snd_soc_pcm_stream playback;
  181. unsigned int symmetric_rates:1;
  182. /* probe ordering - for components with runtime dependencies */
  183. int probe_order;
  184. int remove_order;
  185. };
  186. /*
  187. * Digital Audio Interface runtime data.
  188. *
  189. * Holds runtime data for a DAI.
  190. */
  191. struct snd_soc_dai {
  192. const char *name;
  193. int id;
  194. struct device *dev;
  195. void *ac97_pdata; /* platform_data for the ac97 codec */
  196. /* driver ops */
  197. struct snd_soc_dai_driver *driver;
  198. /* DAI runtime info */
  199. unsigned int capture_active:1; /* stream is in use */
  200. unsigned int playback_active:1; /* stream is in use */
  201. unsigned int symmetric_rates:1;
  202. struct snd_pcm_runtime *runtime;
  203. unsigned int active;
  204. unsigned char pop_wait:1;
  205. unsigned char probed:1;
  206. /* DAI DMA data */
  207. void *playback_dma_data;
  208. void *capture_dma_data;
  209. /* parent platform/codec */
  210. union {
  211. struct snd_soc_platform *platform;
  212. struct snd_soc_codec *codec;
  213. };
  214. struct snd_soc_card *card;
  215. struct list_head list;
  216. struct list_head card_list;
  217. };
  218. static inline void *snd_soc_dai_get_dma_data(const struct snd_soc_dai *dai,
  219. const struct snd_pcm_substream *ss)
  220. {
  221. return (ss->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  222. dai->playback_dma_data : dai->capture_dma_data;
  223. }
  224. static inline void snd_soc_dai_set_dma_data(struct snd_soc_dai *dai,
  225. const struct snd_pcm_substream *ss,
  226. void *data)
  227. {
  228. if (ss->stream == SNDRV_PCM_STREAM_PLAYBACK)
  229. dai->playback_dma_data = data;
  230. else
  231. dai->capture_dma_data = data;
  232. }
  233. static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai,
  234. void *data)
  235. {
  236. dev_set_drvdata(dai->dev, data);
  237. }
  238. static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai)
  239. {
  240. return dev_get_drvdata(dai->dev);
  241. }
  242. #endif