0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __LINUX_SND_SOC_DAI_H
0011 #define __LINUX_SND_SOC_DAI_H
0012
0013
0014 #include <linux/list.h>
0015 #include <sound/asoc.h>
0016
0017 struct snd_pcm_substream;
0018 struct snd_soc_dapm_widget;
0019 struct snd_compr_stream;
0020
0021
0022
0023
0024
0025
0026
0027 #define SND_SOC_DAIFMT_I2S SND_SOC_DAI_FORMAT_I2S
0028 #define SND_SOC_DAIFMT_RIGHT_J SND_SOC_DAI_FORMAT_RIGHT_J
0029 #define SND_SOC_DAIFMT_LEFT_J SND_SOC_DAI_FORMAT_LEFT_J
0030 #define SND_SOC_DAIFMT_DSP_A SND_SOC_DAI_FORMAT_DSP_A
0031 #define SND_SOC_DAIFMT_DSP_B SND_SOC_DAI_FORMAT_DSP_B
0032 #define SND_SOC_DAIFMT_AC97 SND_SOC_DAI_FORMAT_AC97
0033 #define SND_SOC_DAIFMT_PDM SND_SOC_DAI_FORMAT_PDM
0034
0035
0036 #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
0037 #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
0038
0039
0040
0041
0042
0043
0044
0045 #define SND_SOC_POSSIBLE_DAIFMT_FORMAT_SHIFT 0
0046 #define SND_SOC_POSSIBLE_DAIFMT_FORMAT_MASK (0xFFFF << SND_SOC_POSSIBLE_DAIFMT_FORMAT_SHIFT)
0047 #define SND_SOC_POSSIBLE_DAIFMT_I2S (1 << SND_SOC_DAI_FORMAT_I2S)
0048 #define SND_SOC_POSSIBLE_DAIFMT_RIGHT_J (1 << SND_SOC_DAI_FORMAT_RIGHT_J)
0049 #define SND_SOC_POSSIBLE_DAIFMT_LEFT_J (1 << SND_SOC_DAI_FORMAT_LEFT_J)
0050 #define SND_SOC_POSSIBLE_DAIFMT_DSP_A (1 << SND_SOC_DAI_FORMAT_DSP_A)
0051 #define SND_SOC_POSSIBLE_DAIFMT_DSP_B (1 << SND_SOC_DAI_FORMAT_DSP_B)
0052 #define SND_SOC_POSSIBLE_DAIFMT_AC97 (1 << SND_SOC_DAI_FORMAT_AC97)
0053 #define SND_SOC_POSSIBLE_DAIFMT_PDM (1 << SND_SOC_DAI_FORMAT_PDM)
0054
0055
0056
0057
0058
0059
0060
0061 #define SND_SOC_DAIFMT_CONT (1 << 4)
0062 #define SND_SOC_DAIFMT_GATED (0 << 4)
0063
0064
0065
0066
0067
0068
0069
0070 #define SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT 16
0071 #define SND_SOC_POSSIBLE_DAIFMT_CLOCK_MASK (0xFFFF << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
0072 #define SND_SOC_POSSIBLE_DAIFMT_GATED (0x1ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
0073 #define SND_SOC_POSSIBLE_DAIFMT_CONT (0x2ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 #define SND_SOC_DAIFMT_NB_NF (0 << 8)
0097 #define SND_SOC_DAIFMT_NB_IF (2 << 8)
0098 #define SND_SOC_DAIFMT_IB_NF (3 << 8)
0099 #define SND_SOC_DAIFMT_IB_IF (4 << 8)
0100
0101
0102 #define SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT 32
0103 #define SND_SOC_POSSIBLE_DAIFMT_INV_MASK (0xFFFFULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
0104 #define SND_SOC_POSSIBLE_DAIFMT_NB_NF (0x1ULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
0105 #define SND_SOC_POSSIBLE_DAIFMT_NB_IF (0x2ULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
0106 #define SND_SOC_POSSIBLE_DAIFMT_IB_NF (0x4ULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
0107 #define SND_SOC_POSSIBLE_DAIFMT_IB_IF (0x8ULL << SND_SOC_POSSIBLE_DAIFMT_INV_SHIFT)
0108
0109
0110
0111
0112
0113
0114
0115
0116 #define SND_SOC_DAIFMT_CBP_CFP (1 << 12)
0117 #define SND_SOC_DAIFMT_CBC_CFP (2 << 12)
0118 #define SND_SOC_DAIFMT_CBP_CFC (3 << 12)
0119 #define SND_SOC_DAIFMT_CBC_CFC (4 << 12)
0120
0121
0122 #define SND_SOC_DAIFMT_CBM_CFM SND_SOC_DAIFMT_CBP_CFP
0123 #define SND_SOC_DAIFMT_CBS_CFM SND_SOC_DAIFMT_CBC_CFP
0124 #define SND_SOC_DAIFMT_CBM_CFS SND_SOC_DAIFMT_CBP_CFC
0125 #define SND_SOC_DAIFMT_CBS_CFS SND_SOC_DAIFMT_CBC_CFC
0126
0127
0128 #define SND_SOC_DAIFMT_BP_FP SND_SOC_DAIFMT_CBP_CFP
0129 #define SND_SOC_DAIFMT_BC_FP SND_SOC_DAIFMT_CBC_CFP
0130 #define SND_SOC_DAIFMT_BP_FC SND_SOC_DAIFMT_CBP_CFC
0131 #define SND_SOC_DAIFMT_BC_FC SND_SOC_DAIFMT_CBC_CFC
0132
0133
0134 #define SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT 48
0135 #define SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_MASK (0xFFFFULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
0136 #define SND_SOC_POSSIBLE_DAIFMT_CBP_CFP (0x1ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
0137 #define SND_SOC_POSSIBLE_DAIFMT_CBC_CFP (0x2ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
0138 #define SND_SOC_POSSIBLE_DAIFMT_CBP_CFC (0x4ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
0139 #define SND_SOC_POSSIBLE_DAIFMT_CBC_CFC (0x8ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
0140
0141 #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
0142 #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
0143 #define SND_SOC_DAIFMT_INV_MASK 0x0f00
0144 #define SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK 0xf000
0145
0146 #define SND_SOC_DAIFMT_MASTER_MASK SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK
0147
0148
0149
0150
0151 #define SND_SOC_CLOCK_IN 0
0152 #define SND_SOC_CLOCK_OUT 1
0153
0154 #define SND_SOC_STD_AC97_FMTS (SNDRV_PCM_FMTBIT_S8 |\
0155 SNDRV_PCM_FMTBIT_S16_LE |\
0156 SNDRV_PCM_FMTBIT_S16_BE |\
0157 SNDRV_PCM_FMTBIT_S20_3LE |\
0158 SNDRV_PCM_FMTBIT_S20_3BE |\
0159 SNDRV_PCM_FMTBIT_S20_LE |\
0160 SNDRV_PCM_FMTBIT_S20_BE |\
0161 SNDRV_PCM_FMTBIT_S24_3LE |\
0162 SNDRV_PCM_FMTBIT_S24_3BE |\
0163 SNDRV_PCM_FMTBIT_S32_LE |\
0164 SNDRV_PCM_FMTBIT_S32_BE)
0165
0166 struct snd_soc_dai_driver;
0167 struct snd_soc_dai;
0168 struct snd_ac97_bus_ops;
0169
0170
0171 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
0172 unsigned int freq, int dir);
0173
0174 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
0175 int div_id, int div);
0176
0177 int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
0178 int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
0179
0180 int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
0181
0182
0183 int snd_soc_dai_get_fmt_max_priority(struct snd_soc_pcm_runtime *rtd);
0184 u64 snd_soc_dai_get_fmt(struct snd_soc_dai *dai, int priority);
0185 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
0186
0187 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
0188 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width);
0189
0190 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
0191 unsigned int tx_num, unsigned int *tx_slot,
0192 unsigned int rx_num, unsigned int *rx_slot);
0193
0194 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
0195
0196
0197 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
0198 int direction);
0199
0200
0201 int snd_soc_dai_get_channel_map(struct snd_soc_dai *dai,
0202 unsigned int *tx_num, unsigned int *tx_slot,
0203 unsigned int *rx_num, unsigned int *rx_slot);
0204
0205 int snd_soc_dai_is_dummy(struct snd_soc_dai *dai);
0206
0207 int snd_soc_dai_hw_params(struct snd_soc_dai *dai,
0208 struct snd_pcm_substream *substream,
0209 struct snd_pcm_hw_params *params);
0210 void snd_soc_dai_hw_free(struct snd_soc_dai *dai,
0211 struct snd_pcm_substream *substream,
0212 int rollback);
0213 int snd_soc_dai_startup(struct snd_soc_dai *dai,
0214 struct snd_pcm_substream *substream);
0215 void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
0216 struct snd_pcm_substream *substream, int rollback);
0217 void snd_soc_dai_suspend(struct snd_soc_dai *dai);
0218 void snd_soc_dai_resume(struct snd_soc_dai *dai);
0219 int snd_soc_dai_compress_new(struct snd_soc_dai *dai,
0220 struct snd_soc_pcm_runtime *rtd, int num);
0221 bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int stream);
0222 void snd_soc_dai_link_set_capabilities(struct snd_soc_dai_link *dai_link);
0223 void snd_soc_dai_action(struct snd_soc_dai *dai,
0224 int stream, int action);
0225 static inline void snd_soc_dai_activate(struct snd_soc_dai *dai,
0226 int stream)
0227 {
0228 snd_soc_dai_action(dai, stream, 1);
0229 }
0230 static inline void snd_soc_dai_deactivate(struct snd_soc_dai *dai,
0231 int stream)
0232 {
0233 snd_soc_dai_action(dai, stream, -1);
0234 }
0235 int snd_soc_dai_active(struct snd_soc_dai *dai);
0236
0237 int snd_soc_pcm_dai_probe(struct snd_soc_pcm_runtime *rtd, int order);
0238 int snd_soc_pcm_dai_remove(struct snd_soc_pcm_runtime *rtd, int order);
0239 int snd_soc_pcm_dai_new(struct snd_soc_pcm_runtime *rtd);
0240 int snd_soc_pcm_dai_prepare(struct snd_pcm_substream *substream);
0241 int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream, int cmd,
0242 int rollback);
0243 int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream,
0244 int cmd);
0245 void snd_soc_pcm_dai_delay(struct snd_pcm_substream *substream,
0246 snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
0247
0248 int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
0249 struct snd_compr_stream *cstream);
0250 void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai,
0251 struct snd_compr_stream *cstream,
0252 int rollback);
0253 int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai,
0254 struct snd_compr_stream *cstream, int cmd);
0255 int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai,
0256 struct snd_compr_stream *cstream,
0257 struct snd_compr_params *params);
0258 int snd_soc_dai_compr_get_params(struct snd_soc_dai *dai,
0259 struct snd_compr_stream *cstream,
0260 struct snd_codec *params);
0261 int snd_soc_dai_compr_ack(struct snd_soc_dai *dai,
0262 struct snd_compr_stream *cstream,
0263 size_t bytes);
0264 int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai,
0265 struct snd_compr_stream *cstream,
0266 struct snd_compr_tstamp *tstamp);
0267 int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai,
0268 struct snd_compr_stream *cstream,
0269 struct snd_compr_metadata *metadata);
0270 int snd_soc_dai_compr_get_metadata(struct snd_soc_dai *dai,
0271 struct snd_compr_stream *cstream,
0272 struct snd_compr_metadata *metadata);
0273
0274 struct snd_soc_dai_ops {
0275
0276
0277
0278
0279 int (*set_sysclk)(struct snd_soc_dai *dai,
0280 int clk_id, unsigned int freq, int dir);
0281 int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
0282 unsigned int freq_in, unsigned int freq_out);
0283 int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
0284 int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
0285
0286
0287
0288
0289
0290 int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
0291 int (*xlate_tdm_slot_mask)(unsigned int slots,
0292 unsigned int *tx_mask, unsigned int *rx_mask);
0293 int (*set_tdm_slot)(struct snd_soc_dai *dai,
0294 unsigned int tx_mask, unsigned int rx_mask,
0295 int slots, int slot_width);
0296 int (*set_channel_map)(struct snd_soc_dai *dai,
0297 unsigned int tx_num, unsigned int *tx_slot,
0298 unsigned int rx_num, unsigned int *rx_slot);
0299 int (*get_channel_map)(struct snd_soc_dai *dai,
0300 unsigned int *tx_num, unsigned int *tx_slot,
0301 unsigned int *rx_num, unsigned int *rx_slot);
0302 int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
0303
0304 int (*set_stream)(struct snd_soc_dai *dai,
0305 void *stream, int direction);
0306 void *(*get_stream)(struct snd_soc_dai *dai, int direction);
0307
0308
0309
0310
0311
0312 int (*mute_stream)(struct snd_soc_dai *dai, int mute, int stream);
0313
0314
0315
0316
0317
0318 int (*startup)(struct snd_pcm_substream *,
0319 struct snd_soc_dai *);
0320 void (*shutdown)(struct snd_pcm_substream *,
0321 struct snd_soc_dai *);
0322 int (*hw_params)(struct snd_pcm_substream *,
0323 struct snd_pcm_hw_params *, struct snd_soc_dai *);
0324 int (*hw_free)(struct snd_pcm_substream *,
0325 struct snd_soc_dai *);
0326 int (*prepare)(struct snd_pcm_substream *,
0327 struct snd_soc_dai *);
0328
0329
0330
0331
0332
0333
0334
0335 int (*trigger)(struct snd_pcm_substream *, int,
0336 struct snd_soc_dai *);
0337 int (*bespoke_trigger)(struct snd_pcm_substream *, int,
0338 struct snd_soc_dai *);
0339
0340
0341
0342
0343 snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
0344 struct snd_soc_dai *);
0345
0346
0347
0348
0349
0350
0351
0352
0353 u64 *auto_selectable_formats;
0354 int num_auto_selectable_formats;
0355
0356
0357 unsigned int no_capture_mute:1;
0358 };
0359
0360 struct snd_soc_cdai_ops {
0361
0362
0363
0364 int (*startup)(struct snd_compr_stream *,
0365 struct snd_soc_dai *);
0366 int (*shutdown)(struct snd_compr_stream *,
0367 struct snd_soc_dai *);
0368 int (*set_params)(struct snd_compr_stream *,
0369 struct snd_compr_params *, struct snd_soc_dai *);
0370 int (*get_params)(struct snd_compr_stream *,
0371 struct snd_codec *, struct snd_soc_dai *);
0372 int (*set_metadata)(struct snd_compr_stream *,
0373 struct snd_compr_metadata *, struct snd_soc_dai *);
0374 int (*get_metadata)(struct snd_compr_stream *,
0375 struct snd_compr_metadata *, struct snd_soc_dai *);
0376 int (*trigger)(struct snd_compr_stream *, int,
0377 struct snd_soc_dai *);
0378 int (*pointer)(struct snd_compr_stream *,
0379 struct snd_compr_tstamp *, struct snd_soc_dai *);
0380 int (*ack)(struct snd_compr_stream *, size_t,
0381 struct snd_soc_dai *);
0382 };
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394 struct snd_soc_dai_driver {
0395
0396 const char *name;
0397 unsigned int id;
0398 unsigned int base;
0399 struct snd_soc_dobj dobj;
0400
0401
0402 int (*probe)(struct snd_soc_dai *dai);
0403 int (*remove)(struct snd_soc_dai *dai);
0404
0405 int (*compress_new)(struct snd_soc_pcm_runtime *rtd, int num);
0406
0407 int (*pcm_new)(struct snd_soc_pcm_runtime *rtd,
0408 struct snd_soc_dai *dai);
0409
0410
0411 const struct snd_soc_dai_ops *ops;
0412 const struct snd_soc_cdai_ops *cops;
0413
0414
0415 struct snd_soc_pcm_stream capture;
0416 struct snd_soc_pcm_stream playback;
0417 unsigned int symmetric_rate:1;
0418 unsigned int symmetric_channels:1;
0419 unsigned int symmetric_sample_bits:1;
0420
0421
0422 int probe_order;
0423 int remove_order;
0424 };
0425
0426
0427
0428
0429
0430
0431 struct snd_soc_dai {
0432 const char *name;
0433 int id;
0434 struct device *dev;
0435
0436
0437 struct snd_soc_dai_driver *driver;
0438
0439
0440 unsigned int stream_active[SNDRV_PCM_STREAM_LAST + 1];
0441
0442 struct snd_soc_dapm_widget *playback_widget;
0443 struct snd_soc_dapm_widget *capture_widget;
0444
0445
0446 void *playback_dma_data;
0447 void *capture_dma_data;
0448
0449
0450 unsigned int rate;
0451 unsigned int channels;
0452 unsigned int sample_bits;
0453
0454
0455 struct snd_soc_component *component;
0456
0457
0458 unsigned int tx_mask;
0459 unsigned int rx_mask;
0460
0461 struct list_head list;
0462
0463
0464 struct snd_pcm_substream *mark_startup;
0465 struct snd_pcm_substream *mark_hw_params;
0466 struct snd_pcm_substream *mark_trigger;
0467 struct snd_compr_stream *mark_compr_startup;
0468
0469
0470 unsigned int probed:1;
0471 };
0472
0473 static inline struct snd_soc_pcm_stream *
0474 snd_soc_dai_get_pcm_stream(const struct snd_soc_dai *dai, int stream)
0475 {
0476 return (stream == SNDRV_PCM_STREAM_PLAYBACK) ?
0477 &dai->driver->playback : &dai->driver->capture;
0478 }
0479
0480 static inline
0481 struct snd_soc_dapm_widget *snd_soc_dai_get_widget(
0482 struct snd_soc_dai *dai, int stream)
0483 {
0484 return (stream == SNDRV_PCM_STREAM_PLAYBACK) ?
0485 dai->playback_widget : dai->capture_widget;
0486 }
0487
0488 static inline void *snd_soc_dai_get_dma_data(const struct snd_soc_dai *dai,
0489 const struct snd_pcm_substream *ss)
0490 {
0491 return (ss->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
0492 dai->playback_dma_data : dai->capture_dma_data;
0493 }
0494
0495 static inline void snd_soc_dai_set_dma_data(struct snd_soc_dai *dai,
0496 const struct snd_pcm_substream *ss,
0497 void *data)
0498 {
0499 if (ss->stream == SNDRV_PCM_STREAM_PLAYBACK)
0500 dai->playback_dma_data = data;
0501 else
0502 dai->capture_dma_data = data;
0503 }
0504
0505 static inline void snd_soc_dai_init_dma_data(struct snd_soc_dai *dai,
0506 void *playback, void *capture)
0507 {
0508 dai->playback_dma_data = playback;
0509 dai->capture_dma_data = capture;
0510 }
0511
0512 static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai,
0513 void *data)
0514 {
0515 dev_set_drvdata(dai->dev, data);
0516 }
0517
0518 static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai)
0519 {
0520 return dev_get_drvdata(dai->dev);
0521 }
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535 static inline int snd_soc_dai_set_stream(struct snd_soc_dai *dai,
0536 void *stream, int direction)
0537 {
0538 if (dai->driver->ops->set_stream)
0539 return dai->driver->ops->set_stream(dai, stream, direction);
0540 else
0541 return -ENOTSUPP;
0542 }
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555 static inline void *snd_soc_dai_get_stream(struct snd_soc_dai *dai,
0556 int direction)
0557 {
0558 if (dai->driver->ops->get_stream)
0559 return dai->driver->ops->get_stream(dai, direction);
0560 else
0561 return ERR_PTR(-ENOTSUPP);
0562 }
0563
0564 static inline unsigned int
0565 snd_soc_dai_stream_active(struct snd_soc_dai *dai, int stream)
0566 {
0567 return dai->stream_active[stream];
0568 }
0569
0570 #endif