From 94e5c82f6b02a96452051663d1cbe85be363c207 Mon Sep 17 00:00:00 2001 From: Yeleswarapu Nagaradhesh Date: Thu, 20 Oct 2016 10:53:23 +0530 Subject: [PATCH] ASoC: wcd-mbhc: correct detection logic for headphone Report cable as headphone only if there is button 0 press interrupt. Otherwise SW cannot differentiate between normal GND-MIC swap and 3 pole extension cable. CRs-Fixed: 1063474 Change-Id: I63450a94ccbf6c25b935d06dc16b3a26b1d076e3 Signed-off-by: Yeleswarapu Nagaradhesh --- sound/soc/codecs/wcd-mbhc-v2.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/wcd-mbhc-v2.c b/sound/soc/codecs/wcd-mbhc-v2.c index 0549b235fade..e66ab820e653 100644 --- a/sound/soc/codecs/wcd-mbhc-v2.c +++ b/sound/soc/codecs/wcd-mbhc-v2.c @@ -1557,6 +1557,7 @@ static void wcd_mbhc_swch_irq_handler(struct wcd_mbhc *mbhc) if (mbhc->mbhc_cb->enable_mb_source) mbhc->mbhc_cb->enable_mb_source(mbhc, true); mbhc->btn_press_intr = false; + mbhc->is_btn_press = false; wcd_mbhc_detect_plug_type(mbhc); } else if ((mbhc->current_plug != MBHC_PLUG_TYPE_NONE) && !detection_type) { @@ -1574,6 +1575,7 @@ static void wcd_mbhc_swch_irq_handler(struct wcd_mbhc *mbhc) mbhc->mbhc_cb->set_cap_mode(codec, micbias1, false); mbhc->btn_press_intr = false; + mbhc->is_btn_press = false; if (mbhc->current_plug == MBHC_PLUG_TYPE_HEADPHONE) { wcd_mbhc_hs_elec_irq(mbhc, WCD_MBHC_ELEC_HS_REM, false); @@ -1762,6 +1764,7 @@ determine_plug: mic_trigerred = 0; mbhc->is_extn_cable = true; mbhc->btn_press_intr = false; + mbhc->is_btn_press = false; wcd_mbhc_detect_plug_type(mbhc); WCD_MBHC_RSC_UNLOCK(mbhc); pr_debug("%s: leave\n", __func__); @@ -1938,15 +1941,13 @@ static irqreturn_t wcd_mbhc_btn_press_handler(int irq, void *data) pr_debug("%s: enter\n", __func__); complete(&mbhc->btn_press_compl); WCD_MBHC_RSC_LOCK(mbhc); - /* send event to sw intr handler*/ - mbhc->is_btn_press = true; wcd_cancel_btn_work(mbhc); if (wcd_swch_level_remove(mbhc)) { pr_debug("%s: Switch level is low ", __func__); goto done; } - mbhc->btn_press_intr = true; + mbhc->is_btn_press = true; msec_val = jiffies_to_msecs(jiffies - mbhc->jiffies_atreport); pr_debug("%s: msec_val = %ld\n", __func__, msec_val); if (msec_val < MBHC_BUTTON_PRESS_THRESHOLD_MIN) { @@ -1960,12 +1961,15 @@ static irqreturn_t wcd_mbhc_btn_press_handler(int irq, void *data) __func__); goto done; } + mask = wcd_mbhc_get_button_mask(mbhc); + if (mask == SND_JACK_BTN_0) + mbhc->btn_press_intr = true; + if (mbhc->current_plug != MBHC_PLUG_TYPE_HEADSET) { pr_debug("%s: Plug isn't headset, ignore button press\n", __func__); goto done; } - mask = wcd_mbhc_get_button_mask(mbhc); mbhc->buttons_pressed |= mask; mbhc->mbhc_cb->lock_sleep(mbhc, true); if (schedule_delayed_work(&mbhc->mbhc_btn_dwork, @@ -1991,8 +1995,8 @@ static irqreturn_t wcd_mbhc_release_handler(int irq, void *data) goto exit; } - if (mbhc->btn_press_intr) { - mbhc->btn_press_intr = false; + if (mbhc->is_btn_press) { + mbhc->is_btn_press = false; } else { pr_debug("%s: This release is for fake btn press\n", __func__); goto exit;