基於imx6q-Android6.0的ASOC架構 -- Machine、Platform和Codec簡介

arm平臺:IMX6Q
內核:Linux4.1.15
系統:Android6.0
codec:wm8960
主要內容爲Machine、Platform和Codec三大部分之間的關係和實現。文章中的舉例和代碼均爲imx6q-Android6.0源碼和文件。
文章中如有錯誤和不嚴謹內容,歡迎指正。

ASOC下的Machine、Platform和Codec

1、codec:編解碼芯片驅動

kernel_imx/sound/soc/codecs/wm8960.c

作用:實現控制命令的的具體操作。編解碼芯片寄存器的讀寫等功能。
主要的兩個結構體:
struct snd_soc_codec_driver 控制接口(i2c)
struct snd_soc_dai_driver 音頻傳輸接口(ssi或i2s)
函數:
snd_soc_register_codec

snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm8960, &wm8960_dai, 1);

struct snd_soc_codec_driver soc_codec_dev_wm8960 = {
        .probe =        wm8960_probe,
        .set_bias_level = wm8960_set_bias_level,
        .suspend_bias_off = true,
};

static const struct snd_soc_dai_ops wm8960_dai_ops = {
        .hw_params = wm8960_hw_params,
        .hw_free = wm8960_hw_free,
        .digital_mute = wm8960_mute,
        .set_fmt = wm8960_set_dai_fmt,
        .set_clkdiv = wm8960_set_dai_clkdiv,
        .set_pll = wm8960_set_dai_pll,
        .set_sysclk = wm8960_set_dai_sysclk,
};

static struct snd_soc_dai_driver wm8960_dai = {
        .name = "wm8960-hifi",
        .playback = {
                .stream_name = "Playback",
                .channels_min = 1,
                .channels_max = 2,
                .rates = WM8960_RATES,
                .formats = WM8960_FORMATS,},
        .capture = {
                .stream_name = "Capture",
                .channels_min = 1,
                .channels_max = 2,
                .rates = WM8960_RATES,
                .formats = WM8960_FORMATS,},
        .ops = &wm8960_dai_ops,
        .symmetric_rates = 1,
};

2、Platform :CPU接口驅動

kernel_imx/sound/soc/fsl/fsl_ssi.c

作用:註冊CPU接口驅動和實現。
主要結構體:
struct snd_soc_dai_driver
函數:
snd_soc_register_component

static struct snd_soc_dai_driver fsl_ssi_ac97_dai = {
        .bus_control = true,
        .playback = {
                .stream_name = "AC97 Playback",
                .channels_min = 2,
                .channels_max = 2,
                .rates = SNDRV_PCM_RATE_8000_48000,
                .formats = SNDRV_PCM_FMTBIT_S16_LE,
        },
        .capture = {
                .stream_name = "AC97 Capture",
                .channels_min = 2,
                .channels_max = 2,
                .rates = SNDRV_PCM_RATE_48000,
                .formats = SNDRV_PCM_FMTBIT_S16_LE,
        },
        .ops = &fsl_ssi_dai_ops,
};

3、Machine:連接platform和codec

kernel_imx/sound/soc/fsl/imx-wm8960.c

主要結構體:
struct snd_soc_card
struct snd_soc_dai_link

函數:snd_soc_register_card

static struct snd_soc_dai_link imx_wm8960_dai[] = {
        {
                .name = "HiFi",
                .stream_name = "HiFi",
                .codec_dai_name = "wm8960-hifi",
                .ops = &imx_hifi_ops,
        },
        {
                .name = "HiFi-ASRC-FE",
                .stream_name = "HiFi-ASRC-FE",
                .codec_name = "snd-soc-dummy",
                .codec_dai_name = "snd-soc-dummy-dai",
                .dynamic = 1,
                .ignore_pmdown_time = 1,
                .dpcm_playback = 1,
                .dpcm_capture = 1,
        },
        {
                .name = "HiFi-ASRC-BE",
                .stream_name = "HiFi-ASRC-BE",
                .codec_dai_name = "wm8960-hifi",
                .platform_name = "snd-soc-dummy",
                .no_pcm = 1,
                .ignore_pmdown_time = 1,
                .dpcm_playback = 1,
                .dpcm_capture = 1,
                .ops = &imx_hifi_ops,
                .be_hw_params_fixup = be_hw_params_fixup,
        },
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章