blob: 2a8881978930d975b5be6e90aaad35dca839b7e5 [file] [log] [blame]
Kuninori Morimoto02e75632020-05-25 09:57:14 +09001// 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)
12static inline int _soc_link_ret(struct snd_soc_pcm_runtime *rtd,
13 const char *func, int ret)
14{
Pierre-Louis Bossart28ff4372020-05-29 07:36:13 -050015 /* Positive, Zero values are not errors */
16 if (ret >= 0)
17 return ret;
18
19 /* Negative values might be errors */
Kuninori Morimoto02e75632020-05-25 09:57:14 +090020 switch (ret) {
21 case -EPROBE_DEFER:
22 case -ENOTSUPP:
Kuninori Morimoto02e75632020-05-25 09:57:14 +090023 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
Kuninori Morimoto6064ed72020-09-28 09:00:57 +090033/*
34 * We might want to check substream by using list.
35 * In such case, we can update these macros.
36 */
37#define soc_link_mark_push(rtd, substream, tgt) ((rtd)->mark_##tgt = substream)
38#define soc_link_mark_pop(rtd, substream, tgt) ((rtd)->mark_##tgt = NULL)
39#define soc_link_mark_match(rtd, substream, tgt) ((rtd)->mark_##tgt == substream)
40
Kuninori Morimoto02e75632020-05-25 09:57:14 +090041int snd_soc_link_init(struct snd_soc_pcm_runtime *rtd)
42{
43 int ret = 0;
44
45 if (rtd->dai_link->init)
46 ret = rtd->dai_link->init(rtd);
47
48 return soc_link_ret(rtd, ret);
49}
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090050
Pierre-Louis Bossart21a00fb2020-06-22 10:42:37 -050051void snd_soc_link_exit(struct snd_soc_pcm_runtime *rtd)
52{
53 if (rtd->dai_link->exit)
54 rtd->dai_link->exit(rtd);
55}
56
Kuninori Morimoto0cbbf8a2020-05-25 09:57:36 +090057int snd_soc_link_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
58 struct snd_pcm_hw_params *params)
59{
60 int ret = 0;
61
62 if (rtd->dai_link->be_hw_params_fixup)
63 ret = rtd->dai_link->be_hw_params_fixup(rtd, params);
64
65 return soc_link_ret(rtd, ret);
66}
67
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090068int snd_soc_link_startup(struct snd_pcm_substream *substream)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090069{
Kuninori Morimoto0ceef682020-07-20 10:17:39 +090070 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090071 int ret = 0;
72
73 if (rtd->dai_link->ops &&
74 rtd->dai_link->ops->startup)
75 ret = rtd->dai_link->ops->startup(substream);
76
Kuninori Morimoto6064ed72020-09-28 09:00:57 +090077 /* mark substream if succeeded */
78 if (ret == 0)
79 soc_link_mark_push(rtd, substream, startup);
80
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090081 return soc_link_ret(rtd, ret);
82}
83
Kuninori Morimoto6064ed72020-09-28 09:00:57 +090084void snd_soc_link_shutdown(struct snd_pcm_substream *substream,
85 int rollback)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090086{
Kuninori Morimoto0ceef682020-07-20 10:17:39 +090087 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090088
Kuninori Morimoto6064ed72020-09-28 09:00:57 +090089 if (rollback && !soc_link_mark_match(rtd, substream, startup))
90 return;
91
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090092 if (rtd->dai_link->ops &&
93 rtd->dai_link->ops->shutdown)
94 rtd->dai_link->ops->shutdown(substream);
Kuninori Morimoto6064ed72020-09-28 09:00:57 +090095
96 /* remove marked substream */
97 soc_link_mark_pop(rtd, substream, startup);
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090098}
99
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +0900100int snd_soc_link_prepare(struct snd_pcm_substream *substream)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +0900101{
Kuninori Morimoto0ceef682020-07-20 10:17:39 +0900102 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +0900103 int ret = 0;
104
105 if (rtd->dai_link->ops &&
106 rtd->dai_link->ops->prepare)
107 ret = rtd->dai_link->ops->prepare(substream);
108
109 return soc_link_ret(rtd, ret);
110}
111
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +0900112int snd_soc_link_hw_params(struct snd_pcm_substream *substream,
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +0900113 struct snd_pcm_hw_params *params)
114{
Kuninori Morimoto0ceef682020-07-20 10:17:39 +0900115 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +0900116 int ret = 0;
117
118 if (rtd->dai_link->ops &&
119 rtd->dai_link->ops->hw_params)
120 ret = rtd->dai_link->ops->hw_params(substream, params);
121
122 return soc_link_ret(rtd, ret);
123}
124
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +0900125void snd_soc_link_hw_free(struct snd_pcm_substream *substream)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +0900126{
Kuninori Morimoto0ceef682020-07-20 10:17:39 +0900127 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +0900128
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +0900129 if (rtd->dai_link->ops &&
130 rtd->dai_link->ops->hw_free)
131 rtd->dai_link->ops->hw_free(substream);
132}
133
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +0900134int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +0900135{
Kuninori Morimoto0ceef682020-07-20 10:17:39 +0900136 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +0900137 int ret = 0;
138
139 if (rtd->dai_link->ops &&
140 rtd->dai_link->ops->trigger)
141 ret = rtd->dai_link->ops->trigger(substream, cmd);
142
143 return soc_link_ret(rtd, ret);
144}
Kuninori Morimoto9ab711c2020-05-25 09:57:41 +0900145
146int snd_soc_link_compr_startup(struct snd_compr_stream *cstream)
147{
148 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
149 int ret = 0;
150
151 if (rtd->dai_link->compr_ops &&
152 rtd->dai_link->compr_ops->startup)
153 ret = rtd->dai_link->compr_ops->startup(cstream);
154
155 return soc_link_ret(rtd, ret);
156}
157EXPORT_SYMBOL_GPL(snd_soc_link_compr_startup);
Kuninori Morimoto0e532c92020-05-25 09:57:45 +0900158
159void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream)
160{
161 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
162
163 if (rtd->dai_link->compr_ops &&
164 rtd->dai_link->compr_ops->shutdown)
165 rtd->dai_link->compr_ops->shutdown(cstream);
166}
167EXPORT_SYMBOL_GPL(snd_soc_link_compr_shutdown);
Kuninori Morimotoeab810f2020-05-25 09:57:50 +0900168
169int snd_soc_link_compr_set_params(struct snd_compr_stream *cstream)
170{
171 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
172 int ret = 0;
173
174 if (rtd->dai_link->compr_ops &&
175 rtd->dai_link->compr_ops->set_params)
176 ret = rtd->dai_link->compr_ops->set_params(cstream);
177
178 return soc_link_ret(rtd, ret);
179}
180EXPORT_SYMBOL_GPL(snd_soc_link_compr_set_params);