ASoC: fsl_sai: Enable data lines based on input channels
Subsystems (3)
RFC PATCH 1/1 ASoC: fsl_sai: Enable data lines based on input channels
An audio data frame consists of a number of slots one for each channel. In the case of I2S there are 2 data slots / frame.
The maximum number of SAI slots / frame is configurable at IP integration time. This affects the width of Mask Register. SAI supports up to 32 slots per frame.
The number of datalines is also configurable (up to 8 datalines) and affects TCE/RCE and the number of data/FIFO registers.
The number of needed data lines (pins) is computed as follows:
* pins = channels / slots.
This can be computed in hw_params function so lets move TRCE bits seting from startup to hw_params.
--- sound/soc/fsl/fsl_sai.c | 34 +++++++++++++--------------------- sound/soc/fsl/fsl_sai.h | 2 +- 2 files changed, 14 insertions(+), 22 deletions(-)
sound/soc/fsl/fsl_sai.c +13 -21
@@ -414,6 +414,7 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,u32 val_cr4 =0 , val_cr5 =0 ;u32 slots = (channels ==1 ) ?2 : channels;u32 slot_width = word_width; +u32 pins;int ret;if (sai->slots)
@@ -422,6 +423,8 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,if (sai->slot_width) slot_width = sai->slot_width; + pins =DIV_ROUND_UP (channels, slots); +if (!sai->is_slave_mode[tx]) { ret =fsl_sai_set_bclk (cpu_dai, tx, slots * slot_width *params_rate (params));
@@ -480,13 +483,17 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream, } } +regmap_update_bits (sai->regmap,FSL_SAI_xCR3 (tx, ofs), +FSL_SAI_CR3_TRCE_MASK , +FSL_SAI_CR3_TRCE ((1 << pins) -1 )); +regmap_update_bits (sai->regmap,FSL_SAI_xCR4 (tx, ofs),FSL_SAI_CR4_SYWD_MASK |FSL_SAI_CR4_FRSZ_MASK , val_cr4);regmap_update_bits (sai->regmap,FSL_SAI_xCR5 (tx, ofs),FSL_SAI_CR5_WNW_MASK |FSL_SAI_CR5_W0W_MASK |FSL_SAI_CR5_FBT_MASK , val_cr5); -regmap_write (sai->regmap,FSL_SAI_xMR (tx), ~0UL - ((1 << channels) -1 )); +regmap_write (sai->regmap,FSL_SAI_xMR (tx), ~0UL - ((1 << slots) -1 ));return 0 ; }
@@ -496,6 +503,10 @@ static int fsl_sai_hw_free(struct snd_pcm_substream *substream, {struct fsl_sai *sai =snd_soc_dai_get_drvdata (cpu_dai);bool tx = substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ; +unsigned int ofs = sai->soc_data->reg_offset; + +regmap_update_bits (sai->regmap,FSL_SAI_xCR3 (tx, ofs), +FSL_SAI_CR3_TRCE_MASK ,0 );if (!sai->is_slave_mode[tx] && sai->mclk_streams &BIT (substream->stream)) {
@@ -603,32 +614,13 @@ static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,static int fsl_sai_startup (struct snd_pcm_substream *substream,struct snd_soc_dai *cpu_dai) { -struct fsl_sai *sai =snd_soc_dai_get_drvdata (cpu_dai); -unsigned int ofs = sai->soc_data->reg_offset; -bool tx = substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ;int ret; -regmap_update_bits (sai->regmap,FSL_SAI_xCR3 (tx, ofs), -FSL_SAI_CR3_TRCE_MASK , -FSL_SAI_CR3_TRCE ); - ret =snd_pcm_hw_constraint_list (substream->runtime,0 ,SNDRV_PCM_HW_PARAM_RATE , &fsl_sai_rate_constraints); -return ret; } -static void fsl_sai_shutdown (struct snd_pcm_substream *substream, -struct snd_soc_dai *cpu_dai) -{ -struct fsl_sai *sai =snd_soc_dai_get_drvdata (cpu_dai); -unsigned int ofs = sai->soc_data->reg_offset; -bool tx = substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ; - -regmap_update_bits (sai->regmap,FSL_SAI_xCR3 (tx, ofs), -FSL_SAI_CR3_TRCE_MASK ,0 ); -} -static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = { .set_sysclk = fsl_sai_set_dai_sysclk, .set_fmt = fsl_sai_set_dai_fmt,
@@ -637,7 +629,6 @@ static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = { .hw_free = fsl_sai_hw_free, .trigger = fsl_sai_trigger, .startup = fsl_sai_startup, - .shutdown = fsl_sai_shutdown, };static int fsl_sai_dai_probe (struct snd_soc_dai *cpu_dai)
@@ -881,6 +872,7 @@ static int fsl_sai_probe(struct platform_device *pdev)return -ENOMEM ; sai->pdev = pdev; + sai->soc_data =of_device_get_match_data (&pdev->dev); sai->is_lsb_first =of_property_read_bool (np,"lsb-first" );
sound/soc/fsl/fsl_sai.h +1 -1
@@ -109,7 +109,7 @@#define FSL_SAI_CR2_DIV_MASK 0xff/* SAI Transmit and Receive Configuration 3 Register */ -#define FSL_SAI_CR3_TRCE BIT(16) +#define FSL_SAI_CR3_TRCE (x) ((x) << 16)#define FSL_SAI_CR3_TRCE_MASK GENMASK(23, 16)#define FSL_SAI_CR3_WDFL (x) (x)#define FSL_SAI_CR3_WDFL_MASK 0x1f
Signature · 1 line
2.17.1
Nicolin Chen
reviewerQuoted 29 lines · Daniel Baluta
An audio data frame consists of a number of slots one for each channel. In the case of I2S there are 2 data slots / frame.
The maximum number of SAI slots / frame is configurable at IP integration time. This affects the width of Mask Register. SAI supports up to 32 slots per frame.
The number of datalines is also configurable (up to 8 datalines) and affects TCE/RCE and the number of data/FIFO registers.
The number of needed data lines (pins) is computed as follows:
* pins = channels / slots.
This can be computed in
hw_paramsfunction so lets move TRCE bits seting from startup tohw_params.Signed-off-by Daniel Baluta <[email protected]>--- sound/soc/fsl/fsl_sai.c | 34 +++++++++++++--------------------- sound/soc/fsl/fsl_sai.h | 2 +- 2 files changed, 14 insertions(+), 22 deletions(-)sound/soc/fsl/fsl_sai.c +0
-0
sound/soc/fsl/fsl_sai.c static int fsl_sai_hw_params(struct snd_pcm_substream *substream, · line 484
Quoted 3 lines
sound/soc/fsl/fsl_sai.c +1
-1@@ -480,13 +483,17 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream, -regmap_write (sai->regmap,FSL_SAI_xMR (tx), ~0UL - ((1 << channels) -1 )); +regmap_write (sai->regmap,FSL_SAI_xMR (tx), ~0UL - ((1 << slots) -1 ));
Would this break mono channel audio?
sound/soc/fsl/fsl_sai.c static int fsl_sai_probe(struct platform_device *pdev) · line 875
Quoted 7 lines
sound/soc/fsl/fsl_sai.c +1
-0static int fsl_sai_dai_probe (struct snd_soc_dai *cpu_dai)@@ -881,6 +872,7 @@ static int fsl_sai_probe(struct platform_device *pdev)return -ENOMEM ; sai->pdev = pdev; +
Seemly unnecessary
Quoted 30 lines · Nicolin Chen
Quoted 27 lines · Daniel Baluta
An audio data frame consists of a number of slots one for each channel. In the case of I2S there are 2 data slots / frame.
The maximum number of SAI slots / frame is configurable at IP integration time. This affects the width of Mask Register. SAI supports up to 32 slots per frame.
The number of datalines is also configurable (up to 8 datalines) and affects TCE/RCE and the number of data/FIFO registers.
The number of needed data lines (pins) is computed as follows:
* pins = channels / slots.
This can be computed in
hw_paramsfunction so lets move TRCE bits seting from startup tohw_params.Signed-off-by Daniel Baluta <[email protected]>--- sound/soc/fsl/fsl_sai.c | 34 +++++++++++++--------------------- sound/soc/fsl/fsl_sai.h | 2 +- 2 files changed, 14 insertions(+), 22 deletions(-)sound/soc/fsl/fsl_sai.c +0
-0
Quoted 6 lines
sound/soc/fsl/fsl_sai.c static int fsl_sai_hw_params(struct snd_pcm_substream *substream, · line 484
Quoted 4 lines
sound/soc/fsl/fsl_sai.c +1
-1@@ -480,13 +483,17 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream, -regmap_write (sai->regmap,FSL_SAI_xMR (tx), ~0UL - ((1 << channels) -1 )); +regmap_write (sai->regmap,FSL_SAI_xMR (tx), ~0UL - ((1 << slots) -1 ));Would this break mono channel audio?
Indeed, this isn't good for mono. I see in our internal tree that we have min(channels, slots).
This would fix mono, let me think if this is really the right solution.
Quoted 10 lines
sound/soc/fsl/fsl_sai.c static int fsl_sai_probe(struct platform_device *pdev) · line 875
Quoted 8 lines
sound/soc/fsl/fsl_sai.c +1
-0static int fsl_sai_dai_probe (struct snd_soc_dai *cpu_dai)@@ -881,6 +872,7 @@ static int fsl_sai_probe(struct platform_device *pdev)return -ENOMEM ; sai->pdev = pdev; +Seemly unnecessary
Oh, ok. Will fix in next version.