Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0
0002  *
0003  * linux/sound/soc-dai.h -- ALSA SoC Layer
0004  *
0005  * Copyright:   2005-2008 Wolfson Microelectronics. PLC.
0006  *
0007  * Digital Audio Interface (DAI) API.
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  * DAI hardware audio formats.
0023  *
0024  * Describes the physical PCM data formating and clocking. Add new formats
0025  * to the end.
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 /* left and right justified also known as MSB and LSB respectively */
0036 #define SND_SOC_DAIFMT_MSB      SND_SOC_DAIFMT_LEFT_J
0037 #define SND_SOC_DAIFMT_LSB      SND_SOC_DAIFMT_RIGHT_J
0038 
0039 /* Describes the possible PCM format */
0040 /*
0041  * use SND_SOC_DAI_FORMAT_xx as eash shift.
0042  * see
0043  *  snd_soc_runtime_get_dai_fmt()
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  * DAI Clock gating.
0057  *
0058  * DAI bit clocks can be gated (disabled) when the DAI is not
0059  * sending or receiving PCM data in a frame. This can be used to save power.
0060  */
0061 #define SND_SOC_DAIFMT_CONT     (1 << 4) /* continuous clock */
0062 #define SND_SOC_DAIFMT_GATED        (0 << 4) /* clock is gated */
0063 
0064 /* Describes the possible PCM format */
0065 /*
0066  * define GATED -> CONT. GATED will be selected if both are selected.
0067  * see
0068  *  snd_soc_runtime_get_dai_fmt()
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  * DAI hardware signal polarity.
0077  *
0078  * Specifies whether the DAI can also support inverted clocks for the specified
0079  * format.
0080  *
0081  * BCLK:
0082  * - "normal" polarity means signal is available at rising edge of BCLK
0083  * - "inverted" polarity means signal is available at falling edge of BCLK
0084  *
0085  * FSYNC "normal" polarity depends on the frame format:
0086  * - I2S: frame consists of left then right channel data. Left channel starts
0087  *      with falling FSYNC edge, right channel starts with rising FSYNC edge.
0088  * - Left/Right Justified: frame consists of left then right channel data.
0089  *      Left channel starts with rising FSYNC edge, right channel starts with
0090  *      falling FSYNC edge.
0091  * - DSP A/B: Frame starts with rising FSYNC edge.
0092  * - AC97: Frame starts with rising FSYNC edge.
0093  *
0094  * "Negative" FSYNC polarity is the one opposite of "normal" polarity.
0095  */
0096 #define SND_SOC_DAIFMT_NB_NF        (0 << 8) /* normal bit clock + frame */
0097 #define SND_SOC_DAIFMT_NB_IF        (2 << 8) /* normal BCLK + inv FRM */
0098 #define SND_SOC_DAIFMT_IB_NF        (3 << 8) /* invert BCLK + nor FRM */
0099 #define SND_SOC_DAIFMT_IB_IF        (4 << 8) /* invert BCLK + FRM */
0100 
0101 /* Describes the possible PCM format */
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  * DAI hardware clock providers/consumers
0111  *
0112  * This is wrt the codec, the inverse is true for the interface
0113  * i.e. if the codec is clk and FRM provider then the interface is
0114  * clk and frame consumer.
0115  */
0116 #define SND_SOC_DAIFMT_CBP_CFP      (1 << 12) /* codec clk provider & frame provider */
0117 #define SND_SOC_DAIFMT_CBC_CFP      (2 << 12) /* codec clk consumer & frame provider */
0118 #define SND_SOC_DAIFMT_CBP_CFC      (3 << 12) /* codec clk provider & frame consumer */
0119 #define SND_SOC_DAIFMT_CBC_CFC      (4 << 12) /* codec clk consumer & frame consumer */
0120 
0121 /* previous definitions kept for backwards-compatibility, do not use in new contributions */
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 /* when passed to set_fmt directly indicate if the device is provider or consumer */
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 /* Describes the possible PCM format */
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  * Master Clock Directions
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 /* Digital Audio Interface clocking API.*/
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 /* Digital Audio interface formatting */
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 /* Digital Audio Interface mute */
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      * DAI clocking configuration, all optional.
0277      * Called by soc_card drivers, normally in their hw_params.
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      * DAI format configuration
0288      * Called by soc_card drivers, normally in their hw_params.
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      * DAI digital mute - optional.
0310      * Called by soc-core to minimise any pops.
0311      */
0312     int (*mute_stream)(struct snd_soc_dai *dai, int mute, int stream);
0313 
0314     /*
0315      * ALSA PCM audio operations - all optional.
0316      * Called by soc-core during audio PCM operations.
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      * NOTE: Commands passed to the trigger function are not necessarily
0330      * compatible with the current state of the dai. For example this
0331      * sequence of commands is possible: START STOP STOP.
0332      * So do not unconditionally use refcounting functions in the trigger
0333      * function, e.g. clk_enable/disable.
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      * For hardware based FIFO caused delay reporting.
0341      * Optional.
0342      */
0343     snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
0344         struct snd_soc_dai *);
0345 
0346     /*
0347      * Format list for auto selection.
0348      * Format will be increased if priority format was
0349      * not selected.
0350      * see
0351      *  snd_soc_dai_get_fmt()
0352      */
0353     u64 *auto_selectable_formats;
0354     int num_auto_selectable_formats;
0355 
0356     /* bit field */
0357     unsigned int no_capture_mute:1;
0358 };
0359 
0360 struct snd_soc_cdai_ops {
0361     /*
0362      * for compress ops
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  * Digital Audio Interface Driver.
0386  *
0387  * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97
0388  * operations and capabilities. Codec and platform drivers will register this
0389  * structure for every DAI they have.
0390  *
0391  * This structure covers the clocking, formating and ALSA operations for each
0392  * interface.
0393  */
0394 struct snd_soc_dai_driver {
0395     /* DAI description */
0396     const char *name;
0397     unsigned int id;
0398     unsigned int base;
0399     struct snd_soc_dobj dobj;
0400 
0401     /* DAI driver callbacks */
0402     int (*probe)(struct snd_soc_dai *dai);
0403     int (*remove)(struct snd_soc_dai *dai);
0404     /* compress dai */
0405     int (*compress_new)(struct snd_soc_pcm_runtime *rtd, int num);
0406     /* Optional Callback used at pcm creation*/
0407     int (*pcm_new)(struct snd_soc_pcm_runtime *rtd,
0408                struct snd_soc_dai *dai);
0409 
0410     /* ops */
0411     const struct snd_soc_dai_ops *ops;
0412     const struct snd_soc_cdai_ops *cops;
0413 
0414     /* DAI capabilities */
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     /* probe ordering - for components with runtime dependencies */
0422     int probe_order;
0423     int remove_order;
0424 };
0425 
0426 /*
0427  * Digital Audio Interface runtime data.
0428  *
0429  * Holds runtime data for a DAI.
0430  */
0431 struct snd_soc_dai {
0432     const char *name;
0433     int id;
0434     struct device *dev;
0435 
0436     /* driver ops */
0437     struct snd_soc_dai_driver *driver;
0438 
0439     /* DAI runtime info */
0440     unsigned int stream_active[SNDRV_PCM_STREAM_LAST + 1]; /* usage count */
0441 
0442     struct snd_soc_dapm_widget *playback_widget;
0443     struct snd_soc_dapm_widget *capture_widget;
0444 
0445     /* DAI DMA data */
0446     void *playback_dma_data;
0447     void *capture_dma_data;
0448 
0449     /* Symmetry data - only valid if symmetry is being enforced */
0450     unsigned int rate;
0451     unsigned int channels;
0452     unsigned int sample_bits;
0453 
0454     /* parent platform/codec */
0455     struct snd_soc_component *component;
0456 
0457     /* CODEC TDM slot masks and params (for fixup) */
0458     unsigned int tx_mask;
0459     unsigned int rx_mask;
0460 
0461     struct list_head list;
0462 
0463     /* function mark */
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     /* bit field */
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  * snd_soc_dai_set_stream() - Configures a DAI for stream operation
0525  * @dai: DAI
0526  * @stream: STREAM (opaque structure depending on DAI type)
0527  * @direction: Stream direction(Playback/Capture)
0528  * Some subsystems, such as SoundWire, don't have a notion of direction and we reuse
0529  * the ASoC stream direction to configure sink/source ports.
0530  * Playback maps to source ports and Capture for sink ports.
0531  *
0532  * This should be invoked with NULL to clear the stream set previously.
0533  * Returns 0 on success, a negative error code otherwise.
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  * snd_soc_dai_get_stream() - Retrieves stream from DAI
0546  * @dai: DAI
0547  * @direction: Stream direction(Playback/Capture)
0548  *
0549  * This routine only retrieves that was previously configured
0550  * with snd_soc_dai_get_stream()
0551  *
0552  * Returns pointer to stream or an ERR_PTR value, e.g.
0553  * ERR_PTR(-ENOTSUPP) if callback is not supported;
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