static int audamrnb_in_release(struct inode *inode, struct file *file) { struct audio_in *audio = file->private_data; MM_DBG("\n"); mutex_lock(&audio->lock); audio->in_call = 0; /* with draw frequency for session incase not stopped the driver */ msm_snddev_withdraw_freq(audio->enc_id, SNDDEV_CAP_TX, AUDDEV_CLNT_ENC); auddev_unregister_evt_listner(AUDDEV_CLNT_ENC, audio->enc_id); audamrnb_in_disable(audio); audamrnb_in_flush(audio); msm_adsp_put(audio->audrec); audpreproc_aenc_free(audio->enc_id); audio->audrec = NULL; audio->opened = 0; if (audio->data) { iounmap(audio->data); pmem_kfree(audio->phys); audio->data = NULL; } mutex_unlock(&audio->lock); return 0; }
static int audpcm_in_release(struct inode *inode, struct file *file) { struct audio_in *audio = file->private_data; if (!audio) return 0; mutex_lock(&audio->lock); audio->in_call = 0; msm_snddev_withdraw_freq(audio->enc_id, SNDDEV_CAP_TX, AUDDEV_CLNT_ENC); auddev_unregister_evt_listner(AUDDEV_CLNT_ENC, audio->enc_id); audpcm_in_disable(audio); audpcm_in_flush(audio); if (audio->audrec) msm_adsp_put(audio->audrec); if (audio->enc_id >=0) audpreproc_aenc_free(audio->enc_id); iounmap(audio->data); pmem_kfree(audio->phys); mutex_unlock(&audio->lock); kfree(audio); #ifdef TEST_ONLY current_audio_in = 0; #endif MM_DBG("closed.\n"); return 0; }
void ddl_pmem_free(struct ddl_buf_addr buff_addr) { if (&buff_addr != NULL && buff_addr.physical_base_addr != NULL && buff_addr.virtual_base_addr != NULL) { DBG("\n%s(): phy_addr %p ker_addr %p", __func__, buff_addr.physical_base_addr, buff_addr.virtual_base_addr); if (buff_addr.virtual_base_addr) iounmap((void *)buff_addr.virtual_base_addr); if ((buff_addr.physical_base_addr) && pmem_kfree((s32) buff_addr.physical_base_addr)) { ERR("\n %s(): Error in Freeing ddl_pmem_free " "Physical Address %p", __func__, buff_addr.physical_base_addr); } buff_addr.buffer_size = 0; buff_addr.physical_base_addr = NULL; buff_addr.virtual_base_addr = NULL; } else pr_err("\n%s(): Trying to free NULL pmem buffer!!\n", __func__); }
void ddl_pmem_free(struct ddl_buf_addr *buff_addr) { if (!buff_addr) { ERR("\n %s() invalid arguments %p", __func__, buff_addr); return; } DBG_PMEM("\n%s() IN: phy_addr(%p) ker_addr(%p) size(%u)", __func__, buff_addr->physical_base_addr, buff_addr->virtual_base_addr, buff_addr->buffer_size); if (buff_addr->virtual_base_addr) iounmap((void *)buff_addr->virtual_base_addr); if ((buff_addr->physical_base_addr) && pmem_kfree((s32) buff_addr->physical_base_addr)) { ERR("\n %s(): Error in Freeing ddl_pmem_free " "Physical Address %p", __func__, buff_addr->physical_base_addr); } DBG_PMEM("\n%s() OUT: phy_addr(%p) ker_addr(%p) size(%u)", __func__, buff_addr->physical_base_addr, buff_addr->virtual_base_addr, buff_addr->buffer_size); buff_addr->buffer_size = 0; buff_addr->physical_base_addr = NULL; buff_addr->virtual_base_addr = NULL; }
void ddl_pmem_free(struct ddl_buf_addr *addr) { DBG_PMEM("\n%s() IN: phy_addr(%p) vir_addr(%p) size(%u)", __func__, addr->physical_base_addr, addr->virtual_base_addr, addr->buffer_size); if (addr->virtual_base_addr) iounmap((void *)addr->virtual_base_addr); if ((addr->physical_base_addr) && pmem_kfree((s32) addr->physical_base_addr)) { DDL_MSG_LOW("\n %s(): Error in Freeing Physical Address %p",\ __func__, addr->physical_base_addr); } DBG_PMEM("\n%s() OUT: phy_addr(%p) vir_addr(%p) size(%u)", __func__, addr->physical_base_addr, addr->virtual_base_addr, addr->buffer_size); addr->physical_base_addr = NULL; addr->virtual_base_addr = NULL; addr->align_virtual_addr = NULL; addr->align_physical_addr = NULL; addr->buffer_size = 0; }
void ddl_pmem_alloc(struct ddl_buf_addr *buff_addr, size_t sz, u32 align) { u32 guard_bytes, align_mask; s32 physical_addr; u32 align_offset; DBG("\n%s() IN : phy_addr(%p) ker_addr(%p) size(%u)", __func__, buff_addr->physical_base_addr, buff_addr->virtual_base_addr, (u32)sz); if (align == DDL_LINEAR_BUFFER_ALIGN_BYTES) { guard_bytes = 31; align_mask = 0xFFFFFFE0U; } else { guard_bytes = DDL_TILE_BUF_ALIGN_GUARD_BYTES; align_mask = DDL_TILE_BUF_ALIGN_MASK; } physical_addr = pmem_kalloc((sz + guard_bytes), PMEM_MEMTYPE_EBI1 | PMEM_ALIGNMENT_4K); buff_addr->physical_base_addr = (u32 *)physical_addr; if (IS_ERR((void *)physical_addr)) { pr_err("%s(): could not allocte in kernel pmem buffers\n", __func__); goto bailout; } buff_addr->virtual_base_addr = (u32 *) ioremap((unsigned long)physical_addr, sz + guard_bytes); if (!buff_addr->virtual_base_addr) { pr_err("%s: could not ioremap in kernel pmem buffers\n", __func__); pmem_kfree(physical_addr); goto bailout; } memset(buff_addr->virtual_base_addr, 0 , sz + guard_bytes); buff_addr->buffer_size = sz; buff_addr->align_physical_addr = (u32 *) ((physical_addr + guard_bytes) & align_mask); align_offset = (u32) (buff_addr->align_physical_addr) - physical_addr; buff_addr->align_virtual_addr = (u32 *) ((u32) (buff_addr->virtual_base_addr) + align_offset); DBG("\n%s() OUT : phy_addr(%p) ker_addr(%p) size(%u)", __func__, buff_addr->physical_base_addr, buff_addr->virtual_base_addr, buff_addr->buffer_size); return; bailout: buff_addr->physical_base_addr = NULL; buff_addr->virtual_base_addr = NULL; buff_addr->buffer_size = 0; }
static int audpcm_in_open(struct inode *inode, struct file *file) { struct audio_in *audio; const char *modname; int rc; audio = kzalloc(sizeof(struct audio_in), GFP_KERNEL); if (!audio) return -ENOMEM; #ifdef TEST_ONLY current_audio_in = audio; #endif audio->phys = pmem_kalloc(DMASZ, PMEM_MEMTYPE_EBI1 | PMEM_ALIGNMENT_4K); if (!IS_ERR((void *) audio->phys)) { audio->data = ioremap(audio->phys, DMASZ); if (!audio->data) { MM_AUD_ERR("Could not remap DMA buffers\n"); pmem_kfree(audio->phys); kfree(audio); return -ENOMEM; } } else { MM_AUD_ERR("Could not allocate DMA buffers\n"); kfree(audio); return -ENOMEM; } audio->enc_id = audpreproc_aenc_alloc(ENC_TYPE_WAV | MSM_AUD_ENC_MODE_TUNNEL, &modname, &audio->queue_ids); if (audio->enc_id < 0) { MM_AUD_ERR("No free encoder available\n"); rc = -ENODEV; goto no_aenc; } MM_DBG("allocated encoder %d, module %s\n", audio->enc_id, modname); rc = auddev_register_evt_listner(AUDDEV_EVT_DEV_RDY | AUDDEV_EVT_DEV_RLS | AUDDEV_EVT_FREQ_CHG | AUDDEV_EVT_VOICE_STATE_CHG, AUDDEV_CLNT_ENC, audio->enc_id, audpcm_in_listener, audio); if (rc) { MM_AUD_ERR("failed to register device event listener\n"); goto evt_error; } rc = msm_adsp_get(modname, &audio->audrec, &audrec_adsp_ops, audio); if (rc) { MM_AUD_ERR("Failed to get AUDREC task\n"); goto no_audrec; } if(!audio->audrec) { MM_AUD_ERR("Null AUDREC task returned by ADSP\n"); rc = -EFAULT; goto no_audrec; } audio->source = INTERNAL_CODEC_TX_SOURCE_MIX_MASK; audio->channel_mode = AUDREC_CMD_MODE_MONO; audio->buffer_size = MONO_DATA_SIZE; audio->samp_rate = 8000; audio->stopped = 0; audio->running = 0; audio->enabled = 0; audpcm_in_flush(audio); mutex_init(&audio->lock); mutex_init(&audio->read_lock); spin_lock_init(&audio->dsp_lock); spin_lock_init(&audio->dev_lock); init_waitqueue_head(&audio->wait); init_waitqueue_head(&audio->wait_enable); init_waitqueue_head(&audio->wait_voice_incall); init_waitqueue_head(&audio->wait_rec_cfg); audio->voice_state = msm_get_voice_state(); file->private_data = audio; return rc; no_audrec: auddev_unregister_evt_listner(AUDDEV_CLNT_ENC, audio->enc_id); evt_error: audpreproc_aenc_free(audio->enc_id); no_aenc: iounmap(audio->data); pmem_kfree(audio->phys); kfree(audio); return rc; }
static int audamrnb_in_open(struct inode *inode, struct file *file) { struct audio_in *audio = &the_audio_amrnb_in; int rc; int encid; mutex_lock(&audio->lock); if (audio->opened) { rc = -EBUSY; goto done; } audio->phys = pmem_kalloc(DMASZ, PMEM_MEMTYPE_EBI1| PMEM_ALIGNMENT_4K); if (!IS_ERR((void *)audio->phys)) { audio->data = ioremap(audio->phys, DMASZ); if (!audio->data) { pr_aud_err("could not allocate DMA buffers\n"); rc = -ENOMEM; pmem_kfree(audio->phys); goto done; } } else { pr_aud_err("could not allocate DMA buffers\n"); rc = -ENOMEM; goto done; } MM_DBG("Memory addr = 0x%8x phy addr = 0x%8x\n",\ (int) audio->data, (int) audio->phys); if ((file->f_mode & FMODE_WRITE) && (file->f_mode & FMODE_READ)) { rc = -EACCES; pr_aud_err("Non tunnel encoding is not supported\n"); goto done; } else if (!(file->f_mode & FMODE_WRITE) && (file->f_mode & FMODE_READ)) { audio->mode = MSM_AUD_ENC_MODE_TUNNEL; MM_DBG("Opened for tunnel mode encoding\n"); } else { rc = -EACCES; goto done; } /* Settings will be re-config at AUDIO_SET_CONFIG, * but at least we need to have initial config */ audio->buffer_size = (FRAME_SIZE - 8); audio->enc_type = ENC_TYPE_AMRNB | audio->mode; audio->dtx_mode = -1; audio->frame_format = 0; audio->used_mode = 7; /* Bit Rate 12.2 kbps MR122 */ encid = audpreproc_aenc_alloc(audio->enc_type, &audio->module_name, &audio->queue_ids); if (encid < 0) { pr_aud_err("No free encoder available\n"); rc = -ENODEV; goto done; } audio->enc_id = encid; rc = msm_adsp_get(audio->module_name, &audio->audrec, &audrec_amrnb_adsp_ops, audio); if (rc) { audpreproc_aenc_free(audio->enc_id); goto done; } audio->stopped = 0; audio->source = 0; audamrnb_in_flush(audio); audio->device_events = AUDDEV_EVT_DEV_RDY | AUDDEV_EVT_DEV_RLS | AUDDEV_EVT_VOICE_STATE_CHG; audio->voice_state = VOICE_STATE_INCALL; rc = auddev_register_evt_listner(audio->device_events, AUDDEV_CLNT_ENC, audio->enc_id, amrnb_in_listener, (void *) audio); if (rc) { pr_aud_err("failed to register device event listener\n"); goto evt_error; } file->private_data = audio; audio->opened = 1; done: mutex_unlock(&audio->lock); return rc; evt_error: msm_adsp_put(audio->audrec); audpreproc_aenc_free(audio->enc_id); mutex_unlock(&audio->lock); return rc; }
static int audamrnb_in_open(struct inode *inode, struct file *file) { struct audio_in *audio = &the_audio_amrnb_in; const char *modname; int rc; mutex_lock(&audio->lock); if (atomic_read(&audio->opened) != 0) { MM_AUD_ERR("Already open\n"); mutex_unlock(&audio->lock); return -EBUSY; } if (!audio->phys) { audio->phys = pmem_kalloc(DMASZ, PMEM_MEMTYPE_EBI1 | PMEM_ALIGNMENT_4K); if (!IS_ERR((void *) audio->phys)) { audio->data = ioremap(audio->phys, DMASZ); if (!audio->data) { MM_AUD_ERR("Could not remap DMA buffers\n"); pmem_kfree(audio->phys); audio->phys = 0; mutex_unlock(&audio->lock); return -ENOMEM; } } else { MM_AUD_ERR("Could not allocate DMA buffers\n"); audio->phys = 0; mutex_unlock(&audio->lock); return -ENOMEM; } } audio->enc_id = audpreproc_aenc_alloc(ENC_TYPE_AMRNB | MSM_AUD_ENC_MODE_TUNNEL, &modname, &audio->queue_ids); if (audio->enc_id < 0) { MM_ERR("No free encoder available\n"); mutex_unlock(&audio->lock); return -ENODEV; } MM_DBG("allocated encoder %d, module %s\n", audio->enc_id, modname); rc = auddev_register_evt_listner(AUDDEV_EVT_DEV_RDY | AUDDEV_EVT_DEV_RLS | AUDDEV_EVT_VOICE_STATE_CHG, AUDDEV_CLNT_ENC, audio->enc_id, amrnb_in_listener, (void *) audio); if (rc) { MM_ERR("failed to register device event listener\n"); goto evt_error; } rc = msm_adsp_get(modname, &audio->audrec, &audrec_amrnb_adsp_ops, audio); if (rc) { MM_AUD_ERR("Failed to get AUDREC task\n"); goto no_audrec; } if(!audio->audrec) { MM_AUD_ERR("Null AUDREC task returned by ADSP\n"); goto no_audrec; } audio->source = INTERNAL_CODEC_TX_SOURCE_MIX_MASK; audio->buffer_size = (FRAME_SIZE - 8); audio->enc_type = ENC_TYPE_AMRNB | MSM_AUD_ENC_MODE_TUNNEL; audio->dtx_mode = AMRNB_DTX_MODE_ENABLE; audio->used_mode = AMRNB_USED_MODE_MR122; /* Bit Rate 12.2 kbps */ audio->stopped = 0; audio->running = 0; audio->enabled = 0; audamrnb_in_flush(audio); audio->voice_state = msm_get_voice_state(); file->private_data = audio; atomic_set(&audio->opened,1); mutex_unlock(&audio->lock); return rc; no_audrec: auddev_unregister_evt_listner(AUDDEV_CLNT_ENC, audio->enc_id); evt_error: audpreproc_aenc_free(audio->enc_id); mutex_unlock(&audio->lock); return rc; }