xref: /linux/sound/soc/soc-link.c (revision 95298d63c67673c654c08952672d016212b26054)
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 int snd_soc_link_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
44 				    struct snd_pcm_hw_params *params)
45 {
46 	int ret = 0;
47 
48 	if (rtd->dai_link->be_hw_params_fixup)
49 		ret = rtd->dai_link->be_hw_params_fixup(rtd, params);
50 
51 	return soc_link_ret(rtd, ret);
52 }
53 
54 int snd_soc_link_startup(struct snd_pcm_substream *substream)
55 {
56 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
57 	int ret = 0;
58 
59 	if (rtd->dai_link->ops &&
60 	    rtd->dai_link->ops->startup)
61 		ret = rtd->dai_link->ops->startup(substream);
62 
63 	return soc_link_ret(rtd, ret);
64 }
65 
66 void snd_soc_link_shutdown(struct snd_pcm_substream *substream)
67 {
68 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
69 
70 	if (rtd->dai_link->ops &&
71 	    rtd->dai_link->ops->shutdown)
72 		rtd->dai_link->ops->shutdown(substream);
73 }
74 
75 int snd_soc_link_prepare(struct snd_pcm_substream *substream)
76 {
77 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
78 	int ret = 0;
79 
80 	if (rtd->dai_link->ops &&
81 	    rtd->dai_link->ops->prepare)
82 		ret = rtd->dai_link->ops->prepare(substream);
83 
84 	return soc_link_ret(rtd, ret);
85 }
86 
87 int snd_soc_link_hw_params(struct snd_pcm_substream *substream,
88 			   struct snd_pcm_hw_params *params)
89 {
90 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
91 	int ret = 0;
92 
93 	if (rtd->dai_link->ops &&
94 	    rtd->dai_link->ops->hw_params)
95 		ret = rtd->dai_link->ops->hw_params(substream, params);
96 
97 	return soc_link_ret(rtd, ret);
98 }
99 
100 void snd_soc_link_hw_free(struct snd_pcm_substream *substream)
101 {
102 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
103 
104 	if (rtd->dai_link->ops &&
105 	    rtd->dai_link->ops->hw_free)
106 		rtd->dai_link->ops->hw_free(substream);
107 }
108 
109 int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd)
110 {
111 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
112 	int ret = 0;
113 
114 	if (rtd->dai_link->ops &&
115 	    rtd->dai_link->ops->trigger)
116 		ret = rtd->dai_link->ops->trigger(substream, cmd);
117 
118 	return soc_link_ret(rtd, ret);
119 }
120 
121 int snd_soc_link_compr_startup(struct snd_compr_stream *cstream)
122 {
123 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
124 	int ret = 0;
125 
126 	if (rtd->dai_link->compr_ops &&
127 	    rtd->dai_link->compr_ops->startup)
128 		ret = rtd->dai_link->compr_ops->startup(cstream);
129 
130 	return soc_link_ret(rtd, ret);
131 }
132 EXPORT_SYMBOL_GPL(snd_soc_link_compr_startup);
133 
134 void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream)
135 {
136 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
137 
138 	if (rtd->dai_link->compr_ops &&
139 	    rtd->dai_link->compr_ops->shutdown)
140 		rtd->dai_link->compr_ops->shutdown(cstream);
141 }
142 EXPORT_SYMBOL_GPL(snd_soc_link_compr_shutdown);
143 
144 int snd_soc_link_compr_set_params(struct snd_compr_stream *cstream)
145 {
146 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
147 	int ret = 0;
148 
149 	if (rtd->dai_link->compr_ops &&
150 	    rtd->dai_link->compr_ops->set_params)
151 		ret = rtd->dai_link->compr_ops->set_params(cstream);
152 
153 	return soc_link_ret(rtd, ret);
154 }
155 EXPORT_SYMBOL_GPL(snd_soc_link_compr_set_params);
156