static int msm_compr_open(struct snd_pcm_substream *substream)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
	struct compr_audio *compr;
	struct msm_audio *prtd;
	int ret = 0;

	/* Capture path */
	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
		return -EINVAL;

	pr_debug("%s\n", __func__);
	compr = kzalloc(sizeof(struct compr_audio), GFP_KERNEL);
	if (compr == NULL) {
		pr_err("Failed to allocate memory for msm_audio\n");
		return -ENOMEM;
	}
	prtd = &compr->prtd;
	prtd->substream = substream;
	prtd->audio_client = q6asm_audio_client_alloc(
				(app_cb)compr_event_handler, compr);
	if (!prtd->audio_client) {
		pr_info("%s: Could not allocate memory\n", __func__);
		kfree(prtd);
		return -ENOMEM;
	}
	prtd->audio_client->perf_mode = false;
	runtime->hw = msm_compr_hardware_playback;

	pr_info("%s: session ID %d\n", __func__, prtd->audio_client->session);

	prtd->session_id = prtd->audio_client->session;
	msm_pcm_routing_reg_phy_stream(soc_prtd->dai_link->be_id,
			prtd->audio_client->perf_mode,
			prtd->session_id, substream->stream);

	prtd->cmd_ack = 1;

	ret = snd_pcm_hw_constraint_list(runtime, 0,
			SNDRV_PCM_HW_PARAM_RATE,
			&constraints_sample_rates);
	if (ret < 0)
		pr_info("snd_pcm_hw_constraint_list failed\n");
	/* Ensure that buffer size is a multiple of period size */
	ret = snd_pcm_hw_constraint_integer(runtime,
			    SNDRV_PCM_HW_PARAM_PERIODS);
	if (ret < 0)
		pr_info("snd_pcm_hw_constraint_integer failed\n");

	prtd->dsp_cnt = 0;
	atomic_set(&prtd->pending_buffer, 1);
	compr->codec = FORMAT_MP3;
	populate_codec_list(compr, runtime);
	runtime->private_data = compr;

	return 0;
}
static int msm_compr_configure_dsp(struct snd_compr_stream *cstream)
{
	struct snd_compr_runtime *runtime = cstream->runtime;
	struct msm_compr_audio *prtd = runtime->private_data;
	struct snd_soc_pcm_runtime *soc_prtd = cstream->private_data;
	uint16_t bits_per_sample = 16;
	int dir = IN, ret = 0;
	struct audio_client *ac = prtd->audio_client;
	struct asm_softpause_params softpause = {
		.enable = SOFT_PAUSE_ENABLE,
		.period = SOFT_PAUSE_PERIOD,
		.step = SOFT_PAUSE_STEP,
		.rampingcurve = SOFT_PAUSE_CURVE_LINEAR,
	};
	struct asm_softvolume_params softvol = {
		.period = SOFT_VOLUME_PERIOD,
		.step = SOFT_VOLUME_STEP,
		.rampingcurve = SOFT_VOLUME_CURVE_LINEAR,
	};

	pr_debug("%s\n", __func__);
	ret = q6asm_stream_open_write_v2(ac,
				prtd->codec, bits_per_sample,
				ac->stream_id,
				prtd->gapless_state.use_dsp_gapless_mode);
	if (ret < 0) {
		pr_err("%s: Session out open failed\n", __func__);
		 return -ENOMEM;
	}

	prtd->gapless_state.stream_opened[ac->stream_id] = 1;
	pr_debug("%s be_id %d\n", __func__, soc_prtd->dai_link->be_id);
	msm_pcm_routing_reg_phy_stream(soc_prtd->dai_link->be_id,
				ac->perf_mode,
				prtd->session_id,
				SNDRV_PCM_STREAM_PLAYBACK);

	ret = msm_compr_set_volume(cstream, 0, 0);
	if (ret < 0)
		pr_err("%s : Set Volume failed : %d", __func__, ret);

	ret = q6asm_set_softpause(ac, &softpause);
	if (ret < 0)
		pr_err("%s: Send SoftPause Param failed ret=%d\n",
			__func__, ret);

	ret = q6asm_set_softvolume(ac, &softvol);
	if (ret < 0)
		pr_err("%s: Send SoftVolume Param failed ret=%d\n",
			__func__, ret);

	ret = q6asm_set_io_mode(ac, (COMPRESSED_IO | ASYNC_IO_MODE));
	if (ret < 0) {
		pr_err("%s: Set IO mode failed\n", __func__);
		return -EINVAL;
	}

	runtime->fragments = prtd->codec_param.buffer.fragments;
	runtime->fragment_size = prtd->codec_param.buffer.fragment_size;
	pr_debug("allocate %d buffers each of size %d\n",
			runtime->fragments,
			runtime->fragment_size);
	ret = q6asm_audio_client_buf_alloc_contiguous(dir, ac,
					runtime->fragment_size,
					runtime->fragments);
	if (ret < 0) {
		pr_err("Audio Start: Buffer Allocation failed rc = %d\n", ret);
		return -ENOMEM;
	}

	prtd->byte_offset  = 0;
	prtd->copied_total = 0;
	prtd->app_pointer  = 0;
	prtd->bytes_received = 0;
	prtd->buffer       = ac->port[dir].buf[0].data;
	prtd->buffer_paddr = ac->port[dir].buf[0].phys;
	prtd->buffer_size  = runtime->fragments * runtime->fragment_size;

	ret = msm_compr_send_media_format_block(cstream, ac->stream_id);
	if (ret < 0)
		pr_err("%s, failed to send media format block\n", __func__);

	return ret;
}
Exemple #3
0
static int msm_compr_open(struct snd_pcm_substream *substream)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
	struct compr_audio *compr;
	struct msm_audio *prtd;

	struct asm_softpause_params softpause = {
		.enable = SOFT_PAUSE_ENABLE,
		.period = SOFT_PAUSE_PERIOD,
		.step = SOFT_PAUSE_STEP,
		.rampingcurve = SOFT_PAUSE_CURVE_LINEAR,
	};
	struct asm_softvolume_params softvol = {
		.period = SOFT_VOLUME_PERIOD,
		.step = SOFT_VOLUME_STEP,
		.rampingcurve = SOFT_VOLUME_CURVE_LINEAR,
	};

	int ret = 0;

	/* Capture path */
	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
		return -EINVAL;

	pr_debug("[AUD]%s\n", __func__);
	compr = kzalloc(sizeof(struct compr_audio), GFP_KERNEL);
	if (compr == NULL) {
		pr_err("[AUD]Failed to allocate memory for msm_audio\n");
		return -ENOMEM;
	}
	prtd = &compr->prtd;
	prtd->substream = substream;
	prtd->audio_client = q6asm_audio_client_alloc(
				(app_cb)compr_event_handler, compr);
	if (!prtd->audio_client) {
		pr_info("[AUD]%s: Could not allocate memory\n", __func__);
		kfree(prtd);
		return -ENOMEM;
	}
	runtime->hw = msm_compr_hardware_playback;

//HTC_AUD +++
	/*
	 * to invoke q6asm_open_write() before opening adm_open()
	 * issue: LPASS cannot handle data stream properly when switching
	 * from non-tunnel to tunnel mode
	 *
	 * the change fixes data format as MP3 which lost extensiblity
	 * should be take care when new codecs supported
	 */
	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
		ret = q6asm_open_write(prtd->audio_client, FORMAT_MP3);
		if (ret < 0) {
			pr_err("[AUD]%s: Session out open failed\n", __func__);
			q6asm_audio_client_free(prtd->audio_client);
			kfree(prtd);
			return -ENOMEM;
		}
		ret = q6asm_set_io_mode(prtd->audio_client, ASYNC_IO_MODE);
		if (ret < 0) {
			pr_err("[AUD]%s: Set IO mode failed\n", __func__);
			q6asm_audio_client_free(prtd->audio_client);
			kfree(prtd);
			return -ENOMEM;
		}
	}
//HTC_AUD ---
	pr_info("[AUD]%s: session ID %d\n", __func__, prtd->audio_client->session);

	prtd->session_id = prtd->audio_client->session;
	msm_pcm_routing_reg_phy_stream(soc_prtd->dai_link->be_id,
			prtd->session_id, substream->stream);

	prtd->cmd_ack = 1;

	ret = snd_pcm_hw_constraint_list(runtime, 0,
			SNDRV_PCM_HW_PARAM_RATE,
			&constraints_sample_rates);
	if (ret < 0)
		pr_info("[AUD]snd_pcm_hw_constraint_list failed\n");
	/* Ensure that buffer size is a multiple of period size */
	ret = snd_pcm_hw_constraint_integer(runtime,
			    SNDRV_PCM_HW_PARAM_PERIODS);
	if (ret < 0)
		pr_info("[AUD]snd_pcm_hw_constraint_integer failed\n");

	prtd->dsp_cnt = 0;
	atomic_set(&prtd->pending_buffer, 1);
	compr->codec = FORMAT_MP3;
	populate_codec_list(compr, runtime);
	runtime->private_data = compr;

	compr_msm_global.prtd = prtd;
	compr_set_volume(compr_msm_global.volume);
	ret = q6asm_set_softpause(compr_msm_global.prtd->audio_client, &softpause);
	if (ret < 0)
		pr_err("[AUD]%s: Send SoftPause Param failed ret=%d\n",
			__func__, ret);
	ret = q6asm_set_softvolume(compr_msm_global.prtd->audio_client, &softvol);
	if (ret < 0)
		pr_err("[AUD]%s: Send SoftVolume Param failed ret=%d\n",
			__func__, ret);

	return 0;
}
Exemple #4
0
static int msm_compr_open(struct snd_pcm_substream *substream)
{
    struct snd_pcm_runtime *runtime = substream->runtime;
    struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
    struct compr_audio *compr;
    struct msm_audio *prtd;

    struct asm_softpause_params softpause = {
        .enable = SOFT_PAUSE_ENABLE,
        .period = SOFT_PAUSE_PERIOD,
        .step = SOFT_PAUSE_STEP,
        .rampingcurve = SOFT_PAUSE_CURVE_LINEAR,
    };
    struct asm_softvolume_params softvol = {
        .period = SOFT_VOLUME_PERIOD,
        .step = SOFT_VOLUME_STEP,
        .rampingcurve = SOFT_VOLUME_CURVE_LINEAR,
    };

    int ret = 0;

    /* Capture path */
    if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
        return -EINVAL;

    pr_debug("[AUD]%s\n", __func__);
    compr = kzalloc(sizeof(struct compr_audio), GFP_KERNEL);
    if (compr == NULL) {
        pr_err("[AUD]Failed to allocate memory for msm_audio\n");
        return -ENOMEM;
    }
    prtd = &compr->prtd;
    prtd->substream = substream;
    prtd->audio_client = q6asm_audio_client_alloc(
                             (app_cb)compr_event_handler, compr);
    if (!prtd->audio_client) {
        pr_info("[AUD]%s: Could not allocate memory\n", __func__);
        kfree(prtd);
        return -ENOMEM;
    }
    runtime->hw = msm_compr_hardware_playback;

    pr_info("[AUD]%s: session ID %d\n", __func__, prtd->audio_client->session);

    prtd->session_id = prtd->audio_client->session;
    msm_pcm_routing_reg_phy_stream(soc_prtd->dai_link->be_id,
                                   prtd->session_id, substream->stream);

    prtd->cmd_ack = 1;

    ret = snd_pcm_hw_constraint_list(runtime, 0,
                                     SNDRV_PCM_HW_PARAM_RATE,
                                     &constraints_sample_rates);
    if (ret < 0)
        pr_info("[AUD]snd_pcm_hw_constraint_list failed\n");
    /* Ensure that buffer size is a multiple of period size */
    ret = snd_pcm_hw_constraint_integer(runtime,
                                        SNDRV_PCM_HW_PARAM_PERIODS);
    if (ret < 0)
        pr_info("[AUD]snd_pcm_hw_constraint_integer failed\n");

    prtd->dsp_cnt = 0;
    atomic_set(&prtd->pending_buffer, 1);
    compr->codec = FORMAT_MP3;
    populate_codec_list(compr, runtime);
    runtime->private_data = compr;

    compr_msm_global.prtd = prtd;
    compr_set_volume(compr_msm_global.volume);
    ret = q6asm_set_softpause(compr_msm_global.prtd->audio_client, &softpause);
    if (ret < 0)
        pr_err("[AUD]%s: Send SoftPause Param failed ret=%d\n",
               __func__, ret);
    ret = q6asm_set_softvolume(compr_msm_global.prtd->audio_client, &softvol);
    if (ret < 0)
        pr_err("[AUD]%s: Send SoftVolume Param failed ret=%d\n",
               __func__, ret);

    return 0;
}