ASoC: WCD9304: Add the compander support to wcd9304

The compander system is intended to increase the dynamic
range of an input signal. But for the wcd9304 codec,
this feature is to use companding in a novel way in the DAC
converter path to increase the signal noise ratio.
The change is to add the compander support to wcd9304
codec. The dynamic compander enable/disable during stream
playback is not supported.

Change-Id: If912302ee9d48dde1318e894a982cba591908d8f
Signed-off-by: Kuirong Wang <kuirongw@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
ASoC: wcd9304: Wait enough time during mbhc calibration

If mbhc micbias has a capacitor which is large enough to delay micbias
voltage ramp up/down, initial calibration also needs to delay enough time
after changing mux to be able to calibrate ground and micbias voltage
accurately.  Increase delay to 50ms during calibration and improve
calibration accuracy.

CRs-Fixed: 495526
Change-Id: I8bf1297045565740175292a522168131754e7940
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
ASoC: wcd9304: recalibrate microphone ground voltage

Different clock sources can affect mbhc voltage inconsistent measurement
accumulation which consecutively results in inaccurate button detection.
Recalibrate ground voltage on dce handler to enhance mbhc button detection
accuracy.

CRs-Fixed: 495526
Change-Id: I30c548677a85febe644da1dfb4ce1c6622c8a658
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
ASoC: wcd9304: Fix dce and sta wait time

Apply correct dce and sta wait time based on calculation
rather than using default values.

CRs-Fixed: 521904
Change-Id: I15578c8ca5ba606af3d7ded85014c178ffc1effe
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>
ASoC: wcd9304: Enhance OCP reporting logic

CODEC has over current protection(OCP) finite state
machine for both left and right headphone while CODEC
driver tries to delay reporting of OCP event after
CODEC reporting OCP two times. Current CODEC driver
implementation results in unlocking one of headphone
power amplifier when OCP reported on both headphone.
Change the behavior to report OCP event for a give
headphone immediately if OCP already occurs on opposite
headphone.

Change-Id: I49d062f7c7f1a99390e82660c8f3e538a0a3cd56
CRs-fixed: 471963
Signed-off-by: Patrick Lai <plai@codeaurora.org>
ASoC: wcd9xxx: Fix MBHC irq handler deadlock scenario.

There is a chance to encounter deadlock when either electrical mbhc irq
or mechanical mbhc irq releases resource lock to let polling thread finish
its job.  This is due to the possibility of one irq handler can preempt
already running the other type of irq handler.
Introduce a new mutex to avoid this preemption.

CRs-fixed: 428653
Change-Id: Idf24c62224026c9c061de12c31e248c05b47de9d
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>

Conflicts:

	drivers/mfd/wcd9xxx-irq.c

Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
ASoC: msm: Add support for external EC reference point

Add mux to sound card topology with output of mux routed
to CS voice uplink front-end as way to indicate external
EC reference point. Currently, MI2S_TX is the only
AFE input port defined for this MUX.

Change-Id: I0c81c579cc01bf92e743eda0e8dee15be2a8c01f
Signed-off-by: Venkat Sudhir <vsudhir@codeaurora.org>
ASoC: msm: Add support to have FM playback through ASM loopback mode

- Add support to provide PP on FM playback.
- Add PCM platform driver which enables ASM loopback mode
Define MultiMedia6 front-end dai

Change-Id: Ibf9d2645e706f9a3027dd356223a2135224a0337
Signed-off-by: Damir Didjusto <damird@codeaurora.org>
ASoC: msm: Add msm-pcm-loopback device

Add msm-pcm-loopback platform device for FM loopback

Change-Id: Ic86f9d92d75bd7c19e3f2d827a4114f6828a7ce8
Signed-off-by: Damir Didjusto <damird@codeaurora.org>
ASoC: msm: Add MultiMedia6 dai link

Add MultiMedia6 dai link for FM loopback.

Change-Id: I08118c9c5add4dba2aaf4af620058dbc9160696d
Signed-off-by: Damir Didjusto <damird@codeaurora.org>
ASoC: msm: flush if prior and current backends rate not matching

It is found that during device switch from one backend
with one sample rate to another backend with another sample rate,
the command to QDSP6 ADM which maps audio stream session to a
particular backend would not get carried out until pending
data of audio stream session from previous backend is either
read out or flushed. This scenario occurs when application
stops providing more buffers to retrieve captured data.
Remedy is to flush upon detection of rate mismatching

Change-Id: I2c01c036d9bb71f938a6795337f08948bd986553
CRs-fixed: 422205
Signed-off-by: Patrick Lai <plai@codeaurora.org>
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
ASoC: msm: Handle data loss at device switch for FM

- When device switch happens there are underflow errors
in LPASS. And there is some break in audio observed for
around 2 sec.
- To handle this, ASM run command needs to be sent again
to DSP at device switch.

Change-Id: I26135ad9267ec5c018708b780b86b7cb4998aa0a
Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
ASoC: msm: Support independent left-right channel volume control

The current volume sent to DSP is averaged between left and
right channels. As a result with volume level as zero on one
channel and non zero on the other channel results to playback on
both channels. Add support to send left and right volumes to DSP

Change-Id: Icc5f182d138c841607ea356ec37a7f78b4ba770d
CRs-Fixed: 449284
Signed-off-by: Subhash Chandra Bose Naripeddy <snariped@codeaurora.org>
Signed-off-by: Jay Wang <jaywang@codeaurora.org>
ASoC: msm8930: properly protect external mclk control function

Both audio path and MBHC accessory detection logic need master clock
enabled along with bandgap and clock block of CODEC. Clock control
is managed by the machine driver. Calls to clock control function from
audio and MBHC detection paths can be nested. As a result, reference
counter of master clock is incremen/decrement out of order and cause
master clock not enabled when audio path is enabled. Without master clock
CODEC will not consume data and this leads to SLIMBUS overflow error.

CRs-Fixed: 469683
Change-Id: Ib3a55f5d0b36ebe9ba345e7f18162a9314500df2
Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>
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: msm: Fix the register address of TX4 registers

The TX4 register address are not correct and needs to be fixed to
correct offset.

CRS-fixed: 486923
Change-Id: Iacb4a57a8c0a8508a68d057d0d431715e617eba5
Signed-off-by: Asish Bhattacharya <asishb@codeaurora.org>
ASoc: msm: Fix for pcm_read getting struck in alsa core.

Advance hardware pointer by period size even if the packet
coming from qdsp6 is of less size. QDSP6 sometimes
(for rapid device switches) gives packets worth less
than period size and this results in hw_ptr appl_ptr mismatch.

CRs-Fixed: 486276
CRs-Fixed: 488449
Change-Id: I893f9a52e4cd507fd72e4a7aba3c5fa76527d1bf
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: Fix wrong wait_event_timeout timeout checks

wait_event_timeout returns zero when there is a timeout.
Change fixes the condition check to handle timeouts.

Change-Id: I01184cce0c98a82bb205023b07dd4dd2d91b42ad
CRs-Fixed: 487821
Signed-off-by: Asish Bhattacharya <asishb@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
ASoC: msm: Add PCM loopback volume control

Add PCM loopback volume controls.

Change-Id: I4d942c16b524797ca535dd0467a830d19963e967
Signed-off-by: Damir Didjusto <damird@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>