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