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

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

ASoC: wcd934x: Add API to enable standalone micbias



Add an API in wcd934x codec driver to enable
standalone micbias. This API can be used to enable
micbias even without an active audio capture session.

CRs-fixed: 1062152
Change-Id: I98074071546c053ce3be733602adeff23d6b4b72
Signed-off-by: default avatarPhani Kumar Uppalapati <phaniu@codeaurora.org>
parent ab26d098
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -3296,6 +3296,58 @@ static int __tavil_codec_enable_micbias(struct snd_soc_dapm_widget *w,
	return 0;
}

/*
 * tavil_codec_enable_standalone_micbias - enable micbias standalone
 * @codec: pointer to codec instance
 * @micb_num: number of micbias to be enabled
 * @enable: true to enable micbias or false to disable
 *
 * This function is used to enable micbias (1, 2, 3 or 4) during
 * standalone independent of whether TX use-case is running or not
 *
 * Return: error code in case of failure or 0 for success
 */
int tavil_codec_enable_standalone_micbias(struct snd_soc_codec *codec,
					  int micb_num,
					  bool enable)
{
	const char * const micb_names[] = {
		DAPM_MICBIAS1_STANDALONE, DAPM_MICBIAS2_STANDALONE,
		DAPM_MICBIAS3_STANDALONE, DAPM_MICBIAS4_STANDALONE
	};
	int micb_index = micb_num - 1;
	int rc;

	if (!codec) {
		pr_err("%s: Codec memory is NULL\n", __func__);
		return -EINVAL;
	}

	if ((micb_index < 0) || (micb_index > TAVIL_MAX_MICBIAS - 1)) {
		dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n",
			__func__, micb_index);
		return -EINVAL;
	}

	if (enable)
		rc = snd_soc_dapm_force_enable_pin_unlocked(
						snd_soc_codec_get_dapm(codec),
						micb_names[micb_index]);
	else
		rc = snd_soc_dapm_disable_pin_unlocked(
						snd_soc_codec_get_dapm(codec),
						micb_names[micb_index]);

	if (!rc)
		snd_soc_dapm_sync(snd_soc_codec_get_dapm(codec));
	else
		dev_err(codec->dev, "%s: micbias%d force %s pin failed\n",
			__func__, micb_num, (enable ? "enable" : "disable"));

	return rc;
}
EXPORT_SYMBOL(tavil_codec_enable_standalone_micbias);

static int tavil_codec_force_enable_micbias(struct snd_soc_dapm_widget *w,
					    struct snd_kcontrol *kcontrol,
					    int event)