BACKPORT: ALSA: hda - Change return value for load_dsp_prepare() to -ENOSYS

Signed-off-by: Ian Minett <ian_minett@creativelabs.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit a3af4807fa6766d0772396989cb6bcf93847bc53)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda - print power state for AFG node in proc file

It seems useful, and power states are required for AFG nodes,
so I see no reason not to print it. As a bonus, also print the
AFG nid.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit f4f0a8c4783a0258f2d0020a67fd619ce41a02a3)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda - Allow power_save_controller option override DCAPS

Change the power_save_controller option to bint from bool so that user
can override the runtime PM capability bit and force to enable or
disable the runtime PM.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 6ab317419c62850a71e2adfd1573e5ee87d8774f)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Simplify alc_auto_is_dac_reachable()

Use the helper function snd_hda_get_conn_index() instead of open
codes.  This also improves the detection of some routes to DAC on
ALC260 (although the difference doesn't influence on the end
results of the mapping).

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 6a84c305f03425bab09ffedb71be942ebc22454d)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - List up all available DACs

In the probing phase, create a list of all available DACs in the codec
and use it for checking the single DAC connections.
This list will be used in more other places in the later commits, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 463419de865622e4b13e977e1536375ab897a53f)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Add output path parser

Add the output path parser to Realtek codec driver as we already have
in patch_via.c.  The nid_path struct represents the complete output
path from a DAC to a pin.  The alc_spec contains an array of these
paths, and a new path is added at each time when a new DAC is
assigned.

So far, this path list is used only in limited codes: namely in this
patch, only alc_is_dac_already_used() checks the list instead of dac
arrays in all possible outputs.  In the later development, the path
list will be referred from more places, such as the mixer control
assignment / check, the mute/unmute of active routes, etc.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 30dcd3b40409a4db272998b0cba1b9e80c15b1c8)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Manage mixer controls in out_path list

As we parse the output paths more precisely now, we can use this path
list for parsing the widgets for volume and mute mixer controls.
The spec->vol_ctls[] and sw_ctls[] bitmasks are replaced with the
ctls[] in each output path instance.

Interestingly, this move alone automagically fixes some bugs that the
conflicting volume or mute NIDs weren't properly detected.
Also, by parsing the whole path, there are more chances to get a free
widget for volume/mute controls.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit ba8111276f2cc10b9851613bc8300cabda3c7e0d)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda - Fix mono amp values in proc output

The mono widget is always connected to the left channel, thus the left
channel amp value also should be referred for mono widgets instead of
the right channel.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 2f179721c4a2d1035a93e9c908740d87ac9952e2)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Reduce vol/mute ctl lookups at parsing codec

So far, Realtek codec driver evaluates the NIDs for volume and mute
controls twice, once while parsing the DACs and evaluating the
assignment, and another while creating the mixer elements.  This is
utterly redundant and even fragile, as it's assuming that the ctl
element evaluation is identical between both parsing DACs and creating
mixer elements.

This patch simplifies the code flow by doing the volume / mute
controls evaluation only once while parsing the DACs.  The patch ended
up in larger changes than expected because of some cleanups became
mandatory.

As a gratis bonus, this patch also fixes some cases where the stereo
channels are used wrongly for mono amps.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 792cf2fa2ea926c0c07277c0b67ab60745e8f898)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Simplify the output volume initialization

Simplify the output path initialization using the existing path
information instead of assuming the topology specific to Realtek
codecs.  This is also implicitly a fix for some amp values on output
pins where the old parser missed (e.g. ALC260 output pins).

The same function alc_auto_set_output_and_unmute() can be used now for
the multi-io activation, since the output selection means nothing but
activating the given output path.

And, finally at this stage, we can get rid of alc_go_down_to_selector()
and other functions that are codec really specifically to Realtek
codecs.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 78e635c93b0e385dc23d18c2a4047fc8857467bd)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Make path->idx[] and path->multi[] consistent

So far, idx[i] and multi[i] indicate the attribute of the widget
path[i - 1].  This was just for simplifying the code in
__parse_output_path(), but this is rather confusing for later use.
It's more natural if both idx[i] and multi[i] point to the same widget
of path[i].  This patch changes to that way.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 95e960cece76cb538fcac03ac80893db0f1e6a15)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Parse input paths

Just like the output paths, parse the whole paths for inputs as well
and store in a path list.  For that purpose, rewrite the output parser
code to be generically usable.

The input path list is not referred at all in this patch.  It'll be
used to replace the fixed adc/capsrc array in later patches for more
flexible input path selections.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 36f0fd540e299c7746601ce7bff7d062a6757c2f)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Parse analog loopback paths more generically

Improve the parser of analog loopback paths and handle in a more
generic way.  The following changes are included in this patch:

- Instead of assuming direct connections between pins and
  the mixer widget, track the whole path between them.  This fixes
  some missing connections like ALC660.

- Introduce the path list for loopback paths like input and output
  path lists.  Currently it's not used for any real purposes, yet.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit c2fd19c2fc3cc5e609c573f3c66711fd809f9d3c)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Check amp capabilities of aa-mixer widget

For handling the analog-loopback paths more generically, check the amp
capabilities of the aa-mixer widget, and create only the appropriate
mixer elements.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit bd32f782b956e6a3040696899a818387ecbe17bc)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Fix initialization of input amps in output paths

When initializing the output paths, we assumed the input amps have
almost two inputs blindly.  It's not only generic but even incorrect
for some codecs like ALC268 & co.  Also, the same assumption (two
sources) exists for the bind input-amp controls.

This patch changes the codes in these places to handle the input
connections in a more generic way.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 9366ede7fd2c3ac7ed3a79c5d7c5ee4ad97043b8)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda - Remove snd_hda_codec_amp_update() call from patch_*.c

It's used only in one place in patch_analog.c, and it can be replaced
with others better.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 8092e6065435d75a68873fa66cd003a1b829e0fe)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda - Introduce cache & flush cmd / amp writes

For optimizing the verb executions, a new mechanism to cache the verbs
and amp update commands is introduced.  With the new "write to cache
and flush" way, you can reduce the same verbs that have been written
multiple times.

When codec->cached_write flag is set, the further
snd_hda_codec_write_cache() and snd_hda_codec_amp_stereo() calls will
be performed only on the command or amp cache table, but not sent to
the hardware yet.  Once after you call all commands and update amps,
call snd_hda_codec_resume_amp() and snd_hda_codec_resume_cache().
Then all cached writes and amp updates will be written to the
hardware, and the dirty flags are cleared.

In this implementation, the existing cache table is reused, so
actually no big code change is seen here.  Each cache entry has a new
dirty flag now (so the cache key is now reduced to 31bit).

As a good side-effect by this change, snd_hda_codec_resume_*() will no
longer execute verbs that have been already issued during the resume
phase by checking the dirty flags.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit c370dd6e9faae4b2e699a1f210827aceaa0c3399)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda - Introduce snd_hda_codec_amp_init*()

The new function snd_hda_codec_amp_init() (and the stereo variant)
initializes the amp value only once at the first access.  If the amp
was already initialized or updated, this won't do anything more.

It's useful for initializing the input amps that are in the part of
the path but never used.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 280e57d544f5f9f599de8e11aacb7c087da254b8)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Remove non-standard automute mode

We are using only AUTOMUTE_MODE_PIN in patch_realtek.c and all others
have been already dropped.  Let's remove the old superfluous codes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit b8a47c79b28c34652acf9594ef48b0c9fc875401)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.
BACKPORT: ALSA: hda/realtek - Add path active flag

... and rewrite the initialization of output paths as a generic
function that is applicable for both i/o directions.

The new flag, active, is introduced to each nid_path entry.  This
indicates whether the given path is active, and it's used for checking
whether a certain widget can be turned off or changed when a path is
no longer used or newly enabled.

It's still used only in the output paths.  More wider adaption for
input and loopback paths will be achieved in the later patch.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
(cherry picked from commit 130e5f0642de99a61f46c4f0468bfc5db6030967)

BUG=chrome-os-partner:19100
TEST=Verified the working of HDMI audio with both stereo and headset by building
     the ChromeOS image along with entire 3.9 HDMI driver patches and four
     additional patches from drm/i915.