soc-dai.h 7.6 KB

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