^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // soc-link.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Copyright (C) 2019 Renesas Electronics Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <sound/soc-link.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define soc_link_ret(rtd, ret) _soc_link_ret(rtd, __func__, ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static inline int _soc_link_ret(struct snd_soc_pcm_runtime *rtd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) const char *func, int ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /* Positive, Zero values are not errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* Negative values might be errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) switch (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) case -EPROBE_DEFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) case -ENOTSUPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) dev_err(rtd->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) "ASoC: error at %s on %s: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) func, rtd->dai_link->name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * We might want to check substream by using list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * In such case, we can update these macros.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define soc_link_mark_push(rtd, substream, tgt) ((rtd)->mark_##tgt = substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define soc_link_mark_pop(rtd, substream, tgt) ((rtd)->mark_##tgt = NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define soc_link_mark_match(rtd, substream, tgt) ((rtd)->mark_##tgt == substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int snd_soc_link_init(struct snd_soc_pcm_runtime *rtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (rtd->dai_link->init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ret = rtd->dai_link->init(rtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return soc_link_ret(rtd, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void snd_soc_link_exit(struct snd_soc_pcm_runtime *rtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (rtd->dai_link->exit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) rtd->dai_link->exit(rtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int snd_soc_link_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (rtd->dai_link->be_hw_params_fixup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ret = rtd->dai_link->be_hw_params_fixup(rtd, params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return soc_link_ret(rtd, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int snd_soc_link_startup(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (rtd->dai_link->ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) rtd->dai_link->ops->startup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ret = rtd->dai_link->ops->startup(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* mark substream if succeeded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) soc_link_mark_push(rtd, substream, startup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return soc_link_ret(rtd, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void snd_soc_link_shutdown(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int rollback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (rollback && !soc_link_mark_match(rtd, substream, startup))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (rtd->dai_link->ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) rtd->dai_link->ops->shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) rtd->dai_link->ops->shutdown(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* remove marked substream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) soc_link_mark_pop(rtd, substream, startup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int snd_soc_link_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (rtd->dai_link->ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) rtd->dai_link->ops->prepare)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ret = rtd->dai_link->ops->prepare(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return soc_link_ret(rtd, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int snd_soc_link_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (rtd->dai_link->ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) rtd->dai_link->ops->hw_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ret = rtd->dai_link->ops->hw_params(substream, params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return soc_link_ret(rtd, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) void snd_soc_link_hw_free(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (rtd->dai_link->ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) rtd->dai_link->ops->hw_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) rtd->dai_link->ops->hw_free(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (rtd->dai_link->ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) rtd->dai_link->ops->trigger)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ret = rtd->dai_link->ops->trigger(substream, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return soc_link_ret(rtd, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int snd_soc_link_compr_startup(struct snd_compr_stream *cstream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct snd_soc_pcm_runtime *rtd = cstream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (rtd->dai_link->compr_ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) rtd->dai_link->compr_ops->startup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ret = rtd->dai_link->compr_ops->startup(cstream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return soc_link_ret(rtd, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) EXPORT_SYMBOL_GPL(snd_soc_link_compr_startup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct snd_soc_pcm_runtime *rtd = cstream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (rtd->dai_link->compr_ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) rtd->dai_link->compr_ops->shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) rtd->dai_link->compr_ops->shutdown(cstream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) EXPORT_SYMBOL_GPL(snd_soc_link_compr_shutdown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int snd_soc_link_compr_set_params(struct snd_compr_stream *cstream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct snd_soc_pcm_runtime *rtd = cstream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (rtd->dai_link->compr_ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) rtd->dai_link->compr_ops->set_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ret = rtd->dai_link->compr_ops->set_params(cstream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return soc_link_ret(rtd, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) EXPORT_SYMBOL_GPL(snd_soc_link_compr_set_params);