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

Commit b3274f04 authored by Josh Kirsch's avatar Josh Kirsch Committed by Gerrit - the friendly Code Review server
Browse files

ASoC: mdmcalifornium: Add fix for MI2S startup reference count



Add a fix for an issue where the MI2S start
references is not tracked properly. The
issue is that since both TX and RX MI2S
calls into the startup function the dai format
is called two times which is not needed and
leads to an error. By tracking the number
of entries this can be avoided.

CRs-fixed: 1019776
Change-Id: I73745213cd5675c9be6e418346c3d24b54196bad
Signed-off-by: default avatarJosh Kirsch <jkirsch@codeaurora.org>
parent 2705efa5
Loading
Loading
Loading
Loading
+167 −152
Original line number Diff line number Diff line
@@ -132,6 +132,8 @@ static int mdm_sec_mi2s_tx_rate = SAMPLE_RATE_48KHZ;

static int mdm_spk_control = 1;
static int mdm_hifi_control;
static atomic_t mi2s_ref_count;
static atomic_t sec_mi2s_ref_count;

static int mdm_enable_codec_ext_clk(struct snd_soc_codec *codec,
					int enable, bool dapm);
@@ -244,10 +246,12 @@ static void mdm_mi2s_shutdown(struct snd_pcm_substream *substream)
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
	int ret;

	if (atomic_dec_return(&mi2s_ref_count) == 0) {
		ret = mdm_mi2s_clk_ctl(rtd, false);
		if (ret < 0)
			pr_err("%s Clock disable failed\n", __func__);
	}
}

static int mdm_mi2s_startup(struct snd_pcm_substream *substream)
{
@@ -258,7 +262,7 @@ static int mdm_mi2s_startup(struct snd_pcm_substream *substream)
	struct mdm_machine_data *pdata = snd_soc_card_get_drvdata(card);
	int ret = 0;


	if (atomic_inc_return(&mi2s_ref_count) == 1) {
		if (lpaif_pri_muxsel_virt_addr != NULL) {
			ret = afe_enable_lpass_core_shared_clock(MI2S_RX,
								 CLOCK_ON);
@@ -346,12 +350,15 @@ static int mdm_mi2s_startup(struct snd_pcm_substream *substream)
				dev_err(card->dev, "%s Set fmt for codec dai failed\n",
					__func__);
		} else {
		dev_err(card->dev, "%s Invalid primary mi2s mode\n", __func__);
			dev_err(card->dev, "%s Invalid primary mi2s mode\n",
					__func__);
			ret = -EINVAL;
		}

err:
		if (ret)
			atomic_dec_return(&mi2s_ref_count);
		afe_enable_lpass_core_shared_clock(MI2S_RX, CLOCK_OFF);
	}
done:
	return ret;
}
@@ -405,11 +412,12 @@ static void mdm_sec_mi2s_shutdown(struct snd_pcm_substream *substream)
{
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
	int ret;

	if (atomic_dec_return(&sec_mi2s_ref_count) == 0) {
		ret = mdm_sec_mi2s_clk_ctl(rtd, false);
		if (ret < 0)
			pr_err("%s Clock disable failed\n", __func__);
	}
}

static int mdm_sec_mi2s_startup(struct snd_pcm_substream *substream)
{
@@ -419,6 +427,7 @@ static int mdm_sec_mi2s_startup(struct snd_pcm_substream *substream)
	struct mdm_machine_data *pdata = snd_soc_card_get_drvdata(card);
	int ret = 0;

	if (atomic_inc_return(&sec_mi2s_ref_count) == 1) {
		if (lpaif_sec_muxsel_virt_addr != NULL) {
			ret = afe_enable_lpass_core_shared_clock(
					SECONDARY_I2S_RX, CLOCK_ON);
@@ -491,9 +500,13 @@ static int mdm_sec_mi2s_startup(struct snd_pcm_substream *substream)
				__func__);
			ret = -EINVAL;
		}

err:
	afe_enable_lpass_core_shared_clock(SECONDARY_I2S_RX, CLOCK_OFF);
			if (ret)
				atomic_dec_return(&sec_mi2s_ref_count);
			afe_enable_lpass_core_shared_clock(
							SECONDARY_I2S_RX,
							CLOCK_OFF);
	}
done:
	return ret;
}
@@ -2185,6 +2198,8 @@ static int mdm_asoc_machine_probe(struct platform_device *pdev)
	}

	mutex_init(&cdc_mclk_mutex);
	atomic_set(&mi2s_ref_count, 0);
	atomic_set(&sec_mi2s_ref_count, 0);
	pdata->prim_clk_usrs = 0;

	card->dev = &pdev->dev;