soc-dai.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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(struct snd_soc_pcm_runtime *rtd);
  159. u64 snd_soc_dai_get_fmt(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, unsigned int *tx_slot,
  165. unsigned int rx_num, 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(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(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(struct snd_soc_dai *dai, int stream);
  189. void snd_soc_dai_link_set_capabilities(struct snd_soc_dai_link *dai_link);
  190. void snd_soc_dai_action(struct snd_soc_dai *dai,
  191. int stream, int action);
  192. static inline void snd_soc_dai_activate(struct snd_soc_dai *dai,
  193. int stream)
  194. {
  195. snd_soc_dai_action(dai, stream, 1);
  196. }
  197. static inline void snd_soc_dai_deactivate(struct snd_soc_dai *dai,
  198. int stream)
  199. {
  200. snd_soc_dai_action(dai, stream, -1);
  201. }
  202. int snd_soc_dai_active(struct snd_soc_dai *dai);
  203. int snd_soc_pcm_dai_probe(struct snd_soc_pcm_runtime *rtd, int order);
  204. int snd_soc_pcm_dai_remove(struct snd_soc_pcm_runtime *rtd, int order);
  205. int snd_soc_pcm_dai_new(struct snd_soc_pcm_runtime *rtd);
  206. int snd_soc_pcm_dai_prepare(struct snd_pcm_substream *substream);
  207. int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream, int cmd,
  208. int rollback);
  209. int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream,
  210. int cmd);
  211. void snd_soc_pcm_dai_delay(struct snd_pcm_substream *substream,
  212. snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
  213. int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
  214. struct snd_compr_stream *cstream);
  215. void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai,
  216. struct snd_compr_stream *cstream,
  217. int rollback);
  218. int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai,
  219. struct snd_compr_stream *cstream, int cmd);
  220. int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai,
  221. struct snd_compr_stream *cstream,
  222. struct snd_compr_params *params);
  223. int snd_soc_dai_compr_get_params(struct snd_soc_dai *dai,
  224. struct snd_compr_stream *cstream,
  225. struct snd_codec *params);
  226. int snd_soc_dai_compr_ack(struct snd_soc_dai *dai,
  227. struct snd_compr_stream *cstream,
  228. size_t bytes);
  229. int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai,
  230. struct snd_compr_stream *cstream,
  231. struct snd_compr_tstamp *tstamp);
  232. int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai,
  233. struct snd_compr_stream *cstream,
  234. struct snd_compr_metadata *metadata);
  235. int snd_soc_dai_compr_get_metadata(struct snd_soc_dai *dai,
  236. struct snd_compr_stream *cstream,
  237. struct snd_compr_metadata *metadata);
  238. struct snd_soc_dai_ops {
  239. /*
  240. * DAI clocking configuration, all optional.
  241. * Called by soc_card drivers, normally in their hw_params.
  242. */
  243. int (*set_sysclk)(struct snd_soc_dai *dai,
  244. int clk_id, unsigned int freq, int dir);
  245. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  246. unsigned int freq_in, unsigned int freq_out);
  247. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  248. int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
  249. /*
  250. * DAI format configuration
  251. * Called by soc_card drivers, normally in their hw_params.
  252. */
  253. int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
  254. int (*xlate_tdm_slot_mask)(unsigned int slots,
  255. unsigned int *tx_mask, unsigned int *rx_mask);
  256. int (*set_tdm_slot)(struct snd_soc_dai *dai,
  257. unsigned int tx_mask, unsigned int rx_mask,
  258. int slots, int slot_width);
  259. int (*set_channel_map)(struct snd_soc_dai *dai,
  260. unsigned int tx_num, unsigned int *tx_slot,
  261. unsigned int rx_num, unsigned int *rx_slot);
  262. int (*get_channel_map)(struct snd_soc_dai *dai,
  263. unsigned int *tx_num, unsigned int *tx_slot,
  264. unsigned int *rx_num, unsigned int *rx_slot);
  265. int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
  266. int (*set_stream)(struct snd_soc_dai *dai,
  267. void *stream, int direction);
  268. void *(*get_stream)(struct snd_soc_dai *dai, int direction);
  269. /*
  270. * DAI digital mute - optional.
  271. * Called by soc-core to minimise any pops.
  272. */
  273. int (*mute_stream)(struct snd_soc_dai *dai, int mute, int stream);
  274. /*
  275. * ALSA PCM audio operations - all optional.
  276. * Called by soc-core during audio PCM operations.
  277. */
  278. int (*startup)(struct snd_pcm_substream *,
  279. struct snd_soc_dai *);
  280. void (*shutdown)(struct snd_pcm_substream *,
  281. struct snd_soc_dai *);
  282. int (*hw_params)(struct snd_pcm_substream *,
  283. struct snd_pcm_hw_params *, struct snd_soc_dai *);
  284. int (*hw_free)(struct snd_pcm_substream *,
  285. struct snd_soc_dai *);
  286. int (*prepare)(struct snd_pcm_substream *,
  287. struct snd_soc_dai *);
  288. /*
  289. * NOTE: Commands passed to the trigger function are not necessarily
  290. * compatible with the current state of the dai. For example this
  291. * sequence of commands is possible: START STOP STOP.
  292. * So do not unconditionally use refcounting functions in the trigger
  293. * function, e.g. clk_enable/disable.
  294. */
  295. int (*trigger)(struct snd_pcm_substream *, int,
  296. struct snd_soc_dai *);
  297. int (*bespoke_trigger)(struct snd_pcm_substream *, int,
  298. struct snd_soc_dai *);
  299. /*
  300. * For hardware based FIFO caused delay reporting.
  301. * Optional.
  302. */
  303. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  304. struct snd_soc_dai *);
  305. /*
  306. * Format list for auto selection.
  307. * Format will be increased if priority format was
  308. * not selected.
  309. * see
  310. * snd_soc_dai_get_fmt()
  311. */
  312. u64 *auto_selectable_formats;
  313. int num_auto_selectable_formats;
  314. /* bit field */
  315. unsigned int no_capture_mute:1;
  316. };
  317. struct snd_soc_cdai_ops {
  318. /*
  319. * for compress ops
  320. */
  321. int (*startup)(struct snd_compr_stream *,
  322. struct snd_soc_dai *);
  323. int (*shutdown)(struct snd_compr_stream *,
  324. struct snd_soc_dai *);
  325. int (*set_params)(struct snd_compr_stream *,
  326. struct snd_compr_params *, struct snd_soc_dai *);
  327. int (*get_params)(struct snd_compr_stream *,
  328. struct snd_codec *, struct snd_soc_dai *);
  329. int (*set_metadata)(struct snd_compr_stream *,
  330. struct snd_compr_metadata *, struct snd_soc_dai *);
  331. int (*get_metadata)(struct snd_compr_stream *,
  332. struct snd_compr_metadata *, struct snd_soc_dai *);
  333. int (*trigger)(struct snd_compr_stream *, int,
  334. struct snd_soc_dai *);
  335. int (*pointer)(struct snd_compr_stream *,
  336. struct snd_compr_tstamp *, struct snd_soc_dai *);
  337. int (*ack)(struct snd_compr_stream *, size_t,
  338. struct snd_soc_dai *);
  339. };
  340. /*
  341. * Digital Audio Interface Driver.
  342. *
  343. * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97
  344. * operations and capabilities. Codec and platform drivers will register this
  345. * structure for every DAI they have.
  346. *
  347. * This structure covers the clocking, formating and ALSA operations for each
  348. * interface.
  349. */
  350. struct snd_soc_dai_driver {
  351. /* DAI description */
  352. const char *name;
  353. unsigned int id;
  354. unsigned int base;
  355. struct snd_soc_dobj dobj;
  356. /* DAI driver callbacks */
  357. int (*probe)(struct snd_soc_dai *dai);
  358. int (*remove)(struct snd_soc_dai *dai);
  359. /* compress dai */
  360. int (*compress_new)(struct snd_soc_pcm_runtime *rtd, int num);
  361. /* Optional Callback used at pcm creation*/
  362. int (*pcm_new)(struct snd_soc_pcm_runtime *rtd,
  363. struct snd_soc_dai *dai);
  364. /* ops */
  365. const struct snd_soc_dai_ops *ops;
  366. const struct snd_soc_cdai_ops *cops;
  367. /* DAI capabilities */
  368. struct snd_soc_pcm_stream capture;
  369. struct snd_soc_pcm_stream playback;
  370. unsigned int symmetric_rate:1;
  371. unsigned int symmetric_channels:1;
  372. unsigned int symmetric_sample_bits:1;
  373. /* probe ordering - for components with runtime dependencies */
  374. int probe_order;
  375. int remove_order;
  376. };
  377. /*
  378. * Digital Audio Interface runtime data.
  379. *
  380. * Holds runtime data for a DAI.
  381. */
  382. struct snd_soc_dai {
  383. const char *name;
  384. int id;
  385. struct device *dev;
  386. /* driver ops */
  387. struct snd_soc_dai_driver *driver;
  388. /* DAI runtime info */
  389. unsigned int stream_active[SNDRV_PCM_STREAM_LAST + 1]; /* usage count */
  390. struct snd_soc_dapm_widget *playback_widget;
  391. struct snd_soc_dapm_widget *capture_widget;
  392. /* DAI DMA data */
  393. void *playback_dma_data;
  394. void *capture_dma_data;
  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. /* CODEC TDM slot masks and params (for fixup) */
  402. unsigned int tx_mask;
  403. unsigned int rx_mask;
  404. struct list_head list;
  405. /* function mark */
  406. struct snd_pcm_substream *mark_startup;
  407. struct snd_pcm_substream *mark_hw_params;
  408. struct snd_pcm_substream *mark_trigger;
  409. struct snd_compr_stream *mark_compr_startup;
  410. /* bit field */
  411. unsigned int probed:1;
  412. };
  413. static inline struct snd_soc_pcm_stream *
  414. snd_soc_dai_get_pcm_stream(const struct snd_soc_dai *dai, int stream)
  415. {
  416. return (stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  417. &dai->driver->playback : &dai->driver->capture;
  418. }
  419. static inline
  420. struct snd_soc_dapm_widget *snd_soc_dai_get_widget(
  421. struct snd_soc_dai *dai, int stream)
  422. {
  423. return (stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  424. dai->playback_widget : dai->capture_widget;
  425. }
  426. static inline void *snd_soc_dai_get_dma_data(const struct snd_soc_dai *dai,
  427. const struct snd_pcm_substream *ss)
  428. {
  429. return (ss->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  430. dai->playback_dma_data : dai->capture_dma_data;
  431. }
  432. static inline void snd_soc_dai_set_dma_data(struct snd_soc_dai *dai,
  433. const struct snd_pcm_substream *ss,
  434. void *data)
  435. {
  436. if (ss->stream == SNDRV_PCM_STREAM_PLAYBACK)
  437. dai->playback_dma_data = data;
  438. else
  439. dai->capture_dma_data = data;
  440. }
  441. static inline void snd_soc_dai_init_dma_data(struct snd_soc_dai *dai,
  442. void *playback, void *capture)
  443. {
  444. dai->playback_dma_data = playback;
  445. dai->capture_dma_data = capture;
  446. }
  447. static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai,
  448. void *data)
  449. {
  450. dev_set_drvdata(dai->dev, data);
  451. }
  452. static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai)
  453. {
  454. return dev_get_drvdata(dai->dev);
  455. }
  456. /**
  457. * snd_soc_dai_set_stream() - Configures a DAI for stream operation
  458. * @dai: DAI
  459. * @stream: STREAM (opaque structure depending on DAI type)
  460. * @direction: Stream direction(Playback/Capture)
  461. * Some subsystems, such as SoundWire, don't have a notion of direction and we reuse
  462. * the ASoC stream direction to configure sink/source ports.
  463. * Playback maps to source ports and Capture for sink ports.
  464. *
  465. * This should be invoked with NULL to clear the stream set previously.
  466. * Returns 0 on success, a negative error code otherwise.
  467. */
  468. static inline int snd_soc_dai_set_stream(struct snd_soc_dai *dai,
  469. void *stream, int direction)
  470. {
  471. if (dai->driver->ops->set_stream)
  472. return dai->driver->ops->set_stream(dai, stream, direction);
  473. else
  474. return -ENOTSUPP;
  475. }
  476. /**
  477. * snd_soc_dai_get_stream() - Retrieves stream from DAI
  478. * @dai: DAI
  479. * @direction: Stream direction(Playback/Capture)
  480. *
  481. * This routine only retrieves that was previously configured
  482. * with snd_soc_dai_get_stream()
  483. *
  484. * Returns pointer to stream or an ERR_PTR value, e.g.
  485. * ERR_PTR(-ENOTSUPP) if callback is not supported;
  486. */
  487. static inline void *snd_soc_dai_get_stream(struct snd_soc_dai *dai,
  488. int direction)
  489. {
  490. if (dai->driver->ops->get_stream)
  491. return dai->driver->ops->get_stream(dai, direction);
  492. else
  493. return ERR_PTR(-ENOTSUPP);
  494. }
  495. static inline unsigned int
  496. snd_soc_dai_stream_active(struct snd_soc_dai *dai, int stream)
  497. {
  498. return dai->stream_active[stream];
  499. }
  500. #endif