]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pdk_k2g_1_0_1/packages/ti/platform/evmk2g/platform_lib/src/platform_audio.c
Merge remote-tracking branch 'origin/dev_psdkaudio_qin_astsplit' into dev_psdkaudio_frank
[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 McASP_CLK_SEL# - GPIO0 101 & PADCONFIG 110 */
149         pinMuxSetMode(114, PADCONFIG_MUX_MODE_QUATERNARY);
150         gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_HSR_HMINTz_GPIO, GPIO_IN);
152         /* Configure McASP AUXCLK source as AUDIO_OSCCLK  */
153         hBootCfg->SERIALPORT_CLKCTL = 0;
154         hBootCfg->OSC_CTL = 0x200;      //SW2:SW1 = 01 (15 - 30 MHz)
156     return (Platform_EOK);
159 /**
160  *  \brief    Resets audio DAC
161  *
162  *  This function toggles the GPIO signal connected to RST pin
163  *  of DAC module to generate DAC reset.
164  *
165  *  \return    Platform_EOK on Success or error code
166  */
167 Platform_STATUS platformAudioResetDac(void)
169         gpioClearOutput(GPIO_PORT_1, PLATFORM_AUDIO_PCM1690_RST_GPIO);
170         platform_delay(1000);
171         gpioSetOutput(GPIO_PORT_1, PLATFORM_AUDIO_PCM1690_RST_GPIO);
173         /* Configure McASP AUXCLK source as AUDIO_OSCCLK  */
174         hBootCfg->SERIALPORT_CLKCTL = 0;
176     return (Platform_EOK);
179 /**
180  *  \brief    Configures audio clock source
181  *
182  *  McASP can receive clock from DIR module on daughter card or external
183  *  I2S device to operate DAC and ADC modules. This function configures
184  *  which clock source to use (DIR or I2S) for DAC and ADC operation
185  *
186  *  \param clkSrc    [IN]  Clock source selection
187  *
188  *  \return    Platform_EOK on Success or error code
189  */
190 Platform_STATUS platformAudioSelectClkSrc(AudioClkSrc clkSrc)
192         IFPRINT(platform_write("platformAudioSelectClkSrc Called \n"));
194         /* Configure GPIO for McASP_CLK_SEL - GPIO0 132 & PADCONFIG 163 */
195         pinMuxSetMode(163, PADCONFIG_MUX_MODE_QUATERNARY);
196         gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO, GPIO_OUT);
198         /* Configure GPIO for McASP_CLK_SEL# - GPIO0 101 & PADCONFIG 110 */
199         pinMuxSetMode(110, PADCONFIG_MUX_MODE_QUATERNARY);
200         gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO, GPIO_OUT);
202         if(clkSrc == AUDIO_CLK_SRC_DIR)
203         {
204                 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO);
205                 gpioClearOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);
206         }
207         else if(clkSrc == AUDIO_CLK_SRC_I2S)
208         {
209                 gpioClearOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO);
210                 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);
211         }
212         else if(clkSrc == AUDIO_CLK_SRC_OSC)
213         {
214                 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SEL_GPIO);
215                 gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);
216         }
217         else
218         {
219                 IFPRINT(platform_write("platformAudioSelectClkSrc : Invalid Inputs\n"));
220                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
221                 return (Platform_EINVALID);
222         }
224         return (Platform_EOK);
227 #if (PLATFORM_AUDIO_ADC)
229 /**
230  *  \brief    Initializes ADC module
231  *
232  *  This function configures the system level setup required for ADC
233  *  operation and initializes the ADC module with default values.
234  *  This function should be called before calling any other ADC functions.
235  *
236  *  After executing this function, ADC module will be ready for audio
237  *  processing with default configuration. Default ADC configurations
238  *  can be changed using the other ADC APIs if required.
239  *
240  *  \param devId    [IN]  Device ID of ADC HW instance
241  *                        Use 'ADC_DEVICE_ALL' to initialize
242  *                        all the ADC devices available.
243  *
244  *  \return    Platform_EOK on Success or error code
245  */
246 Platform_STATUS platformAudioAdcInit(AdcDevId devId)
248         ADC_RET  retVal;
249         Uint8    id;
251         IFPRINT(platform_write("platformAudioAdcInit Called \n"));
253         if(!((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)))
254         {
255                 IFPRINT(platform_write("platformAudioAdcInit : Invalid Inputs\n"));
256                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
257                 return (Platform_EINVALID);
258         }
260         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
261         {
262                 if((id == devId) || (devId == ADC_DEVICE_ALL))
263                 {
264                         retVal = pcm186xAdcInit(gAdcI2cAddr[id]);
265                         if(retVal)
266                         {
267                                 IFPRINT(platform_write("platformAudioAdcInit : ADC Initialization Failed \n"));
268                                 platform_errno = PLATFORM_ERRNO_AUDIO_INIT;
269                                 return (Platform_EFAIL);
270                         }
271                 }
272         }
274     return (Platform_EOK);
277 /**
278  *  \brief    Resets ADC module
279  *
280  *  This function resets all the ADC module registers to their
281  *  HW default values.
282  *
283  *  \param devId    [IN]  Device ID of ADC HW instance
284  *                        Use 'ADC_DEVICE_ALL' to reset
285  *                        all the ADC devices available.
286  *
287  *  \return    Platform_EOK on Success or error code
288  */
289 Platform_STATUS platformAudioAdcReset(AdcDevId devId)
291         ADC_RET  retVal;
292         Uint8    id;
294         IFPRINT(platform_write("platformAudioAdcReset Called \n"));
296         if(!((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)))
297         {
298                 IFPRINT(platform_write("platformAudioAdcReset : Invalid Inputs\n"));
299                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
300                 return (Platform_EINVALID);
301         }
303         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
304         {
305                 if((id == devId) || (devId == ADC_DEVICE_ALL))
306                 {
307                         retVal = pcm186xReset(gAdcI2cAddr[id]);
308                         if(retVal)
309                         {
310                                 IFPRINT(platform_write("platformAudioAdcReset : ADC Reset Failed \n"));
311                                 platform_errno = PLATFORM_ERRNO_AUDIO;
312                                 return (Platform_EFAIL);
313                         }
314                 }
315         }
317     return (Platform_EOK);
320 /**
321  *  \brief    Configures ADC gain value
322  *
323  *  Range of the gain is exposed as percentage by this API. Gain
324  *  is indicated as percentage of maximum gain ranging from 0 to 100.
325  *  0 indicates minimum gain and 100 indicates maximum gain.
326  *
327  *  \param devId      [IN]  Device ID of ADC HW instance
328  *                          Use 'ADC_DEVICE_ALL' to apply the configuration
329  *                          for all the ADC devices available.
330  *
331  *  \param chanId     [IN]  Internal ADC channel Id
332  *                          Use ADC_CH_ALL to set gain for all the
333  *                          ADC channels
334  *
335  *  \param gain       [IN]  Gain value; 0 to 100
336  *
337  *  \return    Platform_EOK on Success or error code
338  */
339 Platform_STATUS platformAudioAdcSetGain(AdcDevId  devId,
340                                         AdcChanId chanId,
341                                         uint8_t   gain)
343         ADC_RET  retVal;
344         Uint8    id;
346         IFPRINT(platform_write("platformAudioAdcSetGain Called \n"));
348         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
349                ((chanId >= ADC_CH1_LEFT) && (chanId <= ADC_CH_ALL)) &&
350            (gain <= 100) ) )
351         {
352                 IFPRINT(platform_write("platformAudioAdcSetGain : Invalid Inputs\n"));
353                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
354                 return (Platform_EINVALID);
355         }
357         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
358         {
359                 if((id == devId) || (devId == ADC_DEVICE_ALL))
360                 {
361                         retVal = pcm186xSetVolume(gAdcI2cAddr[id], (Uint8)gain,
362                                                                          (Uint8)chanId);
363                         if(retVal)
364                         {
365                                 IFPRINT(platform_write("platformAudioAdcSetGain : ADC Access for Gain Config Failed \n"));
366                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
367                                 return (Platform_EFAIL);
368                         }
369                 }
370         }
372     return (Platform_EOK);
375 /**
376  *  \brief    Configures ADC analog input selection for left channel
377  *
378  *  Default input selection of ADC left channels can be modified using
379  *  this function.
380  *
381  *  Default input selection for ADC left channels is listed below
382  *    CH1 LEFT  - VINL1
383  *    CH2 LEFT  - VINL2
384  *
385  *  \param devId      [IN]  Device ID of ADC HW instance
386  *                          Use 'ADC_DEVICE_ALL' to apply the configuration
387  *                          for all the ADC devices available.
388  *
389  *  \param chanId     [IN]  Internal ADC channel Id
390  *                          ADC_CH1_LEFT - Input selection for channel 1 left
391  *                          ADC_CH2_LEFT - Input selection for channel 2 left
392  *                          ADC_CH_ALL - Input selection for channel 1 & 2 left
393  *
394  *  \param inputMux   [IN]  Input mux configuration
395  *
396  *  \return    Platform_EOK on Success or error code
397  */
398 Platform_STATUS platformAudioAdcSetLeftInputMux(AdcDevId        devId,
399                                                 AdcChanId       chanId,
400                                                 AdcLeftInputMux inputMux)
402         ADC_RET  retVal;
403         Uint8    id;
405         IFPRINT(platform_write("platformAudioAdcSetLeftInputMux Called \n"));
407         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
408                ((chanId == ADC_CH1_LEFT) || (chanId == ADC_CH2_LEFT) ||
409                 (chanId == ADC_CH_ALL)) &&
410            ((inputMux >= ADC_INL_NONE) &&
411                 (inputMux <= ADC_INL_DIFF_VIN1P_VIN1M_VIN4P_VIN4M)) ) )
412         {
413                 IFPRINT(platform_write("platformAudioAdcSetLeftInputMux : Invalid Inputs\n"));
414                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
415                 return (Platform_EINVALID);
416         }
418         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
419         {
420                 if((id == devId) || (devId == ADC_DEVICE_ALL))
421                 {
422                         if(chanId == ADC_CH_ALL)
423                         {
424                                 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)ADC_CH1_LEFT,
425                                                                                  (Uint8)inputMux);
426                                 if(retVal)
427                                 {
428                                         IFPRINT(platform_write("platformAudioAdcSetLeftInputMux : ADC Access for Input Selection Failed \n"));
429                                         platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
430                                         return (Platform_EFAIL);
431                                 }
433                                 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)ADC_CH2_LEFT,
434                                                                                  (Uint8)inputMux);
435                         }
436                         else
437                         {
438                                 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)chanId,
439                                                                                  (Uint8)inputMux);
440                         }
442                         if(retVal)
443                         {
444                                 IFPRINT(platform_write("platformAudioAdcSetLeftInputMux : ADC Access for Input Selection Failed \n"));
445                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
446                                 return (Platform_EFAIL);
447                         }
448                 }
449         }
451     return (Platform_EOK);
454 /**
455  *  \brief    Configures ADC analog input selection for right channel
456  *
457  *  Default input selection of ADC right channels can be modified using
458  *  this function
459  *
460  *  Default input selection for ADC right channels is shown below
461  *    CH1 RIGHT - VINR1
462  *    CH2_RIGHT - VINR2
463  *
464  *  \param devId      [IN]  Device ID of ADC HW instance
465  *                          Use 'ADC_DEVICE_ALL' to apply the configuration
466  *                          for all the ADC devices available.
467  *
468  *  \param chanId     [IN]  Internal ADC channel Id
469  *                         ADC_CH1_RIGHT - Input selection for channel 1 right
470  *                         ADC_CH2_RIGHT - Input selection for channel 2 right
471  *                         ADC_CH_ALL - Input selection for channel 1 & 2 right
472  *
473  *  \param inputMux   [IN]  Input mux configuration
474  *
475  *  \return    Platform_EOK on Success or error code
476  */
477 Platform_STATUS platformAudioAdcSetRightInputMux(AdcDevId         devId,
478                                                  AdcChanId        chanId,
479                                                  AdcRightInputMux inputMux)
481         ADC_RET  retVal;
482         Uint8    id;
484         IFPRINT(platform_write("platformAudioAdcSetRightInputMux Called \n"));
486         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
487                ((chanId == ADC_CH1_RIGHT) || (chanId == ADC_CH2_RIGHT) ||
488                 (chanId == ADC_CH_ALL)) &&
489            ((inputMux >= ADC_INR_NONE) &&
490                 (inputMux <= ADC_INR_DIFF_VIN2P_VIN2M_VIN3P_VIN3M)) ) )
491         {
492                 IFPRINT(platform_write("platformAudioAdcSetRightInputMux : Invalid Inputs\n"));
493                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
494                 return (Platform_EINVALID);
495         }
497         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
498         {
499                 if((id == devId) || (devId == ADC_DEVICE_ALL))
500                 {
501                         if(chanId == ADC_CH_ALL)
502                         {
503                                 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)ADC_CH1_RIGHT,
504                                                                                  (Uint8)inputMux);
505                                 if(retVal)
506                                 {
507                                         IFPRINT(platform_write("platformAudioAdcSetRightInputMux : ADC Access for Input Selection Failed \n"));
508                                         platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
509                                         return (Platform_EFAIL);
510                                 }
512                                 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)ADC_CH2_RIGHT,
513                                                                                  (Uint8)inputMux);
514                         }
515                         else
516                         {
517                                 retVal = pcm186xInputSel(gAdcI2cAddr[id], (Uint8)chanId,
518                                                                                  (Uint8)inputMux);
519                         }
521                         if(retVal)
522                         {
523                                 IFPRINT(platform_write("platformAudioAdcSetRightInputMux : ADC Access for Input Selection Failed \n"));
524                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
525                                 return (Platform_EFAIL);
526                         }
527                 }
528         }
530     return (Platform_EOK);
533 /**
534  *  \brief    ADC audio interface data configuration
535  *
536  *  This function configures serial audio interface data format and
537  *  receive PCM word length for ADC
538  *
539  *  \param devId      [IN]  Device ID of ADC HW instance
540  *                          Use 'ADC_DEVICE_ALL' to apply the configuration
541  *                          for all the ADC devices available.
542  *
543  *  \param wLen       [IN]  ADC data word length
544  *
545  *  \param format     [IN]  Audio data format
546  *
547  *  \return    Platform_EOK on Success or error code
548  */
549 Platform_STATUS platformAudioAdcDataConfig(AdcDevId      devId,
550                                            AdcRxWordLen  wLen,
551                                            AdcDataFormat format)
553         ADC_RET  retVal;
554         Uint8    id;
556         IFPRINT(platform_write("platformAudioAdcDataConfig Called \n"));
558         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
559                ((wLen >= ADC_RX_WLEN_24BIT) && (wLen <= ADC_RX_WLEN_16BIT)) &&
560            ((format >= ADC_DATA_FORMAT_I2S) &&
561                 (format <= ADC_DATA_FORMAT_TDM_DSP)) ) )
562         {
563                 IFPRINT(platform_write("platformAudioAdcDataConfig : Invalid Inputs\n"));
564                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
565                 return (Platform_EINVALID);
566         }
568         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
569         {
570                 if((id == devId) || (devId == ADC_DEVICE_ALL))
571                 {
572                         retVal = pcm186xDataConfig(gAdcI2cAddr[id], (Uint8)format,
573                                                    (Uint8)wLen);
574                         if(retVal)
575                         {
576                                 IFPRINT(platform_write("platformAudioAdcDataConfig : ADC Access for Data Config Failed \n"));
577                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
578                                 return (Platform_EFAIL);
579                         }
580                 }
581         }
583     return (Platform_EOK);
586 /**
587  *  \brief    Enables/Disables ADC channel mute
588  *
589  *  This function configures mute functionality of each ADC channel
590  *
591  *  \param devId      [IN]  Device ID of ADC HW instance
592  *                          Use 'ADC_DEVICE_ALL' to apply the configuration
593  *                          for all the ADC devices available.
594  *
595  *  \param chanId     [IN]  Internal ADC channel Id
596  *                          Use ADC_CH_ALL to apply mute configuration for
597  *                          all the ADC channels
598  *
599  *  \param muteEnable [IN]  Flag to configure mute
600  *                          1 - Mute ADC channel
601  *                          0 - Unmute ADC channel
602  *
603  *  \return    Platform_EOK on Success or error code
604  */
605 Platform_STATUS platformAudioAdcMuteCtrl(AdcDevId  devId,
606                                          AdcChanId chanId,
607                                          uint8_t   muteEnable)
609         ADC_RET  retVal;
610         Uint8    chan;
611         Uint8    id;
613         IFPRINT(platform_write("platformAudioAdcMuteCtrl Called \n"));
615         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
616                ((chanId >= ADC_CH1_LEFT) && (chanId <= ADC_CH_ALL)) &&
617            ((muteEnable == 0) || (muteEnable == 1)) ) )
618         {
619                 IFPRINT(platform_write("platformAudioAdcMuteCtrl : Invalid Inputs\n"));
620                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
621                 return (Platform_EINVALID);
622         }
624         if(chanId == ADC_CH_ALL)
625         {
626                 chan = 0xF;
627         }
628         else
629         {
630                 chan = (1 << chanId);
631         }
633         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
634         {
635                 if((id == devId) || (devId == ADC_DEVICE_ALL))
636                 {
637                         retVal = pcm186xMuteChannel(gAdcI2cAddr[id], chan,
638                                                    (Uint8)muteEnable);
639                         if(retVal)
640                         {
641                                 IFPRINT(platform_write("platformAudioAdcMuteCtrl : ADC Access for Mute Config Failed \n"));
642                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
643                                 return (Platform_EFAIL);
644                         }
645                 }
646         }
648     return (Platform_EOK);
651 /**
652  *  \brief    Configures ADC MIC bias
653  *
654  *  This function enables/disables MIC bias for analog MIC input
655  *
656  *  \param devId         [IN]  Device ID of ADC HW instance
657  *                             Use 'ADC_DEVICE_ALL' to apply the configuration
658  *                             for all the ADC devices available.
659  *
660  *  \param micBiasEnable [IN]  Mic Bias enable flag
661  *                             1 - Enable MIC Bias
662  *                             0 - Disable MIC Bias
663  *
664  *  \return    Platform_EOK on Success or error code
665  */
666 Platform_STATUS platformAudioAdcMicBiasCtrl(AdcDevId devId,
667                                             uint8_t  micBiasEnable)
669         ADC_RET  retVal;
670         Uint8    id;
672         IFPRINT(platform_write("platformAudioAdcMicBiasCtrl Called \n"));
674         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
675            ((micBiasEnable == 0) || (micBiasEnable == 1)) ) )
676         {
677                 IFPRINT(platform_write("platformAudioAdcMicBiasCtrl : Invalid Inputs\n"));
678                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
679                 return (Platform_EINVALID);
680         }
682         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
683         {
684                 if((id == devId) || (devId == ADC_DEVICE_ALL))
685                 {
686                         retVal = pcm186xMicBiasCtrl(gAdcI2cAddr[id], (Uint8)micBiasEnable);
687                         if(retVal)
688                         {
689                                 IFPRINT(platform_write("platformAudioAdcMicBiasCtrl : ADC Access for Mic Bias Config Failed \n"));
690                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
691                                 return (Platform_EFAIL);
692                         }
693                 }
694         }
696     return (Platform_EOK);
699 /**
700  *  \brief    Configures ADC power state
701  *
702  *  This function enables/disables different power modes supported by ADC
703  *
704  *  \param devId       [IN]  Device ID of ADC HW instance
705  *                           Use 'ADC_DEVICE_ALL' to apply the configuration
706  *                           for all the ADC devices available.
707  *
708  *  \param powState    [IN]  ADC power state to configure
709  *
710  *  \param stateEnable [IN]  Power state enable flag
711  *                           1 - Enables the power state
712  *                           0 - Disables the power state
713  *
714  *  \return    Platform_EOK on Success or error code
715  */
716 Platform_STATUS platformAudioAdcConfigPowState(AdcDevId      devId,
717                                                AdcPowerState powState,
718                                                uint8_t       stateEnable)
720         ADC_RET  retVal;
721         Uint8    id;
723         IFPRINT(platform_write("platformAudioAdcConfigPowState Called \n"));
725         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
726                ((powState >= ADC_POWER_STATE_STANDBY) &&
727                 (powState <= ADC_POWER_STATE_POWERDOWN)) &&
728            ((stateEnable == 0) || (stateEnable == 1)) ) )
729         {
730                 IFPRINT(platform_write("platformAudioAdcConfigPowState : Invalid Inputs\n"));
731                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
732                 return (Platform_EINVALID);
733         }
735         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
736         {
737                 if((id == devId) || (devId == ADC_DEVICE_ALL))
738                 {
739                         retVal = pcm186xConfigPowState(gAdcI2cAddr[id], (Uint8)powState,
740                                                        (Uint8)stateEnable);
741                         if(retVal)
742                         {
743                                 IFPRINT(platform_write("platformAudioAdcConfigPowState : ADC Access for Power State Config Failed \n"));
744                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
745                                 return (Platform_EFAIL);
746                         }
747                 }
748         }
750     return (Platform_EOK);
753 /**
754  *  \brief    Configures ADC interrupts
755  *
756  *  This function enables/disables different interrupts supported by ADC
757  *
758  *  \param devId       [IN]  Device ID of ADC HW instance
759  *                           Use 'ADC_DEVICE_ALL' to apply the configuration
760  *                           for all the ADC devices available.
761  *
762  *  \param intId       [IN]  Interrupt Id to configure
763  *                           Use to 'ADC_INTR_ALL' to configure all the
764  *                           interrupts together
765  *
766  *  \param intEnable   [IN]  Interrupt enable flag
767  *                           1 - Enables the interrupt
768  *                           0 - Disables the interrupt
769  *
770  *  \return    Platform_EOK on Success or error code
771  */
772 Platform_STATUS platformAudioAdcConfigIntr(AdcDevId devId,
773                                            AdcIntr  intId,
774                                            uint8_t  intEnable)
776         ADC_RET  retVal;
777         Uint8    id;
779         IFPRINT(platform_write("platformAudioAdcConfigIntr Called \n"));
781         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
782                ((intId >= ADC_INTR_ENERGY_SENSE) && (intId <= ADC_INTR_ALL)) &&
783            ((intEnable == 0) || (intEnable == 1)) ) )
784         {
785                 IFPRINT(platform_write("platformAudioAdcConfigIntr : Invalid Inputs\n"));
786                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
787                 return (Platform_EINVALID);
788         }
790         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
791         {
792                 if((id == devId) || (devId == ADC_DEVICE_ALL))
793                 {
794                         retVal = pcm186xSetIntr(gAdcI2cAddr[id], (Uint8)intId,
795                                                 (Uint8)intEnable);
796                         if(retVal)
797                         {
798                                 IFPRINT(platform_write("platformAudioAdcConfigIntr : ADC Access for Intr Config Failed \n"));
799                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
800                                 return (Platform_EFAIL);
801                         }
802                 }
803         }
805     return (Platform_EOK);
808 /**
809  *  \brief    Reads ADC interrupt status
810  *
811  *  This function reads the status of different interrupts supported by ADC
812  *
813  *  \param devId       [IN]  Device ID of ADC HW instance
814  *
815  *  \param intId       [IN]  Interrupt Id to read the status
816  *                           Use to 'ADC_INTR_ALL' to read status of all the
817  *                           interrupts together
818  *
819  *  \return    Interrupt status
820  *             1 - Interrupt occurred
821  *             0 - No interrupt occurred
822  *          0xFF - Error in reading interrupt
823  */
824 uint8_t platformAudioAdcGetIntrStatus(AdcDevId devId,
825                                       AdcIntr  intId)
827         Uint8  retVal;
829         IFPRINT(platform_write("platformAudioAdcGetIntrStatus Called \n"));
831         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_1)) &&
832                ((intId >= ADC_INTR_ENERGY_SENSE) && (intId <= ADC_INTR_ALL)) ) )
833         {
834                 IFPRINT(platform_write("platformAudioAdcGetIntrStatus : Invalid Inputs\n"));
835                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
836                 return (1);
837         }
839         retVal = pcm186xGetIntrStatus(gAdcI2cAddr[devId]);
840         if(retVal == 0xFF)
841         {
842                 IFPRINT(platform_write("platformAudioAdcGetIntrStatus : ADC Access for Intr Status Failed \n"));
843                 platform_errno = PLATFORM_ERRNO_AUDIO_STATUS;
844                 return ((uint8_t)retVal);
845         }
847         if(intId != ADC_INTR_ALL)
848         {
849                 retVal = (retVal >> intId) & 0x1;
850         }
852     return (retVal);
855 /**
856  *  \brief    Reads ADC status bits
857  *
858  *  This function reads the value of different status functions supported
859  *  by ADC module (excluding interrupts).
860  *
861  *  \param devId       [IN]  Device ID of ADC HW instance
862  *
863  *  \param status      [IN]  Status function of which status to be read
864  *
865  *  \return    Value of status function or 0xFF in case of error
866  *
867  */
868 uint8_t platformAudioAdcGetStatus(AdcDevId  devId,
869                                   AdcStatus status)
871         Uint8  retVal;
873         IFPRINT(platform_write("platformAudioAdcGetStatus Called \n"));
875         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_1)) &&
876                ((status >= ADC_STATUS_POWER_STATE) &&
877                 (status <= ADC_STATUS_LDO)) ) )
878         {
879                 IFPRINT(platform_write("platformAudioAdcGetStatus : Invalid Inputs\n"));
880                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
881                 return (1);
882         }
884         switch(status)
885         {
886                 /* Current Power State of the device
887                  *        0x0 - Power Down
888                  *        0x1 - Wait clock stable
889                  *        0x2 - Release reset
890                  *        0x3 - Stand-by
891                  *        0x4 - Fade IN
892                  *        0x5 - Fade OUT
893                  *        0x9 - Sleep
894          *        0xF - Run
895                  */
896                 case ADC_STATUS_POWER_STATE:
897                         retVal = pcm186xGetPowerStateStatus(gAdcI2cAddr[devId]);
898                         break;
900                 /* Current Sampling Frequency
901                  *       0x0 - Out of range (Low) or LRCK Halt
902                  *       0x1 - 8kHz
903                  *       0x2 - 16kHz
904                  *       0x3 - 32-48kHz
905                  *       0x4 - 88.2-96kHz
906                  *       0x5 - 176.4-192kHz
907                  *       0x6 - Out of range (High)
908          *       0x7 - Invalid Fs
909                  */
910                 case ADC_STATUS_SAMPLING_FREQ:
911                         retVal = pcm186xGetSampleFreqStatus(gAdcI2cAddr[devId]);
912                         break;
914                 /* Current receiving BCK ratio
915                  *        0x0 - Out of range (L) or BCK Halt
916                  *        0x1 - 32
917                  *        0x2 - 48
918                  *        0x3 - 64
919                  *        0x4 - 256
920                  *        0x6 - Out of range (High)
921          *        0x7 - Invalid BCK ratio or LRCK Halt
922                  */
923                 case ADC_STATUS_BCK_RATIO:
924                         retVal = pcm186xGetBckRatioStatus(gAdcI2cAddr[devId]);
925                         break;
927                 /* Current SCK Ratio
928                  *        0x0 - Out of range (L) or SCK Halt
929                  *        0x1 - 128
930                  *        0x2 - 256
931                  *        0x3 - 384
932                  *        0x4 - 512
933                  *        0x5 - 768
934                  *        0x6 - Out of range (High)
935                  *        0x7 - Invalid SCK ratio or LRCK Halt
936                  */
937                 case ADC_STATUS_SCK_RATIO:
938                         retVal = pcm186xGetSckRatioStatus(gAdcI2cAddr[devId]);
939                         break;
941                 /* LRCK Halt Status
942                  *     0 - No Error
943          *     1 - Halt
944                  */
945                 case ADC_STATUS_LRCK_HALT:
946                         retVal = pcm186xGetLrckHltStatus(gAdcI2cAddr[devId]);
947                         break;
949                 /* BCK Halt Status
950                  *     0 - No Error
951          *     1 - Halt
952                  */
953                 case ADC_STATUS_BCK_HALT:
954                         retVal = pcm186xGetBckHltStatus(gAdcI2cAddr[devId]);
955                         break;
957                 /* SCK Halt Status
958                  *     0 - No Error
959          *     1 - Halt
960                  */
961                 case ADC_STATUS_SCK_HALT:
962                         retVal = pcm186xGetSckHltStatus(gAdcI2cAddr[devId]);
963                         break;
965                 /* LRCK Error Status
966                  *     0 - No Error
967                  *     1 - Error
968              */
969                 case ADC_STATUS_LRCK_ERR:
970                         retVal = pcm186xGetLrckErrStatus(gAdcI2cAddr[devId]);
971                         break;
973                 /* BCK Error Status
974                  *     0 - No Error
975                  *     1 - Error
976              */
977                 case ADC_STATUS_BCK_ERR:
978                         retVal = pcm186xGetBckErrStatus(gAdcI2cAddr[devId]);
979                         break;
981                 /* SCK Error Status
982                  *     0 - No Error
983                  *     1 - Error
984              */
985                 case ADC_STATUS_SCK_ERR:
986                         retVal = pcm186xGetSckErrStatus(gAdcI2cAddr[devId]);
987                         break;
989                 /* DVDD Status
990                  *   0 - Bad/Missing
991          *   1 - Good
992          */
993                 case ADC_STATUS_DVDD:
994                         retVal = pcm186xGetDvddStatus(gAdcI2cAddr[devId]);
995                         break;
997                 /* AVDD Status
998                  *   0 - Bad/Missing
999          *   1 - Good
1000          */
1001                 case ADC_STATUS_AVDD:
1002                         retVal = pcm186xGetAvddStatus(gAdcI2cAddr[devId]);
1003                         break;
1005                 /* Digital LDO Status
1006                  *   0 - Bad/Missing
1007          *   1 - Good
1008          */
1009                 case ADC_STATUS_LDO:
1010                         retVal = pcm186xGetLdoStatus(gAdcI2cAddr[devId]);
1011                         break;
1013                 default:
1014                         retVal = 0xFF;
1015                         break;
1017         }
1019         if(retVal == 0xFF)
1020         {
1021                 IFPRINT(platform_write("platformAudioAdcGetStatus : ADC Access for Get Status Failed \n"));
1022                 platform_errno = PLATFORM_ERRNO_AUDIO_STATUS;
1023         }
1025         return ((uint8_t)retVal);
1028 /**
1029  *  \brief    ADC DSP channel configuration control
1030  *
1031  *  This function configures the DSP module processing channels
1032  *  supported by ADC
1033  *
1034  *  \param devId       [IN]  Device ID of ADC HW instance
1035  *                           Use 'ADC_DEVICE_ALL' to apply the configuration
1036  *                           for all the ADC devices available.
1037  *
1038  *  \param chanCfg     [IN]  DSP channel configuration
1039  *
1040  *  \return    Platform_EOK on Success or error code
1041  *
1042  */
1043 Platform_STATUS platformAudioAdcDspCtrl(AdcDevId      devId,
1044                                         AdcDspChanCfg chanCfg)
1046         ADC_RET  retVal;
1047         Uint8    id;
1049         IFPRINT(platform_write("platformAudioAdcDspCtrl Called \n"));
1051         if( !( ((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)) &&
1052                ((chanCfg == ADC_DSP_PROC_4CHAN) ||
1053                 (chanCfg == ADC_DSP_PROC_2CHAN)) ) )
1054         {
1055                 IFPRINT(platform_write("platformAudioAdcDspCtrl : Invalid Inputs\n"));
1056                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1057                 return (Platform_EINVALID);
1058         }
1060         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
1061         {
1062                 if((id == devId) || (devId == ADC_DEVICE_ALL))
1063                 {
1064                         retVal = pcm186xDspCtrl(gAdcI2cAddr[id], (Uint8)chanCfg);
1065                         if(retVal)
1066                         {
1067                                 IFPRINT(platform_write("platformAudioAdcDspCtrl : ADC Access for DSP Chan Config Failed \n"));
1068                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1069                                 return (Platform_EFAIL);
1070                         }
1071                 }
1072         }
1074     return (Platform_EOK);
1077 /**
1078  *  \brief    Programs ADC DSP coefficients
1079  *
1080  *  ADC module supports an internal DSP which performs additional audio
1081  *  processing operations like mixing, LPF/HPF etc.
1082  *  DSP coefficients can be programmed by this function.
1083  *
1084  *  \param devId        [IN]  Device ID of ADC HW instance
1085  *                            Use 'ADC_DEVICE_ALL' to apply the configuration
1086  *                            for all the ADC devices available.
1087  *
1088  *  \param coeffRegAddr [IN]  Address of DSP coefficient register
1089  *
1090  *  \param dspCoeff     [IN]  Value of DSP coefficient
1091  *                            Lower 24 bits are written to DSP coeff register
1092  *
1093  *  \return    Platform_EOK on Success or error code
1094  *
1095  */
1096 Platform_STATUS platformAudioAdcProgDspCoeff(AdcDevId      devId,
1097                                              uint8_t       coeffRegAddr,
1098                                              uint32_t      dspCoeff)
1100         ADC_RET  retVal;
1101         Uint8    id;
1103         IFPRINT(platform_write("platformAudioAdcProgDspCoeff Called \n"));
1105         if(!((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)))
1106         {
1107                 IFPRINT(platform_write("platformAudioAdcProgDspCoeff : Invalid Inputs\n"));
1108                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1109                 return (Platform_EINVALID);
1110         }
1112         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
1113         {
1114                 if((id == devId) || (devId == ADC_DEVICE_ALL))
1115                 {
1116                         retVal = pcm186xProgDspCoeff(gAdcI2cAddr[id], (Uint8)coeffRegAddr,
1117                                                      (Uint32)dspCoeff);
1118                         if(retVal)
1119                         {
1120                                 IFPRINT(platform_write("platformAudioAdcProgDspCoeff : ADC DSP Coefficient Config Failed \n"));
1121                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1122                                 return (Platform_EFAIL);
1123                         }
1124                 }
1125         }
1127     return (Platform_EOK);
1130 /**
1131  *  \brief    Displays ADC register programmed values
1132  *
1133  *  This function is provided for debug purpose to read the value
1134  *  of ADC registers. Values read from the ADC registers will be displayed
1135  *  in CCS output window or serial terminal based on the system level
1136  *  configuration for debug messages.
1137  *
1138  *  \param devId       [IN]  Device ID of ADC HW instance
1139  *                           Use 'ADC_DEVICE_ALL' to read the register values
1140  *                           for all the ADC devices available.
1141  *
1142  *  \return    Platform_EOK on Success or error code
1143  */
1144 Platform_STATUS platformAudioAdcGetRegDump(AdcDevId devId)
1146         ADC_RET  retVal;
1147         Uint8    id;
1149         IFPRINT(platform_write("platformAudioAdcGetRegDump Called \n"));
1151         if(!((devId >= ADC_DEVICE_0) && (devId <= ADC_DEVICE_ALL)))
1152         {
1153                 IFPRINT(platform_write("platformAudioAdcGetRegDump : Invalid Inputs\n"));
1154                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1155                 return (Platform_EINVALID);
1156         }
1158         for (id = ADC_DEVICE_0; id < ADC_DEVICE_ALL; id++)
1159         {
1160                 if((id == devId) || (devId == ADC_DEVICE_ALL))
1161                 {
1162                         retVal = pcm186xRegDump(gAdcI2cAddr[id]);
1163                         if(retVal)
1164                         {
1165                                 IFPRINT(platform_write("platformAudioAdcGetRegDump : ADC Reg Read Failed \n"));
1166                                 platform_errno = PLATFORM_ERRNO_AUDIO_STATUS;
1167                                 return (Platform_EFAIL);
1168                         }
1169                 }
1170         }
1172     return (Platform_EOK);
1175 #endif  /* #if (PLATFORM_AUDIO_ADC) */
1178 #if (PLATFORM_AUDIO_DAC)
1180 /**
1181  *  \brief    Initializes DAC module
1182  *
1183  *  This function configures the system level setup required for DAC
1184  *  operation and initializes the DAC module with default values.
1185  *  This function should be called before calling any other DAC functions.
1186  *
1187  *  After executing this function, DAC module should be ready for audio
1188  *  processing with default configuration. Default DAC configurations
1189  *  can be changed using the other DAC APIs if required.
1190  *
1191  *  \param devId        [IN]  Device ID of DAC HW instance
1192  *                            Use 'DAC_DEVICE_ALL' to initialize
1193  *                            all the DAC devices available.
1194  *
1195  *  \return    Platform_EOK on Success or error code
1196  */
1197 Platform_STATUS platformAudioDacInit(DacDevId devId)
1199         DAC_RET  retVal;
1200         Uint8    id;
1202         IFPRINT(platform_write("platformAudioDacInit Called \n"));
1204         if(!((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)))
1205         {
1206                 IFPRINT(platform_write("platformAudioDacInit : Invalid Inputs\n"));
1207                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1208                 return (Platform_EINVALID);
1209         }
1211         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1212         {
1213                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1214                 {
1215                         retVal = pcm169xDacInit(gDacI2cAddr[id]);
1216                         if(retVal)
1217                         {
1218                                 IFPRINT(platform_write("platformAudioDacInit : DAC Initialization Failed \n"));
1219                                 platform_errno = PLATFORM_ERRNO_AUDIO_INIT;
1220                                 return (Platform_EFAIL);
1221                         }
1222                 }
1223         }
1225     return (Platform_EOK);
1228 /**
1229  *  \brief    Resets DAC module
1230  *
1231  *  Resetting the DAC module restarts the re-synchronization between
1232  *  system clock and sampling clock, and DAC operation.
1233  *
1234  *  \param devId        [IN]  Device ID of DAC HW instance
1235  *                            Use 'DAC_DEVICE_ALL' to reset
1236  *                            all the DAC devices available.
1237  *
1238  *  \return    Platform_EOK on Success or error code
1239  */
1240 Platform_STATUS platformAudioDacReset(DacDevId devId)
1242         DAC_RET  retVal;
1243         Uint8    id;
1245         IFPRINT(platform_write("platformAudioDacReset Called \n"));
1247     /* Check input parameters */
1248         if(!((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)))
1249         {
1250                 IFPRINT(platform_write("platformAudioDacReset : Invalid Inputs\n"));
1251                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1252                 return (Platform_EINVALID);
1253         }
1255         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1256         {
1257                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1258                 {
1259                         IFPRINT(platform_write("platformAudioDacReset : DAC Reset Failed \n"));
1260                         retVal = pcm169xReset(gDacI2cAddr[id]);
1261                         if(retVal)
1262                         {
1263                                 platform_errno = PLATFORM_ERRNO_AUDIO;
1264                                 return (Platform_EFAIL);
1265                         }
1266                 }
1267         }
1269     return (Platform_EOK);
1272 /**
1273  *  \brief    Configures DAC Analog mute control
1274  *
1275  *  DAC module supports AMUTE functionality which causes the DAC output
1276  *  to cut-off from the digital input upon the occurrence of any events
1277  *  which are configured by AMUTE control.
1278  *
1279  *  \param devId        [IN]  Device ID of DAC HW instance
1280  *                            Use 'DAC_DEVICE_ALL' to apply the configuration
1281  *                            for all the DAC devices available.
1282  *
1283  *  \param muteCtrl     [IN]  Analog mute control event
1284  *
1285  *  \param muteEnable   [IN]  Flag to configure AMUTE for given control event
1286  *                            1 - Enable AMUTE control
1287  *                            0 - Disable AMUTE control
1288  *
1289  *  \return    Platform_EOK on Success or error code
1290  */
1291 Platform_STATUS platformAudioDacAmuteCtrl(DacDevId     devId,
1292                                           DacAmuteCtrl muteCtrl,
1293                                           uint8_t      muteEnable)
1295         DAC_RET  retVal;
1296         Uint8    id;
1298         IFPRINT(platform_write("platformAudioDacAmuteCtrl Called \n"));
1300     /* Check input parameters */
1301         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1302                ((muteCtrl >= DAC_AMUTE_CTRL_SCKI_LOST) &&
1303                 (muteCtrl <= DAC_AMUTE_CTRL_DAC_DISABLE_CMD)) &&
1304                ((muteEnable == 0) || (muteEnable == 1)) ) )
1305         {
1306                 IFPRINT(platform_write("platformAudioDacAmuteCtrl : Invalid Inputs\n"));
1307                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1308                 return (Platform_EINVALID);
1309         }
1311         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1312         {
1313                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1314                 {
1315                         if(muteEnable == 1)
1316                         {
1317                 retVal = pcm169xEnableAmute(gDacI2cAddr[id],
1318                                             (Uint8)(1 << muteCtrl));
1319                         }
1320                         else
1321                         {
1322                                 retVal = pcm169xDisableAmute(gDacI2cAddr[id],
1323                                                              (Uint8)(1 << muteCtrl));
1324                         }
1326                         if(retVal)
1327                         {
1328                                 IFPRINT(platform_write("platformAudioDacAmuteCtrl : DAC Access for AMUTE Config Failed \n"));
1329                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1330                                 return (Platform_EFAIL);
1331                         }
1332                 }
1333         }
1335     return (Platform_EOK);
1338 /**
1339  *  \brief    Configures DAC Audio sampling mode
1340  *
1341  *  By default, DAC module sampling mode is configured for auto mode.
1342  *  In Auto mode, the sampling mode is automatically set according to multiples
1343  *  between the system clock and sampling clock. Single rate for 512 fS, 768 fS,
1344  *  and 1152 fS, dual rate for 256 fS or 384 fS, and quad rate for 128 fS
1345  *  and 192 fS. Setting the sampling mode is required only if auto mode
1346  *  configurations are not suitable for the application.
1347  *
1348  *  \param devId        [IN]  Device ID of DAC HW instance
1349  *                            Use 'DAC_DEVICE_ALL' to apply the configuration
1350  *                            for all the DAC devices available.
1351  *
1352  *  \param samplingMode [IN]  DAC audio sampling mode
1353  *
1354  *  \return    Platform_EOK on Success or error code
1355  */
1356 Platform_STATUS platformAudioDacSetSamplingMode(DacDevId        devId,
1357                                                 DacSamplingMode samplingMode)
1359         DAC_RET  retVal;
1360         Uint8    id;
1362         IFPRINT(platform_write("platformAudioDacSetSamplingMode Called \n"));
1364     /* Check input parameters */
1365         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1366                ((samplingMode >= DAC_SAMPLING_MODE_AUTO) &&
1367                 (samplingMode <= DAC_SAMPLING_MODE_QUAD_RATE)) ) )
1368         {
1369                 IFPRINT(platform_write("platformAudioDacSetSamplingMode : Invalid Inputs\n"));
1370                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1371                 return (Platform_EINVALID);
1372         }
1374         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1375         {
1376                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1377                 {
1378                         retVal = pcm169xSetSamplingMode(gDacI2cAddr[id],
1379                                                         (Uint8)samplingMode);
1380                         if(retVal)
1381                         {
1382                                 IFPRINT(platform_write("platformAudioDacSetSamplingMode : DAC Access for Sampling Mode Config Failed \n"));
1383                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1384                                 return (Platform_EFAIL);
1385                         }
1386                 }
1387         }
1389     return (Platform_EOK);
1392 /**
1393  *  \brief    Configures DAC Audio interface data format
1394  *
1395  *  \param devId      [IN]  Device ID of DAC HW instance
1396  *                          Use 'DAC_DEVICE_ALL' to apply the configuration
1397  *                          for all the DAC devices available.
1398  *
1399  *  \param dataFormat [IN]  DAC audio data format
1400  *
1401  *  \return    Platform_EOK on Success or error code
1402  */
1403 Platform_STATUS platformAudioDacSetDataFormat(DacDevId      devId,
1404                                               DacDataFormat dataFormat)
1406         DAC_RET  retVal;
1407         Uint8    id;
1409         IFPRINT(platform_write("platformAudioDacSetDataFormat Called \n"));
1411     /* Check input parameters */
1412         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1413                ((dataFormat >= DAC_DATA_FORMAT_I2S) &&
1414                 (dataFormat <= DAC_DATA_FORMAT_24BIT_HS_LEFTJ_TDM)) ) )
1415         {
1416                 IFPRINT(platform_write("platformAudioDacSetDataFormat : Invalid Inputs\n"));
1417                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1418                 return (Platform_EINVALID);
1419         }
1421         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1422         {
1423                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1424                 {
1425                         retVal = pcm169xDataConfig(gDacI2cAddr[id], (Uint8)dataFormat);
1426                         if(retVal)
1427                         {
1428                                 IFPRINT(platform_write("platformAudioDacSetDataFormat : DAC Access for Data Format Config Failed \n"));
1429                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1430                                 return (Platform_EFAIL);
1431                         }
1432                 }
1433         }
1435     return (Platform_EOK);
1438 /**
1439  *  \brief    Configures DAC operation mode
1440  *
1441  *  This function configures a particular DAC channel pair to be operating
1442  *  normal or disabled.
1443  *
1444  *  \param devId      [IN]  Device ID of DAC HW instance
1445  *                          Use 'DAC_DEVICE_ALL' to apply the configuration
1446  *                          for all the DAC devices available.
1447  *
1448  *  \param chanPair   [IN]  Internal DAC channel pair
1449  *                          Use DAC_CHANP_1_2 to DAC_CHANP_7_8 for
1450  *                          individual DAC channel pair configuration
1451  *                          Use DAC_CHANP_ALL to set operation mode
1452  *                          for all DAC channels
1453  *
1454  *  \param opMode     [IN]  DAC operation mode
1455  *
1456  *  \return    Platform_EOK on Success or error code
1457  */
1458 Platform_STATUS platformAudioDacSetOpMode(DacDevId    devId,
1459                                           DacChanPair chanPair,
1460                                           DacOpMode   opMode)
1462         DAC_RET  retVal;
1463         Uint8    modeCtrl;
1464         Uint8    id;
1466         IFPRINT(platform_write("platformAudioDacSetOpMode Called \n"));
1468     /* Check input parameters */
1469         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1470                ((chanPair >= DAC_CHANP_1_2) && (chanPair <= DAC_CHANP_ALL)) &&
1471                ((opMode == DAC_OPMODE_NORMAL) ||
1472                 (opMode == DAC_OPMODE_DISABLED)) ) )
1473         {
1474                 IFPRINT(platform_write("platformAudioDacSetOpMode : Invalid Inputs\n"));
1475                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1476                 return (Platform_EINVALID);
1477         }
1479         if(chanPair == DAC_CHANP_ALL)
1480         {
1481                 modeCtrl = 0xF;
1482         }
1483         else
1484         {
1485                 modeCtrl = (1 << chanPair);
1486         }
1488         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1489         {
1490                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1491                 {
1492                         if(opMode == DAC_OPMODE_DISABLED)
1493                         {
1494                 retVal = pcm169xDisableDacOpeartion(gDacI2cAddr[id], modeCtrl);
1495                         }
1496                         else
1497                         {
1498                                 retVal = pcm169xEnableDacOpeartion(gDacI2cAddr[id], modeCtrl);
1499                         }
1501                         if(retVal)
1502                         {
1503                                 IFPRINT(platform_write("platformAudioDacSetOpMode : DAC Access for Opmode Config Failed \n"));
1504                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1505                                 return (Platform_EFAIL);
1506                         }
1507                 }
1508         }
1510     return (Platform_EOK);
1513 /**
1514  *  \brief    Configures DAC filter roll-off
1515  *
1516  *  \param devId      [IN]  Device ID of DAC HW instance
1517  *                          Use 'DAC_DEVICE_ALL' to apply the configuration
1518  *                          for all the DAC devices available.
1519  *
1520  *  \param chanPair   [IN]  Internal DAC channel pair
1521  *                          Use DAC_CHANP_1_2 to DAC_CHANP_7_8 for
1522  *                          individual DAC channel pair configuration
1523  *                          Use DAC_CHANP_ALL to set filter roll-off
1524  *                          for all DAC channels
1525  *
1526  *  \param rolloff    [IN]  Roll-off configuration
1527  *
1528  *  \return    Platform_EOK on Success or error code
1529  */
1530 Platform_STATUS platformAudioDacSetFilterRolloff(DacDevId         devId,
1531                                                  DacChanPair      chanPair,
1532                                                  DacFilterRolloff rolloff)
1534         DAC_RET  retVal;
1535         Uint8    chanId;
1536         Uint8    id;
1538         IFPRINT(platform_write("platformAudioDacSetFilterRolloff Called \n"));
1540     /* Check input parameters */
1541         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1542                ((chanPair >= DAC_CHANP_1_2) && (chanPair <= DAC_CHANP_ALL)) &&
1543                ((rolloff >= DAC_FILTER_SHARP_ROLLOFF) &&
1544                 (rolloff <= DAC_FILTER_SLOW_ROLLOFF)) ) )
1545         {
1546                 IFPRINT(platform_write("platformAudioDacSetFilterRolloff : Invalid Inputs\n"));
1547                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1548                 return (Platform_EINVALID);
1549         }
1551         if(chanPair == DAC_CHANP_ALL)
1552         {
1553                 chanId = 0xF;
1554         }
1555         else
1556         {
1557                 chanId = (1 << chanPair);
1558         }
1560         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1561         {
1562                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1563                 {
1564                         retVal = pcm169xSetFilterRolloff(gDacI2cAddr[id], chanId,
1565                                                          (Uint8)rolloff);
1566                         if(retVal)
1567                         {
1568                                 IFPRINT(platform_write("platformAudioDacSetFilterRolloff : DAC Access for Filter Roll-off Config Failed \n"));
1569                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1570                                 return (Platform_EFAIL);
1571                         }
1572                 }
1573         }
1575     return (Platform_EOK);
1578 /**
1579  *  \brief    Configures phase of the DAC analog signal outputs
1580  *
1581  *  \param devId      [IN]  Device ID of DAC HW instance
1582  *                          Use 'DAC_DEVICE_ALL' to apply the configuration
1583  *                          for all the DAC devices available.
1584  *
1585  *  \param chanId     [IN]  Internal DAC channel Id
1586  *                          Use DAC_CHAN_1 to DAC_CHAN_8 for individual
1587  *                          DAC channel configuration
1588  *                          Use DAC_CHAN_ALL to set output phase for all
1589  *                          DAC channels
1590  *
1591  *  \param outPhase   [IN]  Output phase selection
1592  *
1593  *  \return    Platform_EOK on Success or error code
1594  */
1595 Platform_STATUS platformAudioDacSetOutputPhase(DacDevId       devId,
1596                                                DacChanId      chanId,
1597                                                DacOutputPhase outPhase)
1599         DAC_RET  retVal;
1600         Uint8    chan;
1601         Uint8    id;
1603         IFPRINT(platform_write("platformAudioDacSetOutputPhase Called \n"));
1605     /* Check input parameters */
1606         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1607                ((chanId >= DAC_CHAN_1) && (chanId <= DAC_CHAN_ALL)) &&
1608                ((outPhase >= DAC_OUTPUT_PHASE_NORMAL) &&
1609                 (outPhase <= DAC_OUTPUT_PHASE_INVERTED)) ) )
1610         {
1611                 IFPRINT(platform_write("platformAudioDacSetOutputPhase : Invalid Inputs\n"));
1612                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1613                 return (Platform_EINVALID);
1614         }
1616         if(chanId == DAC_CHAN_ALL)
1617         {
1618                 chan = 0xFF;
1619         }
1620         else
1621         {
1622                 chan = (1 << chanId);
1623         }
1625         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1626         {
1627                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1628                 {
1629                         retVal = pcm169xSetOutputPhase(gDacI2cAddr[id], chan,
1630                                                        (Uint8)outPhase);
1631                         if(retVal)
1632                         {
1633                                 IFPRINT(platform_write("platformAudioDacSetOutputPhase : DAC Access for Output Phase Config Failed \n"));
1634                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1635                                 return (Platform_EFAIL);
1636                         }
1637                 }
1638         }
1640     return (Platform_EOK);
1643 /**
1644  *  \brief    Soft mute function control
1645  *
1646  *  The Soft mute function allows mute/unmute of DAC output in gradual steps.
1647  *  This configuration reduces pop and zipper noise during muting of the
1648  *  DAC output.
1649  *
1650  *  \param devId      [IN]  Device ID of DAC HW instance
1651  *                          Use 'DAC_DEVICE_ALL' to apply the configuration
1652  *                          for all the DAC devices available.
1653  *
1654  *  \param chanId     [IN]  Internal DAC channel Id
1655  *                          Use DAC_CHAN_1 to DAC_CHAN_8 for individual
1656  *                          DAC channel configuration
1657  *                          Use DAC_CHAN_ALL to mute/unmute all DAC
1658  *                          channels
1659  *
1660  *  \param muteEnable [IN]  Mute enable flag
1661  *                          0 for unmute and 1 for mute
1662  *
1663  *  \return    Platform_EOK on Success or error code
1664  */
1665 Platform_STATUS platformAudioDacSoftMuteCtrl(DacDevId   devId,
1666                                              DacChanId  chanId,
1667                                              uint8_t    muteEnable)
1669         DAC_RET  retVal;
1670         Uint8    chan;
1671         Uint8    id;
1673         IFPRINT(platform_write("platformAudioDacSoftMuteCtrl Called \n"));
1675     /* Check input parameters */
1676         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1677                ((chanId >= DAC_CHAN_1) && (chanId <= DAC_CHAN_ALL)) &&
1678                ((muteEnable == 0) || (muteEnable == 1)) ) )
1679         {
1680                 IFPRINT(platform_write("platformAudioDacSoftMuteCtrl : Invalid Inputs\n"));
1681                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1682                 return (Platform_EINVALID);
1683         }
1685         if(chanId == DAC_CHAN_ALL)
1686         {
1687                 chan = 0xFF;
1688         }
1689         else
1690         {
1691                 chan = (1 << chanId);
1692         }
1694         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1695         {
1696                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1697                 {
1698                         retVal = pcm169xSoftMuteCtrl(gDacI2cAddr[id], chan, muteEnable);
1699                         if(retVal)
1700                         {
1701                                 IFPRINT(platform_write("platformAudioDacSoftMuteCtrl : DAC Access for Soft Mute Config Failed \n"));
1702                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1703                                 return (Platform_EFAIL);
1704                         }
1705                 }
1706         }
1708     return (Platform_EOK);
1711 /**
1712  *  \brief    Sets attenuation mode
1713  *
1714  *  DAC module supports two types of volume/attenuation dB range
1715  *  which can be changed by setting attenuation mode. Volume range and fine
1716  *  tuning will change based on the attenuation mode.
1717  *
1718  *  \param devId    [IN]  Device ID of DAC HW instance
1719  *                        Use 'DAC_DEVICE_ALL' to apply the configuration
1720  *                        for all the DAC devices available.
1721  *
1722  *  \param attnMode [IN]  Attenuation mode
1723  *
1724  *  \return    Platform_EOK on Success or error code
1725  */
1726 Platform_STATUS platformAudioDacSetAttnMode(DacDevId    devId,
1727                                             DacAttnMode attnMode)
1729         DAC_RET  retVal;
1730         Uint8    id;
1732         IFPRINT(platform_write("platformAudioDacSetAttnMode Called \n"));
1734     /* Check input parameters */
1735         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1736                ((attnMode >= DAC_ATTENUATION_FINE_STEP) &&
1737                 (attnMode <= DAC_ATTENUATION_WIDE_RANGE)) ) )
1738         {
1739                 IFPRINT(platform_write("platformAudioDacSetAttnMode : Invalid Inputs\n"));
1740                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1741                 return (Platform_EINVALID);
1742         }
1744         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1745         {
1746                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1747                 {
1748                         retVal = pcm169xSetAttnMode(gDacI2cAddr[id], (Uint8)attnMode);
1749                         if(retVal)
1750                         {
1751                                 IFPRINT(platform_write("platformAudioDacSetAttnMode : DAC Access for Attenuation Mode Config Failed \n"));
1752                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1753                                 return (Platform_EFAIL);
1754                         }
1755                 }
1756         }
1758     return (Platform_EOK);
1761 /**
1762  *  \brief    Function to control digital de-emphasis functionality
1763  *
1764  *  Disables/Enables the various sampling frequencies of the digital
1765  *  de-emphasis function.
1766  *
1767  *  \param devId     [IN]  Device ID of DAC HW instance
1768  *                         Use 'DAC_DEVICE_ALL' to apply the configuration
1769  *                         for all the DAC devices available.
1770  *
1771  *  \param deempCtrl [IN]  De-emphasis control options
1772  *
1773  *  \return    Platform_EOK on Success or error code
1774  */
1775 Platform_STATUS platformAudioDacDeempCtrl(DacDevId     devId,
1776                                           DacDeempCtrl deempCtrl)
1778         DAC_RET  retVal;
1779         Uint8    id;
1781         IFPRINT(platform_write("platformAudioDacDeempCtrl Called \n"));
1783     /* Check input parameters */
1784         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1785                ((deempCtrl >= DAC_DEEMP_DISABLE) &&
1786                 (deempCtrl <= DAC_DEEMP_32KHZ)) ) )
1787         {
1788                 IFPRINT(platform_write("platformAudioDacDeempCtrl : Invalid Inputs\n"));
1789                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1790                 return (Platform_EINVALID);
1791         }
1793         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1794         {
1795                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1796                 {
1797                         retVal = pcm169xDeempCtrl(gDacI2cAddr[id], (Uint8)deempCtrl);
1798                         if(retVal)
1799                         {
1800                                 IFPRINT(platform_write("platformAudioDacDeempCtrl : DAC Access for De-emphasis Config Failed \n"));
1801                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1802                                 return (Platform_EFAIL);
1803                         }
1804                 }
1805         }
1807     return (Platform_EOK);
1810 /**
1811  *  \brief    Configures DAC volume/attenuation
1812  *
1813  *  Range of the volume is exposed as percentage by this API. Volume
1814  *  is indicated as percentage of maximum value ranging from 0 to 100.
1815  *  0 to mute the volume and 100 to set maximum volume
1816  *
1817  *  DAC module supports two types of volume/attenuation dB range
1818  *  which can be changed using platformAudioDacSetAttnMode().
1819  *  Volume range and fine tuning will change based on the attenuation mode.
1820  *
1821  *  \param devId  [IN]  Device ID of DAC HW instance
1822  *                      Use 'DAC_DEVICE_ALL' to apply the configuration
1823  *                      for all the DAC devices available.
1824  *
1825  *  \param chanId [IN]  Internal DAC channel Id
1826  *                      Use DAC_CHAN_1 to DAC_CHAN_8 for individual
1827  *                      DAC channel configuration
1828  *                      Use DAC_CHAN_ALL to mute/unmute all DAC
1829  *                      channels
1830  *
1831  *  \param volume [IN]  Volume in percentage; 0 to 100
1832  *
1833  *  \return    Platform_EOK on Success or error code
1834  */
1835 Platform_STATUS platformAudioDacSetVolume(DacDevId devId,
1836                                           DacChanId chanId,
1837                                           uint8_t  volume)
1839         DAC_RET  retVal;
1840         Uint8    id;
1841         Uint8    chan;
1843         IFPRINT(platform_write("platformAudioDacSetVolume Called \n"));
1845     /* Check input parameters */
1846         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1847                ((chanId >= DAC_CHAN_1) && (chanId <= DAC_CHAN_ALL)) &&
1848                (volume <= 100) ) )
1849         {
1850                 IFPRINT(platform_write("platformAudioDacSetVolume : Invalid Inputs\n"));
1851                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1852                 return (Platform_EINVALID);
1853         }
1855         if(chanId == DAC_CHAN_ALL)
1856         {
1857                 chan = 0xF;
1858         }
1859         else
1860         {
1861                 chan = chanId;
1862         }
1864         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1865         {
1866                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1867                 {
1868                         retVal = pcm169xSetVolume(gDacI2cAddr[id], (Uint8)volume, chan);
1869                         if(retVal)
1870                         {
1871                                 IFPRINT(platform_write("platformAudioDacSetVolume : DAC Access for Volume Config Failed \n"));
1872                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1873                                 return (Platform_EFAIL);
1874                         }
1875                 }
1876         }
1878     return (Platform_EOK);
1881 /**
1882  *  \brief    Configures DAC power-save mode
1883  *
1884  *  \param devId     [IN]  Device ID of DAC HW instance
1885  *                         Use 'DAC_DEVICE_ALL' to apply the configuration
1886  *                         for all the DAC devices available.
1887  *
1888  *  \param PowerMode [IN]  Power-save mode control
1889  *                         0 - Enable power-save mode
1890  *                         1 - Disable power-save mode
1891  *
1892  *  \return    Platform_EOK on Success or error code
1893  */
1894 Platform_STATUS platformAudioDacSetPowerMode(DacDevId devId,
1895                                              uint8_t  PowerMode)
1897         DAC_RET  retVal;
1898         Uint8    id;
1900         IFPRINT(platform_write("platformAudioDacSetPowerMode Called \n"));
1902     /* Check input parameters */
1903         if( !( ((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)) &&
1904                ((PowerMode == 0) || (PowerMode == 1)) ) )
1905         {
1906                 IFPRINT(platform_write("platformAudioDacSetPowerMode : Invalid Inputs\n"));
1907                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1908                 return (Platform_EINVALID);
1909         }
1911         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1912         {
1913                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1914                 {
1915                         retVal = pcm169xSetPowerMode(gDacI2cAddr[id], PowerMode);
1916                         if(retVal)
1917                         {
1918                                 IFPRINT(platform_write("platformAudioDacSetPowerMode : DAC Access for Power-save Mode Config Failed \n"));
1919                                 platform_errno = PLATFORM_ERRNO_AUDIO_CFG;
1920                                 return (Platform_EFAIL);
1921                         }
1922                 }
1923         }
1925     return (Platform_EOK);
1928 /**
1929  *  \brief    Displays DAC register programmed values
1930  *
1931  *  This function is provided for debug purpose to read the value
1932  *  of DAC registers. Values read from the DAC registers will be displayed
1933  *  in CCS output window or serial terminal based on the system level
1934  *  configuration for debug messages.
1935  *
1936  *  \param devId      [IN]  Device ID of DAC HW instance
1937  *                          Use 'DAC_DEVICE_ALL' to apply the configuration
1938  *                          for all the DAC devices available.
1939  *
1940  *  \return    Platform_EOK on Success or error code
1941  */
1942 Platform_STATUS platformAudioDacGetRegDump(DacDevId devId)
1944         DAC_RET  retVal;
1945         Uint8    id;
1947         IFPRINT(platform_write("platformAudioDacGetRegDump Called \n"));
1949         if(!((devId >= DAC_DEVICE_0) && (devId <= DAC_DEVICE_ALL)))
1950         {
1951                 IFPRINT(platform_write("platformAudioDacGetRegDump : Invalid Inputs\n"));
1952                 platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
1953                 return (Platform_EINVALID);
1954         }
1956         for (id = DAC_DEVICE_0; id < DAC_DEVICE_ALL; id++)
1957         {
1958                 if((id == devId) || (devId == DAC_DEVICE_ALL))
1959                 {
1960                         retVal = pcm169xRegDump(gDacI2cAddr[id]);
1961                         if(retVal)
1962                         {
1963                                 IFPRINT(platform_write("platformAudioDacGetRegDump : DAC Access for Reg Dump Failed \n"));
1964                                 platform_errno = PLATFORM_ERRNO_AUDIO_STATUS;
1965                                 return (Platform_EFAIL);
1966                         }
1967                 }
1968         }
1970     return (Platform_EOK);
1972 #endif  /* #if (PLATFORM_AUDIO_DAC) */
1975 #if (PLATFORM_AUDIO_DIR)
1977 /**
1978  *  \brief    Initializes DIR module
1979  *
1980  *  Configures GPIOs and other settings required for DIR module operation.
1981  *  This function should be called before calling any other DIR functions.
1982  *
1983  *  \return    Platform_EOK on Success or error code
1984  *
1985  */
1986 Platform_STATUS platformAudioDirInit(void)
1988         IFPRINT(platform_write("platformAudioDirInit Called \n"));
1990         /* Configure each SOC_GPIO pin connected to DIR status lines
1991            as GPIO and input */
1993         /* DIR RST signal - GPIO 1, pin 9 */
1994         pinMuxSetMode(PLATFORM_AUDIO_DIR_RST_PADCFG,
1995                       PADCONFIG_MUX_MODE_QUATERNARY);
1996         gpioSetDirection(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO, GPIO_OUT);
1997         gpioSetOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
1999         /* DIR AUDIO signal - GPIO 0, pin 134 */
2000         pinMuxSetMode(PLATFORM_AUDIO_DIR_AUDIO_PADCFG,
2001                       PADCONFIG_MUX_MODE_QUATERNARY);
2002         gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_AUDIO_GPIO, GPIO_IN);
2004         /* DIR EMPH signal - GPIO 0, pin 135 */
2005         pinMuxSetMode(PLATFORM_AUDIO_DIR_EMPH_PADCFG,
2006                       PADCONFIG_MUX_MODE_QUATERNARY);
2007         gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_EMPH_GPIO, GPIO_IN);
2009         /* DIR ERROR signal - GPIO 0, pin 136 */
2010         pinMuxSetMode(PLATFORM_AUDIO_DIR_ERR_PADCFG,
2011                       PADCONFIG_MUX_MODE_QUATERNARY);
2012         gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_ERR_GPIO, GPIO_IN);
2014         /* DIR CLKST signal - GPIO 0, pin 133 */
2015         pinMuxSetMode(PLATFORM_AUDIO_DIR_CLKST_PADCFG,
2016                       PADCONFIG_MUX_MODE_QUATERNARY);
2017         gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_CLKST_GPIO, GPIO_IN);
2019         /* DIR FSOUT0 signal - GPIO 0, pin 124 */
2020         pinMuxSetMode(PLATFORM_AUDIO_DIR_FSOUT0_PADCFG,
2021                       PADCONFIG_MUX_MODE_QUATERNARY);
2022         gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_FSOUT0_GPIO, GPIO_IN);
2024         /* DIR FSOUT1 signal - GPIO 0, pin 15 */
2025         pinMuxSetMode(PLATFORM_AUDIO_DIR_FSOUT1_PADCFG,
2026                       PADCONFIG_MUX_MODE_QUATERNARY);
2027         gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_DIR_FSOUT1_GPIO, GPIO_IN);
2029 #if 0
2030     /* Reset DIR */
2031         gpioClearOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
2032         /* DIR Reset signal should be low for at least 100 ns.
2033            Adding a delay of 1usec */
2034         platform_delay(1);
2035         gpioSetOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
2036 #endif
2038     return (Platform_EOK);
2041 /**
2042  *  \brief    Resets DIR module
2043  *
2044  *  \return    Platform_EOK on Success or error code
2045  *
2046  */
2047 Platform_STATUS platformAudioDirReset(void)
2049         IFPRINT(platform_write("platformAudioDirReset Called \n"));
2051         gpioClearOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
2052         /* DIR Reset signal should be low for at least 100 ns.
2053            Adding a delay of 1usec */
2054         platform_delay(1);
2055         gpioSetOutput(GPIO_PORT_1, PLATFORM_AUDIO_DIR_RST_GPIO);
2057     return(Platform_EOK);
2060 /**
2061  *  \brief    Reads AUDIO output status value of the DIR
2062  *
2063  *  DIR AUDIO output pin gives the audio sample word information
2064  *  of the channel-status data bit 1
2065  *
2066  *  \return AUDIO pin output with below possible values
2067  *  \n      0 - Audio sample word represents linear PCM samples
2068  *  \n      1 - Audio sample word is used for other purposes
2069  */
2070 int8_t platformAudioDirGetAudioStatus(void)
2072         int8_t audio;
2074         IFPRINT(platform_write("platformAudioDirGetAudioStatus Called \n"));
2076         audio = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_AUDIO_GPIO);
2078     return(audio);
2081 /**
2082  *  \brief    Reads EMPH output status value of the DIR
2083  *
2084  *  DIR EMPH output pin gives the emphasis information of the
2085  *  channel-status data bit 3.
2086  *
2087  *  \return EMPH pin output with below possible values
2088  *  \n      0 - Two audio channels without pre-emphasis
2089  *  \n      1 - Two audio channels with 50 ms / 15 ms pre-emphasis
2090  */
2091 int8_t platformAudioDirGetEmphStatus(void)
2093         int8_t emph;
2095         IFPRINT(platform_write("platformAudioDirGetEmphStatus Called \n"));
2097         emph = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_EMPH_GPIO);
2099     return(emph);
2102 /**
2103  *  \brief    Reads ERROR pin status value of the DIR
2104  *
2105  *  DIR ERROR output pin gives the error state of data and parity errors.
2106  *
2107  *  \return EMPH pin output with below possible values
2108  *  \n      0 - Lock state of PLL and nondetection of parity error
2109  *  \n      1 - Unlock state of PLL or detection of parity error
2110  */
2111 int8_t platformAudioDirGetErrStatus(void)
2113         int8_t err;
2115         IFPRINT(platform_write("platformAudioDirGetErrStatus Called \n"));
2117         err = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_ERR_GPIO);
2119     return(err);
2122 /**
2123  *  \brief    Reads CLKST pin status value of the DIR
2124  *
2125  *  DIR CLKST pin outputs the PLL status change between LOCK and UNLOCK.
2126  *  The CLKST output pulse depends only on the status change of the PLL.
2127  *
2128  *  \return EMPH pin output with below possible values
2129  *  \n      0 - Lock state of PLL and nondetection of parity error
2130  *  \n      1 - Unlock state of PLL or detection of parity error
2131  */
2132 int8_t platformAudioDirGetClkStatus(void)
2134         int8_t clk;
2136         IFPRINT(platform_write("platformAudioDirGetClkStatus Called \n"));
2138         clk = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_CLKST_GPIO);
2140     return(clk);
2143 /**
2144  *  \brief    Reads FSOUT[1:0] output status value of the DIR
2145  *
2146  *  The DIR module calculates the actual sampling frequency of the
2147  *  biphase input signal and outputs its result through FSOUT[1:0] pins.
2148  *
2149  *  \return FSOUT pin output with below possible values
2150  *  \n      0 - Calculated Sampling Frequency Output is 43 kHz\9645.2 kHz
2151  *  \n      1 - Calculated Sampling Frequency Output is 46.8 kHz\9649.2 kHz
2152  *  \n      2 - Out of range or PLL unlocked
2153  *  \n      3 - Calculated Sampling Frequency Output is 31.2 kHz\9632.8 kHz
2154  */
2155 int8_t platformAudioDirGetFsOut(void)
2157         int8_t fsout;
2159         IFPRINT(platform_write("platformAudioDirGetFsOut Called \n"));
2161         fsout = gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_FSOUT1_GPIO);
2162         fsout <<= 1;
2163         fsout |= gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_DIR_FSOUT0_GPIO);
2165     return(fsout);
2168 #endif /* #if (PLATFORM_AUDIO_DIR) */
2170 #endif /* #if (PLATFORM_AUDIO) */
2172 /* Nothing past this point */