ASoC: msm: Squash upstream changes

ASoC: msm: Fix for USB device switch

Add mutex locks to prevent sending multiple mem map
commands unless the previous one returns, because otherwise
the mem_handle is overwritten.

CRs-fixed: 646752
Signed-off-by: Vicky Sehrawat <vickys@codeaurora.org>

ASoC: msm: propagate the error code from the compr driver

Propagate the error code to the upper layers to avoid the
unwanted sequence of the commands to DSP.

CRs-Fixed: 671241
Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>

ASoC: msm: set the master gain to 0 on DSP while configuring

- Mute media volume and play any music clip then reboot
  the phone. Play music again noise comes. This noise
  is introduced in DSP/LPASS.

- DSP suggestion is to mute master volume gain while
  configuring ASM session to avoid such noise at
  begining of asm playback.

Signed-off-by: Ramjee Singh <ramjee@codeaurora.org>

ASoC: msm: Fix for wma playback after SSR

After SSR apr session doesn't get destroyed as
the callback from apr driver doesn't come.Fix
this by not doing NULL allocation in q6asm callback.

Signed-off-by: Anish Kumar <kanish@codeaurora.org>

ASoC: msm: qdsp6v2: clear old memhandle list when SSR happens

When SSR triggers, ASM gets RESET_EVENT callback.
Clear custom topology related old memhandle list here.
Otherwise for next ASM session opened after SSR,
old memhandle is sent to DSP and result in no audio.
Also, for ASM session while unmap during SSR, APR
command fail is expected, even then go ahead and
clear old mem handles relating to session.
Add changes to clear it from list.

CRs-Fixed: 592823, 589762, 592580, 590719, 589450, 593497
Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>

ASoC: msm: qdsp6v2: Check for null data pointer

Add check for null data pointer in
aprv2_core_fn_q() and log error message if
true.

CRs-Fixed: 575228
Signed-off-by: Kenneth Westfield <kwestfie@codeaurora.org>

ASoC: msm: qdsp6v2: fix possible integer overflow

Check integer overflow before multiplying struct size. If that happens
should return immediately. In addition if param length is greater than
MAX size from spec, better return error.

CRs-fixed: 605273
Signed-off-by: Fred Oh <fred@codeaurora.org>

ASoC: dapm: Unlock mutex in error cases

Dapm functions are not unlocking the mutex when an error
is encountered.This change fixes the mutex unlock issue.

CRs-fixed: 613644
Signed-off-by: Gopikrishnaiah Anandan <agopik@codeaurora.org>
(cherry picked from commit e5d642a37a643bf9ee4606e0a43b6714019fbc4a)

[SCSI] async: introduce 'async_domain' type

This is in preparation for teaching async_synchronize_full() to sync all
pending async work, and not just on the async_running domain.  This
conversion is functionally equivalent, just embedding the existing list
in a new async_domain type.

The .registered attribute is used in a later patch to distinguish
between domains that want to be flushed by async_synchronize_full()
versus those that only expect async_synchronize_{full|cookie}_domain to
be used for flushing.

[jejb: add async.h to scsi_priv.h for struct async_domain]
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: Arjan van de Ven <arjan@linux.intel.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Tested-by: Eldad Zack <eldad@fogrefinery.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>

ASoC: Cold start latency reduction

This patch parallelizes FE (front end) and BE (back end)
when playback/capture path is set up. FE's and BE's which can
be parallelized should be indicated in corresponding machine file.
All the operations can be started asynchronously provided the usecase
supports asynchronous operation.
Parallelizing reduces the startup latency as both FE and BE opeations
run in parallel.

Signed-off-by: Anish Kumar <kanish@codeaurora.org>

Conflicts:
	sound/soc/soc-pcm.c

ASoC: msm8974: Machine driver async ops change

Asoc framework supports parallelization of operations
which reduces the startup latency. Machine driver will
specify which usecases support parallelization. This
change updates the machine driver to enable the parallelization.

Signed-off-by: Anish Kumar <kanish@codeaurora.org>

ASoC: msm: qdsp6v2: move hw_params into prepare

Asoc framework supports parallelization of operations
which reduces the startup latency.
Moving hw_params into prepare further reduces this start
up latency.

Signed-off-by: Anish Kumar <kanish@codeaurora.org>

ASoC: msm: Add MP2 decode support in compress driver

Add MP2 decoder support to ALSA compressed driver. It
allows user-space application to play MP2 audio data through
QDSP6.

Signed-off-by: Dhananjay Kumar <dhakumar@codeaurora.org>

Conflicts:
	sound/soc/msm/qdsp6v2/msm-compress-q6-v2.c

ASoC: msm: Add support for WMA DSP decode

WMA V9 and WMA Pro tunnel-mode supports are added to
compressed driver. It allows user-space application to
decode WMA V9 and WMA Pro audio stream through QDSP6.

Signed-off-by: Manish Dewangan <manish@codeaurora.org>
Signed-off-by: Dhananjay Kumar <dhakumar@codeaurora.org>

Conflicts:
	sound/soc/msm/qdsp6v2/msm-compress-q6-v2.c

ASoC: msm: Fix wma pro block alignment parameter

The current code assigns and sends the wrong block
alignment information to the adsp because of which wma pro
playback fails. The fix assigns the correct block alignment
information for wma pro.

Signed-off-by: Aravind Kumar <akumark@codeaurora.org>

ASoC: qdsp6: Add MP2 decoder format support

New ASM message format is added to support tunnel-mode MP2
decoder through QDSP6.

Signed-off-by: Dhananjay Kumar <dhakumar@codeaurora.org>

ASoC: msm: qdsp6v2: Update pcm media format block to use correct stream id

Repeat mode is not working in pcm offload path. When two streams
are used in a single session pcm format block should be sent
specific to each stream. Data sent on stream 2 is ignored by DSP
because pcm format block is always sent on stream 1. Fix is to
update pcm media format block to use correct stream id before
data is sent to DSP.

CRs-Fixed: 673510
Signed-off-by: Krishnankutty Kolathappilly <kkolat@codeaurora.org>

ASoC: compress: fix the target not going to TCXO shutdown

The error code propagated from the flush cmd in the trigger stop
is causing the error in the state of the soc compress framework.
This hinders in closing the BE connected to the FE.
If the AFE is not closed it prevents the target to go into TCXO
shutdown.
Fixed by removing the error handling of the flush command in the
trigger stop, since failure in flush doesn't signify the
failure in the stop command.

CRs-Fixed: 687111
Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>

Revert "ASoC: compr: Disable soft-pause for compress playback"

This reverts commit ece021021f54cfe776713d1bbaa6340a735b297f.

Signed-off-by: Scott Mertz <smertz@cyngn.com>

ASoC: msm: Complete the wait_event request when SSR is triggered

LPA platform driver should complete the wait_event request when it
knows that SSR(sub system restart) has happened. There is no point
waiting and bailing out after timeout.

CRs-Fixed: 575060
Signed-off-by: Anish Kumar <kanish@codeaurora.org>

ASoC: msm: qdsp6v2: Add support to improve debug logging

Improve debug logs by adding function names. This
change is required to fix rarely reproducible
customer issues.

Signed-off-by: Anish Kumar <kanish@codeaurora.org>

ASoC: msm: qdsp6v2: update platform driver for new SSR design.

Update PCM platform driver to handle the reset events during
SSR and also unblock the write wait according to
the new SSR design.

CRs-Fixed: 661491
Signed-off-by: Santosh Mardi <gsantosh@codeaurora.org>

ASoC: msm: unblock the calls sent to the driver during SSR

Return error code ENETRESET from the platform driver
during the SSR recovery.
This facilitates the client to handle the error code
and take corrective measures rather than being blocked
on the call.

CRs-Fixed: 683288
Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>

ASoC: msm: qdsp6v2: Fix read error using mmap

When capture session is started in mmap mode then
read commands are issued to ADSP after close command
is issued. This causes read failure as ADSP will not
process the successive read commands after issuing
close command. This change prevents issuing read
command to ADSP when capture session is not in running
state.

Crs-Fixed: 518008
Signed-off-by: Venkat Sudhir <vsudhir@codeaurora.org>

ASoC: msm: qdsp6v2: Add mutex to ensure atomicity

Make sure that afe command sent to DSP is atomic in nature
and doesn't get overwritten in concurrent scenarios.

Signed-off-by: Anish Kumar <kanish@codeaurora.org>

asoc: msm8974: Fix compress capture device name

ASoC: compress: propagate the error code from the compress framework

Propagate the error code from the compress framework for the timestamp
query. This error code will be used by the client to handle the
error case scenarios gracefully.

CRs-Fixed: 683288
Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>

ASoC: msm: qdsp6v2: Userspace interaction cleanup

Compress ioctl function transfers data to/from userspace
and additionally implements logic to process ioctl command.
Ioctl function should delegate the processing to internal
functions for support compat mode.
This change moves the processing into internal function.

Signed-off-by: Gopikrishnaiah Anandan <agopik@codeaurora.org>

ASoC: core: Add compat support for compress driver

Change adds compat ioctl for supporting 32 bit userspace
client when kernel is compiled for 64 bit.

Signed-off-by: Gopikrishnaiah Anandan <agopik@codeaurora.org>

asoc: msm8974: Update offload device configuration

 * Actually enable offloading on the extra devices.

ASoC: msm: fix the audio mute issue post SSR

On receiving the RESET_EVENTS the in_count is not incremented
leading to the wait timeout in the capture_copy.
This causes the capture session not to be closed from the client post SSR.
Post SSR, read error causes the state mismatch for the clients
leading to no audio issue.

Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>

ASoC: msm: Check the pointers before memcpy

Check the pointers before memcpy when the application queries
the adsp capability for compressed audio. Invalid pointer
can cause kernel panic when doing memcpy.

CRs-fixed: 665297
Signed-off-by: Kuirong Wang <kuirongw@codeaurora.org>

ASoC: msm: qdsp6v2: add support for device mute

Add support for muting the RX and TX devices without affecting
the voice stream. This feature is added to aid in voice call
quality testing.

CRs-Fixed: 634690
Signed-off-by: Shiv Maliyappanahalli <smaliyap@codeaurora.org>

ASoC: msm: Add support for AAC decode in ADTS format

- Set AAC format based on the format value set in
  compress params
- Default is RAW AAC

Signed-off-by: ApurupaPattapu <apurupa@codeaurora.org>

ASoC: msm: qdsp6v2: Do not free memory that has not been unmapped from DSP

The memory that is not unmapped from DSP should not be used until
DSP clears it. Do not free iom memory if the DSP unmap has
failed.

CRs-fixed: 599780
Signed-off-by: Damir Didjusto <damird@codeaurora.org>

ASoC: msm: qdsp6v2: add check for NULL dereference

The asm loopback driver during close does not check
for NULL before closing the playback and capture
instances.

The change ensures only the valid playback/capture
instances are closed.

CRs-Fixed: 643724
Signed-off-by: Aravind Kumar <akumark@codeaurora.org>

ASoC: msm: fix the target crash due to the NULL pointer dereference

During the close of the FE, the mclk is disabled which accesses the
codec drv data.
In case if the tapan codec was not initialized, then close sequence
will result in the null pointer dereference.
Fix by adding a null check before accessing the codec data structure.

CRs-Fixed: 635065
Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>

ASoC: msm: Use 16K sample rate for RFECNS

To enable record with an RFECNS device use a 16K
sample rate

Signed-off-by: Ben Romberger <bromberg@codeaurora.org>

ASoC: msm: qdsp6v2: Update supported sample rates

Compress driver supports 96Khz and 192Khz sample rates. Change updates
the supported frequencies in the compress driver.

CRs-fixed: 653510
Signed-off-by: Gopikrishnaiah Anandan <agopik@codeaurora.org>

ASoC: msm: qdsp6v2: Add FLAC in compress offload path

Add FLAC format in compress offload driver, and asm
module

Signed-off-by: Apurupa Pattapu <apurupa@codeaurora.org>

ASoC: Fix the sync problem after SSR

After SSR default registers needs to be restored. Then
we need to sync all the registers with cache values. This
fixes the problem where register values got changed
after SSR causing AAC clip playback failure.

CRs-Fixed: 579574
Signed-off-by: Anish Kumar <kanish@codeaurora.org>
Signed-off-by: Fred Oh <fred@codeaurora.org>

ASoC: wcd9320: Add HD2 tuning coefficients for HPH path

Add 2nd Harmonic Distortion (HD2) tuning coefficients
for HPH path. HD2 coefficients get turned ON during HPH
enable and turned OFF during path tear down. Enabling HD2
coefficients would increase the Headphone PA efficiency during
audio playback.

Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>

ASoC: wcd9xxx: Enable headset in high performance

Invoke class AB sequence for headset path dynamically based on
module parameter. Change enables headset path in high performance
mode when module parameter is set to one.

Signed-off-by: Sudheer Papothi <spapothi@codeaurora.org>

ASoC: wcd9xxx: Enable headset in high performance

Invoke class AB mode for headset path when sample rate
is set to 192KHz and bit width is set to 24. Change enables
headset path in Ultra High Quality Audio(UHQA)mode.

Signed-off-by: Sudheer Papothi <spapothi@codeaurora.org>

ASoC: wcd9xxx: Distortion in HPH LO combo device

Follow Class H sequence for headset, lineout and ear concurrency as per
the class H HW design sequence to avoid signal clipping.

CRs-Fixed: 602408,618992
Signed-off-by: Sudheer Papothi <spapothi@codeaurora.org>

ASoC: wcd9xxx: Change in sequence of HPH Rx path

Change HPH Rx path sequence to enable Rx clock and reset Rx interpolator
path before HPH DACs enable to avoid pop during bringup of device path.

CRs-Fixed: 616383
Signed-off-by: Sudheer Papothi <spapothi@codeaurora.org>

ASoC: wcd9320: Change compander parameter for 192Khz playback

Update the meter rate parameter for compander in order to achieve
better performance with Compander support for headphone, lineout
and speaker paths for 192 KHz sampling rate. Update the static gain
offset accordingly depending on the buck voltage requested.

CRs-fixed: 481501
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>

ASoC: msm8974: Set tx bit rate for slim tx params

Set tx bit rate format in slimbus tx hw fixup params.

Change-Id: Ic73d137ce784ab902e4893cc688489ee0fcd8cf3