soc-dai.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. /* left and right justified also known as MSB and LSB respectively */
  29. #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
  30. #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
  31. /*
  32. * DAI Clock gating.
  33. *
  34. * DAI bit clocks can be be gated (disabled) when the DAI is not
  35. * sending or receiving PCM data in a frame. This can be used to save power.
  36. */
  37. #define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */
  38. #define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated */
  39. /*
  40. * DAI hardware signal inversions.
  41. *
  42. * Specifies whether the DAI can also support inverted clocks for the specified
  43. * format.
  44. */
  45. #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */
  46. #define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal BCLK + inv FRM */
  47. #define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert BCLK + nor FRM */
  48. #define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert BCLK + FRM */
  49. /*
  50. * DAI hardware clock masters.
  51. *
  52. * This is wrt the codec, the inverse is true for the interface
  53. * i.e. if the codec is clk and FRM master then the interface is
  54. * clk and frame slave.
  55. */
  56. #define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & FRM master */
  57. #define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & FRM master */
  58. #define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */
  59. #define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & FRM slave */
  60. #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
  61. #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
  62. #define SND_SOC_DAIFMT_INV_MASK 0x0f00
  63. #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
  64. /*
  65. * Master Clock Directions
  66. */
  67. #define SND_SOC_CLOCK_IN 0
  68. #define SND_SOC_CLOCK_OUT 1
  69. #define SND_SOC_STD_AC97_FMTS (SNDRV_PCM_FMTBIT_S8 |\
  70. SNDRV_PCM_FMTBIT_S16_LE |\
  71. SNDRV_PCM_FMTBIT_S16_BE |\
  72. SNDRV_PCM_FMTBIT_S20_3LE |\
  73. SNDRV_PCM_FMTBIT_S20_3BE |\
  74. SNDRV_PCM_FMTBIT_S24_3LE |\
  75. SNDRV_PCM_FMTBIT_S24_3BE |\
  76. SNDRV_PCM_FMTBIT_S32_LE |\
  77. SNDRV_PCM_FMTBIT_S32_BE)
  78. struct snd_soc_dai_ops;
  79. struct snd_soc_dai;
  80. struct snd_ac97_bus_ops;
  81. /* Digital Audio Interface registration */
  82. int snd_soc_register_dai(struct snd_soc_dai *dai);
  83. void snd_soc_unregister_dai(struct snd_soc_dai *dai);
  84. int snd_soc_register_dais(struct snd_soc_dai *dai, size_t count);
  85. void snd_soc_unregister_dais(struct snd_soc_dai *dai, size_t count);
  86. /* Digital Audio Interface clocking API.*/
  87. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  88. unsigned int freq, int dir);
  89. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  90. int div_id, int div);
  91. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  92. int pll_id, unsigned int freq_in, unsigned int freq_out);
  93. /* Digital Audio interface formatting */
  94. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  95. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  96. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width);
  97. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
  98. /* Digital Audio Interface mute */
  99. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute);
  100. /*
  101. * Digital Audio Interface.
  102. *
  103. * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97
  104. * operations and capabilities. Codec and platform drivers will register this
  105. * structure for every DAI they have.
  106. *
  107. * This structure covers the clocking, formating and ALSA operations for each
  108. * interface.
  109. */
  110. struct snd_soc_dai_ops {
  111. /*
  112. * DAI clocking configuration, all optional.
  113. * Called by soc_card drivers, normally in their hw_params.
  114. */
  115. int (*set_sysclk)(struct snd_soc_dai *dai,
  116. int clk_id, unsigned int freq, int dir);
  117. int (*set_pll)(struct snd_soc_dai *dai,
  118. int pll_id, unsigned int freq_in, unsigned int freq_out);
  119. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  120. /*
  121. * DAI format configuration
  122. * Called by soc_card drivers, normally in their hw_params.
  123. */
  124. int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
  125. int (*set_tdm_slot)(struct snd_soc_dai *dai,
  126. unsigned int tx_mask, unsigned int rx_mask,
  127. int slots, int slot_width);
  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. /*
  135. * ALSA PCM audio operations - all optional.
  136. * Called by soc-core during audio PCM operations.
  137. */
  138. int (*startup)(struct snd_pcm_substream *,
  139. struct snd_soc_dai *);
  140. void (*shutdown)(struct snd_pcm_substream *,
  141. struct snd_soc_dai *);
  142. int (*hw_params)(struct snd_pcm_substream *,
  143. struct snd_pcm_hw_params *, struct snd_soc_dai *);
  144. int (*hw_free)(struct snd_pcm_substream *,
  145. struct snd_soc_dai *);
  146. int (*prepare)(struct snd_pcm_substream *,
  147. struct snd_soc_dai *);
  148. int (*trigger)(struct snd_pcm_substream *, int,
  149. struct snd_soc_dai *);
  150. };
  151. /*
  152. * Digital Audio Interface runtime data.
  153. *
  154. * Holds runtime data for a DAI.
  155. */
  156. struct snd_soc_dai {
  157. /* DAI description */
  158. char *name;
  159. unsigned int id;
  160. int ac97_control;
  161. struct device *dev;
  162. void *ac97_pdata; /* platform_data for the ac97 codec */
  163. /* DAI callbacks */
  164. int (*probe)(struct platform_device *pdev,
  165. struct snd_soc_dai *dai);
  166. void (*remove)(struct platform_device *pdev,
  167. struct snd_soc_dai *dai);
  168. int (*suspend)(struct snd_soc_dai *dai);
  169. int (*resume)(struct snd_soc_dai *dai);
  170. /* ops */
  171. struct snd_soc_dai_ops *ops;
  172. /* DAI capabilities */
  173. struct snd_soc_pcm_stream capture;
  174. struct snd_soc_pcm_stream playback;
  175. unsigned int symmetric_rates:1;
  176. /* DAI runtime info */
  177. struct snd_pcm_runtime *runtime;
  178. struct snd_soc_codec *codec;
  179. unsigned int active;
  180. unsigned char pop_wait:1;
  181. void *dma_data;
  182. /* DAI private data */
  183. void *private_data;
  184. /* parent platform */
  185. struct snd_soc_platform *platform;
  186. struct list_head list;
  187. };
  188. #endif