[1/7] ASoC: add soc-link.c
diff mbox series

Message ID 875zcs68m4.wl-kuninori.morimoto.gx@renesas.com
State New
Headers show
Series
  • ASoC: add soc-link
Related show

Commit Message

Kuninori Morimoto May 19, 2020, 1:01 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Current ALSA SoC has many dai_link->xxx() functions.
But, it is implemented randomly at random place.

This patch creates new soc-link.c to collect dai_link related
operation into it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/soc-link.h | 13 +++++++++++++
 include/sound/soc.h      |  1 +
 sound/soc/Makefile       |  2 +-
 sound/soc/soc-core.c     | 11 +++--------
 sound/soc/soc-link.c     | 36 ++++++++++++++++++++++++++++++++++++
 5 files changed, 54 insertions(+), 9 deletions(-)
 create mode 100644 include/sound/soc-link.h
 create mode 100644 sound/soc/soc-link.c

Comments

Ranjani Sridharan May 19, 2020, 1:42 a.m. UTC | #1
On Tue, 2020-05-19 at 10:01 +0900, Kuninori Morimoto wrote:
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> Current ALSA SoC has many dai_link->xxx() functions.
> But, it is implemented randomly at random place.
> 
> This patch creates new soc-link.c to collect dai_link related
> operation into it.
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---
>  include/sound/soc-link.h | 13 +++++++++++++
>  include/sound/soc.h      |  1 +
>  sound/soc/Makefile       |  2 +-
>  sound/soc/soc-core.c     | 11 +++--------
>  sound/soc/soc-link.c     | 36 ++++++++++++++++++++++++++++++++++++
>  5 files changed, 54 insertions(+), 9 deletions(-)
>  create mode 100644 include/sound/soc-link.h
>  create mode 100644 sound/soc/soc-link.c
> 
> diff --git a/include/sound/soc-link.h b/include/sound/soc-link.h
> new file mode 100644
> index 000000000000..7fc5cead5942
> --- /dev/null
> +++ b/include/sound/soc-link.h
> @@ -0,0 +1,13 @@
> +/* SPDX-License-Identifier: GPL-2.0
> + *
> + * soc-link.h
> + *
> + * Copyright (C) 2019 Renesas Electronics Corp.
2020?
> + * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> + */
> +#ifndef __SOC_LINK_H
> +#define __SOC_LINK_H
> +
> +int snd_soc_link_init(struct snd_soc_pcm_runtime *rtd);
> +
> +#endif /* __SOC_LINK_H */
> diff --git a/include/sound/soc.h b/include/sound/soc.h
> index a7fa64260108..81d5337963ce 100644
> --- a/include/sound/soc.h
> +++ b/include/sound/soc.h
> @@ -1449,5 +1449,6 @@ static inline void
> snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
>  }
>  
>  #include <sound/soc-component.h>
> +#include <sound/soc-link.h>
Why do we need to include this in soc.h? Is it to ensure that soc-
link.h included in all files that include soc.h?

I think the right way to do this would be include soc-link.h where it
is needed, say for example in soc-pcm.c etc.
>  
>  #endif
> diff --git a/sound/soc/Makefile b/sound/soc/Makefile
> index 861a21b79484..70a5f19ea3a1 100644
> --- a/sound/soc/Makefile
> +++ b/sound/soc/Makefile
> @@ -1,6 +1,6 @@
>  # SPDX-License-Identifier: GPL-2.0
>  snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-utils.o
> soc-dai.o soc-component.o
> -snd-soc-core-objs += soc-pcm.o soc-io.o soc-devres.o soc-ops.o
> +snd-soc-core-objs += soc-pcm.o soc-io.o soc-devres.o soc-ops.o soc-
> link.o
>  snd-soc-core-$(CONFIG_SND_SOC_COMPRESS) += soc-compress.o
>  
>  ifneq ($(CONFIG_SND_SOC_TOPOLOGY),)
> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
> index e697258d2ffc..d5450e61626a 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -1049,14 +1049,9 @@ static int soc_init_pcm_runtime(struct
> snd_soc_card *card,
>  	rtd->pmdown_time = pmdown_time;
>  
>  	/* do machine specific initialization */
> -	if (dai_link->init) {
> -		ret = dai_link->init(rtd);
> -		if (ret < 0) {
> -			dev_err(card->dev, "ASoC: failed to init %s:
> %d\n",
> -				dai_link->name, ret);
> -			return ret;
> -		}
> -	}
> +	ret = snd_soc_link_init(rtd);
> +	if (ret < 0)
> +		return ret;
>  
>  	if (dai_link->dai_fmt) {
>  		ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link-
> >dai_fmt);
> diff --git a/sound/soc/soc-link.c b/sound/soc/soc-link.c
> new file mode 100644
> index 000000000000..4bdd8d0dd93a
> --- /dev/null
> +++ b/sound/soc/soc-link.c
> @@ -0,0 +1,36 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// soc-link.c
> +//
> +// Copyright (C) 2019 Renesas Electronics Corp.
2020?
Thanks,
Ranjani
Kuninori Morimoto May 19, 2020, 4:20 a.m. UTC | #2
Hi Ranjani

> > From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> > 
> > Current ALSA SoC has many dai_link->xxx() functions.
> > But, it is implemented randomly at random place.
> > 
> > This patch creates new soc-link.c to collect dai_link related
> > operation into it.
> > 
> > Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> > ---
(snip)
> >  #include <sound/soc-component.h>
> > +#include <sound/soc-link.h>
> Why do we need to include this in soc.h? Is it to ensure that soc-
> link.h included in all files that include soc.h?
> 
> I think the right way to do this would be include soc-link.h where it
> is needed, say for example in soc-pcm.c etc.

OK.
Will check and update it in v2

Thank you for your help !!

Best regards
---
Kuninori Morimoto

Patch
diff mbox series

diff --git a/include/sound/soc-link.h b/include/sound/soc-link.h
new file mode 100644
index 000000000000..7fc5cead5942
--- /dev/null
+++ b/include/sound/soc-link.h
@@ -0,0 +1,13 @@ 
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * soc-link.h
+ *
+ * Copyright (C) 2019 Renesas Electronics Corp.
+ * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
+ */
+#ifndef __SOC_LINK_H
+#define __SOC_LINK_H
+
+int snd_soc_link_init(struct snd_soc_pcm_runtime *rtd);
+
+#endif /* __SOC_LINK_H */
diff --git a/include/sound/soc.h b/include/sound/soc.h
index a7fa64260108..81d5337963ce 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1449,5 +1449,6 @@  static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
 }
 
 #include <sound/soc-component.h>
+#include <sound/soc-link.h>
 
 #endif
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 861a21b79484..70a5f19ea3a1 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,6 +1,6 @@ 
 # SPDX-License-Identifier: GPL-2.0
 snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-utils.o soc-dai.o soc-component.o
-snd-soc-core-objs += soc-pcm.o soc-io.o soc-devres.o soc-ops.o
+snd-soc-core-objs += soc-pcm.o soc-io.o soc-devres.o soc-ops.o soc-link.o
 snd-soc-core-$(CONFIG_SND_SOC_COMPRESS) += soc-compress.o
 
 ifneq ($(CONFIG_SND_SOC_TOPOLOGY),)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index e697258d2ffc..d5450e61626a 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1049,14 +1049,9 @@  static int soc_init_pcm_runtime(struct snd_soc_card *card,
 	rtd->pmdown_time = pmdown_time;
 
 	/* do machine specific initialization */
-	if (dai_link->init) {
-		ret = dai_link->init(rtd);
-		if (ret < 0) {
-			dev_err(card->dev, "ASoC: failed to init %s: %d\n",
-				dai_link->name, ret);
-			return ret;
-		}
-	}
+	ret = snd_soc_link_init(rtd);
+	if (ret < 0)
+		return ret;
 
 	if (dai_link->dai_fmt) {
 		ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
diff --git a/sound/soc/soc-link.c b/sound/soc/soc-link.c
new file mode 100644
index 000000000000..4bdd8d0dd93a
--- /dev/null
+++ b/sound/soc/soc-link.c
@@ -0,0 +1,36 @@ 
+// SPDX-License-Identifier: GPL-2.0
+//
+// soc-link.c
+//
+// Copyright (C) 2019 Renesas Electronics Corp.
+// Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
+//
+#include <sound/soc.h>
+
+#define soc_link_ret(rtd, ret) _soc_link_ret(rtd, __func__, ret)
+static inline int _soc_link_ret(struct snd_soc_pcm_runtime *rtd,
+				const char *func, int ret)
+{
+	switch (ret) {
+	case -EPROBE_DEFER:
+	case -ENOTSUPP:
+	case 0:
+		break;
+	default:
+		dev_err(rtd->dev,
+			"ASoC: error at %s on %s: %d\n",
+			func, rtd->dai_link->name, ret);
+	}
+
+	return ret;
+}
+
+int snd_soc_link_init(struct snd_soc_pcm_runtime *rtd)
+{
+	int ret = 0;
+
+	if (rtd->dai_link->init)
+		ret = rtd->dai_link->init(rtd);
+
+	return soc_link_ret(rtd, ret);
+}