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

Commit 94bc9eae authored by Vatsal Bucha's avatar Vatsal Bucha Committed by Gerrit - the friendly Code Review server
Browse files

ASoC: bengal: Fix euro usbc plug not detected during reboot



Euro usbc plug is not detected if we keep headset inserted
and reboot target. This is because usbc_swap_gnd_mic function
does not get called until mbhc interrupt is generated.
Implement late probe so that hs_detect is called after
sound card is registered.

Change-Id: I8cdf94f3cc14bc625afd3a1e05bbcd25e4f9a7fa
Signed-off-by: default avatarVatsal Bucha <vbucha@codeaurora.org>
parent 5154124e
Loading
Loading
Loading
Loading
+59 −29
Original line number Diff line number Diff line
@@ -5979,6 +5979,62 @@ static const struct of_device_id bengal_asoc_machine_of_match[] = {
	{},
};

static int msm_snd_card_bengal_late_probe(struct snd_soc_card *card)
{
	struct snd_soc_component *component;
	struct platform_device *pdev = NULL;
	char *data = NULL;
	int ret = 0, i = 0;
	void *mbhc_calibration;

	for (i = 0; i < card->num_aux_devs; i++)
	{
		if (msm_aux_dev[i].name != NULL ) {
			if (strstr(msm_aux_dev[i].name, "wsa"))
				continue;
		}

		if (msm_aux_dev[i].codec_of_node) {
			pdev = of_find_device_by_node(
					msm_aux_dev[i].codec_of_node);
			if (pdev) {
				data = (char*) of_device_get_match_data(
							&pdev->dev);
				component = soc_find_component(
					    msm_aux_dev[i].codec_of_node,
					    NULL);
			}
		}
	}

	if (data != NULL && component != NULL) {
		if (!strncmp(data, "wcd937x", sizeof("wcd937x"))) {
			mbhc_calibration = def_wcd_mbhc_cal();
			if (!mbhc_calibration)
				goto err_mbhc_cal;
			wcd_mbhc_cfg.calibration = mbhc_calibration;
			ret = wcd937x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
		} else if (!strncmp( data, "rouleur", sizeof("rouleur"))) {
			mbhc_calibration = def_rouleur_mbhc_cal();
			if (!mbhc_calibration)
				goto err_mbhc_cal;
			wcd_mbhc_cfg.calibration = mbhc_calibration;
			ret = rouleur_mbhc_hs_detect(component, &wcd_mbhc_cfg);
		}
	}

	if (ret) {
		dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
			__func__, ret);
		goto err_hs_detect;
	}
	return 0;

err_hs_detect:
	kfree(mbhc_calibration);
err_mbhc_cal:
	return ret;
}
static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
{
	struct snd_soc_card *card = NULL;
@@ -6137,6 +6193,7 @@ static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
	if (card) {
		card->dai_link = dailink;
		card->num_links = total_links;
		card->late_probe = msm_snd_card_bengal_late_probe;
	}

	return card;
@@ -6147,7 +6204,6 @@ static int msm_aux_codec_init(struct snd_soc_component *component)
	struct snd_soc_dapm_context *dapm =
				snd_soc_component_get_dapm(component);
	int ret = 0;
	void *mbhc_calibration;
	struct snd_info_entry *entry;
	struct snd_card *card = component->card->snd_card;
	struct msm_asoc_mach_data *pdata;
@@ -6174,7 +6230,7 @@ static int msm_aux_codec_init(struct snd_soc_component *component)
			dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
				 __func__);
			ret = 0;
			goto mbhc_cfg_cal;
			goto err;
		}
		pdata->codec_root = entry;
	}
@@ -6208,33 +6264,7 @@ static int msm_aux_codec_init(struct snd_soc_component *component)
			}
		}
	}

mbhc_cfg_cal:
        if (data != NULL) {
		if (!strncmp(data, "wcd937x", sizeof("wcd937x"))) {
			mbhc_calibration = def_wcd_mbhc_cal();
			if (!mbhc_calibration)
				return -ENOMEM;
			wcd_mbhc_cfg.calibration = mbhc_calibration;
			ret = wcd937x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
		} else if (!strncmp( data, "rouleur", sizeof("rouleur"))) {
			mbhc_calibration = def_rouleur_mbhc_cal();
			if (!mbhc_calibration)
				return -ENOMEM;
			wcd_mbhc_cfg.calibration = mbhc_calibration;
			ret = rouleur_mbhc_hs_detect(component, &wcd_mbhc_cfg);
		}
	}

	if (ret) {
		dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
			__func__, ret);
		goto err_hs_detect;
	}
	return 0;

err_hs_detect:
	kfree(mbhc_calibration);
err:
	return ret;
}