static snd_pcm_uframes_t mtk_dl1_awb_pcm_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 *Awb_Block = &(Dl1_AWB_Control_context->rBlock); PRINTK_AUD_AWB("mtk_dl1_awb_pcm_pointer Awb_Block->u4WriteIdx;= 0x%x \n", Awb_Block->u4WriteIdx); if (GetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_AWB) == true) { // get total bytes to copysinewavetohdmi Frameidx = audio_bytes_to_frame(substream , Awb_Block->u4WriteIdx); return Frameidx; HW_Cur_ReadIdx = Align64ByteSize(Afe_Get_Reg(AFE_AWB_CUR)); if (HW_Cur_ReadIdx == 0) { printk("[Auddrv] mtk_awb_pcm_pointer HW_Cur_ReadIdx ==0 \n"); HW_Cur_ReadIdx = Awb_Block->pucPhysBufAddr; } HW_memory_index = (HW_Cur_ReadIdx - Awb_Block->pucPhysBufAddr); Previous_Hw_cur = HW_memory_index; PRINTK_AUD_AWB("[Auddrv] mtk_awb_pcm_pointer =0x%x HW_memory_index = 0x%x\n", HW_Cur_ReadIdx, HW_memory_index); return audio_bytes_to_frame(substream, Previous_Hw_cur); } return 0; }
static snd_pcm_uframes_t mtk_i2s0_awb_pcm_pointer(struct snd_pcm_substream *substream) { kal_int32 HW_memory_index = 0; kal_int32 HW_Cur_ReadIdx = 0; /*modified by jiaqing.yang for ALPS02074446(For_JHZ6735M_65C_L_ALPS.L1.MP3.V1_P67) 20150706 begin*/ #if 0 //kal_uint32 Frameidx =0; #else kal_uint32 Frameidx =0; #endif /*modified by jiaqing.yang for ALPS02074446(For_JHZ6735M_65C_L_ALPS.L1.MP3.V1_P67) 20150706 end*/ AFE_BLOCK_T *Awb_Block = &(I2S0_AWB_Control_context->rBlock); PRINTK_AUD_AWB("mtk_i2s0_awb_pcm_pointer Awb_Block->u4WriteIdx;= 0x%x \n",Awb_Block->u4WriteIdx); if (GetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_AWB) == true) { // get total bytes to copysinewavetohdmi /*modified by jiaqing.yang for ALPS02074446(For_JHZ6735M_65C_L_ALPS.L1.MP3.V1_P67) 20150706 begin*/ #if 0 //Frameidx =audio_bytes_to_frame(substream , Awb_Block->u4WriteIdx); //return Frameidx; #else Frameidx =audio_bytes_to_frame(substream , Awb_Block->u4WriteIdx); return Frameidx; #endif /*modified by jiaqing.yang for ALPS02074446(For_JHZ6735M_65C_L_ALPS.L1.MP3.V1_P67) 20150706 begin*/ /*modified by jiaqing.yang for ALPS02074446(For_JHZ6735M_65C_L_ALPS.L1.MP3.V1_P67) 20150706 begin*/ #if 0 /*modified by jiaqing.yang for ALPS02074446(For_JHZ6735M_65C_L_ALPS.L1.MP3.V1_P67) 20150706 end*/ HW_Cur_ReadIdx = Align64ByteSize(Afe_Get_Reg(AFE_AWB_CUR)); if (HW_Cur_ReadIdx == 0) { printk("[Auddrv] mtk_awb_pcm_pointer HW_Cur_ReadIdx ==0 \n"); HW_Cur_ReadIdx = Awb_Block->pucPhysBufAddr; } HW_memory_index = (HW_Cur_ReadIdx - Awb_Block->pucPhysBufAddr); Previous_Hw_cur = HW_memory_index; PRINTK_AUD_AWB("[Auddrv] mtk_i2s0_awb_pcm_pointer =0x%x HW_memory_index = 0x%x\n", HW_Cur_ReadIdx, HW_memory_index); return audio_bytes_to_frame(substream,Previous_Hw_cur); /*modified by jiaqing.yang for ALPS02074446(For_JHZ6735M_65C_L_ALPS.L1.MP3.V1_P67) 20150706 begin*/ #endif /*modified by jiaqing.yang for ALPS02074446(For_JHZ6735M_65C_L_ALPS.L1.MP3.V1_P67) 20150706 end*/ } return 0; }
static int mtk_fm_i2s_awb_pcm_copy(struct snd_pcm_substream *substream, int channel, snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count) { AFE_MEM_CONTROL_T *pAWB_MEM_ConTrol = NULL; AFE_BLOCK_T *Awb_Block = NULL; char *Read_Data_Ptr = (char *)dst; ssize_t DMA_Read_Ptr = 0, read_size = 0, read_count = 0; unsigned long flags; /* get total bytes to copy */ #ifdef AUDIO_64BYTE_ALIGN count = Align64ByteSize(audio_frame_to_bytes(substream, count)); #else count = audio_frame_to_bytes(substream, count); #endif PRINTK_AUD_AWB("%s pos = %lu count = %lu\n ", __func__, pos, count); /* check which memif nned to be write */ pAWB_MEM_ConTrol = FM_I2S_AWB_Control_context; Awb_Block = &(pAWB_MEM_ConTrol->rBlock); if (pAWB_MEM_ConTrol == NULL) { pr_err("cannot find MEM control !!!!!!!\n"); msleep(50); return 0; } if (Awb_Block->u4BufferSize <= 0) { msleep(50); return 0; } if (CheckNullPointer((void *)Awb_Block->pucVirtBufAddr)) { pr_err("CheckNullPointer pucVirtBufAddr = %p\n", Awb_Block->pucVirtBufAddr); return 0; } spin_lock_irqsave(&auddrv_AWBInCtl_lock, flags); if (Awb_Block->u4DataRemained > Awb_Block->u4BufferSize) { pr_warn("AudDrv_MEMIF_Read u4DataRemained=%x > u4BufferSize=%x" , Awb_Block->u4DataRemained, Awb_Block->u4BufferSize); Awb_Block->u4DataRemained = 0; Awb_Block->u4DMAReadIdx = Awb_Block->u4WriteIdx; } if (count > Awb_Block->u4DataRemained) read_size = Awb_Block->u4DataRemained; else read_size = count; DMA_Read_Ptr = Awb_Block->u4DMAReadIdx; spin_unlock_irqrestore(&auddrv_AWBInCtl_lock, flags); PRINTK_AUD_AWB("AudDrv_MEMIF_Read finish0, read_count:0x%x, read_size:0x%x, u4DataRemained:0x%x, u4DMAReadIdx:0x%x, u4WriteIdx:0x%x \r\n", read_count, read_size, Awb_Block->u4DataRemained, Awb_Block->u4DMAReadIdx, Awb_Block->u4WriteIdx); if (DMA_Read_Ptr + read_size < Awb_Block->u4BufferSize) { if (DMA_Read_Ptr != Awb_Block->u4DMAReadIdx) { pr_warn ("%s 1, read_size:0x%zu, DataRemained:0x%x, DMA_Read_Ptr:0x%zu,DMAReadIdx:0x%x \r\n", __func__, read_size, Awb_Block->u4DataRemained, DMA_Read_Ptr, Awb_Block->u4DMAReadIdx); } if (copy_to_user((void __user *)Read_Data_Ptr, (Awb_Block->pucVirtBufAddr + DMA_Read_Ptr), read_size)) { pr_err ("%s Fail1 Read_Data_Ptr:%p,pucVirtBufAddr:%p,DMAReadIdx:0x%x,DMA_Read_Ptr:0x%zu,read_size:%zu", __func__, Read_Data_Ptr, Awb_Block->pucVirtBufAddr, Awb_Block->u4DMAReadIdx, DMA_Read_Ptr, read_size); return 0; } read_count += read_size; spin_lock(&auddrv_AWBInCtl_lock); Awb_Block->u4DataRemained -= read_size; Awb_Block->u4DMAReadIdx += read_size; Awb_Block->u4DMAReadIdx %= Awb_Block->u4BufferSize; DMA_Read_Ptr = Awb_Block->u4DMAReadIdx; spin_unlock(&auddrv_AWBInCtl_lock); Read_Data_Ptr += read_size; count -= read_size; PRINTK_AUD_AWB("AudDrv_MEMIF_Read finish1, copy size:0x%x, u4DMAReadIdx:0x%x, u4WriteIdx:0x%x, u4DataRemained:0x%x \r\n", read_size, Awb_Block->u4DMAReadIdx, Awb_Block->u4WriteIdx, Awb_Block->u4DataRemained); } else {
static int mtk_mrgrx_awb_pcm_copy(struct snd_pcm_substream *substream, int channel, snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count) { AFE_MEM_CONTROL_T *pAWB_MEM_ConTrol = NULL; AFE_BLOCK_T *Awb_Block = NULL; char *Read_Data_Ptr = (char *)dst; ssize_t DMA_Read_Ptr = 0 , read_size = 0, read_count = 0; unsigned long flags; // get total bytes to copy count = Align64ByteSize(audio_frame_to_bytes(substream , count)); PRINTK_AUD_AWB("%s pos = %lu count = %lu\n ", __func__,pos, count); // check which memif nned to be write pAWB_MEM_ConTrol = Mrgrx_AWB_Control_context; Awb_Block = &(pAWB_MEM_ConTrol->rBlock); if (pAWB_MEM_ConTrol == NULL) { printk("cannot find MEM control !!!!!!!\n"); msleep(50); return 0; } if (Awb_Block->u4BufferSize <= 0) { msleep(50); return 0; } if (CheckNullPointer((void *)Awb_Block->pucVirtBufAddr)) { printk("CheckNullPointer pucVirtBufAddr = %p\n", Awb_Block->pucVirtBufAddr); return 0; } spin_lock_irqsave(&auddrv_AWBInCtl_lock, flags); if (Awb_Block->u4DataRemained > Awb_Block->u4BufferSize) { printk("AudDrv_MEMIF_Read u4DataRemained=%x > u4BufferSize=%x" , Awb_Block->u4DataRemained, Awb_Block->u4BufferSize); Awb_Block->u4DataRemained = 0; Awb_Block->u4DMAReadIdx = Awb_Block->u4WriteIdx; } if (count > Awb_Block->u4DataRemained) { read_size = Awb_Block->u4DataRemained; } else { read_size = count; } DMA_Read_Ptr = Awb_Block->u4DMAReadIdx + Get_Mem_CopySizeByStream(Soc_Aud_Digital_Block_MEM_AWB,substream); PRINTK_AUD_AWB("Awb_Block->u4DMAReadIdx= 0x%x Get_Mem_CopySizeByStream = 0x%x \r\n", Awb_Block->u4DMAReadIdx ,Get_Mem_CopySizeByStream(Soc_Aud_Digital_Block_MEM_AWB,substream)); if(DMA_Read_Ptr >= Awb_Block->u4BufferSize ) { DMA_Read_Ptr -=Awb_Block->u4BufferSize; } spin_unlock_irqrestore(&auddrv_AWBInCtl_lock, flags); PRINTK_AUD_AWB("AudDrv_MEMIF_Read finish0, read_count:0x%x, read_size:0x%x, u4DataRemained:0x%x, u4DMAReadIdx:0x%x, u4WriteIdx:0x%x \r\n", read_count, read_size, Awb_Block->u4DataRemained, Awb_Block->u4DMAReadIdx, Awb_Block->u4WriteIdx); if (DMA_Read_Ptr + read_size <= Awb_Block->u4BufferSize) { if (DMA_Read_Ptr != Awb_Block->u4DMAReadIdx) { printk("AudDrv_MEMIF_Read 1, read_size:%zu, DataRemained:0x%x, DMA_Read_Ptr:%zu, DMAReadIdx:0x%x \r\n", read_size, Awb_Block->u4DataRemained, DMA_Read_Ptr, Awb_Block->u4DMAReadIdx); } if (copy_to_user((void __user *)Read_Data_Ptr, (Awb_Block->pucVirtBufAddr + DMA_Read_Ptr), read_size)) { printk("AudDrv_MEMIF_Read Fail 1 copy to user Read_Data_Ptr:%p, pucVirtBufAddr:%p, u4DMAReadIdx:0x%x, DMA_Read_Ptr:%zu,read_size:%zu", Read_Data_Ptr, Awb_Block->pucVirtBufAddr, Awb_Block->u4DMAReadIdx, DMA_Read_Ptr, read_size); return 0; } read_count += read_size; spin_lock(&auddrv_AWBInCtl_lock); Set_Mem_CopySizeByStream(Soc_Aud_Digital_Block_MEM_AWB,substream,read_size); spin_unlock(&auddrv_AWBInCtl_lock); Read_Data_Ptr += read_size; count -= read_size; PRINTK_AUD_AWB("AudDrv_MEMIF_Read finish1, copy size:0x%x, u4DMAReadIdx:0x%x, u4WriteIdx:0x%x, u4DataRemained:0x%x u4MaxCopySize:0x%x \n", read_size, Awb_Block->u4DMAReadIdx, Awb_Block->u4WriteIdx, Awb_Block->u4DataRemained,Get_Mem_CopySizeByStream(Soc_Aud_Digital_Block_MEM_AWB,substream)); } else { uint32 size_1 , size_2; size_1 = Awb_Block->u4BufferSize - DMA_Read_Ptr; size_2 = read_size - size_1; if (DMA_Read_Ptr != Awb_Block->u4DMAReadIdx) { printk("AudDrv_MEMIF_Read 2, read_size1:0x%x, DataRemained:0x%x, DMA_Read_Ptr:%zu, DMAReadIdx:0x%x \r\n", size_1, Awb_Block->u4DataRemained, DMA_Read_Ptr, Awb_Block->u4DMAReadIdx); } if (copy_to_user((void __user *)Read_Data_Ptr, (Awb_Block->pucVirtBufAddr + DMA_Read_Ptr), size_1)) { printk("AudDrv_MEMIF_Read Fail 2 copy to user Read_Data_Ptr:%p, pucVirtBufAddr:%p, u4DMAReadIdx:0x%x, DMA_Read_Ptr:%zu,read_size:%zu", Read_Data_Ptr, Awb_Block->pucVirtBufAddr, Awb_Block->u4DMAReadIdx, DMA_Read_Ptr, read_size); return 0; } read_count += size_1; spin_lock(&auddrv_AWBInCtl_lock); DMA_Read_Ptr += size_1; Set_Mem_CopySizeByStream(Soc_Aud_Digital_Block_MEM_AWB,substream,size_1); if(DMA_Read_Ptr >= Awb_Block->u4BufferSize ) { DMA_Read_Ptr -= Awb_Block->u4BufferSize; } spin_unlock(&auddrv_AWBInCtl_lock); PRINTK_AUD_AWB("AudDrv_MEMIF_Read finish2, copy size_1:0x%x, u4DMAReadIdx:0x%x, u4WriteIdx:0x%x, u4DataRemained:0x%x \r\n", size_1, Awb_Block->u4DMAReadIdx, Awb_Block->u4WriteIdx, Awb_Block->u4DataRemained); if (DMA_Read_Ptr != Awb_Block->u4DMAReadIdx) { PRINTK_AUD_AWB("AudDrv_AWB_Read 3, read_size2:%x, DataRemained:%x, DMA_Read_Ptr:0x%x, DMAReadIdx:%x \r\n", size_2, Awb_Block->u4DataRemained, DMA_Read_Ptr, Awb_Block->u4DMAReadIdx); } if (copy_to_user((void __user *)(Read_Data_Ptr + size_1), (Awb_Block->pucVirtBufAddr + DMA_Read_Ptr), size_2)) { printk("AudDrv_MEMIF_Read Fail 3 copy to user Read_Data_Ptr:%p, pucVirtBufAddr:%p, u4DMAReadIdx:0x%x , DMA_Read_Ptr:0x%zu, read_size:%zu", Read_Data_Ptr, Awb_Block->pucVirtBufAddr, Awb_Block->u4DMAReadIdx, DMA_Read_Ptr, read_size); return read_count << 2; } read_count += size_2; spin_lock(&auddrv_AWBInCtl_lock); DMA_Read_Ptr += size_2; Set_Mem_CopySizeByStream(Soc_Aud_Digital_Block_MEM_AWB,substream,size_2); spin_unlock(&auddrv_AWBInCtl_lock); count -= read_size; Read_Data_Ptr += read_size; PRINTK_AUD_AWB("AudDrv_MEMIF_Read finish3, copy size_2:0x%x, u4DMAReadIdx:0x%x, u4WriteIdx:0x%x u4DataRemained:0x%x \r\n", size_2, Awb_Block->u4DMAReadIdx, Awb_Block->u4WriteIdx, Awb_Block->u4DataRemained); } return read_count >> 2; }