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

Commit fc93c486 authored by Surendar Karka's avatar Surendar Karka Committed by Gerrit - the friendly Code Review server
Browse files

asoc: add support to set TTP offset



- Add support to set TTP offset.
- Add direction support for render mode

Change-Id: Ia869767c58192f3e07cddc7bf230992076f7a02e
Signed-off-by: default avatarSurendar Karka <skarka@codeaurora.org>
parent 1038df1f
Loading
Loading
Loading
Loading
+30 −3
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ static int msm_compr_send_dec_params(struct snd_compr_stream *cstream,
				     int stream_id);

static int msm_compr_set_render_mode(struct msm_compr_audio *prtd,
				     uint32_t render_mode) {
				     uint32_t render_mode, int dir) {
	int ret = -EINVAL;
	struct audio_client *ac = prtd->audio_client;

@@ -250,7 +250,7 @@ static int msm_compr_set_render_mode(struct msm_compr_audio *prtd,
		goto exit;
	}

	ret = q6asm_send_mtmx_strtr_render_mode(ac, render_mode);
	ret = q6asm_send_mtmx_strtr_render_mode(ac, render_mode, dir);
	if (ret) {
		pr_err("%s, Render mode can't be set error %d\n", __func__,
			ret);
@@ -324,6 +324,29 @@ static int msm_compr_set_render_window(struct audio_client *ac,
	return ret;
}

static int msm_compr_set_ttp_offset(struct audio_client *ac,
		uint32_t offset_lsw, uint32_t offset_msw, int dir)
{
	int ret = -EINVAL;
	struct asm_session_mtmx_strtr_param_ttp_offset_t ttp_offset;
	uint32_t param_id;

	pr_debug("%s, ttp offset lsw 0x%x  ttp offset msw 0x%x\n",
		 __func__, offset_lsw, offset_msw);

	memset(&ttp_offset, 0,
	       sizeof(struct asm_session_mtmx_strtr_param_ttp_offset_t));
	ttp_offset.ttp_offset_lsw = offset_lsw;
	ttp_offset.ttp_offset_msw = offset_msw;
	param_id = ASM_SESSION_MTMX_STRTR_PARAM_TTP_OFFSET;
	ret = q6asm_send_mtmx_strtr_ttp_offset(ac, &ttp_offset, param_id, dir);
	if (ret)
		pr_err("%s, ttp offset can't be set error %d\n", __func__,
			ret);

	return ret;
}

static int msm_compr_enable_adjust_session_clock(struct audio_client *ac,
		bool enable)
{
@@ -3221,7 +3244,8 @@ static int msm_compr_set_metadata(struct snd_compr_stream *cstream,
			 __func__, metadata->value[0]);
		prtd->gapless_state.initial_samples_drop = metadata->value[0];
	} else if (metadata->key == SNDRV_COMPRESS_RENDER_MODE) {
		return msm_compr_set_render_mode(prtd, metadata->value[0]);
		return msm_compr_set_render_mode(prtd, metadata->value[0],
				cstream->direction);
	} else if (metadata->key == SNDRV_COMPRESS_CLK_REC_MODE) {
		return msm_compr_set_clk_rec_mode(ac, metadata->value[0]);
	} else if (metadata->key == SNDRV_COMPRESS_RENDER_WINDOW) {
@@ -3242,6 +3266,9 @@ static int msm_compr_set_metadata(struct snd_compr_stream *cstream,
		return msm_compr_adjust_session_clock(ac,
				metadata->value[0],
				metadata->value[1]);
	} else if (metadata->key == SNDRV_COMPRESS_IN_TTP_OFFSET) {
		return msm_compr_set_ttp_offset(ac, metadata->value[0],
				metadata->value[1], cstream->direction);
	}

	return 0;
+4 −3
Original line number Diff line number Diff line
@@ -613,7 +613,7 @@ static int msm_transcode_loopback_get_caps(struct snd_compr_stream *cstream,
}

static int msm_transcode_set_render_mode(struct msm_transcode_loopback *prtd,
					 uint32_t render_mode)
					 uint32_t render_mode, int dir)
{
	int ret = -EINVAL;
	struct audio_client *ac = prtd->audio_client;
@@ -639,7 +639,7 @@ static int msm_transcode_set_render_mode(struct msm_transcode_loopback *prtd,
		goto exit;
	}

	ret = q6asm_send_mtmx_strtr_render_mode(ac, render_mode);
	ret = q6asm_send_mtmx_strtr_render_mode(ac, render_mode, dir);
	if (ret) {
		pr_err("%s: Render mode can't be set error %d\n", __func__,
			ret);
@@ -705,7 +705,8 @@ static int msm_transcode_loopback_set_metadata(struct snd_compr_stream *cstream,
	}
	case SNDRV_COMPRESS_RENDER_MODE:
	{
		rc = msm_transcode_set_render_mode(prtd, metadata->value[0]);
		rc = msm_transcode_set_render_mode(prtd, metadata->value[0],
						   cstream->direction);
		if (rc)
			pr_err("%s: error setting render mode %d\n", __func__,
				rc);
+91 −2
Original line number Diff line number Diff line
@@ -10047,17 +10047,106 @@ int q6asm_send_mtmx_strtr_window(struct audio_client *ac,
}
EXPORT_SYMBOL(q6asm_send_mtmx_strtr_window);

/**
 * q6asm_send_mtmx_strtr_ttp_offset -
 *       command to send matrix for ttp offset
 *
 * @ac: Audio client handle
 * @ttp_offset: ttp offset params
 * @param_id: param id for ttp offset
 * @dir: RX or TX direction
 *
 * Returns 0 on success or error on failure
 */
int q6asm_send_mtmx_strtr_ttp_offset(struct audio_client *ac,
		struct asm_session_mtmx_strtr_param_ttp_offset_t *ttp_offset,
		uint32_t param_id, int dir)
{
	struct asm_mtmx_strtr_params matrix;
	int sz = 0;
	int rc  = 0;

	pr_debug("%s: ttp offset lsw is %d, ttp offset msw is %d\n", __func__,
		  ttp_offset->ttp_offset_lsw, ttp_offset->ttp_offset_msw);

	if (!ac) {
		pr_err("%s: audio client handle is NULL\n", __func__);
		rc = -EINVAL;
		goto fail_cmd;
	}

	if (ac->apr == NULL) {
		pr_err("%s: ac->apr is NULL", __func__);
		rc = -EINVAL;
		goto fail_cmd;
	}

	memset(&matrix, 0, sizeof(struct asm_mtmx_strtr_params));
	sz = sizeof(struct asm_mtmx_strtr_params);
	q6asm_add_hdr(ac, &matrix.hdr, sz, TRUE);
	atomic_set(&ac->cmd_state, -1);
	matrix.hdr.opcode = ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2;

	matrix.param.data_payload_addr_lsw = 0;
	matrix.param.data_payload_addr_msw = 0;
	matrix.param.mem_map_handle = 0;
	matrix.param.data_payload_size =
		sizeof(struct param_hdr_v1) +
		sizeof(struct asm_session_mtmx_strtr_param_ttp_offset_t);
	matrix.param.direction = dir;
	matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
	matrix.data.param_id = param_id;
	matrix.data.param_size =
		sizeof(struct asm_session_mtmx_strtr_param_ttp_offset_t);
	matrix.data.reserved = 0;
	memcpy(&(matrix.config.ttp_offset),
	       ttp_offset,
	       sizeof(struct asm_session_mtmx_strtr_param_ttp_offset_t));

	rc = apr_send_pkt(ac->apr, (uint32_t *) &matrix);
	if (rc < 0) {
		pr_err("%s: ttp offset send failed paramid [0x%x]\n",
			__func__, matrix.data.param_id);
		rc = -EINVAL;
		goto fail_cmd;
	}

	rc = wait_event_timeout(ac->cmd_wait,
			(atomic_read(&ac->cmd_state) >= 0),
			msecs_to_jiffies(TIMEOUT_MS));
	if (!rc) {
		pr_err("%s: timeout, ttp offset paramid[0x%x]\n",
			__func__, matrix.data.param_id);
		rc = -ETIMEDOUT;
		goto fail_cmd;
	}

	if (atomic_read(&ac->cmd_state) > 0) {
		pr_err("%s: DSP returned error[%s]\n",
				__func__, adsp_err_get_err_str(
				atomic_read(&ac->cmd_state)));
		rc = adsp_err_get_lnx_err_code(
				atomic_read(&ac->cmd_state));
		goto fail_cmd;
	}
	rc = 0;
fail_cmd:
	return rc;
}
EXPORT_SYMBOL(q6asm_send_mtmx_strtr_ttp_offset);

/**
 * q6asm_send_mtmx_strtr_render_mode -
 *       command to send matrix for render mode
 *
 * @ac: Audio client handle
 * @render_mode: rendering mode
 * @dir: RX or TX direction
 *
 * Returns 0 on success or error on failure
 */
int q6asm_send_mtmx_strtr_render_mode(struct audio_client *ac,
		uint32_t render_mode)
		uint32_t render_mode, int dir)
{
	struct asm_mtmx_strtr_params matrix;
	struct asm_session_mtmx_strtr_param_render_mode_t render_param;
@@ -10101,7 +10190,7 @@ int q6asm_send_mtmx_strtr_render_mode(struct audio_client *ac,
	matrix.param.data_payload_size =
		sizeof(struct param_hdr_v1) +
		sizeof(struct asm_session_mtmx_strtr_param_render_mode_t);
	matrix.param.direction = 0; /* RX */
	matrix.param.direction = dir;
	matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
	matrix.data.param_id = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_MODE_CMD;
	matrix.data.param_size =
+27 −0
Original line number Diff line number Diff line
@@ -12348,6 +12348,12 @@ struct afe_av_dev_drift_get_param_resp {
 */
#define ASM_SESSION_MTMX_STRTR_PARAM_RENDER_WINDOW_END_V2   0x00010DD2

/* Parameter used by #ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC to specify the
 * ttp offset value. This parameter is supported only for a Set
 * command (not a Get command) in the Tx direction
 */
#define ASM_SESSION_MTMX_STRTR_PARAM_TTP_OFFSET 0x00013228

/* Generic payload of the window parameters in the
 * #ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC module.
 * This payload is supported only for a Set command
@@ -12456,6 +12462,26 @@ struct asm_session_mtmx_strtr_param_render_mode_t {
	u32                  flags;
} __packed;

struct asm_session_mtmx_strtr_param_ttp_offset_t {
	uint32_t                  ttp_offset_lsw;
	/* Lower 32 bits of the ttp_offset in microseconds. */

	uint32_t                  ttp_offset_msw;
	/* Upper 32 bits of the ttp_offset in microseconds.
	 *
	 * Internal default value is 0 for both values. The 64-bit number
	 * formed by ttp_offset_lsw and ttp_offset_lsw is treated as unsigned.
	 * In case of local DSP loopback when using start flag
	 * ASM_SESSION_CMD_RUN_START_TIME_RUN_WITH_TTP the max. ttp_offset
	 * value is limited by internal buffer constraints. Currently the
	 * limit is 200ms.

	 * This parameter can be set before or while an ASM stream is running,
	 * allowing “at-run-time” changes of the overall latency.
	 */

} __packed;

/* Parameter used by #ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC which allows the
 * audio client to specify the clock recovery mechanism that the audio DSP
 * should use.
@@ -12527,6 +12553,7 @@ union asm_session_mtmx_strtr_param_config {
	struct asm_session_mtmx_strtr_param_render_mode_t render_param;
	struct asm_session_mtmx_strtr_param_clk_rec_t clk_rec_param;
	struct asm_session_mtmx_param_adjust_session_time_ctl_t adj_time_param;
	struct asm_session_mtmx_strtr_param_ttp_offset_t ttp_offset;
} __packed;

struct asm_mtmx_strtr_params {
+6 −2
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
 */
#ifndef __Q6_ASM_V2_H__
#define __Q6_ASM_V2_H__
@@ -726,9 +726,13 @@ int q6asm_send_mtmx_strtr_window(struct audio_client *ac,
		struct asm_session_mtmx_strtr_param_window_v2_t *window_param,
		uint32_t param_id);

int q6asm_send_mtmx_strtr_ttp_offset(struct audio_client *ac,
		struct asm_session_mtmx_strtr_param_ttp_offset_t *ttp_offset,
		uint32_t param_id, int dir);

/* Configure DSP render mode */
int q6asm_send_mtmx_strtr_render_mode(struct audio_client *ac,
		uint32_t render_mode);
		uint32_t render_mode, int dir);

/* Configure DSP clock recovery mode */
int q6asm_send_mtmx_strtr_clk_rec_mode(struct audio_client *ac,