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 snd_pcm_uframes_t mtk_pcm_i2s0_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 = &pI2s0MemControl->rBlock; unsigned int flags; struct snd_pcm_runtime *runtime = substream->runtime; PRINTK_AUD_DL1(" %s Afe_Block->u4DMAReadIdx = 0x%x\n", __func__, Afe_Block->u4DMAReadIdx); // get total bytes to copy //Frameidx = audio_bytes_to_frame(substream , Afe_Block->u4DMAReadIdx); //return Frameidx; spin_lock_irqsave(&auddrv_I2S0_lock, flags); if (GetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_DL1) == true) { HW_Cur_ReadIdx = Afe_Get_Reg(AFE_DL1_CUR); if (HW_Cur_ReadIdx == 0) { PRINTK_AUDDRV("[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_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 pointer return = 0x%x \n", HW_Cur_ReadIdx, HW_memory_index, (HW_memory_index >> 2)); spin_unlock_irqrestore(&auddrv_I2S0_lock, flags); return audio_bytes_to_frame(substream , Afe_Block->u4DMAReadIdx); }
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; }
static int mtk_pcm_dl1bt_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; PRINTK_AUD_DL1("mtk_pcm_dl1bt_copy pos = %lu count = %lu\n ", pos, count); /* get total bytes to copy */ count = audio_frame_to_bytes(substream, count); /* check which memif nned to be write */ Afe_Block = &pdl1btMemControl->rBlock; /* handle for buffer management */ PRINTK_AUD_DL1("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) { pr_err("AudDrv_write: u4BufferSize=0 Error"); return 0; } spin_lock_irqsave(&auddrv_DL1BTCtl_lock, flags); copy_size = Afe_Block->u4BufferSize - Afe_Block->u4DataRemained; /* free space of the buffer */ spin_unlock_irqrestore(&auddrv_DL1BTCtl_lock, flags); if (count <= copy_size) { if (copy_size < 0) copy_size = 0; else copy_size = count; } #ifdef AUDIO_64BYTE_ALIGN copy_size = Align64ByteSize(copy_size); #endif PRINTK_AUD_DL1("copy_size=0x%x, count=0x%x\n", copy_size, (unsigned int)count); if (copy_size != 0) { spin_lock_irqsave(&auddrv_DL1BTCtl_lock, flags); Afe_WriteIdx_tmp = Afe_Block->u4WriteIdx; spin_unlock_irqrestore(&auddrv_DL1BTCtl_lock, flags); if (Afe_WriteIdx_tmp + copy_size < Afe_Block->u4BufferSize) { /* copy once */ if (!access_ok(VERIFY_READ, data_w_ptr, copy_size)) { PRINTK_AUDDRV("AudDrv_write 0ptr invalid data_w_ptr=%p, size=%d", data_w_ptr, copy_size); PRINTK_AUDDRV("AudDrv_write u4BufferSize=%d, u4DataRemained=%d", Afe_Block->u4BufferSize, Afe_Block->u4DataRemained); } else { PRINTK_AUD_DL1("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_AUDDRV("AudDrv_write Fail copy from user\n"); return -1; } } spin_lock_irqsave(&auddrv_DL1BTCtl_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_DL1BTCtl_lock, flags); data_w_ptr += copy_size; count -= copy_size; PRINTK_AUD_DL1("AudDrv_write finish1, copy_size:%x, WriteIdx:%x, ReadIdx=%x, DataRemained:%x, count=%lu \r\n", copy_size, Afe_Block->u4WriteIdx, Afe_Block->u4DMAReadIdx, Afe_Block->u4DataRemained, count); } else { /* copy twice */
static int mtk_pcm_I2S0dl1_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; int copy_size = 0, Afe_WriteIdx_tmp; unsigned long flags; //struct snd_pcm_runtime *runtime = substream->runtime; char *data_w_ptr = (char *)dst; PRINTK_AUD_DL1("mtk_pcm_copy pos = %lu count = %lu\n ", pos, count); #ifdef _DEBUG_6328_CLK // printk("TEST_OUT = 0x%x\n", Ana_Get_Reg(TEST_OUT)); // printk("AFUNC_AUD_MON0 = 0x%x\n", Ana_Get_Reg(AFUNC_AUD_MON0)); // printk("AFUNC_AUD_MON1 = 0x%x\n", Ana_Get_Reg(AFUNC_AUD_MON1)); #endif // get total bytes to copy count = audio_frame_to_bytes(substream , count); // check which memif nned to be write Afe_Block = &pI2S0dl1MemControl->rBlock; // handle for buffer management PRINTK_AUD_DL1(" 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(" u4BufferSize=0 Error"); return 0; } spin_lock_irqsave(&auddrv_I2S0dl1_lock, flags); copy_size = Afe_Block->u4BufferSize - Afe_Block->u4DataRemained; // free space of the buffer spin_unlock_irqrestore(&auddrv_I2S0dl1_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, (unsigned int)count); if (copy_size != 0) { spin_lock_irqsave(&auddrv_I2S0dl1_lock, flags); Afe_WriteIdx_tmp = Afe_Block->u4WriteIdx; spin_unlock_irqrestore(&auddrv_I2S0dl1_lock, flags); if (Afe_WriteIdx_tmp + copy_size < Afe_Block->u4BufferSize) // copy once { if (!access_ok(VERIFY_READ, data_w_ptr, copy_size)) { PRINTK_AUDDRV("0ptr invalid data_w_ptr=%p, size=%d", data_w_ptr, copy_size); PRINTK_AUDDRV(" u4BufferSize=%d, u4DataRemained=%d", Afe_Block->u4BufferSize, Afe_Block->u4DataRemained); } else { PRINTK_AUD_DL1("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_AUDDRV(" Fail copy from user \n"); return -1; } } spin_lock_irqsave(&auddrv_I2S0dl1_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_I2S0dl1_lock, flags); data_w_ptr += copy_size; count -= copy_size; PRINTK_AUD_DL1(" 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, (unsigned int)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(" 1ptr invalid data_w_ptr=%p, size_1=%d", data_w_ptr, size_1); printk(" u4BufferSize=%d, u4DataRemained=%d", Afe_Block->u4BufferSize, Afe_Block->u4DataRemained); } else { PRINTK_AUD_DL1("mcmcpy Afe_Block->pucVirtBufAddr+Afe_WriteIdx= %p 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_AUDDRV(" Fail 1 copy from user"); return -1; } } spin_lock_irqsave(&auddrv_I2S0dl1_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_I2S0dl1_lock, flags); if (!access_ok(VERIFY_READ, data_w_ptr + size_1, size_2)) { PRINTK_AUDDRV("2ptr invalid data_w_ptr=%p, size_1=%d, size_2=%d", data_w_ptr, size_1, size_2); PRINTK_AUDDRV("u4BufferSize=%d, u4DataRemained=%d", Afe_Block->u4BufferSize, Afe_Block->u4DataRemained); } else { PRINTK_AUD_DL1("mcmcpy Afe_Block->pucVirtBufAddr+Afe_WriteIdx= %p 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_AUDDRV("AudDrv_write Fail 2 copy from user"); return -1; } } spin_lock_irqsave(&auddrv_I2S0dl1_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_I2S0dl1_lock, flags); count -= copy_size; data_w_ptr += copy_size; PRINTK_AUD_DL1(" finish2, copy size:%x, WriteIdx:%x,ReadIdx=%x DataRemained:%x \r\n", copy_size, Afe_Block->u4WriteIdx, Afe_Block->u4DMAReadIdx, Afe_Block->u4DataRemained); } } PRINTK_AUD_DL1("pcm_copy return \n"); return 0; }