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

Commit b5a909ab authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ASoC: msm: Add support for AFE RTAC"

parents b1e18847 f9eaeb3a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ enum {
	ADM_RTAC_CAL,
	ASM_RTAC_CAL,
	VOICE_RTAC_CAL,
	AFE_RTAC_CAL,
	MAX_RTAC_BLOCKS
};

@@ -61,5 +62,6 @@ void rtac_set_voice_handle(u32 mode, void *handle);
bool rtac_make_voice_callback(u32 mode, uint32_t *payload, u32 payload_size);
void rtac_copy_voice_payload_to_user(void *payload, u32 payload_size);
int rtac_clear_mapping(uint32_t cal_type);

bool rtac_make_afe_callback(uint32_t *payload, u32 payload_size);
void rtac_set_afe_handle(void *handle);
#endif
+5 −6
Original line number Diff line number Diff line
@@ -2318,8 +2318,6 @@ u32 mem_map_handle;
 * stream.
 */
struct afe_port_cmd_get_param_v2 {

	struct apr_hdr hdr;
	u16 port_id;
/* Port interface and direction (Rx or Tx) to start. */

@@ -6802,6 +6800,7 @@ struct afe_spkr_prot_config_command {
} __packed;

struct afe_spkr_prot_get_vi_calib {
	struct apr_hdr hdr;
	struct afe_port_cmd_get_param_v2 get_param;
	struct afe_port_param_data_v2 pdata;
	struct asm_calib_res_cfg res_cfg;
+3 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#ifndef __Q6AFE_V2_H__
#define __Q6AFE_V2_H__
#include <sound/apr_audio-v2.h>
#include <linux/qdsp6v2/rtac.h>

#define IN			0x000
#define OUT			0x001
@@ -222,4 +223,6 @@ bool afe_has_config(enum afe_config_type config);
void afe_set_aanc_info(struct aanc_data *aanc_info);
int afe_port_group_set_param(u16 *port_id, int channel_count);
int afe_port_group_enable(u16 enable);
int afe_unmap_rtac_block(uint32_t *mem_map_handle);
int afe_map_rtac_block(struct rtac_cal_block_data *cal_block);
#endif /* __Q6AFE_V2_H__ */
+4 −1
Original line number Diff line number Diff line
@@ -40,7 +40,10 @@
							215, void *)
#define AUDIO_SET_RTAC_CVP_CAL		_IOWR(CAL_IOCTL_MAGIC, \
							216, void *)

#define AUDIO_GET_RTAC_AFE_CAL		_IOWR(CAL_IOCTL_MAGIC, \
							217, void *)
#define AUDIO_SET_RTAC_AFE_CAL		_IOWR(CAL_IOCTL_MAGIC, \
							218, void *)
enum {
	CVP_VOC_RX_TOPOLOGY_CAL_TYPE = 0,
	CVP_VOC_TX_TOPOLOGY_CAL_TYPE,
+101 −13
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ static int32_t afe_callback(struct apr_client_data *data, void *priv)
			apr_reset(this_afe.apr);
			atomic_set(&this_afe.state, 0);
			this_afe.apr = NULL;
			rtac_set_afe_handle(this_afe.apr);
		}
		/* send info to user */
		if (this_afe.task == NULL)
@@ -130,18 +131,23 @@ static int32_t afe_callback(struct apr_client_data *data, void *priv)
			 data->payload_size);
	if (data->opcode == AFE_PORT_CMDRSP_GET_PARAM_V2) {
		u8 *payload = data->payload;

		if (rtac_make_afe_callback(data->payload, data->payload_size))
			return 0;

		if ((data->payload_size < sizeof(this_afe.calib_data))
			|| !payload || (data->token >= AFE_MAX_PORTS)) {
			pr_err("%s size %d payload %p token %d\n",
			__func__, data->payload_size, payload, data->token);
			pr_err("%s: Error: size %d payload %p token %d\n",
				__func__, data->payload_size,
				payload, data->token);
			return -EINVAL;
		}
		memcpy(&this_afe.calib_data, payload,
			   sizeof(this_afe.calib_data));
		if (!this_afe.calib_data.status) {
			atomic_set(&this_afe.state, 0);
			pr_err("%s rest %d state %x\n" , __func__
			, this_afe.calib_data.res_cfg.r0_cali_q24,
			pr_err("%s rest %d state %x\n" , __func__,
				this_afe.calib_data.res_cfg.r0_cali_q24,
				this_afe.calib_data.res_cfg.th_vi_ca_state);
		} else
			atomic_set(&this_afe.state, -1);
@@ -161,9 +167,12 @@ static int32_t afe_callback(struct apr_client_data *data, void *priv)
					__func__, payload[0], payload[1]);
			}
			switch (payload[0]) {
			case AFE_PORT_CMD_SET_PARAM_V2:
				if (rtac_make_afe_callback(payload,
					data->payload_size))
					return 0;
			case AFE_PORT_CMD_DEVICE_STOP:
			case AFE_PORT_CMD_DEVICE_START:
			case AFE_PORT_CMD_SET_PARAM_V2:
			case AFE_PSEUDOPORT_CMD_START:
			case AFE_PSEUDOPORT_CMD_STOP:
			case AFE_SERVICE_CMD_SHARED_MEM_MAP_REGIONS:
@@ -367,6 +376,7 @@ int afe_q6_interface_prepare(void)
			pr_err("%s: Unable to register AFE\n", __func__);
			ret = -ENODEV;
		}
		rtac_set_afe_handle(this_afe.apr);
	}
	return ret;
}
@@ -1963,6 +1973,7 @@ int afe_loopback_gain(u16 port_id, u16 volume)
			ret = -ENODEV;
			return ret;
		}
		rtac_set_afe_handle(this_afe.apr);
	}

	if (q6audio_validate_port(port_id) < 0) {
@@ -2390,6 +2401,7 @@ int afe_cmd_memory_map(phys_addr_t dma_addr_p, u32 dma_buf_sz)
			ret = -ENODEV;
			return ret;
		}
		rtac_set_afe_handle(this_afe.apr);
	}

	cmd_size = sizeof(struct afe_service_cmd_shared_mem_map_regions) \
@@ -2481,6 +2493,7 @@ int afe_cmd_memory_map_nowait(int port_id, phys_addr_t dma_addr_p,
			ret = -ENODEV;
			return ret;
		}
		rtac_set_afe_handle(this_afe.apr);
	}
	index = q6audio_get_port_index(port_id);
	if (q6audio_validate_port(port_id) < 0)
@@ -2594,6 +2607,7 @@ int afe_cmd_memory_unmap(u32 mem_map_handle)
			ret = -ENODEV;
			return ret;
		}
		rtac_set_afe_handle(this_afe.apr);
	}

	mregion.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
@@ -2637,6 +2651,7 @@ int afe_cmd_memory_unmap_nowait(u32 mem_map_handle)
			ret = -ENODEV;
			return ret;
		}
		rtac_set_afe_handle(this_afe.apr);
	}

	mregion.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
@@ -2674,6 +2689,7 @@ int afe_register_get_events(u16 port_id,
			ret = -ENODEV;
			return ret;
		}
		rtac_set_afe_handle(this_afe.apr);
	}
	if ((port_id == RT_PROXY_DAI_002_RX) ||
		(port_id == RT_PROXY_DAI_001_TX))
@@ -2722,6 +2738,7 @@ int afe_unregister_get_events(u16 port_id)
			ret = -ENODEV;
			return ret;
		}
		rtac_set_afe_handle(this_afe.apr);
	}

	if ((port_id == RT_PROXY_DAI_002_RX) ||
@@ -3020,6 +3037,7 @@ int afe_dtmf_generate_rx(int64_t duration_in_ms,
			ret = -ENODEV;
			return ret;
		}
		rtac_set_afe_handle(this_afe.apr);
	}

	pr_debug("dur=%lld: hfreq=%d lfreq=%d gain=%d portid=%x\n",
@@ -3578,21 +3596,21 @@ int afe_spk_prot_get_calib_data(struct afe_spkr_prot_get_vi_calib *calib_resp)
		goto fail_cmd;
	}
	index = q6audio_get_port_index(port);
	calib_resp->get_param.hdr.hdr_field =
	calib_resp->hdr.hdr_field =
	APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
	APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
	calib_resp->get_param.hdr.pkt_size = sizeof(*calib_resp);
	calib_resp->get_param.hdr.src_port = 0;
	calib_resp->get_param.hdr.dest_port = 0;
	calib_resp->get_param.hdr.token = index;
	calib_resp->get_param.hdr.opcode =  AFE_PORT_CMD_GET_PARAM_V2;
	calib_resp->hdr.pkt_size = sizeof(*calib_resp);
	calib_resp->hdr.src_port = 0;
	calib_resp->hdr.dest_port = 0;
	calib_resp->hdr.token = index;
	calib_resp->hdr.opcode =  AFE_PORT_CMD_GET_PARAM_V2;
	calib_resp->get_param.mem_map_handle = 0;
	calib_resp->get_param.module_id = AFE_MODULE_FB_SPKR_PROT_VI_PROC;
	calib_resp->get_param.param_id = AFE_PARAM_ID_CALIB_RES_CFG;
	calib_resp->get_param.payload_address_lsw = 0;
	calib_resp->get_param.payload_address_msw = 0;
	calib_resp->get_param.payload_size = sizeof(*calib_resp)
		- sizeof(calib_resp->get_param);
		- sizeof(calib_resp->get_param) - sizeof(calib_resp->hdr);
	calib_resp->get_param.port_id = q6audio_get_port_id(port);
	calib_resp->pdata.module_id = AFE_MODULE_FB_SPKR_PROT_VI_PROC;
	calib_resp->pdata.param_id = AFE_PARAM_ID_CALIB_RES_CFG;
@@ -4074,6 +4092,76 @@ err:
	return ret;
}

int afe_map_rtac_block(struct rtac_cal_block_data *cal_block)
{
	int	result = 0;
	pr_debug("%s:\n", __func__);

	if (cal_block == NULL) {
		pr_err("%s: cal_block is NULL!\n",
			__func__);
		result = -EINVAL;
		goto done;
	}

	if (cal_block->cal_data.paddr == 0) {
		pr_debug("%s: No address to map!\n",
			__func__);
		result = -EINVAL;
		goto done;
	}

	if (cal_block->map_data.map_size == 0) {
		pr_debug("%s: map size is 0!\n",
			__func__);
		result = -EINVAL;
		goto done;
	}

	result = afe_cmd_memory_map(cal_block->cal_data.paddr,
		cal_block->map_data.map_size);
	if (result < 0) {
		pr_err("%s: afe_cmd_memory_map failed for addr = 0x%pa, size = %d, err %d\n",
			__func__, &cal_block->cal_data.paddr,
			cal_block->map_data.map_size, result);
		return result;
	}
	cal_block->map_data.map_handle = this_afe.mmap_handle;

done:
	return result;
}

int afe_unmap_rtac_block(uint32_t *mem_map_handle)
{
	int	result = 0;
	pr_debug("%s:\n", __func__);

	if (mem_map_handle == NULL) {
		pr_err("%s: Map handle is NULL, nothing to unmap\n",
			__func__);
		goto done;
	}

	if (*mem_map_handle == 0) {
		pr_debug("%s: Map handle is 0, nothing to unmap\n",
			__func__);
		goto done;
	}

	result = afe_cmd_memory_unmap(*mem_map_handle);
	if (result) {
		pr_err("%s: AFE memory unmap failed %d, handle 0x%x\n",
		     __func__, result, *mem_map_handle);
		goto done;
	} else {
		*mem_map_handle = 0;
	}

done:
	return result;
}

static int __init afe_init(void)
{
	int i = 0;
Loading