ASoC: wcd9xxx: Bringup headset detection on msm8x10 codec

Changes to enable headset detection and plug type determination
for msm8x10 codec.

Change-Id: I98a0022a833489440508a0868737871412ecaa25
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
(cherry picked from commit df3d50d1979becf1028db42b9cdc7c4403e3a7d4)
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: improve mbhc button detection performance

Update mbhc ground voltage calibration selectively to be able to
accomplish accurate voltage measurement without compromising of measurement
latency.
Revise false button detection logic for different codecs to perform
false button checking for same amount of time.

CRs-fixed: 532971
Change-Id: Id5cb46336a83053ee9135461070ccb5ee58d6d90
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: don't release mbhc firmware while it's still in use

When mbhc is de-initialized, driver shouldn't presume it's end of its
life as software reset might be happening so mbhc firmware should be
retained.  Move mbhc firmware release to mbhc exit function in order to
prevent improper firmware release.

CRs-fixed: 532512
Change-Id: I09b800a76d0502efae153cba9f2b0cc8365f8dce
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: recalibrate DCE reference voltages

Recalibrate DCE reference voltages before starting MBHC insertion detection
to revise possible initial calibration error.

CRs-fixed: 537456
Change-Id: I8128edc0fd79e6c86269c48dc648d2d8f262ab81
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Apply class H parameters based on impedance

Different headphones have different impedance that results in volume level
difference on ears as lower impedance headphone will have higher
volume with the same gain on PAs.
To get better output on headset configure class H controller
based on the impedance detected.

Change-Id: Ia4d62120e57122a52ec0030f7e883cbeb284631b
Signed-off-by: Santosh Mardi <gsantosh@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Add support to compute hph L & R impedance

Add support to compute impedance of the headphone left
and right on Tapan codec. This can be used to adjust gain
according to the value of impedance so that user can have
consistent volume level with different headphones.

Change-Id: Id187bbfaf20c428d367bffa77538182554917e09
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: check NULL for mbhc->resmgr->reg_addr

Check the mbhc->resmgr->reg_addr before getting the
mbhc->resmgr->reg_addr->micb_4_mbhc to avoid
 the null pointer crash

Change-Id: I8a6d8bda90a30782e68760b94cc52cd6ddd52af6
Signed-off-by: Meng Wang <mwang@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Enable MBHC TxFE when micbias is enabled

When micbias is turned ON for audio recording with headset
plugged in, there can be possible noise on the recorded
data due to micbias polling for button detection. To
avoid the noise on audio recording, it is required to
enable the MBHC TxFE (Front-End). Add support to enable
MBHC TxFE when micbias is being enabled for audio recording.

CRs-fixed: 522829
Change-Id: I0689982edab9204aa4f833e59f979f38d6d34418
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Enable voltage source for micbias for headset detection

Micbias on some codecs can be sourced from external voltage source.
In order to enable micbias for MBHC calibration, headset type detection,
etc, it is required to enable external voltage source for such codecs to
avoid incorrect headset type detection. Add callback per codec to enable
external voltage source if such a source is present for the codec power
rail.

CRs-fixed: 535909
Change-Id: I91995655b8ad8f36fccd34223d1d8a6e9a413fd7
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: WCD9XXX: Add configurable micbias option for headset detection

Micbias is required to perform plug type detection on 3.5mm headset
jack. Some platforms can have the microphone pulled up to micbias using
external on-board pull up resistor or using the pull up resistor
internal to the codec. Add support for headset detection logic to
support configurable option for internal or external micbias.

CRs-fixed: 539445
Change-Id: I9438812f0a924c22932dacc56181cf997625e056
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Add codec specific settings to switch micbias to vddio

Micbias to the codec is sourced from LDO (either internal or external to
the codec). Micbias can also be enabled by switching the micbias to
vddio rail in the codec. The register settings changes between codecs.
Add capability to perform this setting specific to codec.

CRs-fixed: 539445
Change-Id: Ie55784ea990df5eba6ca35a97b431bbf93f0c945
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Fix detection issue for headsets with threshold on MIC

Add additional check to see whether micbias is enabled
during DCE measurements and if it is enabled update the
condition so that plug type cannot be wrongly classified
as invalid plug type.

Change-Id: Id758e1bc553e1e6dbc81721f00f9c147b11cf390
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Add support to enable or disable impedance detection

Add support to enable or disable impedance detection
using kernel module parameter. This gives flexibility
for the user to enable or disable this feature.

Change-Id: Ide1d223db256516400e138bf3d7e509a0a2242b9
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Fix crash when enable mbhc driver logs

Fix crash by avoiding NULL pointer access when mbhc driver
logs are enabled.

Change-Id: I6575a215b035bafb3fe85d5fc3ff72f985fe7a25
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Setup internal micbias for headset detection

If recording is also using internal micbias, then after recording
ends, the dapm widget power down callback will reset the state of
internal micbias in codec register. To avoid such issues make sure
internal micbias is setup whenever detection occurs.

CRs-Fixed: 551575
Change-Id: I92ec4f622677fd9f57e75c64617f13f3cb741442
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Avoid plug type re-determination

In the case where there is mechanical interrupt
at the same time when polling scheduled for execution,
we should make sure that if plug type is found and reported
by the polling, re-determination from the insertion irq
should be avoided. Add a check in the insertion irq before
proceeding further to determine the plug type.

Change-Id: I0da017073700d3a362b6175f1292d603885b7ab1
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Correct clk and Bandgap handling

Enable/disable of RC oscillator and Bandgap are not
handled properly due to this RC Oscillator is left high even
after removing headset.So handle clk and bandgap appropriatley.

Change-Id: I165bdea80647868b4beb8d9dcc876dfd76e6d1be
Signed-off-by: Yeleswarapu, Nagaradhesh <nagaradh@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Refactor interrupt mapping per codec

Different codecs can have different interrupt mappings. In order for the
common drivers to be able to request/free the codec interrupts, refactor
out the codec interrupt mapping from the common drivers to individual
codec drivers.

CRs-fixed: 552734
Change-Id: I13c7500f0e3af0f06754b58e433ebed6f0da8274
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Enable MBHC_MUX_MODE when polling is active

MBHC_MUX_MODE is required for Button detection, so do not
disable this bit when polling is still active.

CRs-Fixed: 554884
Change-Id: I9c6e3fe8dd1cc1b1aa15f6c12d139af5f9284296
Signed-off-by: Yeleswarapu, Nagaradhesh <nagaradh@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Reset MBHC registers upon plug removal

Reset MBHC Scaling mux and release detect when mechanical
plug removal is detected. This is to ensure that there is
no micbias voltage present when plug is removed immediately
after insertion.

CRs-fixed: 564412
Change-Id: I1f081e4d9e70ffca4881bce7b5ea681f9546f51c
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>