ASoC: atmel: mchp-spdifrx: Fix format handling and MR configuration
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
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.
---
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
@@ -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
[email protected]
AI reviewRe: [RFC PATCH 1/2] ASoC: atmel: mchp-spdifrx: Fix 16-bit big-endian format check
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@@ -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
Re: [RFC PATCH 1/2] ASoC: atmel: mchp-spdifrx: Fix 16-bit big-endian format check
Quoted 5 lines
[Severity: Medium]
ShouldMCHP_SPDIF_FORMATSbe changed fromSNDRV_PCM_FMTBIT_U16_BEtoSNDRV_PCM_FMTBIT_S16_BEinstead?
Quoted 9 lines
IEC-60958 linear PCM samples are signed two's-complement values, and
SPDIFRX_MR_ENDIAN_BIGonly switches the byte order inSPDIFRX_MRwithout converting signed samples to unsigned. All other format pairs inMCHP_SPDIF_FORMATSare signed, and the companion linux,spdif-dir codec (sound/soc/codecs/spdif_receiver.c) used with this controller only supportsS16_LEandS16_BE, so advertisingU16_BEprevents 16-bit big-endian capture from being negotiated (or delivers signed samples into an unsigned stream if paired with a codec that permitsU16_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.
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.
---
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
@@ -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