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

Commit 46a3226f authored by Ben Romberger's avatar Ben Romberger Committed by Anish Kumar
Browse files

ASoC: msm: Do not deregister APR mmap handle for ASM Custom Topology



Remove APR deregister call from ASM Custom Topology to
ensure that the RESET event is called during SSR to
signal that ASM custom topology needs to be sent.

Various error handling is also added so that reference
count for apr deregister and register also happens properly.

Change-Id: I4a123b07875fe71e13c5b8812264d2e504332dca
Signed-off-by: default avatarBen Romberger <bromberg@codeaurora.org>
Signed-off-by: default avatarAnish Kumar <kanish@codeaurora.org>
parent db9318e3
Loading
Loading
Loading
Loading
+64 −56
Original line number Diff line number Diff line
@@ -373,23 +373,24 @@ void send_asm_custom_topology(struct audio_client *ac)
	struct list_head		*ptr, *next;
	int				result;
	int				size = 4096;

	if (!set_custom_topology)
		return;

	get_asm_custom_topology(&cal_block);
	if (cal_block.cal_size == 0) {
		pr_debug("%s: no cal to send addr= 0x%pa\n",
				__func__, &cal_block.cal_paddr);
		goto done;
		return;
	}

	if (set_custom_topology) {
		if (common_client.mmap_apr == NULL) {
	common_client.mmap_apr = q6asm_mmap_apr_reg();
	common_client.apr = common_client.mmap_apr;
	if (common_client.mmap_apr == NULL) {
		pr_err("%s: q6asm_mmap_apr_reg failed\n",
			__func__);
		result = -EPERM;
				goto done;
			}
		goto mmap_fail;
	}
	/* Only call this once */
	set_custom_topology = 0;
@@ -398,7 +399,7 @@ void send_asm_custom_topology(struct audio_client *ac)
	if (common_client.port[IN].buf == NULL) {
		pr_err("%s: common buf is NULL\n",
			__func__);
			goto done;
		goto err_map;
	}
	common_client.port[IN].buf->phys = cal_block.cal_paddr;

@@ -408,7 +409,7 @@ void send_asm_custom_topology(struct audio_client *ac)
		pr_err("%s: mmap did not work! addr = 0x%pa, size = %zd\n",
			__func__, &cal_block.cal_paddr,
			cal_block.cal_size);
			goto done;
		goto err_map;
	}

	list_for_each_safe(ptr, next,
@@ -421,15 +422,6 @@ void send_asm_custom_topology(struct audio_client *ac)
		}
	}

		result = q6asm_mmap_apr_dereg();
		if (result < 0) {
			pr_err("%s: q6asm_mmap_apr_dereg failed, err %d\n",
				__func__, result);
		} else {
			common_client.mmap_apr = NULL;
		}
	}

	q6asm_add_hdr_custom_topology(ac, &asm_top.hdr,
				      APR_PKT_SIZE(APR_HDR_SIZE,
					sizeof(asm_top)), TRUE);
@@ -448,7 +440,7 @@ void send_asm_custom_topology(struct audio_client *ac)
	if (result < 0) {
		pr_err("%s: Set topologies failed payload = 0x%pa\n",
			__func__, &cal_block.cal_paddr);
		goto done;
		goto err_unmap;
	}

	result = wait_event_timeout(ac->cmd_wait,
@@ -456,10 +448,15 @@ void send_asm_custom_topology(struct audio_client *ac)
	if (!result) {
		pr_err("%s: Set topologies failed payload = 0x%pa\n",
			__func__, &cal_block.cal_paddr);
		goto done;
		goto err_unmap;
	}

done:
	return;
err_unmap:
	q6asm_memory_unmap_regions(ac, IN);
err_map:
	q6asm_mmap_apr_dereg();
	set_custom_topology = 1;
mmap_fail:
	return;
}

@@ -837,7 +834,7 @@ struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
	if (ac->apr == NULL) {
		pr_err("%s Registration with APR failed\n", __func__);
		mutex_unlock(&session_lock);
		goto fail;
		goto fail_apr1;
	}
	ac->apr2 = apr_register("ADSP", "ASM",
				(apr_fn)q6asm_callback,
@@ -847,15 +844,16 @@ struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
	if (ac->apr2 == NULL) {
		pr_err("%s Registration with APR-2 failed\n", __func__);
		mutex_unlock(&session_lock);
		goto fail;
		goto fail_apr2;
	}

	rtac_set_asm_handle(n, ac->apr);

	pr_debug("%s Registering the common port with APR\n", __func__);
	ac->mmap_apr = q6asm_mmap_apr_reg();
	if (ac->mmap_apr == NULL) {
		mutex_unlock(&session_lock);
		goto fail;
		goto fail_mmap;
	}

	init_waitqueue_head(&ac->cmd_wait);
@@ -879,9 +877,12 @@ struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
	mutex_unlock(&session_lock);

	return ac;
fail:
	q6asm_audio_client_free(ac);
	return NULL;
fail_mmap:
	apr_deregister(ac->apr2);
fail_apr2:
	apr_deregister(ac->apr);
fail_apr1:
	q6asm_session_free(ac);
fail_session:
	kfree(ac);
	return NULL;
@@ -1095,12 +1096,20 @@ static int32_t q6asm_srvc_callback(struct apr_client_data *data, void *priv)
	payload = data->payload;

	if (data->opcode == RESET_EVENTS) {
		struct audio_client *ac_mmap = (struct audio_client *)priv;
		if (ac_mmap == NULL) {
			pr_err("%s ac or priv NULL\n", __func__);
			return -EINVAL;
		}
		pr_debug("%s: Reset event is received: %d %d apr[%p]\n",
				__func__,
				data->reset_event,
				data->reset_proc,
				this_mmap.apr);
		atomic_set(&this_mmap.ref_cnt, 0);
		apr_reset(this_mmap.apr);
		this_mmap.apr = NULL;
		ac_mmap->mmap_apr = NULL;
		for (; i <= OUT; i++) {
			list_for_each_safe(ptr, next,
				&common_client.port[i].mem_map_handle) {
@@ -1115,7 +1124,6 @@ static int32_t q6asm_srvc_callback(struct apr_client_data *data, void *priv)
			}
			pr_debug("%s:Clearing custom topology\n", __func__);
		}
		this_mmap.apr = NULL;
		reset_custom_topology_flags();
		set_custom_topology = 1;
		topology_map_handle = 0;