2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /*******************************************************************************
24 * Audio Driver Kernel Function
28 * Audio i2s0 to awb capture
34 *------------------------------------------------------------------------------
40 *******************************************************************************/
43 /*****************************************************************************
44 * C O M P I L E R F L A G S
45 *****************************************************************************/
48 /*****************************************************************************
49 * E X T E R N A L R E F E R E N C E S
50 *****************************************************************************/
52 #include <linux/dma-mapping.h>
53 #include "AudDrv_Common.h"
54 #include "AudDrv_Def.h"
55 #include "AudDrv_Afe.h"
56 #include "AudDrv_Ana.h"
57 #include "AudDrv_Clk.h"
58 #include "AudDrv_Kernel.h"
59 #include "mt_soc_afe_control.h"
60 #include "mt_soc_pcm_common.h"
62 //#define DUMP_HWGAIN1_AWB
65 static AFE_MEM_CONTROL_T
*I2S0_AWB_Control_context
= NULL
;
66 static struct snd_dma_buffer
*Awb_Capture_dma_buf
= NULL
;
68 static DEFINE_SPINLOCK(auddrv_Dl1AWBInCtl_lock
);
71 * function implementation
73 static void StartAudioI2S0AWBHardware(struct snd_pcm_substream
*substream
);
74 static void StopAudioI2S0AWBHardware(struct snd_pcm_substream
*substream
);
75 static int mtk_i2s0_awb_probe(struct platform_device
*pdev
);
76 static int mtk_i2s0_awb_pcm_close(struct snd_pcm_substream
*substream
);
77 static int mtk_asoc_i2s0_awb_pcm_new(struct snd_soc_pcm_runtime
*rtd
);
78 static int mtk_i2s0_dl1_awb_probe(struct snd_soc_platform
*platform
);
80 static struct snd_pcm_hardware mtk_I2S0_awb_hardware
=
82 .info
= (SNDRV_PCM_INFO_INTERLEAVED
),
83 .formats
= SND_SOC_STD_MT_FMTS
,
84 .rates
= SOC_HIGH_USE_RATE
,
85 .rate_min
= SOC_HIGH_USE_RATE_MIN
,
86 .rate_max
= SOC_HIGH_USE_RATE_MAX
,
87 .channels_min
= SOC_NORMAL_USE_CHANNELS_MIN
,
88 .channels_max
= SOC_NORMAL_USE_CHANNELS_MAX
,
89 .buffer_bytes_max
= AWB_MAX_BUFFER_SIZE
,
90 .period_bytes_max
= AWB_MAX_BUFFER_SIZE
,
91 .periods_min
= AWB_MIN_PERIOD_SIZE
,
92 .periods_max
= AWB_MAX_PERIOD_SIZE
,
96 static void StopAudioI2S0AWBHardware(struct snd_pcm_substream
*substream
)
98 printk("StopAudioI2S0AWBHardware \n");
100 SetMemoryPathEnable(Soc_Aud_Digital_Block_I2S_IN_2
, false);
101 SetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_AWB
, false);
103 // here to set interrupt
104 SetIrqEnable(Soc_Aud_IRQ_MCU_MODE_IRQ2_MCU_MODE
, false);
106 Afe_Set_Reg(AFE_I2S_CON
, 0x0, 0x1);
108 // here to turn off digital part
109 #ifdef DUMP_HWGAIN1_AWB
110 SetConnection(Soc_Aud_InterCon_DisConnect
, Soc_Aud_InterConnectionInput_I10
, Soc_Aud_InterConnectionOutput_O05
);
111 SetConnection(Soc_Aud_InterCon_DisConnect
, Soc_Aud_InterConnectionInput_I11
, Soc_Aud_InterConnectionOutput_O06
);
113 SetConnection(Soc_Aud_InterCon_DisConnect
, Soc_Aud_InterConnectionInput_I00
, Soc_Aud_InterConnectionOutput_O05
);
114 SetConnection(Soc_Aud_InterCon_DisConnect
, Soc_Aud_InterConnectionInput_I01
, Soc_Aud_InterConnectionOutput_O06
);
119 static void StartAudioI2S0AWBHardware(struct snd_pcm_substream
*substream
)
121 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
123 uint32 Audio_I2S_Dac
= 0;
126 const bool bEnablePhaseShiftFix
= true;
128 printk("StartAudioI2S0AWBHardware \n");
131 MclkDiv0
= SetCLkMclk(Soc_Aud_I2S0
, runtime
->rate
); //select I2S
132 SetCLkBclk(MclkDiv0
, runtime
->rate
, runtime
->channels
, Soc_Aud_I2S_WLEN_WLEN_32BITS
);
135 SetSampleRate(Soc_Aud_Digital_Block_MEM_I2S
, runtime
->rate
);
137 Audio_I2S_Dac
|= (bEnablePhaseShiftFix
<< 31);
138 Audio_I2S_Dac
|= (Soc_Aud_I2S_IN_PAD_SEL_I2S_IN_FROM_IO_MUX
<< 28);//I2S in from io_mux
139 Audio_I2S_Dac
|= Soc_Aud_LOW_JITTER_CLOCK
<< 12 ; //Low jitter mode
140 Audio_I2S_Dac
|= (Soc_Aud_INV_LRCK_NO_INVERSE
<< 5);
141 Audio_I2S_Dac
|= (Soc_Aud_I2S_FORMAT_I2S
<< 3);
142 Audio_I2S_Dac
|= (Soc_Aud_I2S_WLEN_WLEN_32BITS
<< 1);
143 Afe_Set_Reg(AFE_I2S_CON
, Audio_I2S_Dac
| 0x1, MASK_ALL
);
145 // here to set interrupt
146 SetIrqMcuCounter(Soc_Aud_IRQ_MCU_MODE_IRQ2_MCU_MODE
, substream
->runtime
->period_size
);
147 SetIrqMcuSampleRate(Soc_Aud_IRQ_MCU_MODE_IRQ2_MCU_MODE
, substream
->runtime
->rate
);
148 SetIrqEnable(Soc_Aud_IRQ_MCU_MODE_IRQ2_MCU_MODE
, true);
150 SetSampleRate(Soc_Aud_Digital_Block_MEM_AWB
, substream
->runtime
->rate
);
151 SetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_AWB
, true);
152 SetMemoryPathEnable(Soc_Aud_Digital_Block_I2S_IN_2
, true);
154 // here to turn off digital part
155 #ifdef DUMP_HWGAIN1_AWB
157 SetConnection(Soc_Aud_InterCon_DisConnect
, Soc_Aud_InterConnectionInput_I00
, Soc_Aud_InterConnectionOutput_O05
);
158 SetConnection(Soc_Aud_InterCon_DisConnect
, Soc_Aud_InterConnectionInput_I01
, Soc_Aud_InterConnectionOutput_O06
);
159 printk("%s() Soc_Aud_InterCon_Connection I10 O5\n", __func__
);
160 SetConnection(Soc_Aud_InterCon_Connection
, Soc_Aud_InterConnectionInput_I10
, Soc_Aud_InterConnectionOutput_O05
);
161 printk("%s() Soc_Aud_InterCon_Connection I11 O6\n", __func__
);
162 SetConnection(Soc_Aud_InterCon_Connection
, Soc_Aud_InterConnectionInput_I11
, Soc_Aud_InterConnectionOutput_O06
);
165 REG420
= Afe_Get_Reg(AFE_GAIN1_CONN
);
166 printk("%s() AFE_GAIN1_CONN (0X420) =0x%x\n", __func__
, REG420
);
168 SetConnection(Soc_Aud_InterCon_Connection
, Soc_Aud_InterConnectionInput_I00
, Soc_Aud_InterConnectionOutput_O05
);
169 SetConnection(Soc_Aud_InterCon_Connection
, Soc_Aud_InterConnectionInput_I01
, Soc_Aud_InterConnectionOutput_O06
);
175 static int mtk_i2s0_awb_pcm_prepare(struct snd_pcm_substream
*substream
)
177 printk("mtk_i2s0_awb_pcm_prepare substream->rate = %d substream->channels = %d \n", substream
->runtime
->rate
, substream
->runtime
->channels
);
181 static int mtk_i2s0_awb_alsa_stop(struct snd_pcm_substream
*substream
)
183 //AFE_BLOCK_T *Awb_Block = &(I2S0_AWB_Control_context->rBlock);
184 printk("mtk_i2s0_awb_alsa_stop \n");
185 StopAudioI2S0AWBHardware(substream
);
186 RemoveMemifSubStream(Soc_Aud_Digital_Block_MEM_AWB
,substream
);
190 static kal_int32 Previous_Hw_cur
= 0;
191 static snd_pcm_uframes_t
mtk_i2s0_awb_pcm_pointer(struct snd_pcm_substream
*substream
)
193 kal_int32 HW_memory_index
= 0;
194 kal_int32 HW_Cur_ReadIdx
= 0;
195 kal_uint32 Frameidx
=0;
196 AFE_BLOCK_T
*Awb_Block
= &(I2S0_AWB_Control_context
->rBlock
);
197 PRINTK_AUD_AWB("mtk_i2s0_awb_pcm_pointer Awb_Block->u4WriteIdx;= 0x%x \n",Awb_Block
->u4WriteIdx
);
198 if (GetMemoryPathEnable(Soc_Aud_Digital_Block_MEM_AWB
) == true)
200 // get total bytes to copysinewavetohdmi
201 Frameidx
=audio_bytes_to_frame(substream
, Awb_Block
->u4WriteIdx
);
204 HW_Cur_ReadIdx
= Align64ByteSize(Afe_Get_Reg(AFE_AWB_CUR
));
205 if (HW_Cur_ReadIdx
== 0)
207 printk("[Auddrv] mtk_awb_pcm_pointer HW_Cur_ReadIdx ==0 \n");
208 HW_Cur_ReadIdx
= Awb_Block
->pucPhysBufAddr
;
210 HW_memory_index
= (HW_Cur_ReadIdx
- Awb_Block
->pucPhysBufAddr
);
211 Previous_Hw_cur
= HW_memory_index
;
212 PRINTK_AUD_AWB("[Auddrv] mtk_i2s0_awb_pcm_pointer =0x%x HW_memory_index = 0x%x\n", HW_Cur_ReadIdx
, HW_memory_index
);
213 return audio_bytes_to_frame(substream
,Previous_Hw_cur
);
219 static void SetAWBBuffer(struct snd_pcm_substream
*substream
,
220 struct snd_pcm_hw_params
*hw_params
)
222 AFE_BLOCK_T
*pblock
= &I2S0_AWB_Control_context
->rBlock
;
223 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
224 printk("SetAWBBuffer\n");
225 pblock
->pucPhysBufAddr
= runtime
->dma_addr
;
226 pblock
->pucVirtBufAddr
= runtime
->dma_area
;
227 pblock
->u4BufferSize
= runtime
->dma_bytes
;
228 pblock
->u4SampleNumMask
= 0x001f; // 32 byte align
229 pblock
->u4WriteIdx
= 0;
230 pblock
->u4DMAReadIdx
= 0;
231 pblock
->u4DataRemained
= 0;
232 pblock
->u4fsyncflag
= false;
233 pblock
->uResetFlag
= true;
234 printk("dma_bytes = %d dma_area = %p dma_addr = 0x%x\n",
235 pblock
->u4BufferSize
, pblock
->pucVirtBufAddr
, pblock
->pucPhysBufAddr
);
236 // set sram address top hardware
237 Afe_Set_Reg(AFE_AWB_BASE
, pblock
->pucPhysBufAddr
, 0xffffffff);
238 Afe_Set_Reg(AFE_AWB_END
, pblock
->pucPhysBufAddr
+ (pblock
->u4BufferSize
- 1), 0xffffffff);
242 static int mtk_i2s0_awb_pcm_hw_params(struct snd_pcm_substream
*substream
,
243 struct snd_pcm_hw_params
*hw_params
)
245 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
246 struct snd_dma_buffer
*dma_buf
= &substream
->dma_buffer
;
249 printk("mtk_i2s0_awb_pcm_hw_params \n");
251 dma_buf
->dev
.type
= SNDRV_DMA_TYPE_DEV
;
252 dma_buf
->dev
.dev
= substream
->pcm
->card
->dev
;
253 dma_buf
->private_data
= NULL
;
255 if (Awb_Capture_dma_buf
->area
)
257 printk("mtk_i2s0_awb_pcm_hw_params Awb_Capture_dma_buf->area\n");
258 runtime
->dma_bytes
= params_buffer_bytes(hw_params
);
259 runtime
->dma_area
= Awb_Capture_dma_buf
->area
;
260 runtime
->dma_addr
= Awb_Capture_dma_buf
->addr
;
264 printk("mtk_i2s0_awb_pcm_hw_params snd_pcm_lib_malloc_pages\n");
265 ret
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
267 printk("mtk_i2s0_awb_pcm_hw_params dma_bytes = %zu dma_area = %p dma_addr = 0x%lx\n",
268 runtime
->dma_bytes
, runtime
->dma_area
, (long)runtime
->dma_addr
);
270 printk("runtime->hw.buffer_bytes_max = %zu \n", runtime
->hw
.buffer_bytes_max
);
271 SetAWBBuffer(substream
, hw_params
);
273 printk("dma_bytes = %zu dma_area = %p dma_addr = 0x%lx\n",
274 substream
->runtime
->dma_bytes
, substream
->runtime
->dma_area
, (long)substream
->runtime
->dma_addr
);
278 static int mtk_i2s0_capture_pcm_hw_free(struct snd_pcm_substream
*substream
)
280 printk("mtk_i2s0_capture_pcm_hw_free \n");
281 if (Awb_Capture_dma_buf
->area
)
287 return snd_pcm_lib_free_pages(substream
);
291 static struct snd_pcm_hw_constraint_list dl1_awb_constraints_sample_rates
=
293 .count
= ARRAY_SIZE(soc_high_supported_sample_rates
),
294 .list
= soc_high_supported_sample_rates
,
297 static int mtk_i2s0_awb_pcm_open(struct snd_pcm_substream
*substream
)
299 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
301 printk("mtk_i2s0_awb_pcm_open\n");
302 I2S0_AWB_Control_context
= Get_Mem_ControlT(Soc_Aud_Digital_Block_MEM_AWB
);
303 runtime
->hw
= mtk_I2S0_awb_hardware
;
304 memcpy((void *)(&(runtime
->hw
)), (void *)&mtk_I2S0_awb_hardware
, sizeof(struct snd_pcm_hardware
));
306 ret
= snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
307 &dl1_awb_constraints_sample_rates
);
308 ret
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
);
312 printk("snd_pcm_hw_constraint_integer failed\n");
315 // here open audio clocks
318 //print for hw pcm information
319 printk("mtk_i2s0_awb_pcm_open runtime rate = %d channels = %d \n", runtime
->rate
, runtime
->channels
);
320 runtime
->hw
.info
|= SNDRV_PCM_INFO_INTERLEAVED
;
321 runtime
->hw
.info
|= SNDRV_PCM_INFO_NONINTERLEAVED
;
322 runtime
->hw
.info
|= SNDRV_PCM_INFO_MMAP_VALID
;
324 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
326 printk("SNDRV_PCM_STREAM_CAPTURE \n");
335 printk("mtk_i2s0_awb_pcm_close\n");
336 mtk_i2s0_awb_pcm_close(substream
);
340 printk("mtk_i2s0_awb_pcm_open return\n");
344 static int mtk_i2s0_awb_pcm_close(struct snd_pcm_substream
*substream
)
346 AudDrv_Emi_Clk_Off();
350 static int mtk_i2s0_awb_alsa_start(struct snd_pcm_substream
*substream
)
352 printk("mtk_i2s0_awb_alsa_start \n");
353 SetMemifSubStream(Soc_Aud_Digital_Block_MEM_AWB
, substream
);
354 StartAudioI2S0AWBHardware(substream
);
358 static int mtk_i2s0_awb_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
360 printk("mtk_i2s0_awb_pcm_trigger cmd = %d\n", cmd
);
364 case SNDRV_PCM_TRIGGER_START
:
365 case SNDRV_PCM_TRIGGER_RESUME
:
366 return mtk_i2s0_awb_alsa_start(substream
);
367 case SNDRV_PCM_TRIGGER_STOP
:
368 case SNDRV_PCM_TRIGGER_SUSPEND
:
369 return mtk_i2s0_awb_alsa_stop(substream
);
374 static bool CheckNullPointer(void *pointer
)
378 printk("CheckNullPointer pointer = NULL");
384 static int mtk_i2s0_awb_pcm_copy(struct snd_pcm_substream
*substream
,
385 int channel
, snd_pcm_uframes_t pos
,
386 void __user
*dst
, snd_pcm_uframes_t count
)
388 AFE_MEM_CONTROL_T
*pAWB_MEM_ConTrol
= NULL
;
389 AFE_BLOCK_T
*Awb_Block
= NULL
;
390 char *Read_Data_Ptr
= (char *)dst
;
391 ssize_t DMA_Read_Ptr
= 0 , read_size
= 0, read_count
= 0;
394 // get total bytes to copy
395 count
= Align64ByteSize(audio_frame_to_bytes(substream
, count
));
397 printk("%s pos = %lu count = %lu\n ", __func__
, pos
, count
);
399 // check which memif nned to be write
400 pAWB_MEM_ConTrol
= I2S0_AWB_Control_context
;
401 Awb_Block
= &(pAWB_MEM_ConTrol
->rBlock
);
403 if (pAWB_MEM_ConTrol
== NULL
)
405 printk("cannot find MEM control !!!!!!!\n");
410 if (Awb_Block
->u4BufferSize
<= 0)
416 if (CheckNullPointer((void *)Awb_Block
->pucVirtBufAddr
))
418 printk("CheckNullPointer pucVirtBufAddr = %p\n", Awb_Block
->pucVirtBufAddr
);
422 spin_lock_irqsave(&auddrv_Dl1AWBInCtl_lock
, flags
);
423 if (Awb_Block
->u4DataRemained
> Awb_Block
->u4BufferSize
)
425 printk("AudDrv_MEMIF_Read u4DataRemained=%x > u4BufferSize=%x" , Awb_Block
->u4DataRemained
, Awb_Block
->u4BufferSize
);
426 Awb_Block
->u4DataRemained
= 0;
427 Awb_Block
->u4DMAReadIdx
= Awb_Block
->u4WriteIdx
;
429 if (count
> Awb_Block
->u4DataRemained
)
431 read_size
= Awb_Block
->u4DataRemained
;
438 DMA_Read_Ptr
= Awb_Block
->u4DMAReadIdx
;
439 spin_unlock_irqrestore(&auddrv_Dl1AWBInCtl_lock
, flags
);
441 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",
442 read_count
, read_size
, Awb_Block
->u4DataRemained
, Awb_Block
->u4DMAReadIdx
, Awb_Block
->u4WriteIdx
);
444 if (DMA_Read_Ptr
+ read_size
< Awb_Block
->u4BufferSize
)
446 if (DMA_Read_Ptr
!= Awb_Block
->u4DMAReadIdx
)
448 printk("AudDrv_MEMIF_Read 1, read_size:%zu, DataRemained:0x%x, DMA_Read_Ptr:%zu, DMAReadIdx:0x%x \r\n",
449 read_size
, Awb_Block
->u4DataRemained
, DMA_Read_Ptr
, Awb_Block
->u4DMAReadIdx
);
452 if (copy_to_user((void __user
*)Read_Data_Ptr
, (Awb_Block
->pucVirtBufAddr
+ DMA_Read_Ptr
), read_size
))
455 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
);
459 read_count
+= read_size
;
460 spin_lock(&auddrv_Dl1AWBInCtl_lock
);
461 Awb_Block
->u4DataRemained
-= read_size
;
462 Awb_Block
->u4DMAReadIdx
+= read_size
;
463 Awb_Block
->u4DMAReadIdx
%= Awb_Block
->u4BufferSize
;
464 DMA_Read_Ptr
= Awb_Block
->u4DMAReadIdx
;
465 spin_unlock(&auddrv_Dl1AWBInCtl_lock
);
467 Read_Data_Ptr
+= read_size
;
470 PRINTK_AUD_AWB("AudDrv_MEMIF_Read finish1, copy size:0x%x, u4DMAReadIdx:0x%x, u4WriteIdx:0x%x, u4DataRemained:0x%x \r\n",
471 read_size
, Awb_Block
->u4DMAReadIdx
, Awb_Block
->u4WriteIdx
, Awb_Block
->u4DataRemained
);
476 uint32 size_1
= Awb_Block
->u4BufferSize
- DMA_Read_Ptr
;
477 uint32 size_2
= read_size
- size_1
;
479 if (DMA_Read_Ptr
!= Awb_Block
->u4DMAReadIdx
)
482 printk("AudDrv_MEMIF_Read 2, read_size1:0x%x, DataRemained:0x%x, DMA_Read_Ptr:%zu, DMAReadIdx:0x%x \r\n",
483 size_1
, Awb_Block
->u4DataRemained
, DMA_Read_Ptr
, Awb_Block
->u4DMAReadIdx
);
485 if (copy_to_user((void __user
*)Read_Data_Ptr
, (Awb_Block
->pucVirtBufAddr
+ DMA_Read_Ptr
), size_1
))
488 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",
489 Read_Data_Ptr
, Awb_Block
->pucVirtBufAddr
, Awb_Block
->u4DMAReadIdx
, DMA_Read_Ptr
, read_size
);
493 read_count
+= size_1
;
494 spin_lock(&auddrv_Dl1AWBInCtl_lock
);
495 Awb_Block
->u4DataRemained
-= size_1
;
496 Awb_Block
->u4DMAReadIdx
+= size_1
;
497 Awb_Block
->u4DMAReadIdx
%= Awb_Block
->u4BufferSize
;
498 DMA_Read_Ptr
= Awb_Block
->u4DMAReadIdx
;
499 spin_unlock(&auddrv_Dl1AWBInCtl_lock
);
501 PRINTK_AUD_AWB("AudDrv_MEMIF_Read finish2, copy size_1:0x%x, u4DMAReadIdx:0x%x, u4WriteIdx:0x%x, u4DataRemained:0x%x \r\n",
502 size_1
, Awb_Block
->u4DMAReadIdx
, Awb_Block
->u4WriteIdx
, Awb_Block
->u4DataRemained
);
504 if (DMA_Read_Ptr
!= Awb_Block
->u4DMAReadIdx
)
507 printk("AudDrv_AWB_Read 3, read_size2:%x, DataRemained:%x, DMA_Read_Ptr:%zu, DMAReadIdx:%x \r\n",
508 size_2
, Awb_Block
->u4DataRemained
, DMA_Read_Ptr
, Awb_Block
->u4DMAReadIdx
);
510 if (copy_to_user((void __user
*)(Read_Data_Ptr
+ size_1
), (Awb_Block
->pucVirtBufAddr
+ DMA_Read_Ptr
), size_2
))
513 printk("AudDrv_MEMIF_Read Fail 3 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
);
514 return read_count
<< 2;
517 read_count
+= size_2
;
518 spin_lock(&auddrv_Dl1AWBInCtl_lock
);
519 Awb_Block
->u4DataRemained
-= size_2
;
520 Awb_Block
->u4DMAReadIdx
+= size_2
;
521 DMA_Read_Ptr
= Awb_Block
->u4DMAReadIdx
;
522 spin_unlock(&auddrv_Dl1AWBInCtl_lock
);
525 Read_Data_Ptr
+= read_size
;
527 PRINTK_AUD_AWB("AudDrv_MEMIF_Read finish3, copy size_2:0x%x, u4DMAReadIdx:0x%x, u4WriteIdx:0x%x u4DataRemained:0x%x \r\n",
528 size_2
, Awb_Block
->u4DMAReadIdx
, Awb_Block
->u4WriteIdx
, Awb_Block
->u4DataRemained
);
531 return read_count
>> 2;
534 static int mtk_capture_pcm_silence(struct snd_pcm_substream
*substream
,
535 int channel
, snd_pcm_uframes_t pos
,
536 snd_pcm_uframes_t count
)
538 printk("dummy_pcm_silence \n");
539 return 0; /* do nothing */
543 static void *dummy_page
[2];
545 static struct page
*mtk_i2s0_capture_pcm_page(struct snd_pcm_substream
*substream
,
546 unsigned long offset
)
548 printk("dummy_pcm_page \n");
549 return virt_to_page(dummy_page
[substream
->stream
]); /* the same page */
553 static struct snd_pcm_ops mtk_i2s0_awb_ops
=
555 .open
= mtk_i2s0_awb_pcm_open
,
556 .close
= mtk_i2s0_awb_pcm_close
,
557 .ioctl
= snd_pcm_lib_ioctl
,
558 .hw_params
= mtk_i2s0_awb_pcm_hw_params
,
559 .hw_free
= mtk_i2s0_capture_pcm_hw_free
,
560 .prepare
= mtk_i2s0_awb_pcm_prepare
,
561 .trigger
= mtk_i2s0_awb_pcm_trigger
,
562 .pointer
= mtk_i2s0_awb_pcm_pointer
,
563 .copy
= mtk_i2s0_awb_pcm_copy
,
564 .silence
= mtk_capture_pcm_silence
,
565 .page
= mtk_i2s0_capture_pcm_page
,
568 static struct snd_soc_platform_driver mtk_soc_platform
=
570 .ops
= &mtk_i2s0_awb_ops
,
571 .pcm_new
= mtk_asoc_i2s0_awb_pcm_new
,
572 .probe
= mtk_i2s0_dl1_awb_probe
,
575 static int mtk_i2s0_awb_probe(struct platform_device
*pdev
)
577 printk("mtk_i2s0_awb_probe\n");
579 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(64);
580 if (!pdev
->dev
.dma_mask
)
582 pdev
->dev
.dma_mask
= &pdev
->dev
.coherent_dma_mask
;
585 if (pdev
->dev
.of_node
)
587 dev_set_name(&pdev
->dev
, "%s", MT_SOC_I2S0_AWB_PCM
);
590 printk("%s: dev name %s\n", __func__
, dev_name(&pdev
->dev
));
591 return snd_soc_register_platform(&pdev
->dev
,
595 static int mtk_asoc_i2s0_awb_pcm_new(struct snd_soc_pcm_runtime
*rtd
)
597 printk("mtk_asoc_i2s0_awb_pcm_new \n");
601 static int mtk_i2s0_dl1_awb_probe(struct snd_soc_platform
*platform
)
603 printk("mtk_i2s0_dl1_awb_probe\n");
604 AudDrv_Allocate_mem_Buffer(platform
->dev
, Soc_Aud_Digital_Block_MEM_AWB
, AWB_MAX_BUFFER_SIZE
);
605 Awb_Capture_dma_buf
= Get_Mem_Buffer(Soc_Aud_Digital_Block_MEM_AWB
);
609 static int mtk_dl1_awb_remove(struct platform_device
*pdev
)
611 pr_debug("%s\n", __func__
);
612 snd_soc_unregister_platform(&pdev
->dev
);
617 static const struct of_device_id mt_soc_pcm_i2s0_awb_of_ids
[] =
619 { .compatible
= "mediatek,mt_soc_pcm_i2s0_awb", },
624 static struct platform_driver mtk_i2s0_awb_capture_driver
=
627 .name
= MT_SOC_I2S0_AWB_PCM
,
628 .owner
= THIS_MODULE
,
630 .of_match_table
= mt_soc_pcm_i2s0_awb_of_ids
,
633 .probe
= mtk_i2s0_awb_probe
,
634 .remove
= mtk_dl1_awb_remove
,
638 static struct platform_device
*soc_i2s0_awb_capture_dev
;
641 static int __init
mtk_soc_i2s0_awb_platform_init(void)
644 printk("%s\n", __func__
);
646 soc_i2s0_awb_capture_dev
= platform_device_alloc(MT_SOC_I2S0_AWB_PCM
, -1);
647 if (!soc_i2s0_awb_capture_dev
)
652 ret
= platform_device_add(soc_i2s0_awb_capture_dev
);
655 platform_device_put(soc_i2s0_awb_capture_dev
);
659 ret
= platform_driver_register(&mtk_i2s0_awb_capture_driver
);
663 static void __exit
mtk_soc_i2s0_awb_platform_exit(void)
665 printk("%s\n", __func__
);
666 platform_driver_unregister(&mtk_i2s0_awb_capture_driver
);
669 module_init(mtk_soc_i2s0_awb_platform_init
);
670 module_exit(mtk_soc_i2s0_awb_platform_exit
);
672 MODULE_DESCRIPTION("I2S0 AWB module platform driver");
673 MODULE_LICENSE("GPL");