update supported sample format
Subsystems (4)
v4 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
changes in v4
- update according to Nicolin's comments.
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 | 59 ++++++++++++++++--- sound/soc/soc-generic-dmaengine-pcm.c | 61 ++------------------ 6 files changed, 193 insertions(+), 87 deletions(-)
Signature · 1 line
2.21.0
PATCH v4 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
@@ -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
@@ -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
PATCH v4 2/4 ASoC: fsl_asrc: update supported sample format
In reply to Shengjiu WangThe 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
@@ -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
PATCH v4 3/4 ASoC: pcm_dmaengine: Extract snd_dmaengine_pcm_refine_runtime_hwparams
In reply to Shengjiu WangWhen 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 | 61 ++------------------ 3 files changed, 94 insertions(+), 55 deletions(-)
include/sound/dmaengine_pcm.h +5 -0
@@ -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 +6 -55
74 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH V4 3/4] ASoC: pcm_dmaengine: Extract snd_dmaengine_pcm_refine_runtime_hwparams
Quoted 9 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_hwparamsfunction to a separate functionsnd_dmaengine_pcm_refine_runtime_hwparams, that other components which need this feature can call this function.Signed-off-by Shengjiu Wang <[email protected]>
Looks good to me.
PATCH v4 4/4 ASoC: fsl_asrc: Fix error with S24_3LE format bitstream in i.MX8
In reply to Shengjiu WangThere 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 | 59 +++++++++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 10 deletions(-)
sound/soc/fsl/fsl_asrc.c +2 -2
@@ -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
@@ -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 +51 -8
87 lines not on this page · raw message
Signature · 1 line
2.21.0
Nicolin Chen
reviewerRe: [PATCH V4 4/4] ASoC: fsl_asrc: Fix error with S24_3LE format bitstream in i.MX8
Quoted 23 lines · Shengjiu Wang
There is error "aplay: pcm_write:2023: write error: Input/output error" on i.MX8QM/i.MX8QXP platform for
S24_3LEformat.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.
Signed-off-by Shengjiu Wang <[email protected]>--- sound/soc/fsl/fsl_asrc.c | 4 +-- sound/soc/fsl/fsl_asrc.h | 3 ++ sound/soc/fsl/fsl_asrc_dma.c | 59 +++++++++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 10 deletions(-)sound/soc/fsl/fsl_asrc_dma.c +1
-0@@ -270,12 +268,17 @@ static int fsl_asrc_dma_hw_free(struct snd_pcm_substream *substream)static int fsl_asrc_dma_startup (struct snd_pcm_substream *substream) { +bool tx = substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ;struct snd_soc_pcm_runtime *rtd = substream->private_data;struct snd_pcm_runtime *runtime = substream->runtime;
sound/soc/fsl/fsl_asrc_dma.c static int fsl_asrc_dma_hw_free(struct snd_pcm_substream *substream) · line 283
Quoted 10 lines
sound/soc/fsl/fsl_asrc_dma.c +4
-0struct snd_soc_component *component =snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_dmaengine_dai_dma_data *dma_data;struct device *dev = component->dev;struct fsl_asrc *asrc_priv =dev_get_drvdata (dev);struct fsl_asrc_pair *pair; +struct dma_chan *tmp_chan =NULL ; +u8 dir = tx ?OUT :IN ; +int ret =0 ; pair =kzalloc (sizeof (struct fsl_asrc_pair ),GFP_KERNEL );
Sorry, I didn't catch it previously. We would need to release this memory also for all error-out paths, as the code doesn't have any error-out routine, prior to applying this change.
sound/soc/fsl/fsl_asrc_dma.c static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream) · line 292
Quoted 7 lines
sound/soc/fsl/fsl_asrc_dma.c +4
-0if (!pair)@@ -285,11 +288,51 @@ static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream) +/* Request a dummy pair, which will be released later. +* Request pair function needs channel num as input, for this +* dummy pair, we just request "1" channel temporary. +*/
"temporary" => "temporarily"
sound/soc/fsl/fsl_asrc_dma.c static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream) · line 308
Quoted 7 lines
sound/soc/fsl/fsl_asrc_dma.c +7
-0+ ret =fsl_asrc_request_pair (1 , pair); +if (ret <0 ) { +dev_err (dev,"failed to request asrc pair\n" ); +return ret; + } + +/* Request a dummy dma channel, which will be release later. */
"release" => "released"