[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / application / itopo / evmk2g / mcasp_cfg.c
1 /*
2 * Copyright (c) 2015, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
34 /**
35 * \file mcasp_config.c
36 *
37 * \brief Configures McASP module
38 *
39 */
41 #include "mcasp_cfg.h"
42 #include "ioConfig.h"
44 #define AUDIO_DAC0_TEST
46 /* McASP device handles - one for each McASP port. */
47 Ptr mcaspDevHandles[NUM_MCASP_PORTS] = {NULL, NULL, NULL};
49 /* McASP parameters needed by mcaspBindDev */
50 Mcasp_Params mcaspParams;
52 /* Error flag */
53 uint32_t gblErrFlag = 0;
54 Error_Block eb;
56 void GblErr(Mcasp_errCbStatus arg);
58 /* Handle to eDMA */
59 extern EDMA3_DRV_Handle hEdma0;
60 extern EDMA3_DRV_Handle hEdma1;
62 /* External function declarations */
63 extern void McaspDevice_init(void);
64 extern signed char* getGlobalAddr(signed char* addr);
66 #ifdef IO_LOOPBACK_TEST
67 extern void mcaspAppCallbackRx(void* arg, MCASP_Packet *mcasp_packet);
68 extern void mcaspAppCallbackTx(void* arg, MCASP_Packet *mcasp_packet);
69 #else
70 extern void asipMcaspCallback(void* arg, MCASP_Packet *mcasp_packet);
71 extern void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet);
72 #endif
75 /* McASP HW setup for receive (ADC) */
76 Mcasp_HwSetupData mcaspRcvSetupADC = {
77 /* .rmask = */ 0xFFFFFFFF, /* 16 bits are to be used */
78 /* .rfmt = */ 0x0001C0F0, /*
79 * 0 bit delay from framesync
80 * MSB first
81 * No extra bit padding
82 * Padding bit (ignore)
83 * slot Size is 32
84 * Reads from DMA port
85 * NO rotation
86 */
87 /* .afsrctl = */ 0X00000112, /* I2S mode - 2 slot TDM
88 * Frame sync is one word
89 * Internally generated frame sync
90 * Rising edge is start of frame
91 */
92 /* .rtdm = */ 0x00000003, /* slot 1 and 2 are active (I2S) */
93 /* .rintctl = */ 0x00000000, /* sync error and overrun error */
94 /* .rstat = */ 0x000001FF, /* reset any existing status bits */
95 /* .revtctl = */ 0x00000000, /* DMA request is enabled */
96 {
97 /* .aclkrctl = */ 0x000000A7, // Receiver samples data on the rising edge of the serial clock
98 // Internal receive clock source from output of programmable bit clock divider
99 // Receive bit clock divide ratio = 8
100 /* .ahclkrctl = */ 0x00008000, // Internal receive high-frequency clock source from output of programmable high clock divider.
101 // Falling edge. AHCLKR is inverted before programmable bit clock divider.
102 /* .rclkchk = */ 0x00000000
103 }
104 };
106 /* McASP HW setup for receive (S/PDIF or HDMI)*/
107 Mcasp_HwSetupData mcaspRcvSetupDIR = {
108 MCASP_DIR_RMASK, /* .rmask: 0xFFFFFFFF */
109 MCASP_DIR_RFMT, /* .rfmt: 0x000180F0 */
110 MCASP_DIR_AFSRCTL, /* .afsrctl: 0x00000111 */
111 MCASP_DIR_RTDM, /* .rtdm: 0x00000003 */
112 MCASP_DIR_RINTCTL, /* .rintctl: 0x00000000 */
113 MCASP_DIR_RSTAT, /* .rstat: 0x000001FF */
114 MCASP_DIR_REVTCTL, /* .revtctl */
115 {
116 MCASP_DIR_ACLKRCTL, /* .aclkrctl: 0x00000080 */ // Receiver samples data on the rising edge of the serial clock
117 // External receive clock source from ACLKR pin.
118 // Receive bit clock divide ratio = 1
119 MCASP_DIR_AHCLKRCTL, /* .ahclkrctl: 0x00000000 */
120 MCASP_DIR_RCLKCHK /* .rclkchk: 0x00000000 */
121 }
122 };
124 /* McASP HW setup for transmit (DAC) */
125 Mcasp_HwSetupData mcaspXmtSetupDAC = {
126 /* .xmask = */ 0xFFFFFFFF, /* 16 bits are to be used */
127 /* .xfmt = */ 0x000180F0, /*
128 * 0 bit delay from framesync
129 * MSB first
130 * No extra bit padding
131 * Padding bit (ignore)
132 * slot Size is 32
133 * Reads from DMA port
134 * NO rotation
135 */
136 /* .afsxctl = */ 0x00000112, /* I2S mode - 2 slot TDM
137 * Frame sync is one word
138 * Rising edge is start of frame
139 * Internally generated frame sync
140 */
141 /* .xtdm = */ 0x00000003, /* slot 1 and 2 are active (I2S) */
142 /* .xintctl = */ 0x00000000, /* sync error,overrun error,clK error */
143 /* .xstat = */ 0x000001FF, /* reset any existing status bits */
144 /* .xevtctl = */ 0x00000000, /* DMA request is enabled or disabled */
145 {
146 // /* .aclkxctl = */ 0X000000E1, // Transmit bit clock divide ratio = 2 --> works for 48khz PCM but not for DDP
147 /* .aclkxctl = */ 0X000000E7, // Transmit bit clock divide ratio = 8 --> working for DDP 48khz but not for PCM
148 /* .ahclkxctl = */ 0x00004000,
149 /* .xclkchk = */ 0x00000000
150 },
151 };
153 /* McASP HW setup for transmit (DAC slave) */
154 Mcasp_HwSetupData mcaspXmtSetupDACSlave = {
155 /* .xmask = */ 0xFFFFFFFF, /* 16 bits are to be used */
156 /* .xfmt = */ 0x000180F0, /*
157 * 0 bit delay from framesync
158 * MSB first
159 * No extra bit padding
160 * Padding bit (ignore)
161 * slot Size is 32
162 * Reads from DMA port
163 * NO rotation
164 */
165 /* .afsxctl = */ 0x00000113, /* I2S mode - 2 slot TDM
166 * Frame sync is one word
167 * Rising edge is start of frame
168 * Internally generated frame sync
169 */
170 /* .xtdm = */ 0x00000003, /* slot 1 and 2 are active (I2S) */
171 /* .xintctl = */ 0x00000000, /* sync error,overrun error,clK error */
172 /* .xstat = */ 0x000001FF, /* reset any existing status bits */
173 /* .xevtctl = */ 0x00000000, /* DMA request is enabled or disabled */
174 {
175 /* .aclkxctl = */ 0X000000A7,
176 /* .ahclkxctl = */ 0x0000C000,
177 /* .xclkchk = */ 0x00000000
178 },
179 };
181 /* McASP channel parameters for ADC input */
182 Mcasp_ChanParams mcaspRxChanParamADC =
183 {
184 0x0004, /* number of serializers */
185 {Mcasp_SerializerNum_0,
186 Mcasp_SerializerNum_1,
187 Mcasp_SerializerNum_2,
188 Mcasp_SerializerNum_3 }, /* serializer index */
189 &mcaspRcvSetupADC,
190 TRUE, /* isDmaDriven */
191 Mcasp_OpMode_TDM, /* Mode (TDM/DIT) */
192 Mcasp_WordLength_32, /* wordWidth */
193 NULL, /* void * userLoopJobBuffer */
194 0, /* userLoopJobLength */
195 NULL, /* edmaHandle */
196 GblErr,
197 2, /* number of TDM channels */
198 Mcasp_BufferFormat_MULTISER_MULTISLOT_SEMI_INTERLEAVED_1,
199 TRUE, /* enableHwFifo */
200 1, /* hwFifoEventDMARatio */
201 TRUE, /* isDataPacked */
202 Mcasp_WordBitsSelect_LSB /* wordBitsSelect */
203 };
205 /* McASP channel parameters for ADC 6 channel input */
206 Mcasp_ChanParams mcaspRxChanParamADC6ch =
207 {
208 0x0003, /* number of serializers */
209 {Mcasp_SerializerNum_0,
210 Mcasp_SerializerNum_1,
211 Mcasp_SerializerNum_2}, /* serializer index */
212 &mcaspRcvSetupADC,
213 TRUE,
214 Mcasp_OpMode_TDM, /* Mode (TDM/DIT) */
215 Mcasp_WordLength_32,
216 NULL,
217 0,
218 NULL,
219 GblErr,
220 2, /* number of TDM channels */
221 Mcasp_BufferFormat_MULTISER_MULTISLOT_SEMI_INTERLEAVED_1,
222 TRUE, /* enableHwFifo */
223 1, /* hwFifoEventDMARatio */
224 TRUE, /* isDataPacked */
225 Mcasp_WordBitsSelect_LSB /* wordBitsSelect */
226 };
228 /* McASP channel parameters for ADC stereo input */
229 Mcasp_ChanParams mcaspRxChanParamADCStereo =
230 {
231 0x0001, /* number of serializers */
232 {Mcasp_SerializerNum_0}, /* serializer index */
233 &mcaspRcvSetupADC,
234 TRUE,
235 Mcasp_OpMode_TDM, /* Mode (TDM/DIT) */
236 Mcasp_WordLength_32,
237 NULL,
238 0,
239 NULL,
240 GblErr,
241 2, /* number of TDM channels */
242 Mcasp_BufferFormat_MULTISER_MULTISLOT_SEMI_INTERLEAVED_1,
243 TRUE, /* enableHwFifo */
244 1, /* hwFifoEventDMARatio */
245 TRUE, /* isDataPacked */
246 Mcasp_WordBitsSelect_LSB /* wordBitsSelect */
247 };
249 /* McAsp channel parameters for DIR input */
250 Mcasp_ChanParams mcaspRxChanParamDIR =
251 {
252 0x0001, /* Number of serializers */
253 {Mcasp_SerializerNum_5}, /* Serializer index */
254 &mcaspRcvSetupDIR,
255 TRUE,
256 Mcasp_OpMode_TDM, /* Mode (TDM/DIT) */
257 Mcasp_WordLength_16, /* 16-bit by default */
258 NULL,
259 0,
260 NULL,
261 GblErr,
262 2, /* number of TDM channels */
263 Mcasp_BufferFormat_1SER_MULTISLOT_INTERLEAVED,
264 TRUE,
265 1, /* hwFifoEventDMARatio */
266 TRUE, /* isDataPacked */
267 Mcasp_WordBitsSelect_MSB /* wordBitsSelect */
268 };
270 /* McASP LLD channel parameters for HDMI input with 4XI2S:
271 * When slot size of McASP is configured to 32-bit, HDMI data always come to 16 MSBs of the slot
272 * and the 16 LSBs are filled with 0's. This is the nature of HDMI and I2S.
273 * For PCM data, we want all 32 bits in the slot to be transferred to the input buffer:
274 * - wordWidth = Mcasp_WordLength_32
275 * - isDataPacked = 1,
276 * - wordBitsSelect having no effect since wordWidth = slot size
277 * For bit stream, we want only 16 MSBs in the slot to be transferred to the input buffer:
278 * - wordWidth = Mcasp_WordLength_16
279 * - isDataPacked = 1,
280 * - wordBitsSelect = Mcasp_WordBitsSelect_MSB
281 */
282 Mcasp_ChanParams mcaspRxChanParamHDMI =
283 {
284 0x0004, /* number of serializers */
285 {Mcasp_SerializerNum_12,
286 Mcasp_SerializerNum_13,
287 Mcasp_SerializerNum_14,
288 Mcasp_SerializerNum_15 }, /* serializer index */
289 &mcaspRcvSetupDIR,
290 TRUE,
291 Mcasp_OpMode_TDM, /* Mode (TDM/DIT) */
292 Mcasp_WordLength_16, /* 16-bit word length, MSB or LSB of slot to be transfered, depending on wordBitsSelect */
293 NULL,
294 0,
295 NULL,
296 GblErr,
297 2, /* number of TDM channels */
298 Mcasp_BufferFormat_MULTISER_MULTISLOT_SEMI_INTERLEAVED_1,
299 TRUE, /* enableHwFifo */
300 1, /* hwFifoEventDMARatio */
301 TRUE, /* isDataPacked, only transfer the selected bits of slot, based on wordWidth and wordBitsSelect */
302 Mcasp_WordBitsSelect_MSB /* wordBitsSelect, only matters if wordWidth < slot size */
303 };
305 /* McAsp channel parameters for HDMI stereo input with 1XI2S */
306 Mcasp_ChanParams mcaspRxChanParamHDMIStereo =
307 {
308 0x0001, /* Number of serializers */
309 {Mcasp_SerializerNum_12}, /* Serializer index */
310 &mcaspRcvSetupDIR,
311 TRUE,
312 Mcasp_OpMode_TDM, /* Mode (TDM/DIT) */
313 Mcasp_WordLength_16, /* 16-bit by default */
314 NULL,
315 0,
316 NULL,
317 GblErr,
318 2, /* number of TDM channels */
319 Mcasp_BufferFormat_1SER_MULTISLOT_INTERLEAVED,
320 TRUE, /* enableHwFifo */
321 1, /* hwFifoEventDMARatio */
322 TRUE, /* isDataPacked */
323 Mcasp_WordBitsSelect_MSB /* wordBitsSelect */
324 };
326 /* McAsp channel parameters for DAC output - DAC0 */
327 Mcasp_ChanParams mcaspTx0ChanParamDAC =
328 {
329 0x0004, /* number of serializers */
330 {Mcasp_SerializerNum_0,
331 Mcasp_SerializerNum_1,
332 Mcasp_SerializerNum_2,
333 Mcasp_SerializerNum_3 }, /* serializer index for DAC0 */
334 &mcaspXmtSetupDAC,
335 TRUE,
336 Mcasp_OpMode_TDM,
337 Mcasp_WordLength_32, /* word width */
338 NULL,
339 0,
340 NULL,
341 GblErr,
342 2, /* number of TDM channels */
343 Mcasp_BufferFormat_MULTISER_MULTISLOT_SEMI_INTERLEAVED_1,
344 TRUE,
345 1, /* hwFifoEventDMARatio */
346 TRUE, /* isDataPacked */
347 Mcasp_WordBitsSelect_LSB /* wordBitsSelect */
348 };
350 /* McAsp channel parameters for DAC stereo output - DAC0 */
351 Mcasp_ChanParams mcaspTx0ChanParamDACStereo =
352 {
353 0x0001, /* number of serializers */
354 {Mcasp_SerializerNum_0}, /* serializer index for DAC0 */
355 &mcaspXmtSetupDAC,
356 TRUE,
357 Mcasp_OpMode_TDM,
358 Mcasp_WordLength_32, /* word width */
359 NULL,
360 0,
361 NULL,
362 GblErr,
363 2, /* number of TDM channels */
364 Mcasp_BufferFormat_MULTISER_MULTISLOT_SEMI_INTERLEAVED_1,
365 TRUE,
366 1, /* hwFifoEventDMARatio */
367 TRUE, /* isDataPacked */
368 Mcasp_WordBitsSelect_LSB /* wordBitsSelect */
369 };
371 /* McAsp channel parameters for DAC 12 channel output */
372 Mcasp_ChanParams mcaspTx0ChanParamDAC12ch =
373 {
374 0x0006, /* number of serializers */
375 {Mcasp_SerializerNum_0,
376 Mcasp_SerializerNum_1,
377 Mcasp_SerializerNum_2,
378 Mcasp_SerializerNum_3,
379 Mcasp_SerializerNum_4,
380 Mcasp_SerializerNum_5 }, /* serializer index for DAC0 */
381 &mcaspXmtSetupDAC,
382 TRUE,
383 Mcasp_OpMode_TDM,
384 Mcasp_WordLength_32, /* word width */
385 NULL,
386 0,
387 NULL,
388 GblErr,
389 2, /* number of TDM channels */
390 Mcasp_BufferFormat_MULTISER_MULTISLOT_SEMI_INTERLEAVED_1,
391 TRUE,
392 1, /* hwFifoEventDMARatio */
393 TRUE, /* isDataPacked */
394 Mcasp_WordBitsSelect_LSB /* wordBitsSelect */
395 };
397 /* McAsp channel parameters for DAC 16 channel output */
398 Mcasp_ChanParams mcaspTx0ChanParamDAC16ch =
399 {
400 0x0008, /* number of serializers */
401 {Mcasp_SerializerNum_0,
402 Mcasp_SerializerNum_1,
403 Mcasp_SerializerNum_2,
404 Mcasp_SerializerNum_3,
405 Mcasp_SerializerNum_4,
406 Mcasp_SerializerNum_5,
407 Mcasp_SerializerNum_6,
408 Mcasp_SerializerNum_7 }, /* serializer index for DAC0 */
409 &mcaspXmtSetupDAC,
410 TRUE,
411 Mcasp_OpMode_TDM,
412 Mcasp_WordLength_32, /* word width */
413 NULL,
414 0,
415 NULL,
416 GblErr,
417 2, /* number of TDM channels */
418 Mcasp_BufferFormat_MULTISER_MULTISLOT_SEMI_INTERLEAVED_1,
419 TRUE,
420 1, /* hwFifoEventDMARatio */
421 TRUE, /* isDataPacked */
422 Mcasp_WordBitsSelect_LSB /* wordBitsSelect */
423 };
425 /* McAsp channel parameters for transmit - DAC1 */
426 Mcasp_ChanParams mcaspTx1ChanParam =
427 {
428 0x0001, /* number of serializers */
429 {Mcasp_SerializerNum_4}, /* serializer index for DAC0 */
430 &mcaspXmtSetupDAC,
431 TRUE,
432 Mcasp_OpMode_TDM,
433 Mcasp_WordLength_32, /* word width */
434 NULL,
435 0,
436 NULL,
437 GblErr,
438 2, /* number of TDM channels */
439 Mcasp_BufferFormat_1SER_MULTISLOT_INTERLEAVED,
440 TRUE,
441 1, /* hwFifoEventDMARatio */
442 TRUE, /* isDataPacked */
443 Mcasp_WordBitsSelect_LSB /* wordBitsSelect */
444 };
447 /**
448 * \brief Function called by McASP driver in case of error
449 *
450 * \return None
451 */
452 void GblErr(Mcasp_errCbStatus arg)
453 {
454 gblErrFlag = 1;
455 }
458 /* DAC default configuration parameters */
459 DacConfig DAC_Cfg =
460 {
461 AUDK2G_DAC_AMUTE_CTRL_DAC_DISABLE_CMD, /* Amute event */
462 0, /* Amute control */
463 AUDK2G_DAC_SAMPLING_MODE_AUTO, /* Sampling mode */
464 AUDK2G_DAC_DATA_FORMAT_I2S, /* Data format */
465 0, /* Soft mute control */
466 AUDK2G_DAC_ATTENUATION_WIDE_RANGE, /* Attenuation mode */
467 AUDK2G_DAC_DEEMP_DISABLE, /* De-emph control */
468 100 /* Volume */
469 };
471 /**
472 * \brief Configures audio DAC module
473 *
474 * \return none
475 */
476 void configAudioDAC(void)
477 {
478 Audk2g_STATUS status;
480 audk2g_delay(10000);
482 /* Initialize Audio DAC module */
483 status = audioDacConfig(AUDK2G_DAC_DEVICE_ALL, &DAC_Cfg);
484 if(status != Audk2g_EOK)
485 {
486 //platform_write("Audio DAC Configuration Failed!\n");
487 //testRet(1);
488 }
489 }
490 #if 0
491 /**
492 * \brief Configures McASP module and creates the channel
493 * for audio Tx and Rx
494 *
495 * \return Audk2g_EOK on Success or error code
496 */
497 Audk2g_STATUS mcaspAudioConfig(void)
498 {
499 int32_t status;
501 hMcaspDevTx = NULL;
502 hMcaspDevRx = NULL;
503 hMcaspTxChan = NULL;
504 hMcaspRxChan = NULL;
506 /* Initialize McASP Tx and Rx parameters */
507 mcaspTxParams = Mcasp_PARAMS;
508 mcaspRxParams = Mcasp_PARAMS;
510 mcaspTxParams.mcaspHwSetup.tx.clk.clkSetupClk = 0x23; // not used
511 mcaspTxParams.mcaspHwSetup.rx.clk.clkSetupClk = 0x23; // not used
512 mcaspRxParams.mcaspHwSetup.rx.clk.clkSetupClk = 0x23;
513 mcaspRxParams.mcaspHwSetup.tx.clk.clkSetupClk = 0x63; // Asynchronous. Separate clock and frame sync used by transmit and receive sections.
515 #ifndef INPUT_SPDIF
516 mcaspRxParams.mcaspHwSetup.glb.pdir |= 0x2000000; //Special case, since for HDMI input - mcasp0 is both Rx & Tx
517 mcaspRxParams.mcaspHwSetup.glb.amute = 0x2; // this to ensure one doesn't overwrite the other (rx/tx)
518 mcaspTxParams.mcaspHwSetup.glb.pdir |= 0x2000000; //Set Amute pin as output for Tx channel
519 mcaspTxParams.mcaspHwSetup.glb.amute = 0x2;
520 #else
521 mcaspTxParams.mcaspHwSetup.glb.pdir |= 0x2000000; //Set Amute pin as output for Tx channel
522 mcaspTxParams.mcaspHwSetup.glb.amute = 0x2;
523 #endif
525 /* Set the HW interrupt number */
526 //mcaspTxParams.hwiNumber = 8;
527 //mcaspRxParams.hwiNumber = 8;
529 /* Initialize eDMA handle */
530 #ifdef INPUT_SPDIF
531 mcaspRxChanParam.edmaHandle = hEdma1;
532 #else
533 mcaspRxChanParam.edmaHandle = hEdma0;
534 #endif
536 mcaspTx0ChanParam.edmaHandle = hEdma0;
537 mcaspTx1ChanParam.edmaHandle = hEdma0;
539 #ifdef INPUT_SPDIF
540 /* Bind McASP0 for Tx */
541 status = mcaspBindDev(&hMcaspDevTx, CSL_MCASP_0, &mcaspTxParams);
542 if((status != MCASP_COMPLETED) || (hMcaspDevTx == NULL))
543 {
544 //IFPRINT(platform_write("mcaspBindDev for Tx Failed\n"));
545 return (Audk2g_EFAIL);
546 }
548 /* Bind McASP2 for Rx */
549 status = mcaspBindDev(&hMcaspDevRx, CSL_MCASP_2, &mcaspRxParams);
550 if((status != MCASP_COMPLETED) || (hMcaspDevRx == NULL))
551 {
552 //IFPRINT(platform_write("mcaspBindDev for Rx Failed\n"));
553 return (Audk2g_EFAIL);
554 }
556 #else /* HDMI or HDMI_STEREO */
557 /* Bind McASP0 for Rx and Tx */
558 status = mcaspBindDev(&hMcaspDevRx, CSL_MCASP_0, &mcaspRxParams);
559 if((status != MCASP_COMPLETED) || (hMcaspDevRx == NULL))
560 {
561 //IFPRINT(platform_write("mcaspBindDev for Rx Failed\n"));
562 return (Audk2g_EFAIL);
563 }
565 hMcaspDevTx = hMcaspDevRx;
566 #endif
568 /* Create McASP channel for Tx */
569 status = mcaspCreateChan(&hMcaspTxChan, hMcaspDevTx,
570 MCASP_OUTPUT,
571 #ifdef AUDIO_DAC0_TEST
572 &mcaspTx0ChanParam,
573 #else
574 &mcaspTx1ChanParam,
575 #endif
576 #ifdef IO_LOOPBACK_TEST
577 mcaspAppCallbackTx, NULL);
578 #else
579 asopMcaspCallback, NULL);
580 #endif
582 if((status != MCASP_COMPLETED) || (hMcaspTxChan == NULL))
583 {
584 //IFPRINT(platform_write("mcaspCreateChan for Tx Failed\n"));
585 return (Audk2g_EFAIL);
586 }
588 /* Create McASP channel for Rx */
589 status = mcaspCreateChan(&hMcaspRxChan, hMcaspDevRx,
590 MCASP_INPUT,
591 &mcaspRxChanParam,
592 #ifdef IO_LOOPBACK_TEST
593 mcaspAppCallbackRx, NULL);
594 #else
595 asipMcaspCallback, NULL);
596 #endif
598 if((status != MCASP_COMPLETED) || (hMcaspRxChan == NULL))
599 {
600 //IFPRINT(platform_write("mcaspCreateChan for Rx Failed\n"));
601 return (Audk2g_EFAIL);
602 }
604 return (Audk2g_EOK);
605 } /* mcaspAudioConfig */
608 Audk2g_STATUS mcaspRx(void)
609 {
611 }
613 Audk2g_STATUS mcaspRxDeInit(void)
614 {
615 mcaspDeleteChan(hMcaspRxChan);
616 hMcaspRxChan = NULL;
618 mcaspUnBindDev(hMcaspDevRx);
619 hMcaspDevRx = NULL;
621 return (Audk2g_EOK);
622 }
624 Audk2g_STATUS mcaspChanReset(Ptr hMcaspDev, Ptr hMcaspChan)
625 {
626 if(hMcaspChan != NULL) {
627 mcaspDeleteChan(hMcaspChan);
628 }
629 }
631 Audk2g_STATUS mcaspRxReset(void)
632 {
633 if(hMcaspRxChan != NULL) {
634 mcaspDeleteChan(hMcaspRxChan);
635 hMcaspRxChan = NULL;
636 }
638 return (Audk2g_EOK);
639 }
641 Audk2g_STATUS mcaspRxCreate(void)
642 {
643 int32_t status;
645 /* Create McASP channel for Rx */
646 status = mcaspCreateChan(&hMcaspRxChan, hMcaspDevRx,
647 MCASP_INPUT,
648 &mcaspRxChanParam,
649 #ifdef IO_LOOPBACK_TEST
650 mcaspAppCallbackRx, NULL);
651 #else
652 asipMcaspCallback, NULL);
653 #endif
655 if((status != MCASP_COMPLETED) || (hMcaspRxChan == NULL))
656 {
657 //IFPRINT(platform_write("mcaspCreateChan for Rx Failed\n"));
658 return (Audk2g_EFAIL);
659 }
661 return (Audk2g_EOK);
662 }
664 Audk2g_STATUS mcaspTxReset(void)
665 {
666 if(hMcaspTxChan != NULL) {
667 mcaspDeleteChan(hMcaspTxChan);
668 hMcaspTxChan = NULL;
669 }
671 return (Audk2g_EOK);
672 }
674 Audk2g_STATUS mcaspTxCreate(void)
675 {
676 int32_t status;
678 /* Create McASP channel for Tx */
679 status = mcaspCreateChan(&hMcaspTxChan, hMcaspDevTx,
680 MCASP_OUTPUT,
681 &mcaspTx0ChanParam,
682 #ifdef IO_LOOPBACK_TEST
683 mcaspAppCallbackTx, NULL);
684 #else
685 asopMcaspCallback, NULL);
686 #endif
687 if((status != MCASP_COMPLETED) || (hMcaspTxChan == NULL))
688 {
689 //IFPRINT(platform_write("mcaspCreateChan for Tx Failed\n"));
690 return (Audk2g_EFAIL);
691 }
693 return (Audk2g_EOK);
694 }
695 #endif
698 Audk2g_STATUS mcaspRecfgWordWidth(Ptr hMcaspChan, uint16_t wordWidth)
699 {
700 Mcasp_ChanParams chanParams;
701 int32_t status;
703 chanParams.wordWidth = wordWidth; //to do: change mcaspControlChan to have wordWidth as the parameter instead of chanParams!!
705 status = mcaspControlChan(hMcaspChan, Mcasp_IOCTL_CHAN_PARAMS_WORD_WIDTH, &chanParams);
707 if((status != MCASP_COMPLETED)) {
708 return (Audk2g_EFAIL);
709 }
710 else {
711 return (Audk2g_EOK);
712 }
713 } /* mcaspRecfgWordWidth */
715 /*======================================================================================
716 * This function checks if McASP Rx overruns or Tx underruns
717 *====================================================================================*/
718 int mcaspCheckOverUnderRun(Ptr mcaspChanHandle)
719 {
720 Mcasp_errCbStatus mcaspErrStat;
722 mcaspControlChan(mcaspChanHandle, Mcasp_IOCTL_CHAN_QUERY_ERROR_STATS, &mcaspErrStat);
724 return (mcaspErrStat.isRcvOvrRunOrTxUndRunErr);
725 }
728 /** McASP LLD configuration parameters for all input and output interfaces */
729 mcaspLLDconfig LLDconfigRxDIR = // for SAP_D10_RX_DIR
730 {
731 &mcaspRcvSetupDIR,
732 &mcaspRxChanParamDIR,
733 0x23,
734 0x63, // Asynchronous. Separate clock and frame sync used by transmit and receive sections.
735 0x0,
736 0x2,
737 CSL_MCASP_2,
738 MCASP_INPUT,
739 asipMcaspCallback,
740 NULL,
741 NULL
742 };
744 mcaspLLDconfig LLDconfigRxADC = // for SAP_D10_RX_ADC_44100HZ, SAP_D10_RX_ADC_88200HZ
745 {
746 &mcaspRcvSetupADC,
747 &mcaspRxChanParamADC,
748 0x23,
749 0x63,
750 0x0,
751 0x2,
752 CSL_MCASP_1,
753 MCASP_INPUT,
754 asipMcaspCallback,
755 NULL,
756 NULL
757 };
759 mcaspLLDconfig LLDconfigRxADC6ch = // for SAP_D10_RX_ADC_6CH_44100HZ, SAP_D10_RX_ADC_6CH_88200HZ
760 {
761 &mcaspRcvSetupADC,
762 &mcaspRxChanParamADC6ch,
763 0x23,
764 0x63,
765 0x0,
766 0x2,
767 CSL_MCASP_1,
768 MCASP_INPUT,
769 asipMcaspCallback,
770 NULL,
771 NULL,
772 };
774 mcaspLLDconfig LLDconfigRxADCStereo = // for SAP_D10_RX_ADC_STEREO_44100HZ, SAP_D10_RX_ADC_STEREO_88200HZ
775 {
776 &mcaspRcvSetupADC,
777 &mcaspRxChanParamADCStereo,
778 0x23,
779 0x63,
780 0x0,
781 0x2,
782 CSL_MCASP_1,
783 MCASP_INPUT,
784 asipMcaspCallback,
785 NULL,
786 NULL
787 };
789 mcaspLLDconfig LLDconfigRxHDMIStereo = // for SAP_D10_RX_HDMI_STEREO
790 {
791 &mcaspRcvSetupDIR,
792 &mcaspRxChanParamHDMIStereo,
793 0x23,
794 0x63,
795 0x02000000, // Set Amute pin as output since mcasp0 is both Rx & Tx for DIR/HDMI
796 0x2,
797 CSL_MCASP_0,
798 MCASP_INPUT,
799 asipMcaspCallback,
800 NULL,
801 NULL
802 };
804 mcaspLLDconfig LLDconfigRxHDMI = // for SAP_D10_RX_HDMI
805 {
806 &mcaspRcvSetupDIR,
807 &mcaspRxChanParamHDMI,
808 0x23,
809 0x63,
810 0x02000000, // Set Amute pin as output since mcasp0 is both Rx & Tx for DIR/HDMI
811 0x2,
812 CSL_MCASP_0,
813 MCASP_INPUT,
814 asipMcaspCallback,
815 NULL,
816 NULL
817 };
819 /*
820 mcaspLLDconfig LLDconfigTxDIT = // for SAP_D10_TX_DIT
821 {
822 &mcaspXmtSetupDIT,
823 &mcaspTx0ChanParamDIT,
824 NULL,
825 NULL,
826 CSL_MCASP_2
827 };
828 */
830 mcaspLLDconfig LLDconfigTxDAC = // for SAP_D10_TX_DAC
831 {
832 &mcaspXmtSetupDAC,
833 &mcaspTx0ChanParamDAC,
834 0x23,
835 0x63,
836 0x02000000, // Set Amute pin as output for Tx channel
837 0x2,
838 CSL_MCASP_0,
839 MCASP_OUTPUT,
840 asopMcaspCallback,
841 NULL,
842 NULL
843 };
845 mcaspLLDconfig LLDconfigTxDACSlave = // for SAP_D10_TX_DAC_SLAVE
846 {
847 &mcaspXmtSetupDACSlave,
848 &mcaspTx0ChanParamDAC,
849 0x23,
850 0x63,
851 0x02000000,
852 0x2,
853 CSL_MCASP_0,
854 MCASP_OUTPUT,
855 asopMcaspCallback,
856 NULL,
857 NULL
858 };
860 mcaspLLDconfig LLDconfigTxDACStereo = // for SAP_D10_TX_STEREO_DAC
861 {
862 &mcaspXmtSetupDAC,
863 &mcaspTx0ChanParamDACStereo,
864 0x23,
865 0x63,
866 0x02000000,
867 0x2,
868 CSL_MCASP_0,
869 MCASP_OUTPUT,
870 asopMcaspCallback,
871 NULL,
872 NULL
873 };
875 mcaspLLDconfig LLDconfigTxDACStereoSlave = // for SAP_D10_TX_STEREO_DAC_SLAVE
876 {
877 &mcaspXmtSetupDACSlave,
878 &mcaspTx0ChanParamDACStereo,
879 0x23,
880 0x63,
881 0x02000000,
882 0x2,
883 CSL_MCASP_0,
884 MCASP_OUTPUT,
885 asopMcaspCallback,
886 NULL,
887 NULL
888 };
890 mcaspLLDconfig LLDconfigTxDAC12ch = // for SAP_D10_TX_DAC_12CH
891 {
892 &mcaspXmtSetupDAC,
893 &mcaspTx0ChanParamDAC12ch,
894 0x23,
895 0x63,
896 0x02000000,
897 0x2,
898 CSL_MCASP_0,
899 MCASP_OUTPUT,
900 asopMcaspCallback,
901 NULL,
902 NULL
903 };
905 mcaspLLDconfig LLDconfigTxDAC16ch = // for SAP_D10_TX_DAC_16CH
906 {
907 &mcaspXmtSetupDAC,
908 &mcaspTx0ChanParamDAC16ch,
909 0x23,
910 0x63,
911 0x02000000,
912 0x2,
913 CSL_MCASP_0,
914 MCASP_OUTPUT,
915 asopMcaspCallback,
916 NULL,
917 NULL
918 };
921 /**
922 * \brief Create a channel of McASP LLD and return the handle.
923 *
924 * \return Audk2g_EOK on Success or error code
925 */
926 Audk2g_STATUS mcasplldChanCreate(mcaspLLDconfig *lldCfg, Ptr *pChanHandle)
927 {
928 int32_t status;
930 if(mcaspDevHandles[lldCfg->mcaspPort] == NULL) {
931 /* Initialize McASP parameters */
932 mcaspParams = Mcasp_PARAMS; // Mcasp_PARAMS defined in McASP LLD
934 mcaspParams.mcaspHwSetup.rx.clk.clkSetupClk = lldCfg->clkSetupClkRx;
935 mcaspParams.mcaspHwSetup.tx.clk.clkSetupClk = lldCfg->clkSetupClkTx;
936 mcaspParams.mcaspHwSetup.glb.pdir |= lldCfg->pdirAmute;
937 mcaspParams.mcaspHwSetup.glb.amute = lldCfg->amute;
939 status = mcaspBindDev(&mcaspDevHandles[lldCfg->mcaspPort], lldCfg->mcaspPort, &mcaspParams);
940 if((status != MCASP_COMPLETED) || (mcaspDevHandles[lldCfg->mcaspPort] == NULL)) {
941 return (Audk2g_EFAIL);
942 }
943 }
945 lldCfg->hMcaspDev = mcaspDevHandles[lldCfg->mcaspPort];
947 lldCfg->mcaspChanParams->mcaspSetup = lldCfg->mcaspSetupData;
948 if(lldCfg->mcaspPort == CSL_MCASP_0) {
949 lldCfg->mcaspChanParams->edmaHandle = hEdma0;
950 }
951 else {
952 lldCfg->mcaspChanParams->edmaHandle = hEdma1;
953 }
955 /* Create McASP channel */
956 *pChanHandle = NULL;
957 status = mcaspCreateChan(pChanHandle, lldCfg->hMcaspDev,
958 lldCfg->chanMode, lldCfg->mcaspChanParams,
959 lldCfg->cbFxn, NULL);
961 if((status != MCASP_COMPLETED) || (*pChanHandle == NULL))
962 {
963 //IFPRINT(platform_write("mcaspCreateChan for Tx Failed\n"));
964 return (Audk2g_EFAIL);
965 }
967 return (Audk2g_EOK);
968 } /* mcasplldChanCreate */
970 /* Nothing past this point */