static int audio_open(struct inode *inode, struct file *file) { struct q6audio_aio *audio = NULL; int rc = 0; struct asm_softpause_params softpause = { .enable = SOFT_PAUSE_ENABLE, .period = SOFT_PAUSE_PERIOD * 3, .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, }; #ifdef CONFIG_DEBUG_FS /* 4 bytes represents decoder number, 1 byte for terminate string */ char name[sizeof "msm_mp3_" + 5]; #endif audio = kzalloc(sizeof(struct q6audio_aio), GFP_KERNEL); if (audio == NULL) { pr_err("Could not allocate memory for mp3 decode driver\n"); return -ENOMEM; } audio->pcm_cfg.buffer_size = PCM_BUFSZ_MIN; audio->ac = q6asm_audio_client_alloc((app_cb) q6_audio_cb, (void *)audio); if (!audio->ac) { pr_err("Could not allocate memory for audio client\n"); kfree(audio); return -ENOMEM; } /* open in T/NT mode */ if ((file->f_mode & FMODE_WRITE) && (file->f_mode & FMODE_READ)) { rc = q6asm_open_read_write(audio->ac, FORMAT_LINEAR_PCM, FORMAT_MP3); if (rc < 0) { pr_err("NT mode Open failed rc=%d\n", rc); rc = -ENODEV; goto fail; } audio->feedback = NON_TUNNEL_MODE; /* open MP3 decoder, expected frames is always 1 audio->buf_cfg.frames_per_buf = 0x01;*/ audio->buf_cfg.meta_info_enable = 0x01; } else if ((file->f_mode & FMODE_WRITE) && !(file->f_mode & FMODE_READ)) { rc = q6asm_open_write(audio->ac, FORMAT_MP3); if (rc < 0) { pr_err("T mode Open failed rc=%d\n", rc); rc = -ENODEV; goto fail; } audio->feedback = TUNNEL_MODE; audio->buf_cfg.meta_info_enable = 0x00; } else { pr_err("Not supported mode\n"); rc = -EACCES; goto fail; } rc = audio_aio_open(audio, file); #ifdef CONFIG_DEBUG_FS snprintf(name, sizeof name, "msm_mp3_%04x", audio->ac->session); audio->dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, NULL, (void *)audio, &audio_mp3_debug_fops); if (IS_ERR(audio->dentry)) pr_debug("debugfs_create_file failed\n"); #endif if (softpause.rampingcurve == SOFT_PAUSE_CURVE_LINEAR) softpause.step = SOFT_PAUSE_STEP_LINEAR; if (softvol.rampingcurve == SOFT_VOLUME_CURVE_LINEAR) softvol.step = SOFT_VOLUME_STEP_LINEAR; rc = q6asm_set_volume(audio->ac, 0); if (rc < 0) pr_err("%s: Send Volume command failed rc=%d\n", __func__, rc); rc = q6asm_set_softpause(audio->ac, &softpause); if (rc < 0) pr_err("%s: Send SoftPause Param failed rc=%d\n", __func__, rc); rc = q6asm_set_softvolume(audio->ac, &softvol); if (rc < 0) pr_err("%s: Send SoftVolume Param failed rc=%d\n", __func__, rc); /* disable mute by default */ rc = q6asm_set_mute(audio->ac, 0); if (rc < 0) pr_err("%s: Send mute command failed rc=%d\n", __func__, rc); pr_info("%s:mp3dec success mode[%d]session[%d]\n", __func__, audio->feedback, audio->ac->session); return rc; fail: q6asm_audio_client_free(audio->ac); kfree(audio); return rc; } static const struct file_operations audio_mp3_fops = { .owner = THIS_MODULE, .open = audio_open, .release = audio_aio_release, .unlocked_ioctl = audio_ioctl, .fsync = audio_aio_fsync, }; struct miscdevice audio_mp3_misc = { .minor = MISC_DYNAMIC_MINOR, .name = "msm_mp3", .fops = &audio_mp3_fops, }; static int __init audio_mp3_init(void) { return misc_register(&audio_mp3_misc); } device_initcall(audio_mp3_init);
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; }
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; }
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; }