设备树添加es7202的节点,内容如下
&i2c3 {
status = "okay";
clock-frequency = <400000>;
es7202: es7202@37 {
status = "okay";
compatible = "ES7202_PDM_ADC_1";
#sound-dai-cells = <0>;
reg = <0x37>;
};
};
在设备树下添加声卡节点
sound_es7202 {
status = "okay";
compatible = "simple-audio-card";
simple-audio-card,format = "pdm";
simple-audio-card,name = "rockchip,Es7202";
simple-audio-card,mclk-fs = <256>;
simple-audio-card,cpu {
sound-dai = <&pdm>;
};
simple-audio-card,codec {
sound-dai = <&es7202>;
};
};
设备树
&pdm {
status = "okay";
rockchip,path-map = <1 0 2 3>;
clocks = <&cru MCLK_PDM>, <&cru HCLK_PDM>;
clock-names = "pdm_clk", "pdm_hclk";
pinctrl-names = "default";
pinctrl-0 = <&pdmm0_clk1
&pdmm0_sdi1>;
//#sound-dai-cells = <0>;
};
这其中rockchip,path-map含义如下:
Optional properties:
- rockchip,path-map: This is a variable length array, that shows the mapping
of SDIx to PATHx. By default, they are one-to-one mapping as follows:
path0 <-- sdi0
path1 <-- sdi1
path2 <-- sdi2
path3 <-- sdi3
e.g. "rockchip,path-map = <3 2 1 0>" means the mapping as follows:
path0 <-- sdi3
path1 <-- sdi2
path2 <-- sdi1
path3 <-- sdi0
在hardware/rockchip/audio/tinyalsa_hal/下的audio_hw.c,修改内容:
struct dev_proc_info MIC_IN_NAME[] =
{
{"realtekrt5616c", NULL,},
{"realtekrt5651co", "rt5651-aif1",},
{"realtekrt5670c", NULL,},
{"realtekrt5672c", NULL,},
{"realtekrt5678co", NULL,},
{"rockchipes8316c", NULL,},
{"rockchipes8323c", NULL,},
{"rockchipes8396c", NULL,},
{"rockchipes7210", NULL,},
{"rockchipes7243", NULL,},
{"rockchiprk", NULL, },
{"rockchiprk809co", NULL,},
{"rockchiprk817co", NULL,},
{"rockchiprt5640c", NULL,},
{"rockchiprt5670c", NULL,},
{"rockchiprt5672c", NULL,},
{"rockchipEs7202",NULL}, // es7202
{NULL, NULL}, /* Note! Must end with NULL, else will cause crash */
};
我的es7202的声卡名是"rockchipEs7202",依葫芦画瓢,复制一下上面的内容更改以下就可以了,
rk66_gnrc:/ $ cat proc/asound/cards
0 [rockchiprk817co]: rockchip_rk817- - rockchip,rk817-codec
rockchip,rk817-codec
1 [rockchipEs7202 ]: rockchip_Es7202 - rockchip,Es7202
rockchip,Es7202
rk66_gnrc:/ $
这个名字是通过在adb终端cat查看的,我之前有加后缀太长发现不行,这个名字跟simple-audio-card,name = “rockchip,Es7202”;,有关我之前是:simple-audio-card,name = “rockchip,sound_es7202”; ,下面是我之前cat出来的信息:
rk66_gnrc:/ $ cat proc/asound/cards
0 [rockchiprk817co]: rockchip_rk817- - rockchip,rk817-codec
rockchip,rk817-codec
1 [rockchipsoundes]: rockchip_sound_ - rockchip,sound_es7202
rockchip,sound_es7202
将上面的添加好后发现用安卓里的录音APP录音没有反应,最后通过好几天的查找是es7202.c源码里有问题,内容如下
static int es7202_mute(struct snd_soc_dai *dai, int mute)
{
if (mute) {
es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x03);
} else if (dai->playback_active) {
es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x00);
}
return 0;
}
#define es7202_RATES SNDRV_PCM_RATE_8000_96000
static struct snd_soc_dai_ops es7202_ops = {
.digital_mute = es7202_mute,
};
更改如下:
static int es7202_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
{
printk("Vantron-------es7202_mute_stream------------------------\r\n");
if (stream == SNDRV_PCM_STREAM_CAPTURE) {
if (mute) {
es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x03);
} else {
msleep(150);
es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x00);
}
}
return 0;
}
#define es7202_RATES SNDRV_PCM_RATE_8000_96000
static struct snd_soc_dai_ops es7202_ops = {
//.digital_mute = es7202_mute,
.mute_stream = es7202_mute_stream,
};