blob: 5ce3e209b1a84dec754d865ad73ccc5f0091fda5 [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{
15 switch (ret) {
16 case -EPROBE_DEFER:
17 case -ENOTSUPP:
18 case 0:
19 break;
20 default:
21 dev_err(rtd->dev,
22 "ASoC: error at %s on %s: %d\n",
23 func, rtd->dai_link->name, ret);
24 }
25
26 return ret;
27}
28
29int snd_soc_link_init(struct snd_soc_pcm_runtime *rtd)
30{
31 int ret = 0;
32
33 if (rtd->dai_link->init)
34 ret = rtd->dai_link->init(rtd);
35
36 return soc_link_ret(rtd, ret);
37}
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090038
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090039int snd_soc_link_startup(struct snd_pcm_substream *substream)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090040{
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090041 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090042 int ret = 0;
43
44 if (rtd->dai_link->ops &&
45 rtd->dai_link->ops->startup)
46 ret = rtd->dai_link->ops->startup(substream);
47
48 return soc_link_ret(rtd, ret);
49}
50
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090051void snd_soc_link_shutdown(struct snd_pcm_substream *substream)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090052{
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090053 struct snd_soc_pcm_runtime *rtd = substream->private_data;
54
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090055 if (rtd->dai_link->ops &&
56 rtd->dai_link->ops->shutdown)
57 rtd->dai_link->ops->shutdown(substream);
58}
59
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090060int snd_soc_link_prepare(struct snd_pcm_substream *substream)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090061{
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090062 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090063 int ret = 0;
64
65 if (rtd->dai_link->ops &&
66 rtd->dai_link->ops->prepare)
67 ret = rtd->dai_link->ops->prepare(substream);
68
69 return soc_link_ret(rtd, ret);
70}
71
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090072int snd_soc_link_hw_params(struct snd_pcm_substream *substream,
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090073 struct snd_pcm_hw_params *params)
74{
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090075 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090076 int ret = 0;
77
78 if (rtd->dai_link->ops &&
79 rtd->dai_link->ops->hw_params)
80 ret = rtd->dai_link->ops->hw_params(substream, params);
81
82 return soc_link_ret(rtd, ret);
83}
84
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090085void snd_soc_link_hw_free(struct snd_pcm_substream *substream)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090086{
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090087 struct snd_soc_pcm_runtime *rtd = substream->private_data;
88
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090089 if (rtd->dai_link->ops &&
90 rtd->dai_link->ops->hw_free)
91 rtd->dai_link->ops->hw_free(substream);
92}
93
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090094int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd)
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090095{
Kuninori Morimoto7cf3c5b2020-05-25 09:57:31 +090096 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Kuninori Morimotoa5e6c102020-05-25 09:57:19 +090097 int ret = 0;
98
99 if (rtd->dai_link->ops &&
100 rtd->dai_link->ops->trigger)
101 ret = rtd->dai_link->ops->trigger(substream, cmd);
102
103 return soc_link_ret(rtd, ret);
104}