Asoc: msm: 8064: Set channel as Mono for Incall Music Delivery

For incall music delivery, there is only one share channel is
supported between MDM and APQ. If the media is stereo, afe tries to
open two share channels and causes music playback failure.
Add fixup fucntion to always set the channel as 1 whenever the media
is stereo or mono. And make sure only one share channel is opened.

(cherry picked from commit 548741eb8164c54197d2625120481dd1b51242d1)

Change-Id: I3b2b9a4d3be69797fa2e6f3a507cf360dcf1f22c
CRs-Fixed: 398100
Signed-off-by: Helen Zeng <xiaoyunz@codeaurora.org>
Signed-off-by: Jessica Gonzalez <jgaona@codeaurora.org>
asoc: msm: Audio megapatch

 * Bring up to date with CodeAurora reference code for MR2

ASoc: msm: Add amr-wb/wb+ tunnel playback support

Update compress audio platform driver
to support amr-wb/wb+ tunnel mode playback.

Change-Id: I98d087db490441c57c8e2d4fe03a7e91b28e67fc
Signed-off-by: Ajit Khare <ajitk@codeaurora.org>

Conflicts:
	sound/soc/msm/msm-compr-q6.c

ASoC: msm: Register restart api for under run issue.

Update compressed platform driver to register an restart callback.
Implementation of the restart callback is to issue an pending buffer
Written by application to restart the session when  the de queue
Process is stopped due to underrun issue.

Restart callback is triggered from the ALSA core framework when
Framework detects that the render stopped pulling the data
And application is writtig the data.

This callback will be running in atomic context.

Change-Id: Iada382f39bd052beeb0b1d165959d510fa51ff7c
Signed-off-by: Santosh Mardi <gsantosh@codeaurora.org>

Conflicts:
	sound/soc/msm/msm-compr-q6.c

ASoC: msm: Fixes for underrun issue in LPA Playback

Update LPA platform driver to register restart callback.
The implementation of the callback is to issue a pending buffer
written by the application to restart the session when the dequeue
process is stopped due to underrun issue.
The callback is triggered from ALSA core when the framework
detects that the renderer stopped pulling data but the application
is still writing data. It runs in atomic context.

Fixes:
-A disturbance was heard when switching from one song
to the other, or when the song is paused for greater
than 3 seconds and then resumed
-This was due to the previous value of the track
volume being used in the lpa driver
-This was fixed by setting 0 as the initial volume

Change-Id: I035760937d032038fb3f3383dc87ecbdc5f4700d
Signed-off-by: Subhash Chandra Bose Naripeddy <snariped@codeaurora.org>

ASoC : msm: HDMI 5.1 LPCM playback support.

Support 6 channels configuration in HDMI driver
and the ALSA framework to play 5.1 LPCM format

CRs-Fixed: 370096
Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>
(cherry picked from commit fc3b780b571b62f302fe38c9faaa58508ad5464f)
(cherry picked from commit 7fd4b7af623ac3dfef0b23d4e68758b1a65941d6)

Change-Id: I091cd3187e9c68eb2589c9b3412b1d8a7bb59164
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:
	sound/soc/msm/msm-compr-q6.c

ASoC: msm: proper error code for drain ioctl

If a drain ioctl on a compressed driver has been interrupted
by a reset ioctl, we need to return a proper error code for the
drain ioctl

Change-Id: I15f42a22b1cc13b3a0e2ae873adfcd1db2ac1e53
Signed-off-by: Haynes Mathew George <hgeorge@codeaurora.org>
CRs-Fixed: 445370

Conflicts:
	sound/soc/msm/msm-compr-q6.c
	sound/soc/msm/msm-pcm-q6.h

ASoC: msm: Allow drain only if a write was called

For compressed drivers, allow the drain ioctl only if
there are pending writes. Return a proper error (-EWOULDBLOCK) otherwise.

Change-Id: I4799351a8930c44d88d6968802df98896fc1531a
Signed-off-by: Haynes Mathew George <hgeorge@codeaurora.org>
CRs-Fixed: 445370

Conflicts:
	sound/soc/msm/msm-compr-q6.c

ASoC: msm: Resume writes only for start command

For compressed and LPA drivers, set pending_buffers flag to 1 only if the client
issues a trigger_start command, not a pause_release command. This flag
is used to initiate writes to the dsp.

Change-Id: I503156863646210b460613a0b9a26a6bfb8854ed
CRs-Fixed: 442269, 449126
Signed-off-by: Haynes Mathew George <hgeorge@codeaurora.org>

ASoC: msm: skip sending volume in compressed pass through playback

For the playback use of compressed pass through on HDMI device,
post processing features are not supported and should not be sent to
DSP. Hence the change is now to send the volume only for the playback
of decode and render in DSP and skip for compressed pass through

CRs-Fixed: 442140
Change-Id: I2125f08baf1676f6bb1d13463a1f01dfe280963f
Signed-off-by: Subhash Chandra Bose Naripeddy <snariped@codeaurora.org>

ASoC: msm: avoid negative time stamp check

Time stamp is unsigned. There is no need to check for
negative value.

Change-Id: I15e380f81e46908f6a9fe8d29c174de1b7c33173
CRs-fixed: 423372
Signed-off-by: Patrick Lai <plai@codeaurora.org>

ASoC: msm: Fix for improper volume ramp up in tunnel playback

A disturbance is heard when resuming the playback after
switching from headset to speaker and back to headset with the
music paused for more than 3 sec. This is due to, data getting
rendered with the speaker volume where it had to played with headset
volume. Fix is to set the '0' as the initial volume.

Change-Id: Ie4726a7898620fb912279270e24fa15a45a437f9
CRs-fixed: 453704
Signed-off-by: Amal Paul <amal@codeaurora.org>

ASoc: msm: update the pending buffer flags in underrun

Update the pending buffer flag on a driver underrun.
This causes a drain call to be rejected if the underrun
happens immediately after an EOS buffer has been given to the DSP
following a flush

CRs-Fixed: 463332
Change-Id: I2ba224a49e5af14ca909300afc0788cb4b21eb16
Signed-off-by: Subhash Chandra Bose Naripeddy <snariped@codeaurora.org>

ASoC: msm: Add support for meta data in compressed TX

There is a usecase where compressed data is sent over HDMI IN to
ADSP. The format of compressed is detected in ADSP and sent through
the meta data to compressed driver. Add support for meta data in
compressed TX for this use case.

Change-Id: Idbb18fe4a0ad828e9c2e9d7beec048b3cedf002d
Signed-off-by: Subhash Chandra Bose Naripeddy <snariped@codeaurora.org>

ASoC: msm: Add AMR-WB tunnel capture support.

Update compress audio platform driver
to support AMR-WB tunnel mode capture.

Signed-off-by: Sachin Shah <sachins@codeaurora.org>
(cherry picked from commit b96124a67cebcbe91e13f5e4c7f2bb9bcb2bb15f)

Change-Id: I9805d606c634cb8e3b7b24f35a796a6d82a611eb

ASoC: msm: implement drain command in compress platform driver

Currently, at the end of compress audio playback, session is
terminated without ensuring compressed audio stream is completely
rendered. Use ioctl drain to drain out all the data before EOS is
signalled and session is closed. This is to make sure all the
data is played out by DSP.

CRs-Fixed: 390897
Change-Id: I3e39b210a8924180de9eb4453c6f6f6435ded0ee
Signed-off-by: Krishnankutty Kolathappilly <kkolat@codeaurora.org>

ASoC: msm: Add metadata mode changes to LPA driver

Playback hangs for three seconds on seeking to EOS. This is
because the lpa driver works on period size. Partial buffers
are not handled. Add metadata mode changes to LPA Driver to
support partial frames.

CRs-Fixed: 458904
Change-Id: Ieb89b59dbca4b40ec0915a286d53c4617c23c471
Signed-off-by: Krishnankutty Kolathappilly <kkolat@codeaurora.org>

Asoc: msm: 8064: Set channel as Mono for Incall Music Delivery

For incall music delivery, there is only one share channel is
supported between MDM and APQ. If the media is stereo, afe tries to
open two share channels and causes music playback failure.
Add fixup fucntion to always set the channel as 1 whenever the media
is stereo or mono. And make sure only one share channel is opened.

(cherry picked from commit 548741eb8164c54197d2625120481dd1b51242d1)

Change-Id: I3b2b9a4d3be69797fa2e6f3a507cf360dcf1f22c
CRs-Fixed: 398100
Signed-off-by: Helen Zeng <xiaoyunz@codeaurora.org>
Signed-off-by: Jessica Gonzalez <jgaona@codeaurora.org>

ASoC: msm: Reduce min buffer size for low latency

The current low latency driver has 512 bytes as
the min buffer size threshold. With this reducing
the playback time to lower values is not possible.
Setting it to 128 bytes gives us more room
to try out lower buffer sizes from the user space

Change-Id: I0895b50d4b86324a9e3ecb6bec053839fa7fd7ea
Signed-off-by: Alexy Joseph <alexyj@codeaurora.org>
Signed-off-by: Mekala Natarajan <mekalan@codeaurora.org>

ASoC: msm: Change QOS value for low latency path

There were variations in the time taken to
return from each write. This was due
to the delay in switching in and out of
power collapse. To manage this set QOS
value to 1ms so that the core has enough
time to wake up from power collapse

Signed-off-by: Alexy Joseph <alexyj@codeaurora.org>
Signed-off-by: Mekala Natarajan <mekalan@codeaurora.org>

Revert "ASoC: msm: Decrease the playback period size of PCM driver"

This reverts commit b0580099ac7d5e735fb42946612a499bf196cda1.

Change-Id: I487797334cf75978daa3c536ff92de8a54b1f7fb
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>

ASoC: msm: Flexible period size for pcm playback

PCM driver was configured for fixed buffer
size on the playback path. With this, varying
the buffer sizes on the playback path was not
possible. To fix this, support for flexible
period sizes is added by setting different
values for min and max buffer sizes

Change-Id: I7f69db4940f67e5e3a795101af1b1682afbdb530
Signed-off-by: Alexy Joseph <alexyj@codeaurora.org>
Signed-off-by: Mekala Natarajan <mekalan@codeaurora.org>

msm: soc: Underp merge

Change-Id: I7ab9a6823beee72ffbac25447fdd6dd5dd8f0b91

ASoC: msm: Fix delay in switching from WFD session

- When a running WFD session is paused/disconnected, there is
  a delay of about 10-15 seconds in switching audio from WFD
  sink to target.
- pcm_write is blocked because pausing/disconnecting the WFD
  session closes the backend DAI before a new link is established.
- Avoid closing afe if front end PCM session is still active.

CRs-Fixed: 444163
CRs-Fixed: 425512
Change-Id: I1ad6de1e201aa6130c397007219c0d370c7be2a1
Signed-off-by: Satya Krishna Pindiproli <satyak@codeaurora.org>

ASoC: msm: Fix for proxy port open failure in WFD session

When playback is paused and proxy device disabled, afe is
not closed. This results in failure of proxy port open in the second
iteration. Fix the same by closing and opening the proxy.

Change-Id: Idfa94e5756d87e59dc0101fd688d6accfe6287e7
CRs-Fixed: 447001
CRs-Fixed: 446504
Signed-off-by: Satya Krishna Pindiproli <satyak@codeaurora.org>

ASoC: msm: qdsp6: check for invalid port index

Function which converts port ID to port index can return
error value if port ID is invalid. Caller should not
blindly use return value without checking

Change-Id: I02b8112b6714e3364758907e7078bcbb88d45b6b
Signed-off-by: Patrick Lai <plai@codeaurora.org>

ASoC: msm: qdsp6: avoid unnecessary check

Remove unnecessary check as it should be reasonable
to assume valid parameter would be issued through
debugfs interface

Change-Id: I1a23d8c5324b813bf9501c5462684234926b5dcc
Signed-off-by: Patrick Lai <plai@codeaurora.org>

ASoC: msm: qdsp6: add check for maximum COPPs allowed

There is maximum number of COPPs ASM session can be routed
to even though there are far more number of AFE ports.
Add the check to make sure caller is not routing to more
than ADM can actually support.

Change-Id: Iee97dd7e5d21820c87244a422fa252c2228185f9
Signed-off-by: Patrick Lai <plai@codeaurora.org>

ASoC: msm: qdsp6: Add support to configure ISO and ARIB coefficients

Add support for configuring ISO or ARIB stereo mixing
coefficients. This change introduces a function with whichi,
AAC multi-channel driver can configure ISO or ARIB coefficients
according to configuration done by the client.

Change-Id: I72b74033532a276fa3bc1d305a04720ff6767409
Signed-off-by: Amal Paul <amal@codeaurora.org>

ASoC: msm: qdsp6: Check copp_id's array index

Validate the AFE port index before using it as copp_id's
array index.

Change-Id: I16112d03779980ce787ea78b589b34b5fd59ab36
Signed-off-by: Jay Wang <jaywang@codeaurora.org>

ASoC: audio: Fix MEM_UNMAP called before CLOSE ack

-When the commands for ASM_STREAM_CMD_SET_PP_PARAMS
and ASM_STREAM_CMD_CLOSE are sent back to back, Ack
for first command is misinterpreted as CMD_CLOSE ack
and proceeds to send memory unmap command resulting
in LPASS fatal.
-Maintain separate variable to wait on for CMD_CLOSE
that will avoid dependency to other commands getting
Ack early.

CRs-Fixed: 434279
Change-Id: I7b6b7f1b8154437b21c5ea14be2e774e4b96e2d1
Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>

Asoc: msm: Set the right topology during in call voice recording

Obsereved silence in incall voice recording with dual mic, when fluence is
enabled.Fluence topology is applied even on audio recording path.Default topology
is set for incall voice recording.

CRs-Fixed: 454359
Change-Id: I9d34f00e424355fdc183ce1a5769c4083b6ae6a7
Signed-off-by: Sidipotu Ashok <sashok@codeaurora.org>

ASoC: msm: qdsp6: Fix for EVRC-B/WB vocoder rate

Rate set in userspace for EVRC-B/WB vocoders are not
propagated to DSP. Fix the issue by sending rate command to DSP

Change-Id: I478f4afafac25dcb4b23964db24598205f9bcc05
Signed-off-by: Vidyakumar Athota <vathota@codeaurora.org>
CRs-Fixed: 488084

ASoC: msm: qdsp6: Add error check for memory commands

- Write failures observed during audio playback.
- Error checks are missing for memory map and memory unmap cmds,
  we are proceeding to write data even if memory map is failed. Due
  to this pcm_out_write failures are observed.
- Add proper error handling for memory map and unmap cmds.

CRs-Fixed: 485051
Change-Id: Iedd369fcd655b02a213277e973059612c040fe34
Signed-off-by: Deepa Madiregama <dmadireg@codeaurora.org>

ASoC: msm: Reset the calibration block after subsystem restart.

    - After sub system restart ACDB cannot push data to Q6
    - Memory map is not happening after sub system restart, because
      the calibration block address is same as the cached address.
      Without memory map calibration block is sent to DSP, where it is
      failing with memory map error.
    - Reset the calibration block after sub system restart, so that
      memory map happens after sub system restart.

CRs-Fixed: 389214
Signed-off-by: Deepa Madiregama <dmadireg@codeaurora.org>
(cherry picked from commit b71818e0ee674b2357d419c6559b5aa009d96a14)
(cherry picked from commit 9bf11c66fb6ec7c39b7cef010b7db99a79ebb6a4)

Change-Id: I9ac78f92afae6711b6eb9604c54db6303199a910
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

ASoC: msm: Add 8-channel L-PCM TX support

There is use case that the HDMI input goes through MI2S TX
interface to ADSP. Add 8-channel L-PCM TX support for this
use case.

Change-Id: Iaf10ec357a25fe4cf80e36a2ceba3d113e9b0416
Signed-off-by: Subhash Chandra Bose Naripeddy <snariped@codeaurora.org>

Conflicts:
	sound/soc/msm/qdsp6/q6asm.c

msm: audio: qdsp6v2: Add support for VOLTE

Update the number of supported voice networks
in the ACDB driver and change the voice driver
to support concurrent calibration for VOLTE,
VOIP & voice.

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

Conflicts:
	sound/soc/msm/qdsp6/q6voice.c

ASoC: msm: Apply cached volume and mute at call start.

Volume and mute settings before voice call is started are cached
in the driver, apply the cached settings at call start.

Change-Id: Iabc1f47c46a8e986c79106545ac3ee977fbca99c
Signed-off-by: Neema Shetty <nshetty@codeaurora.org>

Conflicts:
	sound/soc/msm/qdsp6/q6voice.c

ASoC:msm: Enabling TTY for VoLTE call

Enabled TTY for VoLTE call. Earlier TTY feature is not
supported for VoLTE call.

Change-Id: If5e3436504f40c3e782bf79a16547be068f6b27e
Signed-off-by: Sidipotu Ashok <sashok@codeaurora.org>

ASOC: qdsp6: Fix for validation of supported bitrates.

This change fixes the validation of supported bitrates for
aac encoder in aac-lc mode.

Change-Id: I7bbcfcc96bcd109f08c7f873f3d9bf74351f91a5
Signed-off-by: Bharath Ramachandramurthy <bramacha@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/qdsp6v2/aac_in.c

qdsp6v2: Remove dead code

Change-Id: I2b8eb312d6a3d5681ceca1b0695a8a2803b0b088

ASoC: core: Update ALSA core  to issue restart in underrun.

When compressed and pcm session is started the buffer pull will
Be from the DSP, in mmap mode for the scenario Hardware pointer
Is same as application pointer implies application has not filled the
Buffer to be send to DSP, and platform driver has to break and restart
The de queue process when the application has sufficient buffers.

When hardware pointer is same as application pointer it is an under run
Scenario where the ALSA framework has to trigger the under run and in HAL
The session has to re-prepare and re-triggered. based on the stop
Threshold, but in our system the stop threshold is INT_MAX which
Indicates that under run is not triggered in practical cases.

We have a brodcast usecase in which the mentioned under run case
Is hit mulitple times, and every time re-prepare and re-trigger will be
Expensive

Update the ASoC core framework to restart de queue process stopped
By platform Driver when the under run is hit, based on the available
Buffer and render flag, so the System will recover from the hang state.

To restart de queue process the ASoC core will be calling the restart
Callback registered by platform driver and this callback will be running in
Atomic context.

Change-Id: Ic9ea05a0dc6246346e9913493232882e2f5447d1
Signed-off-by: Santosh Mardi <gsantosh@codeaurora.org>