Re: rt5651 + rk3399 orange-pi 4b no HP output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]





On 22/1/2025 15:10, Chris Ruehl wrote:
On 21/1/2025 18:33, Chris Ruehl wrote:
Hi,

Fighting for over a week try to get the headphone sound working on a orange-pi 4b (rk3399 + rt5651-codec) as simple-card setup. So far I got all clocks working on the i2s1 bus and use alsamixer set Dac1 mix to HPO_L/R. Jack plugin gpio is working correct and I see the status change in the /sys/ kernel/debug/sound/card1/Headphones Jack/status
All I got is a 'knack-noise' when starting/stopping the stream.


....

Keep going debugging,
add a dev_dbg to rockchip_i2s.c to compare the bclk rates.
and there is a difference in i2s vs. rt565 where the bclk frequency is 1/2 of
what i2s is using.

[   72.204217] rt5651 1-001a: Sysclk is 5644800Hz and clock id is 0
[   72.204922] rt5651 1-001a: framesize: 32
[   72.205272] rt5651 1-001a: bclk is 705600Hz and lrck is 22050Hz
[   72.205792] rt5651 1-001a: bclk_ms is 0 and pre_div is 0 for iis 0
[   72.206345] rockchip-i2s ff890000.i2s: mclk_rate: 5644800 bclk_rate: 1411200 div_bclk: 4 div_lrck: 64


Finally have it working, the Realtek Codec driver rt5651 not enabled the master clock gate to the MBCK port on the chip. Other codes like rt5616 do this. In consequence, non of the other rk3399-*.dts with same config can have a workable headphone output!

Here is my patch to make the headphones working:
--- sound/soc/codecs/rt5651.c.org       2025-01-23 14:44:54.488095319 +0800
+++ sound/soc/codecs/rt5651.c   2025-01-23 14:47:07.125695637 +0800
@@ -6,6 +6,7 @@
  * Author: Bard Liao <bardliao@xxxxxxxxxxx>
  */

+#include <linux/clk.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/delay.h>
@@ -1298,6 +1299,7 @@
dev_err(component->dev, "Unsupported frame size: %d\n", frame_size);
                return -EINVAL;
        }
+
        bclk_ms = frame_size > 32 ? 1 : 0;
        rt5651->bclk[dai->id] = rt5651->lrck[dai->id] * (32 << bclk_ms);

@@ -1511,6 +1513,9 @@
 static int rt5651_set_bias_level(struct snd_soc_component *component,
                        enum snd_soc_bias_level level)
 {
+       int ret;
+       struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component);
+
        switch (level) {
        case SND_SOC_BIAS_PREPARE:
if (SND_SOC_BIAS_STANDBY == snd_soc_component_get_bias_level(component)) {
@@ -1531,6 +1536,12 @@
                                RT5651_PWR_FV1 | RT5651_PWR_FV2,
                                RT5651_PWR_FV1 | RT5651_PWR_FV2);
snd_soc_component_update_bits(component, RT5651_D_MISC, 0x1, 0x1);
+                       ret = clk_prepare_enable(rt5651->mclk);
+                       if (ret) {
+                               dev_err(component->dev,
+                                       "failed to enable MCLK: %d\n", ret);
+                               return ret;
+                       }
                }
                break;

@@ -1546,6 +1557,7 @@
                /* Leave PLL1 and jack-detect power as is, all others off */
                snd_soc_component_update_bits(component, RT5651_PWR_ANLG2,
                                    ~(RT5651_PWR_PLL | RT5651_PWR_JD_M), 0);
+               clk_disable_unprepare(rt5651->mclk);
                break;

        default:
@@ -2241,6 +2253,11 @@

        regmap_write(rt5651->regmap, RT5651_RESET, 0);

+       /* Check if MCLK provided */
+       rt5651->mclk = devm_clk_get_optional(&i2c->dev, "mclk");
+       if (IS_ERR(rt5651->mclk))
+               return PTR_ERR(rt5651->mclk);
+
        ret = regmap_register_patch(rt5651->regmap, init_list,
                                    ARRAY_SIZE(init_list));
        if (ret != 0)

--- sound/soc/codecs/rt5651.h.org       2025-01-23 14:45:09.173212267 +0800
+++ sound/soc/codecs/rt5651.h   2025-01-23 14:47:07.685582610 +0800
@@ -2084,6 +2084,8 @@
        unsigned int ovcd_th;
        unsigned int ovcd_sf;

+       struct clk *mclk;
+
        int irq;
        int sysclk;
        int sysclk_src;

Is there a patch upstream lined up?

Regards
Chris




[Index of Archives]     [Pulseaudio]     [Linux Audio Users]     [ALSA Devel]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux