Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: mediatek: Add common snd_soc_ops .startup() callback

MediaTek platforms are typically setting PCM rate and channels
constraints for playback, capture and HDMI/DisplayPort playback:
commonize the startup callback by adding the PCM constraints data
to the mtk_platform_card_data structure and by reusing the common
mtk_soundcard_startup() function for all of them by getting back
the parameters from the aforementioned struct.

Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20240416071410.75620-8-angelogioacchino.delregno@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

AngeloGioacchino Del Regno and committed by
Mark Brown
fe071237 44a53c8e

+75
+51
sound/soc/mediatek/common/mtk-soundcard-driver.c
··· 139 139 } 140 140 EXPORT_SYMBOL_GPL(clean_card_reference); 141 141 142 + int mtk_soundcard_startup(struct snd_pcm_substream *substream, 143 + enum mtk_pcm_constraint_type ctype) 144 + { 145 + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 146 + struct mtk_soc_card_data *soc_card = snd_soc_card_get_drvdata(rtd->card); 147 + const struct mtk_pcm_constraints_data *mpc = &soc_card->card_data->pcm_constraints[ctype]; 148 + int ret; 149 + 150 + if (unlikely(!mpc)) 151 + return -EINVAL; 152 + 153 + ret = snd_pcm_hw_constraint_list(substream->runtime, 0, 154 + SNDRV_PCM_HW_PARAM_RATE, 155 + mpc->rates); 156 + if (ret < 0) { 157 + dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 158 + return ret; 159 + } 160 + 161 + ret = snd_pcm_hw_constraint_list(substream->runtime, 0, 162 + SNDRV_PCM_HW_PARAM_CHANNELS, 163 + mpc->channels); 164 + if (ret < 0) { 165 + dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 166 + return ret; 167 + } 168 + 169 + return 0; 170 + } 171 + EXPORT_SYMBOL_GPL(mtk_soundcard_startup); 172 + 173 + static int mtk_soundcard_playback_startup(struct snd_pcm_substream *substream) 174 + { 175 + return mtk_soundcard_startup(substream, MTK_CONSTRAINT_PLAYBACK); 176 + } 177 + 178 + const struct snd_soc_ops mtk_soundcard_common_playback_ops = { 179 + .startup = mtk_soundcard_playback_startup, 180 + }; 181 + EXPORT_SYMBOL_GPL(mtk_soundcard_common_playback_ops); 182 + 183 + static int mtk_soundcard_capture_startup(struct snd_pcm_substream *substream) 184 + { 185 + return mtk_soundcard_startup(substream, MTK_CONSTRAINT_CAPTURE); 186 + } 187 + 188 + const struct snd_soc_ops mtk_soundcard_common_capture_ops = { 189 + .startup = mtk_soundcard_capture_startup, 190 + }; 191 + EXPORT_SYMBOL_GPL(mtk_soundcard_common_capture_ops); 192 + 142 193 int mtk_soundcard_common_probe(struct platform_device *pdev) 143 194 { 144 195 struct device_node *platform_node, *adsp_node;
+24
sound/soc/mediatek/common/mtk-soundcard-driver.h
··· 11 11 12 12 struct mtk_sof_priv; 13 13 struct mtk_soc_card_data; 14 + struct snd_pcm_hw_constraint_list; 15 + 16 + enum mtk_pcm_constraint_type { 17 + MTK_CONSTRAINT_PLAYBACK, 18 + MTK_CONSTRAINT_CAPTURE, 19 + MTK_CONSTRAINT_HDMIDP, 20 + MTK_CONSTRAINT_MAX 21 + }; 22 + 23 + struct mtk_pcm_constraints_data { 24 + const struct snd_pcm_hw_constraint_list *channels; 25 + const struct snd_pcm_hw_constraint_list *rates; 26 + }; 14 27 15 28 struct mtk_platform_card_data { 16 29 struct snd_soc_card *card; 17 30 struct snd_soc_jack *jacks; 31 + const struct mtk_pcm_constraints_data *pcm_constraints; 18 32 u8 num_jacks; 33 + u8 num_pcm_constraints; 19 34 u8 flags; 20 35 }; 21 36 ··· 38 23 const char *card_name; 39 24 struct mtk_platform_card_data *card_data; 40 25 const struct mtk_sof_priv *sof_priv; 26 + 41 27 int (*soc_probe)(struct mtk_soc_card_data *card_data, bool legacy); 42 28 }; 29 + 30 + /* Common playback/capture card startup ops */ 31 + extern const struct snd_soc_ops mtk_soundcard_common_playback_ops; 32 + extern const struct snd_soc_ops mtk_soundcard_common_capture_ops; 33 + 34 + /* Exported for custom/extended soundcard startup ops */ 35 + int mtk_soundcard_startup(struct snd_pcm_substream *substream, 36 + enum mtk_pcm_constraint_type ctype); 43 37 44 38 int parse_dai_link_info(struct snd_soc_card *card); 45 39 void clean_card_reference(struct snd_soc_card *card);