当前位置:网站首页>关于imx8mp的es8316的芯片调试

关于imx8mp的es8316的芯片调试

2022-07-06 04:38:00 永不秃头的程序员


记录在imx8mp上调试音频芯片es8316的笔记,因为在这个平台上是第一次调试这个芯片,遇到的一些问题比较多,做一次笔记

一、驱动配置

1.1 dts配置


diff --git a/arch/arm64/boot/dts/freescale/vt_sbc_mx8mp_biol.dts b/arch/arm64/boot/dts/freescale/vt_sbc_mx8mp_biol.dts
index 1389f9a2ada5..9372cd63b3a5 100755
--- a/arch/arm64/boot/dts/freescale/vt_sbc_mx8mp_biol.dts
+++ b/arch/arm64/boot/dts/freescale/vt_sbc_mx8mp_biol.dts
@@ -188,8 +188,18 @@ bt_sco_codec: bt_sco_codec {
    
                compatible = "linux,bt-sco";
        };
 
+       sound-es8316 {
    
+               compatible = "fsl,imx-audio-es8316";
+               model = "imx-audio-es8316";
+               audio-cpu = <&sai3>;
+               audio-codec = <&codec_es8316>;
+               audio-routing = 
+                       "Ext Spk", "HPOL",
+                       "Ext Spk", "HPOR";
+               };



&i2c1 {
    

+       codec_es8316: [email protected]10 {
    
+               compatible = "everest,es8316";
+               reg = <0x10>;
+               clocks = <&audio_blk_ctrl IMX8MP_CLK_AUDIO_BLK_CTRL_SAI3_MCLK1>;
+               clock-names = "mclk";
+       };
 };

1.2 cpu端的配置

因为es8316并不在fsl-asoc-card.c的默认配置内,所以我们需要自己去添加配置:

+++ b/sound/soc/fsl/fsl-asoc-card.c
@@ -43,6 +43,7 @@ enum fsl_asoc_card_type {
    
        CARD_WM8960,
        CARD_WM8962,
        CARD_SGTL5000,
+       CARD_ES8316,
        CARD_AC97,
        CARD_CS427X,
        CARD_TLV320AIC32X4,
@@ -307,7 +308,7 @@ static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
        priv->streams &= ~BIT(substream->stream);
        return ret;
 }
-
+#if 0
 /*power off amp*/
 static int  direction_output_high(struct platform_device *pdev)
 {
    
@@ -357,7 +358,7 @@ static int  direction_output_low(struct platform_device *pdev)
 
     return 0;
 }
-
+#endif
 static int fsl_asoc_card_hw_free(struct snd_pcm_substream *substream)
 {
    
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
@@ -365,11 +366,11 @@ static int fsl_asoc_card_hw_free(struct snd_pcm_substream *substream)
        struct codec_priv *codec_priv = &priv->codec_priv;
        struct device *dev = rtd->card->dev;
        int ret;
-       
-
        priv->streams &= ~BIT(substream->stream);
 
        if (!priv->streams && codec_priv->pll_id && codec_priv->fll_id) {
    
@@ -391,6 +392,7 @@ static int fsl_asoc_card_hw_free(struct snd_pcm_substream *substream)
                }
        }
 
        return 0;
 }
 
@@ -405,14 +407,11 @@ static int fsl_asoc_card_startup(struct snd_pcm_substream *substream)
        int ret;
        int gpio;
        gpio = gpio_get_value(amp_en);

        if (priv->card_type == CARD_CS42888) {
    
                if (priv->codec_priv.mclk_freq % 12288000 == 0) {
    
                        support_rates[0] = 48000;
@@ -448,7 +447,7 @@ static int fsl_asoc_card_startup(struct snd_pcm_substream *substream)
                        return ret;
 
        }
-
        return 0;
 }
 
@@ -861,6 +860,10 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
                priv->codec_priv.mclk_id = SGTL5000_SYSCLK;
                priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
                priv->card_type = CARD_SGTL5000;
+       } else if (of_device_is_compatible(np, "fsl,imx-audio-es8316")) {
    
+               codec_dai_name = "ES8316 HiFi";
+               priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
+               priv->card_type = CARD_ES8316;
        } else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic32x4")) {
    
                codec_dai_name = "tlv320aic32x4-hifi";
                priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
@@ -1230,6 +1233,7 @@ static const struct of_device_id fsl_asoc_card_dt_ids[] = {
    
        {
     .compatible = "fsl,imx-audio-cs427x", },
        {
     .compatible = "fsl,imx-audio-tlv320aic32x4", },
        {
     .compatible = "fsl,imx-audio-sgtl5000", },
+       {
     .compatible = "fsl,imx-audio-es8316", },
        {
     .compatible = "fsl,imx-audio-wm8962", },
        {
     .compatible = "fsl,imx-audio-wm8960", },
        {
     .compatible = "fsl,imx-audio-mqs", },

1.3 添加驱动

这个就直接添加在对应的Makefile文件里面去就好了,编译完后生成对应的驱动文件就行。
这个还有一个比较坑的地方再与,es8316的默认配置是关闭了的,所以你即使成功的加载驱动,你也无法发出声音,这个可以用tinymix进行修改。

evk_8mp:/ # tinymix                                                                                     
Mixer name: 'imx-audio-es8316'
Number of controls: 35
ctl	type	num	name                                     value

0	INT	2	Headphone Playback Volume                3 3
1	INT	2	Headphone Mixer Volume                   0 0
2	ENUM	1	Playback Polarity                        Normal
3	INT	2	DAC Playback Volume                      192 192 //默认是 0
4	BOOL	1	DAC Soft Ramp Switch                     Off
5	INT	1	DAC Soft Ramp Rate                       4
6	BOOL	1	DAC Notch Filter Switch                  Off
7	BOOL	1	DAC Double Fs Switch                     Off
8	INT	1	DAC Stereo Enhancement                   0
9	BOOL	1	DAC Mono Mix Switch                      Off
10	ENUM	1	Capture Polarity                         Normal
11	BOOL	1	Mic Boost Switch                         On
12	INT	1	ADC Capture Volume                       0
13	INT	1	ADC PGA Gain Volume                      0
14	BOOL	1	ADC Soft Ramp Switch                     On
15	BOOL	1	ADC Double Fs Switch                     Off
16	BOOL	1	ALC Capture Switch                       Off
17	INT	1	ALC Capture Max Volume                   28
18	INT	1	ALC Capture Min Volume                   0
19	INT	1	ALC Capture Target Volume                11
20	INT	1	ALC Capture Hold Time                    0
21	INT	1	ALC Capture Decay Time                   3
22	INT	1	ALC Capture Attack Time                  2
23	BOOL	1	ALC Capture Noise Gate Switch            Off
24	INT	1	ALC Capture Noise Gate Threshold         0
25	ENUM	1	ALC Capture Noise Gate Type              Constant PGA Gain
26	ENUM	1	Differential Mux                         lin1-rin1
27	ENUM	1	Digital Mic Mux                          dmic disable
28	ENUM	1	DAC Source Mux                           LDATA TO LDAC, RDATA TO RDAC
29	ENUM	1	Left Headphone Mux                       lin1-rin1
30	ENUM	1	Right Headphone Mux                      lin1-rin1
31	BOOL	1	Left Headphone Mixer LLIN Switch         Off
32	BOOL	1	Left Headphone Mixer Left DAC Switch     on //默认是off
33	BOOL	1	Right Headphone Mixer RLIN Switch        Off
34	BOOL	1	Right Headphone Mixer Right DAC Switch   on //默认是off

主要是修改这三个对应的寄存器
最开始我是在驱动中直接操作的寄存器:

     * Documentation for this register is unclear and incomplete,
     * but here is a vendor-provided value that improves volume
     * and quality for Intel CHT platforms.
     */
    snd_soc_component_write(component, ES8316_CLKMGR_ADCOSR, 0x32);
    /* 后面默认去添加 这三个寄存器的配置,然后就会修改对应的配置*/
    //snd_soc_component_write(component, ES8316_HPMIX_SWITCH, 0x88);
    //snd_soc_component_write(component, ES8316_DAC_VOLL, 0x00);
    //snd_soc_component_write(component, ES8316_DAC_VOLR, 0x00);

1.4 对应的验证

不出意外,你现在可以通过cat /proc/asound/cards
看到会有对应的 imx-audio-es8316的声卡配置

130|evk_8mp:/ # cat /proc/asound/cards                                                                                                                                     
 0 [imxaudioes8316 ]: imx-audio-es831 - imx-audio-es8316
                      imx-audio-es8316
 1 [imxaudiomicfil ]: imx-audio-micfi - imx-audio-micfil
                      imx-audio-micfil
evk_8mp:/ # 

同样的可以通过 tinypcminfo 看到对应的信息

evk_8mp:/ # tinypcminfo -D 0 -d 0                                                                                                                                          
Info for card 0, device 0:

PCM out:
      Access:	0x000009
   Format[0]:	0x000044
   Format[1]:	00000000
 Format Name:	S16_LE, S24_LE
   Subformat:	0x000001
        Rate:	min=16000Hz	max=48000Hz
    Channels:	min=1		max=2
 Sample bits:	min=16		max=32
 Period size:	min=32		max=32767
Period count:	min=2		max=8192

PCM in:
      Access:	0x000009
   Format[0]:	0x000044
   Format[1]:	00000000
 Format Name:	S16_LE, S24_LE
   Subformat:	0x000001
        Rate:	min=16000Hz	max=48000Hz
    Channels:	min=1		max=2
 Sample bits:	min=16		max=32
 Period size:	min=32		max=32767
Period count:	min=2		max=8192
evk_8mp:/ # 

如果硬件接线没有问题的话,你就可以使用 tinymix的工具进行录音和播放了,因为nxp的接线有些问题,会导致对应的声卡的RLCK这个数据只有1.8v-0.9v的幅值,而不是1.8v-0v,所以这个时候你的声音是没法出来的。当时我还以为是我软件的问题,干了好久都没干出来。

二、device目录下的配置

上述修改完成后,我的情况是可以播放音乐,但是无法通过对应的录音工具进行录音.
我打开对应的alsa的DEBUG宏添加对应的打印后
查看log后发现:

07-01 07:40:22.095  2122  2122 I audio_hw_primary: parse_one_card: parse /vendor/etc/configs/audio/micfil_config.json
07-01 07:40:22.095  2122  2122 I audio_hw_primary: parse_control: ctl idx 0, [CH0 Volume 5]
07-01 07:40:22.095  2122  2122 I audio_hw_primary: parse_control: ctl idx 1, [CH1 Volume 5]
07-01 07:40:22.095  2122  2122 I audio_hw_primary: parse_control: ctl idx 2, [CH2 Volume 5]
07-01 07:40:22.095  2122  2122 I audio_hw_primary: parse_control: ctl idx 3, [CH3 Volume 5]
07-01 07:40:22.095  2122  2122 I audio_hw_primary: parse_control: ctl idx 4, [CH4 Volume 5]
07-01 07:40:22.096  2122  2122 I audio_hw_primary: parse_control: ctl idx 5, [CH5 Volume 5]
07-01 07:40:22.096  2122  2122 I audio_hw_primary: parse_control: ctl idx 6, [CH6 Volume 5]
07-01 07:40:22.096  2122  2122 I audio_hw_primary: parse_control: ctl idx 7, [CH7 Volume 5]
07-01 07:40:22.096  2122  2122 I audio_hw_primary: parse_one_card: driver name imx-audio-micfi, bus name (null), out_devices 0x0, in_devices 0x80000004, out_vol[0, 255], dsd 0, hfp 0, hdmi 0, multi_chn 0, out period_size 0, out period_count 0, in period_size 0, in period_count 0, secondary_bus_name: (null)
07-01 07:40:22.096  2122  2122 I audio_hw_primary: parse_one_card: parse /vendor/etc/configs/audio/btsco_config.json
07-01 07:40:22.096  2122  2122 I audio_hw_primary: parse_one_card: driver name bt-sco-audio, bus name (null), out_devices 0x70, in_devices 0x80000008, out_vol[0, 255], dsd 0, hfp 1, hdmi 0, multi_chn 0, out period_size 0, out period_count 0, in period_size 0, in period_count 0, secondary_bus_name: (null)
07-01 07:40:22.096  2122  2122 I audio_hw_primary: parse_one_card: parse /vendor/etc/configs/audio/hdmi_config.json
07-01 07:40:22.096  2122  2122 I audio_hw_primary: parse_one_card: driver name audio-hdmi, bus name (null), out_devices 0x400, in_devices 0x0, out_vol[0, 255], dsd 0, hfp 0, hdmi 1, multi_chn 0, out period_size 0, out period_count 0, in period_size 0, in period_count 0, secondary_bus_name: (null)
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_one_card: parse /vendor/etc/configs/audio/wm8960_config.json
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_control: ctl idx 0, [Left Output Mixer PCM Playback Switch 1]
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_control: ctl idx 1, [Right Output Mixer PCM Playback Switch 1]
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_control: ctl idx 2, [Playback Volume 230]
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_control: ctl idx 3, [Speaker Playback Volume 120]
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_control: ctl idx 4, [Headphone Playback Volume 120]
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_control: ctl idx 0, [ALC Function 3]
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_control: ctl idx 1, [Left Input Mixer Boost Switch 1]
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_control: ctl idx 2, [ADC PCM Capture Volume 230]
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_control: ctl idx 3, [Capture Volume 60]
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_volume_control: ctl idx 0, name Playback Volume
07-01 07:40:22.097  2122  2122 I audio_hw_primary: parse_one_card: driver name wm8960-audio, bus name bus1_system_sound_out, out_devices 0x102000e, in_devices 0x80000014, out_vol[0, 255], dsd 0, hfp 0, hdmi 0, multi_chn 0, out period_size 0, out period_count 0, in period_size 0, in period_count 0, secondary_bus_name: (null)
07-01 07:40:22.098  2122  2122 E audio_hw_primary: cluo--> leave parse_all_cards, supported card num 4
07-01 07:40:22.098  2122  2122 I audio_hw_primary: cluo=========================================1===============
07-01 07:40:22.098  2122  2122 I audio_hw_primary: card0: imx-audio-es8316
07-01 07:40:22.098  2122  2122 E audio_hw_primary: cluo--> audio_card name  = imx-audio-es8316
07-01 07:40:22.098  2122  2122 E audio_hw_primary: cluo--> audio_card = (null)
07-01 07:40:22.098  2122  2122 E audio_hw_primary: cluo--> audio_card = (null)
07-01 07:40:22.098  2122  2122 E audio_hw_primary: cluo---> !audio_card
07-01 07:40:22.098  2122  2122 I audio_hw_primary: cluo  scan_available_device: card imx-audio-es8316 is not supported

他会去解析对应的 /vendor/etc/configs/audio/xxxxxx.json的文件配置
但是没有es8316的默认配置,查看原来的wm8960的配置文件后,发现可以通过对应的json文件去修改配置

diff --git a/common/audio-json/es8316_config.json b/common/audio-json/es8316_config.json
new file mode 100644
index 00000000..0b0f12e5
--- /dev/null
+++ b/common/audio-json/es8316_config.json
@@ -0,0 +1,17 @@
+{
    
+  "driver_name": "imx-audio-es8316",
+  "supported_in_devices": ["builtin_mic"],
+  "bus_name": "bus1_system_sound_out",
+  "supported_out_devices": ["speaker"],
+
+  "init_ctl": [
+    {
    "name": "DAC Playback Volume", "type": "int", "val": 192},
+    {
    "name": "Left Headphone Mixer Left DAC Switch", "type": "int", "val": 1},
+    {
    "name": "Right Headphone Mixer Right DAC Switch", "type": "int", "val": 1}
+  ],
+
+  "builtin_mic_ctl": [
+    {
    "name": "ADC Capture Volume", "type": "int", "val": 192},
+    {
    "name": "ADC PGA Gain Volume", "type": "int", "val": 5}
+  ]
+}

这个配置文件会去配置相关的设置,从这里也可以看出来这个配置文件中的name就是tinymix中的name。
最重要的是他会通过"driver_name": “imx-audio-es8316”, 去添加声卡,不然的花你的声卡的不能使用的,也就是上面看到的这一行log

07-01 07:40:22.098  2122  2122 I audio_hw_primary: cluo  scan_available_device: card imx-audio-es8316 is not supported

在添加完配置文件后再次查看log

07-04 02:53:05.353  2205  2205 I audio_hw_primary: parse_one_card: parse /vendor/etc/configs/audio/es8316_config.json
07-04 02:53:05.353  2205  2205 I audio_hw_primary: parse_control: ctl idx 0, [DAC Playback Volume 192]
07-04 02:53:05.353  2205  2205 I audio_hw_primary: parse_control: ctl idx 1, [Left Headphone Mixer Left DAC Switch 1]
07-04 02:53:05.353  2205  2205 I audio_hw_primary: parse_control: ctl idx 2, [Right Headphone Mixer Right DAC Switch 1]
07-04 02:53:05.353  2205  2205 I audio_hw_primary: parse_control: ctl idx 0, [ADC Capture Volume 150]
07-04 02:53:05.353  2205  2205 I audio_hw_primary: parse_control: ctl idx 1, [ADC PGA Gain Volume 3]
07-04 02:53:05.353  2205  2205 I audio_hw_primary: parse_one_card: driver name imx-audio-es8316, bus name bus1_system_sound_out, out_devices 0x2, in_devices 0x80000004, out_vol[0, 255], dsd 0, hfp 0, hdmi 0, multi_chn 0, out period_size 0, out period_count 0, in period_size 0, in period_count 0, secondary_bus_name: (null)
07-04 02:53:05.354  2205  2205 I audio_hw_primary: parse_one_card: parse /vendor/etc/configs/audio/btsco_config.json
07-04 02:53:05.354  2205  2205 I audio_hw_primary: parse_one_card: driver name bt-sco-audio, bus name (null), out_devices 0x70, in_devices 0x80000008, out_vol[0, 255], dsd 0, hfp 1, hdmi 0, multi_chn 0, out period_size 0, out period_count 0, in period_size 0, in period_count 0, secondary_bus_name: (null)
07-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> leave parse_all_cards, supported card num 5
07-04 02:53:05.354  2205  2205 I audio_hw_primary: cluo=========================================1===============
07-04 02:53:05.354  2205  2205 I audio_hw_primary: card0: imx-audio-es8316
07-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> audio_card name  = imx-audio-es8316
07-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> audio_card = P��
07-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> audio_card = P��
��-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> audio_card = 0
��-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> audio_card = 0
07-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> audio_card = ��
07-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> audio_card = ��
07-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> audio_card = 0
07-04 02:53:05.354  2205  2205 E audio_hw_primary: ����
07-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo--> audio_card = 0
07-04 02:53:05.354  2205  2205 E audio_hw_primary: ����
07-04 02:53:05.354  2205  2205 E audio_hw_primary: cluo---> audio_card->driver_name
07-04 02:53:05.362  2205  2205 E audio_hw_primary: PCM_FORMAT_S16_LE, format = 0
07-04 02:53:05.362  2205  2205 W audio_hw_primary: Supported input format imx-audio-es8316 , 0
07-04 02:53:05.362  2205  2205 E audio_hw_primary:  adev->audio_card_num = card_num =1, card_name = imx-audio-es8316

声卡已经支持,我们也可以使用对应的apk进行录音和播放。
之前没玩过imx8mp的音频,所以我也不知道会有这些东西,后面自己去实验后才发现对应框架以及使用,还是要去了解平台的相关知识阿。

原网站

版权声明
本文为[永不秃头的程序员]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_51178981/article/details/125598928