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