From ea61ad7739b1446591af699889d26d514b66a49b Mon Sep 17 00:00:00 2001 From: Vlad Karpovich Date: Fri, 13 Jul 2018 15:27:54 -0500 Subject: [PATCH] extcon: madera: Fix MICD polarity check If first MICD key range max is configured too high then impedence will fall into the first MICD range and MICBIAS will not be changed for polarity check. Before skipping the polarity change, make sure the first range max is low enough to put a wrong polarity headset in the second range. Change-Id: I42e56172ec6d49ec66290a8ad1e531014908a8d8 Signed-off-by: Vlad Karpovich Signed-off-by: Ravi Vembu Mot-CRs-Fixed: (CR) Change-Id: Ic8db2e8da71b98b3b1da09d515ad0a25fa08df16 Reviewed-on: https://gerrit.mot.com/1209640 Reviewed-by: Rav(CR) Vembu SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Submit-Approved: Jira Key --- drivers/extcon/extcon-madera.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/extcon/extcon-madera.c b/drivers/extcon/extcon-madera.c index f123c4bda479..545e169594a7 100644 --- a/drivers/extcon/extcon-madera.c +++ b/drivers/extcon/extcon-madera.c @@ -44,6 +44,8 @@ #define MADERA_MICD_CLAMP_MODE_JD1L_JD2H 0x9 #define MADERA_MICD_CLAMP_MODE_JD1H_JD2H 0xb +#define MADERA_MICD_WRONG_POLARITY 30 + #define MADERA_HPDET_MAX_OHM 10000 #define MADERA_HPDET_MAX_HOHM (MADERA_HPDET_MAX_OHM * 100) #define MADERA_HP_SHORT_IMPEDANCE_MIN 4 @@ -1899,7 +1901,8 @@ int madera_micd_mic_reading(struct madera_extcon *info, int val) * plain headphones. If both polarities report a low * impedence then give up and report headphones. */ - if (ohms > info->micd_ranges[0].max && + if (((info->micd_ranges[0].max > MADERA_MICD_WRONG_POLARITY) || + (ohms > info->micd_ranges[0].max)) && info->num_micd_modes > 1) { if (info->jack_flips >= info->num_micd_modes * 10) { dev_dbg(info->dev, "Detected HP/line\n");