static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	struct q6audio_aio *audio = file->private_data;
	int rc = 0;
	switch (cmd) {
	case AUDIO_START: {
		struct asm_aac_cfg aac_cfg;
		struct msm_audio_aac_config *aac_config;
		uint32_t sbr_ps = 0x00;
		pr_debug("%s: AUDIO_START session_id[%d]\n", __func__,
							audio->ac->session);
		if (audio->feedback == NON_TUNNEL_MODE) {
			
			rc = q6asm_enc_cfg_blk_pcm(audio->ac, 0, 0);
			if (rc < 0) {
				pr_err("pcm output block config failed\n");
				break;
			}
		}
		
		rc = q6asm_enable_sbrps(audio->ac, sbr_ps);
		if (rc < 0)
			pr_err("sbr-ps enable failed\n");
		aac_config = (struct msm_audio_aac_config *)audio->codec_cfg;
		if (aac_config->sbr_ps_on_flag)
			aac_cfg.aot = AAC_ENC_MODE_EAAC_P;
		else if (aac_config->sbr_on_flag)
			aac_cfg.aot = AAC_ENC_MODE_AAC_P;
		else
			aac_cfg.aot = AAC_ENC_MODE_AAC_LC;

		switch (aac_config->format) {
		case AUDIO_AAC_FORMAT_ADTS:
			aac_cfg.format = 0x00;
			break;
		case AUDIO_AAC_FORMAT_LOAS:
			aac_cfg.format = 0x01;
			break;
		case AUDIO_AAC_FORMAT_ADIF:
			aac_cfg.format = 0x02;
			break;
		default:
		case AUDIO_AAC_FORMAT_RAW:
			aac_cfg.format = 0x03;
		}
		aac_cfg.ep_config = aac_config->ep_config;
		aac_cfg.section_data_resilience =
			aac_config->aac_section_data_resilience_flag;
		aac_cfg.scalefactor_data_resilience =
			aac_config->aac_scalefactor_data_resilience_flag;
		aac_cfg.spectral_data_resilience =
			aac_config->aac_spectral_data_resilience_flag;
		aac_cfg.ch_cfg = audio->pcm_cfg.channel_count;
		if (audio->feedback == TUNNEL_MODE) {
			aac_cfg.sample_rate = aac_config->sample_rate;
			aac_cfg.ch_cfg = aac_config->channel_configuration;
		} else {
			aac_cfg.sample_rate =  audio->pcm_cfg.sample_rate;
			aac_cfg.ch_cfg = audio->pcm_cfg.channel_count;
		}

		pr_debug("%s:format=%x aot=%d  ch=%d sr=%d\n",
			__func__, aac_cfg.format,
			aac_cfg.aot, aac_cfg.ch_cfg,
			aac_cfg.sample_rate);

		
		rc = q6asm_media_format_block_aac(audio->ac, &aac_cfg);
		if (rc < 0) {
			pr_err("cmd media format block failed\n");
			break;
		}
		rc = audio_aio_enable(audio);
		audio->eos_rsp = 0;
		audio->eos_flag = 0;
		if (!rc) {
			audio->enabled = 1;
		} else {
			audio->enabled = 0;
			pr_err("Audio Start procedure failed rc=%d\n", rc);
			break;
		}
		pr_info("%s: AUDIO_START sessionid[%d]enable[%d]\n", __func__,
						audio->ac->session,
						audio->enabled);
		if (audio->stopped == 1)
			audio->stopped = 0;
		break;
	}
	case AUDIO_GET_AAC_CONFIG: {
		if (copy_to_user((void *)arg, audio->codec_cfg,
			sizeof(struct msm_audio_aac_config))) {
			rc = -EFAULT;
			break;
		}
		break;
	}
	case AUDIO_SET_AAC_CONFIG: {
		struct msm_audio_aac_config *aac_config;
		pr_debug("%s: AUDIO_SET_AAC_CONFIG\n", __func__);
		if (copy_from_user(audio->codec_cfg, (void *)arg,
			sizeof(struct msm_audio_aac_config))) {
			rc = -EFAULT;
			break;
		} else {
			uint16_t sce_left = 1, sce_right = 2;
			aac_config = audio->codec_cfg;
			
			if (aac_config->dual_mono_mode >
			    AUDIO_AAC_DUAL_MONO_PL_SR) {
				pr_err("%s:AUDIO_SET_AAC_CONFIG: Invalid"
					"dual_mono mode =%d\n", __func__,
					aac_config->dual_mono_mode);
			} else {
				pr_debug("%s: AUDIO_SET_AAC_CONFIG: modify"
					 "dual_mono mode =%d\n", __func__,
					 aac_config->dual_mono_mode);
				switch (aac_config->dual_mono_mode) {
				case AUDIO_AAC_DUAL_MONO_PL_PR:
					sce_left = 1;
					sce_right = 1;
					break;
				case AUDIO_AAC_DUAL_MONO_SL_SR:
					sce_left = 2;
					sce_right = 2;
					break;
				case AUDIO_AAC_DUAL_MONO_SL_PR:
					sce_left = 2;
					sce_right = 1;
					break;
				case AUDIO_AAC_DUAL_MONO_PL_SR:
				default:
					sce_left = 1;
					sce_right = 2;
					break;
				}
				rc = q6asm_cfg_dual_mono_aac(audio->ac,
							sce_left, sce_right);
				if (rc < 0)
					pr_err("%s: asm cmd dualmono failed"
						" rc=%d\n", __func__, rc);
			}
		}
		break;
	}
	case AUDIO_SET_Q6_EFFECT: {
		struct param {
			uint32_t effect_type; 
			uint32_t module_id;
			uint32_t param_id;
			uint32_t payload_size;
		} q6_param;
		void *payload;

		pr_aud_info("AUDIO_SET_Q6_EFFECT, session %d ++++\n", audio->ac->session);
		if (copy_from_user(&q6_param, (void *) arg,
					sizeof(q6_param))) {
			pr_aud_err("%s: copy param from user failed\n",
				__func__);
			rc = -EFAULT;
			break;
		}

		if (q6_param.payload_size <= 0 ||
		    (q6_param.effect_type != 0 &&
		     q6_param.effect_type != 1)) {
			pr_aud_err("%s: unsupported param: %d, 0x%x, 0x%x, %d\n",
				__func__, q6_param.effect_type,
				q6_param.module_id, q6_param.param_id,
				q6_param.payload_size);
			rc = -EINVAL;
			break;
		}

		payload = kzalloc(q6_param.payload_size, GFP_KERNEL);
		if (!payload) {
			pr_aud_err("%s: failed to allocate memory\n",
				__func__);
			rc = -ENOMEM;
			break;
		}
		if (copy_from_user(payload, (void *) (arg + sizeof(q6_param)),
			q6_param.payload_size)) {
			pr_aud_err("%s: copy payload from user failed\n",
				__func__);
			kfree(payload);
			rc = -EFAULT;
			break;;
		}

		if (q6_param.effect_type == 0) { 
			rc = q6asm_enable_effect(audio->ac,
						q6_param.module_id,
						q6_param.param_id,
						q6_param.payload_size,
						payload);
			pr_aud_info("q6asm_enable_effect, return %d (session %d)\n", rc, audio->ac->session);
		}
#if Q6_EFFECT_DEBUG
		{
			int *ptr;
			int i;
			ptr = (int *)payload;
			for (i = 0; i < (q6_param.payload_size / 4); i++)
				pr_aud_info("0x%08x", *(ptr + i));
		}
#endif
		kfree(payload);
		pr_aud_info("AUDIO_SET_Q6_EFFECT, session %d ---\n", audio->ac->session);
		break;
	}

	default:
		
		rc = audio->codec_ioctl(file, cmd, arg);
		if (rc)
			pr_err("%s[%p]:Failed in utils_ioctl: %d\n",
				__func__, audio, rc);
	}
	return rc;
}
Example #2
0
static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	struct q6audio_aio *audio = file->private_data;
	int rc = 0;

	switch (cmd) {
	case AUDIO_START: {
		struct asm_aac_cfg aac_cfg;
		struct msm_audio_aac_config *aac_config;
		uint32_t sbr_ps = 0x00;
		pr_debug("%s: AUDIO_START session_id[%d]\n", __func__,
						audio->ac->session);
		if (audio->feedback == NON_TUNNEL_MODE) {
			/* Configure PCM output block */
			rc = q6asm_enc_cfg_blk_pcm(audio->ac,
				0, /*native sampling rate*/
				0 /*native channel count*/);
			if (rc < 0) {
				pr_err("pcm output block config failed\n");
				break;
			}
		}
		/* turn on both sbr and ps */
		rc = q6asm_enable_sbrps(audio->ac, sbr_ps);
		if (rc < 0)
			pr_err("sbr-ps enable failed\n");
		aac_config = (struct msm_audio_aac_config *)audio->codec_cfg;
		if (aac_config->sbr_ps_on_flag)
			aac_cfg.aot = AAC_ENC_MODE_EAAC_P;
		else if (aac_config->sbr_on_flag)
			aac_cfg.aot = AAC_ENC_MODE_AAC_P;
		else
			aac_cfg.aot = AAC_ENC_MODE_AAC_LC;

		switch (aac_config->format) {
		case AUDIO_AAC_FORMAT_ADTS:
			aac_cfg.format = 0x00;
			break;
		case AUDIO_AAC_FORMAT_LOAS:
			aac_cfg.format = 0x01;
			break;
		case AUDIO_AAC_FORMAT_ADIF:
			aac_cfg.format = 0x02;
			break;
		default:
		case AUDIO_AAC_FORMAT_RAW:
			aac_cfg.format = 0x03;
		}
		aac_cfg.ep_config = aac_config->ep_config;
		aac_cfg.section_data_resilience =
			aac_config->aac_section_data_resilience_flag;
		aac_cfg.scalefactor_data_resilience =
			aac_config->aac_scalefactor_data_resilience_flag;
		aac_cfg.spectral_data_resilience =
			aac_config->aac_spectral_data_resilience_flag;
		aac_cfg.ch_cfg = aac_config->channel_configuration;
		aac_cfg.sample_rate =  audio->pcm_cfg.sample_rate;

		pr_debug("%s:format=%x aot=%d  ch=%d sr=%d\n",
			__func__, aac_cfg.format,
			aac_cfg.aot, aac_cfg.ch_cfg,
			aac_cfg.sample_rate);

		/* Configure Media format block */
		rc = q6asm_media_format_block_multi_aac(audio->ac, &aac_cfg);
		if (rc < 0) {
			pr_err("cmd media format block failed\n");
			break;
		}
		if (!cpu_is_msm8x60()) {
			rc = q6asm_set_encdec_chan_map(audio->ac, 2);
			if (rc < 0) {
				pr_err("%s: cmd set encdec_chan_map failed\n",
					__func__);
				break;
			}
		}
		rc = audio_aio_enable(audio);
		audio->eos_rsp = 0;
		audio->eos_flag = 0;
		if (!rc) {
			audio->enabled = 1;
		} else {
			audio->enabled = 0;
			pr_err("Audio Start procedure failed rc=%d\n", rc);
			break;
		}
		pr_info("%s: AUDIO_START sessionid[%d]enable[%d]\n", __func__,
						audio->ac->session,
						audio->enabled);
		if (audio->stopped == 1)
			audio->stopped = 0;
		break;
	}
	case AUDIO_GET_AAC_CONFIG: {
		if (copy_to_user((void *)arg, audio->codec_cfg,
			sizeof(struct msm_audio_aac_config))) {
			rc = -EFAULT;
			break;
		}
		break;
	}
	case AUDIO_SET_AAC_CONFIG: {
		struct msm_audio_aac_config *aac_config;
		if (copy_from_user(audio->codec_cfg, (void *)arg,
			sizeof(struct msm_audio_aac_config))) {
			rc = -EFAULT;
		} else {
			uint16_t sce_left = 1, sce_right = 2;
			aac_config = audio->codec_cfg;
			if (aac_config->dual_mono_mode >
				AUDIO_AAC_DUAL_MONO_PL_SR) {
				pr_err("%s:AUDIO_SET_AAC_CONFIG: Invalid"
					"dual_mono mode =%d\n", __func__,
					aac_config->dual_mono_mode);
			} else {
				/* convert the data from user into sce_left
				 * and sce_right based on the definitions
				 */
				pr_debug("%s: AUDIO_SET_AAC_CONFIG: modify"
					 "dual_mono mode =%d\n", __func__,
					 aac_config->dual_mono_mode);
				switch (aac_config->dual_mono_mode) {
				case AUDIO_AAC_DUAL_MONO_PL_PR:
					sce_left = 1;
					sce_right = 1;
					break;
				case AUDIO_AAC_DUAL_MONO_SL_SR:
					sce_left = 2;
					sce_right = 2;
					break;
				case AUDIO_AAC_DUAL_MONO_SL_PR:
					sce_left = 2;
					sce_right = 1;
					break;
				case AUDIO_AAC_DUAL_MONO_PL_SR:
				default:
					sce_left = 1;
					sce_right = 2;
					break;
				}
				rc = q6asm_cfg_dual_mono_aac(audio->ac,
							sce_left, sce_right);
				if (rc < 0)
					pr_err("%s: asm cmd dualmono failed"
						" rc=%d\n", __func__, rc);
			}			break;
		}
		break;
	}
	default:
		pr_debug("Calling utils ioctl\n");
		rc = audio->codec_ioctl(file, cmd, arg);
	}
	return rc;
}
static long audio_ioctl_shared(struct file *file, unsigned int cmd,
						void *arg)
{
	struct q6audio_aio *audio = file->private_data;
	int rc = 0;

	switch (cmd) {
	case AUDIO_START: {
		struct asm_aac_cfg aac_cfg;
		struct msm_audio_aac_config *aac_config;
		uint32_t sbr_ps = 0x00;
		aac_config = (struct msm_audio_aac_config *)audio->codec_cfg;
		if (audio->feedback == TUNNEL_MODE) {
			aac_cfg.sample_rate = aac_config->sample_rate;
			aac_cfg.ch_cfg = aac_config->channel_configuration;
		} else {
			aac_cfg.sample_rate =  audio->pcm_cfg.sample_rate;
			aac_cfg.ch_cfg = audio->pcm_cfg.channel_count;
		}
		pr_debug("%s: AUDIO_START session_id[%d]\n", __func__,
						audio->ac->session);
		if (audio->feedback == NON_TUNNEL_MODE) {
			/* Configure PCM output block */
			rc = q6asm_enc_cfg_blk_pcm_native(audio->ac,
				aac_cfg.sample_rate,
				aac_cfg.ch_cfg);
			if (rc < 0) {
				pr_err("pcm output block config failed\n");
				break;
			}
		}
		/* turn on both sbr and ps */
		rc = q6asm_enable_sbrps(audio->ac, sbr_ps);
		if (rc < 0)
			pr_err("sbr-ps enable failed\n");
		if (aac_config->sbr_ps_on_flag)
			aac_cfg.aot = AAC_ENC_MODE_EAAC_P;
		else if (aac_config->sbr_on_flag)
			aac_cfg.aot = AAC_ENC_MODE_AAC_P;
		else
			aac_cfg.aot = AAC_ENC_MODE_AAC_LC;

		switch (aac_config->format) {
		case AUDIO_AAC_FORMAT_ADTS:
			aac_cfg.format = 0x00;
			break;
		case AUDIO_AAC_FORMAT_LOAS:
			aac_cfg.format = 0x01;
			break;
		case AUDIO_AAC_FORMAT_ADIF:
			aac_cfg.format = 0x02;
			break;
		default:
		case AUDIO_AAC_FORMAT_RAW:
			aac_cfg.format = 0x03;
		}
		aac_cfg.ep_config = aac_config->ep_config;
		aac_cfg.section_data_resilience =
			aac_config->aac_section_data_resilience_flag;
		aac_cfg.scalefactor_data_resilience =
			aac_config->aac_scalefactor_data_resilience_flag;
		aac_cfg.spectral_data_resilience =
			aac_config->aac_spectral_data_resilience_flag;

		pr_debug("%s:format=%x aot=%d  ch=%d sr=%d\n",
			__func__, aac_cfg.format,
			aac_cfg.aot, aac_cfg.ch_cfg,
			aac_cfg.sample_rate);

		/* Configure Media format block */
		rc = q6asm_media_format_block_multi_aac(audio->ac, &aac_cfg);
		if (rc < 0) {
			pr_err("cmd media format block failed\n");
			break;
		}
		rc = q6asm_set_encdec_chan_map(audio->ac, 2);
		if (rc < 0) {
			pr_err("%s: cmd set encdec_chan_map failed\n",
				__func__);
			break;
		}
		rc = audio_aio_enable(audio);
		audio->eos_rsp = 0;
		audio->eos_flag = 0;
		if (!rc) {
			audio->enabled = 1;
		} else {
			audio->enabled = 0;
			pr_err("Audio Start procedure failed rc=%d\n", rc);
			break;
		}
		pr_info("%s: AUDIO_START sessionid[%d]enable[%d]\n", __func__,
						audio->ac->session,
						audio->enabled);
		if (audio->stopped == 1)
			audio->stopped = 0;
		break;
	}
	case AUDIO_SET_AAC_CONFIG: {
		struct msm_audio_aac_config *aac_config;
		uint16_t sce_left = 1, sce_right = 2;

		if (arg == NULL) {
			pr_err("%s: NULL config pointer\n", __func__);
			rc = -EINVAL;
			break;
		}
		memcpy(audio->codec_cfg, arg,
				sizeof(struct msm_audio_aac_config));
		aac_config = audio->codec_cfg;
		if (aac_config->dual_mono_mode >
		    AUDIO_AAC_DUAL_MONO_PL_SR) {
			pr_err("%s:AUDIO_SET_AAC_CONFIG: Invalid dual_mono mode =%d\n",
				 __func__, aac_config->dual_mono_mode);
		} else {
			/* convert the data from user into sce_left
			 * and sce_right based on the definitions
			 */
			pr_debug("%s: AUDIO_SET_AAC_CONFIG: modify dual_mono mode =%d\n",
				 __func__, aac_config->dual_mono_mode);
			switch (aac_config->dual_mono_mode) {
			case AUDIO_AAC_DUAL_MONO_PL_PR:
				sce_left = 1;
				sce_right = 1;
				break;
			case AUDIO_AAC_DUAL_MONO_SL_SR:
				sce_left = 2;
				sce_right = 2;
				break;
			case AUDIO_AAC_DUAL_MONO_SL_PR:
				sce_left = 2;
				sce_right = 1;
				break;
			case AUDIO_AAC_DUAL_MONO_PL_SR:
			default:
				sce_left = 1;
				sce_right = 2;
				break;
			}
			rc = q6asm_cfg_dual_mono_aac(audio->ac,
						sce_left, sce_right);
			if (rc < 0)
				pr_err("%s: asm cmd dualmono failed rc=%d\n",
							 __func__, rc);
		}			break;
		break;
	}
	case AUDIO_SET_AAC_MIX_CONFIG:	{
		u32 *mix_coeff = (u32 *)arg;
		if (!arg) {
			pr_err("%s: Invalid param for %s\n",
				__func__, "AUDIO_SET_AAC_MIX_CONFIG");
			rc = -EINVAL;
			break;
		}
		pr_debug("%s, AUDIO_SET_AAC_MIX_CONFIG", __func__);
		pr_debug("%s, value of coeff = %d",
					__func__, *mix_coeff);
		q6asm_cfg_aac_sel_mix_coef(audio->ac, *mix_coeff);
		if (rc < 0)
			pr_err("%s asm aac_sel_mix_coef failed rc=%d\n",
				 __func__, rc);
		break;
	}
	default:
		pr_err("%s: Unknown ioctl cmd = %d", __func__, cmd);
		rc = -EINVAL;
		break;
	}
	return rc;
}