Browse Source

asoc: mbhc: fix for fake ins irq

Check for in2p clamp state in insertion irq
and ignore the interrupt if the clamp is already
set, which means the mechanical removal is about
to happen next.

Change-Id: I55691d427cf07d5b61862b6dbd39f3ec34d873e5
Signed-off-by: Karthikeyan Mani <[email protected]>
Karthikeyan Mani 7 years ago
parent
commit
dd50371847
3 changed files with 21 additions and 2 deletions
  1. 17 1
      asoc/codecs/wcd-mbhc-adc.c
  2. 1 0
      asoc/codecs/wcd-mbhc-v2.h
  3. 3 1
      asoc/codecs/wcd934x/wcd934x-mbhc.c

+ 17 - 1
asoc/codecs/wcd-mbhc-adc.c

@@ -1,4 +1,4 @@
-/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -34,6 +34,7 @@
 #define WCD_MBHC_ADC_HS_THRESHOLD_MV    1700
 #define WCD_MBHC_ADC_HPH_THRESHOLD_MV   75
 #define WCD_MBHC_ADC_MICBIAS_MV         1800
+#define WCD_MBHC_FAKE_INS_RETRY         4
 
 static int wcd_mbhc_get_micbias(struct wcd_mbhc *mbhc)
 {
@@ -1021,6 +1022,8 @@ exit:
 static irqreturn_t wcd_mbhc_adc_hs_ins_irq(int irq, void *data)
 {
 	struct wcd_mbhc *mbhc = data;
+	u8 clamp_state = 0;
+	u8 clamp_retry = WCD_MBHC_FAKE_INS_RETRY;
 
 	pr_debug("%s: enter\n", __func__);
 
@@ -1035,6 +1038,19 @@ static irqreturn_t wcd_mbhc_adc_hs_ins_irq(int irq, void *data)
 		return IRQ_HANDLED;
 	}
 
+	do {
+		WCD_MBHC_REG_READ(WCD_MBHC_IN2P_CLAMP_STATE, clamp_state);
+		if (clamp_state) {
+			pr_debug("%s: fake insertion irq, leave\n", __func__);
+			return IRQ_HANDLED;
+		}
+		/*
+		 * check clamp for 120ms but at 30ms chunks to leave
+		 * room for other interrupts to be processed
+		 */
+		usleep_range(30000, 30100);
+	} while (--clamp_retry);
+
 	WCD_MBHC_RSC_LOCK(mbhc);
 	/*
 	 * If current plug is headphone then there is no chance to

+ 1 - 0
asoc/codecs/wcd-mbhc-v2.h

@@ -189,6 +189,7 @@ enum wcd_mbhc_register_function {
 	WCD_MBHC_BTN_DBNC,
 	WCD_MBHC_HS_VREF,
 	WCD_MBHC_HS_COMP_RESULT,
+	WCD_MBHC_IN2P_CLAMP_STATE,
 	WCD_MBHC_MIC_SCHMT_RESULT,
 	WCD_MBHC_HPHL_SCHMT_RESULT,
 	WCD_MBHC_HPHR_SCHMT_RESULT,

+ 3 - 1
asoc/codecs/wcd934x/wcd934x-mbhc.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -86,6 +86,8 @@ static struct wcd_mbhc_register
 			  WCD934X_MBHC_NEW_CTL_2, 0x03, 0, 0),
 	WCD_MBHC_REGISTER("WCD_MBHC_HS_COMP_RESULT",
 			  WCD934X_ANA_MBHC_RESULT_3, 0x08, 3, 0),
+	WCD_MBHC_REGISTER("WCD_MBHC_IN2P_CLAMP_STATE",
+			  WCD934X_ANA_MBHC_RESULT_3, 0x10, 4, 0),
 	WCD_MBHC_REGISTER("WCD_MBHC_MIC_SCHMT_RESULT",
 			  WCD934X_ANA_MBHC_RESULT_3, 0x20, 5, 0),
 	WCD_MBHC_REGISTER("WCD_MBHC_HPHL_SCHMT_RESULT",