Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0
0002  *
0003  * linux/sound/soc-dpcm.h -- ALSA SoC Dynamic PCM Support
0004  *
0005  * Author:      Liam Girdwood <lrg@ti.com>
0006  */
0007 
0008 #ifndef __LINUX_SND_SOC_DPCM_H
0009 #define __LINUX_SND_SOC_DPCM_H
0010 
0011 #include <linux/slab.h>
0012 #include <linux/list.h>
0013 #include <sound/pcm.h>
0014 
0015 struct snd_soc_pcm_runtime;
0016 
0017 /*
0018  * Types of runtime_update to perform. e.g. originated from FE PCM ops
0019  * or audio route changes triggered by muxes/mixers.
0020  */
0021 enum snd_soc_dpcm_update {
0022     SND_SOC_DPCM_UPDATE_NO  = 0,
0023     SND_SOC_DPCM_UPDATE_BE,
0024     SND_SOC_DPCM_UPDATE_FE,
0025 };
0026 
0027 /*
0028  * Dynamic PCM Frontend -> Backend link management states.
0029  */
0030 enum snd_soc_dpcm_link_state {
0031     SND_SOC_DPCM_LINK_STATE_NEW = 0,    /* newly created link */
0032     SND_SOC_DPCM_LINK_STATE_FREE,       /* link to be dismantled */
0033 };
0034 
0035 /*
0036  * Dynamic PCM Frontend -> Backend link PCM states.
0037  */
0038 enum snd_soc_dpcm_state {
0039     SND_SOC_DPCM_STATE_NEW  = 0,
0040     SND_SOC_DPCM_STATE_OPEN,
0041     SND_SOC_DPCM_STATE_HW_PARAMS,
0042     SND_SOC_DPCM_STATE_PREPARE,
0043     SND_SOC_DPCM_STATE_START,
0044     SND_SOC_DPCM_STATE_STOP,
0045     SND_SOC_DPCM_STATE_PAUSED,
0046     SND_SOC_DPCM_STATE_SUSPEND,
0047     SND_SOC_DPCM_STATE_HW_FREE,
0048     SND_SOC_DPCM_STATE_CLOSE,
0049 };
0050 
0051 /*
0052  * Dynamic PCM trigger ordering. Triggering flexibility is required as some
0053  * DSPs require triggering before/after their CPU platform and DAIs.
0054  *
0055  * i.e. some clients may want to manually order this call in their PCM
0056  * trigger() whilst others will just use the regular core ordering.
0057  */
0058 enum snd_soc_dpcm_trigger {
0059     SND_SOC_DPCM_TRIGGER_PRE        = 0,
0060     SND_SOC_DPCM_TRIGGER_POST,
0061     SND_SOC_DPCM_TRIGGER_BESPOKE,
0062 };
0063 
0064 /*
0065  * Dynamic PCM link
0066  * This links together a FE and BE DAI at runtime and stores the link
0067  * state information and the hw_params configuration.
0068  */
0069 struct snd_soc_dpcm {
0070     /* FE and BE DAIs*/
0071     struct snd_soc_pcm_runtime *be;
0072     struct snd_soc_pcm_runtime *fe;
0073 
0074     /* link state */
0075     enum snd_soc_dpcm_link_state state;
0076 
0077     /* list of BE and FE for this DPCM link */
0078     struct list_head list_be;
0079     struct list_head list_fe;
0080 
0081     /* hw params for this link - may be different for each link */
0082     struct snd_pcm_hw_params hw_params;
0083 #ifdef CONFIG_DEBUG_FS
0084     struct dentry *debugfs_state;
0085 #endif
0086 };
0087 
0088 /*
0089  * Dynamic PCM runtime data.
0090  */
0091 struct snd_soc_dpcm_runtime {
0092     struct list_head be_clients;
0093     struct list_head fe_clients;
0094 
0095     int users;
0096     struct snd_pcm_runtime *runtime;
0097     struct snd_pcm_hw_params hw_params;
0098 
0099     /* state and update */
0100     enum snd_soc_dpcm_update runtime_update;
0101     enum snd_soc_dpcm_state state;
0102 
0103     int trigger_pending; /* trigger cmd + 1 if pending, 0 if not */
0104 
0105     int be_start; /* refcount protected by BE stream pcm lock */
0106     int be_pause; /* refcount protected by BE stream pcm lock */
0107     bool fe_pause; /* used to track STOP after PAUSE */
0108 };
0109 
0110 #define for_each_dpcm_fe(be, stream, _dpcm)             \
0111     list_for_each_entry(_dpcm, &(be)->dpcm[stream].fe_clients, list_fe)
0112 
0113 #define for_each_dpcm_be(fe, stream, _dpcm)             \
0114     list_for_each_entry(_dpcm, &(fe)->dpcm[stream].be_clients, list_be)
0115 #define for_each_dpcm_be_safe(fe, stream, _dpcm, __dpcm)            \
0116     list_for_each_entry_safe(_dpcm, __dpcm, &(fe)->dpcm[stream].be_clients, list_be)
0117 #define for_each_dpcm_be_rollback(fe, stream, _dpcm)            \
0118     list_for_each_entry_continue_reverse(_dpcm, &(fe)->dpcm[stream].be_clients, list_be)
0119 
0120 /* can this BE stop and free */
0121 int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
0122         struct snd_soc_pcm_runtime *be, int stream);
0123 
0124 /* can this BE perform a hw_params() */
0125 int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
0126         struct snd_soc_pcm_runtime *be, int stream);
0127 
0128 /* is the current PCM operation for this FE ? */
0129 int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream);
0130 
0131 /* is the current PCM operation for this BE ? */
0132 int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
0133         struct snd_soc_pcm_runtime *be, int stream);
0134 
0135 /* get the substream for this BE */
0136 struct snd_pcm_substream *
0137     snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream);
0138 
0139 /* update audio routing between PCMs and any DAI links */
0140 int snd_soc_dpcm_runtime_update(struct snd_soc_card *card);
0141 
0142 #ifdef CONFIG_DEBUG_FS
0143 void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd);
0144 #else
0145 static inline void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
0146 {
0147 }
0148 #endif
0149 
0150 int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
0151     int stream, struct snd_soc_dapm_widget_list **list_);
0152 void dpcm_path_put(struct snd_soc_dapm_widget_list **list);
0153 int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
0154     int stream, struct snd_soc_dapm_widget_list **list, int new);
0155 int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream);
0156 void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream,
0157               int do_hw_free, struct snd_soc_dpcm *last);
0158 void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream);
0159 void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream);
0160 void dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream);
0161 int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int tream);
0162 int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd);
0163 int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream);
0164 int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
0165     int event);
0166 bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget, enum snd_soc_dapm_direction dir);
0167 
0168 #define dpcm_be_dai_startup_rollback(fe, stream, last)  \
0169                         dpcm_be_dai_stop(fe, stream, 0, last)
0170 #define dpcm_be_dai_startup_unwind(fe, stream)  dpcm_be_dai_stop(fe, stream, 0, NULL)
0171 #define dpcm_be_dai_shutdown(fe, stream)    dpcm_be_dai_stop(fe, stream, 1, NULL)
0172 
0173 #endif