soc-dai.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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, int source, 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_channel_map(struct snd_soc_dai *dai,
  98. unsigned int tx_num, unsigned int *tx_slot,
  99. unsigned int rx_num, unsigned int *rx_slot);
  100. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
  101. /* Digital Audio Interface mute */
  102. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute);
  103. /*
  104. * Digital Audio Interface.
  105. *
  106. * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97
  107. * operations and capabilities. Codec and platform drivers will register this
  108. * structure for every DAI they have.
  109. *
  110. * This structure covers the clocking, formating and ALSA operations for each
  111. * interface.
  112. */
  113. struct snd_soc_dai_ops {
  114. /*
  115. * DAI clocking configuration, all optional.
  116. * Called by soc_card drivers, normally in their hw_params.
  117. */
  118. int (*set_sysclk)(struct snd_soc_dai *dai,
  119. int clk_id, unsigned int freq, int dir);
  120. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  121. unsigned int freq_in, unsigned int freq_out);
  122. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  123. /*
  124. * DAI format configuration
  125. * Called by soc_card drivers, normally in their hw_params.
  126. */
  127. int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
  128. int (*set_tdm_slot)(struct snd_soc_dai *dai,
  129. unsigned int tx_mask, unsigned int rx_mask,
  130. int slots, int slot_width);
  131. int (*set_channel_map)(struct snd_soc_dai *dai,
  132. unsigned int tx_num, unsigned int *tx_slot,
  133. unsigned int rx_num, unsigned int *rx_slot);
  134. int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
  135. /*
  136. * DAI digital mute - optional.
  137. * Called by soc-core to minimise any pops.
  138. */
  139. int (*digital_mute)(struct snd_soc_dai *dai, int mute);
  140. /*
  141. * ALSA PCM audio operations - all optional.
  142. * Called by soc-core during audio PCM operations.
  143. */
  144. int (*startup)(struct snd_pcm_substream *,
  145. struct snd_soc_dai *);
  146. void (*shutdown)(struct snd_pcm_substream *,
  147. struct snd_soc_dai *);
  148. int (*hw_params)(struct snd_pcm_substream *,
  149. struct snd_pcm_hw_params *, struct snd_soc_dai *);
  150. int (*hw_free)(struct snd_pcm_substream *,
  151. struct snd_soc_dai *);
  152. int (*prepare)(struct snd_pcm_substream *,
  153. struct snd_soc_dai *);
  154. int (*trigger)(struct snd_pcm_substream *, int,
  155. struct snd_soc_dai *);
  156. };
  157. /*
  158. * Digital Audio Interface runtime data.
  159. *
  160. * Holds runtime data for a DAI.
  161. */
  162. struct snd_soc_dai {
  163. /* DAI description */
  164. char *name;
  165. unsigned int id;
  166. int ac97_control;
  167. struct device *dev;
  168. void *ac97_pdata; /* platform_data for the ac97 codec */
  169. /* DAI callbacks */
  170. int (*probe)(struct platform_device *pdev,
  171. struct snd_soc_dai *dai);
  172. void (*remove)(struct platform_device *pdev,
  173. struct snd_soc_dai *dai);
  174. int (*suspend)(struct snd_soc_dai *dai);
  175. int (*resume)(struct snd_soc_dai *dai);
  176. /* ops */
  177. 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. /* DAI runtime info */
  183. struct snd_pcm_runtime *runtime;
  184. struct snd_soc_codec *codec;
  185. unsigned int active;
  186. unsigned char pop_wait:1;
  187. void *dma_data;
  188. /* DAI private data */
  189. void *private_data;
  190. /* parent platform */
  191. struct snd_soc_platform *platform;
  192. struct list_head list;
  193. };
  194. #endif