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

Commit d68a532d authored by Surendar Karka's avatar Surendar Karka
Browse files

ASoC: msm: qdsp6v2: Add dynamic chmix config support



Add support to dynamically configure channel mixing weightage
coefficients for ASM sessions.

CRs-Fixed: 2235684
Change-Id: Ib184cda4d7f9752d0676c77cb8ff55f65cb30b3c
Signed-off-by: default avatarSurendar Karka <skarka@codeaurora.org>
parent 245d958f
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -28,6 +28,8 @@
#define AUD_VOL_BLOCK_SIZE	4096
#define AUDIO_RX_CALIBRATION_SIZE	(AUD_PROC_BLOCK_SIZE + \
						AUD_VOL_BLOCK_SIZE)
#define SESSION_TYPE_RX 0
#define SESSION_TYPE_TX 1
enum {
	ADM_CUSTOM_TOP_CAL = 0,
	ADM_AUDPROC_CAL,
@@ -180,5 +182,6 @@ int adm_get_source_tracking(int port_id, int copp_idx,
int adm_programable_channel_mixer(int port_id, int copp_idx, int session_id,
			int session_type,
			struct msm_pcm_channel_mixer *ch_mixer,
			int channel_index);
			int channel_index, bool use_default_chmap,
			char *ch_map);
#endif /* __Q6_ADM_V2_H__ */
+121 −2
Original line number Diff line number Diff line
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -3447,6 +3447,16 @@ static int msm_compr_probe(struct snd_soc_platform *platform)
	return 0;
}

static int msm_compr_chmix_cfg_ctl_info(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_info *uinfo)
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 128;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 0xFFFFFFFF;
	return 0;
}

static int msm_compr_volume_info(struct snd_kcontrol *kcontrol,
				 struct snd_ctl_elem_info *uinfo)
{
@@ -3765,6 +3775,113 @@ static int msm_compr_add_app_type_cfg_control(struct snd_soc_pcm_runtime *rtd)
	return 0;
}


static int msm_compr_chmix_cfg_ctl_put(struct snd_kcontrol *kcontrol,
					struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
	struct msm_compr_pdata *pdata = (struct msm_compr_pdata *)
				snd_soc_component_get_drvdata(comp);
	struct snd_compr_stream *cstream = NULL;
	struct snd_soc_pcm_runtime *rtd = NULL;
	u64 fe_id = kcontrol->private_value;
	int ip_channel_cnt, op_channel_cnt;
	int i, index = 0;
	int ch_coeff[PCM_FORMAT_MAX_NUM_CHANNEL * PCM_FORMAT_MAX_NUM_CHANNEL];
	bool use_default_chmap = true;
	char *chmap = NULL;

	pr_debug("%s: fe_id- %llu\n", __func__, fe_id);
	if (fe_id >= MSM_FRONTEND_DAI_MAX) {
		pr_err("%s: Received out of bounds fe_id %llu\n",
			__func__, fe_id);
		return -EINVAL;
	}
	cstream = pdata->cstream[fe_id];
	if (!cstream) {
		pr_err("%s: stream inactive\n", __func__);
		return -EINVAL;
	}
	rtd = cstream->private_data;
	if (!rtd) {
		pr_err("%s: stream inactive\n", __func__);
		return -EINVAL;
	}

	use_default_chmap = !(pdata->ch_map[rtd->dai_link->be_id]->set_ch_map);
	chmap = pdata->ch_map[rtd->dai_link->be_id]->channel_map;

	ip_channel_cnt = ucontrol->value.integer.value[index++];
	op_channel_cnt = ucontrol->value.integer.value[index++];
	/*
	 * wght coeff of first out channel corresponding to each in channel
	 * are sent followed by second out channel for each in channel etc.
	 */
	memset(ch_coeff, 0, sizeof(ch_coeff));
	for (i = 0; i < op_channel_cnt * ip_channel_cnt; i++) {
		ch_coeff[i] =
			ucontrol->value.integer.value[index++];
	}

	msm_pcm_routing_send_chmix_cfg(fe_id, ip_channel_cnt, op_channel_cnt,
			ch_coeff, SESSION_TYPE_RX, use_default_chmap, chmap);

	return 0;
}

static int msm_compr_chmix_cfg_ctl_get(struct snd_kcontrol *kcontrol,
					struct snd_ctl_elem_value *ucontrol)
{
	return 0;
}

static int msm_compr_add_chmix_cfg_controls(struct snd_soc_pcm_runtime *rtd)
{
	const char *mixer_ctl_name = "Audio Stream";
	const char *deviceNo       = "NN";
	const char *suffix         = "Channel Mix Cfg";
	int ctl_len;
	char *mixer_str = NULL;
	struct snd_kcontrol_new chmix_cfg_controls[1] = {
		{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "?",
		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
		.info = msm_compr_chmix_cfg_ctl_info,
		.get = msm_compr_chmix_cfg_ctl_get,
		.put = msm_compr_chmix_cfg_ctl_put,
		.private_value = 0,
		}
	};

	if (!rtd) {
		pr_err("%s NULL rtd\n", __func__);
		return -EINVAL;
	}

	pr_debug("%s: added new compr FE with name %s, id %d, cpu dai %s, device no %d\n",
		 __func__, rtd->dai_link->name, rtd->dai_link->be_id,
		 rtd->dai_link->cpu_dai_name, rtd->pcm->device);

	ctl_len = strlen(mixer_ctl_name) + 1 + strlen(deviceNo) + 1 +
		  strlen(suffix) + 1;
	mixer_str = kzalloc(ctl_len, GFP_KERNEL);
	if (!mixer_str)
		return -ENOMEM;

	snprintf(mixer_str, ctl_len, "%s %d %s", mixer_ctl_name,
		 rtd->pcm->device, suffix);

	chmix_cfg_controls[0].name = mixer_str;
	chmix_cfg_controls[0].private_value = rtd->dai_link->be_id;
	pr_debug("%s: Registering new mixer ctl %s", __func__, mixer_str);
	snd_soc_add_platform_controls(rtd->platform,
				      chmix_cfg_controls,
				      ARRAY_SIZE(chmix_cfg_controls));
	kfree(mixer_str);
	return 0;
}

static int msm_compr_add_channel_map_control(struct snd_soc_pcm_runtime *rtd)
{
	const char *mixer_ctl_name = "Playback Channel Map";
@@ -3795,7 +3912,6 @@ static int msm_compr_add_channel_map_control(struct snd_soc_pcm_runtime *rtd)

	ctl_len = strlen(mixer_ctl_name) + strlen(deviceNo) + 1;
	mixer_str = kzalloc(ctl_len, GFP_KERNEL);

	if (!mixer_str) {
		pr_err("%s: failed to allocate mixer ctrl str of len %d\n",
			__func__, ctl_len);
@@ -3854,6 +3970,9 @@ static int msm_compr_new(struct snd_soc_pcm_runtime *rtd)
	if (rc)
		pr_err("%s: Could not add Compr Channel Map Control\n",
			__func__);
	rc = msm_compr_add_chmix_cfg_controls(rtd);
	if (rc)
		pr_err("%s: add chmix cfg controls failed:%d\n", __func__, rc);
	return 0;
}

+149 −1
Original line number Diff line number Diff line
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -1563,6 +1563,150 @@ static int msm_pcm_add_app_type_controls(struct snd_soc_pcm_runtime *rtd)
	return 0;
}

static int msm_pcm_chmix_cfg_ctl_info(struct snd_kcontrol *kcontrol,
					struct snd_ctl_elem_info *uinfo)
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 128;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 0xFFFFFFFF;
	return 0;
}

static int msm_pcm_chmix_cfg_ctl_put(struct snd_kcontrol *kcontrol,
					struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_component *usr_info = snd_kcontrol_chip(kcontrol);
	struct snd_soc_platform *platform;
	struct msm_plat_data *pdata;
	struct snd_pcm_substream *substream;
	struct msm_audio *prtd;
	u64 fe_id = kcontrol->private_value;
	int ip_channel_cnt, op_channel_cnt;
	int i, index = 0, ret = 0;
	int ch_coeff[PCM_FORMAT_MAX_NUM_CHANNEL * PCM_FORMAT_MAX_NUM_CHANNEL];
	bool use_default_chmap = true;
	char *ch_map = NULL;

	pr_debug("%s: fe_id- %llu\n", __func__, fe_id);
	if (fe_id >= MSM_FRONTEND_DAI_MAX) {
		pr_err("%s: Received out of bounds fe_id %llu\n",
			__func__, fe_id);
		ret = -EINVAL;
		goto done;
	}

	if (!usr_info) {
		pr_err("%s: usr_info is null\n", __func__);
		ret = -EINVAL;
		goto done;
	}
	platform = snd_soc_component_to_platform(usr_info);
	if (!platform) {
		pr_err("%s: platform is null\n", __func__);
		ret = -EINVAL;
		goto done;
	}
	pdata = dev_get_drvdata(platform->dev);
	if (!pdata) {
		pr_err("%s: pdata is null\n", __func__);
		ret = -EINVAL;
		goto done;
	}
	substream = pdata->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;

	if (!substream) {
		pr_err("%s substream not found\n", __func__);
		return -ENODEV;
	}
	if (!substream->runtime) {
		pr_err("%s substream runtime not found\n", __func__);
		ret = -EINVAL;
		goto done;
	}
	prtd = substream->runtime->private_data;
	if (!prtd) {
		pr_err("%s: stream inactive\n", __func__);
		ret = -EINVAL;
		goto done;
	}
	use_default_chmap = !prtd->set_channel_map;
	ch_map = prtd->channel_map;
	ip_channel_cnt = ucontrol->value.integer.value[index++];
	op_channel_cnt = ucontrol->value.integer.value[index++];
	/*
	 * wght coeff of first out channel corresponding to each in channel
	 * are sent followed by second out channel for each in channel etc.
	 */
	memset(ch_coeff, 0, sizeof(ch_coeff));
	for (i = 0; i < op_channel_cnt * ip_channel_cnt; i++) {
		ch_coeff[i] =
			ucontrol->value.integer.value[index++];
	}

	msm_pcm_routing_send_chmix_cfg(fe_id, ip_channel_cnt, op_channel_cnt,
			ch_coeff, SESSION_TYPE_RX, use_default_chmap, ch_map);
done:
	return ret;
}

static int msm_pcm_chmix_cfg_ctl_get(struct snd_kcontrol *kcontrol,
					struct snd_ctl_elem_value *ucontrol)
{
	return 0;
}

static int msm_pcm_add_chmix_cfg_controls(struct snd_soc_pcm_runtime *rtd)
{
	const char *mixer_ctl_name = "Audio Stream";
	const char *deviceNo       = "NN";
	const char *suffix         = "Channel Mix Cfg";
	char *mixer_str = NULL;
	int ctl_len = 0;
	struct msm_plat_data *pdata;
	struct snd_kcontrol_new chmix_cfg_controls[1] = {
		{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "?",
		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
		.info = msm_pcm_chmix_cfg_ctl_info,
		.get = msm_pcm_chmix_cfg_ctl_get,
		.put = msm_pcm_chmix_cfg_ctl_put,
		.private_value = 0,
		}
	};

	if (!rtd) {
		pr_err("%s: NULL rtd\n", __func__);
		return -EINVAL;
	}

	ctl_len = strlen(mixer_ctl_name) + 1 +
		  strlen(deviceNo) + 1 + strlen(suffix) + 1;
	mixer_str = kzalloc(ctl_len, GFP_KERNEL);
	if (!mixer_str)
		return -ENOMEM;

	snprintf(mixer_str, ctl_len, "%s %d %s",
		 mixer_ctl_name, rtd->pcm->device, suffix);
	chmix_cfg_controls[0].name = mixer_str;
	chmix_cfg_controls[0].private_value = rtd->dai_link->be_id;
	pr_debug("%s: Registering new mixer ctl %s\n", __func__, mixer_str);
	pdata = dev_get_drvdata(rtd->platform->dev);
	if (pdata) {
		if (!pdata->pcm)
			pdata->pcm = rtd->pcm;
		snd_soc_add_platform_controls(rtd->platform,
					      chmix_cfg_controls,
					      ARRAY_SIZE(chmix_cfg_controls));
	} else {
		pr_err("%s: NULL pdata\n", __func__);
		return -EINVAL;
	}
	kfree(mixer_str);
	return 0;
}

static int msm_pcm_add_controls(struct snd_soc_pcm_runtime *rtd)
{
	int ret = 0;
@@ -1580,6 +1724,10 @@ static int msm_pcm_add_controls(struct snd_soc_pcm_runtime *rtd)
		pr_err("%s: Could not add pcm topology control %d\n",
			__func__, ret);
	}

	ret = msm_pcm_add_chmix_cfg_controls(rtd);
	if (ret)
		pr_err("%s: add chmix cfg controls failed:%d\n", __func__, ret);
	return ret;
}

+1 −0
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ struct output_meta_data_st {
struct msm_plat_data {
	int perf_mode;
	int perf_mode_set;
	struct snd_pcm *pcm;
};

#endif /*_MSM_PCM_H*/
+76 −1
Original line number Diff line number Diff line
@@ -670,6 +670,78 @@ static bool is_mm_lsm_fe_id(int fe_id)
	return rc;
}
/*
 * msm_pcm_routing_send_chmix_cfg
 *
 * Receives fe_id, ip_channel_cnt, op_channel_cnt, channel weight, session_type
 * use_default_chmap and channel map to map in channel mixer and send to
 * adm programmable matrix.
 *
 * fe_id - Passed value, frontend id which is wanted
 * ip_channel_cnt - Passed value, number of input channels
 * op_channel_cnt - Passed value, number of output channels
 * ch_wght_coeff - Passed reference, weights for each output channel
 * session_type - Passed value, session_type for RX or TX
 * use_default_chmap - true if default channel map  to be used
 * ch_map - input/output channel map for playback/capture session respectively
 */
int msm_pcm_routing_send_chmix_cfg(int fe_id, int ip_channel_cnt,
				   int op_channel_cnt, int *ch_wght_coeff,
				   int session_type, bool use_default_chmap,
				   char *channel_map)
{
	int rc = 0, idx = 0, i, j;
	int be_index = 0, port_id, index = 0;
	unsigned int session_id = 0;
	pr_debug("%s: fe_id[%d] ip_ch[%d] op_ch[%d] sess_type [%d]\n",
		 __func__, fe_id, ip_channel_cnt, op_channel_cnt, session_type);
	if (!use_default_chmap && (channel_map == NULL)) {
		pr_err("%s: No valid chan map and can't use default\n",
			__func__);
		return -EINVAL;
	}
	if ((ch_wght_coeff == NULL) || (op_channel_cnt > ADM_MAX_CHANNELS) ||
	     (ip_channel_cnt > ADM_MAX_CHANNELS)) {
		pr_err("%s: Invalid channels or null coefficients\n", __func__);
		return -EINVAL;
	}
	for (be_index = 0; be_index < MSM_BACKEND_DAI_MAX; be_index++) {
		port_id = msm_bedais[be_index].port_id;
		if (!msm_bedais[be_index].active ||
			!test_bit(fe_id, &msm_bedais[be_index].fe_sessions))
			continue;
		session_id = fe_dai_map[fe_id][session_type].strm_id;
		channel_mixer[fe_id].input_channels[0] = ip_channel_cnt;
		channel_mixer[fe_id].output_channel = op_channel_cnt;
		channel_mixer[fe_id].rule = 0;
		for (j = 0; j < op_channel_cnt; j++) {
			for (i = 0; i < ip_channel_cnt; i++)
				channel_mixer[fe_id].channel_weight[j][i] =
						ch_wght_coeff[index++];
		}
		for (idx = 0; idx < MAX_COPPS_PER_PORT; idx++) {
			unsigned long copp =
				session_copp_map[fe_id][session_type][be_index];
			if (!test_bit(idx, &copp))
				continue;
			rc = adm_programable_channel_mixer(port_id,
					idx, session_id, session_type,
					channel_mixer + fe_id, 0,
					use_default_chmap, channel_map);
			if (rc < 0)
				pr_err("%s: err setting channel mix config\n",
					__func__);
		}
	}
	return 0;
}
void msm_pcm_routing_reg_stream_app_type_cfg(int fedai_id, int app_type,
	int acdb_dev_id, int sample_rate, int session_type)
@@ -1127,6 +1199,8 @@ static int msm_pcm_routing_channel_mixer(int fe_id, bool perf_mode,
	int sess_type = 0;
	int i = 0, j = 0, be_id;
	int ret = 0;
	bool use_default_chmap = true;
	char *ch_map = NULL;
	if (fe_id >= MSM_FRONTEND_DAI_MM_SIZE) {
		pr_err("%s: invalid FE %d\n", __func__, fe_id);
@@ -1169,7 +1243,8 @@ static int msm_pcm_routing_channel_mixer(int fe_id, bool perf_mode,
			ret = adm_programable_channel_mixer(
					msm_bedais[be_id].port_id,
					copp_idx, dspst_id, sess_type,
					channel_mixer + fe_id, i);
					channel_mixer + fe_id, i,
					use_default_chmap, ch_map);
		}
	}
Loading