soc-dai.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * linux/sound/soc-dai.h -- ALSA SoC Layer
  4. *
  5. * Copyright: 2005-2008 Wolfson Microelectronics. PLC.
  6. *
  7. * Digital Audio Interface (DAI) API.
  8. */
  9. #ifndef __LINUX_SND_SOC_DAI_H
  10. #define __LINUX_SND_SOC_DAI_H
  11. #include <linux/list.h>
  12. #include <sound/asoc.h>
  13. struct snd_pcm_substream;
  14. struct snd_soc_dapm_widget;
  15. struct snd_compr_stream;
  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 SND_SOC_DAI_FORMAT_I2S
  23. #define SND_SOC_DAIFMT_RIGHT_J SND_SOC_DAI_FORMAT_RIGHT_J
  24. #define SND_SOC_DAIFMT_LEFT_J SND_SOC_DAI_FORMAT_LEFT_J
  25. #define SND_SOC_DAIFMT_DSP_A SND_SOC_DAI_FORMAT_DSP_A
  26. #define SND_SOC_DAIFMT_DSP_B SND_SOC_DAI_FORMAT_DSP_B
  27. #define SND_SOC_DAIFMT_AC97 SND_SOC_DAI_FORMAT_AC97
  28. #define SND_SOC_DAIFMT_PDM SND_SOC_DAI_FORMAT_PDM
  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. /* Describes the possible PCM format */
  33. /*
  34. * use SND_SOC_DAI_FORMAT_xx as eash shift.
  35. * see
  36. * snd_soc_runtime_get_dai_fmt()
  37. */
  38. #define SND_SOC_POSSIBLE_DAIFMT_FORMAT_SHIFT 0
  39. #define SND_SOC_POSSIBLE_DAIFMT_FORMAT_MASK (0xFFFF << SND_SOC_POSSIBLE_DAIFMT_FORMAT_SHIFT)
  40. #define SND_SOC_POSSIBLE_DAIFMT_I2S (1 << SND_SOC_DAI_FORMAT_I2S)
  41. #define SND_SOC_POSSIBLE_DAIFMT_RIGHT_J (1 << SND_SOC_DAI_FORMAT_RIGHT_J)
  42. #define SND_SOC_POSSIBLE_DAIFMT_LEFT_J (1 << SND_SOC_DAI_FORMAT_LEFT_J)
  43. #define SND_SOC_POSSIBLE_DAIFMT_DSP_A (1 << SND_SOC_DAI_FORMAT_DSP_A)
  44. #define SND_SOC_POSSIBLE_DAIFMT_DSP_B (1 << SND_SOC_DAI_FORMAT_DSP_B)
  45. #define SND_SOC_POSSIBLE_DAIFMT_AC97 (1 << SND_SOC_DAI_FORMAT_AC97)
  46. #define SND_SOC_POSSIBLE_DAIFMT_PDM (1 << SND_SOC_DAI_FORMAT_PDM)
  47. /*
  48. * DAI Clock gating.
  49. *
  50. * DAI bit clocks can be gated (disabled) when the DAI is not
  51. * sending or receiving PCM data in a frame. This can be used to save power.
  52. */
  53. #define SND_SOC_DAIFMT_CONT (1 << 4) /* continuous clock */
  54. #define SND_SOC_DAIFMT_GATED (0 << 4) /* clock is gated */
  55. /* Describes the possible PCM format */
  56. /*
  57. * define GATED -> CONT. GATED will be selected if both are selected.
  58. * see
  59. * snd_soc_runtime_get_dai_fmt()
  60. */
  61. #define SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT 16
  62. #define SND_SOC_POSSIBLE_DAIFMT_CLOCK_MASK (0xFFFF << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
  63. #define SND_SOC_POSSIBLE_DAIFMT_GATED (0x1ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
  64. #define SND_SOC_POSSIBLE_DAIFMT_CONT (0x2ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
  65. /*
  66. * DAI hardware signal polarity.
  67. *
  68. * Specifies whether the DAI can also support inverted clocks for the specified
  69. * format.
  70. *
  71. * BCLK:
  72. * - "normal" polarity means signal is available at rising edge of BCLK
  73. * - "inverted" polarity means signal is available at falling edge of BCLK
  74. *
  75. * FSYNC "normal" polarity depends on the frame format:
  76. * - I2S: frame consists of left then right channel data. Left channel starts
  77. * with falling FSYNC edge, right channel starts with rising FSYNC edge.
  78. * - Left/Right Justified: frame consists of left then right channel data.
  79. * Left channel starts with rising FSYNC edge, right channel starts with
  80. * falling FSYNC edge.
  81. * - DSP A/B: Frame starts with rising FSYNC edge.
  82. * - AC97: Frame starts with rising FSYNC edge.
  83. *
  84. * "Negative" FSYNC polarity is the one opposite of "normal" polarity.
  85. */
  86. #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */
  87. #define SND_SOC_DAIFMT_NB_IF (2 << 8) /* normal BCLK + inv FRM */
  88. #define SND_SOC_DAIFMT_IB_NF (3 << 8) /* invert BCLK + nor FRM */
  89. #define SND_SOC_DAIFMT_IB_IF (4 << 8) /* invert BCLK + FRM */
  90. /* Describes the possible PCM format */
  91. #define SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT 32
  92. #define SND_SOC_POSSIBLE_DAIFMT_INV_MASK (0xFFFFULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
  93. #define SND_SOC_POSSIBLE_DAIFMT_NB_NF (0x1ULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
  94. #define SND_SOC_POSSIBLE_DAIFMT_NB_IF (0x2ULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
  95. #define SND_SOC_POSSIBLE_DAIFMT_IB_NF (0x4ULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
  96. #define SND_SOC_POSSIBLE_DAIFMT_IB_IF (0x8ULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
  97. /*
  98. * DAI hardware clock providers/consumers
  99. *
  100. * This is wrt the codec, the inverse is true for the interface
  101. * i.e. if the codec is clk and FRM provider then the interface is
  102. * clk and frame consumer.
  103. */
  104. #define SND_SOC_DAIFMT_CBP_CFP (1 << 12) /* codec clk provider & frame provider */
  105. #define SND_SOC_DAIFMT_CBC_CFP (2 << 12) /* codec clk consumer & frame provider */
  106. #define SND_SOC_DAIFMT_CBP_CFC (3 << 12) /* codec clk provider & frame consumer */
  107. #define SND_SOC_DAIFMT_CBC_CFC (4 << 12) /* codec clk consumer & frame consumer */
  108. /* previous definitions kept for backwards-compatibility, do not use in new contributions */
  109. #define SND_SOC_DAIFMT_CBM_CFM SND_SOC_DAIFMT_CBP_CFP
  110. #define SND_SOC_DAIFMT_CBS_CFM SND_SOC_DAIFMT_CBC_CFP
  111. #define SND_SOC_DAIFMT_CBM_CFS SND_SOC_DAIFMT_CBP_CFC
  112. #define SND_SOC_DAIFMT_CBS_CFS SND_SOC_DAIFMT_CBC_CFC
  113. /* when passed to set_fmt directly indicate if the device is provider or consumer */
  114. #define SND_SOC_DAIFMT_BP_FP SND_SOC_DAIFMT_CBP_CFP
  115. #define SND_SOC_DAIFMT_BC_FP SND_SOC_DAIFMT_CBC_CFP
  116. #define SND_SOC_DAIFMT_BP_FC SND_SOC_DAIFMT_CBP_CFC
  117. #define SND_SOC_DAIFMT_BC_FC SND_SOC_DAIFMT_CBC_CFC
  118. /* Describes the possible PCM format */
  119. #define SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT 48
  120. #define SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_MASK (0xFFFFULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
  121. #define SND_SOC_POSSIBLE_DAIFMT_CBP_CFP (0x1ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
  122. #define SND_SOC_POSSIBLE_DAIFMT_CBC_CFP (0x2ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
  123. #define SND_SOC_POSSIBLE_DAIFMT_CBP_CFC (0x4ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
  124. #define SND_SOC_POSSIBLE_DAIFMT_CBC_CFC (0x8ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
  125. #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
  126. #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
  127. #define SND_SOC_DAIFMT_INV_MASK 0x0f00
  128. #define SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK 0xf000
  129. #define SND_SOC_DAIFMT_MASTER_MASK SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK
  130. /*
  131. * Master Clock Directions
  132. */
  133. #define SND_SOC_CLOCK_IN 0
  134. #define SND_SOC_CLOCK_OUT 1
  135. #define SND_SOC_STD_AC97_FMTS (SNDRV_PCM_FMTBIT_S8 |\
  136. SNDRV_PCM_FMTBIT_S16_LE |\
  137. SNDRV_PCM_FMTBIT_S16_BE |\
  138. SNDRV_PCM_FMTBIT_S20_3LE |\
  139. SNDRV_PCM_FMTBIT_S20_3BE |\
  140. SNDRV_PCM_FMTBIT_S20_LE |\
  141. SNDRV_PCM_FMTBIT_S20_BE |\
  142. SNDRV_PCM_FMTBIT_S24_3LE |\
  143. SNDRV_PCM_FMTBIT_S24_3BE |\
  144. SNDRV_PCM_FMTBIT_S32_LE |\
  145. SNDRV_PCM_FMTBIT_S32_BE)
  146. struct snd_soc_dai_driver;
  147. struct snd_soc_dai;
  148. struct snd_ac97_bus_ops;
  149. /* Digital Audio Interface clocking API.*/
  150. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  151. unsigned int freq, int dir);
  152. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  153. int div_id, int div);
  154. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  155. int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
  156. int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
  157. /* Digital Audio interface formatting */
  158. int snd_soc_dai_get_fmt_max_priority(const struct snd_soc_pcm_runtime *rtd);
  159. u64 snd_soc_dai_get_fmt(const struct snd_soc_dai *dai, int priority);
  160. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  161. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  162. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width);
  163. int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
  164. unsigned int tx_num, const unsigned int *tx_slot,
  165. unsigned int rx_num, const unsigned int *rx_slot);
  166. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
  167. /* Digital Audio Interface mute */
  168. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
  169. int direction);
  170. int snd_soc_dai_get_channel_map(const struct snd_soc_dai *dai,
  171. unsigned int *tx_num, unsigned int *tx_slot,
  172. unsigned int *rx_num, unsigned int *rx_slot);
  173. int snd_soc_dai_is_dummy(const struct snd_soc_dai *dai);
  174. int snd_soc_dai_hw_params(struct snd_soc_dai *dai,
  175. struct snd_pcm_substream *substream,
  176. struct snd_pcm_hw_params *params);
  177. void snd_soc_dai_hw_free(struct snd_soc_dai *dai,
  178. struct snd_pcm_substream *substream,
  179. int rollback);
  180. int snd_soc_dai_startup(struct snd_soc_dai *dai,
  181. struct snd_pcm_substream *substream);
  182. void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
  183. struct snd_pcm_substream *substream, int rollback);
  184. void snd_soc_dai_suspend(struct snd_soc_dai *dai);
  185. void snd_soc_dai_resume(struct snd_soc_dai *dai);
  186. int snd_soc_dai_compress_new(struct snd_soc_dai *dai,
  187. struct snd_soc_pcm_runtime *rtd, int num);
  188. bool snd_soc_dai_stream_valid(const struct snd_soc_dai *dai, int stream);
  189. void snd_soc_dai_action(struct snd_soc_dai *dai,
  190. int stream, int action);
  191. static inline void snd_soc_dai_activate(struct snd_soc_dai *dai,
  192. int stream)
  193. {
  194. snd_soc_dai_action(dai, stream, 1);
  195. }
  196. static inline void snd_soc_dai_deactivate(struct snd_soc_dai *dai,
  197. int stream)
  198. {
  199. snd_soc_dai_action(dai, stream, -1);
  200. }
  201. int snd_soc_dai_active(const struct snd_soc_dai *dai);
  202. int snd_soc_pcm_dai_probe(struct snd_soc_pcm_runtime *rtd, int order);
  203. int snd_soc_pcm_dai_remove(struct snd_soc_pcm_runtime *rtd, int order);
  204. int snd_soc_pcm_dai_new(struct snd_soc_pcm_runtime *rtd);
  205. int snd_soc_pcm_dai_prepare(struct snd_pcm_substream *substream);
  206. int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream, int cmd,
  207. int rollback);
  208. void snd_soc_pcm_dai_delay(struct snd_pcm_substream *substream,
  209. snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
  210. int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
  211. struct snd_compr_stream *cstream);
  212. void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai,
  213. struct snd_compr_stream *cstream,
  214. int rollback);
  215. int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai,
  216. struct snd_compr_stream *cstream, int cmd);
  217. int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai,
  218. struct snd_compr_stream *cstream,
  219. struct snd_compr_params *params);
  220. int snd_soc_dai_compr_get_params(struct snd_soc_dai *dai,
  221. struct snd_compr_stream *cstream,
  222. struct snd_codec *params);
  223. int snd_soc_dai_compr_ack(struct snd_soc_dai *dai,
  224. struct snd_compr_stream *cstream,
  225. size_t bytes);
  226. int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai,
  227. struct snd_compr_stream *cstream,
  228. struct snd_compr_tstamp *tstamp);
  229. int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai,
  230. struct snd_compr_stream *cstream,
  231. struct snd_compr_metadata *metadata);
  232. int snd_soc_dai_compr_get_metadata(struct snd_soc_dai *dai,
  233. struct snd_compr_stream *cstream,
  234. struct snd_compr_metadata *metadata);
  235. const char *snd_soc_dai_name_get(const struct snd_soc_dai *dai);
  236. struct snd_soc_dai_ops {
  237. /* DAI driver callbacks */
  238. int (*probe)(struct snd_soc_dai *dai);
  239. int (*remove)(struct snd_soc_dai *dai);
  240. /* compress dai */
  241. int (*compress_new)(struct snd_soc_pcm_runtime *rtd, int num);
  242. /* Optional Callback used at pcm creation*/
  243. int (*pcm_new)(struct snd_soc_pcm_runtime *rtd,
  244. struct snd_soc_dai *dai);
  245. /*
  246. * DAI clocking configuration, all optional.
  247. * Called by soc_card drivers, normally in their hw_params.
  248. */
  249. int (*set_sysclk)(struct snd_soc_dai *dai,
  250. int clk_id, unsigned int freq, int dir);
  251. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  252. unsigned int freq_in, unsigned int freq_out);
  253. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  254. int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
  255. /*
  256. * DAI format configuration
  257. * Called by soc_card drivers, normally in their hw_params.
  258. */
  259. int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
  260. int (*xlate_tdm_slot_mask)(unsigned int slots,
  261. unsigned int *tx_mask, unsigned int *rx_mask);
  262. int (*set_tdm_slot)(struct snd_soc_dai *dai,
  263. unsigned int tx_mask, unsigned int rx_mask,
  264. int slots, int slot_width);
  265. int (*set_channel_map)(struct snd_soc_dai *dai,
  266. unsigned int tx_num, const unsigned int *tx_slot,
  267. unsigned int rx_num, const unsigned int *rx_slot);
  268. int (*get_channel_map)(const struct snd_soc_dai *dai,
  269. unsigned int *tx_num, unsigned int *tx_slot,
  270. unsigned int *rx_num, unsigned int *rx_slot);
  271. int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
  272. int (*set_stream)(struct snd_soc_dai *dai,
  273. void *stream, int direction);
  274. void *(*get_stream)(struct snd_soc_dai *dai, int direction);
  275. /*
  276. * DAI digital mute - optional.
  277. * Called by soc-core to minimise any pops.
  278. */
  279. int (*mute_stream)(struct snd_soc_dai *dai, int mute, int stream);
  280. /*
  281. * ALSA PCM audio operations - all optional.
  282. * Called by soc-core during audio PCM operations.
  283. */
  284. int (*startup)(struct snd_pcm_substream *,
  285. struct snd_soc_dai *);
  286. void (*shutdown)(struct snd_pcm_substream *,
  287. struct snd_soc_dai *);
  288. int (*hw_params)(struct snd_pcm_substream *,
  289. struct snd_pcm_hw_params *, struct snd_soc_dai *);
  290. int (*hw_free)(struct snd_pcm_substream *,
  291. struct snd_soc_dai *);
  292. int (*prepare)(struct snd_pcm_substream *,
  293. struct snd_soc_dai *);
  294. /*
  295. * NOTE: Commands passed to the trigger function are not necessarily
  296. * compatible with the current state of the dai. For example this
  297. * sequence of commands is possible: START STOP STOP.
  298. * So do not unconditionally use refcounting functions in the trigger
  299. * function, e.g. clk_enable/disable.
  300. */
  301. int (*trigger)(struct snd_pcm_substream *, int,
  302. struct snd_soc_dai *);
  303. /*
  304. * For hardware based FIFO caused delay reporting.
  305. * Optional.
  306. */
  307. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  308. struct snd_soc_dai *);
  309. /*
  310. * Format list for auto selection.
  311. * Format will be increased if priority format was
  312. * not selected.
  313. * see
  314. * snd_soc_dai_get_fmt()
  315. */
  316. const u64 *auto_selectable_formats;
  317. int num_auto_selectable_formats;
  318. /* probe ordering - for components with runtime dependencies */
  319. int probe_order;
  320. int remove_order;
  321. /* bit field */
  322. unsigned int no_capture_mute:1;
  323. unsigned int mute_unmute_on_trigger:1;
  324. };
  325. struct snd_soc_cdai_ops {
  326. /*
  327. * for compress ops
  328. */
  329. int (*startup)(struct snd_compr_stream *,
  330. struct snd_soc_dai *);
  331. int (*shutdown)(struct snd_compr_stream *,
  332. struct snd_soc_dai *);
  333. int (*set_params)(struct snd_compr_stream *,
  334. struct snd_compr_params *, struct snd_soc_dai *);
  335. int (*get_params)(struct snd_compr_stream *,
  336. struct snd_codec *, struct snd_soc_dai *);
  337. int (*set_metadata)(struct snd_compr_stream *,
  338. struct snd_compr_metadata *, struct snd_soc_dai *);
  339. int (*get_metadata)(struct snd_compr_stream *,
  340. struct snd_compr_metadata *, struct snd_soc_dai *);
  341. int (*trigger)(struct snd_compr_stream *, int,
  342. struct snd_soc_dai *);
  343. int (*pointer)(struct snd_compr_stream *,
  344. struct snd_compr_tstamp *, struct snd_soc_dai *);
  345. int (*ack)(struct snd_compr_stream *, size_t,
  346. struct snd_soc_dai *);
  347. };
  348. /*
  349. * Digital Audio Interface Driver.
  350. *
  351. * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97
  352. * operations and capabilities. Codec and platform drivers will register this
  353. * structure for every DAI they have.
  354. *
  355. * This structure covers the clocking, formating and ALSA operations for each
  356. * interface.
  357. */
  358. struct snd_soc_dai_driver {
  359. /* DAI description */
  360. const char *name;
  361. unsigned int id;
  362. unsigned int base;
  363. struct snd_soc_dobj dobj;
  364. const struct of_phandle_args *dai_args;
  365. /* ops */
  366. const struct snd_soc_dai_ops *ops;
  367. const struct snd_soc_cdai_ops *cops;
  368. /* DAI capabilities */
  369. struct snd_soc_pcm_stream capture;
  370. struct snd_soc_pcm_stream playback;
  371. unsigned int symmetric_rate:1;
  372. unsigned int symmetric_channels:1;
  373. unsigned int symmetric_sample_bits:1;
  374. };
  375. /* for Playback/Capture */
  376. struct snd_soc_dai_stream {
  377. struct snd_soc_dapm_widget *widget;
  378. unsigned int active; /* usage count */
  379. unsigned int tdm_mask; /* CODEC TDM slot masks and params (for fixup) */
  380. void *dma_data; /* DAI DMA data */
  381. };
  382. /*
  383. * Digital Audio Interface runtime data.
  384. *
  385. * Holds runtime data for a DAI.
  386. */
  387. struct snd_soc_dai {
  388. const char *name;
  389. int id;
  390. struct device *dev;
  391. /* driver ops */
  392. struct snd_soc_dai_driver *driver;
  393. /* DAI runtime info */
  394. struct snd_soc_dai_stream stream[SNDRV_PCM_STREAM_LAST + 1];
  395. /* Symmetry data - only valid if symmetry is being enforced */
  396. unsigned int rate;
  397. unsigned int channels;
  398. unsigned int sample_bits;
  399. /* parent platform/codec */
  400. struct snd_soc_component *component;
  401. struct list_head list;
  402. /* function mark */
  403. struct snd_pcm_substream *mark_startup;
  404. struct snd_pcm_substream *mark_hw_params;
  405. struct snd_pcm_substream *mark_trigger;
  406. struct snd_compr_stream *mark_compr_startup;
  407. /* bit field */
  408. unsigned int probed:1;
  409. };
  410. static inline const struct snd_soc_pcm_stream *
  411. snd_soc_dai_get_pcm_stream(const struct snd_soc_dai *dai, int stream)
  412. {
  413. return (stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  414. &dai->driver->playback : &dai->driver->capture;
  415. }
  416. #define snd_soc_dai_get_widget_playback(dai) snd_soc_dai_get_widget(dai, SNDRV_PCM_STREAM_PLAYBACK)
  417. #define snd_soc_dai_get_widget_capture(dai) snd_soc_dai_get_widget(dai, SNDRV_PCM_STREAM_CAPTURE)
  418. static inline
  419. struct snd_soc_dapm_widget *snd_soc_dai_get_widget(struct snd_soc_dai *dai, int stream)
  420. {
  421. return dai->stream[stream].widget;
  422. }
  423. #define snd_soc_dai_set_widget_playback(dai, widget) snd_soc_dai_set_widget(dai, SNDRV_PCM_STREAM_PLAYBACK, widget)
  424. #define snd_soc_dai_set_widget_capture(dai, widget) snd_soc_dai_set_widget(dai, SNDRV_PCM_STREAM_CAPTURE, widget)
  425. static inline
  426. void snd_soc_dai_set_widget(struct snd_soc_dai *dai, int stream, struct snd_soc_dapm_widget *widget)
  427. {
  428. dai->stream[stream].widget = widget;
  429. }
  430. #define snd_soc_dai_dma_data_get_playback(dai) snd_soc_dai_dma_data_get(dai, SNDRV_PCM_STREAM_PLAYBACK)
  431. #define snd_soc_dai_dma_data_get_capture(dai) snd_soc_dai_dma_data_get(dai, SNDRV_PCM_STREAM_CAPTURE)
  432. #define snd_soc_dai_get_dma_data(dai, ss) snd_soc_dai_dma_data_get(dai, ss->stream)
  433. static inline void *snd_soc_dai_dma_data_get(const struct snd_soc_dai *dai, int stream)
  434. {
  435. return dai->stream[stream].dma_data;
  436. }
  437. #define snd_soc_dai_dma_data_set_playback(dai, data) snd_soc_dai_dma_data_set(dai, SNDRV_PCM_STREAM_PLAYBACK, data)
  438. #define snd_soc_dai_dma_data_set_capture(dai, data) snd_soc_dai_dma_data_set(dai, SNDRV_PCM_STREAM_CAPTURE, data)
  439. #define snd_soc_dai_set_dma_data(dai, ss, data) snd_soc_dai_dma_data_set(dai, ss->stream, data)
  440. static inline void snd_soc_dai_dma_data_set(struct snd_soc_dai *dai, int stream, void *data)
  441. {
  442. dai->stream[stream].dma_data = data;
  443. }
  444. static inline void snd_soc_dai_init_dma_data(struct snd_soc_dai *dai, void *playback, void *capture)
  445. {
  446. snd_soc_dai_dma_data_set_playback(dai, playback);
  447. snd_soc_dai_dma_data_set_capture(dai, capture);
  448. }
  449. static inline unsigned int snd_soc_dai_tdm_mask_get(const struct snd_soc_dai *dai,
  450. int stream)
  451. {
  452. return dai->stream[stream].tdm_mask;
  453. }
  454. static inline void snd_soc_dai_tdm_mask_set(struct snd_soc_dai *dai, int stream,
  455. unsigned int tdm_mask)
  456. {
  457. dai->stream[stream].tdm_mask = tdm_mask;
  458. }
  459. static inline unsigned int snd_soc_dai_stream_active(const struct snd_soc_dai *dai,
  460. int stream)
  461. {
  462. /* see snd_soc_dai_action() for setup */
  463. return dai->stream[stream].active;
  464. }
  465. static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai,
  466. void *data)
  467. {
  468. dev_set_drvdata(dai->dev, data);
  469. }
  470. static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai)
  471. {
  472. return dev_get_drvdata(dai->dev);
  473. }
  474. /**
  475. * snd_soc_dai_set_stream() - Configures a DAI for stream operation
  476. * @dai: DAI
  477. * @stream: STREAM (opaque structure depending on DAI type)
  478. * @direction: Stream direction(Playback/Capture)
  479. * Some subsystems, such as SoundWire, don't have a notion of direction and we reuse
  480. * the ASoC stream direction to configure sink/source ports.
  481. * Playback maps to source ports and Capture for sink ports.
  482. *
  483. * This should be invoked with NULL to clear the stream set previously.
  484. * Returns 0 on success, a negative error code otherwise.
  485. */
  486. static inline int snd_soc_dai_set_stream(struct snd_soc_dai *dai,
  487. void *stream, int direction)
  488. {
  489. if (dai->driver->ops->set_stream)
  490. return dai->driver->ops->set_stream(dai, stream, direction);
  491. else
  492. return -ENOTSUPP;
  493. }
  494. /**
  495. * snd_soc_dai_get_stream() - Retrieves stream from DAI
  496. * @dai: DAI
  497. * @direction: Stream direction(Playback/Capture)
  498. *
  499. * This routine only retrieves that was previously configured
  500. * with snd_soc_dai_get_stream()
  501. *
  502. * Returns pointer to stream or an ERR_PTR value, e.g.
  503. * ERR_PTR(-ENOTSUPP) if callback is not supported;
  504. */
  505. static inline void *snd_soc_dai_get_stream(struct snd_soc_dai *dai,
  506. int direction)
  507. {
  508. if (dai->driver->ops->get_stream)
  509. return dai->driver->ops->get_stream(dai, direction);
  510. else
  511. return ERR_PTR(-ENOTSUPP);
  512. }
  513. #endif