Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 528f2767 authored by Phani Kumar Uppalapati's avatar Phani Kumar Uppalapati
Browse files

ASoC: wcd9xxx: Continue polling for Unsupported plug types



Sometimes slow insertion of headphone could lead to
detection of unsupported plug types. In these cases,
continue polling so that headphone can be detected
once it is fully inserted.

CRs-Fixed: 745214
Change-Id: I4fe40d1afe71a5b1f5c8e8e69ba3afe16750161e
Signed-off-by: default avatarPhani Kumar Uppalapati <phaniu@codeaurora.org>
parent dbd2b72e
Loading
Loading
Loading
Loading
+60 −34
Original line number Diff line number Diff line
@@ -3093,6 +3093,37 @@ static bool wcd9xxx_mbhc_enable_mb_decision(int high_hph_cnt)
	return (high_hph_cnt > 2) && !(high_hph_cnt & (high_hph_cnt - 1));
}

static inline void wcd9xxx_handle_gnd_mic_swap(struct wcd9xxx_mbhc *mbhc,
					int pt_gnd_mic_swap_cnt,
					enum wcd9xxx_mbhc_plug_type plug_type)
{
	if (mbhc->mbhc_cfg->swap_gnd_mic &&
	    (pt_gnd_mic_swap_cnt == GND_MIC_SWAP_THRESHOLD)) {
		/*
		 * if switch is toggled, check again,
		 * otherwise report unsupported plug
		 */
		mbhc->mbhc_cfg->swap_gnd_mic(mbhc->codec);
	} else if (pt_gnd_mic_swap_cnt >= GND_MIC_SWAP_THRESHOLD) {
		/* Report UNSUPPORTED plug
		 * and continue polling
		 */
		WCD9XXX_BCL_LOCK(mbhc->resmgr);
		if (!mbhc->mbhc_cfg->detect_extn_cable) {
			if (mbhc->current_plug == PLUG_TYPE_HEADPHONE)
				wcd9xxx_report_plug(mbhc, 0,
						    SND_JACK_HEADPHONE);
			else if (mbhc->current_plug == PLUG_TYPE_HEADSET)
				wcd9xxx_report_plug(mbhc, 0,
						    SND_JACK_HEADSET);
		}
		if (mbhc->current_plug != plug_type)
			wcd9xxx_report_plug(mbhc, 1,
					SND_JACK_UNSUPPORTED);
		WCD9XXX_BCL_UNLOCK(mbhc->resmgr);
	}
}

static void wcd9xxx_correct_swch_plug(struct work_struct *work)
{
	struct wcd9xxx_mbhc *mbhc;
@@ -3207,24 +3238,15 @@ static void wcd9xxx_correct_swch_plug(struct work_struct *work)
		} else {
			if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
				pt_gnd_mic_swap_cnt++;
				if (pt_gnd_mic_swap_cnt <
				if (pt_gnd_mic_swap_cnt >=
						GND_MIC_SWAP_THRESHOLD)
					wcd9xxx_handle_gnd_mic_swap(mbhc,
							pt_gnd_mic_swap_cnt,
							plug_type);
				pr_debug("%s: unsupported HS detected, continue polling\n",
					 __func__);
				continue;
				else if (pt_gnd_mic_swap_cnt >
					 GND_MIC_SWAP_THRESHOLD) {
					/*
					 * This is due to GND/MIC switch didn't
					 * work,  Report unsupported plug
					 */
				} else if (mbhc->mbhc_cfg->swap_gnd_mic) {
					/*
					 * if switch is toggled, check again,
					 * otherwise report unsupported plug
					 */
					if (mbhc->mbhc_cfg->swap_gnd_mic(codec))
						continue;
				}
			} else
			} else {
				pt_gnd_mic_swap_cnt = 0;

				WCD9XXX_BCL_LOCK(mbhc->resmgr);
@@ -3234,15 +3256,19 @@ static void wcd9xxx_correct_swch_plug(struct work_struct *work)
							&mbhc->mbhc_bias_regs,
							false, false);
				else
				wcd9xxx_turn_onoff_override(mbhc, false);
					wcd9xxx_turn_onoff_override(mbhc,
								    false);
				/*
			 * The valid plug also includes PLUG_TYPE_GND_MIC_SWAP
				 * The valid plug also includes
				 * PLUG_TYPE_GND_MIC_SWAP
				 */
				wcd9xxx_find_plug_and_report(mbhc, plug_type);
				WCD9XXX_BCL_UNLOCK(mbhc->resmgr);
			pr_debug("Attempt %d found correct plug %d\n", retry,
				pr_debug("Attempt %d found correct plug %d\n",
						retry,
						plug_type);
				correction = true;
			}
			break;
		}
	}