xref: /openbmc/linux/sound/soc/soc-link.c (revision 4eb5928d)
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // soc-link.c
4 //
5 // Copyright (C) 2019 Renesas Electronics Corp.
6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7 //
8 #include <sound/soc.h>
9 #include <sound/soc-link.h>
10 
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)
14 {
15 	/* Positive, Zero values are not errors */
16 	if (ret >= 0)
17 		return ret;
18 
19 	/* Negative values might be errors */
20 	switch (ret) {
21 	case -EPROBE_DEFER:
22 	case -ENOTSUPP:
23 		break;
24 	default:
25 		dev_err(rtd->dev,
26 			"ASoC: error at %s on %s: %d\n",
27 			func, rtd->dai_link->name, ret);
28 	}
29 
30 	return ret;
31 }
32 
33 int snd_soc_link_init(struct snd_soc_pcm_runtime *rtd)
34 {
35 	int ret = 0;
36 
37 	if (rtd->dai_link->init)
38 		ret = rtd->dai_link->init(rtd);
39 
40 	return soc_link_ret(rtd, ret);
41 }
42 
43 void snd_soc_link_exit(struct snd_soc_pcm_runtime *rtd)
44 {
45 	if (rtd->dai_link->exit)
46 		rtd->dai_link->exit(rtd);
47 }
48 
49 int snd_soc_link_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
50 				    struct snd_pcm_hw_params *params)
51 {
52 	int ret = 0;
53 
54 	if (rtd->dai_link->be_hw_params_fixup)
55 		ret = rtd->dai_link->be_hw_params_fixup(rtd, params);
56 
57 	return soc_link_ret(rtd, ret);
58 }
59 
60 int snd_soc_link_startup(struct snd_pcm_substream *substream)
61 {
62 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
63 	int ret = 0;
64 
65 	if (rtd->dai_link->ops &&
66 	    rtd->dai_link->ops->startup)
67 		ret = rtd->dai_link->ops->startup(substream);
68 
69 	return soc_link_ret(rtd, ret);
70 }
71 
72 void snd_soc_link_shutdown(struct snd_pcm_substream *substream)
73 {
74 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
75 
76 	if (rtd->dai_link->ops &&
77 	    rtd->dai_link->ops->shutdown)
78 		rtd->dai_link->ops->shutdown(substream);
79 }
80 
81 int snd_soc_link_prepare(struct snd_pcm_substream *substream)
82 {
83 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
84 	int ret = 0;
85 
86 	if (rtd->dai_link->ops &&
87 	    rtd->dai_link->ops->prepare)
88 		ret = rtd->dai_link->ops->prepare(substream);
89 
90 	return soc_link_ret(rtd, ret);
91 }
92 
93 int snd_soc_link_hw_params(struct snd_pcm_substream *substream,
94 			   struct snd_pcm_hw_params *params)
95 {
96 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
97 	int ret = 0;
98 
99 	if (rtd->dai_link->ops &&
100 	    rtd->dai_link->ops->hw_params)
101 		ret = rtd->dai_link->ops->hw_params(substream, params);
102 
103 	return soc_link_ret(rtd, ret);
104 }
105 
106 void snd_soc_link_hw_free(struct snd_pcm_substream *substream)
107 {
108 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
109 
110 	if (rtd->dai_link->ops &&
111 	    rtd->dai_link->ops->hw_free)
112 		rtd->dai_link->ops->hw_free(substream);
113 }
114 
115 int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd)
116 {
117 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
118 	int ret = 0;
119 
120 	if (rtd->dai_link->ops &&
121 	    rtd->dai_link->ops->trigger)
122 		ret = rtd->dai_link->ops->trigger(substream, cmd);
123 
124 	return soc_link_ret(rtd, ret);
125 }
126 
127 int snd_soc_link_compr_startup(struct snd_compr_stream *cstream)
128 {
129 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
130 	int ret = 0;
131 
132 	if (rtd->dai_link->compr_ops &&
133 	    rtd->dai_link->compr_ops->startup)
134 		ret = rtd->dai_link->compr_ops->startup(cstream);
135 
136 	return soc_link_ret(rtd, ret);
137 }
138 EXPORT_SYMBOL_GPL(snd_soc_link_compr_startup);
139 
140 void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream)
141 {
142 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
143 
144 	if (rtd->dai_link->compr_ops &&
145 	    rtd->dai_link->compr_ops->shutdown)
146 		rtd->dai_link->compr_ops->shutdown(cstream);
147 }
148 EXPORT_SYMBOL_GPL(snd_soc_link_compr_shutdown);
149 
150 int snd_soc_link_compr_set_params(struct snd_compr_stream *cstream)
151 {
152 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
153 	int ret = 0;
154 
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);
158 
159 	return soc_link_ret(rtd, ret);
160 }
161 EXPORT_SYMBOL_GPL(snd_soc_link_compr_set_params);
162