Skip to contentSkip to conversation

ASoC: samsung: Provide helper for DMA init

PATCH In review Mark Brown 2 participants 11 messages Dec 5, 2013 – Dec 10, 2013

Subsystems (4)
lore
Share & tools
lore

Mark Brown

author maintainer
#0 lore raw

PATCH 1/2 ASoC: samsung: Provide helper for DMA init

From: Mark Brown <[email protected]>

In preparation for using the dmaengine helpers in ASoC rather than the dmaengine wrappers for the Samsung API wrap the configuration of dma_data. The dmaengine code expects different data to that used by the legacy API.

---

This will need merging with the fix patch I sent earlier, I'l do that assuming this is OK.

 sound/soc/samsung/ac97.c | 51 +++++++++++++++---------------------------------
 sound/soc/samsung/dma.c  |  8 ++++++++
 sound/soc/samsung/dma.h  |  3 +++
 sound/soc/samsung/i2s.c  |  7 +++++--
 sound/soc/samsung/pcm.c  | 18 +++++++++--------
 5 files changed, 42 insertions(+), 45 deletions(-)
sound/soc/samsung/ac97.c +16 -35
index 350ba23a9893..4a88e36c82ec 100644
@@ -221,24 +221,6 @@ static struct snd_ac97_bus_ops s3c_ac97_ops = {
 	.reset      = s3c_ac97_cold_reset,
 };
 
-static int s3c_ac97_hw_params(struct snd_pcm_substream *substream,
-				  struct snd_pcm_hw_params *params,
-				  struct snd_soc_dai *dai)
-{
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-	struct s3c_dma_params *dma_data;
-
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		dma_data = &s3c_ac97_pcm_out;
-	else
-		dma_data = &s3c_ac97_pcm_in;
-
-	snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
-
-	return 0;
-}
-
 static int s3c_ac97_trigger(struct snd_pcm_substream *substream, int cmd,
 				struct snd_soc_dai *dai)
 {
@@ -279,21 +261,6 @@ static int s3c_ac97_trigger(struct snd_pcm_substream *substream, int cmd,
 	return 0;
 }
 
-static int s3c_ac97_hw_mic_params(struct snd_pcm_substream *substream,
-				      struct snd_pcm_hw_params *params,
-				      struct snd_soc_dai *dai)
-{
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		return -ENODEV;
-	else
-		snd_soc_dai_set_dma_data(cpu_dai, substream, &s3c_ac97_mic_in);
-
-	return 0;
-}
-
 static int s3c_ac97_mic_trigger(struct snd_pcm_substream *substream,
 				    int cmd, struct snd_soc_dai *dai)
 {
@@ -329,15 +296,27 @@ static int s3c_ac97_mic_trigger(struct snd_pcm_substream *substream,
 }
 
 static const struct snd_soc_dai_ops s3c_ac97_dai_ops = {
-	.hw_params	= s3c_ac97_hw_params,
 	.trigger	= s3c_ac97_trigger,
 };
 
 static const struct snd_soc_dai_ops s3c_ac97_mic_dai_ops = {
-	.hw_params	= s3c_ac97_hw_mic_params,
 	.trigger	= s3c_ac97_mic_trigger,
 };
 
+static int s3c_ac97_dai_probe(struct snd_soc_dai *dai)
+{
+	samsung_asoc_init_dma_data(dai, &s3c_ac97_pcm_out, &s3c_ac97_pcm_in);
+
+	return 0;
+}
+
+static int s3c_ac97_mic_dai_probe(struct snd_soc_dai *dai)
+{
+	samsung_asoc_init_dma_data(dai, NULL, &s3c_ac97_mic_in);
+
+	return 0;
+}
+
 static struct snd_soc_dai_driver s3c_ac97_dai[] = {
 	[S3C_AC97_DAI_PCM] = {
 		.name =	"samsung-ac97",
@@ -354,6 +333,7 @@ static struct snd_soc_dai_driver s3c_ac97_dai[] = {
 			.channels_max = 2,
 			.rates = SNDRV_PCM_RATE_8000_48000,
 			.formats = SNDRV_PCM_FMTBIT_S16_LE,},
+		.probe = s3c_ac97_dai_probe,
 		.ops = &s3c_ac97_dai_ops,
 	},
 	[S3C_AC97_DAI_MIC] = {
@@ -365,6 +345,7 @@ static struct snd_soc_dai_driver s3c_ac97_dai[] = {
 			.channels_max = 1,
 			.rates = SNDRV_PCM_RATE_8000_48000,
 			.formats = SNDRV_PCM_FMTBIT_S16_LE,},
+		.probe = s3c_ac97_mic_dai_probe,
 		.ops = &s3c_ac97_mic_dai_ops,
 	},
 };
sound/soc/samsung/dma.c +8 -0
index fe2748b494d4..ee23194f7ab8 100644
@@ -441,6 +441,14 @@ static struct snd_soc_platform_driver samsung_asoc_platform = {
 	.pcm_free	= dma_free_dma_buffers,
 };
 
+void samsung_asoc_init_dma_data(struct snd_soc_dai *dai,
+				struct s3c_dma_params *playback,
+				struct s3c_dma_params *capture)
+{
+	snd_soc_dai_init_dma_data(dai, playback, capture);
+}
+EXPORT_SYMBOL_GPL(samsung_asoc_init_dma_data);
+
 int samsung_asoc_dma_platform_register(struct device *dev)
 {
 	return snd_soc_register_platform(dev, &samsung_asoc_platform);
sound/soc/samsung/dma.h +3 -0
index 0e86315a3eaf..fb09a1c5f75b 100644
@@ -22,6 +22,9 @@ struct s3c_dma_params {
 	char *ch_name;
 };
 
+void samsung_asoc_init_dma_data(struct snd_soc_dai *dai,
+				struct s3c_dma_params *playback,
+				struct s3c_dma_params *capture);
 int samsung_asoc_dma_platform_register(struct device *dev);
 void samsung_asoc_dma_platform_unregister(struct device *dev);
 
sound/soc/samsung/i2s.c +5 -2
index a5cbdb4f1655..eab0050d4579 100644
@@ -946,8 +946,11 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
 	struct i2s_dai *i2s = to_info(dai);
 	struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
 
-	if (other && other->clk) /* If this is probe on secondary */
+	if (other && other->clk) { /* If this is probe on secondary */
+		samsung_asoc_init_dma_data(dai, &other->sec_dai->dma_playback,
+					   NULL);
 		goto probe_exit;
+	}
 
 	i2s->addr = ioremap(i2s->base, 0x100);
 	if (i2s->addr == NULL) {
@@ -963,7 +966,7 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
 	}
 	clk_prepare_enable(i2s->clk);
 
-	snd_soc_dai_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
+	samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
 
 	if (other) {
 		other->addr = i2s->addr;
sound/soc/samsung/pcm.c +10 -8
index e54256fc4b2c..6a5e4bf6ac96 100644
@@ -275,7 +275,6 @@ static int s3c_pcm_hw_params(struct snd_pcm_substream *substream,
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct s3c_pcm_info *pcm = snd_soc_dai_get_drvdata(rtd->cpu_dai);
-	struct s3c_dma_params *dma_data;
 	void __iomem *regs = pcm->regs;
 	struct clk *clk;
 	int sclk_div, sync_div;
@@ -284,13 +283,6 @@ static int s3c_pcm_hw_params(struct snd_pcm_substream *substream,
 
 	dev_dbg(pcm->dev, "Entered %s\n", __func__);
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		dma_data = pcm->dma_playback;
-	else
-		dma_data = pcm->dma_capture;
-
-	snd_soc_dai_set_dma_data(rtd->cpu_dai, substream, dma_data);
-
 	/* Strictly check for sample size */
 	switch (params_format(params)) {
 	case SNDRV_PCM_FORMAT_S16_LE:
@@ -461,10 +453,20 @@ static const struct snd_soc_dai_ops s3c_pcm_dai_ops = {
 	.set_fmt	= s3c_pcm_set_fmt,
 };
 
+static int s3c_pcm_dai_probe(struct snd_soc_dai *dai)
+{
+	struct s3c_pcm_info *pcm = snd_soc_dai_get_drvdata(dai);
+
+	snd_soc_dai_init_dma_data(dai, pcm->dma_playback, pcm->dma_capture);
+
+	return 0;
+}
+
 #define S3C_PCM_RATES  SNDRV_PCM_RATE_8000_96000
 
 #define S3C_PCM_DAI_DECLARE			\
 	.symmetric_rates = 1,					\
+	.probe = s3c_pcm_dai_probe,				\
 	.ops = &s3c_pcm_dai_ops,				\
 	.playback = {						\
 		.channels_min	= 2,				\
Signature · 1 line
1.8.5.1
author maintainer
#1 lore raw

PATCH 2/2 ASoC: samsung: Use ASoC dmaengine code where possible

From: Mark Brown <[email protected]>

Since all Exynos platforms have been converted to dmaengine and many of the older platforms are in the process of conversion they do not need to use the legacy s3c-dma APIs for DMA but can instead use the standard ASoC dmaengine helpers. This both allows them to benefit from improvements implemented in the generic code and supports multiplatform.

This patch includes some fixes from Padma for Exynos SoCs.

Tested By: Padmavathi Venna <[email protected]>
---

I think this should reflect all your testing but a recheck would be good.

 sound/soc/samsung/Kconfig     | 13 +++++--
 sound/soc/samsung/Makefile    |  6 ++--
 sound/soc/samsung/dma.h       |  3 ++
 sound/soc/samsung/dmaengine.c | 84 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 102 insertions(+), 4 deletions(-)
 create mode 100644 sound/soc/samsung/dmaengine.c
sound/soc/samsung/Kconfig +11 -2
index 37459dfd168d..27930fc432dc 100644
@@ -1,13 +1,22 @@
 config SND_SOC_SAMSUNG
 	tristate "ASoC support for Samsung"
 	depends on PLAT_SAMSUNG
-	select S3C64XX_DMA if ARCH_S3C64XX
-	select S3C24XX_DMA if ARCH_S3C24XX
+	select S3C2410_DMA if ARCH_S3C24XX
+	select S3C64XX_PL080 if ARCH_S3C64XX
+	select SND_S3C_DMA if !ARCH_S3C24XX
+	select SND_S3C_DMA_LEGACY if ARCH_S3C24XX
+	select SND_SOC_GENERIC_DMAENGINE_PCM if !ARCH_S3C24XX
 	help
 	  Say Y or M if you want to add support for codecs attached to
 	  the Samsung SoCs' Audio interfaces. You will also need to
 	  select the audio interfaces to support below.
 
+config SND_S3C_DMA
+	tristate
+
+config SND_S3C_DMA_LEGACY
+	tristate
+
 config SND_S3C24XX_I2S
 	tristate
 	select S3C2410_DMA
sound/soc/samsung/Makefile +4 -2
index 709f6059ad67..86715d8efee6 100644
@@ -1,5 +1,6 @@
 # S3c24XX Platform Support
-snd-soc-s3c24xx-objs := dma.o
+snd-soc-s3c-dma-objs := dmaengine.o
+snd-soc-s3c-dma-legacy-objs := dma.o
 snd-soc-idma-objs := idma.o
 snd-soc-s3c24xx-i2s-objs := s3c24xx-i2s.o
 snd-soc-s3c2412-i2s-objs := s3c2412-i2s.o
@@ -9,7 +10,8 @@ snd-soc-samsung-spdif-objs := spdif.o
 snd-soc-pcm-objs := pcm.o
 snd-soc-i2s-objs := i2s.o
 
-obj-$(CONFIG_SND_SOC_SAMSUNG) += snd-soc-s3c24xx.o
+obj-$(CONFIG_SND_S3C_DMA) += snd-soc-s3c-dma.o
+obj-$(CONFIG_SND_S3C_DMA_LEGACY) += snd-soc-s3c-dma-legacy.o
 obj-$(CONFIG_SND_S3C24XX_I2S) += snd-soc-s3c24xx-i2s.o
 obj-$(CONFIG_SND_SAMSUNG_AC97) += snd-soc-ac97.o
 obj-$(CONFIG_SND_S3C2412_SOC_I2S) += snd-soc-s3c2412-i2s.o
sound/soc/samsung/dma.h +3 -0
index fb09a1c5f75b..225e5378014e 100644
@@ -12,6 +12,8 @@
 #ifndef _S3C_AUDIO_H
 #define _S3C_AUDIO_H
 
+#include <sound/dmaengine_pcm.h>
+
 struct s3c_dma_params {
 	struct s3c2410_dma_client *client;	/* stream identifier */
 	int channel;				/* Channel ID */
@@ -20,6 +22,7 @@ struct s3c_dma_params {
 	unsigned ch;
 	struct samsung_dma_ops *ops;
 	char *ch_name;
+	struct snd_dmaengine_dai_dma_data dma_data;
 };
 
 void samsung_asoc_init_dma_data(struct snd_soc_dai *dai,
sound/soc/samsung/dmaengine.c new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
1.8.5.1
#2 lore raw

Re: [alsa-devel] [PATCH 2/2] ASoC: samsung: Use ASoC dmaengine code where possible

Hi Mark,

Quoted 8 lines · Mark Brown

From: Mark Brown <[email protected]>

Since all Exynos platforms have been converted to dmaengine and many of the older platforms are in the process of conversion they do not need to use the legacy s3c-dma APIs for DMA but can instead use the standard ASoC dmaengine helpers. This both allows them to benefit from improvements implemented in the generic code and supports multiplatform.

Quoted 7 lines

This patch includes some fixes from Padma for Exynos SoCs.

Tested By: Padmavathi Venna <[email protected]>
---

I think this should reflect all your testing but a recheck would be good.

I couldn't test this patch set due to some crash in recent kernel in dmaengine_unmap_put. I think this unmap support is not yet implemented for pl330 driver. It is mentioned in the commit "dmaengine: prepare for generic 'unmap' data", [bzolnier: prepare pl330 driver for adding missing unmap while at it].

[snip]

sound/soc/samsung/dmaengine.c line 71

Quoted 6 lines
sound/soc/samsung/dmaengine.c new file +6 -0
+
+int samsung_asoc_dma_platform_register(struct device *dev)
+{
+       return snd_dmaengine_pcm_register(dev, &samsung_dmaengine_pcm_config,
+                                         SND_DMAENGINE_PCM_FLAG_CUSTOM_CHANNEL_NAME |
+                                         SND_DMAENGINE_PCM_NO_RESIDUE |

This flag should be SND_DMAENGINE_PCM_FLAG_NO_RESIDUE.

sound/soc/samsung/dmaengine.c line 75

Quoted 4 lines
sound/soc/samsung/dmaengine.c new file +4 -0
+                                         SND_DMAENGINE_PCM_FLAG_COMPAT);
+}
+EXPORT_SYMBOL_GPL(samsung_asoc_dma_platform_register);
+

Thanks
Padma

author maintainer
#3 lore raw

Re: [alsa-devel] [PATCH 2/2] ASoC: samsung: Use ASoC dmaengine code where possible

Quoted 5 lines · Padma Venkat

I couldn't test this patch set due to some crash in recent kernel in dmaengine_unmap_put. I think this unmap support is not yet implemented for pl330 driver. It is mentioned in the commit "dmaengine: prepare for generic 'unmap' data", [bzolnier: prepare pl330 driver for adding missing unmap while at it].

This is unfortunate... I'd suggest trying mainline but I see it's broken in Linus' tree too and no fixes in -next. :(

I'm tempted to push up with your Tested-by a note saying you did your testing on an earlier version but weren't able to test due to other bugs.

#4 lore raw

Re: [alsa-devel] [PATCH 2/2] ASoC: samsung: Use ASoC dmaengine code where possible

Hi Mark,

Quoted 8 lines · Mark Brown
Quoted 5 lines · Padma Venkat

I couldn't test this patch set due to some crash in recent kernel in dmaengine_unmap_put. I think this unmap support is not yet implemented for pl330 driver. It is mentioned in the commit "dmaengine: prepare for generic 'unmap' data", [bzolnier: prepare pl330 driver for adding missing unmap while at it].

Quoted 5 lines

This is unfortunate... I'd suggest trying mainline but I see it's broken in Linus' tree too and no fixes in -next. :(

I'm tempted to push up with your Tested-by a note saying you did your testing on an earlier version but weren't able to test due to other bugs.

I managed to test your latest version of these patches(posted on Dec6th) on earlier version of linux-samsung tree. May be you can push up these patches with my Tested-by.

Thanks
Padma

author maintainer
#5 lore raw

Re: [PATCH 2/2] ASoC: samsung: Use ASoC dmaengine code where possible

Quoted 11 lines · Padma Venkat
Quoted 5 lines · Mark Brown

This is unfortunate... I'd suggest trying mainline but I see it's broken in Linus' tree too and no fixes in -next. :(

I'm tempted to push up with your Tested-by a note saying you did your testing on an earlier version but weren't able to test due to other bugs.

I managed to test your latest version of these patches(posted on Dec6th) on earlier version of linux-samsung tree. May be you can push up these patches with my Tested-by.

Yeah, that was what I was planning - I was just going to add a note saying you'd not been able to test this version due to the other breakage so if it turns out to have problems people know it was something I introduced after your testing.

#6 lore raw
In reply to Mark Brown

Hi Mark,

Quoted 12 lines · Mark Brown

From: Mark Brown <[email protected]>

In preparation for using the dmaengine helpers in ASoC rather than the dmaengine wrappers for the Samsung API wrap the configuration of dma_data. The dmaengine code expects different data to that used by the legacy API.

---

This will need merging with the fix patch I sent earlier, I'l do that assuming this is OK.

[snip]

Quoted 5 lines
sound/soc/samsung/i2s.c +0 -0
index a5cbdb4f1655..eab0050d4579 100644

sound/soc/samsung/i2s.c static int samsung_i2s_dai_probe(struct snd_soc_dai *dai) · line 953

Quoted 9 lines
sound/soc/samsung/i2s.c +4 -1
@@ -946,8 +946,11 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
        struct i2s_dai *i2s = to_info(dai);
        struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
 
-       if (other && other->clk) /* If this is probe on secondary */
+       if (other && other->clk) { /* If this is probe on secondary */
+               samsung_asoc_init_dma_data(dai, &other->sec_dai->dma_playback,
+                                          NULL);
                goto probe_exit;
+       }

This is done in your earlier patch " ASoC: samsung: Ensure DMA data is initialised for secondary DAI ". Was it done on purpose or by mistake in this patch?

I think you also told to include a patch for reinitialization of the dma_data in i2s_hw_params. If you are in the process of debugging some bug as you mentioned earlier you can ignore this comment. Otherwise it is just a reminder.

Thanks
Padma

author maintainer
#7 lore raw
Quoted 3 lines · Padma Venkat

This is done in your earlier patch " ASoC: samsung: Ensure DMA data is initialised for secondary DAI ". Was it done on purpose or by mistake in this patch?

It's intentional - notice that the function has changed, this is why I kept asking you about mainline. Mainline doesn't have the wrapper function that abstracts the difference between s3c-dma and dmaengine, this is why I'm saying these two will need to be rebased on top of the mainline fix.

Quoted 4 lines

I think you also told to include a patch for reinitialization of the dma_data in i2s_hw_params. If you are in the process of debugging some bug as you mentioned earlier you can ignore this comment. Otherwise it is just a reminder.

Hrm, forgot to commit that bit.

#8 lore raw

Hi Mark,

Quoted 11 lines · Mark Brown
Quoted 3 lines · Padma Venkat

This is done in your earlier patch " ASoC: samsung: Ensure DMA data is initialised for secondary DAI ". Was it done on purpose or by mistake in this patch?

It's intentional - notice that the function has changed, this is why I kept asking you about mainline. Mainline doesn't have the wrapper function that abstracts the difference between s3c-dma and dmaengine, this is why I'm saying these two will need to be rebased on top of the mainline fix.

Ok. I didn't notice the function name. Then this commit is not required in the mainline.
This is required only after your changes because in dmaengine we are requesting the dma channel statically but in mainline(with samsung proprietary ops) we are requesting the dma channel at run time during playback or capture.

Quoted 7 lines
Quoted 5 lines

I think you also told to include a patch for reinitialization of the dma_data in i2s_hw_params. If you are in the process of debugging some bug as you mentioned earlier you can ignore this comment. Otherwise it is just a reminder.

Hrm, forgot to commit that bit.

Thanks
Padma

#9 lore raw

Hi Mark,

Quoted 15 lines · Padma Venkat

Hi Mark,

Quoted 11 lines · Mark Brown
Quoted 3 lines · Padma Venkat

This is done in your earlier patch " ASoC: samsung: Ensure DMA data is initialised for secondary DAI ". Was it done on purpose or by mistake in this patch?

It's intentional - notice that the function has changed, this is why I kept asking you about mainline. Mainline doesn't have the wrapper function that abstracts the difference between s3c-dma and dmaengine, this is why I'm saying these two will need to be rebased on top of the mainline fix.

Quoted 6 lines

Ok. I didn't notice the function name. Then this commit is not required in the mainline.
This is required only after your changes because in dmaengine we are requesting the dma channel statically but in mainline(with samsung proprietary ops) we are requesting the dma channel at run time during playback or capture.

sorry for the mix-up. I think we need to set the dma data for the secondary dai even in mainline.

Quoted 11 lines
Quoted 8 lines
Quoted 6 lines

I think you also told to include a patch for reinitialization of the dma_data in i2s_hw_params. If you are in the process of debugging some bug as you mentioned earlier you can ignore this comment. Otherwise it is just a reminder.

Hrm, forgot to commit that bit.

Thanks
Padma

author maintainer
#10 lore raw
In reply to Padma Venkat
Quoted 4 lines · Padma Venkat

This is required only after your changes because in dmaengine we are requesting the dma channel statically but in mainline(with samsung proprietary ops) we are requesting the dma channel at run time during playback or capture.

OK, so it does get set somewhere but not here?