Skip to contentSkip to conversation

ASoC: sun4i-spdif: Add 24bit support

PATCH In review [email protected] 2 participants 5 messages Nov 11, 2024 – Dec 10, 2024

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

cover ASoC: sun4i-spdif: Add 24bit support

From: Marcus Cooper <[email protected]>

Hi All,
I've tested this patch series on the Allwinner H3, A64, H6 and H313 SoCs up to 192KHz.
24bit support is working on my H313 board but 16bit plays a bit slow and I suspect that there is an issue with the clock setups. This is even present without this patch stack. I would look to address this asap, but for now can you please review what's here.
BR,
CK

George Lander (1):
ASoC: sun4i-spdif: Add clock multiplier settings

Marcus Cooper (2):
ASoC: sun4i-spdif: Always set the valid data to be the MSB
ASoC: sun4i-spdif: Add working 24bit audio support

 sound/soc/sunxi/sun4i-spdif.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
Signature · 1 line
2.47.0
#1 lore raw

PATCH 1/3 ASoC: sun4i-spdif: Add clock multiplier settings

From: George Lander <[email protected]>

There have been intermittent issues with the SPDIF output on H3 and H2+ devices which has been fixed by setting the s_clk to 4 times the audio pll.
Add a quirk for the clock multiplier as not every supported SoC requires it. Without the multiplier, the audio at normal sampling rates was distorted and did not play at higher sampling rates.

Fixes 1bd92af877ab ("ASoC: sun4i-spdif: Add support for the H3 SoC")
---
 sound/soc/sunxi/sun4i-spdif.c | 7 +++++++
 1 file changed, 7 insertions(+)
sound/soc/sunxi/sun4i-spdif.c +7 -0
index 0aa4164232464..7cf623cbe9ed4 100644
@@ -176,6 +176,7 @@ struct sun4i_spdif_quirks {
 	unsigned int reg_dac_txdata;
 	bool has_reset;
 	unsigned int val_fctl_ftx;
+	unsigned int mclk_multiplier;
 };
 
 struct sun4i_spdif_dev {
@@ -313,6 +314,7 @@ static int sun4i_spdif_hw_params(struct snd_pcm_substream *substream,
 	default:
 		return -EINVAL;
 	}
+	mclk *= host->quirks->mclk_multiplier;
 
 	ret = clk_set_rate(host->spdif_clk, mclk);
 	if (ret < 0) {
@@ -347,6 +349,7 @@ static int sun4i_spdif_hw_params(struct snd_pcm_substream *substream,
 	default:
 		return -EINVAL;
 	}
+	mclk_div *= host->quirks->mclk_multiplier;
 
 	reg_val = 0;
 	reg_val |= SUN4I_SPDIF_TXCFG_ASS;
@@ -540,24 +543,28 @@ static struct snd_soc_dai_driver sun4i_spdif_dai = {
 static const struct sun4i_spdif_quirks sun4i_a10_spdif_quirks = {
 	.reg_dac_txdata	= SUN4I_SPDIF_TXFIFO,
 	.val_fctl_ftx   = SUN4I_SPDIF_FCTL_FTX,
+	.mclk_multiplier = 1,
 };
 
 static const struct sun4i_spdif_quirks sun6i_a31_spdif_quirks = {
 	.reg_dac_txdata	= SUN4I_SPDIF_TXFIFO,
 	.val_fctl_ftx   = SUN4I_SPDIF_FCTL_FTX,
 	.has_reset	= true,
+	.mclk_multiplier = 1,
 };
 
 static const struct sun4i_spdif_quirks sun8i_h3_spdif_quirks = {
 	.reg_dac_txdata	= SUN8I_SPDIF_TXFIFO,
 	.val_fctl_ftx   = SUN4I_SPDIF_FCTL_FTX,
 	.has_reset	= true,
+	.mclk_multiplier = 4,
 };
 
 static const struct sun4i_spdif_quirks sun50i_h6_spdif_quirks = {
 	.reg_dac_txdata = SUN8I_SPDIF_TXFIFO,
 	.val_fctl_ftx   = SUN50I_H6_SPDIF_FCTL_FTX,
 	.has_reset      = true,
+	.mclk_multiplier = 1,
 };
 
 static const struct of_device_id sun4i_spdif_of_match[] = {
Signature · 1 line
2.47.0
#2 lore raw

PATCH 2/3 ASoC: sun4i-spdif: Always set the valid data to be the MSB

In reply to [email protected]

From: Marcus Cooper <[email protected]>

This doesn't affect 16bit formats and allows us to properly run 24bit formats.

---
 sound/soc/sunxi/sun4i-spdif.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
sound/soc/sunxi/sun4i-spdif.c +4 -3
index 7cf623cbe9ed4..5a9407aaa1a19 100644
@@ -202,6 +202,10 @@ static void sun4i_spdif_configure(struct sun4i_spdif_dev *host)
 	regmap_update_bits(host->regmap, SUN4I_SPDIF_FCTL,
 			   quirks->val_fctl_ftx, quirks->val_fctl_ftx);
 
+	/* Valid data at the MSB of TXFIFO Register */
+	regmap_update_bits(host->regmap, SUN4I_SPDIF_FCTL,
+			   SUN4I_SPDIF_FCTL_TXIM, 0);
+
 	/* clear TX counter */
 	regmap_write(host->regmap, SUN4I_SPDIF_TXCNT, 0);
 }
@@ -323,9 +327,6 @@ static int sun4i_spdif_hw_params(struct snd_pcm_substream *substream,
 		return ret;
 	}
 
-	regmap_update_bits(host->regmap, SUN4I_SPDIF_FCTL,
-			   SUN4I_SPDIF_FCTL_TXIM, SUN4I_SPDIF_FCTL_TXIM);
-
 	switch (rate) {
 	case 22050:
 	case 24000:
Signature · 1 line
2.47.0
#3 lore raw

PATCH 3/3 ASoC: sun4i-spdif: Add working 24bit audio support

In reply to [email protected]

From: Marcus Cooper <[email protected]>

24 bit audio file can be detected by the alsa driver as S32_LE. Add this format to what is supported and change the DMA address width.

---
 sound/soc/sunxi/sun4i-spdif.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
sound/soc/sunxi/sun4i-spdif.c +7 -3
index 5a9407aaa1a19..41caf1795d09b 100644
@@ -287,14 +287,17 @@ static int sun4i_spdif_hw_params(struct snd_pcm_substream *substream,
 		return -EINVAL;
 	}
 
+	host->dma_params_tx.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
 	switch (params_format(params)) {
 	case SNDRV_PCM_FORMAT_S16_LE:
 		fmt |= SUN4I_SPDIF_TXCFG_FMT16BIT;
+		host->dma_params_tx.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
 		break;
 	case SNDRV_PCM_FORMAT_S20_3LE:
 		fmt |= SUN4I_SPDIF_TXCFG_FMT20BIT;
 		break;
 	case SNDRV_PCM_FORMAT_S24_LE:
+	case SNDRV_PCM_FORMAT_S32_LE:
 		fmt |= SUN4I_SPDIF_TXCFG_FMT24BIT;
 		break;
 	default:
@@ -526,9 +529,10 @@ static const struct regmap_config sun4i_spdif_regmap_config = {
 
 #define SUN4I_RATES	SNDRV_PCM_RATE_8000_192000
 
-#define SUN4I_FORMATS	(SNDRV_PCM_FORMAT_S16_LE | \
-				SNDRV_PCM_FORMAT_S20_3LE | \
-				SNDRV_PCM_FORMAT_S24_LE)
+#define SUN4I_FORMATS	(SNDRV_PCM_FMTBIT_S16_LE | \
+				SNDRV_PCM_FMTBIT_S20_3LE | \
+				SNDRV_PCM_FMTBIT_S24_LE | \
+				SNDRV_PCM_FMTBIT_S32_LE)
 
 static struct snd_soc_dai_driver sun4i_spdif_dai = {
 	.playback = {
Signature · 1 line
2.47.0
maintainer
#4 lore raw
In reply to [email protected]
Quoted 10 lines · On Mon, 11 Nov 2024 17:55:28 +0100, [email protected] wrote:

I've tested this patch series on the Allwinner H3, A64, H6 and H313 SoCs up to 192KHz.
24bit support is working on my H313 board but 16bit plays a bit slow and I suspect that there is an issue with the clock setups. This is even present without this patch stack. I would look to address this asap, but for now can you please review what's here.
BR,
CK

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/3] ASoC: sun4i-spdif: Add clock multiplier settings

      commit: 0a2319308de88b9e819c0b43d0fccd857123eb31
[2/3] ASoC: sun4i-spdif: Always set the valid data to be the MSB
      commit: 80ac12ffb3a9e19a2f11eb1975ed31c9a39183c8
[3/3] ASoC: sun4i-spdif: Add working 24bit audio support
      commit: 6e750d3ec7410c8d3aa6a006d37142eb837b3c03

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark