static ssize_t lpa_if_write(struct file *file, const char __user *buf, size_t count, loff_t *pos) { struct lpa_if *lpa_if = file->private_data; struct audio_buffer *ab; const char __user *start = buf; int xfer, rc; struct sched_param s = { .sched_priority = 1 }; int old_prio = current->rt_priority; int old_policy = current->policy; int cap_nice = cap_raised(current_cap(), CAP_SYS_NICE); /* just for this write, set us real-time */ if (!task_has_rt_policy(current)) { struct cred *new = prepare_creds(); cap_raise(new->cap_effective, CAP_SYS_NICE); commit_creds(new); if ((sched_setscheduler(current, SCHED_RR, &s)) < 0) pr_err("sched_setscheduler failed\n"); } mutex_lock(&lpa_if->lock); if (dma_buf_index < 2) { ab = lpa_if->audio_buf + dma_buf_index; if (copy_from_user(ab->data, buf, count)) { pr_err("copy from user failed\n"); rc = 0; goto end; } mb(); pr_debug("prefill: count %u audio_buf[%u].size %u\n", count, dma_buf_index, ab->size); ab->used = 1; dma_buf_index++; rc = count; goto end; } if (lpa_if->config != 1) { pr_err("AUDIO_START did not happen\n"); rc = 0; goto end; } while (count > 0) { ab = lpa_if->audio_buf + lpa_if->cpu_buf; rc = wait_event_timeout(lpa_if->wait, (ab->used == 0), 10 * HZ); if (!rc) { pr_err("wait_event_timeout failed\n"); rc = buf - start; goto end; } xfer = count; if (xfer > lpa_if->dma_period_sz) xfer = lpa_if->dma_period_sz; if (copy_from_user(ab->data, buf, xfer)) { pr_err("copy from user failed\n"); rc = buf - start; goto end; } mb(); buf += xfer; count -= xfer; ab->used = 1; pr_debug("xfer %d, size %d, used %d cpu_buf %d\n", xfer, ab->size, ab->used, lpa_if->cpu_buf); lpa_if->cpu_buf++; lpa_if->cpu_buf = lpa_if->cpu_buf % lpa_if->cfg.buffer_count; } rc = buf - start; end: mutex_unlock(&lpa_if->lock); /* restore old scheduling policy */ if (!rt_policy(old_policy)) { struct sched_param v = { .sched_priority = old_prio }; if ((sched_setscheduler(current, old_policy, &v)) < 0) pr_err("sched_setscheduler failed\n"); if (likely(!cap_nice)) { struct cred *new = prepare_creds(); cap_lower(new->cap_effective, CAP_SYS_NICE); commit_creds(new); } } return rc; } static int lpa_if_release(struct inode *inode, struct file *file) { struct lpa_if *lpa_if = file->private_data; hdmi_audio_packet_enable(0); wait_for_dma_cnt_stop(lpa_if->dma_ch); hdmi_audio_enable(0, HDMI_AUDIO_FIFO_WATER_MARK); if (lpa_if->config) { unregister_dma_irq_handler(lpa_if->dma_ch); dai_stop_hdmi(lpa_if->dma_ch); lpa_if->config = 0; } core_req_bus_bandwith(AUDIO_IF_BUS_ID, 0, 0); if (hdmi_msm_audio_get_sample_rate() != HDMI_SAMPLE_RATE_48KHZ) hdmi_msm_audio_sample_rate_reset(HDMI_SAMPLE_RATE_48KHZ); return 0; } static const struct file_operations lpa_if_fops = { .owner = THIS_MODULE, .open = lpa_if_open, .write = lpa_if_write, .release = lpa_if_release, .unlocked_ioctl = lpa_if_ioctl, }; struct miscdevice lpa_if_misc = { .minor = MISC_DYNAMIC_MINOR, .name = "msm_lpa_if_out", .fops = &lpa_if_fops, }; static int __init lpa_if_init(void) { int rc; lpa_if_ptr = kzalloc(sizeof(struct lpa_if), GFP_KERNEL); if (!lpa_if_ptr) { pr_info("No mem for lpa-if\n"); return -ENOMEM; } mutex_init(&lpa_if_ptr->lock); init_waitqueue_head(&lpa_if_ptr->wait); lpa_if_ptr->buffer = dma_alloc_coherent(NULL, DMA_ALLOC_BUF_SZ, &(lpa_if_ptr->buffer_phys), GFP_KERNEL); if (!lpa_if_ptr->buffer) { pr_err("dma_alloc_coherent failed\n"); kfree(lpa_if_ptr); return -ENOMEM; } pr_info("lpa_if_ptr 0x%08x buf_vir 0x%08x buf_phy 0x%08x " " buf_zise %u\n", (u32)lpa_if_ptr, (u32)(lpa_if_ptr->buffer), lpa_if_ptr->buffer_phys, DMA_ALLOC_BUF_SZ); rc = misc_register(&lpa_if_misc); if (rc < 0) { pr_err("misc_register failed\n"); dma_free_coherent(NULL, DMA_ALLOC_BUF_SZ, lpa_if_ptr->buffer, lpa_if_ptr->buffer_phys); kfree(lpa_if_ptr); } return rc; } device_initcall(lpa_if_init);
static int msm_dai_q6_hdmi_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { struct msm_dai_q6_hdmi_dai_data *dai_data = dev_get_drvdata(dai->dev); u32 channel_allocation = 0; u32 level_shift = 0; bool down_mix = FALSE; int sample_rate = 48000; dai_data->channels = params_channels(params); dai_data->rate = params_rate(params); dai_data->port_config.hdmi_multi_ch.reserved = 0; switch (dai_data->rate) { case 48000: sample_rate = HDMI_SAMPLE_RATE_48KHZ; break; case 44100: sample_rate = HDMI_SAMPLE_RATE_44_1KHZ; break; case 32000: sample_rate = HDMI_SAMPLE_RATE_32KHZ; break; } hdmi_msm_audio_sample_rate_reset(sample_rate); switch (dai_data->channels) { case 2: channel_allocation = 0; hdmi_msm_audio_info_setup(1, MSM_HDMI_AUDIO_CHANNEL_2, channel_allocation, level_shift, down_mix); dai_data->port_config.hdmi_multi_ch.channel_allocation = channel_allocation; break; case 6: channel_allocation = 0x0B; hdmi_msm_audio_info_setup(1, MSM_HDMI_AUDIO_CHANNEL_6, channel_allocation, level_shift, down_mix); dai_data->port_config.hdmi_multi_ch.channel_allocation = channel_allocation; break; case 8: channel_allocation = 0x1F; hdmi_msm_audio_info_setup(1, MSM_HDMI_AUDIO_CHANNEL_8, channel_allocation, level_shift, down_mix); dai_data->port_config.hdmi_multi_ch.channel_allocation = channel_allocation; break; default: dev_err(dai->dev, "invalid Channels = %u\n", dai_data->channels); return -EINVAL; } dev_dbg(dai->dev, "%s() num_ch = %u rate =%u" " channel_allocation = %u data type = %d\n", __func__, dai_data->channels, dai_data->rate, dai_data->port_config.hdmi_multi_ch.channel_allocation, dai_data->port_config.hdmi_multi_ch.data_type); return 0; }
static long lpa_if_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct lpa_if *lpa_if = file->private_data; int rc = 0; unsigned int i; pr_debug("cmd %u\n", cmd); mutex_lock(&lpa_if->lock); switch (cmd) { case AUDIO_START: pr_debug("AUDIO_START\n"); if (dma_buf_index == 2) { if (!lpa_if->config) { rc = lpa_if_config(lpa_if); if (rc) pr_err("lpa_if_config failed\n"); } } else { pr_err("did not receved two buffer for " "AUDIO_STAR\n"); rc = -EPERM; } break; case AUDIO_STOP: pr_debug("AUDIO_STOP\n"); break; case AUDIO_FLUSH: pr_debug("AUDIO_FLUSH\n"); break; case AUDIO_GET_CONFIG: pr_debug("AUDIO_GET_CONFIG\n"); if (copy_to_user((void *)arg, &lpa_if->cfg, sizeof(struct msm_audio_config))) { rc = -EFAULT; } break; case AUDIO_SET_CONFIG: { /* Setting default rate as 48khz */ unsigned int cur_sample_rate = HDMI_SAMPLE_RATE_48KHZ; struct msm_audio_config config; pr_debug("AUDIO_SET_CONFIG\n"); if (copy_from_user(&config, (void *)arg, sizeof(config))) { rc = -EFAULT; break; } lpa_if->dma_period_sz = config.buffer_size; if ((lpa_if->dma_period_sz * lpa_if->num_periods) > DMA_ALLOC_BUF_SZ) { pr_err("Dma buffer size greater than allocated size\n"); return -EINVAL; } pr_debug("Dma_period_sz %d\n", lpa_if->dma_period_sz); if (lpa_if->dma_period_sz < (2 * SZ_4K)) lpa_if->num_periods = 6; pr_debug("No. of Periods %d\n", lpa_if->num_periods); lpa_if->cfg.buffer_count = lpa_if->num_periods; lpa_if->cfg.buffer_size = lpa_if->dma_period_sz * lpa_if->num_periods; for (i = 0; i < lpa_if->cfg.buffer_count; i++) { lpa_if->audio_buf[i].phys = lpa_if->buffer_phys + i * lpa_if->dma_period_sz; lpa_if->audio_buf[i].data = lpa_if->buffer + i * lpa_if->dma_period_sz; lpa_if->audio_buf[i].size = lpa_if->dma_period_sz; lpa_if->audio_buf[i].used = 0; } pr_debug("Sample rate %d\n", config.sample_rate); switch (config.sample_rate) { case 48000: cur_sample_rate = HDMI_SAMPLE_RATE_48KHZ; break; case 44100: cur_sample_rate = HDMI_SAMPLE_RATE_44_1KHZ; break; case 32000: cur_sample_rate = HDMI_SAMPLE_RATE_32KHZ; break; case 88200: cur_sample_rate = HDMI_SAMPLE_RATE_88_2KHZ; break; case 96000: cur_sample_rate = HDMI_SAMPLE_RATE_96KHZ; break; case 176400: cur_sample_rate = HDMI_SAMPLE_RATE_176_4KHZ; break; case 192000: cur_sample_rate = HDMI_SAMPLE_RATE_192KHZ; break; default: cur_sample_rate = HDMI_SAMPLE_RATE_48KHZ; } if (cur_sample_rate != hdmi_msm_audio_get_sample_rate()) hdmi_msm_audio_sample_rate_reset(cur_sample_rate); else pr_debug("Previous sample rate and current" "sample rate are same\n"); break; } default: pr_err("UnKnown Ioctl\n"); rc = -EINVAL; } mutex_unlock(&lpa_if->lock); return rc; }