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

Commit 13a491c7 authored by Phani Kumar Uppalapati's avatar Phani Kumar Uppalapati
Browse files

ASoC: wcd934x: Add impedance detection controls



Add impedance detection mixer controls used to get
the impedance values of headphone left and right
channels.

CRs-Fixed: 1083198
Change-Id: Ibbca465192c58deba3618d70e36089119c7f3994
Signed-off-by: default avatarPhani Kumar Uppalapati <phaniu@codeaurora.org>
parent ce610f2f
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -870,11 +870,41 @@ static int tavil_get_hph_type(struct snd_kcontrol *kcontrol,
	return 0;
}

static int tavil_hph_impedance_get(struct snd_kcontrol *kcontrol,
				   struct snd_ctl_elem_value *ucontrol)
{
	uint32_t zl, zr;
	bool hphr;
	struct soc_multi_mixer_control *mc;
	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
	struct wcd934x_mbhc *wcd934x_mbhc = tavil_soc_get_mbhc(codec);

	if (!wcd934x_mbhc) {
		dev_err(codec->dev, "%s: mbhc not initialized!\n", __func__);
		return -EINVAL;
	}

	mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
	hphr = mc->shift;
	wcd_mbhc_get_impedance(&wcd934x_mbhc->wcd_mbhc, &zl, &zr);
	dev_dbg(codec->dev, "%s: zl=%u(ohms), zr=%u(ohms)\n", __func__, zl, zr);
	ucontrol->value.integer.value[0] = hphr ? zr : zl;

	return 0;
}

static const struct snd_kcontrol_new hph_type_detect_controls[] = {
	SOC_SINGLE_EXT("HPH Type", 0, 0, UINT_MAX, 0,
		       tavil_get_hph_type, NULL),
};

static const struct snd_kcontrol_new impedance_detect_controls[] = {
	SOC_SINGLE_EXT("HPHL Impedance", 0, 0, UINT_MAX, 0,
		       tavil_hph_impedance_get, NULL),
	SOC_SINGLE_EXT("HPHR Impedance", 0, 1, UINT_MAX, 0,
		       tavil_hph_impedance_get, NULL),
};

/*
 * tavil_mbhc_hs_detect: starts mbhc insertion/removal functionality
 * @codec: handle to snd_soc_codec *
@@ -985,6 +1015,8 @@ int tavil_mbhc_init(struct wcd934x_mbhc **mbhc, struct snd_soc_codec *codec,
				0;
	}

	snd_soc_add_codec_controls(codec, impedance_detect_controls,
				   ARRAY_SIZE(impedance_detect_controls));
	snd_soc_add_codec_controls(codec, hph_type_detect_controls,
				   ARRAY_SIZE(hph_type_detect_controls));