1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright (C) 2019 Renesas Electronics Corp.
9 #include <sound/soc-link.h>
11 #define soc_link_ret(rtd, ret) _soc_link_ret(rtd, __func__, ret)
12 static inline int _soc_link_ret(struct snd_soc_pcm_runtime *rtd,
13 const char *func, int ret)
15 /* Positive, Zero values are not errors */
19 /* Negative values might be errors */
26 "ASoC: error at %s on %s: %d\n",
27 func, rtd->dai_link->name, ret);
33 int snd_soc_link_init(struct snd_soc_pcm_runtime *rtd)
37 if (rtd->dai_link->init)
38 ret = rtd->dai_link->init(rtd);
40 return soc_link_ret(rtd, ret);
43 void snd_soc_link_exit(struct snd_soc_pcm_runtime *rtd)
45 if (rtd->dai_link->exit)
46 rtd->dai_link->exit(rtd);
49 int snd_soc_link_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
50 struct snd_pcm_hw_params *params)
54 if (rtd->dai_link->be_hw_params_fixup)
55 ret = rtd->dai_link->be_hw_params_fixup(rtd, params);
57 return soc_link_ret(rtd, ret);
60 int snd_soc_link_startup(struct snd_pcm_substream *substream)
62 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
65 if (rtd->dai_link->ops &&
66 rtd->dai_link->ops->startup)
67 ret = rtd->dai_link->ops->startup(substream);
69 return soc_link_ret(rtd, ret);
72 void snd_soc_link_shutdown(struct snd_pcm_substream *substream)
74 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
76 if (rtd->dai_link->ops &&
77 rtd->dai_link->ops->shutdown)
78 rtd->dai_link->ops->shutdown(substream);
81 int snd_soc_link_prepare(struct snd_pcm_substream *substream)
83 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
86 if (rtd->dai_link->ops &&
87 rtd->dai_link->ops->prepare)
88 ret = rtd->dai_link->ops->prepare(substream);
90 return soc_link_ret(rtd, ret);
93 int snd_soc_link_hw_params(struct snd_pcm_substream *substream,
94 struct snd_pcm_hw_params *params)
96 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
99 if (rtd->dai_link->ops &&
100 rtd->dai_link->ops->hw_params)
101 ret = rtd->dai_link->ops->hw_params(substream, params);
103 return soc_link_ret(rtd, ret);
106 void snd_soc_link_hw_free(struct snd_pcm_substream *substream)
108 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
110 if (rtd->dai_link->ops &&
111 rtd->dai_link->ops->hw_free)
112 rtd->dai_link->ops->hw_free(substream);
115 int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd)
117 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
120 if (rtd->dai_link->ops &&
121 rtd->dai_link->ops->trigger)
122 ret = rtd->dai_link->ops->trigger(substream, cmd);
124 return soc_link_ret(rtd, ret);
127 int snd_soc_link_compr_startup(struct snd_compr_stream *cstream)
129 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
132 if (rtd->dai_link->compr_ops &&
133 rtd->dai_link->compr_ops->startup)
134 ret = rtd->dai_link->compr_ops->startup(cstream);
136 return soc_link_ret(rtd, ret);
138 EXPORT_SYMBOL_GPL(snd_soc_link_compr_startup);
140 void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream)
142 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
144 if (rtd->dai_link->compr_ops &&
145 rtd->dai_link->compr_ops->shutdown)
146 rtd->dai_link->compr_ops->shutdown(cstream);
148 EXPORT_SYMBOL_GPL(snd_soc_link_compr_shutdown);
150 int snd_soc_link_compr_set_params(struct snd_compr_stream *cstream)
152 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
155 if (rtd->dai_link->compr_ops &&
156 rtd->dai_link->compr_ops->set_params)
157 ret = rtd->dai_link->compr_ops->set_params(cstream);
159 return soc_link_ret(rtd, ret);
161 EXPORT_SYMBOL_GPL(snd_soc_link_compr_set_params);