[Linux驅動煉成記] 04-音訊晶片TAS5754外設
阿新 • • 發佈:2018-12-12
背景
整個嵌入式專案由Buildroot構建,現有專案增加音訊TAS5754驅動,詳細步驟如下
Buildroot 配置
- 核心檔案配置
Kernel -> Defconfig name -> 核心配置檔名稱
- 核心DTS配置
Kernel -> Device Tree Source file name -> dts名稱
核心配置
核心中主要涉及DTS的配置,路徑arch/arm64/boot/dts/廠商/xxx.dts
#include "mesonaxg.dtsi"
/ {
model = "Amlogic";
amlogic-dt-id = "xxxx"; // 這個配置很重要,要和buildroot中Device Tree Source file name名稱一致
sugr-case-id = "xxx";
sugr-hw-id = "11";
compatible = "xxx, xxx";
interrupt-parent = <&gic>;
#size-cells = <2>;
- DTS中晶片IIC配置
/* for spk board */
&i2c2 {
status = "okay";
pinctrl-names="default";
pinctrl-0=<&c_i2c_master>;
npcp215x_e6: [email protected] {
compatible = "nuvoton,npcp215x";
#sound-dai-cells = <0>;
reg = <0x73>;
status = "disable"; // 禁止
reset_pin = <&gpio_ao GPIOAO_4 0>;
mute_pin = <&gpio_ao GPIOAO_3 0>;
amp_power = <&gpio_ao GPIOAO_7 0>;
};
tas575x_37: [email protected]37 {
compatible = "ti,tas575x"; //匹配名稱
#sound-dai-cells = <0>;
reg = <0x4e>; //IIC從機裝置地址
status = "okay"; //使能
mute_pin = <&gpio_ao GPIOAO_3 0>; //引腳配置
amp_power = <&gpio_ao GPIOAO_7 0>;
};
};
kernel/sound/soc/codecs/廠商/tas575x.c
//DTS 裝置匹配
static const struct of_device_id tas575x_of_match[] = {
{ .compatible = "ti, tas5754", 0 },
{ .compatible = "ti, tas5756", 0 },
{ .compatible = "ti, tas575x", 0 },
{ }
};
//i2c id 匹配
static const struct i2c_device_id tas575x_i2c_id[] = {
{ "tas5754", (kernel_ulong_t) 0 },
{ "tas5756", (kernel_ulong_t) 0 },
{ "tas575x", (kernel_ulong_t) 0 },
{ }
};
//DTS中配置的引腳通過該介面來操作
amp_power = of_get_named_gpio(node,"amp_power",0);
if (amp_power < 0){
pr_err("%s fail to get mute pin from dts!\n", __func__);
}
gpio_direction_output(amp_power,GPIOF_OUT_INIT_HIGH);
- DTS中IIS配置
aml-audio-card,dai-[email protected]2 {
format = "i2s";
mclk-fs = <256>;
continuous-clock;
/* tdmb clk using tdmc so no bclk-inv */
//bitclock-inversion;
//frame-inversion;
bitclock-master = <&aml_tdmc>;
frame-master = <&aml_tdmc>;
cpu {
sound-dai = <&aml_tdmc>;
dai-tdm-slot-tx-mask = <1 1>;
dai-tdm-slot-rx-mask = <1 1>;
dai-tdm-slot-num = <2>;
dai-tdm-slot-width = <32>;
system-clock-frequency = <12288000>;
};
codec {
//sound-dai = <&npcp215x_e6>;
sound-dai = <&tas575x_37>; //ALSA dai配置
};
};
IIS這裡的配置並沒有深入研究,後續需要會跟進
驗證音訊驅動
1. IIC通訊是否成功
static int tas575x_i2c_probe(struct i2c_client *client,const struct i2c_device_id *id)
{
//const struct of_device_id *of_id;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
i2c_set_clientdata(client, priv);
priv->regmap = devm_regmap_init_i2c(client, &tas575x_regmap);
...
return snd_soc_register_codec(dev, &soc_codec_dev_tas575x,
&tas575x_dai, 1);
}
需要注意一點:軟體中tas575x_i2c_probe匹配成功,IIC不一定通訊成功,需要實際驗證
2 . 相關功放引腳
檢視功放TAS5754資料手冊,MUTE需要拉高功放才能出聲,否則會處於靜音狀態
3. 音訊裝置節點是否掛載成功
-
成功建立裝置節點,包括播放,錄音裝置
-
通過aplay 列出所有音效卡和數字音訊裝置,熒光筆標註的地方代表已經識別到tas575x音效卡
-
音訊EQ配置
後續跟進
- 播放音訊 音訊驅動正常啟動之後,可以通過alsa-utils-1.1.3.tar.bz2中的提供的工具aplay播放音訊,看功放是否正常出聲音
aplay -Dhw:0,2 xxx.wav
-D : select PCM by name
0 : 代表 card0 2: 代表 deveice 2
IIC除錯
除錯IIC過程中需要用到邏輯分析儀,這裡用Saleae logic,軟體下載地址,軟體全平臺覆蓋,非常方便,相關軟體資料見
連結: https://pan.baidu.com/s/1KbFhnSIsWD4bFwJoIk1yzw 提取碼: xav9
問題
- 測試音訊驅動,用應用程式aplay播放wav檔案:
aplay -Dhw:0,2 xxx.wav
aplay: main:788: audio open error: Device or resource busy
主要由於其他程序佔用card 0 裝置