static int mtk_pcm_fmtx_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_dma_buffer *dma_buf = &substream->dma_buffer; int ret = 0; PRINTK_AUD_FMTX("mtk_pcm_fmtx_hw_params \n"); if (fake_buffer) { /* runtime->dma_bytes has to be set manually to allow mmap */ substream->runtime->dma_bytes = params_buffer_bytes(hw_params); // here to allcoate sram to hardware --------------------------- AudDrv_Allocate_mem_Buffer(mDev, Soc_Aud_Digital_Block_MEM_DL1, substream->runtime->dma_bytes); substream->runtime->dma_area = (unsigned char *)Get_Afe_SramBase_Pointer(); substream->runtime->dma_addr = AFE_INTERNAL_SRAM_PHY_BASE; // ------------------------------------------------------- PRINTK_AUD_FMTX("1 dma_bytes = %d dma_area = %p dma_addr = 0x%x\n", substream->runtime->dma_bytes, substream->runtime->dma_area, substream->runtime->dma_addr); return 0; } else { dma_buf->dev.type = SNDRV_DMA_TYPE_DEV; dma_buf->dev.dev = substream->pcm->card->dev; dma_buf->private_data = NULL; ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); } PRINTK_AUD_FMTX("2 dma_bytes = %d dma_area = %p dma_addr = 0x%x\n", substream->runtime->dma_bytes, substream->runtime->dma_area, substream->runtime->dma_addr); return ret; }
static snd_pcm_uframes_t mtk_pcm_fmtx_pointer(struct snd_pcm_substream *substream) { kal_int32 HW_memory_index = 0; kal_int32 HW_Cur_ReadIdx = 0; kal_uint32 Frameidx =0; AFE_BLOCK_T *Afe_Block = &pMemControl->rBlock; PRINTK_AUD_FMTX("[mtk_pcm_fmtx_pointer] Afe_Block->u4DMAReadIdx = 0x%x\n", Afe_Block->u4DMAReadIdx); if (pMemControl->interruptTrigger == 1) { Frameidx =audio_bytes_to_frame(substream , Afe_Block->u4DMAReadIdx); return Frameidx; HW_Cur_ReadIdx = Afe_Get_Reg(AFE_DL1_CUR); if (HW_Cur_ReadIdx == 0) { PRINTK_AUD_FMTX("[Auddrv] HW_Cur_ReadIdx ==0 \n"); HW_Cur_ReadIdx = Afe_Block->pucPhysBufAddr; } HW_memory_index = (HW_Cur_ReadIdx - Afe_Block->pucPhysBufAddr); Previous_Hw_cur = HW_memory_index; PRINTK_AUD_FMTX("[Auddrv] HW_Cur_ReadIdx =0x%x HW_memory_index = 0x%x pointer return = 0x%x \n", HW_Cur_ReadIdx, HW_memory_index, (HW_memory_index >> 2)); pMemControl->interruptTrigger = 0; return (HW_memory_index >> 2); }
static int mtk_pcm_fmtx_silence(struct snd_pcm_substream *substream, int channel, snd_pcm_uframes_t pos, snd_pcm_uframes_t count) { PRINTK_AUD_FMTX("%s \n", __func__); return 0; /* do nothing */ }
static int mtk_pcm_fmtx_stop(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; //AFE_BLOCK_T *Afe_Block = &(pMemControl->rBlock); PRINTK_AUD_FMTX("mtk_pcm_fmtx_stop \n"); SetIrqEnable(Soc_Aud_IRQ_MCU_MODE_IRQ1_MCU_MODE, false); // here to turn off digital part SetConnection(Soc_Aud_InterCon_DisConnect, Soc_Aud_InterConnectionInput_I05, Soc_Aud_InterConnectionOutput_O00); SetConnection(Soc_Aud_InterCon_DisConnect, Soc_Aud_InterConnectionInput_I06, Soc_Aud_InterConnectionOutput_O01); // if (GetMrgI2SEnable() == false) // { SetMrgI2SEnable(false, runtime->rate); // } SetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_DL1, false); SetMemoryPathEnable(Soc_Aud_Digital_Block_MRG_I2S_OUT, false); Set2ndI2SOutEnable(false); EnableAfe(false); RemoveMemifSubStream(Soc_Aud_Digital_Block_MEM_DL1, substream); AudDrv_Clk_Off(); return 0; }
static snd_pcm_uframes_t mtk_pcm_fmtx_pointer(struct snd_pcm_substream *substream) { kal_int32 HW_memory_index = 0; kal_int32 HW_Cur_ReadIdx = 0; kal_uint32 Frameidx = 0; kal_int32 Afe_consumed_bytes = 0; AFE_BLOCK_T *Afe_Block = &pMemControl->rBlock; PRINTK_AUD_FMTX("[mtk_pcm_fmtx_pointer] Afe_Block->u4DMAReadIdx = 0x%x\n", Afe_Block->u4DMAReadIdx); Auddrv_Dl1_Spinlock_lock(); if (GetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_DL1) == true) { HW_Cur_ReadIdx = Afe_Get_Reg(AFE_DL1_CUR); if (HW_Cur_ReadIdx == 0) { PRINTK_AUD_FMTX("[Auddrv] HW_Cur_ReadIdx ==0 \n"); HW_Cur_ReadIdx = Afe_Block->pucPhysBufAddr; } HW_memory_index = (HW_Cur_ReadIdx - Afe_Block->pucPhysBufAddr); if (HW_memory_index >= Afe_Block->u4DMAReadIdx) { Afe_consumed_bytes = HW_memory_index - Afe_Block->u4DMAReadIdx; } else { Afe_consumed_bytes = Afe_Block->u4BufferSize + HW_memory_index - Afe_Block->u4DMAReadIdx ; } Afe_consumed_bytes = Align64ByteSize(Afe_consumed_bytes); Afe_Block->u4DataRemained -= Afe_consumed_bytes; Afe_Block->u4DMAReadIdx += Afe_consumed_bytes; Afe_Block->u4DMAReadIdx %= Afe_Block->u4BufferSize; PRINTK_AUD_DL1("[Auddrv] HW_Cur_ReadIdx =0x%x HW_memory_index = 0x%x Afe_consumed_bytes = 0x%x\n", HW_Cur_ReadIdx, HW_memory_index, Afe_consumed_bytes); Auddrv_Dl1_Spinlock_unlock(); return audio_bytes_to_frame(substream , Afe_Block->u4DMAReadIdx); } else { Frameidx = audio_bytes_to_frame(substream , Afe_Block->u4DMAReadIdx); Auddrv_Dl1_Spinlock_unlock(); return Frameidx; } }
static int mtk_pcm_fmtx_hw_free(struct snd_pcm_substream *substream) { PRINTK_AUD_FMTX("mtk_pcm_fmtx_hw_free \n"); if (fake_buffer) { return 0; } return snd_pcm_lib_free_pages(substream); }
static int mtk_pcm_fmtx_open(struct snd_pcm_substream *substream) { int ret = 0; struct snd_pcm_runtime *runtime = substream->runtime; PRINTK_AUD_FMTX("mtk_pcm_fmtx_open\n"); AudDrv_Clk_On(); // get dl1 memconptrol and record substream pMemControl = Get_Mem_ControlT(Soc_Aud_Digital_Block_MEM_DL1); runtime->hw = mtk_fmtx_hardware; memcpy((void *)(&(runtime->hw)), (void *)&mtk_fmtx_hardware , sizeof(struct snd_pcm_hardware)); //PRINTK_AUDDRV("runtime->hw->rates= 0x%x mtk_pcm_hardware = = 0x%x\n ", runtime->hw.rates, &mtk_pcm_hardware); ret = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_fmtx_sample_rates); ret = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (ret < 0) { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_open]snd_pcm_hw_constraint_integer failed\n"); } //print for hw pcm information PRINTK_AUD_FMTX("[mtk_pcm_fmtx_open] runtime rate = %d channels = %d substream->pcm->device = %d\n", runtime->rate, runtime->channels, substream->pcm->device); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_open]SNDRV_PCM_FMTX_PLAYBACK mtkalsa_playback_constraints\n"); } else { } if (ret < 0) { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_open]mtk_pcm_fmtx_close\n"); mtk_pcm_fmtx_close(substream); return ret; } //PRINTK_AUDDRV("mtk_pcm_open return\n"); return 0; }
static int mtk_afe_fmtx_probe(struct snd_soc_platform *platform) { PRINTK_AUD_FMTX("mtk_afe_afe_probe\n"); snd_soc_add_platform_controls(platform, Audio_snd_fmtx_controls, ARRAY_SIZE(Audio_snd_fmtx_controls)); AudDrv_Allocate_mem_Buffer(platform->dev, Soc_Aud_Digital_Block_MEM_DL1, Dl1_MAX_BUFFER_SIZE); FMTX_Playback_dma_buf = Get_Mem_Buffer(Soc_Aud_Digital_Block_MEM_DL1); return 0; }
static int mtk_fmtx_probe(struct platform_device *pdev) { PRINTK_AUD_FMTX("%s \n", __func__); pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64); if (!pdev->dev.dma_mask) { pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; } if (pdev->dev.of_node) { dev_set_name(&pdev->dev, "%s", MT_SOC_FM_MRGTX_PCM); } PRINTK_AUD_FMTX("%s: dev name %s\n", __func__, dev_name(&pdev->dev)); mDev = &pdev->dev; return snd_soc_register_platform(&pdev->dev, &mtk_fmtx_soc_platform); }
static int mtk_pcm_fmtx_close(struct snd_pcm_substream *substream) { PRINTK_AUD_FMTX("%s \n", __func__); // mtk_wcn_cmb_stub_audio_ctrl((CMB_STUB_AIF_X)CMB_STUB_AIF_0); if (mPlaybackSramState == SRAM_STATE_PLAYBACKDRAM) { AudDrv_Emi_Clk_Off(); } AfeControlSramLock(); ClearSramState(mPlaybackSramState); mPlaybackSramState = GetSramState(); AfeControlSramUnLock(); AudDrv_Clk_Off(); return 0; }
static int __init mtk_soc_platform_init(void) { int ret; PRINTK_AUD_FMTX("%s \n", __func__); #ifndef CONFIG_OF soc_mtkfmtx_dev = platform_device_alloc(MT_SOC_FM_MRGTX_PCM, -1); if (!soc_mtkfmtx_dev) { return -ENOMEM; } ret = platform_device_add(soc_mtkfmtx_dev); if (ret != 0) { platform_device_put(soc_mtkfmtx_dev); return ret; } #endif ret = platform_driver_register(&mtk_fmtx_driver); return ret; }
static void __exit mtk_soc_platform_exit(void) { PRINTK_AUD_FMTX("%s \n", __func__); platform_driver_unregister(&mtk_fmtx_driver); }
static int mtk_fmtx_remove(struct platform_device *pdev) { PRINTK_AUD_FMTX("%s \n", __func__); snd_soc_unregister_platform(&pdev->dev); return 0; }
static int mtk_asoc_pcm_fmtx_new(struct snd_soc_pcm_runtime *rtd) { int ret = 0; PRINTK_AUD_FMTX("%s\n", __func__); return ret; }
static struct page *mtk_pcm_fmtx_page(struct snd_pcm_substream *substream, unsigned long offset) { PRINTK_AUD_FMTX("%s \n", __func__); return virt_to_page(dummy_page[substream->stream]); /* the same page */ }
static int mtk_pcm_fmtx_copy(struct snd_pcm_substream *substream, int channel, snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count) { AFE_BLOCK_T *Afe_Block = NULL; unsigned long flags; char *data_w_ptr = (char *)dst; int copy_size = 0, Afe_WriteIdx_tmp; // get total bytes to copy count = audio_frame_to_bytes(substream , count); PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] pos = %lu count = %lu\n ", pos, count); // check which memif nned to be write Afe_Block = &pMemControl->rBlock; // handle for buffer management PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy]AudDrv_write WriteIdx=0x%x, ReadIdx=0x%x, DataRemained=0x%x \n", Afe_Block->u4WriteIdx, Afe_Block->u4DMAReadIdx, Afe_Block->u4DataRemained); if (Afe_Block->u4BufferSize == 0) { printk("AudDrv_write: u4BufferSize=0 Error"); return 0; } spin_lock_irqsave(&auddrv_FMTxCtl_lock, flags); copy_size = Afe_Block->u4BufferSize - Afe_Block->u4DataRemained; // free space of the buffer spin_unlock_irqrestore(&auddrv_FMTxCtl_lock, flags); if (count <= copy_size) { if (copy_size < 0) { copy_size = 0; } else { copy_size = count; } } copy_size = Align64ByteSize(copy_size); PRINTK_AUD_DL1("copy_size=0x%x, count=0x%x \n", copy_size, count); if (copy_size != 0) { spin_lock_irqsave(&auddrv_FMTxCtl_lock, flags); Afe_WriteIdx_tmp = Afe_Block->u4WriteIdx; spin_unlock_irqrestore(&auddrv_FMTxCtl_lock, flags); if (Afe_WriteIdx_tmp + copy_size < Afe_Block->u4BufferSize) // copy once { if (!access_ok(VERIFY_READ, data_w_ptr, copy_size)) { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] 0ptr invalid data_w_ptr=0x%x, size=%d", (kal_uint32)data_w_ptr, copy_size); PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] u4BufferSize=%d, u4DataRemained=%d", Afe_Block->u4BufferSize, Afe_Block->u4DataRemained); } else { PRINTK_AUD_FMTX("memcpy Afe_Block->pucVirtBufAddr+Afe_WriteIdx= %p data_w_ptr = %p copy_size = 0x%x\n", Afe_Block->pucVirtBufAddr + Afe_WriteIdx_tmp, data_w_ptr, copy_size); if (copy_from_user((Afe_Block->pucVirtBufAddr + Afe_WriteIdx_tmp), data_w_ptr, copy_size)) { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] Fail copy from user \n"); return -1; } } spin_lock_irqsave(&auddrv_FMTxCtl_lock, flags); Afe_Block->u4DataRemained += copy_size; Afe_Block->u4WriteIdx = Afe_WriteIdx_tmp + copy_size; Afe_Block->u4WriteIdx %= Afe_Block->u4BufferSize; spin_unlock_irqrestore(&auddrv_FMTxCtl_lock, flags); data_w_ptr += copy_size; count -= copy_size; PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] finish1, copy_size:%x, WriteIdx:%x, ReadIdx=%x, DataRemained:%x, count=%x \r\n", copy_size, Afe_Block->u4WriteIdx, Afe_Block->u4DMAReadIdx, Afe_Block->u4DataRemained, count); } else // copy twice { kal_uint32 size_1 = 0, size_2 = 0; size_1 = Align64ByteSize((Afe_Block->u4BufferSize - Afe_WriteIdx_tmp)); size_2 = Align64ByteSize((copy_size - size_1)); PRINTK_AUD_DL1("size_1=0x%x, size_2=0x%x \n", size_1, size_2); if (!access_ok(VERIFY_READ, data_w_ptr, size_1)) { printk("[mtk_pcm_fmtx_copy] 1ptr invalid data_w_ptr=%p, size_1=%d", data_w_ptr, size_1); printk("[mtk_pcm_fmtx_copy] u4BufferSize=%d, u4DataRemained=%d", Afe_Block->u4BufferSize, Afe_Block->u4DataRemained); } else { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy]mcmcpy Afe_Block->pucVirtBufAddr+Afe_WriteIdx= %x data_w_ptr = %p size_1 = %x\n", Afe_Block->pucVirtBufAddr + Afe_WriteIdx_tmp, data_w_ptr, size_1); if ((copy_from_user((Afe_Block->pucVirtBufAddr + Afe_WriteIdx_tmp), data_w_ptr , size_1))) { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] Fail 1 copy from user"); return -1; } } spin_lock_irqsave(&auddrv_FMTxCtl_lock, flags); Afe_Block->u4DataRemained += size_1; Afe_Block->u4WriteIdx = Afe_WriteIdx_tmp + size_1; Afe_Block->u4WriteIdx %= Afe_Block->u4BufferSize; Afe_WriteIdx_tmp = Afe_Block->u4WriteIdx; spin_unlock_irqrestore(&auddrv_FMTxCtl_lock, flags); if (!access_ok(VERIFY_READ, data_w_ptr + size_1, size_2)) { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] 2ptr invalid data_w_ptr=%x, size_1=%d, size_2=%d", (kal_uint32)data_w_ptr, size_1, size_2); PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] u4BufferSize=%d, u4DataRemained=%d", Afe_Block->u4BufferSize, Afe_Block->u4DataRemained); } else { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy]mcmcpy Afe_Block->pucVirtBufAddr+Afe_WriteIdx= %x data_w_ptr+size_1 = %p size_2 = %x\n", Afe_Block->pucVirtBufAddr + Afe_WriteIdx_tmp, data_w_ptr + size_1, size_2); if ((copy_from_user((Afe_Block->pucVirtBufAddr + Afe_WriteIdx_tmp), (data_w_ptr + size_1), size_2))) { PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] Fail 2 copy from user"); return -1; } } spin_lock_irqsave(&auddrv_FMTxCtl_lock, flags); Afe_Block->u4DataRemained += size_2; Afe_Block->u4WriteIdx = Afe_WriteIdx_tmp + size_2; Afe_Block->u4WriteIdx %= Afe_Block->u4BufferSize; spin_unlock_irqrestore(&auddrv_FMTxCtl_lock, flags); count -= copy_size; data_w_ptr += copy_size; PRINTK_AUD_FMTX("[mtk_pcm_fmtx_copy] finish2, copy size:%x, WriteIdx:%x,ReadIdx=%x DataRemained:%x \r\n", copy_size, Afe_Block->u4WriteIdx, Afe_Block->u4DMAReadIdx, Afe_Block->u4DataRemained); } } return 0; }