ASoC: msm8960: Fix mbhc multi button detection

If mic bias voltage is higher than vddio voltage, scale up the measured
voltage when a button is pressed during playback in order to use ACDB
button voltage range.
Default mic bias of mbhc voltage has changed from 1.8v to 2.7v,
so fix default values with re-calibrated ones based on 2.7v mic bias
voltage.

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

Conflicts:

	sound/soc/msm/msm8960.c
ASoC: wcd9310: make HPH status registers as volatile

HPH status registers are read-only registers that can be changed by
hardware.  Make those as volatile so not to cache it.

Change-Id: Iaf894ec2776ad757de147a55695ac04b1ecf4ad5
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>

Conflicts:

	sound/soc/codecs/wcd9310.c
ASoC: wcd9310: Turn off DMIC clk when both DMICs in the pair are off.

Digital Mic inputs on Tabla comes in Pairs. The DMICs in a pair share
same clock. So even if one of the DMIC in pair is powered down clk should
not be turned off if the other DMIC in pair is still active.

CRs-Fixed: 357684
Change-Id: I9ddc9d88cdd8f81e8fa7a9ea7899bc8c324cb94e
Signed-off-by: Kiran Kandi <kkandi@codeaurora.org>
ASoC: wcd9310: Fix audiable click noise with active ANC headset

If mbhc polling is active, enable mbhc path to avoid polling noise.

CRs-fixed: 347090
Change-Id: I3d9d1d6ec64620e24244091d735ef71c605c64fd
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
ASoC: wcd9310/9304: Pull down Mic Bias output by default.

If Mic Bias is high Z by default and when the LDOH is enabled,
the Mic Bias output can pull-up to a non-zero voltage if there
is no loading or if the load leakage is very small.  Pulling
down the Mic Bias output so it is not in high Z to eliminate
the floating voltage.

Change-Id: I38e76a8c03107879727564f177b2713c9dfa4631
CRs-Fixed: 368898
Signed-off-by: Kuirong Wang <kuirongw@codeaurora.org>
ASoC: WCD9310: Reduce the sleep time after lineout PA enable

- Speaker warm-up time is too long(over 100 ms) due to big delay
  (16*2ms for mono and 16*4ms for stereo)after lineout PA enabled.
- Measured by "adb shell dumpsys media.audio_flinger |grep measuredWarmup",
  speaker warm-up time is reduced to ~70-80ms

Signed-off-by: SathishKumar Mani <smani@codeaurora.org>
bug-id: 7022794

Conflicts:

	sound/soc/codecs/wcd9310.c
ASoC: wcd9310: reduce mbhc button release GPIO debounce time.

Current GPIO debounce time is too long so it delays next button
press detection.  Reduce this debounce time so driver can detect
next button press and release quickly.
Typically mic voltage ramps up within few milliseconds after button
release so 50ms is long enough.

Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
(cherry picked from commit db606b0a39452c90e26692c22300c390f5822f29)
(cherry picked from commit 96e92e0a22a0c54f9cfda447d346c1a2dd9f4639)

Change-Id: Ibf0aa4d4c07fab9cd50021cb0e256ee23b320059
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
ASoC: wcd9310: 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.

CRs-fixed: 339620
Signed-off-by: Patrick Lai <plai@codeaurora.org>
(cherry picked from commit c2d833d524c1230c72f2d078b543baba7a8db26f)
(cherry picked from commit 6b8cacf2d5ed669048c3813b56851c10fe5c5af1)

Change-Id: Iea28c8baa1a6372dcb4c0214ec0e74bfc483f563
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
ASoC: wcd9310: Resend edge triggered GPIO IRQ

If MBHC GPIO IRQ for mechanical headset detection asserted while power
management's suspend call chain is being called, wcd9xxx_lock_sleep will
fail to wait for system's resume since power management interface has
to finish suspend in order to resume system.
In this case, interrupt cannot be handled as codec driver cannot
guarantee if underlying bus is awake.
Wake up system and resend the IRQ for this situation.

(cherry picked from commit ecf379cd17b7fe94e6f0df0598a472b6f1828ad5)
(cherry picked from commit bdda99b93915d217150f5484f9c718c905703f1e)
CRs-fixed: 404167
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>

Change-Id: Id5970b359b80e0cd1f701b30c61ade23e0f67b9e
Signed-off-by: Neha Pandey <nehap@codeaurora.org>

Conflicts:

	sound/soc/codecs/wcd9310.c
ASoC: wcd9xxx: Fix the ANC CnP

Add virtual ANC widgets which are used to enable ANC
before PA is turned on, and to disable ANC before TX is
turned off.

CRs-fixed: 387904
Change-Id: I8c2fa670062f1486499c79653a2c223f7daba84f
Signed-off-by: Damir Didjusto <damird@codeaurora.org>

Conflicts:

	sound/soc/codecs/wcd9310.c
ASoC: wcd9xxx: Support earpiece ANC

Added virtual widgets for enabling and disabling earpiece ANC.

Change-Id: Ia235928c34022de89ec0e66dbe533143f4d56684
Signed-off-by: Damir Didjusto <damird@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:

	sound/soc/codecs/wcd9310.c
ASoC: wcd9310: Update compander configuration sequence

Update compander configuration sequence for headphone path
to prevent the concurreny of ANC and compander in addition
to bypass the delay buffer for ANC and class G to avoid the
audio delay change between class G enabled and disable modes.

CRs-fixed: 456565
Change-Id: I561cb878906b9e31d8c1b04c145c533090f80f1f
Signed-off-by: Kuirong Wang <kuirongw@codeaurora.org>
ASoC: wcd9310: Update compander gain implementation

When compander is enabled, PA has no impact on the playback
path. In order to keep the output audio level consistently during
compander enabling and disabling so we have to apply the same
gain/attention in PA to digital gain to compensate the PA gain.

CRs-fixed: 456565
Change-Id: Idf760bac35b25aab419a23ce5803c68831850856
Signed-off-by: Kuirong Wang <kuirongw@codeaurora.org>
ASoC: wcd9310: Disable Mic Bias Pull down prior to enable micbias

Pull down Mic Bias and add a delay of 250ms to avoid issue
of something else pulling up the mic voltage other than mbhc
polling prior to enable micbias when recording starts.

CRs-fixed: 431573
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>
(cherry picked from commit 1b9a309c9a58bfd47d0e6dee75cfd6fea12e0760)

Change-Id: I575cc61c1f0d9956958768f8852b87695bb2211c
Signed-off-by: Sivasri Kumar Vanka <sivasri@codeaurora.org>
ASoC: wcd9310: Fix to reduce the delay while recording

The current delay of 250ms is too long and can impact
several usecases which involve TX path. Reduce the delay
to 20ms as it is safe to do so. This delay was added to
ensure low voltage for a while before turning on micbias
for recording. Reason being, few headsets need voltage to
be ramped up from 0V to micbias to enable microphone.

CRs-Fixed: 486830
Change-Id: I6becfde379403115a77492754bae26c2fd1ba9cb
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>
ASoC: wcd9310: Fix DMIC current leakage after disable

Observed after disabling DMIC path, some DMICs observe
power leakage of around 2mA and affecting power numbers.
This happens due to the DMIC clock runs off MCLK. 2 Stage
of Dividers are used to  generate various DMIC Clock Freq.
Since the SW Enable/Disabling is async to MCLK, the Divider
will either hold the last stage 0 or 1.
Manually force the digital mic clock pin to GPIO mode from
functional mode through the TLMM mux option and force the value
of DMIC voltage to 0V. This will avoid any current leakage.

Change-Id: Id2018aee27c4b31b0de8a9094613c1b07fa1112d
CRs-Fixed: 504468
Signed-off-by: Laxminath Kasam <lkasam@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>
mfd: wcd9xxx: Let system suspend and lock it later

When wcd9xxx codec receives IRQ, codec driver acquires suspend lock to
prevent system from entering suspend and waits until either system is
already awake or is awoken.
However if power management interface is already in the middle of calling
suspend chains, codec cannot lock suspend.
For this case, let the power management interface to proceed suspend and
make codec driver not to handle IRQ for now so unhandled IRQ would raise
shortly again.

Change-Id: Ia06394a890fe0c5fbde65d482d584346d167132a
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>

Conflicts:

	drivers/mfd/wcd9xxx-irq.c
Revert "ASoC: WCD9310: Reduce the sleep time after lineout PA enable"

This reverts commit 88ad9154f372d4df776fd6c7eb6e5daedf4e2bdf.