<commit_before>MORE NOTES ON HD-AUDIO DRIVER
=============================
					<NAME> <<EMAIL>>


GENERAL
-------

HD-audio is the new standard on-board audio component on modern PCs
after AC97.  Although Linux has been supporting HD-audio since long
time ago, there are often problems with new machines.  A part of the
problem is broken BIOS, and the rest is the driver implementation.
This document explains the brief trouble-shooting and debugging
methods for the	HD-audio hardware.

The HD-audio component consists of two parts: the controller chip and 
the codec chips on the HD-audio bus.  Linux provides a single driver
for all controllers, snd-hda-intel.  Although the driver name contains
a word of a well-known harware vendor, it's not specific to it but for
all controller chips by other companies.  Since the HD-audio
controllers are supposed to be compatible, the single snd-hda-driver
should work in most cases.  But, not surprisingly, there are known
bugs and issues specific to each controller type.  The snd-hda-intel
driver has a bunch of workarounds for these as described below.

A controller may have multiple codecs.  Usually you have one audio
codec and optionally one modem codec.  In theory, there might be
multiple audio codecs, e.g. for analog and digital outputs, and the
driver might not work properly because of conflict of mixer elements.
This should be fixed in future if such hardware really exists.

The snd-hda-intel driver has several different codec parsers depending
on the codec.  It has a generic parser as a fallback, but this
functionality is fairly limited until now.  Instead of the generic
parser, usually the codec-specific parser (coded in patch_*.c) is used
for the codec-specific implementations.  The details about the
codec-specific problems are explained in the later sections.

If you are interested in the deep debugging of HD-audio, read the
HD-audio specification at first.  The specification is found on
Intel's web page, for example:

- http://www.intel.com/standards/hdaudio/


HD-AUDIO CONTROLLER
-------------------

DMA-Position Problem
~~~~~~~~~~~~~~~~~~~~
The most common problem of the controller is the inaccurate DMA
pointer reporting.  The DMA pointer for playback and capture can be
read in two ways, either via a LPIB register or via a position-buffer
map.  As default the driver tries to read from the io-mapped
position-buffer, and falls back to LPIB if the position-buffer appears
dead.  However, this detection isn't perfect on some devices.  In such
a case, you can change the default method via `position_fix` option.

`position_fix=1` means to use LPIB method explicitly.
`position_fix=2` means to use the position-buffer.  0 is the default
value, the automatic check and fallback to LPIB as described in the
above.  If you get a problem of repeated sounds, this option might
help.

In addition to that, every controller is known to be broken regarding
the wake-up timing.  It wakes up a few samples before actually
processing the data on the buffer.  This caused a lot of problems, for
example, with ALSA dmix or JACK.  Since 2.6.27 kernel, the driver puts
an artificial delay to the wake up timing.  This delay is controlled
via `bdl_pos_adj` option. 

When `bdl_pos_adj` is a negative value (as default), it's assigned to
an appropriate value depending on the controller chip.  For Intel
chips, it'd be 1 while it'd be 32 for others.  Usually this works.
Only in case it doesn't work and you get warning messages, you should
change this parameter to other values.


Codec-Probing Problem
~~~~~~~~~~~~~~~~~~~~~
A less often but a more severe problem is the codec probing.  When
BIOS reports the available codec slots wrongly, the driver gets
confused and tries to access the non-existing codec slot.  This often
results in the total screw-up, and destructs the further communication
with the codec chips.  The symptom appears usually as error messages
like:
------------------------------------------------------------------------
  hda_intel: azx_get_response timeout, switching to polling mode:
        last cmd=0x12345678
  hda_intel: azx_get_response timeout, switching to single_cmd mode:
        last cmd=0x12345678
------------------------------------------------------------------------

The first line is a warning, and this is usually relatively harmless.
It means that the codec response isn't notified via an IRQ.  The
driver uses explicit polling method to read the response.  It gives
very slight CPU overhead, but you'd unlikely notice it.

The second line is, however, a fatal error.  If this happens, usually
it means that something is really wrong.  Most likely you are
accessing a non-existing codec slot.

Thus, if the second error message appears, try to narrow the probed
codec slots via `probe_mask` option.  It's a bitmask, and each bit
corresponds to the codec slot.  For example, to probe only the first
slot, pass `probe_mask=1`.  For the first and the third slots, pass
`probe_mask=5` (where 5 = 1 | 4), and so on.

Since 2.6.29 kernel, the driver has a more robust probing method, so
this error might happen rarely, though.


Interrupt Handling
~~~~~~~~~~~~~~~~~~
In rare but some cases, the interrupt isn't properly handled as
default.  You would notice this by the DMA transfer error reported by
ALSA PCM core, for example.  Using MSI might help in such a case.
Pass `enable_msi=1` option for enabling MSI.


HD-AUDIO CODEC
--------------

Model Option
~~~~~~~~~~~~
The most common problem regarding the HD-audio driver is the
unsupported codec features or the mismatched device configuration.
Most of codec-specific code has several preset models, either to
override the BIOS setup or to provide more comprehensive features.

The driver checks PCI SSID and looks through the static configuration
table until any matching entry is found.  If you have a new machine,
you may see a message like below:
------------------------------------------------------------------------
    hda_codec: Unknown model for ALC880, trying auto-probe from BIOS...
------------------------------------------------------------------------
Even if you see such a message, DON'T PANIC.  Take a deep breath and
keep your towel.  First of all, it's an informational message, no
warning, no error.  This means that the PCI SSID of your device isn't
listed in the known preset model (white-)list.  But, this doesn't mean
that the driver is broken.  Many codec-drivers provide the automatic
configuration mechanism based on the BIOS setup.

The HD-audio codec has usually "pin" widgets, and BIOS sets the default
configuration of each pin, which indicates the location, the
connection type, the jack color, etc.  The HD-audio driver can guess
the right connection judging from these default configuration values.
However -- some codec-support codes, such as patch_analog.c, don't
support the automatic probing (yet as of 2.6.28).  And, BIOS is often,
yes, pretty often broken.  It sets up wrong values and screws up the
driver.

The preset model is provided basically to overcome such a situation.
When the matching preset model is found in the white-list, the driver
assumes the static configuration of that preset and builds the mixer
elements and PCM streams based on the static information.  Thus, if
you have a newer machine with a slightly different PCI SSID from the
existing one, you may have a good chance to re-use the same model.
You can pass the `model` option to specify the preset model instead of
PCI SSID look-up.

What `model` option values are available depends on the codec chip.
Check your codec chip from the codec proc file (see "Codec Proc-File"
section below).  It will show the vendor/product name of your codec
chip.  Then, see Documentation/sound/alsa/ALSA-Configuration.txt
file, the section of HD-audio driver.  You can find a list of codecs
and `model` options belonging to each codec.  For example, for Realtek
ALC262 codec chip, pass `model=ultra` for devices that are compatible
with Samsung Q1 Ultra.

Thus, the first thing you can do for any brand-new, unsupported and
non-working HD-audio hardware is to check HD-audio codec and several<commit_msg>ALSA: hda - Fix HD-Audio.txt reference of model list<commit_after>MORE NOTES ON HD-AUDIO DRIVER
=============================
					<NAME> <<EMAIL>>


GENERAL
-------

HD-audio is the new standard on-board audio component on modern PCs
after AC97.  Although Linux has been supporting HD-audio since long
time ago, there are often problems with new machines.  A part of the
problem is broken BIOS, and the rest is the driver implementation.
This document explains the brief trouble-shooting and debugging
methods for the	HD-audio hardware.

The HD-audio component consists of two parts: the controller chip and 
the codec chips on the HD-audio bus.  Linux provides a single driver
for all controllers, snd-hda-intel.  Although the driver name contains
a word of a well-known harware vendor, it's not specific to it but for
all controller chips by other companies.  Since the HD-audio
controllers are supposed to be compatible, the single snd-hda-driver
should work in most cases.  But, not surprisingly, there are known
bugs and issues specific to each controller type.  The snd-hda-intel
driver has a bunch of workarounds for these as described below.

A controller may have multiple codecs.  Usually you have one audio
codec and optionally one modem codec.  In theory, there might be
multiple audio codecs, e.g. for analog and digital outputs, and the
driver might not work properly because of conflict of mixer elements.
This should be fixed in future if such hardware really exists.

The snd-hda-intel driver has several different codec parsers depending
on the codec.  It has a generic parser as a fallback, but this
functionality is fairly limited until now.  Instead of the generic
parser, usually the codec-specific parser (coded in patch_*.c) is used
for the codec-specific implementations.  The details about the
codec-specific problems are explained in the later sections.

If you are interested in the deep debugging of HD-audio, read the
HD-audio specification at first.  The specification is found on
Intel's web page, for example:

- http://www.intel.com/standards/hdaudio/


HD-AUDIO CONTROLLER
-------------------

DMA-Position Problem
~~~~~~~~~~~~~~~~~~~~
The most common problem of the controller is the inaccurate DMA
pointer reporting.  The DMA pointer for playback and capture can be
read in two ways, either via a LPIB register or via a position-buffer
map.  As default the driver tries to read from the io-mapped
position-buffer, and falls back to LPIB if the position-buffer appears
dead.  However, this detection isn't perfect on some devices.  In such
a case, you can change the default method via `position_fix` option.

`position_fix=1` means to use LPIB method explicitly.
`position_fix=2` means to use the position-buffer.  0 is the default
value, the automatic check and fallback to LPIB as described in the
above.  If you get a problem of repeated sounds, this option might
help.

In addition to that, every controller is known to be broken regarding
the wake-up timing.  It wakes up a few samples before actually
processing the data on the buffer.  This caused a lot of problems, for
example, with ALSA dmix or JACK.  Since 2.6.27 kernel, the driver puts
an artificial delay to the wake up timing.  This delay is controlled
via `bdl_pos_adj` option. 

When `bdl_pos_adj` is a negative value (as default), it's assigned to
an appropriate value depending on the controller chip.  For Intel
chips, it'd be 1 while it'd be 32 for others.  Usually this works.
Only in case it doesn't work and you get warning messages, you should
change this parameter to other values.


Codec-Probing Problem
~~~~~~~~~~~~~~~~~~~~~
A less often but a more severe problem is the codec probing.  When
BIOS reports the available codec slots wrongly, the driver gets
confused and tries to access the non-existing codec slot.  This often
results in the total screw-up, and destructs the further communication
with the codec chips.  The symptom appears usually as error messages
like:
------------------------------------------------------------------------
  hda_intel: azx_get_response timeout, switching to polling mode:
        last cmd=0x12345678
  hda_intel: azx_get_response timeout, switching to single_cmd mode:
        last cmd=0x12345678
------------------------------------------------------------------------

The first line is a warning, and this is usually relatively harmless.
It means that the codec response isn't notified via an IRQ.  The
driver uses explicit polling method to read the response.  It gives
very slight CPU overhead, but you'd unlikely notice it.

The second line is, however, a fatal error.  If this happens, usually
it means that something is really wrong.  Most likely you are
accessing a non-existing codec slot.

Thus, if the second error message appears, try to narrow the probed
codec slots via `probe_mask` option.  It's a bitmask, and each bit
corresponds to the codec slot.  For example, to probe only the first
slot, pass `probe_mask=1`.  For the first and the third slots, pass
`probe_mask=5` (where 5 = 1 | 4), and so on.

Since 2.6.29 kernel, the driver has a more robust probing method, so
this error might happen rarely, though.


Interrupt Handling
~~~~~~~~~~~~~~~~~~
In rare but some cases, the interrupt isn't properly handled as
default.  You would notice this by the DMA transfer error reported by
ALSA PCM core, for example.  Using MSI might help in such a case.
Pass `enable_msi=1` option for enabling MSI.


HD-AUDIO CODEC
--------------

Model Option
~~~~~~~~~~~~
The most common problem regarding the HD-audio driver is the
unsupported codec features or the mismatched device configuration.
Most of codec-specific code has several preset models, either to
override the BIOS setup or to provide more comprehensive features.

The driver checks PCI SSID and looks through the static configuration
table until any matching entry is found.  If you have a new machine,
you may see a message like below:
------------------------------------------------------------------------
    hda_codec: Unknown model for ALC880, trying auto-probe from BIOS...
------------------------------------------------------------------------
Even if you see such a message, DON'T PANIC.  Take a deep breath and
keep your towel.  First of all, it's an informational message, no
warning, no error.  This means that the PCI SSID of your device isn't
listed in the known preset model (white-)list.  But, this doesn't mean
that the driver is broken.  Many codec-drivers provide the automatic
configuration mechanism based on the BIOS setup.

The HD-audio codec has usually "pin" widgets, and BIOS sets the default
configuration of each pin, which indicates the location, the
connection type, the jack color, etc.  The HD-audio driver can guess
the right connection judging from these default configuration values.
However -- some codec-support codes, such as patch_analog.c, don't
support the automatic probing (yet as of 2.6.28).  And, BIOS is often,
yes, pretty often broken.  It sets up wrong values and screws up the
driver.

The preset model is provided basically to overcome such a situation.
When the matching preset model is found in the white-list, the driver
assumes the static configuration of that preset and builds the mixer
elements and PCM streams based on the static information.  Thus, if
you have a newer machine with a slightly different PCI SSID from the
existing one, you may have a good chance to re-use the same model.
You can pass the `model` option to specify the preset model instead of
PCI SSID look-up.

What `model` option values are available depends on the codec chip.
Check your codec chip from the codec proc file (see "Codec Proc-File"
section below).  It will show the vendor/product name of your codec
chip.  Then, see Documentation/sound/alsa/HD-Audio-Modelstxt file,
the section of HD-audio driver.  You can find a list of codecs
and `model` options belonging to each codec.  For example, for Realtek
ALC262 codec chip, pass `model=ultra` for devices that are compatible
with Samsung Q1 Ultra.

Thus, the first thing you can do for any brand-new, unsupported and
non-working HD-audio hardware is to check HD-audio codec and several
{'fraction_non_alphanumeric': 0.09224754108375588, 'fraction_numerical': 0.006231290854664304, 'mean_word_length': 3.4556341861731084, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2999338', 'n_tokens_mistral': 4297, 'n_tokens_neox': 4022, 'n_words': 2434}