[processor-sdk/performance-audio-sr.git] / pdk_k2g_1_0_1 / packages / ti / platform / evmk2g / platform_lib / src / platform_audio.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 platform_audio.c
36 *
37 * \brief Platform audio interface file.
38 *
39 * This file contains APIs for accessing DAC/ADC/DIR modules on audio daughter
40 * card.
41 *
42 */
44 #include "platform_internal.h"
46 #if (PLATFORM_AUDIO)
48 /* DAC HW instance I2C slave address */
49 Uint8 gDacI2cAddr[PLATFORM_AUDIO_DAC_COUNT] = {PLATFORM_AUDIO_DAC0_ADDR,
50 PLATFORM_AUDIO_DAC1_ADDR};
51 /* ADC HW instance I2C slave address */
52 Uint8 gAdcI2cAddr[PLATFORM_AUDIO_ADC_COUNT] = {PLATFORM_AUDIO_ADC0_ADDR,
53 PLATFORM_AUDIO_ADC1_ADDR};
55 /**
56 * \brief Initializes Audio module
57 *
58 * This function configures the system level setup required for
59 * operation of the modules that are available on audio daughter card.
60 * This function shall be called before calling any other platform
61 * audio module functions.
62 *
63 * \return Platform_EOK on Success or error code
64 */
65 Platform_STATUS platformAudioInit(void)
66 {
67 uint8_t padCfg;
68 uint8_t padMax;
70 IFPRINT(platform_write("platformAudioInit Called \n"));
72 /* Configure McASP0 lines */
73 /* MCASP0AMUTE, MCASP0ACLKR, MCASP0FSR, MCASP0AHCLKR
74 MCASP0ACLKX, MCASP0FSX, MCASP0AHCLKX,
75 MCASP0AXR[0:7] - PADCONFIG 169 to 183 */
76 padMax = 183;
77 for (padCfg = 169; padCfg <= padMax; padCfg++)
78 {
79 pinMuxSetMode(padCfg, PADCONFIG_MUX_MODE_QUINARY);
80 }
82 /* MCASP0AXR[12:15] - PADCONFIG 188 to 191 */
83 padMax = 191;
84 for (padCfg = 188; padCfg <= padMax; padCfg++)
85 {
86 pinMuxSetMode(padCfg, PADCONFIG_MUX_MODE_QUINARY);
87 }
90 /* Configure McASP1 lines */
91 /* MCASP1ACLKR, MCASP1FSR, MCASP1AHCLKR - PADCONFIG 152 to 154 */
92 padMax = 154;
93 for (padCfg = 152; padCfg <= padMax; padCfg++)
94 {
95 pinMuxSetMode(padCfg, PADCONFIG_MUX_MODE_QUINARY);
96 }
98 /* MCASP1AHCLKX - PADCONFIG 157 */
99 pinMuxSetMode(157, PADCONFIG_MUX_MODE_QUINARY);
101 /* MCASP1AXR[0:3] - PADCONFIG 159 to 162 */
102 padMax = 162;
103 for (padCfg = 159; padCfg <= padMax; padCfg++)
104 {
105 pinMuxSetMode(padCfg, PADCONFIG_MUX_MODE_QUINARY);
106 }
108 /* MCASP1AXR9 - PADCONFIG 168 */
109 pinMuxSetMode(168, PADCONFIG_MUX_MODE_QUINARY);
112 /* Configure McASP2 lines */
113 /* MCASP2AXR[1:5], MCASP2ACLKR, MCASP2FSR, MCASP2AHCLKR
114 - PADCONFIG 140 to 147 */
115 padMax = 147;
116 for (padCfg = 140; padCfg <= padMax; padCfg++)
117 {
118 pinMuxSetMode(padCfg, PADCONFIG_MUX_MODE_QUINARY);
119 }
121 /* MCASP2FSX - PADCONFIG 149 */
122 pinMuxSetMode(149, PADCONFIG_MUX_MODE_QUINARY);
124 /* MCASP2ACLKX - PADCONFIG 151 */
125 pinMuxSetMode(151, PADCONFIG_MUX_MODE_QUINARY);
127 /* Configure GPIO for McASP_CLK_SEL - GPIO0 132 & PADCONFIG 163 */
128 pinMuxSetMode(163, PADCONFIG_MUX_MODE_QUATERNARY);
129 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO, GPIO_OUT);
130 /* Slect the clock source as DIR */
131 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO);
133 /* Configure GPIO for McASP_CLK_SEL# - GPIO0 101 & PADCONFIG 110 */
134 pinMuxSetMode(110, PADCONFIG_MUX_MODE_QUATERNARY);
135 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO, GPIO_OUT);
136 /* Slect the clock source as DIR */
137 //gpioClearOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);
138 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO); // Default configurations are set for McASP AHCLK driven by SoC
140 /* Configure GPIO for PCM1690_RST# - GPIO1 10 & PADCONFIG 185 */
141 pinMuxSetMode(185, PADCONFIG_MUX_MODE_QUATERNARY);
142 gpioSetDirection(GPIO_PORT_1, PLATFORM_AUDIO_PCM1690_RST_GPIO, GPIO_OUT);
144 gpioClearOutput(GPIO_PORT_1, PLATFORM_AUDIO_PCM1690_RST_GPIO);
145 platform_delay(1000);
146 gpioSetOutput(GPIO_PORT_1, PLATFORM_AUDIO_PCM1690_RST_GPIO);
148 /* Configure GPIO for HSR HDMI Signaling - GPIO0 104 (~RESET) & 105 (~HMINT) */
149 pinMuxSetMode(114, PADCONFIG_MUX_MODE_QUATERNARY);
150 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_HSR_HMINTz_GPIO, GPIO_IN);
152 pinMuxSetMode(113, PADCONFIG_MUX_MODE_QUATERNARY);
153 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_HSR_RESETz_GPIO, GPIO_OUT);
154 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_HSR_RESETz_GPIO);
156 /* Configure McASP AUXCLK source as AUDIO_OSCCLK */
157 hBootCfg->SERIALPORT_CLKCTL = 0;
158 hBootCfg->OSC_CTL = 0x200; //SW2:SW1 = 01 (15 - 30 MHz)
160 return (Platform_EOK);
161 }
163 /**
164 * \brief Resets audio DAC
165 *
166 * This function toggles the GPIO signal connected to RST pin
167 * of DAC module to generate DAC reset.
168 *
169 * \return Platform_EOK on Success or error code
170 */
171 Platform_STATUS platformAudioResetDac(void)
172 {
173 gpioClearOutput(GPIO_PORT_1, PLATFORM_AUDIO_PCM1690_RST_GPIO);
174 platform_delay(1000);
175 gpioSetOutput(GPIO_PORT_1, PLATFORM_AUDIO_PCM1690_RST_GPIO);
177 /* Configure McASP AUXCLK source as AUDIO_OSCCLK */
178 hBootCfg->SERIALPORT_CLKCTL = 0;
180 return (Platform_EOK);
181 }
183 /**
184 * \brief Configures audio clock source
185 *
186 * McASP can receive clock from DIR module on daughter card or external
187 * I2S device to operate DAC and ADC modules. This function configures
188 * which clock source to use (DIR or I2S) for DAC and ADC operation
189 *
190 * \param clkSrc [IN] Clock source selection
191 *
192 * \return Platform_EOK on Success or error code
193 */
194 Platform_STATUS platformAudioSelectClkSrc(AudioClkSrc clkSrc)
195 {
196 IFPRINT(platform_write("platformAudioSelectClkSrc Called \n"));
198 /* Configure GPIO for McASP_CLK_SEL - GPIO0 132 & PADCONFIG 163 */
199 pinMuxSetMode(163, PADCONFIG_MUX_MODE_QUATERNARY);
200 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO, GPIO_OUT);
202 /* Configure GPIO for McASP_CLK_SEL# - GPIO0 101 & PADCONFIG 110 */
203 pinMuxSetMode(110, PADCONFIG_MUX_MODE_QUATERNARY);
204 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO, GPIO_OUT);
206 if(clkSrc == AUDIO_CLK_SRC_DIR)
207 {
208 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO);
209 gpioClearOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);
210 }
211 else if(clkSrc == AUDIO_CLK_SRC_I2S)
212 {
213 gpioClearOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO);
214 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);
215 }
216 else if(clkSrc == AUDIO_CLK_SRC_OSC)
217 {
218 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO);
219 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);
220 }
221 else
222 {
223 IFPRINT(platform_write("platformAudioSelectClkSrc : Invalid Inputs\n"));
224 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
225 return (Platform_EINVALID);
226 }
228 return (Platform_EOK);
229 }
231 #if (PLATFORM_AUDIO_ADC)
233 /**
234 * \brief Initializes ADC module
235 *
236 * This function configures the system level setup required for ADC
237 * operation and initializes the ADC module with default values.
238 * This function should be called before calling any other ADC functions.
239 *
240 * After executing this function, ADC module will be ready for audio
241 * processing with default configuration. Default ADC configurations
242 * can be changed using the other ADC APIs if required.
243 *
244 * \param devId [IN] Device ID of ADC HW instance
245 * Use 'ADC_DEVICE_ALL' to initialize
246 * all the ADC devices available.
247 *
248 * \return Platform_EOK on Success or error code
249 */
250 Platform_STATUS platformAudioAdcInit(AdcDevId devId)
251 {
252 ADC_RET retVal;
253 Uint8 id;
255 IFPRINT(platform_write("platformAudioAdcInit Called \n"));
257 if(!((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)))
258 {
259 IFPRINT(platform_write("platformAudioAdcInit : Invalid Inputs\n"));
260 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
261 return (Platform_EINVALID);
262 }
264 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
265 {
266 if((id == devId) || (devId == ADC_DEVICE_ALL))
267 {
268 retVal = pcm186xAdcInit(gAdcI2cAddr[id]);
269 if(retVal)
270 {
271 IFPRINT(platform_write("platformAudioAdcInit : ADC Initialization Failed \n"));
272 platform_errno = PLATFORM_ERRNO_AUDIO_INIT;
273 return (Platform_EFAIL);
274 }
275 }
276 }
278 return (Platform_EOK);
279 }
281 /**
282 * \brief Resets ADC module
283 *
284 * This function resets all the ADC module registers to their
285 * HW default values.
286 *
287 * \param devId [IN] Device ID of ADC HW instance
288 * Use 'ADC_DEVICE_ALL' to reset
289 * all the ADC devices available.
290 *
291 * \return Platform_EOK on Success or error code
292 */
293 Platform_STATUS platformAudioAdcReset(AdcDevId devId)
294 {
295 ADC_RET retVal;
296 Uint8 id;
298 IFPRINT(platform_write("platformAudioAdcReset Called \n"));
300 if(!((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)))
301 {
302 IFPRINT(platform_write("platformAudioAdcReset : Invalid Inputs\n"));
303 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
304 return (Platform_EINVALID);
305 }
307 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
308 {
309 if((id == devId) || (devId == ADC_DEVICE_ALL))
310 {
311 retVal = pcm186xReset(gAdcI2cAddr[id]);
312 if(retVal)
313 {
314 IFPRINT(platform_write("platformAudioAdcReset : ADC Reset Failed \n"));
315 platform_errno = PLATFORM_ERRNO_AUDIO;
316 return (Platform_EFAIL);
317 }
318 }
319 }
321 return (Platform_EOK);
322 }
324 /**
325 * \brief Configures ADC gain value
326 *
327 * Range of the gain is exposed as percentage by this API. Gain
328 * is indicated as percentage of maximum gain ranging from 0 to 100.
329 * 0 indicates minimum gain and 100 indicates maximum gain.
330 *
331 * \param devId [IN] Device ID of ADC HW instance
332 * Use 'ADC_DEVICE_ALL' to apply the configuration
333 * for all the ADC devices available.
334 *
335 * \param chanId [IN] Internal ADC channel Id
336 * Use ADC_CH_ALL to set gain for all the
337 * ADC channels
338 *
339 * \param gain [IN] Gain value; 0 to 100
340 *
341 * \return Platform_EOK on Success or error code
342 */
343 Platform_STATUS platformAudioAdcSetGain(AdcDevId devId,
344 AdcChanId chanId,
345 uint8_t gain)
346 {
347 ADC_RET retVal;
348 Uint8 id;
350 IFPRINT(platform_write("platformAudioAdcSetGain Called \n"));
352 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
353 ((chanId >= ADC_CH1_LEFT) && (chanId <= ADC_CH_ALL)) &&
354 (gain <= 100) ) )
355 {
356 IFPRINT(platform_write("platformAudioAdcSetGain : Invalid Inputs\n"));
357 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
358 return (Platform_EINVALID);
359 }
361 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
362 {
363 if((id == devId) || (devId == ADC_DEVICE_ALL))
364 {
365 retVal = pcm186xSetVolume(gAdcI2cAddr[id], (Uint8)gain,
366 (Uint8)chanId);
367 if(retVal)
368 {
369 IFPRINT(platform_write("platformAudioAdcSetGain : ADC Access for Gain Config Failed \n"));
370 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
371 return (Platform_EFAIL);
372 }
373 }
374 }
376 return (Platform_EOK);
377 }
379 /**
380 * \brief Configures ADC analog input selection for left channel
381 *
382 * Default input selection of ADC left channels can be modified using
383 * this function.
384 *
385 * Default input selection for ADC left channels is listed below
386 * CH1 LEFT - VINL1
387 * CH2 LEFT - VINL2
388 *
389 * \param devId [IN] Device ID of ADC HW instance
390 * Use 'ADC_DEVICE_ALL' to apply the configuration
391 * for all the ADC devices available.
392 *
393 * \param chanId [IN] Internal ADC channel Id
394 * ADC_CH1_LEFT - Input selection for channel 1 left
395 * ADC_CH2_LEFT - Input selection for channel 2 left
396 * ADC_CH_ALL - Input selection for channel 1 & 2 left
397 *
398 * \param inputMux [IN] Input mux configuration
399 *
400 * \return Platform_EOK on Success or error code
401 */
402 Platform_STATUS platformAudioAdcSetLeftInputMux(AdcDevId devId,
403 AdcChanId chanId,
404 AdcLeftInputMux inputMux)
405 {
406 ADC_RET retVal;
407 Uint8 id;
409 IFPRINT(platform_write("platformAudioAdcSetLeftInputMux Called \n"));
411 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
412 ((chanId == ADC_CH1_LEFT) || (chanId == ADC_CH2_LEFT) ||
413 (chanId == ADC_CH_ALL)) &&
414 ((inputMux >= ADC_INL_NONE) &&
415 (inputMux <= ADC_INL_DIFF_VIN1P_VIN1M_VIN4P_VIN4M)) ) )
416 {
417 IFPRINT(platform_write("platformAudioAdcSetLeftInputMux : Invalid Inputs\n"));
418 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
419 return (Platform_EINVALID);
420 }
422 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
423 {
424 if((id == devId) || (devId == ADC_DEVICE_ALL))
425 {
426 if(chanId == ADC_CH_ALL)
427 {
428 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)ADC_CH1_LEFT,
429 (Uint8)inputMux);
430 if(retVal)
431 {
432 IFPRINT(platform_write("platformAudioAdcSetLeftInputMux : ADC Access for Input Selection Failed \n"));
433 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
434 return (Platform_EFAIL);
435 }
437 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)ADC_CH2_LEFT,
438 (Uint8)inputMux);
439 }
440 else
441 {
442 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)chanId,
443 (Uint8)inputMux);
444 }
446 if(retVal)
447 {
448 IFPRINT(platform_write("platformAudioAdcSetLeftInputMux : ADC Access for Input Selection Failed \n"));
449 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
450 return (Platform_EFAIL);
451 }
452 }
453 }
455 return (Platform_EOK);
456 }
458 /**
459 * \brief Configures ADC analog input selection for right channel
460 *
461 * Default input selection of ADC right channels can be modified using
462 * this function
463 *
464 * Default input selection for ADC right channels is shown below
465 * CH1 RIGHT - VINR1
466 * CH2_RIGHT - VINR2
467 *
468 * \param devId [IN] Device ID of ADC HW instance
469 * Use 'ADC_DEVICE_ALL' to apply the configuration
470 * for all the ADC devices available.
471 *
472 * \param chanId [IN] Internal ADC channel Id
473 * ADC_CH1_RIGHT - Input selection for channel 1 right
474 * ADC_CH2_RIGHT - Input selection for channel 2 right
475 * ADC_CH_ALL - Input selection for channel 1 & 2 right
476 *
477 * \param inputMux [IN] Input mux configuration
478 *
479 * \return Platform_EOK on Success or error code
480 */
481 Platform_STATUS platformAudioAdcSetRightInputMux(AdcDevId devId,
482 AdcChanId chanId,
483 AdcRightInputMux inputMux)
484 {
485 ADC_RET retVal;
486 Uint8 id;
488 IFPRINT(platform_write("platformAudioAdcSetRightInputMux Called \n"));
490 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
491 ((chanId == ADC_CH1_RIGHT) || (chanId == ADC_CH2_RIGHT) ||
492 (chanId == ADC_CH_ALL)) &&
493 ((inputMux >= ADC_INR_NONE) &&
494 (inputMux <= ADC_INR_DIFF_VIN2P_VIN2M_VIN3P_VIN3M)) ) )
495 {
496 IFPRINT(platform_write("platformAudioAdcSetRightInputMux : Invalid Inputs\n"));
497 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
498 return (Platform_EINVALID);
499 }
501 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
502 {
503 if((id == devId) || (devId == ADC_DEVICE_ALL))
504 {
505 if(chanId == ADC_CH_ALL)
506 {
507 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)ADC_CH1_RIGHT,
508 (Uint8)inputMux);
509 if(retVal)
510 {
511 IFPRINT(platform_write("platformAudioAdcSetRightInputMux : ADC Access for Input Selection Failed \n"));
512 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
513 return (Platform_EFAIL);
514 }
516 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)ADC_CH2_RIGHT,
517 (Uint8)inputMux);
518 }
519 else
520 {
521 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)chanId,
522 (Uint8)inputMux);
523 }
525 if(retVal)
526 {
527 IFPRINT(platform_write("platformAudioAdcSetRightInputMux : ADC Access for Input Selection Failed \n"));
528 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
529 return (Platform_EFAIL);
530 }
531 }
532 }
534 return (Platform_EOK);
535 }
537 /**
538 * \brief ADC audio interface data configuration
539 *
540 * This function configures serial audio interface data format and
541 * receive PCM word length for ADC
542 *
543 * \param devId [IN] Device ID of ADC HW instance
544 * Use 'ADC_DEVICE_ALL' to apply the configuration
545 * for all the ADC devices available.
546 *
547 * \param wLen [IN] ADC data word length
548 *
549 * \param format [IN] Audio data format
550 *
551 * \return Platform_EOK on Success or error code
552 */
553 Platform_STATUS platformAudioAdcDataConfig(AdcDevId devId,
554 AdcRxWordLen wLen,
555 AdcDataFormat format)
556 {
557 ADC_RET retVal;
558 Uint8 id;
560 IFPRINT(platform_write("platformAudioAdcDataConfig Called \n"));
562 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
563 ((wLen >= ADC_RX_WLEN_24BIT) && (wLen <= ADC_RX_WLEN_16BIT)) &&
564 ((format >= ADC_DATA_FORMAT_I2S) &&
565 (format <= ADC_DATA_FORMAT_TDM_DSP)) ) )
566 {
567 IFPRINT(platform_write("platformAudioAdcDataConfig : Invalid Inputs\n"));
568 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
569 return (Platform_EINVALID);
570 }
572 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
573 {
574 if((id == devId) || (devId == ADC_DEVICE_ALL))
575 {
576 retVal = pcm186xDataConfig(gAdcI2cAddr[id], (Uint8)format,
577 (Uint8)wLen);
578 if(retVal)
579 {
580 IFPRINT(platform_write("platformAudioAdcDataConfig : ADC Access for Data Config Failed \n"));
581 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
582 return (Platform_EFAIL);
583 }
584 }
585 }
587 return (Platform_EOK);
588 }
590 /**
591 * \brief Enables/Disables ADC channel mute
592 *
593 * This function configures mute functionality of each ADC channel
594 *
595 * \param devId [IN] Device ID of ADC HW instance
596 * Use 'ADC_DEVICE_ALL' to apply the configuration
597 * for all the ADC devices available.
598 *
599 * \param chanId [IN] Internal ADC channel Id
600 * Use ADC_CH_ALL to apply mute configuration for
601 * all the ADC channels
602 *
603 * \param muteEnable [IN] Flag to configure mute
604 * 1 - Mute ADC channel
605 * 0 - Unmute ADC channel
606 *
607 * \return Platform_EOK on Success or error code
608 */
609 Platform_STATUS platformAudioAdcMuteCtrl(AdcDevId devId,
610 AdcChanId chanId,
611 uint8_t muteEnable)
612 {
613 ADC_RET retVal;
614 Uint8 chan;
615 Uint8 id;
617 IFPRINT(platform_write("platformAudioAdcMuteCtrl Called \n"));
619 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
620 ((chanId >= ADC_CH1_LEFT) && (chanId <= ADC_CH_ALL)) &&
621 ((muteEnable == 0) || (muteEnable == 1)) ) )
622 {
623 IFPRINT(platform_write("platformAudioAdcMuteCtrl : Invalid Inputs\n"));
624 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
625 return (Platform_EINVALID);
626 }
628 if(chanId == ADC_CH_ALL)
629 {
630 chan = 0xF;
631 }
632 else
633 {
634 chan = (1 << chanId);
635 }
637 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
638 {
639 if((id == devId) || (devId == ADC_DEVICE_ALL))
640 {
641 retVal = pcm186xMuteChannel(gAdcI2cAddr[id], chan,
642 (Uint8)muteEnable);
643 if(retVal)
644 {
645 IFPRINT(platform_write("platformAudioAdcMuteCtrl : ADC Access for Mute Config Failed \n"));
646 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
647 return (Platform_EFAIL);
648 }
649 }
650 }
652 return (Platform_EOK);
653 }
655 /**
656 * \brief Configures ADC MIC bias
657 *
658 * This function enables/disables MIC bias for analog MIC input
659 *
660 * \param devId [IN] Device ID of ADC HW instance
661 * Use 'ADC_DEVICE_ALL' to apply the configuration
662 * for all the ADC devices available.
663 *
664 * \param micBiasEnable [IN] Mic Bias enable flag
665 * 1 - Enable MIC Bias
666 * 0 - Disable MIC Bias
667 *
668 * \return Platform_EOK on Success or error code
669 */
670 Platform_STATUS platformAudioAdcMicBiasCtrl(AdcDevId devId,
671 uint8_t micBiasEnable)
672 {
673 ADC_RET retVal;
674 Uint8 id;
676 IFPRINT(platform_write("platformAudioAdcMicBiasCtrl Called \n"));
678 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
679 ((micBiasEnable == 0) || (micBiasEnable == 1)) ) )
680 {
681 IFPRINT(platform_write("platformAudioAdcMicBiasCtrl : Invalid Inputs\n"));
682 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
683 return (Platform_EINVALID);
684 }
686 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
687 {
688 if((id == devId) || (devId == ADC_DEVICE_ALL))
689 {
690 retVal = pcm186xMicBiasCtrl(gAdcI2cAddr[id], (Uint8)micBiasEnable);
691 if(retVal)
692 {
693 IFPRINT(platform_write("platformAudioAdcMicBiasCtrl : ADC Access for Mic Bias Config Failed \n"));
694 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
695 return (Platform_EFAIL);
696 }
697 }
698 }
700 return (Platform_EOK);
701 }
703 /**
704 * \brief Configures ADC power state
705 *
706 * This function enables/disables different power modes supported by ADC
707 *
708 * \param devId [IN] Device ID of ADC HW instance
709 * Use 'ADC_DEVICE_ALL' to apply the configuration
710 * for all the ADC devices available.
711 *
712 * \param powState [IN] ADC power state to configure
713 *
714 * \param stateEnable [IN] Power state enable flag
715 * 1 - Enables the power state
716 * 0 - Disables the power state
717 *
718 * \return Platform_EOK on Success or error code
719 */
720 Platform_STATUS platformAudioAdcConfigPowState(AdcDevId devId,
721 AdcPowerState powState,
722 uint8_t stateEnable)
723 {
724 ADC_RET retVal;
725 Uint8 id;
727 IFPRINT(platform_write("platformAudioAdcConfigPowState Called \n"));
729 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
730 ((powState >= ADC_POWER_STATE_STANDBY) &&
731 (powState <= ADC_POWER_STATE_POWERDOWN)) &&
732 ((stateEnable == 0) || (stateEnable == 1)) ) )
733 {
734 IFPRINT(platform_write("platformAudioAdcConfigPowState : Invalid Inputs\n"));
735 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
736 return (Platform_EINVALID);
737 }
739 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
740 {
741 if((id == devId) || (devId == ADC_DEVICE_ALL))
742 {
743 retVal = pcm186xConfigPowState(gAdcI2cAddr[id], (Uint8)powState,
744 (Uint8)stateEnable);
745 if(retVal)
746 {
747 IFPRINT(platform_write("platformAudioAdcConfigPowState : ADC Access for Power State Config Failed \n"));
748 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
749 return (Platform_EFAIL);
750 }
751 }
752 }
754 return (Platform_EOK);
755 }
757 /**
758 * \brief Configures ADC interrupts
759 *
760 * This function enables/disables different interrupts supported by ADC
761 *
762 * \param devId [IN] Device ID of ADC HW instance
763 * Use 'ADC_DEVICE_ALL' to apply the configuration
764 * for all the ADC devices available.
765 *
766 * \param intId [IN] Interrupt Id to configure
767 * Use to 'ADC_INTR_ALL' to configure all the
768 * interrupts together
769 *
770 * \param intEnable [IN] Interrupt enable flag
771 * 1 - Enables the interrupt
772 * 0 - Disables the interrupt
773 *
774 * \return Platform_EOK on Success or error code
775 */
776 Platform_STATUS platformAudioAdcConfigIntr(AdcDevId devId,
777 AdcIntr intId,
778 uint8_t intEnable)
779 {
780 ADC_RET retVal;
781 Uint8 id;
783 IFPRINT(platform_write("platformAudioAdcConfigIntr Called \n"));
785 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
786 ((intId >= ADC_INTR_ENERGY_SENSE) && (intId <= ADC_INTR_ALL)) &&
787 ((intEnable == 0) || (intEnable == 1)) ) )
788 {
789 IFPRINT(platform_write("platformAudioAdcConfigIntr : Invalid Inputs\n"));
790 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
791 return (Platform_EINVALID);
792 }
794 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
795 {
796 if((id == devId) || (devId == ADC_DEVICE_ALL))
797 {
798 retVal = pcm186xSetIntr(gAdcI2cAddr[id], (Uint8)intId,
799 (Uint8)intEnable);
800 if(retVal)
801 {
802 IFPRINT(platform_write("platformAudioAdcConfigIntr : ADC Access for Intr Config Failed \n"));
803 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
804 return (Platform_EFAIL);
805 }
806 }
807 }
809 return (Platform_EOK);
810 }
812 /**
813 * \brief Reads ADC interrupt status
814 *
815 * This function reads the status of different interrupts supported by ADC
816 *
817 * \param devId [IN] Device ID of ADC HW instance
818 *
819 * \param intId [IN] Interrupt Id to read the status
820 * Use to 'ADC_INTR_ALL' to read status of all the
821 * interrupts together
822 *
823 * \return Interrupt status
824 * 1 - Interrupt occurred
825 * 0 - No interrupt occurred
826 * 0xFF - Error in reading interrupt
827 */
828 uint8_t platformAudioAdcGetIntrStatus(AdcDevId devId,
829 AdcIntr intId)
830 {
831 Uint8 retVal;
833 IFPRINT(platform_write("platformAudioAdcGetIntrStatus Called \n"));
835 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_1)) &&
836 ((intId >= ADC_INTR_ENERGY_SENSE) && (intId <= ADC_INTR_ALL)) ) )
837 {
838 IFPRINT(platform_write("platformAudioAdcGetIntrStatus : Invalid Inputs\n"));
839 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
840 return (1);
841 }
843 retVal = pcm186xGetIntrStatus(gAdcI2cAddr[devId]);
844 if(retVal == 0xFF)
845 {
846 IFPRINT(platform_write("platformAudioAdcGetIntrStatus : ADC Access for Intr Status Failed \n"));
847 platform_errno = PLATFORM_ERRNO_AUDIO_STATUS;
848 return ((uint8_t)retVal);
849 }
851 if(intId != ADC_INTR_ALL)
852 {
853 retVal = (retVal >> intId) & 0x1;
854 }
856 return (retVal);
857 }
859 /**
860 * \brief Reads ADC status bits
861 *
862 * This function reads the value of different status functions supported
863 * by ADC module (excluding interrupts).
864 *
865 * \param devId [IN] Device ID of ADC HW instance
866 *
867 * \param status [IN] Status function of which status to be read
868 *
869 * \return Value of status function or 0xFF in case of error
870 *
871 */
872 uint8_t platformAudioAdcGetStatus(AdcDevId devId,
873 AdcStatus status)
874 {
875 Uint8 retVal;
877 IFPRINT(platform_write("platformAudioAdcGetStatus Called \n"));
879 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_1)) &&
880 ((status >= ADC_STATUS_POWER_STATE) &&
881 (status <= ADC_STATUS_LDO)) ) )
882 {
883 IFPRINT(platform_write("platformAudioAdcGetStatus : Invalid Inputs\n"));
884 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
885 return (1);
886 }
888 switch(status)
889 {
890 /* Current Power State of the device
891 * 0x0 - Power Down
892 * 0x1 - Wait clock stable
893 * 0x2 - Release reset
894 * 0x3 - Stand-by
895 * 0x4 - Fade IN
896 * 0x5 - Fade OUT
897 * 0x9 - Sleep
898 * 0xF - Run
899 */
900 case ADC_STATUS_POWER_STATE:
901 retVal = pcm186xGetPowerStateStatus(gAdcI2cAddr[devId]);
902 break;
904 /* Current Sampling Frequency
905 * 0x0 - Out of range (Low) or LRCK Halt
906 * 0x1 - 8kHz
907 * 0x2 - 16kHz
908 * 0x3 - 32-48kHz
909 * 0x4 - 88.2-96kHz
910 * 0x5 - 176.4-192kHz
911 * 0x6 - Out of range (High)
912 * 0x7 - Invalid Fs
913 */
914 case ADC_STATUS_SAMPLING_FREQ:
915 retVal = pcm186xGetSampleFreqStatus(gAdcI2cAddr[devId]);
916 break;
918 /* Current receiving BCK ratio
919 * 0x0 - Out of range (L) or BCK Halt
920 * 0x1 - 32
921 * 0x2 - 48
922 * 0x3 - 64
923 * 0x4 - 256
924 * 0x6 - Out of range (High)
925 * 0x7 - Invalid BCK ratio or LRCK Halt
926 */
927 case ADC_STATUS_BCK_RATIO:
928 retVal = pcm186xGetBckRatioStatus(gAdcI2cAddr[devId]);
929 break;
931 /* Current SCK Ratio
932 * 0x0 - Out of range (L) or SCK Halt
933 * 0x1 - 128
934 * 0x2 - 256
935 * 0x3 - 384
936 * 0x4 - 512
937 * 0x5 - 768
938 * 0x6 - Out of range (High)
939 * 0x7 - Invalid SCK ratio or LRCK Halt
940 */
941 case ADC_STATUS_SCK_RATIO:
942 retVal = pcm186xGetSckRatioStatus(gAdcI2cAddr[devId]);
943 break;
945 /* LRCK Halt Status
946 * 0 - No Error
947 * 1 - Halt
948 */
949 case ADC_STATUS_LRCK_HALT:
950 retVal = pcm186xGetLrckHltStatus(gAdcI2cAddr[devId]);
951 break;
953 /* BCK Halt Status
954 * 0 - No Error
955 * 1 - Halt
956 */
957 case ADC_STATUS_BCK_HALT:
958 retVal = pcm186xGetBckHltStatus(gAdcI2cAddr[devId]);
959 break;
961 /* SCK Halt Status
962 * 0 - No Error
963 * 1 - Halt
964 */
965 case ADC_STATUS_SCK_HALT:
966 retVal = pcm186xGetSckHltStatus(gAdcI2cAddr[devId]);
967 break;
969 /* LRCK Error Status
970 * 0 - No Error
971 * 1 - Error
972 */
973 case ADC_STATUS_LRCK_ERR:
974 retVal = pcm186xGetLrckErrStatus(gAdcI2cAddr[devId]);
975 break;
977 /* BCK Error Status
978 * 0 - No Error
979 * 1 - Error
980 */
981 case ADC_STATUS_BCK_ERR:
982 retVal = pcm186xGetBckErrStatus(gAdcI2cAddr[devId]);
983 break;
985 /* SCK Error Status
986 * 0 - No Error
987 * 1 - Error
988 */
989 case ADC_STATUS_SCK_ERR:
990 retVal = pcm186xGetSckErrStatus(gAdcI2cAddr[devId]);
991 break;
993 /* DVDD Status
994 * 0 - Bad/Missing
995 * 1 - Good
996 */
997 case ADC_STATUS_DVDD:
998 retVal = pcm186xGetDvddStatus(gAdcI2cAddr[devId]);
999 break;
1001 /* AVDD Status
1002 * 0 - Bad/Missing
1003 * 1 - Good
1004 */
1005 case ADC_STATUS_AVDD:
1006 retVal = pcm186xGetAvddStatus(gAdcI2cAddr[devId]);
1007 break;
1009 /* Digital LDO Status
1010 * 0 - Bad/Missing
1011 * 1 - Good
1012 */
1013 case ADC_STATUS_LDO:
1014 retVal = pcm186xGetLdoStatus(gAdcI2cAddr[devId]);
1015 break;
1017 default:
1018 retVal = 0xFF;
1019 break;
1021 }
1023 if(retVal == 0xFF)
1024 {
1025 IFPRINT(platform_write("platformAudioAdcGetStatus : ADC Access for Get Status Failed \n"));
1026 platform_errno = PLATFORM_ERRNO_AUDIO_STATUS;
1027 }
1029 return ((uint8_t)retVal);
1030 }
1032 /**
1033 * \brief ADC DSP channel configuration control
1034 *
1035 * This function configures the DSP module processing channels
1036 * supported by ADC
1037 *
1038 * \param devId [IN] Device ID of ADC HW instance
1039 * Use 'ADC_DEVICE_ALL' to apply the configuration
1040 * for all the ADC devices available.
1041 *
1042 * \param chanCfg [IN] DSP channel configuration
1043 *
1044 * \return Platform_EOK on Success or error code
1045 *
1046 */
1047 Platform_STATUS platformAudioAdcDspCtrl(AdcDevId devId,
1048 AdcDspChanCfg chanCfg)
1049 {
1050 ADC_RET retVal;
1051 Uint8 id;
1053 IFPRINT(platform_write("platformAudioAdcDspCtrl Called \n"));
1055 if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
1056 ((chanCfg == ADC_DSP_PROC_4CHAN) ||
1057 (chanCfg == ADC_DSP_PROC_2CHAN)) ) )
1058 {
1059 IFPRINT(platform_write("platformAudioAdcDspCtrl : Invalid Inputs\n"));
1060 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1061 return (Platform_EINVALID);
1062 }
1064 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
1065 {
1066 if((id == devId) || (devId == ADC_DEVICE_ALL))
1067 {
1068 retVal = pcm186xDspCtrl(gAdcI2cAddr[id], (Uint8)chanCfg);
1069 if(retVal)
1070 {
1071 IFPRINT(platform_write("platformAudioAdcDspCtrl : ADC Access for DSP Chan Config Failed \n"));
1072 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1073 return (Platform_EFAIL);
1074 }
1075 }
1076 }
1078 return (Platform_EOK);
1079 }
1081 /**
1082 * \brief Programs ADC DSP coefficients
1083 *
1084 * ADC module supports an internal DSP which performs additional audio
1085 * processing operations like mixing, LPF/HPF etc.
1086 * DSP coefficients can be programmed by this function.
1087 *
1088 * \param devId [IN] Device ID of ADC HW instance
1089 * Use 'ADC_DEVICE_ALL' to apply the configuration
1090 * for all the ADC devices available.
1091 *
1092 * \param coeffRegAddr [IN] Address of DSP coefficient register
1093 *
1094 * \param dspCoeff [IN] Value of DSP coefficient
1095 * Lower 24 bits are written to DSP coeff register
1096 *
1097 * \return Platform_EOK on Success or error code
1098 *
1099 */
1100 Platform_STATUS platformAudioAdcProgDspCoeff(AdcDevId devId,
1101 uint8_t coeffRegAddr,
1102 uint32_t dspCoeff)
1103 {
1104 ADC_RET retVal;
1105 Uint8 id;
1107 IFPRINT(platform_write("platformAudioAdcProgDspCoeff Called \n"));
1109 if(!((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)))
1110 {
1111 IFPRINT(platform_write("platformAudioAdcProgDspCoeff : Invalid Inputs\n"));
1112 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1113 return (Platform_EINVALID);
1114 }
1116 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
1117 {
1118 if((id == devId) || (devId == ADC_DEVICE_ALL))
1119 {
1120 retVal = pcm186xProgDspCoeff(gAdcI2cAddr[id], (Uint8)coeffRegAddr,
1121 (Uint32)dspCoeff);
1122 if(retVal)
1123 {
1124 IFPRINT(platform_write("platformAudioAdcProgDspCoeff : ADC DSP Coefficient Config Failed \n"));
1125 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1126 return (Platform_EFAIL);
1127 }
1128 }
1129 }
1131 return (Platform_EOK);
1132 }
1134 /**
1135 * \brief Displays ADC register programmed values
1136 *
1137 * This function is provided for debug purpose to read the value
1138 * of ADC registers. Values read from the ADC registers will be displayed
1139 * in CCS output window or serial terminal based on the system level
1140 * configuration for debug messages.
1141 *
1142 * \param devId [IN] Device ID of ADC HW instance
1143 * Use 'ADC_DEVICE_ALL' to read the register values
1144 * for all the ADC devices available.
1145 *
1146 * \return Platform_EOK on Success or error code
1147 */
1148 Platform_STATUS platformAudioAdcGetRegDump(AdcDevId devId)
1149 {
1150 ADC_RET retVal;
1151 Uint8 id;
1153 IFPRINT(platform_write("platformAudioAdcGetRegDump Called \n"));
1155 if(!((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)))
1156 {
1157 IFPRINT(platform_write("platformAudioAdcGetRegDump : Invalid Inputs\n"));
1158 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1159 return (Platform_EINVALID);
1160 }
1162 for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
1163 {
1164 if((id == devId) || (devId == ADC_DEVICE_ALL))
1165 {
1166 retVal = pcm186xRegDump(gAdcI2cAddr[id]);
1167 if(retVal)
1168 {
1169 IFPRINT(platform_write("platformAudioAdcGetRegDump : ADC Reg Read Failed \n"));
1170 platform_errno = PLATFORM_ERRNO_AUDIO_STATUS;
1171 return (Platform_EFAIL);
1172 }
1173 }
1174 }
1176 return (Platform_EOK);
1177 }
1179 #endif /* #if (PLATFORM_AUDIO_ADC) */
1182 #if (PLATFORM_AUDIO_DAC)
1184 /**
1185 * \brief Initializes DAC module
1186 *
1187 * This function configures the system level setup required for DAC
1188 * operation and initializes the DAC module with default values.
1189 * This function should be called before calling any other DAC functions.
1190 *
1191 * After executing this function, DAC module should be ready for audio
1192 * processing with default configuration. Default DAC configurations
1193 * can be changed using the other DAC APIs if required.
1194 *
1195 * \param devId [IN] Device ID of DAC HW instance
1196 * Use 'DAC_DEVICE_ALL' to initialize
1197 * all the DAC devices available.
1198 *
1199 * \return Platform_EOK on Success or error code
1200 */
1201 Platform_STATUS platformAudioDacInit(DacDevId devId)
1202 {
1203 DAC_RET retVal;
1204 Uint8 id;
1206 IFPRINT(platform_write("platformAudioDacInit Called \n"));
1208 if(!((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)))
1209 {
1210 IFPRINT(platform_write("platformAudioDacInit : Invalid Inputs\n"));
1211 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1212 return (Platform_EINVALID);
1213 }
1215 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1216 {
1217 if((id == devId) || (devId == DAC_DEVICE_ALL))
1218 {
1219 retVal = pcm169xDacInit(gDacI2cAddr[id]);
1220 if(retVal)
1221 {
1222 IFPRINT(platform_write("platformAudioDacInit : DAC Initialization Failed \n"));
1223 platform_errno = PLATFORM_ERRNO_AUDIO_INIT;
1224 return (Platform_EFAIL);
1225 }
1226 }
1227 }
1229 return (Platform_EOK);
1230 }
1232 /**
1233 * \brief Resets DAC module
1234 *
1235 * Resetting the DAC module restarts the re-synchronization between
1236 * system clock and sampling clock, and DAC operation.
1237 *
1238 * \param devId [IN] Device ID of DAC HW instance
1239 * Use 'DAC_DEVICE_ALL' to reset
1240 * all the DAC devices available.
1241 *
1242 * \return Platform_EOK on Success or error code
1243 */
1244 Platform_STATUS platformAudioDacReset(DacDevId devId)
1245 {
1246 DAC_RET retVal;
1247 Uint8 id;
1249 IFPRINT(platform_write("platformAudioDacReset Called \n"));
1251 /* Check input parameters */
1252 if(!((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)))
1253 {
1254 IFPRINT(platform_write("platformAudioDacReset : Invalid Inputs\n"));
1255 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1256 return (Platform_EINVALID);
1257 }
1259 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1260 {
1261 if((id == devId) || (devId == DAC_DEVICE_ALL))
1262 {
1263 IFPRINT(platform_write("platformAudioDacReset : DAC Reset Failed \n"));
1264 retVal = pcm169xReset(gDacI2cAddr[id]);
1265 if(retVal)
1266 {
1267 platform_errno = PLATFORM_ERRNO_AUDIO;
1268 return (Platform_EFAIL);
1269 }
1270 }
1271 }
1273 return (Platform_EOK);
1274 }
1276 /**
1277 * \brief Configures DAC Analog mute control
1278 *
1279 * DAC module supports AMUTE functionality which causes the DAC output
1280 * to cut-off from the digital input upon the occurrence of any events
1281 * which are configured by AMUTE control.
1282 *
1283 * \param devId [IN] Device ID of DAC HW instance
1284 * Use 'DAC_DEVICE_ALL' to apply the configuration
1285 * for all the DAC devices available.
1286 *
1287 * \param muteCtrl [IN] Analog mute control event
1288 *
1289 * \param muteEnable [IN] Flag to configure AMUTE for given control event
1290 * 1 - Enable AMUTE control
1291 * 0 - Disable AMUTE control
1292 *
1293 * \return Platform_EOK on Success or error code
1294 */
1295 Platform_STATUS platformAudioDacAmuteCtrl(DacDevId devId,
1296 DacAmuteCtrl muteCtrl,
1297 uint8_t muteEnable)
1298 {
1299 DAC_RET retVal;
1300 Uint8 id;
1302 IFPRINT(platform_write("platformAudioDacAmuteCtrl Called \n"));
1304 /* Check input parameters */
1305 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1306 ((muteCtrl >= DAC_AMUTE_CTRL_SCKI_LOST) &&
1307 (muteCtrl <= DAC_AMUTE_CTRL_DAC_DISABLE_CMD)) &&
1308 ((muteEnable == 0) || (muteEnable == 1)) ) )
1309 {
1310 IFPRINT(platform_write("platformAudioDacAmuteCtrl : Invalid Inputs\n"));
1311 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1312 return (Platform_EINVALID);
1313 }
1315 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1316 {
1317 if((id == devId) || (devId == DAC_DEVICE_ALL))
1318 {
1319 if(muteEnable == 1)
1320 {
1321 retVal = pcm169xEnableAmute(gDacI2cAddr[id],
1322 (Uint8)(1 << muteCtrl));
1323 }
1324 else
1325 {
1326 retVal = pcm169xDisableAmute(gDacI2cAddr[id],
1327 (Uint8)(1 << muteCtrl));
1328 }
1330 if(retVal)
1331 {
1332 IFPRINT(platform_write("platformAudioDacAmuteCtrl : DAC Access for AMUTE Config Failed \n"));
1333 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1334 return (Platform_EFAIL);
1335 }
1336 }
1337 }
1339 return (Platform_EOK);
1340 }
1342 /**
1343 * \brief Configures DAC Audio sampling mode
1344 *
1345 * By default, DAC module sampling mode is configured for auto mode.
1346 * In Auto mode, the sampling mode is automatically set according to multiples
1347 * between the system clock and sampling clock. Single rate for 512 fS, 768 fS,
1348 * and 1152 fS, dual rate for 256 fS or 384 fS, and quad rate for 128 fS
1349 * and 192 fS. Setting the sampling mode is required only if auto mode
1350 * configurations are not suitable for the application.
1351 *
1352 * \param devId [IN] Device ID of DAC HW instance
1353 * Use 'DAC_DEVICE_ALL' to apply the configuration
1354 * for all the DAC devices available.
1355 *
1356 * \param samplingMode [IN] DAC audio sampling mode
1357 *
1358 * \return Platform_EOK on Success or error code
1359 */
1360 Platform_STATUS platformAudioDacSetSamplingMode(DacDevId devId,
1361 DacSamplingMode samplingMode)
1362 {
1363 DAC_RET retVal;
1364 Uint8 id;
1366 IFPRINT(platform_write("platformAudioDacSetSamplingMode Called \n"));
1368 /* Check input parameters */
1369 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1370 ((samplingMode >= DAC_SAMPLING_MODE_AUTO) &&
1371 (samplingMode <= DAC_SAMPLING_MODE_QUAD_RATE)) ) )
1372 {
1373 IFPRINT(platform_write("platformAudioDacSetSamplingMode : Invalid Inputs\n"));
1374 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1375 return (Platform_EINVALID);
1376 }
1378 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1379 {
1380 if((id == devId) || (devId == DAC_DEVICE_ALL))
1381 {
1382 retVal = pcm169xSetSamplingMode(gDacI2cAddr[id],
1383 (Uint8)samplingMode);
1384 if(retVal)
1385 {
1386 IFPRINT(platform_write("platformAudioDacSetSamplingMode : DAC Access for Sampling Mode Config Failed \n"));
1387 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1388 return (Platform_EFAIL);
1389 }
1390 }
1391 }
1393 return (Platform_EOK);
1394 }
1396 /**
1397 * \brief Configures DAC Audio interface data format
1398 *
1399 * \param devId [IN] Device ID of DAC HW instance
1400 * Use 'DAC_DEVICE_ALL' to apply the configuration
1401 * for all the DAC devices available.
1402 *
1403 * \param dataFormat [IN] DAC audio data format
1404 *
1405 * \return Platform_EOK on Success or error code
1406 */
1407 Platform_STATUS platformAudioDacSetDataFormat(DacDevId devId,
1408 DacDataFormat dataFormat)
1409 {
1410 DAC_RET retVal;
1411 Uint8 id;
1413 IFPRINT(platform_write("platformAudioDacSetDataFormat Called \n"));
1415 /* Check input parameters */
1416 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1417 ((dataFormat >= DAC_DATA_FORMAT_I2S) &&
1418 (dataFormat <= DAC_DATA_FORMAT_24BIT_HS_LEFTJ_TDM)) ) )
1419 {
1420 IFPRINT(platform_write("platformAudioDacSetDataFormat : Invalid Inputs\n"));
1421 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1422 return (Platform_EINVALID);
1423 }
1425 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1426 {
1427 if((id == devId) || (devId == DAC_DEVICE_ALL))
1428 {
1429 retVal = pcm169xDataConfig(gDacI2cAddr[id], (Uint8)dataFormat);
1430 if(retVal)
1431 {
1432 IFPRINT(platform_write("platformAudioDacSetDataFormat : DAC Access for Data Format Config Failed \n"));
1433 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1434 return (Platform_EFAIL);
1435 }
1436 }
1437 }
1439 return (Platform_EOK);
1440 }
1442 /**
1443 * \brief Configures DAC operation mode
1444 *
1445 * This function configures a particular DAC channel pair to be operating
1446 * normal or disabled.
1447 *
1448 * \param devId [IN] Device ID of DAC HW instance
1449 * Use 'DAC_DEVICE_ALL' to apply the configuration
1450 * for all the DAC devices available.
1451 *
1452 * \param chanPair [IN] Internal DAC channel pair
1453 * Use DAC_CHANP_1_2 to DAC_CHANP_7_8 for
1454 * individual DAC channel pair configuration
1455 * Use DAC_CHANP_ALL to set operation mode
1456 * for all DAC channels
1457 *
1458 * \param opMode [IN] DAC operation mode
1459 *
1460 * \return Platform_EOK on Success or error code
1461 */
1462 Platform_STATUS platformAudioDacSetOpMode(DacDevId devId,
1463 DacChanPair chanPair,
1464 DacOpMode opMode)
1465 {
1466 DAC_RET retVal;
1467 Uint8 modeCtrl;
1468 Uint8 id;
1470 IFPRINT(platform_write("platformAudioDacSetOpMode Called \n"));
1472 /* Check input parameters */
1473 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1474 ((chanPair >= DAC_CHANP_1_2) && (chanPair <= DAC_CHANP_ALL)) &&
1475 ((opMode == DAC_OPMODE_NORMAL) ||
1476 (opMode == DAC_OPMODE_DISABLED)) ) )
1477 {
1478 IFPRINT(platform_write("platformAudioDacSetOpMode : Invalid Inputs\n"));
1479 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1480 return (Platform_EINVALID);
1481 }
1483 if(chanPair == DAC_CHANP_ALL)
1484 {
1485 modeCtrl = 0xF;
1486 }
1487 else
1488 {
1489 modeCtrl = (1 << chanPair);
1490 }
1492 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1493 {
1494 if((id == devId) || (devId == DAC_DEVICE_ALL))
1495 {
1496 if(opMode == DAC_OPMODE_DISABLED)
1497 {
1498 retVal = pcm169xDisableDacOpeartion(gDacI2cAddr[id], modeCtrl);
1499 }
1500 else
1501 {
1502 retVal = pcm169xEnableDacOpeartion(gDacI2cAddr[id], modeCtrl);
1503 }
1505 if(retVal)
1506 {
1507 IFPRINT(platform_write("platformAudioDacSetOpMode : DAC Access for Opmode Config Failed \n"));
1508 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1509 return (Platform_EFAIL);
1510 }
1511 }
1512 }
1514 return (Platform_EOK);
1515 }
1517 /**
1518 * \brief Configures DAC filter roll-off
1519 *
1520 * \param devId [IN] Device ID of DAC HW instance
1521 * Use 'DAC_DEVICE_ALL' to apply the configuration
1522 * for all the DAC devices available.
1523 *
1524 * \param chanPair [IN] Internal DAC channel pair
1525 * Use DAC_CHANP_1_2 to DAC_CHANP_7_8 for
1526 * individual DAC channel pair configuration
1527 * Use DAC_CHANP_ALL to set filter roll-off
1528 * for all DAC channels
1529 *
1530 * \param rolloff [IN] Roll-off configuration
1531 *
1532 * \return Platform_EOK on Success or error code
1533 */
1534 Platform_STATUS platformAudioDacSetFilterRolloff(DacDevId devId,
1535 DacChanPair chanPair,
1536 DacFilterRolloff rolloff)
1537 {
1538 DAC_RET retVal;
1539 Uint8 chanId;
1540 Uint8 id;
1542 IFPRINT(platform_write("platformAudioDacSetFilterRolloff Called \n"));
1544 /* Check input parameters */
1545 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1546 ((chanPair >= DAC_CHANP_1_2) && (chanPair <= DAC_CHANP_ALL)) &&
1547 ((rolloff >= DAC_FILTER_SHARP_ROLLOFF) &&
1548 (rolloff <= DAC_FILTER_SLOW_ROLLOFF)) ) )
1549 {
1550 IFPRINT(platform_write("platformAudioDacSetFilterRolloff : Invalid Inputs\n"));
1551 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1552 return (Platform_EINVALID);
1553 }
1555 if(chanPair == DAC_CHANP_ALL)
1556 {
1557 chanId = 0xF;
1558 }
1559 else
1560 {
1561 chanId = (1 << chanPair);
1562 }
1564 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1565 {
1566 if((id == devId) || (devId == DAC_DEVICE_ALL))
1567 {
1568 retVal = pcm169xSetFilterRolloff(gDacI2cAddr[id], chanId,
1569 (Uint8)rolloff);
1570 if(retVal)
1571 {
1572 IFPRINT(platform_write("platformAudioDacSetFilterRolloff : DAC Access for Filter Roll-off Config Failed \n"));
1573 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1574 return (Platform_EFAIL);
1575 }
1576 }
1577 }
1579 return (Platform_EOK);
1580 }
1582 /**
1583 * \brief Configures phase of the DAC analog signal outputs
1584 *
1585 * \param devId [IN] Device ID of DAC HW instance
1586 * Use 'DAC_DEVICE_ALL' to apply the configuration
1587 * for all the DAC devices available.
1588 *
1589 * \param chanId [IN] Internal DAC channel Id
1590 * Use DAC_CHAN_1 to DAC_CHAN_8 for individual
1591 * DAC channel configuration
1592 * Use DAC_CHAN_ALL to set output phase for all
1593 * DAC channels
1594 *
1595 * \param outPhase [IN] Output phase selection
1596 *
1597 * \return Platform_EOK on Success or error code
1598 */
1599 Platform_STATUS platformAudioDacSetOutputPhase(DacDevId devId,
1600 DacChanId chanId,
1601 DacOutputPhase outPhase)
1602 {
1603 DAC_RET retVal;
1604 Uint8 chan;
1605 Uint8 id;
1607 IFPRINT(platform_write("platformAudioDacSetOutputPhase Called \n"));
1609 /* Check input parameters */
1610 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1611 ((chanId >= DAC_CHAN_1) && (chanId <= DAC_CHAN_ALL)) &&
1612 ((outPhase >= DAC_OUTPUT_PHASE_NORMAL) &&
1613 (outPhase <= DAC_OUTPUT_PHASE_INVERTED)) ) )
1614 {
1615 IFPRINT(platform_write("platformAudioDacSetOutputPhase : Invalid Inputs\n"));
1616 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1617 return (Platform_EINVALID);
1618 }
1620 if(chanId == DAC_CHAN_ALL)
1621 {
1622 chan = 0xFF;
1623 }
1624 else
1625 {
1626 chan = (1 << chanId);
1627 }
1629 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1630 {
1631 if((id == devId) || (devId == DAC_DEVICE_ALL))
1632 {
1633 retVal = pcm169xSetOutputPhase(gDacI2cAddr[id], chan,
1634 (Uint8)outPhase);
1635 if(retVal)
1636 {
1637 IFPRINT(platform_write("platformAudioDacSetOutputPhase : DAC Access for Output Phase Config Failed \n"));
1638 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1639 return (Platform_EFAIL);
1640 }
1641 }
1642 }
1644 return (Platform_EOK);
1645 }
1647 /**
1648 * \brief Soft mute function control
1649 *
1650 * The Soft mute function allows mute/unmute of DAC output in gradual steps.
1651 * This configuration reduces pop and zipper noise during muting of the
1652 * DAC output.
1653 *
1654 * \param devId [IN] Device ID of DAC HW instance
1655 * Use 'DAC_DEVICE_ALL' to apply the configuration
1656 * for all the DAC devices available.
1657 *
1658 * \param chanId [IN] Internal DAC channel Id
1659 * Use DAC_CHAN_1 to DAC_CHAN_8 for individual
1660 * DAC channel configuration
1661 * Use DAC_CHAN_ALL to mute/unmute all DAC
1662 * channels
1663 *
1664 * \param muteEnable [IN] Mute enable flag
1665 * 0 for unmute and 1 for mute
1666 *
1667 * \return Platform_EOK on Success or error code
1668 */
1669 Platform_STATUS platformAudioDacSoftMuteCtrl(DacDevId devId,
1670 DacChanId chanId,
1671 uint8_t muteEnable)
1672 {
1673 DAC_RET retVal;
1674 Uint8 chan;
1675 Uint8 id;
1677 IFPRINT(platform_write("platformAudioDacSoftMuteCtrl Called \n"));
1679 /* Check input parameters */
1680 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1681 ((chanId >= DAC_CHAN_1) && (chanId <= DAC_CHAN_ALL)) &&
1682 ((muteEnable == 0) || (muteEnable == 1)) ) )
1683 {
1684 IFPRINT(platform_write("platformAudioDacSoftMuteCtrl : Invalid Inputs\n"));
1685 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1686 return (Platform_EINVALID);
1687 }
1689 if(chanId == DAC_CHAN_ALL)
1690 {
1691 chan = 0xFF;
1692 }
1693 else
1694 {
1695 chan = (1 << chanId);
1696 }
1698 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1699 {
1700 if((id == devId) || (devId == DAC_DEVICE_ALL))
1701 {
1702 retVal = pcm169xSoftMuteCtrl(gDacI2cAddr[id], chan, muteEnable);
1703 if(retVal)
1704 {
1705 IFPRINT(platform_write("platformAudioDacSoftMuteCtrl : DAC Access for Soft Mute Config Failed \n"));
1706 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1707 return (Platform_EFAIL);
1708 }
1709 }
1710 }
1712 return (Platform_EOK);
1713 }
1715 /**
1716 * \brief Sets attenuation mode
1717 *
1718 * DAC module supports two types of volume/attenuation dB range
1719 * which can be changed by setting attenuation mode. Volume range and fine
1720 * tuning will change based on the attenuation mode.
1721 *
1722 * \param devId [IN] Device ID of DAC HW instance
1723 * Use 'DAC_DEVICE_ALL' to apply the configuration
1724 * for all the DAC devices available.
1725 *
1726 * \param attnMode [IN] Attenuation mode
1727 *
1728 * \return Platform_EOK on Success or error code
1729 */
1730 Platform_STATUS platformAudioDacSetAttnMode(DacDevId devId,
1731 DacAttnMode attnMode)
1732 {
1733 DAC_RET retVal;
1734 Uint8 id;
1736 IFPRINT(platform_write("platformAudioDacSetAttnMode Called \n"));
1738 /* Check input parameters */
1739 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1740 ((attnMode >= DAC_ATTENUATION_FINE_STEP) &&
1741 (attnMode <= DAC_ATTENUATION_WIDE_RANGE)) ) )
1742 {
1743 IFPRINT(platform_write("platformAudioDacSetAttnMode : Invalid Inputs\n"));
1744 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1745 return (Platform_EINVALID);
1746 }
1748 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1749 {
1750 if((id == devId) || (devId == DAC_DEVICE_ALL))
1751 {
1752 retVal = pcm169xSetAttnMode(gDacI2cAddr[id], (Uint8)attnMode);
1753 if(retVal)
1754 {
1755 IFPRINT(platform_write("platformAudioDacSetAttnMode : DAC Access for Attenuation Mode Config Failed \n"));
1756 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1757 return (Platform_EFAIL);
1758 }
1759 }
1760 }
1762 return (Platform_EOK);
1763 }
1765 /**
1766 * \brief Function to control digital de-emphasis functionality
1767 *
1768 * Disables/Enables the various sampling frequencies of the digital
1769 * de-emphasis function.
1770 *
1771 * \param devId [IN] Device ID of DAC HW instance
1772 * Use 'DAC_DEVICE_ALL' to apply the configuration
1773 * for all the DAC devices available.
1774 *
1775 * \param deempCtrl [IN] De-emphasis control options
1776 *
1777 * \return Platform_EOK on Success or error code
1778 */
1779 Platform_STATUS platformAudioDacDeempCtrl(DacDevId devId,
1780 DacDeempCtrl deempCtrl)
1781 {
1782 DAC_RET retVal;
1783 Uint8 id;
1785 IFPRINT(platform_write("platformAudioDacDeempCtrl Called \n"));
1787 /* Check input parameters */
1788 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1789 ((deempCtrl >= DAC_DEEMP_DISABLE) &&
1790 (deempCtrl <= DAC_DEEMP_32KHZ)) ) )
1791 {
1792 IFPRINT(platform_write("platformAudioDacDeempCtrl : Invalid Inputs\n"));
1793 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1794 return (Platform_EINVALID);
1795 }
1797 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1798 {
1799 if((id == devId) || (devId == DAC_DEVICE_ALL))
1800 {
1801 retVal = pcm169xDeempCtrl(gDacI2cAddr[id], (Uint8)deempCtrl);
1802 if(retVal)
1803 {
1804 IFPRINT(platform_write("platformAudioDacDeempCtrl : DAC Access for De-emphasis Config Failed \n"));
1805 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1806 return (Platform_EFAIL);
1807 }
1808 }
1809 }
1811 return (Platform_EOK);
1812 }
1814 /**
1815 * \brief Configures DAC volume/attenuation
1816 *
1817 * Range of the volume is exposed as percentage by this API. Volume
1818 * is indicated as percentage of maximum value ranging from 0 to 100.
1819 * 0 to mute the volume and 100 to set maximum volume
1820 *
1821 * DAC module supports two types of volume/attenuation dB range
1822 * which can be changed using platformAudioDacSetAttnMode().
1823 * Volume range and fine tuning will change based on the attenuation mode.
1824 *
1825 * \param devId [IN] Device ID of DAC HW instance
1826 * Use 'DAC_DEVICE_ALL' to apply the configuration
1827 * for all the DAC devices available.
1828 *
1829 * \param chanId [IN] Internal DAC channel Id
1830 * Use DAC_CHAN_1 to DAC_CHAN_8 for individual
1831 * DAC channel configuration
1832 * Use DAC_CHAN_ALL to mute/unmute all DAC
1833 * channels
1834 *
1835 * \param volume [IN] Volume in percentage; 0 to 100
1836 *
1837 * \return Platform_EOK on Success or error code
1838 */
1839 Platform_STATUS platformAudioDacSetVolume(DacDevId devId,
1840 DacChanId chanId,
1841 uint8_t volume)
1842 {
1843 DAC_RET retVal;
1844 Uint8 id;
1845 Uint8 chan;
1847 IFPRINT(platform_write("platformAudioDacSetVolume Called \n"));
1849 /* Check input parameters */
1850 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1851 ((chanId >= DAC_CHAN_1) && (chanId <= DAC_CHAN_ALL)) &&
1852 (volume <= 100) ) )
1853 {
1854 IFPRINT(platform_write("platformAudioDacSetVolume : Invalid Inputs\n"));
1855 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1856 return (Platform_EINVALID);
1857 }
1859 if(chanId == DAC_CHAN_ALL)
1860 {
1861 chan = 0xF;
1862 }
1863 else
1864 {
1865 chan = chanId;
1866 }
1868 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1869 {
1870 if((id == devId) || (devId == DAC_DEVICE_ALL))
1871 {
1872 retVal = pcm169xSetVolume(gDacI2cAddr[id], (Uint8)volume, chan);
1873 if(retVal)
1874 {
1875 IFPRINT(platform_write("platformAudioDacSetVolume : DAC Access for Volume Config Failed \n"));
1876 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1877 return (Platform_EFAIL);
1878 }
1879 }
1880 }
1882 return (Platform_EOK);
1883 }
1885 /**
1886 * \brief Configures DAC power-save mode
1887 *
1888 * \param devId [IN] Device ID of DAC HW instance
1889 * Use 'DAC_DEVICE_ALL' to apply the configuration
1890 * for all the DAC devices available.
1891 *
1892 * \param PowerMode [IN] Power-save mode control
1893 * 0 - Enable power-save mode
1894 * 1 - Disable power-save mode
1895 *
1896 * \return Platform_EOK on Success or error code
1897 */
1898 Platform_STATUS platformAudioDacSetPowerMode(DacDevId devId,
1899 uint8_t PowerMode)
1900 {
1901 DAC_RET retVal;
1902 Uint8 id;
1904 IFPRINT(platform_write("platformAudioDacSetPowerMode Called \n"));
1906 /* Check input parameters */
1907 if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1908 ((PowerMode == 0) || (PowerMode == 1)) ) )
1909 {
1910 IFPRINT(platform_write("platformAudioDacSetPowerMode : Invalid Inputs\n"));
1911 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1912 return (Platform_EINVALID);
1913 }
1915 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1916 {
1917 if((id == devId) || (devId == DAC_DEVICE_ALL))
1918 {
1919 retVal = pcm169xSetPowerMode(gDacI2cAddr[id], PowerMode);
1920 if(retVal)
1921 {
1922 IFPRINT(platform_write("platformAudioDacSetPowerMode : DAC Access for Power-save Mode Config Failed \n"));
1923 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1924 return (Platform_EFAIL);
1925 }
1926 }
1927 }
1929 return (Platform_EOK);
1930 }
1932 /**
1933 * \brief Displays DAC register programmed values
1934 *
1935 * This function is provided for debug purpose to read the value
1936 * of DAC registers. Values read from the DAC registers will be displayed
1937 * in CCS output window or serial terminal based on the system level
1938 * configuration for debug messages.
1939 *
1940 * \param devId [IN] Device ID of DAC HW instance
1941 * Use 'DAC_DEVICE_ALL' to apply the configuration
1942 * for all the DAC devices available.
1943 *
1944 * \return Platform_EOK on Success or error code
1945 */
1946 Platform_STATUS platformAudioDacGetRegDump(DacDevId devId)
1947 {
1948 DAC_RET retVal;
1949 Uint8 id;
1951 IFPRINT(platform_write("platformAudioDacGetRegDump Called \n"));
1953 if(!((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)))
1954 {
1955 IFPRINT(platform_write("platformAudioDacGetRegDump : Invalid Inputs\n"));
1956 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1957 return (Platform_EINVALID);
1958 }
1960 for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1961 {
1962 if((id == devId) || (devId == DAC_DEVICE_ALL))
1963 {
1964 retVal = pcm169xRegDump(gDacI2cAddr[id]);
1965 if(retVal)
1966 {
1967 IFPRINT(platform_write("platformAudioDacGetRegDump : DAC Access for Reg Dump Failed \n"));
1968 platform_errno = PLATFORM_ERRNO_AUDIO_STATUS;
1969 return (Platform_EFAIL);
1970 }
1971 }
1972 }
1974 return (Platform_EOK);
1975 }
1976 #endif /* #if (PLATFORM_AUDIO_DAC) */
1979 #if (PLATFORM_AUDIO_DIR)
1981 /**
1982 * \brief Initializes DIR module
1983 *
1984 * Configures GPIOs and other settings required for DIR module operation.
1985 * This function should be called before calling any other DIR functions.
1986 *
1987 * \return Platform_EOK on Success or error code
1988 *
1989 */
1990 Platform_STATUS platformAudioDirInit(void)
1991 {
1992 IFPRINT(platform_write("platformAudioDirInit Called \n"));
1994 /* Configure each SOC_GPIO pin connected to DIR status lines
1995 as GPIO and input */
1997 /* DIR RST signal - GPIO 1, pin 9 */
1998 pinMuxSetMode(PLATFORM_AUDIO_DIR_RST_PADCFG,
1999 PADCONFIG_MUX_MODE_QUATERNARY);
2000 gpioSetDirection(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO, GPIO_OUT);
2001 gpioSetOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
2003 /* DIR AUDIO signal - GPIO 0, pin 134 */
2004 pinMuxSetMode(PLATFORM_AUDIO_DIR_AUDIO_PADCFG,
2005 PADCONFIG_MUX_MODE_QUATERNARY);
2006 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_AUDIO_GPIO, GPIO_IN);
2008 /* DIR EMPH signal - GPIO 0, pin 135 */
2009 pinMuxSetMode(PLATFORM_AUDIO_DIR_EMPH_PADCFG,
2010 PADCONFIG_MUX_MODE_QUATERNARY);
2011 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_EMPH_GPIO, GPIO_IN);
2013 /* DIR ERROR signal - GPIO 0, pin 136 */
2014 pinMuxSetMode(PLATFORM_AUDIO_DIR_ERR_PADCFG,
2015 PADCONFIG_MUX_MODE_QUATERNARY);
2016 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_ERR_GPIO, GPIO_IN);
2018 /* DIR CLKST signal - GPIO 0, pin 133 */
2019 pinMuxSetMode(PLATFORM_AUDIO_DIR_CLKST_PADCFG,
2020 PADCONFIG_MUX_MODE_QUATERNARY);
2021 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_CLKST_GPIO, GPIO_IN);
2023 /* DIR FSOUT0 signal - GPIO 0, pin 124 */
2024 pinMuxSetMode(PLATFORM_AUDIO_DIR_FSOUT0_PADCFG,
2025 PADCONFIG_MUX_MODE_QUATERNARY);
2026 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_FSOUT0_GPIO, GPIO_IN);
2028 /* DIR FSOUT1 signal - GPIO 0, pin 15 */
2029 pinMuxSetMode(PLATFORM_AUDIO_DIR_FSOUT1_PADCFG,
2030 PADCONFIG_MUX_MODE_QUATERNARY);
2031 gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_FSOUT1_GPIO, GPIO_IN);
2033 #if 0
2034 /* Reset DIR */
2035 gpioClearOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
2036 /* DIR Reset signal should be low for at least 100 ns.
2037 Adding a delay of 1usec */
2038 platform_delay(1);
2039 gpioSetOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
2040 #endif
2042 return (Platform_EOK);
2043 }
2045 /**
2046 * \brief Resets DIR module
2047 *
2048 * \return Platform_EOK on Success or error code
2049 *
2050 */
2051 Platform_STATUS platformAudioDirReset(void)
2052 {
2053 IFPRINT(platform_write("platformAudioDirReset Called \n"));
2055 gpioClearOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
2056 /* DIR Reset signal should be low for at least 100 ns.
2057 Adding a delay of 1usec */
2058 platform_delay(1);
2059 gpioSetOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
2061 return(Platform_EOK);
2062 }
2064 /**
2065 * \brief Reads AUDIO output status value of the DIR
2066 *
2067 * DIR AUDIO output pin gives the audio sample word information
2068 * of the channel-status data bit 1
2069 *
2070 * \return AUDIO pin output with below possible values
2071 * \n 0 - Audio sample word represents linear PCM samples
2072 * \n 1 - Audio sample word is used for other purposes
2073 */
2074 int8_t platformAudioDirGetAudioStatus(void)
2075 {
2076 int8_t audio;
2078 IFPRINT(platform_write("platformAudioDirGetAudioStatus Called \n"));
2080 audio = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_AUDIO_GPIO);
2082 return(audio);
2083 }
2085 /**
2086 * \brief Reads EMPH output status value of the DIR
2087 *
2088 * DIR EMPH output pin gives the emphasis information of the
2089 * channel-status data bit 3.
2090 *
2091 * \return EMPH pin output with below possible values
2092 * \n 0 - Two audio channels without pre-emphasis
2093 * \n 1 - Two audio channels with 50 ms / 15 ms pre-emphasis
2094 */
2095 int8_t platformAudioDirGetEmphStatus(void)
2096 {
2097 int8_t emph;
2099 IFPRINT(platform_write("platformAudioDirGetEmphStatus Called \n"));
2101 emph = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_EMPH_GPIO);
2103 return(emph);
2104 }
2106 /**
2107 * \brief Reads ERROR pin status value of the DIR
2108 *
2109 * DIR ERROR output pin gives the error state of data and parity errors.
2110 *
2111 * \return EMPH pin output with below possible values
2112 * \n 0 - Lock state of PLL and nondetection of parity error
2113 * \n 1 - Unlock state of PLL or detection of parity error
2114 */
2115 int8_t platformAudioDirGetErrStatus(void)
2116 {
2117 int8_t err;
2119 IFPRINT(platform_write("platformAudioDirGetErrStatus Called \n"));
2121 err = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_ERR_GPIO);
2123 return(err);
2124 }
2126 /**
2127 * \brief Reads CLKST pin status value of the DIR
2128 *
2129 * DIR CLKST pin outputs the PLL status change between LOCK and UNLOCK.
2130 * The CLKST output pulse depends only on the status change of the PLL.
2131 *
2132 * \return EMPH pin output with below possible values
2133 * \n 0 - Lock state of PLL and nondetection of parity error
2134 * \n 1 - Unlock state of PLL or detection of parity error
2135 */
2136 int8_t platformAudioDirGetClkStatus(void)
2137 {
2138 int8_t clk;
2140 IFPRINT(platform_write("platformAudioDirGetClkStatus Called \n"));
2142 clk = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_CLKST_GPIO);
2144 return(clk);
2145 }
2147 /**
2148 * \brief Reads FSOUT[1:0] output status value of the DIR
2149 *
2150 * The DIR module calculates the actual sampling frequency of the
2151 * biphase input signal and outputs its result through FSOUT[1:0] pins.
2152 *
2153 * \return FSOUT pin output with below possible values
2154 * \n 0 - Calculated Sampling Frequency Output is 43 kHz\9645.2 kHz
2155 * \n 1 - Calculated Sampling Frequency Output is 46.8 kHz\9649.2 kHz
2156 * \n 2 - Out of range or PLL unlocked
2157 * \n 3 - Calculated Sampling Frequency Output is 31.2 kHz\9632.8 kHz
2158 */
2159 int8_t platformAudioDirGetFsOut(void)
2160 {
2161 int8_t fsout;
2163 IFPRINT(platform_write("platformAudioDirGetFsOut Called \n"));
2165 fsout = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_FSOUT1_GPIO);
2166 fsout <<= 1;
2167 fsout |= gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_FSOUT0_GPIO);
2169 return(fsout);
2170 }
2172 #endif /* #if (PLATFORM_AUDIO_DIR) */
2174 #endif /* #if (PLATFORM_AUDIO) */
2176 /* Nothing past this point */