ASoC: wcd9306: fix the NULL pointer dereference in the tapan codec

During the close of the AFE port the AIF1 PB widget will be closed
which access the core variable.
If the core is not initialized yet it will result in the kernel panic.
Fix by adding the check for the core structure to be initialized.

CRs-Fixed: 635790
Change-Id: Ic057e2eb75b25dbc55aa06cbce2b49aca0b1b25f
Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>
ASoC: wcd9306: Update condition to disable HPH PA after impedance detection

For headsets with threshold on mic, the flag hph_pa_dac_state gets
cleared once they are re-inserted into headphone jack with hph pas
are still ON. This causes impedance detection to disable the PA after
impedance computations. This will result into audio mute. Avoid the
audio mute by updating the condition to disable PAs.

CRs-Fixed: 694315
Change-Id: Ib7ab495485a321333c1b8b211559adc7c164735c
Signed-off-by: Yeleswarapu Nagaradhesh <nagaradh@codeaurora.org>
ASoC: wcd9xxx: Avoid enabling button polling from event notify handler

During insertion, it is possible that recording is already
enabled from handset which will switch to headset. During
POST_MICBIAS_2_ON event, though button polling is not actually
enabled, due to polling_active becomes true, the event
notification handler pauses and re-starts button polling.
This could lead to unknown state for button polling state
machine.

CRs-Fixed: 639116
Change-Id: Ie379e5ff58c2e99f8e21e534cbcdb914bc98b7ec
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
ASoC: wcd9xxx: Synchronize button press with notifiers

Button press handler and event notification handler needs
to be syncronized so that they do not interfere in the
excution leading to incorrect register writes or threshold
updates.

CRs-Fixed: 637805
Change-Id: I51ebf1d546aa59e219ce71517970b35730589b6c
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>
ASoC: wcd9xxx: Clear unsupported jack from hph status

In the case when headphone or headset is removed at the
other end of extension cable, unsupported jack event is
never cleared. Further headset/headphone insertion event
will always have the unsupported jack bit ON in the hph_status.

Change-Id: I5ea046b09cf8db4702c2e6d97fa1c8d23ba2702c
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
ASoC: wcd9xxx: Don't enable micbias if headset is removed

If special headset is removed, the callback to
disable micbias will be called, as micbias is
always on with special headset. Mbhc driver
checks a flag, used to disable/enable micbias
for special headset, to make sure micbias is
not disabled by recording. If this flag is not
updated properly before the callback is called
while the headset is removed, it can cause that
micbias is left enabled.

CRs-Fixed: 687630
Change-Id: Id49a2a0ba43821deef8fc5b6fb904239b2273f69
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>
ASoC: wcd9306: Update DEM-2 mux input based on codec type

Tapan codec has two variants wcd9306 and wcd9302.
WCD9302 codec does not have compander block and hence
the DEM-2 mux input should always be selected to NZ_SHAPER.
Selecting the mux to CLASS_H_BUFFER would cause audio mute
if the CP clock is not enabled, which is the case when RX2
interpolator path is shared for HPHR and LO.

Change-Id: I7ea00a30d0554cc9e012fd0975c9a28e7cdf12f0
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
ASoC: wcd9xxx: Add check for NULL pointer and buffer overflow

Current code has possible scenarios where NULL pointer
could be dereferenced or an out-of-bound index of array
could be accessed. The change checks the pointer for NULL
before they are dereferenced and checks for buffer overflows
to ensure out of bound indexes of arrays are not
accessed.

CRs-Fixed: 628865 628869 628873 628874 628875
Change-Id: I3002d1831eb852445619dabeb0f26285ab420953
Signed-off-by: Aravind Kumar <akumark@codeaurora.org>
ASoC: wcd9xxx: Add check for buffer overflow

Current code does not check if the indexes of array
codec_dai being accessed is within the maximum
number of codec dais for a particular codec. The change
adds this check and ensures that indexes outside the
bounds of array are not accessed.

CRs-Fixed: 628865
Change-Id: Ibf81f91b35e43feddc6b03a1239b4d12e04a95da
Signed-off-by: Aravind Kumar <akumark@codeaurora.org>
ASoC: wcd93xx: Remove delay for Slimbus during SSR recovery

When SLIMBUS data channel is to be torn down, CODEC driver
waits for channel removal interrupt from SLIMBUS slave device
with 1 second timeout as measure to prevent system from lock
down in case channel removal interrupt never arrive due to
known reason. When ADSP SSR happen, SLIMBUS would be reset
hence data channel will be gone inherently. Waiting for 1
second will only prolong SSR recovery latency. Update to
avoid the delay after SSR.

Change-Id: Ic6a94ddd1150ba143f4dd33aac1785d7d2ee7653
CRs-fixed: 653504
Signed-off-by: Kuirong Wang <kuirongw@codeaurora.org>

Conflicts:
	sound/soc/codecs/wcd9306.c
	sound/soc/codecs/wcd9320.c
ASoC: wcd9xxx: Fix RX Ear register gain values

Rx Ear Gain register on WCD9306 supports different gain
values from 6DB to -12DB. It was wrongly configured with
2DB. This change fixes the issue and adds support for
correct gain values for Ear PA Gain.

CRs-Fixed: 520688
Change-Id: I6493cf63a1d36d9c9c0a3086b645b92f8c3de588
Signed-off-by: Venkat Sudhir <vsudhir@codeaurora.org>

Conflicts:
	sound/soc/codecs/wcd9306.c
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
Change-Id: I517a5df98708f7292111e5cf71ffcf6ef8c4b870
Signed-off-by: Sudheer Papothi <spapothi@codeaurora.org>
ASoC: msm: fix the hph and lineout concurrency

There was a noise observed during the concurrency of the
hph and the lineout usecase.
This is due to incorrect register value updates in the concurrencies.
Update the register values as per the hw/sw document.

CRs-Fixed: 684412
Change-Id: Ia3f01aec017499d703acc8e170d4444676e50003
Signed-off-by: Aviral Gupta <aviralg@codeaurora.org>
ASoC: wcd9xxx :Modify detection of Euro Headset

Detect the cable as EU Headset only if below conditions met.
1.Plug types for 1st, 2nd, 4th are consistent and equal to HEADSET.
2.Delta b/w 1st, 2nd, 4th is not more than WCD9XXX_CS_MEAS_DELTA_MAX_MV.
3.Plug type of the 3rd measurement is HEADPHONE.
4.Don't consider the status of HPHL.

Change-Id: Iee5f05a360599295e75496bec87b595709ba5a6c
Signed-off-by: Yeleswarapu, Nagaradhesh <nagaradh@codeaurora.org>

Conflicts:
	sound/soc/codecs/wcd9xxx-mbhc.c
ASoC: wcd9xxx: switch to VDDIO while recording is on TX1

On Tapan, ADC2/3 are same and there is coupling between ADC1
and ADC2 due to this there is polling noise in the recorded
audio when IN1/IN3 path is used for the recording with
headset inserted.Switch to VDDIO to avoid polling noise
to be captured in the recorded audio

CRs-Fixed: 696178
Change-Id: I34e96f31ce9460b77eae7a82803015995cce3641
Signed-off-by: Yeleswarapu Nagaradhesh <nagaradh@codeaurora.org>
ASoC: wcd9xxx: Correct wrong check conditions

1) For targets where micbias is shared, we do not
use vddio to identify special headset. We want
micbias to be enabled always with any headset
inserted for such targets. Currently, if headset is
inserted during recording, we check for this vddio
flag as well. Since, it is null for the above mentioned
targets, we never touch the code to enable micbias
always for any type of headset.

2) Again for the above mentioned targets, if micbias
is enabled by voice call, and we insert the headset.
Now if headset is removed, we try force diable of
micbias. This results in Tx mute. The count to disable
micbias needs to be corrected.

Change-Id: I022a54578c47485ebf7eef27c405e31ea6395ecf
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>