Hi NVpeople
I wanna use I2S0 and I2C_GP0 to connect alc5640 audio codec.
i followed this topic and Document
https://devtalk.nvidia.com/default/topic/1031303/jetson-tx2/audio-codec-rt5631-on-tx2
- in tegra186-quill-common-p3310-1000-a00.dtsi //reset codec
gpio@2200000 {
wifi_over_pcie {
gpio-hog;
gpios = <TEGRA_MAIN_GPIO(R, 4) 0>;
output-low;
label = "wifi-over-pcie";
status = "disabled";
};
pcie0_lane2_mux {
gpio-hog;
gpios = <TEGRA_MAIN_GPIO(R, 3) 0>;
output-low;
label = "pcie-lane2-mux";
status = "disabled";
};
e3325_sdio_rst {
gpio-hog;
gpios = <TEGRA_MAIN_GPIO(B, 6) 0>;
output-high;
label = "e3325-sdio-rst";
status = "disabled";
};
e3325_lane0_mux {
gpio-hog;
gpios = <TEGRA_MAIN_GPIO(B, 4) 0>;
output-low;
label = "e3325-lane0-mux";
status = "disabled";
};
aud_rst {
gpio-hog;
gpios = <TEGRA_MAIN_GPIO(J, 6) 0>;
output-high;
label = "audio reset";
status = "okay";
};
};
- modify sound structure. in tegra186-quill-common.dtsi
i2c@c240000 {
clock-frequency = <400000>;
rt5640_codec: rt5640@1c {
compatible = "realtek,rt5640";
reg = <0x1c>;
gpios = <&tegra_main_gpio TEGRA_MAIN_GPIO(J , 5) GPIO_ACTIVE_HIGH>;
realtek,jd-src = <1>; /* RT5659_JD3 */
realtek,ldo1-en-gpios = <&tegra_main_gpio TEGRA_MAIN_GPIO(J, 6) GPIO_ACTIVE_HIGH>;
};
};
tegra_sound: sound {
compatible = "nvidia,tegra-audio-t186ref-mobile-rt565x";
nvidia,model = "tegra-snd-t186ref-mobile-rt565x";
nvidia,num-codec-link = <11>;
nvidia,num-clk = <8>;
nvidia,ldo-gpios = <&tegra_main_gpio TEGRA_MAIN_GPIO(J, 6) GPIO_ACTIVE_HIGH>; //reset
nvidia,hp-det-gpios = <&tegra_main_gpio TEGRA_MAIN_GPIO(J, 5) GPIO_ACTIVE_HIGH>;
nvidia,clk-rates = < 270950400 /* PLLA_x11025_RATE */
11289600 /* AUD_MCLK_x11025_RATE */
45158400 /* PLLA_OUT0_x11025_RATE */
45158400 /* AHUB_x11025_RATE */
245760000 /* PLLA_x8000_RATE */
12288000 /* AUD_MCLK_x8000_RATE */
49152000 /* PLLA_OUT0_x8000_RATE */
49152000 >;/* AHUB_x8000_RATE */
clocks = <&tegra_car TEGRA186_CLK_PLLP_OUT0>,
<&tegra_car TEGRA186_CLK_PLLA>,
<&tegra_car TEGRA186_CLK_PLL_A_OUT0>,
<&tegra_car TEGRA186_CLK_AHUB>,
<&tegra_car TEGRA186_CLK_CLK_M>,
<&tegra_car TEGRA186_CLK_AUD_MCLK>;
clock-names = "pll_p_out1", "pll_a", "pll_a_out0", "ahub",
"clk_m", "extern1";
resets = <&tegra_car TEGRA186_RESET_AUD_MCLK>;
reset-names = "extern1_rst";
status = "okay";
nvidia,audio-routing =
"x Headphone", "x Left DAC",
"x Headphone", "x Right DAC",
"x IN", "x Left ADC",
"x IN", "x Right ADC",
"y Headphone", "y OUT",
"y IN", "y Mic",
"z Headphone", "z OUT",
"z IN", "z Mic",
"m Headphone", "m OUT",
"m IN", "m Mic",
"n Headphone", "n OUT",
"n IN", "n Mic",
"o Headphone", "o OUT",
"o IN", "o Mic",
"a IN", "a Mic",
"b IN", "b Mic",
"c IN", "c Mic",
"d IN", "d Mic",
"e Headphone", "e OUT",
"e IN", "e Mic",
"d1 Headphone", "d1 OUT",
"d2 Headphone", "d2 OUT";
nvidia,xbar = <&tegra_axbar>;
rt565x_dai_link: nvidia,dai-link-1 {
link-name = "rt5640-playback";
cpu-dai = <&tegra_i2s1>;
codec-dai = <&rt5640_codec>;
cpu-dai-name = "I2S1";
codec-dai-name = "rt5640-aif1";
format = "i2s";
bitclock-slave;
frame-slave;
bitclock-noninversion;
frame-noninversion;
bit-format = "s16_le";
bclk_ratio = <0>;
srate = <48000>;
num-channel = <2>;
ignore_suspend;
name-prefix = "x";
status = "okay";
};
and i followed
https://devtalk.nvidia.com/default/topic/1031303/jetson-tx2/audio-codec-rt5631-on-tx2/post/5247188/#5247188
step 2 modify tegra_t186ref_mobile_rt565x.c
static int tegra_t186ref_dai_init(struct snd_soc_pcm_runtime *rtd,
int rate,
int channels,
u64 formats,
bool is_playback)
{
struct snd_soc_card *card = rtd->card;
struct tegra_t186ref *machine = snd_soc_card_get_drvdata(card);
struct snd_soc_pcm_stream *dai_params;
unsigned int idx, clk_out_rate;
int err, codec_rate, clk_rate;
codec_rate = tegra_t186ref_srate_values[machine->rate_via_kcontrol];
clk_rate = (machine->rate_via_kcontrol) ? codec_rate : rate;
err = tegra_alt_asoc_utils_set_rate(&machine->audio_clock, clk_rate,
0, 0);
if (err < 0) {
dev_err(card->dev, "Can't configure clocks\n");
return err;
}
clk_out_rate = machine->audio_clock.clk_out_rate;
pr_debug("pll_a_out0 = %d Hz, aud_mclk = %d Hz, codec rate = %d Hz\n",
machine->audio_clock.set_mclk, clk_out_rate, clk_rate);
tegra_t186ref_set_params(card, machine, rate, channels, formats);
idx = tegra_machine_get_codec_dai_link_idx_t18x("rt5640-playback");
/* check if idx has valid number */
if (idx != -EINVAL) {
dai_params =
(struct snd_soc_pcm_stream *)card->rtd[idx].dai_link->params;
/*
dai_params->rate_min = clk_rate;
dai_params->formats = (machine->fmt_via_kcontrol == 2) ?
(1ULL << SNDRV_PCM_FORMAT_S32_LE) : formats;
if (!machine->is_codec_dummy) {
err = snd_soc_dai_set_sysclk(card->rtd[idx].codec_dai,
RT5659_SCLK_S_MCLK, clk_out_rate, SND_SOC_CLOCK_IN);
if (err < 0) {
dev_err(card->dev, "codec_dai clock not set\n");
return err;
}
}
*/
dai_params->rate_min = clk_rate;
dai_params->formats = formats;
err = snd_soc_dai_set_pll(card->rtd[idx].codec_dai, 0, 0, 0, 0);
if (err < 0)
{
dev_err(card->dev, "failed to set codec clock to %d\n",clk_out_rate);
return err;
}
}
/* set clk rate for i2s3 dai link*/
idx = tegra_machine_get_codec_dai_link_idx_t18x("spdif-dit-2");
if (idx != -EINVAL) {
dai_params =
(struct snd_soc_pcm_stream *)card->rtd[idx].dai_link->params;
dai_params->rate_min = clk_rate;
}
static void dai_link_setup(struct platform_device *pdev)
{
struct snd_soc_card *card = platform_get_drvdata(pdev);
struct tegra_t186ref *machine = snd_soc_card_get_drvdata(card);
struct snd_soc_codec_conf *tegra_machine_codec_conf = NULL;
struct snd_soc_codec_conf *tegra_t186ref_codec_conf = NULL;
struct snd_soc_dai_link *tegra_machine_dai_links = NULL;
struct snd_soc_dai_link *tegra_t186ref_codec_links = NULL;
int i;
printk("test!!test[%s][%d]\n",__func__,__LINE__);
/* set new codec links and conf */
tegra_t186ref_codec_links = tegra_machine_new_codec_links(pdev,
tegra_t186ref_codec_links,
&machine->num_codec_links);
if (!tegra_t186ref_codec_links)
goto err_alloc_dai_link;
/* set codec init */
for (i = 0; i < machine->num_codec_links; i++) {
if (tegra_t186ref_codec_links[i].name) {
if (strstr(tegra_t186ref_codec_links[i].name,
"rt565x-playback"))
tegra_t186ref_codec_links[i].init = tegra_t186ref_init;
else if (strstr(tegra_t186ref_codec_links[i].name,
"rt5640-playback"))
tegra_t186ref_codec_links[i].init = tegra_t186ref_init;
else if (strstr(tegra_t186ref_codec_links[i].name,
"dspk-playback-r"))
tegra_t186ref_codec_links[i].init = tegra_t186ref_dspk_init;
else if (strstr(tegra_t186ref_codec_links[i].name,
"dspk-playback-l"))
tegra_t186ref_codec_links[i].init = tegra_t186ref_dspk_init;
}
}
the console message
[ 4.570046] cpuidle: Initializing cpuidle driver init for Denver cluster
[ 4.570166] cpuidle: Initializing cpuidle driver init for A57 cluster
[ 4.571230] tachometer tegra-tachometer: Tachometer driver tegra-tachometer registered
[ 4.571234] Tachometer driver initialized with pulse_per_rev: 2 and win_len: 2
[ 4.573238] test[rt5640_i2c_probe][2429]
[ 4.582052] tegradc 15210000.nvdisplay: blank - powerdown
[ 4.582632] test[rt5640_i2c_probe][2501]
[ 4.584185] tegra210_adsp_audio_platform_probe: platform probe started
[ 4.584788] tegra210-adsp adsp_audio: Default param-type to BYTE for mp3-dec1
[ 4.585062] tegra210-adsp adsp_audio: Default param-type to BYTE for spkprot
[ 4.585419] tegra210-adsp adsp_audio: Default param-type to BYTE for src
[ 4.585729] tegra210-adsp adsp_audio: Default param-type to BYTE for aac-dec1
[ 4.586075] tegra210-adsp adsp_audio: Default param-type to BYTE for aec
[ 4.586079] tegra210-adsp adsp_audio: adma channel page address dt entry not found
[ 4.586080] tegra210-adsp adsp_audio: using adma channel page 0
[ 4.587229] tegra210_adsp_audio_platform_probe probe successfull.
[ 4.587230] input: tegra-hda HDMI/DP,pcm=3 as /devices/3510000.hda/sound/card0/input0
[ 4.587404] input: tegra-hda HDMI/DP,pcm=7 as /devices/3510000.hda/sound/card0/input1
[ 4.596029] OPE platform probe
[ 4.596096] OPE platform probe successful
[ 4.627181] test!!test[tegra_t186ref_driver_probe][1038]
[ 4.627231] test!!test[dai_link_setup][932]
[ 4.672954] random: nonblocking pool is initialized
[ 4.676717] test[rt5640_probe][2027]
[ 4.681238] test[rt5640_probe][2072]
[ 4.686523] PD DISP2 index4 DOWN
[ 4.686627] PD DISP1 index3 DOWN
[ 4.686719] PD DISP0 index2 DOWN
[ 4.695356] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF1 <-> ADMAIF1 mapping ok
[ 4.695451] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF2 <-> ADMAIF2 mapping ok
[ 4.695539] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF3 <-> ADMAIF3 mapping ok
[ 4.695631] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF4 <-> ADMAIF4 mapping ok
[ 4.695727] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF5 <-> ADMAIF5 mapping ok
[ 4.695821] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF6 <-> ADMAIF6 mapping ok
[ 4.695910] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF7 <-> ADMAIF7 mapping ok
[ 4.695998] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF8 <-> ADMAIF8 mapping ok
[ 4.696095] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF9 <-> ADMAIF9 mapping ok
[ 4.696209] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF10 <-> ADMAIF10 mapping ok
[ 4.696301] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF11 <-> ADMAIF11 mapping ok
[ 4.696391] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF12 <-> ADMAIF12 mapping ok
[ 4.696482] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF13 <-> ADMAIF13 mapping ok
[ 4.696569] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF14 <-> ADMAIF14 mapping ok
[ 4.696661] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF15 <-> ADMAIF15 mapping ok
[ 4.696761] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF16 <-> ADMAIF16 mapping ok
[ 4.696859] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF17 <-> ADMAIF17 mapping ok
[ 4.696949] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF18 <-> ADMAIF18 mapping ok
[ 4.697045] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF19 <-> ADMAIF19 mapping ok
[ 4.697137] tegra-snd-t186ref-mobile-rt565x sound: ADMAIF20 <-> ADMAIF20 mapping ok
[ 4.701339] tegra-snd-t186ref-mobile-rt565x sound: ADSP-FE1 <-> ADSP PCM1 mapping ok
[ 4.701437] tegra-snd-t186ref-mobile-rt565x sound: ADSP-FE2 <-> ADSP PCM2 mapping ok
[ 4.701465] compress asoc: ADSP-FE3 <-> ADSP COMPR1 mapping ok
[ 4.701492] compress asoc: ADSP-FE4 <-> ADSP COMPR2 mapping ok
[ 4.708922] tegradc 15210000.nvdisplay: unblank
[ 4.708937] PD DISP0 index2 UP
[ 4.709986] PD DISP1 index3 UP
[ 4.710086] PD DISP2 index4 UP
[ 4.711718] Parent Clock set for DC plld2
[ 4.713337] tegradc 15210000.nvdisplay: hdmi: pclk:297000K, set prod-setting:prod_c_300M
[ 4.716581] tegra-snd-t186ref-mobile-rt565x sound: ASoC: no source widget found for x Left DAC
[ 4.716586] tegra-snd-t186ref-mobile-rt565x sound: ASoC: Failed to add route x Left DAC -> direct -> x Headphone
[ 4.716616] tegra-snd-t186ref-mobile-rt565x sound: ASoC: no source widget found for x Right DAC
[ 4.716619] tegra-snd-t186ref-mobile-rt565x sound: ASoC: Failed to add route x Right DAC -> direct -> x Headphone
[ 4.716681] tegra-snd-t186ref-mobile-rt565x sound: ASoC: no source widget found for x Left ADC
[ 4.716684] tegra-snd-t186ref-mobile-rt565x sound: ASoC: Failed to add route x Left ADC -> direct -> x IN
[ 4.716752] tegra-snd-t186ref-mobile-rt565x sound: ASoC: no source widget found for x Right ADC
[ 4.716754] tegra-snd-t186ref-mobile-rt565x sound: ASoC: Failed to add route x Right ADC -> direct -> x IN
[ 4.717234] tegra-snd-t186ref-mobile-rt565x sound: ASoC: no source widget found for d1 OUT
[ 4.717237] tegra-snd-t186ref-mobile-rt565x sound: ASoC: Failed to add route d1 OUT -> direct -> d1 Headphone
[ 4.717267] tegra-snd-t186ref-mobile-rt565x sound: ASoC: no source widget found for d2 OUT
[ 4.717270] tegra-snd-t186ref-mobile-rt565x sound: ASoC: Failed to add route d2 OUT -> direct -> d2 Headphone
[ 4.746133] input: tegra-snd-t186ref-mobile-rt565x Headphone Jack as /devices/sound/sound/card1/input2
[ 4.746843] tegra-snd-t186ref-mobile-rt565x sound: codec link not defined - codec not part of sound card
[ 4.746846] test!!test[tegra_t186ref_driver_probe][1146]
[ 4.747420] GACT probability NOT on
[ 4.747430] Mirror/redirect action on
[ 4.747441] u32 classifier
[ 4.747442] Actions configured
[ 4.747469] nf_conntrack version 0.5.0 (65536 buckets, 262144 max)
[ 4.748190] IPVS: Registered protocols ()
[ 4.748216] IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
[ 4.748287] IPVS: Creating netns size=1424 id=0
[ 4.748316] IPVS: ipvs loaded.
[ 4.748321] IPVS: [rr] scheduler registered.
[ 4.748398] ipip: IPv4 over IPv4 tunneling driver
nvidia@tegra-ubuntu:~$
nvidia@tegra-ubuntu:~$
nvidia@tegra-ubuntu:~$ sudo i2cdetect -y -r 1
[sudo] password for nvidia:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
nvidia@tegra-ubuntu:~$
nvidia@tegra-ubuntu:~$ find /sys/devices/*.i2c/ -name name -exec cat {} \; | grep 5640
rt5640
nvidia@tegra-ubuntu:~$
nvidia@tegra-ubuntu:~$
i can’t hear voice form headphone.
audio routing is correct or need to modify??
and how the check rt5640 codec configuration?