Kuninori Morimoto | 02e7563 | 2020-05-25 09:57:14 +0900 | [diff] [blame] | 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 | 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 | |
| 29 | int 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 Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 38 | |
Kuninori Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 39 | int snd_soc_link_startup(struct snd_pcm_substream *substream) |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 40 | { |
Kuninori Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 41 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 42 | 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 Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 51 | void snd_soc_link_shutdown(struct snd_pcm_substream *substream) |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 52 | { |
Kuninori Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 53 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 54 | |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 55 | if (rtd->dai_link->ops && |
| 56 | rtd->dai_link->ops->shutdown) |
| 57 | rtd->dai_link->ops->shutdown(substream); |
| 58 | } |
| 59 | |
Kuninori Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 60 | int snd_soc_link_prepare(struct snd_pcm_substream *substream) |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 61 | { |
Kuninori Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 62 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 63 | 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 Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 72 | int snd_soc_link_hw_params(struct snd_pcm_substream *substream, |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 73 | struct snd_pcm_hw_params *params) |
| 74 | { |
Kuninori Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 75 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 76 | 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 Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 85 | void snd_soc_link_hw_free(struct snd_pcm_substream *substream) |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 86 | { |
Kuninori Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 87 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 88 | |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 89 | if (rtd->dai_link->ops && |
| 90 | rtd->dai_link->ops->hw_free) |
| 91 | rtd->dai_link->ops->hw_free(substream); |
| 92 | } |
| 93 | |
Kuninori Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 94 | int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd) |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 95 | { |
Kuninori Morimoto | 7cf3c5b | 2020-05-25 09:57:31 +0900 | [diff] [blame^] | 96 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | a5e6c10 | 2020-05-25 09:57:19 +0900 | [diff] [blame] | 97 | 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 | } |