目录
4.1.2 获取codec的vendor_id 和 subsystem_id
5.2 查看系统初始化时使用的pin Configuration(/sys/class/sound/hwC0D0/init_pin_configs)
1 简介
Realtek的ALCxxx 系列的codec芯片的音频通道(pin)大多是双向的,也就是说,既可以作为音频输入,也可以作为音频输出。
linux内核中会为常见的ALCxxx 系列的codec芯片设置一个默认配置,默认配置中会指定codec芯片的音频通道的方向。但是有时候,硬件设计和内核中的默认配置会不同,比如,硬件设计的某个音频通道是作为扬声器(output)的,但是内核中的默认配置是麦克风(input)。这个时候,我们可以通过驱动自带的自定义配置接口(snd_hda_intel.patch=xxx)来更正默认配置。
2 硬件信息
以ALC260为例,其功能框图如下:
图中标注“In/Out”的通道表示 既可以作为音频输入,也可以作为音频输出。
3 pin Configuration
3.1 数据格式
每一组音频通道都有一个对应32bits的pin configuration。分析linux5.4.18的内核代码可知32bits的configuration定义如下:
位域 | 名称 | 不同值的含义 | 参考代码(sound/pci/hda/hda_proc.c) |
[31:30] | PORT_CONN |
0x00: Jack 0x01: N/A 0x02: Fixed 0x03: Both |
print_pin_caps() |
[29:24] | LOCATION |
0x00: N/A 0x01: Rear 0x02: Front 0x03: Left 0x04: Right 0x05: Top 0x06: Botton 0x07: Rear Panel 0x08: Drive Bar 0x17: Riser 0x18: HDMI 0x19: ATAPI 0x37: Mobile-In 0x38: Mobile-Out |
get_jack_location() |
[23:20] | DEVICE |
0x00: Line Out 0x01: Speaker 0x02: HP Out 0x03: CD 0x04: SPDIF Out 0x05: Digital Out 0x06: Modem Line 0x07: Modem Hand 0x08: Line In 0x09: Aux 0x0a: Mic 0x0b: Telephony 0x0c: SPDIF In 0x0d: Digital In 0x0e: Reserved 0x0f: Other |
get_jack_type() |
[19:16] | CONN_TYPE |
0x00: Unknown 0x01: 1/8 0x02: 1/4 0x03: ATAPI 0x04: RCA 0x05: Optical 0x06: Digital 0x07: Analog 0x08: DIN 0x09: XLR 0x0a: RJ11 0x0b: Comb 0x0c: NULL 0x0d: NULL 0x0e: NULL 0x0f: Other |
get_jack_connection() |
[15:12] | COLOR |
0x00: Unknown 0x01: Black 0x02: Grey 0x03: Blue 0x04: Green 0x05: Red 0x06: Orange 0x07: Yellow 0x08: Purple 0x09: Pink 0x0a: NULL 0x0b: NULL 0x0c: NULL 0x0d: NULL 0x0e: White 0x0f: Other |
get_jack_color() |
[11:8] | MISC |
0x01: Misc = NO_PRESENCE | print_pin_caps() |
[7:4] | DEF_ASSOC |
print_pin_caps() | |
[3:0] | SEQUENCE |
print_pin_caps() |
3.2 实际数据示例
# cat /proc/asound/card0/codec#0
Codec: Realtek ALC257
......
Node 0x12 [Pin Complex] wcaps 0x40040b: Stereo Amp-In
Amp-In caps: ofs=0x00, nsteps=0x03, stepsize=0x27, mute=0
Amp-In vals: [0x00 0x00]
Pincap 0x00000020: IN
Pin Default 0x411111f0: [N/A] Speaker at Ext Rear
Conn = 1/8, Color = Black
DefAssociation = 0xf, Sequence = 0x0
Misc = NO_PRESENCE
Pin-ctls: 0x00:
Power states: D0 D1 D2 D3 EPSS
Power: setting=D0, actual=D0
Node 0x13 [Pin Complex] wcaps 0x40040b: Stereo Amp-In
Amp-In caps: ofs=0x00, nsteps=0x03, stepsize=0x27, mute=0
Amp-In vals: [0x00 0x00]
Pincap 0x00000020: IN
Pin Default 0x40000000: [N/A] Line Out at Ext N/A
Conn = Unknown, Color = Unknown
DefAssociation = 0x0, Sequence = 0x0
Pin-ctls: 0x00:
Power states: D0 D1 D2 D3 EPSS
Power: setting=D0, actual=D0
Node 0x14 [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
Control: name="Speaker Playback Switch", index=0, device=0
ControlAmp: chs=3, dir=Out, idx=0, ofs=0
Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
Amp-Out vals: [0x80 0x80]
Pincap 0x00010014: OUT EAPD Detect
EAPD 0x2: EAPD
Pin Default 0x90170110: [Fixed] Speaker at Int N/A
Conn = Analog, Color = Unknown
DefAssociation = 0x1, Sequence = 0x0
Misc = NO_PRESENCE
Pin-ctls: 0x40: OUT
Unsolicited: tag=00, enabled=0
Power states: D0 D1 D2 D3 EPSS
Power: setting=D0, actual=D0
Connection: 1
0x02
4 修改默认的pin Configuration
4.1 临时修改(重启后无效)
例如将 nid=0x15 的音频接口配置为 0x0201e010
echo 0x15 0x0201e010 > /sys/class/sound/hwC0D0/user_pin_configs
echo 1 > /sys/class/sound/hwC0D0/reconfig
4.2 永久修改
4.1.1 参考资料
Documentation/sound/hd-audio/notes.rst
Early Patching
--------------
When ``CONFIG_SND_HDA_PATCH_LOADER=y`` is set, you can pass a "patch"
as a firmware file for modifying the HD-audio setup before
initializing the codec. This can work basically like the
reconfiguration via sysfs in the above, but it does it before the
first codec configuration.
A patch file is a plain text file which looks like below:
::
[codec]
0x12345678 0xabcd1234 2
[model]
auto
[pincfg]
0x12 0x411111f0
[verb]
0x20 0x500 0x03
0x20 0x400 0xff
[hint]
jack_detect = no
The file needs to have a line ``[codec]``. The next line should contain
three numbers indicating the codec vendor-id (0x12345678 in the
example), the codec subsystem-id (0xabcd1234) and the address (2) of
the codec. The rest patch entries are applied to this specified codec
until another codec entry is given. Passing 0 or a negative number to
the first or the second value will make the check of the corresponding
field be skipped. It'll be useful for really broken devices that don't
initialize SSID properly.
The ``[model]`` line allows to change the model name of the each codec.
In the example above, it will be changed to model=auto.
Note that this overrides the module option.
After the ``[pincfg]`` line, the contents are parsed as the initial
default pin-configurations just like ``user_pin_configs`` sysfs above.
The values can be shown in user_pin_configs sysfs file, too.
Similarly, the lines after ``[verb]`` are parsed as ``init_verbs``
sysfs entries, and the lines after ``[hint]`` are parsed as ``hints``
sysfs entries, respectively.
4.1.2 获取codec的vendor_id 和 subsystem_id
# cat /sys/class/sound/hwC0D0/vendor_id
0x10ec0260
# cat /sys/class/sound/hwC0D0/subsystem_id
0x2600000
4.1.3 使用新的pin Configuration
例如现在需要设置NID是0x0f和 0x15的音频通道都是输出,可以选择下面的Configuration
0x0f 0x02214000
0x15 0x90130110
4.1.4 新建文件test_patch,内容如下
[codec]
0x10ec0260 0x2600000 0
[model]
auto
[pincfg]
0x0f 0x02214000
0x15 0x90130110
[hint]
jack_detect = no
然后将文件test_patch放到系统的/lib/firmware/目录下。
4.1.5 修改内核启动参数 并重启系统
添加启动参数:snd_hda_intel.patch=test_patch
然后重启系统。
5 其他信息
5.1 通过dmesg信息查看codec的初始化信息
例如:
[ 25.861010] sof-audio-pci-intel-tgl 0000:00:1f.3: ASoC: Parent card not yet available, widget card binding deferred
[ 25.895469] snd_hda_codec_realtek ehdaudio0D0: autoconfig for ALC257: line_outs=1 (0x14/0x0/0x0/0x0/0x0) type:speaker
[ 25.895473] snd_hda_codec_realtek ehdaudio0D0: speaker_outs=0 (0x0/0x0/0x0/0x0/0x0)
[ 25.895474] snd_hda_codec_realtek ehdaudio0D0: hp_outs=1 (0x21/0x0/0x0/0x0/0x0)
[ 25.895476] snd_hda_codec_realtek ehdaudio0D0: mono: mono_out=0x0
[ 25.895476] snd_hda_codec_realtek ehdaudio0D0: inputs:
[ 25.895477] snd_hda_codec_realtek ehdaudio0D0: Mic=0x19
[ 25.950004] snd_hda_codec_realtek ehdaudio0D0: ASoC: sink widget AIF1TX overwritten
5.2 查看系统初始化时使用的pin Configuration(/sys/class/sound/hwC0D0/init_pin_configs)
# cat /sys/class/sound/hwC0D0/init_pin_configs
0x12 0x411111f0
0x13 0x40000000
0x14 0x90170110
0x18 0x411111f0
0x19 0x04a11030
0x1a 0x411111f0
0x1b 0x411111f0
0x1d 0x40661b45
0x1e 0x411111f0
0x21 0x0421101f