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

Commit b17402be authored by Phani Kumar Uppalapati's avatar Phani Kumar Uppalapati
Browse files

ASoC: wcd9xxx: move DCE_Z recalibration after mic measurements



Recalibrating DCE/STA gnd voltages in the middle of DC
Estimate for mic voltage will cause problem due to micbias
pull down and then pull up. The measured mic voltage probably
is not at its steadystate value due to slow ramp up of micbias.
Calibrate these DCE/STA gnd voltages only after taking all the
DCE measurements required to classify the accessory type.

CRs-Fixed: 731148
Change-Id: I70c022655f7915f815bb3772e0cbbe71b3b32c5b
Signed-off-by: default avatarPhani Kumar Uppalapati <phaniu@codeaurora.org>
parent d2a8c71b
Loading
Loading
Loading
Loading
+35 −9
Original line number Diff line number Diff line
@@ -207,6 +207,10 @@ static void wcd9xxx_get_z(struct wcd9xxx_mbhc *mbhc, s16 *dce_z, s16 *sta_z,

static void wcd9xxx_mbhc_calc_thres(struct wcd9xxx_mbhc *mbhc);

static u16 wcd9xxx_codec_v_sta_dce(struct wcd9xxx_mbhc *mbhc,
				   enum meas_type dce, s16 vin_mv,
				   bool cs_enable);

static bool wcd9xxx_mbhc_polling(struct wcd9xxx_mbhc *mbhc)
{
	return snd_soc_read(mbhc->codec, WCD9XXX_A_CDC_MBHC_EN_CTL) & 0x1;
@@ -1203,10 +1207,6 @@ static short wcd9xxx_mbhc_setup_hs_polling(struct wcd9xxx_mbhc *mbhc,
	struct snd_soc_codec *codec = mbhc->codec;
	short bias_value;
	u8 cfilt_mode;
	s16 reg;
	int change;
	struct wcd9xxx_mbhc_btn_detect_cfg *btn_det;
	s16 sta_z = 0, dce_z = 0;

	WCD9XXX_BCL_ASSERT_LOCKED(mbhc->resmgr);

@@ -1216,7 +1216,6 @@ static short wcd9xxx_mbhc_setup_hs_polling(struct wcd9xxx_mbhc *mbhc,
		return -ENODEV;
	}

	btn_det = WCD9XXX_MBHC_CAL_BTN_DET_PTR(mbhc->mbhc_cfg->calibration);
	/* Enable external voltage source to micbias if present */
	if (mbhc->mbhc_cb && mbhc->mbhc_cb->enable_mb_source)
		mbhc->mbhc_cb->enable_mb_source(codec, true, true);
@@ -1276,6 +1275,21 @@ static short wcd9xxx_mbhc_setup_hs_polling(struct wcd9xxx_mbhc *mbhc,
	snd_soc_write(codec, mbhc_micb_regs->cfilt_ctl, cfilt_mode);
	snd_soc_update_bits(codec, WCD9XXX_A_MBHC_HPH, 0x13, 0x00);

	return bias_value;
}

static void wcd9xxx_recalibrate(struct wcd9xxx_mbhc *mbhc,
				struct mbhc_micbias_regs *mbhc_micb_regs,
				bool is_cs_enable)
{
	struct snd_soc_codec *codec = mbhc->codec;
	s16 reg;
	int change;
	struct wcd9xxx_mbhc_btn_detect_cfg *btn_det;
	s16 sta_z = 0, dce_z = 0;

	btn_det = WCD9XXX_MBHC_CAL_BTN_DET_PTR(mbhc->mbhc_cfg->calibration);

	if (mbhc->mbhc_cfg->do_recalibration) {
		/* recalibrate dce_z and sta_z */
		reg = snd_soc_read(codec, WCD9XXX_A_CDC_MBHC_B1_CTL);
@@ -1310,17 +1324,24 @@ static short wcd9xxx_mbhc_setup_hs_polling(struct wcd9xxx_mbhc *mbhc,
			snd_soc_write(mbhc->codec, WCD9XXX_A_CDC_MBHC_B1_CTL,
				      reg);
			if (dce_z) {
				pr_debug("%s: dce_nsc_cs_z 0x%x -> 0x%x\n",
					 __func__, mbhc->mbhc_data.dce_nsc_cs_z,
					 dce_z & 0xffff);
				mbhc->mbhc_data.dce_nsc_cs_z = dce_z;
				/* update v_cs_ins_h with new dce_nsc_cs_z */
				mbhc->mbhc_data.v_cs_ins_h =
						wcd9xxx_codec_v_sta_dce(
							mbhc, DCE,
							WCD9XXX_V_CS_HS_MAX,
							is_cs_enable);
				pr_debug("%s: dce_nsc_cs_z 0x%x -> 0x%x, v_cs_ins_h 0x%x\n",
					  __func__,
					  mbhc->mbhc_data.dce_nsc_cs_z,
					  dce_z & 0xffff,
					  mbhc->mbhc_data.v_cs_ins_h);
			} else {
				pr_debug("%s: failed get new dce_nsc_cs_z\n",
					 __func__);
			}
		}
	}
	return bias_value;
}

static void wcd9xxx_shutdown_hs_removal_detect(struct wcd9xxx_mbhc *mbhc)
@@ -1897,6 +1918,9 @@ wcd9xxx_codec_cs_get_plug_type(struct wcd9xxx_mbhc *mbhc, bool highhph)
			wcd9xxx_codec_hphr_gnd_switch(codec, false);
	}

	/* recalibrate DCE/STA GND voltages */
	wcd9xxx_recalibrate(mbhc, &mbhc->mbhc_bias_regs, true);

	type = wcd9xxx_cs_find_plug_type(mbhc, rt, ARRAY_SIZE(rt), highhph,
					 mbhc->event_state);

@@ -1977,6 +2001,8 @@ wcd9xxx_codec_get_plug_type(struct wcd9xxx_mbhc *mbhc, bool highhph)
		if (rt[i].swap_gnd)
			wcd9xxx_codec_hphr_gnd_switch(codec, false);
	}
	/* recalibrate DCE/STA GND voltages */
	wcd9xxx_recalibrate(mbhc, &mbhc->mbhc_bias_regs, false);

	if (vddioon)
		__wcd9xxx_switch_micbias(mbhc, 1, false, false);