Kuninori Morimoto | b53c34b | 2018-07-02 06:22:58 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 |
| 2 | * |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 3 | * linux/sound/soc-dpcm.h -- ALSA SoC Dynamic PCM Support |
| 4 | * |
| 5 | * Author: Liam Girdwood <lrg@ti.com> |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __LINUX_SND_SOC_DPCM_H |
| 9 | #define __LINUX_SND_SOC_DPCM_H |
| 10 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 11 | #include <linux/slab.h> |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 12 | #include <linux/list.h> |
| 13 | #include <sound/pcm.h> |
| 14 | |
| 15 | struct snd_soc_pcm_runtime; |
| 16 | |
| 17 | /* |
| 18 | * Types of runtime_update to perform. e.g. originated from FE PCM ops |
| 19 | * or audio route changes triggered by muxes/mixers. |
| 20 | */ |
| 21 | enum snd_soc_dpcm_update { |
| 22 | SND_SOC_DPCM_UPDATE_NO = 0, |
| 23 | SND_SOC_DPCM_UPDATE_BE, |
| 24 | SND_SOC_DPCM_UPDATE_FE, |
| 25 | }; |
| 26 | |
| 27 | /* |
| 28 | * Dynamic PCM Frontend -> Backend link management states. |
| 29 | */ |
| 30 | enum snd_soc_dpcm_link_state { |
| 31 | SND_SOC_DPCM_LINK_STATE_NEW = 0, /* newly created link */ |
| 32 | SND_SOC_DPCM_LINK_STATE_FREE, /* link to be dismantled */ |
| 33 | }; |
| 34 | |
| 35 | /* |
| 36 | * Dynamic PCM Frontend -> Backend link PCM states. |
| 37 | */ |
| 38 | enum snd_soc_dpcm_state { |
| 39 | SND_SOC_DPCM_STATE_NEW = 0, |
| 40 | SND_SOC_DPCM_STATE_OPEN, |
| 41 | SND_SOC_DPCM_STATE_HW_PARAMS, |
| 42 | SND_SOC_DPCM_STATE_PREPARE, |
| 43 | SND_SOC_DPCM_STATE_START, |
| 44 | SND_SOC_DPCM_STATE_STOP, |
| 45 | SND_SOC_DPCM_STATE_PAUSED, |
| 46 | SND_SOC_DPCM_STATE_SUSPEND, |
| 47 | SND_SOC_DPCM_STATE_HW_FREE, |
| 48 | SND_SOC_DPCM_STATE_CLOSE, |
| 49 | }; |
| 50 | |
| 51 | /* |
| 52 | * Dynamic PCM trigger ordering. Triggering flexibility is required as some |
| 53 | * DSPs require triggering before/after their CPU platform and DAIs. |
| 54 | * |
| 55 | * i.e. some clients may want to manually order this call in their PCM |
| 56 | * trigger() whilst others will just use the regular core ordering. |
| 57 | */ |
| 58 | enum snd_soc_dpcm_trigger { |
| 59 | SND_SOC_DPCM_TRIGGER_PRE = 0, |
| 60 | SND_SOC_DPCM_TRIGGER_POST, |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 61 | SND_SOC_DPCM_TRIGGER_BESPOKE, |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* |
| 65 | * Dynamic PCM link |
| 66 | * This links together a FE and BE DAI at runtime and stores the link |
| 67 | * state information and the hw_params configuration. |
| 68 | */ |
| 69 | struct snd_soc_dpcm { |
| 70 | /* FE and BE DAIs*/ |
| 71 | struct snd_soc_pcm_runtime *be; |
| 72 | struct snd_soc_pcm_runtime *fe; |
| 73 | |
| 74 | /* link state */ |
| 75 | enum snd_soc_dpcm_link_state state; |
| 76 | |
| 77 | /* list of BE and FE for this DPCM link */ |
| 78 | struct list_head list_be; |
| 79 | struct list_head list_fe; |
| 80 | |
| 81 | /* hw params for this link - may be different for each link */ |
| 82 | struct snd_pcm_hw_params hw_params; |
Liam Girdwood | f86dcef | 2012-04-25 12:12:50 +0100 | [diff] [blame] | 83 | #ifdef CONFIG_DEBUG_FS |
| 84 | struct dentry *debugfs_state; |
| 85 | #endif |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | /* |
| 89 | * Dynamic PCM runtime data. |
| 90 | */ |
| 91 | struct snd_soc_dpcm_runtime { |
| 92 | struct list_head be_clients; |
| 93 | struct list_head fe_clients; |
| 94 | |
| 95 | int users; |
| 96 | struct snd_pcm_runtime *runtime; |
| 97 | struct snd_pcm_hw_params hw_params; |
| 98 | |
| 99 | /* state and update */ |
| 100 | enum snd_soc_dpcm_update runtime_update; |
| 101 | enum snd_soc_dpcm_state state; |
Takashi Iwai | ea9d0d7 | 2014-11-04 16:52:28 +0100 | [diff] [blame] | 102 | |
| 103 | int trigger_pending; /* trigger cmd + 1 if pending, 0 if not */ |
Pierre-Louis Bossart | 848aedf | 2021-12-07 11:37:44 -0600 | [diff] [blame] | 104 | |
| 105 | int be_start; /* refcount protected by BE stream pcm lock */ |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 106 | }; |
| 107 | |
Kuninori Morimoto | 4baabbf | 2019-10-25 09:56:10 +0900 | [diff] [blame] | 108 | #define for_each_dpcm_fe(be, stream, _dpcm) \ |
| 109 | list_for_each_entry(_dpcm, &(be)->dpcm[stream].fe_clients, list_fe) |
Kuninori Morimoto | d2e24d6 | 2018-09-18 01:30:54 +0000 | [diff] [blame] | 110 | |
Kuninori Morimoto | 4baabbf | 2019-10-25 09:56:10 +0900 | [diff] [blame] | 111 | #define for_each_dpcm_be(fe, stream, _dpcm) \ |
| 112 | list_for_each_entry(_dpcm, &(fe)->dpcm[stream].be_clients, list_be) |
| 113 | #define for_each_dpcm_be_safe(fe, stream, _dpcm, __dpcm) \ |
| 114 | list_for_each_entry_safe(_dpcm, __dpcm, &(fe)->dpcm[stream].be_clients, list_be) |
| 115 | #define for_each_dpcm_be_rollback(fe, stream, _dpcm) \ |
| 116 | list_for_each_entry_continue_reverse(_dpcm, &(fe)->dpcm[stream].be_clients, list_be) |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 117 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 118 | /* can this BE stop and free */ |
| 119 | int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe, |
| 120 | struct snd_soc_pcm_runtime *be, int stream); |
| 121 | |
| 122 | /* can this BE perform a hw_params() */ |
| 123 | int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe, |
| 124 | struct snd_soc_pcm_runtime *be, int stream); |
| 125 | |
| 126 | /* is the current PCM operation for this FE ? */ |
| 127 | int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream); |
| 128 | |
| 129 | /* is the current PCM operation for this BE ? */ |
| 130 | int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe, |
| 131 | struct snd_soc_pcm_runtime *be, int stream); |
| 132 | |
| 133 | /* get the substream for this BE */ |
| 134 | struct snd_pcm_substream * |
| 135 | snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream); |
| 136 | |
Guennadi Liakhovetski | f17a147 | 2020-03-12 10:52:14 +0100 | [diff] [blame] | 137 | /* update audio routing between PCMs and any DAI links */ |
| 138 | int snd_soc_dpcm_runtime_update(struct snd_soc_card *card); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 139 | |
Kuninori Morimoto | ee5b3f1 | 2019-08-07 10:31:31 +0900 | [diff] [blame] | 140 | #ifdef CONFIG_DEBUG_FS |
| 141 | void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd); |
| 142 | #else |
| 143 | static inline void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd) |
| 144 | { |
| 145 | } |
| 146 | #endif |
| 147 | |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 148 | int dpcm_path_get(struct snd_soc_pcm_runtime *fe, |
| 149 | int stream, struct snd_soc_dapm_widget_list **list_); |
Kuninori Morimoto | 52645e33 | 2020-02-19 15:56:52 +0900 | [diff] [blame] | 150 | void dpcm_path_put(struct snd_soc_dapm_widget_list **list); |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 151 | int dpcm_process_paths(struct snd_soc_pcm_runtime *fe, |
| 152 | int stream, struct snd_soc_dapm_widget_list **list, int new); |
| 153 | int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream); |
Kuninori Morimoto | 531590b | 2021-03-09 10:08:17 +0900 | [diff] [blame] | 154 | void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream, |
| 155 | int do_hw_free, struct snd_soc_dpcm *last); |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 156 | void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream); |
| 157 | void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream); |
Kuninori Morimoto | f52366e | 2021-03-15 09:58:32 +0900 | [diff] [blame] | 158 | void dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream); |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 159 | int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int tream); |
| 160 | int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd); |
| 161 | int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream); |
| 162 | int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir, |
| 163 | int event); |
Ranjani Sridharan | d1a7af0 | 2021-09-27 15:05:10 +0300 | [diff] [blame] | 164 | bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget, enum snd_soc_dapm_direction dir); |
Liam Girdwood | 2360702 | 2014-01-17 17:03:55 +0000 | [diff] [blame] | 165 | |
Kuninori Morimoto | 531590b | 2021-03-09 10:08:17 +0900 | [diff] [blame] | 166 | #define dpcm_be_dai_startup_rollback(fe, stream, last) \ |
| 167 | dpcm_be_dai_stop(fe, stream, 0, last) |
| 168 | #define dpcm_be_dai_startup_unwind(fe, stream) dpcm_be_dai_stop(fe, stream, 0, NULL) |
| 169 | #define dpcm_be_dai_shutdown(fe, stream) dpcm_be_dai_stop(fe, stream, 1, NULL) |
| 170 | |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 171 | #endif |