$ git log --pretty=format:'%h %s (%cs)%d'
9da4c1e More workarounds for building with 6.14+ kernels (2025-03-24)
(HEAD -> master)
eafefa8 Add missing __le16, __le64 and co definitions in wrapper.h (2024-10-17)
defa83b Fix build with 6.12-rc1 (2024-10-01)
b0ac84f Fix the previous regmap fix for bit updates (2024-07-26)
dbc0bf9 Fix builds with 6.10 / 6.11 (2024-07-25)
3f7e171 Fix the regmap bit updates (2024-07-25)
39e4cba Fix for 6.8+ kernel builds (2024-02-28)
4ca0847 Fix build on 6.5 (2023-07-21)
15998e2 Fix runtime PM initial state (2022-09-02)
5136dc8 Workaround for 6.0 (2022-09-01)
...
$ git cat-file blob HEAD:README
HD-AUDIO EMULATOR
=================
GENERAL
-------
hda-emu ("HD-Audio EMUlator", or "Horribly Destructive And
Embarrassingly Malfunctional Unit") is a program written for making
test and debug of ALSA HD-audio driver easier. The source tree
contains three things: the HD-audio controller/codec emulation codes,
the build stub for codec parser codes in the kernel HD-audio driver
tree, and a collection of codec proc files.
This package itself doesn't contain the kernel driver code at all.
You need to prepare the Linux kernel-tree to emulate, and pass the
root directory of Linux kernel to --with-kerneldir option of configure
script. For example, if you have linux-4.0 kernel in
/somewhere/linux-4.0,
% ./configure --with-kerneldir=/somewhere/linux-2.0
Then it'll copy (symlink) the files from the given directory into
kernel subdirectory.
The wrapper of kernel functions can be found in include directory.
There are several cheats and tricks there. Many codes are replaced
with other normal functions.
The build is as usual -- configure and make. No special requirement,
as far as I know.
GETTING STARTED
---------------
Start hda-emu program with a codec proc file to emulate.
% hda-emu my-proc-file
The program will skip other lines than proc contents, so you can pass
alsa-info.sh output, too. If the file contains multiple codecs, you
can specify the codec index via -i option. As default, the first
codec is used.
% hda-emu -i 1 alsa-info.txt
For testing, just pick up one file found in codecs subdirectory.
As default, the program is pretty verbose. When you start it up,
you'll see a bunch of messages like:
% hda-emu codecs/stac9200-dell-d820-laptop
# Parsing..
hda_codec: Unknown model for STAC9200, using BIOS defaults
hda_codec: pin nid 08 bios pin config 40c003fa
...
The emulator prints all logs of snd_printdd() and snd_printd() in the
default log level in addition to its own messages. To suppress the
driver log messages, pass -l option with an appropriate log level.
The level 0 will suppress all messages except for errors.
The level 1 will show snd_printd() and snd_printdd() messages as well
as basic messages of hda-emu itself.
The level 2 will show each codec verbs in addition to messages shown
via the level 1.
The program has a stupid dumb command shell, and will ask you a command
after initializing and showing the messages.
# Building controls...
CTRL: add: Master Playback Volume:0
...
# Building PCMs...
>
At this point, you can give a command. For example, type "help" or
"h" and enter,
> help
Available commands: list get set dump jack option help verb pm \
init fs quit
Run "help CMD" for details
No surprise, huh?
The basic commands are described in the next sections.
BASIC COMMANDS
--------------
* list
List the control (mixer) elements created by the driver.
> list
1: Master Playback Volume:0 (1)
2: Master Playback Switch:0 (1)
3: Input Source:0 (1)
4: Capture Volume:0 (1)
...
The first number is the control element numid. This number is used
in get and set commands to specify the element.
Then the control element name follows. The number after colon (:)
shows the element index. When multiple elements with the same name
exists, there can be more than zero there.
The last number in parentheses is the number of multi-elements.
When this is more than 1, it means that there are multiple elements.
* get
Get the control element information. Pass the numid of the element
to see.
> get 1
1 Master Playback Volume:0
MIN/MAX: 0/31, VAL: [0] [0]
In this case, the element 1, "Master Playback Volume", takes an
integer value between 0 and 31, and its current values are 0 and 0
(usually for left and right channels).
Instead of the numid, you can pass the name string of the control
element. Use single- or double quotes around the name.
> get "Master Playback Volume"
1 Master Playback Volume:0
MIN/MAX: 0/31, VAL: [0] [0]
If there are multiple control elements with the same name and
different indices, pass the index number with ":" suffix.
> get "Headphone Playback Switch:1"
20 Headphone Playback Switch:1
MIN/MAX: 0/1, VAL: [1] [1]
* set
Set the control element value. Pass the numid or the name string in
the first argument, and pass and the value(s) in the rest.
> set 1 10 4
or
> set "Master Playback Volume" 10 4
When the log level is more than 1, you'll see the codec verbs such
as
send: NID=0xb, VERB=0x3a0(set_amp_gain_mute), PARM=0xa
send: NID=0xb, VERB=0x390(set_amp_gain_mute), PARM=0x84
* dump
Dump the codec proc output. This is identical with proc file
contents.
> dump
Codec: SigmaTel STAC9200
Address: 0
Vendor Id: 0x83847690
Subsystem Id: 0x102801cc
...
If you would like to show only a certain widget, you can pass the
widget NID as the argument.
> dump 0x10
Node 0x10 [Pin Complex] wcaps 0x400181: Stereo
Pincap 0x081737: IN OUT
Pin Default 0x01a19021: [Jack] Mic at Ext Rear
Conn = 1/8, Color = Pink
Pin-ctls: 0x20: IN
Connection: 1
Passing the value 0 to the first argument is equivalent without
passing the argument, i.e. showing full dump.
By passing the value 1, it dumps only the codec and FG information
(e.g. codec name, vendor id, etc).
Also, you can pass a file name to the second argument if you want
to save the dump to the specifid file.
* jack
Get / set the jack plug state. When invoked without arguments,
it lists the active pin NIDs.
> jack
NID 0x0d: cfg 0x032110f0: [Jack] HP Out at Ext Left
NID 0x0f: cfg 0x03a110f0: [Jack] Mic at Ext Left
NID 0x10: cfg 0x921701f0: [Fixed] Speaker at Int Front
NID 0x11: cfg 0x95a601f0: [Fixed] Mic at Int Top
Usually this shows the jack status the driver keeps internally.
If you'd need to look at the original default pincfg, pass -r
option.
> jack -r
NID 0x0d: cfg 0x921701f0: [Fixed] Speaker at Int Front
...
(Note that the difference appears only with 3.8 or later kernel
code. In the older kernels, both results with and without -r
will show the same list.)
When called with a widget numid, it shows the current jack state.
> jack 0x0d
Jack state [0xd] = 0
To emulate the jack plug / unplug, set the value in the second
argument, either 1 or 0. With the loglevel > 1, you'll see the
codec verbs handled in the unsol_event handler.
> jack 0x0d 1
send: NID=0xd, VERB=0xf09(get_pin_sense), PARM=0x0
receive: 0x80000000
send: NID=0xd, VERB=0x707(set_pin_ctl), PARM=0xc0
...
* PCM
List the registered PCM streams or test the PCM stream.
When no argument is passed, hda-emu lists the all registered PCM
streams. For example,
> PCM
0: STAC92xx Analog:0 (audio), play=1, capt=2
1: STAC92xx Digital:1 (SPDIF), play=1, capt=0
where the first number indicates the stream ID number.
For testing a PCM stream, pass the ID number to the first argument,
and the stream direction, either playback or capture (or 0, 1).
Also, pass the sample rate (default = 48000), channels (default =
2), and format bits (default = 16) if you want to test with
different values. Then hda-emu does a single-shot PCM test: open,
prepare, cleanup and close.
> PCM 0 p 48000 2 16
Open PCM STAC92xx Analog for play
send: NID=0x21, VERB=0xf00(get_parameters), PARM=0xa(PCM)
receive: 0xe07e0
...
Prepare PCM, rate=48000, channels=2, format=16 bits
PCM format_val = 0x11
...
A PCM substream can be specified as a style of "a:b". For example,
passing 1:2 for the first argument means that the stream id 1, the
substream id 2. This is useful to check when the driver supports
the multiple-substreams.
As default, PCM command simulates from open to close. When -s
option is passed after "PCM", it operates only the open/prepare.
When -e option is passed, it operates only the close procedure.
* route
Show the routes from/to the given widget.
> route 0x28
Pin[2c] -- Mix[21] -- Mix[1b] -> Pin[28]
Out[08] -> Sel[34] -- Mix[1b] -> Pin[28]
Pin[28] -- Mix[21] -- Mix[1c] -> Pin[29]
Pin[28] -- Mix[21] -- Mix[1b] -> Pin[28]
...
When -x option is passed, it shows also the routes from/to inactive
pins.
As default, it shows only the active (i.e. currently connected)
routes. When option -a is passed before the widget NID, it shows
all routes even though the connection isn't active. (-a option
includes -i option implicitly.)
> route -a 0x28
Pin[2c] -- Mix[21] -- Mix[1b] -> Pin[28]
Out[08] -> Sel[34] -- Mix[1b] -> Pin[28]
Pin[28] -- Mix[21] -x Sel[1f] -> In [11]
Pin[28] -- Mix[21] -x Sel[1e] -> In [10]
Pin[28] -- Mix[21] -- Mix[1c] -> Pin[29]
Pin[28] -- Mix[21] -- Mix[1b] -> Pin[28]
...
The options -i and -o specify the direction of connection. When -i
is passed, it shows only the routes ended to the given NID. When -o
is passed, shows only the routes starting from the given NID. As
default, both routes are shown.
The option -m makes the mute flag appearing in the routes. When
an input or an output amp is muted, the letter '|' appears in the
path.
* pm
Simulate suspend/resume cycle.
When option -i is given, the pin control values and the in/out amp
values are reset to the initial state before resume. When option -r
is given, the pin control values and the in/out amp values are set
randomly before resume. These options are useful to check whether
the resume procedure properly restores the values.
* quit
Quit the shell.
ADVANCED COMMANDS
-----------------
* verb
Execute a verb. Use as you like.
> verb 0x0d 0xf07 0x00
Command response:: 0xc0
* unsol
Issue an arbitrary unsolicited event. Pass the NID to issue an
event. The tag is automatically obtained from the current widget
status.
* option
Change the module option dynamically.
Currently, only power_save option can be changed by this command.
> option power_save
Power-save = 0
> option power_save 1
> option power_save
Power-save = 1
* fs
Access to sysfs file entry. This command takes a sub-command,
either of "get", "set" and "list". Not all sysfs files are
available yet.
"fs list" shows the available sysfs file entries.
> fs list
Available sysfs entries:
driver_pin_configs (R)
init_pin_configs (R)
...
> fs get init_pin_configs
0x24 0x01014010
0x25 0x01011012
0x26 0x01016011
...
> fs set user_pin_configs 0x24 0x411111f0
send: NID=0x24, VERB=0x71c(set_config_def_0), PARM=0xf0
...
> fs set hints jack_detect=false
> fs get hints
jack_detect = false
> fs set reconfig 1
LOG FILE
--------
The messages can be saved to a file by starting with -o option.
When -q option is given, the program doesn't echo the messages to
stdout but outputs only to the log file. It's useful for automating
test. The shell command can be fed from stdin, so you can write a
command sequence in a file and redirect it to hda-emu.
MODEL OPTION
------------
If you need to give a certain "model" module option to the driver,
e.g. if you need to debug the behavior of the driver with
model=laptop, pass it via -m option to hda-emu. Also, the PCI SSID
can be overridden by -p option.
COLORED OUTPUT
--------------
As default, hda-emu outputs the lines in color using ANSI escape
sequences. The escape sequences will be stripped in the log files,
though. You can toggle color/non-color behavior via -C and -M
options, respectively.
INITIAL PIN-CONFIGURATION AND HINTS
-----------------------------------
As default, hda-emu takes the default pin-configurations as set in the
given codec proc file (or the proc file content in the given
alsa-info.sh output). But the codec proc file might contain the
status that is already overwritten by the driver or changed by user,
which isn't identical with the real initial state.
When the pin-config sysfs file is available, hda-emu can read it and
initialize the pin defaults accordingly via -P option. When the input
file is a recent alsa-info.sh output containing sysfs file entries,
pass like "-P hwC0D0/init_pin_configs". Then hda-emu will initialize
the pin-default contents found in hwC0D0/init_pin_configs sysfs file.
You can also pass an external file name to -P option instead of the
sysfs files in the input file. The file must contain a pair of
register and pin-config value in each line just like in *_pin_configs
sysfs files. Also, you can pass a pin config directly via -P optoin,
e.g. -P 0x0a=0x12345678.
For providing the user-defined pin configurations, use -U instead of
-P option. The difference between these two options is that the pin
configuration set via -P option may be overridden by the driver's own
setup while the pin configuration set via -U remains over the driver's
setup.
Similarly, you can give the initial hints strings either from sysfs
file in alsa-info.sh output or an external file via -H option. Also,
you can pass a hint directrly via -H option, e.g. -H "jack_detect=0".
If you want to debug a certain jack-plug state at the initial time,
pass the pin NID to turn on via -j option. When nothing is set, all
pins are assumed to be unplugged at the start up.
START WITHOUT CODEC PARSER
--------------------------
When you don't want to start the codec parser procedure, i.e. just
probe the codec and initializes the instance without invoking the
parser, pass -n option. (This corresponds to probe_only=1 option for
snd-hda-intel module.)
Then you can inspect the pin config, add hints or whatever, then
trigger the codec parser manually later by "fs set reconfig 1" command.
DEBUGGING DRIVER WITH GDB
-------------------------
It's often useful to debug the driver behavior via gdb. When you pass
-a option to hda-emu, it'll send SIGTRAP when the error is from the
driver; i.e. when printk(KERN_ERR ...) is issued. Then gdb will trap
it and you can see the code path and invesitage there.
The -a option doesn't affect operations when hda-emu isn't invoked in
gdb or such, as SIGTRAP is ignored as default in hda-emu.
DOWNLOAD
--------
The git tree is found at:
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/hda-emu.git
A backup repo is at:
https://github.com/tiwai/hda-emu
LICENSE
-------
GPL v2. See COPYING file.
# heads (aka `branches'):
$ git for-each-ref --sort=-creatordate refs/heads \
--format='%(HEAD) %(refname:short) %(subject) (%(creatordate:short))'
* master More workarounds for building with 6.14+ kernels (2025-03-24)
kernel-4.0 Add ASUS PCI id to pci_ids.h (2015-02-19)
# tags:
$ git for-each-ref --sort=-creatordate refs/tags \
--format='%(refname:short) %(subject) (%(creatordate:short))'
v0.2.6 Version 0.2.6 (2009-09-02) tar.gz
v0.2.5 Version 0.2.5 (2009-04-23) tar.gz
v0.2.4 Version 0.2.4 (2009-03-11) tar.gz
v0.2.3 Version 0.2.3 (2009-02-10) tar.gz
v0.2.2 version 0.2.2 (2009-01-28) tar.gz
v0.2.1 version 0.2.1 (2009-01-23) tar.gz
v0.2.0 version 0.2.0 (2009-01-21) tar.gz
v0.1.2 version 0.1.2 (2009-01-16) tar.gz
v0.1.1 version 0.1.1 (2009-01-16) tar.gz
v0.1.0 version 0.1.0 (2009-01-14) tar.gz
...
# associated public inboxes:
# (number on the left is used for dev purposes)
89 alsa-devel
28 lkml
7 netdev
6 linux-mm
5 qemu-devel
5 stable
5 u-boot
4 linux-arm-kernel
4 linux-usb
4 linux-pci
4 kvm
4 igt-dev
3 linux-samsung-soc
3 linux-xfs
3 bpf
3 linux-devicetree
3 fstests
3 linux-scsi
3 selinux
3 intel-gfx
3 linux-omap
3 linux-i2c
3 linux-perf-users
3 kvm-ppc
3 lvm-devel
2 linux-wireless
2 linux-mtd
2 linux-riscv
2 linux-nvme
2 linux-nfs
2 linux-mediatek
2 linux-crypto
2 linux-efi
2 linux-acpi
2 netfilter-devel
2 linux-fsdevel
2 linux-cifs
2 linux-amlogic
2 linux-erofs
2 linux-iommu
2 linux-media
2 xen-devel
2 linux-mips
2 linux-pm
2 linux-rtc
2 linux-input
2 linux-btrfs
2 kvmarm
2 driverdev-devel
2 linux-kselftest
2 linux-clk
2 linux-iio
2 linux-gpio
2 linux-rdma
2 linux-ext4
2 dpdk-dev
2 linux-leds
2 linux-security-module
2 linux-f2fs-devel
2 linuxppc-dev
2 linux-modules
2 linux-rt-users
2 linux-bluetooth
2 linux-ide
2 linux-serial
2 linux-watchdog
2 linux-trace-devel
2 util-linux
2 backports
2 linux-doc
2 git
2 linux-man
2 linux-mmc
2 amd-gfx
2 dri-devel
2 linux-api
2 linux-spi
2 linux-sparse
2 linux-tegra
2 lttng-dev
2 virtualization
2 linux-kbuild
2 linux-arch
2 linux-can
2 containers
2 linux-rockchip
2 linux-raid
2 platform-driver-x86
2 openbmc
2 linux-fbdev
2 linux-cxl
2 linux-sh
2 nouveau
2 linux-s390
2 kernel-janitors
2 mptcp
2 linux-coco
2 buildroot
2 iwd
2 ofono
2 ltp
2 yocto
2 yocto-meta-freescale
2 openembedded-core
2 yocto-toaster
2 yocto-meta-arm
2 openembedded-devel
2 bitbake-devel
2 yocto-meta-virtualization
2 yocto-meta-ti
2 yocto-meta-arago
2 outreachy
2 openrisc
2 intel-wired-lan
2 kexec
2 intel-xe
2 linux-um
2 virtio-comment
2 poky
2 qemu-riscv
2 cluster-devel
2 grub-devel
2 linux-hexagon
2 reiserfs-devel
2 virtio-fs
2 fuego
1 linux-fscrypt
1 cocci
1 linux-block
1 live-patching
1 linux-integrity
1 linux-edac
1 linux-arm-msm
1 linux-nvdimm
1 linux-snps-arc
1 linux-hwmon
1 linux-renesas-soc
1 kernel-hardening
1 dmaengine
1 linux-next
1 linux-parisc
1 kernelnewbies
1 linux-sgx
1 linux-hyperv
1 workflows
1 rcu
1 selinux-refpolicy
1 linux-m68k
1 linux-i3c
1 linux-spdx
1 linux-wpan
1 ksummit-discuss
1 wireguard
1 io-uring
1 linux-kernel-mentees
1 linux-csky
1 tpmdd-devel
1 linux-unionfs
1 linux-firmware
1 cip-dev
1 linux-audit
1 linux-remoteproc
1 linux-dash
1 linux-bcache
1 mm-commits
1 linux-pwm
1 linux-fpga
1 ceph-devel
1 xdp-newbies
1 phone-devel
1 linux-hardening
1 dash
1 dm-devel
1 keyrings
1 linux-sctp
1 target-devel
1 lustre-devel
1 soc
1 ocfs2-devel
1 rust-for-linux
1 ath10k
1 ath11k
1 linux-phy
1 sparclinux
1 linux-staging
1 linux-sunxi
1 regressions
1 ksummit
1 b43-dev
1 nvdimm
1 linux-nfc
1 linux-bcachefs
1 ath9k-devel
1 ntfs3
1 llvm
1 fio
1 ell
1 yocto-docs
1 linux-patches
1 chrome-platform
1 ntb
1 xenomai
1 damon
1 asahi
1 loongarch
1 imx
1 ath12k
1 b4-sent
1 linux-trace-kernel
1 oe-linux-nfc
1 oe-kbuild-all
1 oe-chipsec
1 batman
1 virtio-dev
1 v9fs
1 ecryptfs
1 linux-ia64
1 kbd
1 autofs
1 cpufreq
1 dccp
1 cgroups
1 devicetree-spec
1 devicetree-compiler
1 initramfs
1 hail-devel
1 kvm-ia64
1 linux-8086
1 kernel-testers
1 linux-alpha
1 linux-btrace
1 linux-embedded
1 linux-hams
1 linux-hotplug
1 linux-laptop
1 linux-sound
1 trinity
1 linux-metag
1 linux-x25
1 linux-nilfs
1 lvs-devel
1 netfilter
1 linux-oxnas
1 u-boot-amlogic
1 lm-sensors
1 acpica-devel
1 perfbook
1 smatch
1 wireless-regdb
1 powertop
git clone https://yhbt.net/lore/pub/scm/linux/kernel/git/tiwai/hda-emu.git