Skip to main content
Ara.1
Associate III
August 6, 2021
Question

sgtl5000 codec dsi i2c

  • August 6, 2021
  • 42 replies
  • 11268 views

Hi All,

i am using stm32mp1 with i2c on sgtl5000 codec and control lines are over carrier i2s

i am getting kernel soc sgtl5000.c error

sgtl5000 0-000a: Error reading chip id -6

<STM32_PINMUX('A', 15, AF5)>; /* I2S1_WS */

<STM32_PINMUX('Z', 0, AF5)>, /* I2S1_CK */

                  <STM32_PINMUX('Z', 1, AF5)>, /* I2S1_SDI */

                  <STM32_PINMUX('Z', 2, AF5)>, /* I2S1_SDO */

                  <STM32_PINMUX('Z', 6, AF5)>; /* I2S1_MCK */

Any reference dts on i2s1 would be helpful.. and suggest on kernel error .

This topic has been closed for replies.

42 replies

Bernard PUEL
Technical Moderator
August 31, 2021

OK. After review with experts, here are our conclusions:

  • the external codec requiring MCLK to finish I2c init, I2s part will never solve the issue (MCLK is triggered by ASOC power management and will never happen if the external codec cannot pass I2C init).
  • I2s is the MCLK provider so the best way to solve this mutual dependency would be to make a hack in I2c driver to be consumer of this MCLK clock. That way, the MCLK will be activated as soon as the I2c will request it (so before external codec init).
  • This is not a clean solution but it should work.
Ara.1
Ara.1Author
Associate III
September 1, 2021

could you brief be how the routing property will makes the always generation of i2s mclk

and will i get patch for Setting I2S as a master clock provider this should be always on while stm32_i2s_probe ?

Bernard PUEL
Technical Moderator
September 1, 2021

Could you please share your device tree (i2s, I2c and  sgtl5000) ?

Because it seems to me you have all (but in separate threads) so I would like to check your latest one.

Ara.1
Ara.1Author
Associate III
September 2, 2021

Hi Bernard,

&i2s1 {

#clock-cells = <0>;

clocks = <&rcc SPI1>, <&rcc SPI1_K>, <&rcc PLL3_Q>, <&rcc PLL3_R>;

clock-names = "pclk", "i2sclk", "x8k", "x11k";

#sound-dai-cells = <1>;

status = "okay";

i2s1_port: ports {

#address-cells = <1>;

#size-cells = <0>;

i2s2_endpoint: port@0 {

reg = <0>;

remote-endpoint = <&sgtl5000_tx_endpoint>;

system-clock-frequency = <48000>;

system-clock-direction-out;

frame-master;

bitclock-master;

format = "i2s";

mclk-fs = <256>;

};

};

};

sound0:sound@0 {

compatible = "audio-graph-card";

label = "STM32MP1-I2S1";

routing =

"Playback" , "MCLK1",

"Capture" , "MCLK1";

dais = <&i2s1_port>;

status = "okay";

};

sgtl5000: sgtl5000.0-000a@a {

compatible = "fsl,sgtl5000";

reg = <0x0a>;

#sound-dai-cells = <0>;

clocks = <&i2s1>;

clock-names = "mclk";

status = "okay";

VDDD-supply = <&v1v8_audio>;

VDDA-supply = <&v3v3_fix>;

VDDIO-supply = <&v3v3_fix>;

ports {

#address-cells = <1>;

#size-cells = <0>;

port@0 {

reg = <0>;

sgtl5000_tx_endpoint: endpoint@0 {

reg = <0>;

remote-endpoint = <&i2s2_endpoint>;

};

};

};

};

Bernard PUEL
Technical Moderator
September 2, 2021

I/ You should have this structure:

&i2c {

      sgtl5000 {

            clocks = <&i2s1>;

            …

      };

};

II/ If not already tested, did you try to increase this delay in codec driver:

https://github.com/torvalds/linux/blob/master/sound/soc/codecs/sgtl5000.c#L1628

Ara.1
Ara.1Author
Associate III
September 2, 2021

Sorry it was under i2c node only i missed

i am using 4.19.XX but have the changes of ,mainly mclk provider but looks like

i have tried udelay(), still no MCLK

linux/stm32_i2s.c at master · torvalds/linux · GitHub

and i observe that i2s-mclk clocks out if any codec stream activity, like playback, capture. may you point out how to make always clock enable with configuring 11.XX MHz frequency in following

Observation:

if i made SGTL5000 as a codec as a kernel module it does respond to i2c command, but only i2c probe got success, and still sgtl5000_probe did not get called,

the codec stream activity done by dummy codec, so i have suggestion in following probe requirement which will work.

static int stm32_i2s_probe(struct platform_device *pdev)------------by default always clock enable

{

  1. stm32_i2s_configure(cpu_dai, params, substream);
  2. if (STM32_I2S_IS_MASTER(i2s))
  3. ret = stm32_i2s_configure_clock(cpu_dai, params);

}

so that SGTL5000 always get MCLK software, and reacts to i2c commands, is that possible ?

Bernard PUEL
Technical Moderator
September 2, 2021

With your devicetree mclk should be there and looking to the codec code, you can see there is no error to get the mclk before the error on the chip ID.

So the idea was the delay to enable the clock between the 2 blocs (only one usec) was not enough ... udelay(1000) may be tried.

Then the next idea would be to activate the dynamic traces into the i2s driver to see what happens.

Then next possibility would be a pb of clock management due to 4.19 kernel + Mclk backport. Between 4.19 and 5.10, scmi was enabled to manage the clocks.

I will review with experts and let you know.

Ara.1
Ara.1Author
Associate III
September 2, 2021

Yes Please, thanks please do review with expert and let m know

i never seen mclk after the configure stm32_i2s_configure is getting called /stm32-i2s start which does after root login prompt, i believe the same behavior exist in 5.10.XX , as we don't have sgtl5000 external crystal connect 24 mclk , we totally depends on SOC/SOM i2s_mclk, to detect SGTL5000 on i2c, by default to make it ON on stm32_i2s_probe

Ara.1
Ara.1Author
Associate III
September 2, 2021

i believe the mclk also not enabled in 5.10.xx, as the codecs are fed with crystal frequency, which codec active by default, but there are some board design like us who depends on internal mclk generation, MCLK is not live until codec sub stream is ready

Ara.1
Ara.1Author
Associate III
September 2, 2021

i believe the mclk also not enabled in 5.10.xx, as the codecs are fed with crystal frequency, which codec active by default, but there are some board design like us who depends on internal mclk generation, MCLK is not live until codec sub stream is ready

Bernard PUEL
Technical Moderator
September 3, 2021

Hello,

Just reviewed deeply the use case with experts. Many things to share.

First to answer your questions:

  • We do think 5.10 / 4.19 is not a pb. With your backport there should not be any pb.
  • To force the mclk: there is no magic commands and the ones done in the codec drivers are the only ones (clk_get + clk_prepare_enable)

Few remarks:

  • in your latest dts, i understand your i2s node is in i2c nodes (maybe i am wrong). Please make sure it is like below:

&i2c {

           sgtl5000 {

                      clocks = <&i2s1>;

                       …

           };

};

&i2s1 {

           #clock-cells = <0>;

           mclk-fs = <256> ;

           …

}

  • There is suspicion the clock got from the dts is not the right one here: "sgtl5000->mclk = devm_clk_get(&client->dev, NULL);" . Could you replace this code to explicitly name this clock "sgtl5000->mclk = devm_clk_get(&client->dev, "mclk");" ? Check there is no error.
  • after the probing of the codec (that fails), could you please print clock tree: "Board $> cat /sys/kernel/debug/clk/clk_summary" ?
  • Activating the i2s dynamic debug, you can check the master clock is enabled or not in the i2s driver (there is a dbg print)

I hope this will give some information about what happens.

On any other kernel clock, we can force them to be always active but here with the I2S, this is dependent from the activation of the I2S peripheral.

Ara.1
Ara.1Author
Associate III
September 4, 2021

Hi Bernard,

I have made

dts change

&i2c {

           sgtl5000 {

                      clocks = <&i2s1>;

                       …

           };

};

kernel/driver

sgtl5000,c change as "mclk", still i didnt get mclk during probe of SGTL, but i see mclk is getting after 35 sec, where the root login prompt comes, which

0693W00000DmBQhQAN.bmp 

you can see sgtl5000 lies at 0x0a, but probe still fails which means that i2s block is not providing the mclk during sgtl5000 probe,

if you have demo probe may you confirm the behaviour, but i see in scope after 35sec gets mclk enabled, following is the log

[  34.016482] sound/soc/stm/stm32_i2s.c stm32_i2s_startup:953

[  34.020706] sound/soc/generic/audio-graph-card.c asoc_graph_card_startup::75 ret 0

[  34.028307] sound/soc/generic/audio-graph-card.c asoc_graph_card_startup::80 ret 0

[  34.036399] sound/soc/generic/audio-graph-card.c asoc_graph_card_hw_params::110 ret 0

[  34.043703] sound/soc/generic/audio-graph-card.c asoc_graph_card_hw_params::120 ret mclk 11289600

[  34.052714] sound/soc/soc-core.c snd_soc_dai_set_sysclk 2499 dai->driver->ops->set_sysclk 0

[  34.061041] sound/soc/soc-core.c snd_soc_component_set_sysclk 2525 ************************8 11289600 0 

[  34.078598] sound/soc/soc-core.c snd_soc_dai_set_sysclk 2499 dai->driver->ops->set_sysclk c08ca710

[  34.086125] sound/soc/stm/stm32_i2s.c stm32_i2s_set_sysclk:663 cpu_dai 44004000.audio-controller (null)

[  34.098170] ****************I2S MCLK frequency is 11289600Hz. mode: master, dir: output

[  34.104740] sound/soc/stm/stm32_i2s.c stm32_i2s_set_sysclk:673 freq 11289600 dir 1 mode 1

[  34.113210] sound/soc/stm/stm32_i2s.c stm32_i2s_set_sysclk:695

[  34.119263] sound/soc/stm/stm32_i2s.c stm32_i2s_set_sysclk:714

[  34.126283] sound/soc/stm/stm32_i2s.c stm32_i2s_set_sysclk:719-- enable_mclk 5

[  34.132270] sound/soc/stm/stm32_i2s.c stm32_i2s_set_sysclk:729-- enable_mclk 5

[  34.140539] sound/soc/stm/stm32_i2s.c stm32_i2s_set_sysclk:737

[  34.145158] sound/soc/stm/stm32_i2s.c stm32_i2s_set_sysclk:738 mck oe

the above does not come during sgtl probe,

if you have demo board may you confirm the behavior ?