orangepi-xunlong / linux-orangepi

Other
200 stars 174 forks source link

OPiOS on OPi Zero2: right channel not working in audio testing with alsa speaker-test #43

Closed warpme closed 1 year ago

warpme commented 1 year ago

Hi,

I'm using https://drive.google.com/file/d/1Xpxu-HlvEPhDdhHZQQ3hkGqkUHDVsq6y/view?usp=drive_link on my OPI Zero2. Opening terminal and issuing speaker-test -c2 i'm hearing audio but only on left channel This seems to be the same issue like reported by me in https://github.com/orangepi-xunlong/linux-orangepi/issues/18

FYI: For older kernels (using non v2 audiohub implementation from https://github.com/orangepi-xunlong/linux-orangepi/commit/cfe0a8df18c2418f77acb24b17b88c9271d9613c ) patch below fixed issue.


diff -Naur sunxi.old/sun50i-ahub-cpudai.c sunxi/sun50i-ahub-cpudai.c
--- sunxi.old/sun50i-ahub-cpudai.c  2023-07-24 17:27:19.383230277 +0200
+++ sunxi/sun50i-ahub-cpudai.c  2023-07-24 16:30:20.086637225 +0200
@@ -96,13 +96,14 @@
                (1<<I2S1_GAT), (1<<I2S1_GAT));
        sunxi_ahub_update_bits(SUNXI_AHUB_I2S_CTL(1),
                (1<<I2S_CTL_TXEN), (1<<I2S_CTL_TXEN));
-
+#if 0
        sunxi_ahub_update_bits(SUNXI_AHUB_RST,
                (1<<I2S0_RST), (1<<I2S0_RST));
        sunxi_ahub_update_bits(SUNXI_AHUB_GAT,
                (1<<I2S0_GAT), (1<<I2S0_GAT));
        sunxi_ahub_update_bits(SUNXI_AHUB_I2S_CTL(0),
                (1<<I2S_CTL_TXEN), (1<<I2S_CTL_TXEN));
+#endif
        break;
    case 1:
        /* operation CVBS module */
@@ -280,6 +281,32 @@
    return 0;
 }

+static int sunxi_ahub_cpudai_hw_params(struct snd_pcm_substream *substream,
+                      struct snd_pcm_hw_params *params,
+                      struct snd_soc_dai *dai)
+{
+   struct sunxi_ahub_cpudai_priv *sunxi_ahub_cpudai =
+                   snd_soc_dai_get_drvdata(dai);
+
+   switch (params_physical_width(params)) {
+   case 16:
+       sunxi_ahub_cpudai->playback_dma_param.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
+       sunxi_ahub_cpudai->capture_dma_param.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
+       break;
+   case 24:
+   case 32:
+       sunxi_ahub_cpudai->playback_dma_param.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+       sunxi_ahub_cpudai->capture_dma_param.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+       break;
+   default:
+       dev_err(dai->dev, "Unsupported physical sample width: %d\n",
+           params_physical_width(params));
+       return -EINVAL;
+   }
+
+   return 0;
+}
+
 static int sunxi_ahub_cpudai_startup(struct snd_pcm_substream *substream,
                struct snd_soc_dai *dai)
 {
@@ -365,6 +392,7 @@
 }

 static struct snd_soc_dai_ops sunxi_ahub_cpudai_dai_ops = {
+   .hw_params = sunxi_ahub_cpudai_hw_params,
    .startup = sunxi_ahub_cpudai_startup,
    .trigger = sunxi_ahub_cpudai_trigger,
 };
@@ -452,12 +480,10 @@
    sunxi_ahub_cpudai->playback_dma_param.addr =
        res.start + SUNXI_AHUB_APBIF_TXFIFO(sunxi_ahub_cpudai->id);
    sunxi_ahub_cpudai->playback_dma_param.maxburst = 8;
-   sunxi_ahub_cpudai->playback_dma_param.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;

    sunxi_ahub_cpudai->capture_dma_param.addr =
        res.start + SUNXI_AHUB_APBIF_RXFIFO(sunxi_ahub_cpudai->id);
    sunxi_ahub_cpudai->capture_dma_param.maxburst = 8;
-   sunxi_ahub_cpudai->capture_dma_param.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;

    sunxi_ahub_cpudai->regmap = sunxi_ahub_regmap_init(pdev);
    if (!sunxi_ahub_cpudai->regmap) {
diff -Naur sunxi.old/sun50i-ahub-daudio.c sunxi/sun50i-ahub-daudio.c
--- sunxi.old/sun50i-ahub-daudio.c  2023-07-24 17:27:19.383230277 +0200
+++ sunxi/sun50i-ahub-daudio.c  2023-07-24 16:30:20.086637225 +0200
@@ -577,7 +577,7 @@

    if (sunxi_ahub_daudio->tdm_config)
        /* I2S/TDM two channel mode */
-       div_ratio = clk_div / (sunxi_ahub_daudio->pcm_lrck_period * 2);
+       div_ratio = clk_div / (sunxi_ahub_daudio->pcm_lrck_period * 4);
    else
        /* PCM mode */
        div_ratio = clk_div / sunxi_ahub_daudio->pcm_lrck_period;
warpme commented 1 year ago

It looks following path fixes issue: https://github.com/warpme/minimyth2/blob/113255b4f71be1b3ad585b29ba698197197918cd/script/kernel/linux-6.4/files/0617-0608-sound-soc-sunxi-fix-no-Rch-and-slow-24bit.patch