Skip to contentSkip to conversation

update supported sample format

PATCH Superseded Shengjiu Wang 2 participants 8 messages Sep 19, 2019 – Sep 20, 2019

Subsystems (4)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover update supported sample format

This patch serial is to update the supported format for fsl_asrc and fix some format issue.

Shengjiu Wang (4):
ASoC: fsl_asrc: Use in(out)put_format instead of in(out)put_word_width
ASoC: fsl_asrc: update supported sample format
ASoC: pcm_dmaengine: Extract snd_dmaengine_pcm_refine_runtime_hwparams
ASoC: fsl_asrc: Fix error with S24_3LE format bitstream in i.MX8

changes in v2
- extract snd_dmaengine_pcm_set_runtime_hwparams in one separate path.
- 4th patch depends on 3rd patch

changes in v3
- Fix build report by kbuild test robot <[email protected]>
- change snd_dmaengine_pcm_set_runtime_hwparams to snd_dmaengine_pcm_refine_runtime_hwparams

 include/sound/dmaengine_pcm.h         |  5 ++
 sound/core/pcm_dmaengine.c            | 83 +++++++++++++++++++++++++++
 sound/soc/fsl/fsl_asrc.c              | 65 ++++++++++++++-------
 sound/soc/fsl/fsl_asrc.h              |  7 ++-
 sound/soc/fsl/fsl_asrc_dma.c          | 52 ++++++++++++++---
 sound/soc/soc-generic-dmaengine-pcm.c | 62 +++-----------------
 6 files changed, 188 insertions(+), 86 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH v3 1/4 ASoC: fsl_asrc: Use in(out)put_format instead of in(out)put_word_width

snd_pcm_format_t is more formal than enum asrc_word_width, which has two property, width and physical width, which is more accurate than enum asrc_word_width. So it is better to use in(out)put_format instead of in(out)put_word_width.

---
 sound/soc/fsl/fsl_asrc.c | 56 +++++++++++++++++++++++++++-------------
 sound/soc/fsl/fsl_asrc.h |  4 +--
 2 files changed, 40 insertions(+), 20 deletions(-)
sound/soc/fsl/fsl_asrc.c +38 -18
index cfa40ef6b1ca..4d3804a1ea55 100644
@@ -265,6 +265,8 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair)
 	struct asrc_config *config = pair->config;
 	struct fsl_asrc *asrc_priv = pair->asrc_priv;
 	enum asrc_pair_index index = pair->index;
+	enum asrc_word_width input_word_width;
+	enum asrc_word_width output_word_width;
 	u32 inrate, outrate, indiv, outdiv;
 	u32 clk_index[2], div[2];
 	int in, out, channels;
@@ -283,9 +285,32 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair)
 		return -EINVAL;
 	}
 
-	/* Validate output width */
-	if (config->output_word_width == ASRC_WIDTH_8_BIT) {
-		pair_err("does not support 8bit width output\n");
+	switch (snd_pcm_format_width(config->input_format)) {
+	case 8:
+		input_word_width = ASRC_WIDTH_8_BIT;
+		break;
+	case 16:
+		input_word_width = ASRC_WIDTH_16_BIT;
+		break;
+	case 24:
+		input_word_width = ASRC_WIDTH_24_BIT;
+		break;
+	default:
+		pair_err("does not support this input format, %d\n",
+			 config->input_format);
+		return -EINVAL;
+	}
+
+	switch (snd_pcm_format_width(config->output_format)) {
+	case 16:
+		output_word_width = ASRC_WIDTH_16_BIT;
+		break;
+	case 24:
+		output_word_width = ASRC_WIDTH_24_BIT;
+		break;
+	default:
+		pair_err("does not support this output format, %d\n",
+			 config->output_format);
 		return -EINVAL;
 	}
 
@@ -383,8 +408,8 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair)
 	/* Implement word_width configurations */
 	regmap_update_bits(asrc_priv->regmap, REG_ASRMCR1(index),
 			   ASRMCR1i_OW16_MASK | ASRMCR1i_IWD_MASK,
-			   ASRMCR1i_OW16(config->output_word_width) |
-			   ASRMCR1i_IWD(config->input_word_width));
+			   ASRMCR1i_OW16(output_word_width) |
+			   ASRMCR1i_IWD(input_word_width));
 
 	/* Enable BUFFER STALL */
 	regmap_update_bits(asrc_priv->regmap, REG_ASRMCR(index),
@@ -497,13 +522,13 @@ static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream,
 				  struct snd_soc_dai *dai)
 {
 	struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai);
-	int width = params_width(params);
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct fsl_asrc_pair *pair = runtime->private_data;
 	unsigned int channels = params_channels(params);
 	unsigned int rate = params_rate(params);
 	struct asrc_config config;
-	int word_width, ret;
+	snd_pcm_format_t format;
+	int ret;
 
 	ret = fsl_asrc_request_pair(channels, pair);
 	if (ret) {
@@ -513,15 +538,10 @@ static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream,
 
 	pair->config = &config;
 
-	if (width == 16)
-		width = ASRC_WIDTH_16_BIT;
-	else
-		width = ASRC_WIDTH_24_BIT;
-
 	if (asrc_priv->asrc_width == 16)
-		word_width = ASRC_WIDTH_16_BIT;
+		format = SNDRV_PCM_FORMAT_S16_LE;
 	else
-		word_width = ASRC_WIDTH_24_BIT;
+		format = SNDRV_PCM_FORMAT_S24_LE;
 
 	config.pair = pair->index;
 	config.channel_num = channels;
@@ -529,13 +549,13 @@ static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream,
 	config.outclk = OUTCLK_ASRCK1_CLK;
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-		config.input_word_width   = width;
-		config.output_word_width  = word_width;
+		config.input_format   = params_format(params);
+		config.output_format  = format;
 		config.input_sample_rate  = rate;
 		config.output_sample_rate = asrc_priv->asrc_rate;
 	} else {
-		config.input_word_width   = word_width;
-		config.output_word_width  = width;
+		config.input_format   = format;
+		config.output_format  = params_format(params);
 		config.input_sample_rate  = asrc_priv->asrc_rate;
 		config.output_sample_rate = rate;
 	}
sound/soc/fsl/fsl_asrc.h +2 -2
index c60075112570..38af485bdd22 100644
@@ -342,8 +342,8 @@ struct asrc_config {
 	unsigned int dma_buffer_size;
 	unsigned int input_sample_rate;
 	unsigned int output_sample_rate;
-	enum asrc_word_width input_word_width;
-	enum asrc_word_width output_word_width;
+	snd_pcm_format_t input_format;
+	snd_pcm_format_t output_format;
 	enum asrc_inclk inclk;
 	enum asrc_outclk outclk;
 };
Signature · 1 line
2.21.0
#2 lore raw

PATCH v3 2/4 ASoC: fsl_asrc: update supported sample format

In reply to Shengjiu Wang

The ASRC support 24bit/16bit/8bit input width, which is data width, not slot width.

For the S20_3LE format, the data with is 20bit, slot width is 24bit, if we set ASRMCR1n.IWD to be 24bits, the result is the volume is lower than expected, it likes 24bit data right shift 4 bits

So replace S20_3LE with S24_3LE in supported list and add S8 format in TX supported list

---
 sound/soc/fsl/fsl_asrc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/fsl/fsl_asrc.c +3 -2
index 4d3804a1ea55..584badf956d2 100644
@@ -624,7 +624,7 @@ static int fsl_asrc_dai_probe(struct snd_soc_dai *dai)
 
 #define FSL_ASRC_FORMATS	(SNDRV_PCM_FMTBIT_S24_LE | \
 				 SNDRV_PCM_FMTBIT_S16_LE | \
-				 SNDRV_PCM_FMTBIT_S20_3LE)
+				 SNDRV_PCM_FMTBIT_S24_3LE)
 
 static struct snd_soc_dai_driver fsl_asrc_dai = {
 	.probe = fsl_asrc_dai_probe,
@@ -635,7 +635,8 @@ static struct snd_soc_dai_driver fsl_asrc_dai = {
 		.rate_min = 5512,
 		.rate_max = 192000,
 		.rates = SNDRV_PCM_RATE_KNOT,
-		.formats = FSL_ASRC_FORMATS,
+		.formats = FSL_ASRC_FORMATS |
+			   SNDRV_PCM_FMTBIT_S8,
 	},
 	.capture = {
 		.stream_name = "ASRC-Capture",
Signature · 1 line
2.21.0
reviewer Acked-by on v3 2/4
#3 lore raw

Re: [PATCH V3 2/4] ASoC: fsl_asrc: update supported sample format

Quoted 8 lines · Shengjiu Wang

The ASRC support 24bit/16bit/8bit input width, which is data width, not slot width.

For the S20_3LE format, the data with is 20bit, slot width is 24bit, if we set ASRMCR1n.IWD to be 24bits, the result is the volume is lower than expected, it likes 24bit data right shift 4 bits

Quoted 4 lines

So replace S20_3LE with S24_3LE in supported list and add S8 format in TX supported list

Quoted 30 lines
---
 sound/soc/fsl/fsl_asrc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/fsl/fsl_asrc.c +3 -2
index 4d3804a1ea55..584badf956d2 100644
@@ -624,7 +624,7 @@ static int fsl_asrc_dai_probe(struct snd_soc_dai *dai)
 
 #define FSL_ASRC_FORMATS	(SNDRV_PCM_FMTBIT_S24_LE | \
 				 SNDRV_PCM_FMTBIT_S16_LE | \
-				 SNDRV_PCM_FMTBIT_S20_3LE)
+				 SNDRV_PCM_FMTBIT_S24_3LE)
 
 static struct snd_soc_dai_driver fsl_asrc_dai = {
 	.probe = fsl_asrc_dai_probe,
@@ -635,7 +635,8 @@ static struct snd_soc_dai_driver fsl_asrc_dai = {
 		.rate_min = 5512,
 		.rate_max = 192000,
 		.rates = SNDRV_PCM_RATE_KNOT,
-		.formats = FSL_ASRC_FORMATS,
+		.formats = FSL_ASRC_FORMATS |
+			   SNDRV_PCM_FMTBIT_S8,
 	},
 	.capture = {
 		.stream_name = "ASRC-Capture",
Signature · 1 line
2.21.0
#4 lore raw

PATCH v3 3/4 ASoC: pcm_dmaengine: Extract snd_dmaengine_pcm_refine_runtime_hwparams

In reply to Shengjiu Wang

When set the runtime hardware parameters, we may need to query the capability of DMA to complete the parameters.

This patch is to Extract this operation from dmaengine_pcm_set_runtime_hwparams function to a separate function snd_dmaengine_pcm_refine_runtime_hwparams, that other components which need this feature can call this function.

---
 include/sound/dmaengine_pcm.h         |  5 ++
 sound/core/pcm_dmaengine.c            | 83 +++++++++++++++++++++++++++
 sound/soc/soc-generic-dmaengine-pcm.c | 62 +++-----------------
 3 files changed, 95 insertions(+), 55 deletions(-)
include/sound/dmaengine_pcm.h +5 -0
index c679f6116580..b65220685920 100644
@@ -83,6 +83,11 @@ void snd_dmaengine_pcm_set_config_from_dai_data(
 	const struct snd_dmaengine_dai_dma_data *dma_data,
 	struct dma_slave_config *config);
 
+int snd_dmaengine_pcm_refine_runtime_hwparams(
+	struct snd_pcm_substream *substream,
+	struct snd_dmaengine_dai_dma_data *dma_data,
+	struct snd_pcm_hardware *hw,
+	struct dma_chan *chan);
 
 /*
  * Try to request the DMA channel using compat_request_channel or
sound/core/pcm_dmaengine.c +83 -0

87 lines not on this page · raw message

sound/soc/soc-generic-dmaengine-pcm.c +7 -55

77 lines not on this page · raw message

Signature · 1 line
2.21.0
reviewer
#5 lore raw

Re: [PATCH V3 3/4] ASoC: pcm_dmaengine: Extract snd_dmaengine_pcm_refine_runtime_hwparams

Quoted 12 lines · Shengjiu Wang

When set the runtime hardware parameters, we may need to query the capability of DMA to complete the parameters.

This patch is to Extract this operation from dmaengine_pcm_set_runtime_hwparams function to a separate function snd_dmaengine_pcm_refine_runtime_hwparams, that other components which need this feature can call this function.

sound/soc/soc-generic-dmaengine-pcm.c +0 -0
@@ -145,58 +140,15 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea
 

sound/soc/soc-generic-dmaengine-pcm.c static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea · line 150

Quoted 10 lines
sound/soc/soc-generic-dmaengine-pcm.c +7 -0
+	ret = snd_dmaengine_pcm_refine_runtime_hwparams(substream,
+							dma_data,
+							&hw,
+							chan);
+	if (ret)
+		return ret;
 
 	return snd_soc_set_runtime_hwparams(substream, &hw);
+
 }

Just a nit, why add a line here? :)

The rest looks good to me, not sure whether the name "refine" would be the best one though, would like to wait for opinions from others.

Thanks

#6 lore raw

PATCH v3 4/4 ASoC: fsl_asrc: Fix error with S24_3LE format bitstream in i.MX8

In reply to Shengjiu Wang

There is error "aplay: pcm_write:2023: write error: Input/output error" on i.MX8QM/i.MX8QXP platform for S24_3LE format.

In i.MX8QM/i.MX8QXP, the DMA is EDMA, which don't support 24bit sample, but we didn't add any constraint, that cause issues.

So we need to query the caps of dma, then update the hw parameters according to the caps.

---
 sound/soc/fsl/fsl_asrc.c     |  4 +--
 sound/soc/fsl/fsl_asrc.h     |  3 +++
 sound/soc/fsl/fsl_asrc_dma.c | 52 +++++++++++++++++++++++++++++++-----
 3 files changed, 50 insertions(+), 9 deletions(-)
sound/soc/fsl/fsl_asrc.c +2 -2
index 584badf956d2..0bf91a6f54b9 100644
@@ -115,7 +115,7 @@ static void fsl_asrc_sel_proc(int inrate, int outrate,
  * within range [ANCA, ANCA+ANCB-1], depends on the channels of pair A
  * while pair A and pair C are comparatively independent.
  */
-static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair)
+int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair)
 {
 	enum asrc_pair_index index = ASRC_INVALID_PAIR;
 	struct fsl_asrc *asrc_priv = pair->asrc_priv;
@@ -158,7 +158,7 @@ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair)
  *
  * It clears the resource from asrc_priv and releases the occupied channels.
  */
-static void fsl_asrc_release_pair(struct fsl_asrc_pair *pair)
+void fsl_asrc_release_pair(struct fsl_asrc_pair *pair)
 {
 	struct fsl_asrc *asrc_priv = pair->asrc_priv;
 	enum asrc_pair_index index = pair->index;
sound/soc/fsl/fsl_asrc.h +3 -0
index 38af485bdd22..2b57e8c53728 100644
@@ -462,4 +462,7 @@ struct fsl_asrc {
 #define DRV_NAME "fsl-asrc-dai"
 extern struct snd_soc_component_driver fsl_asrc_component;
 struct dma_chan *fsl_asrc_get_dma_channel(struct fsl_asrc_pair *pair, bool dir);
+int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair);
+void fsl_asrc_release_pair(struct fsl_asrc_pair *pair);
+
 #endif /* _FSL_ASRC_H */
sound/soc/fsl/fsl_asrc_dma.c +45 -7

73 lines not on this page · raw message

Signature · 1 line
2.21.0
reviewer
#7 lore raw

Re: [PATCH V3 4/4] ASoC: fsl_asrc: Fix error with S24_3LE format bitstream in i.MX8

Hello Shengjiu,

One issue for error-out and some nit-pickings inline. Thanks.

Quoted 17 lines · Shengjiu Wang

There is error "aplay: pcm_write:2023: write error: Input/output error" on i.MX8QM/i.MX8QXP platform for S24_3LE format.

In i.MX8QM/i.MX8QXP, the DMA is EDMA, which don't support 24bit sample, but we didn't add any constraint, that cause issues.

So we need to query the caps of dma, then update the hw parameters according to the caps.

---
 sound/soc/fsl/fsl_asrc.c     |  4 +--
 sound/soc/fsl/fsl_asrc.h     |  3 +++
 sound/soc/fsl/fsl_asrc_dma.c | 52 +++++++++++++++++++++++++++++++-----
 3 files changed, 50 insertions(+), 9 deletions(-)

sound/soc/fsl/fsl_asrc_dma.c static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream) · line 280

Quoted 7 lines
sound/soc/fsl/fsl_asrc_dma.c +4 -0
@@ -276,6 +274,11 @@ static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream)
 	struct device *dev = component->dev;
 	struct fsl_asrc *asrc_priv = dev_get_drvdata(dev);
 	struct fsl_asrc_pair *pair;
+	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
+	u8 dir = tx ? OUT : IN;
+	struct dma_chan *tmp_chan;
+	struct snd_dmaengine_dai_dma_data *dma_data;

Nit: would it be possible to reorganize these a bit? Usually we put struct things together unless there is a dependency, similar to fsl_asrc_dma_hw_params().

sound/soc/fsl/fsl_asrc_dma.c static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream) · line 291

Quoted 5 lines
sound/soc/fsl/fsl_asrc_dma.c +1 -0
@@ -285,9 +288,44 @@ static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream)
 
 	runtime->private_data = pair;
 
+	/* Request a temp pair, which is release in the end */

Nit: "which will be released later" or "and will release it later"? And could we use a work like "dummy"? Or at least I would love to see the comments explaining the parameter "1" in the function call below.

sound/soc/fsl/fsl_asrc_dma.c static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream) · line 307

Quoted 9 lines
sound/soc/fsl/fsl_asrc_dma.c +9 -0
+	ret = fsl_asrc_request_pair(1, pair);
+	if (ret < 0) {
+		dev_err(dev, "failed to request asrc pair\n");
+		return ret;
+	}
+
+	tmp_chan = fsl_asrc_get_dma_channel(pair, dir);
+	if (!tmp_chan) {
+		dev_err(dev, "can't get dma channel\n");

Could we align with other error messages using "failed to"?

Quoted 4 lines
sound/soc/fsl/fsl_asrc_dma.c +4 -0
+	ret = snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
+	if (ret)
+		return ret;
+

[...]

sound/soc/fsl/fsl_asrc_dma.c static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream) · line 327

Quoted 2 lines
sound/soc/fsl/fsl_asrc_dma.c +2 -0
+	dma_release_channel(tmp_chan);
+	fsl_asrc_release_pair(pair);

I think we need an "out:" here for those error-out routines to goto. Otherwise, it'd be a pair leak?

Quoted 1 line

+

Could we drop this? There is a blank line below already :)

Quoted 6 lines

return 0;
}

Signature · 1 line
2.21.0