ALSA: pcm: Zero-clear reserved fields of PCM status ioctl in compat mode

In compat mode, we copy each field of snd_pcm_status struct but don't
touch the reserved fields, and this leaves uninitialized values
there.  Meanwhile the native ioctl does zero-clear the whole
structure, so we should follow the same rule in compat mode, too.

Reported-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: hda - Add workaround for CMI8888 snoop behavior

CMI8888 shows the stuttering playback when the snooping is disabled
on the audio buffer.  Meanwhile, we've got reports that CORB/RIRB
doesn't work in the snooped mode.  So, as a compromise, disable the
snoop only for CORB/RIRB and enable the snoop for the stream buffers.

The resultant patch became a bit ugly, unfortunately, but we still can
live with it.

Reported-and-tested-by: Geoffrey McRae <geoff@spacevs.com>
Cc: <stable@vger.kernel.org> # 3.17+
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: hda - Add ultra dock support for Thinkpad X240.

Adding ultra doch support for Lenovo Thinkpad X240 (17aa:2214).
[Actually replaced the entry with ALC292_FIXUP_TPT440_DOCK -- tiwai]

Signed-off-by: Lukas Bossard <mr.bobukas@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: hda - Set GPIO 4 low for a few HP machines

These HP machines needs GPIO 4 low to enable the headphone amplifier.
In addition, we still need to control LEDs via vref and GPIO.

Cc: stable@vger.kernel.org
BugLink: https://bugs.launchpad.net/bugs/1387128
Tested-by: TienFu Chen <tienfu.chen@canonical.com>
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: hda - change three SSID quirks to one pin quirk

These three HP machines all have the same pin config, so we can
change it to a pin quirk.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: hda/realtek - Update Initial AMP for EAPD control

The default EAPD control uses verb command to control EAPD. Some codec
does not have verb command for EAPD. It needs to control by hidden
register.

This update will avoid wrong behavior for some codec.  This patch will
fix double setup for EAPD.  It just needs to turn on by one site for
verb command or hidden register controlled.

Detailed changes:
- alc889_coef_init() is replaced with alc_update_coef_idx() with a
  correct COEF value.
- for ALC262, ALC887 and ALC900, the EAPD setup via the hidden
  register is removed because this rather conflicts with the EAPD verb
  setup.
-  For ALC888-VC, also the hidden register access is removed in
  alc888_coef_init().
- Remove the dead #if 0 code for ALC267/ALC268.

Signed-off-by: Kailang Yang <kailang@realtek.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: pcm: Simplify snd_pcm_action_lock_irq()

The function snd_pcm_action_lock_irq() can be much simplified by
simply wrapping snd_pcm_action() with the stream lock.  This was
rather the original idea, but later it was open coded for
optimization.  However, looking at the optimization part closely, one
notices that the probability of the optimized path is quite low; in
normal situations, the linked stream action happens only for the
triggered substream, thus the operation becomes identical.  So the
code simplification has a clear win, especially because we have now
doubly codes for both atomic and non-atomic locks.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: pcm: Refactoring snd_pcm_action()

Just a small code refactoring to reduce more lines.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: echoaudio: add reference of struct echoaudio

added reference of struct echoaudio to free_firmware function.
this structure will be later used to get a reference of the card
when converting snd_printk to dev_* in the next patch of the series.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: echoaudio: remove all snd_printk

removed all references of snd_printk with the standard dev_* macro.

[a few places degraded to dev_dbg(), too -- tiwai]

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: emu10k1: Deletion of unnecessary checks before three function calls

The functions kfree(), release_firmware() and snd_util_memhdr_free() test
whether their argument is NULL and then return immediately. Thus the test
around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: es18xx: Add GPO controls

Add GPO0 and GPO1 (General Purpose Outputs) controls to mixer.
These can be used on some cards to control amplifier mute (seen in ES1868
datasheet) or additional onboard chips such as QX2130 QXpander processor.

These GPOs are present on ES1868, ES1869, ES1887 and ES1888 chips.

Tested on ES1868 with QX2130.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: pcm: Correct PCM BUG error message

While converting to dev_*(), the message showing the invalid PCM
position was wrongly tagged as if an XRUN although it's actually a
BUG.  This patch corrects the message again.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: pcm: Replace PCM hwptr tracking with tracepoints

ALSA PCM core has a mechanism tracking the PCM hwptr updates for
analyzing XRUNs.  But its log is limited (up to 10) and its log output
is a kernel message, which is hard to handle.

In this patch, the hwptr logging is moved to the tracing
infrastructure instead of its own.  Not only the hwptr updates but
also XRUN and hwptr errors are recorded on the trace log, so that user
can see such events at the exact timing.

The new "snd_pcm" entry will appear in the tracing events:
  # ls -F /sys/kernel/debug/tracing/events/snd_pcm
  enable  filter  hw_ptr_error/  hwptr/  xrun/

The hwptr is for the regular hwptr update events.  An event trace
looks like:

  aplay-26187 [004] d..3  4012.834761: hwptr: pcmC0D0p/sub0: POS: pos=488, old=0, base=0, period=1024, buf=16384

"POS" shows the hwptr update by the explicit position update call and
"IRQ" means the hwptr update by the interrupt,
i.e. snd_pcm_period_elapsed() call.  The "pos" is the passed
ring-buffer offset by the caller, "old" is the previous hwptr, "base"
is the hwptr base position, "period" and "buf" are period- and
buffer-size of the target PCM substream.
(Note that the hwptr position displayed here isn't the ring-buffer
 offset.  It increments up to the PCM position boundary.)

The XRUN event appears similarly, but without "pos" field.
The hwptr error events appear with the PCM identifier and its reason
string, such as "Lost interrupt?".

The XRUN and hwptr error reports on kernel message are still left, can
be turned on/off via xrun_debug proc like before.  But the bit 3, 4, 5
and 6 bits of xrun_debug proc are dropped by this patch.  Also, along
with the change, the message strings have been reformatted to be a bit
more consistent.

Last but not least, the hwptr reporting is enabled only when
CONFIG_SND_PCM_XRUN_DEBUG is set.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: pcm: Add xrun_injection proc entry

This patch adds a new proc entry for PCM substreams to inject an
XRUN.  When a PCM substream is running and any value is written to its
xrun_injection proc file, the driver triggers XRUN.  This is a useful
feature for debugging XRUN and error handling code paths.

Note that this entry is enabled only when CONFIG_SND_PCM_XRUN_DEBUG is
set.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: usb-audio: Flatten probe and disconnect functions

The usb-audio probe and disconnect functions have been split just for
adapting the (new!) API at 2.5 kernel time.  We left them until now,
partly because we wanted to build with the pretty old kernels in the
external alsa-driver tree.  But the support of such old kernels has
been longly stopped, so it's good time to clean up this mess.

One good point by this cleanup is that now the probe function returns
a proper error code instead of only -EIO.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: usb-audio: Pass direct struct pointer instead of list_head

Some functions in mixer.c and endpoint.c receive list_head instead of
the object itself.  This is not obvious and rather error-prone.  Let's
pass the proper object directly instead.

The functions in midi.c still receive list_head and this can't be
changed since the object definition isn't exposed to the outside of
midi.c, so left as is.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: usb-audio: Use strim() instead of open code

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ALSA: hda - fix mute led problem for three HP laptops

Without the fix, the mute led can't work on these three machines.

After apply this fix, these three machines will fall back on the led
control quirk as below, and through testing, the mute led works very
well.
PIN_QUIRK(0x10ec0282, 0x103c, "HP", ALC269_FIXUP_HP_LINE1_MIC1_LED,
            ALC282_STANDARD_PINS,
            {0x12, 0x90a60140},
            ...

BugLink: https://bugs.launchpad.net/bugs/1389497
Tested-by: TieFu Chen <tienfu.chen@canonical.com>
Cc: Kailang Yang <kailang@realtek.com>
Cc: stable@vger.kernel.org
Signed-off-by: Hui Wang <hui.wang@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Merge branch 'topic/pcm-locking' into for-next

here is a small series of patches for cleaning up / enhancing the
PCM core stuff.