Skip to contentSkip to conversation

ASoC: atmel: mchp-spdifrx: Fix format handling and MR configuration

RFC PATCH In review [email protected] 2 participants 5 messages Nov 20

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ASoC: atmel: mchp-spdifrx: Fix format handling and MR configuration

From: bui duc phuc <[email protected]>

Hi all,

This series addresses two issues in the mchp-spdifrx driver: inconsistent handling of the 16-bit big-endian format and MR register updates in hw_params().

This series was developed on top of the previous series:
https://lore.kernel.org/all/[email protected]/

Since this is an RFC series, I have kept it separate rather than including these changes in the previous series. The previous series should be applied first to avoid conflicts when applying these patches.

The changes are not hardware-tested, and I would appreciate feedback from someone with access to the hardware.

In particular, the MR register change needs verification. If the current code works as expected, the existing full-register write in hw_params() may be intentional, and the actual issue could instead be the default configuration in dai_probe().

For the 16-bit big-endian format, the current format check is clearly inconsistent with MCHP_SPDIF_FORMATS. However, it is also possible that the advertised format should be corrected instead of changing the check in hw_params(). Furthermore, I could not find datasheet documentation confirming support for big-endian 16-bit and 20-bit formats.

Therefore, hardware testing is needed to determine whether these changes are correct.

Compile-tested only.

Best regards,
Phuc

bui duc phuc (2):
ASoC: atmel: mchp-spdifrx: Fix 16-bit big-endian format check
ASoC: atmel: mchp-spdifrx: Preserve MR defaults in hw_params

 sound/soc/atmel/mchp-spdifrx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/2 ASoC: atmel: mchp-spdifrx: Fix 16-bit big-endian format check

From: bui duc phuc <[email protected]>

MCHP_SPDIF_FORMATS advertises SNDRV_PCM_FMTBIT_U16_BE as a supported format, but mchp_spdifrx_hw_params() checks for SNDRV_PCM_FORMAT_S16_BE instead.

Replace SNDRV_PCM_FORMAT_S16_BE with SNDRV_PCM_FORMAT_U16_BE to make the format check consistent with the advertised supported formats.

Fixes ef265c55c1ac ("ASoC: mchp-spdifrx: add driver for SPDIF RX")

---

Note:
The SAMA7G5 datasheet does not explicitly document support for 16-bit and 20-bit big-endian samples. This change only makes the format check consistent with MCHP_SPDIF_FORMATS. Hardware testing on SAMA7G5 is needed to confirm whether these formats are actually supported.

 sound/soc/atmel/mchp-spdifrx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/atmel/mchp-spdifrx.c +1 -1
index 632da8d7bc81..06a2a5a90a63 100644
@@ -455,7 +455,7 @@ static int mchp_spdifrx_hw_params(struct snd_pcm_substream *substream,
 	}
 
 	switch (params_format(params)) {
-	case SNDRV_PCM_FORMAT_S16_BE:
+	case SNDRV_PCM_FORMAT_U16_BE:
 	case SNDRV_PCM_FORMAT_S20_3BE:
 	case SNDRV_PCM_FORMAT_S24_3BE:
 	case SNDRV_PCM_FORMAT_S24_BE:
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH 2/2 ASoC: atmel: mchp-spdifrx: Preserve MR defaults in hw_params

In reply to [email protected]

From: bui duc phuc <[email protected]>

hw_params() overwrites the entire MR register, clearing the VBMODE and SBMODE bits configured in dai_probe().

Use regmap_update_bits() to update only the ENDIAN and DATAWIDTH fields, preserving the other MR bits.

Fixes fa09fa60385a ("ASoC: mchp-spdifrx: fix controls which rely on rsr register")

---

Note:
Hardware testing on SAMA7G5 is needed to verify this change. If the current full-register write is intentional, the issue may instead be in the default MR configuration in dai_probe().

 sound/soc/atmel/mchp-spdifrx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/atmel/mchp-spdifrx.c +3 -1
index 06a2a5a90a63..e37470165717 100644
@@ -502,7 +502,9 @@ static int mchp_spdifrx_hw_params(struct snd_pcm_substream *substream,
 	dev_dbg(dev->dev, "GCLK range min set to %d\n",
 		params_rate(params) * SPDIFRX_GCLK_RATIO_MIN + 1);
 
-	ret = regmap_write(dev->regmap, SPDIFRX_MR, mr);
+	ret = regmap_update_bits(dev->regmap, SPDIFRX_MR,
+				 SPDIFRX_MR_ENDIAN_MASK | SPDIFRX_MR_DATAWIDTH_MASK,
+				 mr);
 
 unlock:
 	mutex_unlock(&dev->mlock);
Signature · 1 line
2.43.0
#2 lore raw

Re: [RFC PATCH 1/2] ASoC: atmel: mchp-spdifrx: Fix 16-bit big-endian format check

In reply to [email protected]
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] ASoC: atmel: mchp-spdifrx: wrong 16-bit BE format in mchp_spdifrx_hw_params() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] ASoC: atmel: mchp-spdifrx: wrong 16-bit BE format in mchp_spdifrx_hw_params()
--

commit 35438546e4acb88091a245628184b5c5fc916afd
Author: bui duc phuc <[email protected]>

ASoC: atmel: mchp-spdifrx: Fix 16-bit big-endian format check

This commit replaces SNDRV_PCM_FORMAT_S16_BE with SNDRV_PCM_FORMAT_U16_BE in mchp_spdifrx_hw_params() to match MCHP_SPDIF_FORMATS.

sound/soc/atmel/mchp-spdifrx.c static int mchp_spdifrx_hw_params(struct snd_pcm_substream *substream, · line 461

Quoted 13 lines
sound/soc/atmel/mchp-spdifrx.c +1 -1
index 63089ac3ebdc9..80a64af0878b5 100644
@@ -455,7 +455,7 @@ static int mchp_spdifrx_hw_params(struct snd_pcm_substream *substream,
 	}
 
 	switch (params_format(params)) {
-	case SNDRV_PCM_FORMAT_S16_BE:
+	case SNDRV_PCM_FORMAT_U16_BE:
 	case SNDRV_PCM_FORMAT_S20_3BE:
 	case SNDRV_PCM_FORMAT_S24_3BE:
 	case SNDRV_PCM_FORMAT_S24_BE:

[Severity: Medium]
Should MCHP_SPDIF_FORMATS be changed from SNDRV_PCM_FMTBIT_U16_BE to SNDRV_PCM_FMTBIT_S16_BE instead?

IEC-60958 linear PCM samples are signed two's-complement values, and SPDIFRX_MR_ENDIAN_BIG only switches the byte order in SPDIFRX_MR without converting signed samples to unsigned. All other format pairs in MCHP_SPDIF_FORMATS are signed, and the companion linux,spdif-dir codec (sound/soc/codecs/spdif_receiver.c) used with this controller only supports S16_LE and S16_BE, so advertising U16_BE prevents 16-bit big-endian capture from being negotiated (or delivers signed samples into an unsigned stream if paired with a codec that permits U16_BE).

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [RFC PATCH 1/2] ASoC: atmel: mchp-spdifrx: Fix 16-bit big-endian format check

Quoted 5 lines

[Severity: Medium]
Should MCHP_SPDIF_FORMATS be changed from SNDRV_PCM_FMTBIT_U16_BE to SNDRV_PCM_FMTBIT_S16_BE instead?

Quoted 9 lines

IEC-60958 linear PCM samples are signed two's-complement values, and SPDIFRX_MR_ENDIAN_BIG only switches the byte order in SPDIFRX_MR without converting signed samples to unsigned. All other format pairs in MCHP_SPDIF_FORMATS are signed, and the companion linux,spdif-dir codec (sound/soc/codecs/spdif_receiver.c) used with this controller only supports S16_LE and S16_BE, so advertising U16_BE prevents 16-bit big-endian capture from being negotiated (or delivers signed samples into an unsigned stream if paired with a codec that permits U16_BE).

The SAMA7G5 datasheet does not explicitly document support for 16-bit big-endian samples in the SPDIFRX block.
I think hardware testing is needed to confirm this before changing MCHP_SPDIF_FORMATS.