]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/application/itopo/evmk2g/sap_d10.c
7d96e6b6b88fe491d631c56de44f341f85d10ac2
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / application / itopo / evmk2g / sap_d10.c
2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without 
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 //
37 // I/O device configuration data structure definitions D10 (DA10x EVM).
40 // -----------------------------------------------------------------------------
41 // This file contains the necessary configurations and functions for
42 // using the DA10x Audio DC card in the PA environment. In particular, the
43 // SAP configurations are referenced in the pa(i/y)-evmda10x-io.c files
44 // for use in IOS (Input/Output Switching) shortcuts. Each configuration
45 // contains settings appropriate to the various devices on the DA10x-AudioDC;
46 // the DIR, DACs, ADCs, and DIT output. Also each configuration points to
47 // a common control function (D10_sapControl), which handles the various
48 // requests made by the PA framework.
50 // A note about clocking. There are three different master clocks
51 // available corresponding to the three primary input choices: HDMI, DIR and ADC.
52 //
53 // DIR:
54 //       . 512fs @ <= 48kHz
55 //       . 256fs @ > 48kHz & <=96 kHz
56 //       . 128fs @ > 96kHz
57 // ADC:
58 //       . 768fs @ 32kHz
59 //       . 512fs @ 48kHz
60 //       . 256fs @ 96kHz
61 //
62 // This faciliates the logic used for the McASP transmit sections TX0 (DAC) and
63 // TX2 (DIT) which divide the master clock down to generate bit and frame clocks.
65 // -----------------------------------------------------------------------------
66 // Includes
68 #include <sap_d10.h>
69 #include <audio_dc_cfg.h>
70 #include "vproccmds_a.h"
71 #include "evmc66x_gpio.h"  // in "${PDK_INSTALL_PATH}/ti/addon/aud/include"
73 #include "dbgBenchmark.h" // PCM high-sampling rate + SRC + CAR benchmarking
74 #include "mcasp_cfg.h"
76 // -----------------------------------------------------------------------------
77 // Local function declarations
79 XDAS_Int32 D10_sapControl (DEV2_Handle device, const PAF_SIO_Params *pParams, XDAS_Int32 code, XDAS_Int32 arg);
80 static inline XDAS_Int32 initD10 (DEV2_Handle device) ;
81 static XDAS_Int32 clockMuxTx (int sel, int force);
82 static int manageInput  (DEV2_Handle device, const SAP_D10_Rx_Params *pParams, PAF_SIO_InputStatus *pStatusOut);
83 static int manageOutput (DEV2_Handle device, const SAP_D10_Tx_Params *pParams, float rateX);
85 void HSR4_readStatus (PAF_SIO_InputStatus *pStatus);
86 unsigned int HDMIGpioGetState (void);
88 /** GPIO number for I2S Header HSR4's ~HMINT pin - GPIO port 0 */
89 #define AUD_AUDIO_HSR_HMINTz_GPIO      (105)   // missing from audio addon
91 /** GPIO number for I2S Header HSR4's ~RESET pin - GPIO port 0 */
92 #define AUD_AUDIO_HSR_RESETz_GPIO      (104)   // missing from audio addon
94 // -----------------------------------------------------------------------------
95 // State machine variables and defines
97 // flag to facilitate one time initialization of DA10x Audio hardware
98 // 0 ==> not initialized, 1 ==> initialized
99 static char initDone = 0;
101 // input status
102 static PAF_SIO_InputStatus primaryStatus =
104     0,                                 // lock
105     PAF_IEC_AUDIOMODE_UNKNOWN,         // nonaudio
106     PAF_IEC_PREEMPHASIS_UNKNOWN,       // emphasis
107     PAF_SAMPLERATE_UNKNOWN,            // sampleRateMeasured
108     PAF_SAMPLERATE_UNKNOWN,            // sampleRateData
109     0,0,0,                             // unused
110 };
113 // The McASP outputs (both for DAC and DIT) receive a high speed clock
114 // and in turn generate a bit and frame clock. The needed clock divider
115 // values are kept here for easy lookup.
116 unsigned char *pClkxDiv = NULL;
118 static const unsigned char clkxDivDIR[PAF_SAMPLERATE_N] =
120     0x2,  //PAF_SAMPLERATE_UNKNOWN
121     0x8,  //PAF_SAMPLERATE_NONE
122     0x8,  //PAF_SAMPLERATE_32000HZ
123     0x2,  //PAF_SAMPLERATE_44100HZ
124     0x2,  //PAF_SAMPLERATE_48000HZ
125     0x4,  //PAF_SAMPLERATE_88200HZ
126     0x2,  //PAF_SAMPLERATE_96000HZ
127     0x2,  //PAF_SAMPLERATE_192000HZ
128     0x4,  //PAF_SAMPLERATE_64000HZ
129     0x2,  //PAF_SAMPLERATE_128000HZ
130     0x2,  //PAF_SAMPLERATE_176400HZ
131     0x8,  //PAF_SAMPLERATE_8000HZ
132     0x8,  //PAF_SAMPLERATE_11025HZ
133     0x8,  //PAF_SAMPLERATE_12000HZ
134     0x8,  //PAF_SAMPLERATE_16000HZ
135     0x8,  //PAF_SAMPLERATE_22050HZ
136     0x8,  //PAF_SAMPLERATE_24000HZ
137 };
140 static const unsigned char clkxDivADC[PAF_SAMPLERATE_N] =
142     0x8,  //PAF_SAMPLERATE_UNKNOWN
143     0x8,  //PAF_SAMPLERATE_NONE
144     0xC,  //PAF_SAMPLERATE_32000HZ
145     0x8,  //PAF_SAMPLERATE_44100HZ
146     0x8,  //PAF_SAMPLERATE_48000HZ
147     0x4,  //PAF_SAMPLERATE_88200HZ
148     0x4,  //PAF_SAMPLERATE_96000HZ
149     0x2,  //PAF_SAMPLERATE_192000HZ
150     0x4,  //PAF_SAMPLERATE_64000HZ
151     0x2,  //PAF_SAMPLERATE_128000HZ
152     0x2,  //PAF_SAMPLERATE_176400HZ
153     0x8,  //PAF_SAMPLERATE_8000HZ
154     0x8,  //PAF_SAMPLERATE_11025HZ
155     0x8,  //PAF_SAMPLERATE_12000HZ
156     0x8,  //PAF_SAMPLERATE_16000HZ
157     0x8,  //PAF_SAMPLERATE_22050HZ
158     0x8,  //PAF_SAMPLERATE_24000HZ
159 };
161 static const unsigned char clkxDivHDMI[PAF_SAMPLERATE_N] =
163     0x2,  //PAF_SAMPLERATE_UNKNOWN
164     0x2,  //PAF_SAMPLERATE_NONE
165     0x8,  //PAF_SAMPLERATE_32000HZ
166     0x2,  //PAF_SAMPLERATE_44100HZ
167     0x2,  //PAF_SAMPLERATE_48000HZ
168     0x2,  //PAF_SAMPLERATE_88200HZ
169     0x2,  //PAF_SAMPLERATE_96000HZ
170     0x2,  //PAF_SAMPLERATE_192000HZ
171     0x4,  //PAF_SAMPLERATE_64000HZ
172     0x2,  //PAF_SAMPLERATE_128000HZ
173     0x2,  //PAF_SAMPLERATE_176400HZ
174     0x8,  //PAF_SAMPLERATE_8000HZ
175     0x8,  //PAF_SAMPLERATE_11025HZ
176     0x8,  //PAF_SAMPLERATE_12000HZ
177     0x8,  //PAF_SAMPLERATE_16000HZ
178     0x8,  //PAF_SAMPLERATE_22050HZ
179     0x8,  //PAF_SAMPLERATE_24000HZ
180 };
182 // The ADCs, when operating as the master input, can only
183 // generate a limited set of audio sample rates since the clock
184 // is derived from AUXCLK which is the oscillator connected to the DSP.
185 // This table faciliates the access and definition of these rates.
186 static const Uint16 oscRateTable[8] =
188     PAF_SAMPLERATE_UNKNOWN,  // 0
189         PAF_SAMPLERATE_32000HZ,
190         PAF_SAMPLERATE_44100HZ,  // D10_RATE_44_1KHZ
191         PAF_SAMPLERATE_48000HZ,
192         PAF_SAMPLERATE_88200HZ,  // D10_RATE_88_2KHZ
193         PAF_SAMPLERATE_96000HZ,
194         PAF_SAMPLERATE_176400HZ,  // D10_RATE_176_4KHZ
195         PAF_SAMPLERATE_192000HZ
196 };
198 static const Uint16 RateTable_hdmi[8] =
200     PAF_SAMPLERATE_UNKNOWN,  // HSDIO_AudioFreq_RESERVED
201     PAF_SAMPLERATE_32000HZ,  // HSDIO_AudioFreq_32K
202     PAF_SAMPLERATE_44100HZ,  // HSDIO_AudioFreq_44_1K
203     PAF_SAMPLERATE_48000HZ,  // HSDIO_AudioFreq_48K
204     PAF_SAMPLERATE_88200HZ,  // HSDIO_AudioFreq_88_2K
205     PAF_SAMPLERATE_96000HZ,  // HSDIO_AudioFreq_96_4K
206     PAF_SAMPLERATE_176400HZ,  // HSDIO_AudioFreq_176_4K
207     PAF_SAMPLERATE_192000HZ  // HSDIO_AudioFreq_192K
208 };
210 static const Uint16 RateTable_spdif[4] =
212         PAF_SAMPLERATE_44100HZ,  // AudioFreq_44_1K
213         PAF_SAMPLERATE_48000HZ,  // AudioFreq_48K
214         PAF_SAMPLERATE_UNKNOWN,  // AudioFreq_RESERVED
215         PAF_SAMPLERATE_32000HZ,  // HSDIO_AudioFreq_32K
216 };
219 // base mcasp addresses for easy lookup
220 static volatile Uint32 * mcaspAddr[_MCASP_PORT_CNT] =
222     (volatile Uint32 *) _MCASP_BASE_PORT0,
223     (volatile Uint32 *) _MCASP_BASE_PORT1,
224     (volatile Uint32 *) _MCASP_BASE_PORT2
225 };
227 // The DA10x HW is configured for the DAC's mute lines to be operated based
228 // on McASP0's AMUTE (out) line. This is the hard mute.
229 static inline void dacHardMute (void) {
230     volatile Uint32 *mcasp0 = (volatile Uint32 *) _MCASP_BASE_PORT0;
231     mcasp0[_MCASP_PDOUT_OFFSET] |= _MCASP_PDOUT_AMUTE_MASK;
233 static inline void dacHardUnMute (void) {
234     volatile Uint32 *mcasp0 = (volatile Uint32 *) _MCASP_BASE_PORT0;
235     mcasp0[_MCASP_PDOUT_OFFSET] &= ~_MCASP_PDOUT_AMUTE_MASK;
236     mcasp0[_MCASP_AMUTE_OFFSET] |= MCASP_AMUTE_MUTEN_ERRLOW;
239 // How should the PCM18x DAC's soft mute functionality be used here?
240 // i.e, as different from the hard mute? need to review.
241 static inline void dacSoftMute (void) {
242     volatile Uint32 *mcasp0 = (volatile Uint32 *) _MCASP_BASE_PORT0;
243     mcasp0[6] = 0x000 ;
244     mcasp0[6] = 0x400 ;
246 static inline void dacSoftUnMute (void) {
247     volatile Uint32 *mcasp0 = (volatile Uint32 *) _MCASP_BASE_PORT0;
248     mcasp0[6] = 0x000 ;
249     mcasp0[6] = 0x400 ;
252 // -----------------------------------------------------------------------------
253 // McASP Input Configuration Definitions
255 const MCASP_ConfigRcv rxConfigDIR =    // This is used for both DIR and HDMI?? Yes. Same digital format.
257     // The receive format unit bit mask register (RMASK) determines which bits 
258     // of the received data are masked off and padded with a known value before 
259     // being read by the CPU or DMA.
260     MCASP_RMASK_OF(0xFFFFFFFF),     // Don't mask any bits. 0).??
261     // The receive bit stream format register (RFMT) configures the receive data format. 
262     MCASP_RFMT_RMK(      // 0x0001C0F0
263         MCASP_RFMT_RDATDLY_1BIT,    // 17-16: Receive bit delay. Standard I2S configuraiton. MSB first, 1 bit delay.
264         MCASP_RFMT_RRVRS_MSBFIRST,  // 15:    Receive serial bitstream order.
265         MCASP_RFMT_RPAD_RPBIT,      // 14-13: Pad value for extra bits in slot not belonging to the word. N/A because RMASK is 0xFFFFFFFF and no bits need padding.
266         MCASP_RFMT_RPBIT_OF(0),     // 12-8:  RPBIT value determines which bit is used to pad the extra bits. This field only applies when RPAD = 2h. N/A same reason as above.
267         MCASP_RFMT_RSSZ_32BITS,     // 7-4:   Receive slot size. Value is 15.
268         MCASP_RFMT_RBUSEL_DAT,      // 3:     Selects whether reads from serializer buffer XRBUF[n] originate from the configuration bus (CFG) or the data (DAT) port.
269         MCASP_RFMT_RROT_NONE),      // 2-0:   Right-rotation value for receive rotate right format unit.
270     // The receive frame sync control register (AFSRCTL) configures the receive frame sync (AFSR).
271     MCASP_AFSRCTL_RMK(   // 0x00000111
272         MCASP_AFSRCTL_RMOD_OF(2),   // 15-7:  Receive frame sync mode select bits. 2 - 2-slot TDM (I2S mode)
273         MCASP_AFSRCTL_FRWID_WORD,   // 4:     Receive frame sync width. 1 - Single word
274         MCASP_AFSRCTL_FSRM_EXTERNAL,   // 1:  Receive frame sync generation select bit. 0 - Externally-generated receive frame sync
275         MCASP_AFSRCTL_FSRP_ACTIVELOW), // 0:  Receive frame sync polarity select bit. 1 - A falling edge indicates the beginning of a frame.
276     // The receive clock control register (ACLKRCTL) configures the receive bit clock (ACLKR) and the receive clock generator.
277     MCASP_ACLKRCTL_RMK(  // 0x00000080
278         MCASP_ACLKRCTL_CLKRP_RISING,     // 7: Receive bitstream clock polarity select bit. 1 - rising edge. Different from PDK 1.0.1 platform audio test (falling edge)??
279         MCASP_ACLKRCTL_CLKRM_EXTERNAL,   // 5: Receive bit clock source bit.
280         MCASP_ACLKRCTL_CLKRDIV_DEFAULT), // 4-0: Receive bit clock divide ratio bits determine the divide-down ratio from AHCLKR to ACLKR
281     // The receive high-frequency clock control register (AHCLKRCTL) configures the receive high-frequency master clock (AHCLKR) and the receive clock generator.
282     MCASP_AHCLKRCTL_RMK( // 0x00000000
283         MCASP_AHCLKRCTL_HCLKRM_EXTERNAL,   // 15:   Receive high-frequency clock source bit.
284         MCASP_AHCLKRCTL_HCLKRP_RISING,     // 14:   Receive bitstream high-frequency clock polarity select bit. 0 - Rising edge.
285         MCASP_AHCLKRCTL_HCLKRDIV_DEFAULT), // 11-0: Receive high-frequency clock divide ratio bits. 0 - Divide by 1.
286     // The receive TDM time slot register (RTDM) specifies which TDM time slot the receiver is active
287     MCASP_RTDM_OF(3),      // 0x00000003: time slots 0 and 1 are active
288     // The receiver interrupt control register (RINTCTL) controls generation of the McASP receive interrupt (RINT).
289     MCASP_RINTCTL_DEFAULT, // 0x00000000
290     // The receive clock check control register (RCLKCHK) configures the receive clock failure detection circuit.
291     MCASP_RCLKCHK_DEFAULT  // 0x00000000
292 };
294 const MCASP_ConfigRcv rxConfigADC =
296     MCASP_RMASK_OF(0xFFFFFFFF),
297     MCASP_RFMT_RMK(
298         MCASP_RFMT_RDATDLY_1BIT,
299         MCASP_RFMT_RRVRS_MSBFIRST,
300         MCASP_RFMT_RPAD_RPBIT,
301         MCASP_RFMT_RPBIT_OF(0),
302         MCASP_RFMT_RSSZ_32BITS,
303         MCASP_RFMT_RBUSEL_DAT,
304         MCASP_RFMT_RROT_NONE),
305     MCASP_AFSRCTL_RMK(
306         MCASP_AFSRCTL_RMOD_OF(2),
307         MCASP_AFSRCTL_FRWID_WORD,
308         MCASP_AFSRCTL_FSRM_INTERNAL,        // internal
309                 MCASP_AFSRCTL_FSRP_ACTIVEHIGH),     // active high
310     MCASP_ACLKRCTL_RMK(
311         MCASP_ACLKRCTL_CLKRP_RISING,
312         MCASP_ACLKRCTL_CLKRM_INTERNAL,      //
313                 MCASP_ACLKXCTL_CLKXDIV_OF(7)),      //
314     MCASP_AHCLKRCTL_RMK(
315         MCASP_AHCLKRCTL_HCLKRM_INTERNAL,    //
316         MCASP_AHCLKRCTL_HCLKRP_RISING,
317                 MCASP_AHCLKRCTL_HCLKRDIV_DEFAULT),
318     MCASP_RTDM_OF(3),
319     MCASP_RINTCTL_DEFAULT,
320     MCASP_RCLKCHK_DEFAULT
321 };
323 // -----------------------------------------------------------------------------
324 // McASP Output Configuration Definitions
326 const MCASP_ConfigXmt txConfigDAC =
328     MCASP_XMASK_OF(0xFFFFFFFF),
329     MCASP_XFMT_RMK(
330         MCASP_XFMT_XDATDLY_1BIT,
331         MCASP_XFMT_XRVRS_MSBFIRST,
332         MCASP_XFMT_XPAD_ZERO,
333         MCASP_XFMT_XPBIT_DEFAULT,
334         MCASP_XFMT_XSSZ_32BITS,
335         MCASP_XFMT_XBUSEL_DAT,
336                 MCASP_XFMT_XROT_NONE),
337     MCASP_AFSXCTL_RMK(
338         MCASP_AFSXCTL_XMOD_OF(2),
339         MCASP_AFSXCTL_FXWID_WORD,
340         MCASP_AFSXCTL_FSXM_INTERNAL,
341                 MCASP_AFSXCTL_FSXP_ACTIVELOW),
342     MCASP_ACLKXCTL_RMK(
343         MCASP_ACLKXCTL_CLKXP_FALLING,
344         MCASP_ACLKXCTL_ASYNC_ASYNC,
345         MCASP_ACLKXCTL_CLKXM_INTERNAL,
346                 MCASP_ACLKXCTL_CLKXDIV_DEFAULT),
347     MCASP_AHCLKXCTL_RMK(
348         MCASP_AHCLKXCTL_HCLKXM_EXTERNAL,
349         MCASP_AHCLKXCTL_HCLKXP_FALLING,
350         MCASP_AHCLKXCTL_HCLKXDIV_OF(0)),
351     MCASP_XTDM_OF(3),
352     MCASP_XINTCTL_DEFAULT,
353     MCASP_XCLKCHK_DEFAULT
354 };
356 const MCASP_ConfigXmt txConfigDACSlave =
358     MCASP_XMASK_OF(0xFFFFFFFF),
359     MCASP_XFMT_RMK(
360         MCASP_XFMT_XDATDLY_1BIT,
361         MCASP_XFMT_XRVRS_MSBFIRST,
362         MCASP_XFMT_XPAD_ZERO,
363         MCASP_XFMT_XPBIT_DEFAULT,
364         MCASP_XFMT_XSSZ_32BITS,
365         MCASP_XFMT_XBUSEL_DAT,
366                 MCASP_XFMT_XROT_NONE),
367     MCASP_AFSXCTL_RMK(
368         MCASP_AFSXCTL_XMOD_OF(2),
369         MCASP_AFSXCTL_FXWID_WORD,
370         MCASP_AFSXCTL_FSXM_INTERNAL,
371                 MCASP_AFSXCTL_FSXP_ACTIVELOW),
372     MCASP_ACLKXCTL_RMK(
373         MCASP_ACLKXCTL_CLKXP_FALLING,
374         MCASP_ACLKXCTL_ASYNC_ASYNC,
375         MCASP_ACLKXCTL_CLKXM_INTERNAL,
376                 MCASP_ACLKXCTL_CLKXDIV_OF(1)),
377     MCASP_AHCLKXCTL_RMK(
378         MCASP_AHCLKXCTL_HCLKXM_INTERNAL,
379         MCASP_AHCLKXCTL_HCLKXP_FALLING,
380         MCASP_AHCLKXCTL_HCLKXDIV_OF(0)),
381     MCASP_XTDM_OF(3),
382     MCASP_XINTCTL_DEFAULT,
383     MCASP_XCLKCHK_DEFAULT
384 };
386 static const MCASP_ConfigXmt txConfigDIT =
388     MCASP_XMASK_OF(0x00FFFFFF),
389     MCASP_XFMT_RMK(
390         MCASP_XFMT_XDATDLY_1BIT,
391         MCASP_XFMT_XRVRS_LSBFIRST,
392         MCASP_XFMT_XPAD_DEFAULT,
393         MCASP_XFMT_XPBIT_DEFAULT,
394         MCASP_XFMT_XSSZ_32BITS,
395         MCASP_XFMT_XBUSEL_DAT,
396         MCASP_XFMT_XROT_NONE),
397     MCASP_AFSXCTL_RMK(
398         MCASP_AFSXCTL_XMOD_OF(0x180),
399         MCASP_AFSXCTL_FXWID_BIT,
400         MCASP_AFSXCTL_FSXM_INTERNAL,
401         MCASP_AFSXCTL_FSXP_ACTIVEHIGH),
402     MCASP_ACLKXCTL_RMK(
403         MCASP_ACLKXCTL_CLKXP_FALLING,
404         MCASP_ACLKXCTL_ASYNC_ASYNC,
405         MCASP_ACLKXCTL_CLKXM_INTERNAL,
406         MCASP_ACLKXCTL_CLKXDIV_OF(0)),
407     MCASP_AHCLKXCTL_RMK(
408         MCASP_AHCLKXCTL_HCLKXM_EXTERNAL,
409         MCASP_AHCLKXCTL_HCLKXP_FALLING,
410         MCASP_AHCLKXCTL_HCLKXDIV_OF(0)),
411     MCASP_XTDM_OF(0xFFFFFFFF),
412     MCASP_XINTCTL_DEFAULT,
413     MCASP_XCLKCHK_DEFAULT
414 };
416 #if 0
417 static const MCASP_ConfigXmt txConfigDIT_16bit =
419     MCASP_XMASK_OF(0x0000FFFF),
420     MCASP_XFMT_RMK(
421         MCASP_XFMT_XDATDLY_1BIT,
422         MCASP_XFMT_XRVRS_LSBFIRST,
423         MCASP_XFMT_XPAD_DEFAULT,
424         MCASP_XFMT_XPBIT_DEFAULT,
425         MCASP_XFMT_XSSZ_32BITS,
426         MCASP_XFMT_XBUSEL_DAT,
427         MCASP_XFMT_XROT_24BITS),
428     MCASP_AFSXCTL_RMK(
429         MCASP_AFSXCTL_XMOD_OF(0x180),
430         MCASP_AFSXCTL_FXWID_BIT,
431         MCASP_AFSXCTL_FSXM_INTERNAL,
432         MCASP_AFSXCTL_FSXP_ACTIVEHIGH),
433     MCASP_ACLKXCTL_RMK(
434         MCASP_ACLKXCTL_CLKXP_FALLING,
435         MCASP_ACLKXCTL_ASYNC_ASYNC,
436         MCASP_ACLKXCTL_CLKXM_INTERNAL,
437         MCASP_ACLKXCTL_CLKXDIV_OF(0)),
438     MCASP_AHCLKXCTL_RMK(
439         MCASP_AHCLKXCTL_HCLKXM_EXTERNAL,
440         MCASP_AHCLKXCTL_HCLKXP_FALLING,
441         MCASP_AHCLKXCTL_HCLKXDIV_OF(0)),
442     MCASP_XTDM_OF(0xFFFFFFFF),
443     MCASP_XINTCTL_DEFAULT,
444     MCASP_XCLKCHK_DEFAULT
445 };
446 #endif
448 // -----------------------------------------------------------------------------
449 // DAP Input Parameter Definitions
451 const SAP_D10_Rx_Params SAP_D10_RX_DIR =
453     sizeof (SAP_D10_Rx_Params),                 // size
454     "SAP",                                      // name
455     MCASP_DEV2,                                 // moduleNum --> mcasp #
456     //(Void *)&rxConfigDIR,                       // pConfig
457     (Void *)&LLDconfigRxDIR,
458     4,                                         // wordSize (unused)
459     24,                                         // precision (unused)
460     D10_sapControl,                             // control
461     0x00000020,                                 // pinMask
462     (D10_MCLK_DIR << D10_MCLK_SHIFT),                   // mode
463     0,0                                         // unused[2]
464 };
466 const SAP_D10_Rx_Params SAP_D10_RX_ADC_44100HZ =
468     sizeof (SAP_D10_Rx_Params),                 // size
469     "SAP",                                      // name
470     MCASP_DEV1,                                 // moduleNum --> mcasp #
471     //(Void *)&rxConfigADC,                       // pConfig
472     (Void *)&LLDconfigRxADC,
473     4,                                         // wordSize (unused)
474     24,                                         // precision (unused)
475     D10_sapControl,                             // control
476     0xE000000F,                                 // pinMask
477     (D10_RATE_44_1KHZ << D10_RATE_SHIFT) |
478     (D10_MCLK_OSC << D10_MCLK_SHIFT),           // mode
479     0,0                                         // unused[2]
480 };
482 const SAP_D10_Rx_Params SAP_D10_RX_ADC_6CH_44100HZ =
484     sizeof (SAP_D10_Rx_Params),                 // size
485     "SAP",                                      // name
486     MCASP_DEV1,                                 // moduleNum --> mcasp #
487     //(Void *)&rxConfigADC,                       // pConfig
488     (Void *)&LLDconfigRxADC6ch,
489     -1,                                         // wordSize (unused)
490     -1,                                         // precision (unused)
491     D10_sapControl,                             // control
492     0xE0000007,                                 // pinMask
493     (D10_RATE_44_1KHZ << D10_RATE_SHIFT) |
494     (D10_MCLK_OSC << D10_MCLK_SHIFT),           // mode
495     0,0                                         // unused[2]
496 };
498 const SAP_D10_Rx_Params SAP_D10_RX_ADC_STEREO_44100HZ =
500     sizeof (SAP_D10_Rx_Params),                 // size
501     "SAP",                                      // name
502     MCASP_DEV1,                                 // moduleNum --> mcasp #
503     //(Void *)&rxConfigADC,                       // pConfig
504     (Void *)&LLDconfigRxADCStereo,
505     -1,                                         // wordSize (unused)
506     -1,                                         // precision (unused)
507     D10_sapControl,                             // control
508     0xE0000001,                                 // pinMask
509     (D10_RATE_44_1KHZ << D10_RATE_SHIFT) |
510     (D10_MCLK_OSC << D10_MCLK_SHIFT),           // mode
511     0,0                                         // unused[2]
512 };
514 const SAP_D10_Rx_Params SAP_D10_RX_ADC_88200HZ =
516     sizeof (SAP_D10_Rx_Params),                 // size
517     "SAP",                                      // name
518     MCASP_DEV1,                                 // moduleNum --> mcasp #
519     (Void *)&rxConfigADC,                       // pConfig
520     -1,                                         // wordSize (unused)
521     -1,                                         // precision (unused)
522     D10_sapControl,                             // control
523     0xE000000F,                                 // pinMask
524     (D10_RATE_88_2KHZ << D10_RATE_SHIFT) |
525     (D10_MCLK_OSC << D10_MCLK_SHIFT),           // mode
526     0,0                                        // unused[2]
527 };
529 const SAP_D10_Rx_Params SAP_D10_RX_ADC_6CH_88200HZ =
531     sizeof (SAP_D10_Rx_Params),                 // size
532     "SAP",                                      // name
533     MCASP_DEV1,                                 // moduleNum --> mcasp #
534     (Void *)&rxConfigADC,                       // pConfig
535     -1,                                         // wordSize (unused)
536     -1,                                         // precision (unused)
537     D10_sapControl,                             // control
538     0xE0000007,                                 // pinMask
539     (D10_RATE_88_2KHZ << D10_RATE_SHIFT) |
540     (D10_MCLK_OSC << D10_MCLK_SHIFT),           // mode
541     0,0                                        // unused[2]
542 };
544 const SAP_D10_Rx_Params SAP_D10_RX_ADC_STEREO_88200HZ =
546     sizeof (SAP_D10_Rx_Params),                 // size
547     "SAP",                                      // name
548     MCASP_DEV1,                                 // moduleNum --> mcasp #
549     (Void *)&rxConfigADC,                       // pConfig
550     -1,                                         // wordSize (unused)
551     -1,                                         // precision (unused)
552     D10_sapControl,                             // control
553     0xE0000001,                                 // pinMask
554     (D10_RATE_88_2KHZ << D10_RATE_SHIFT) |
555     (D10_MCLK_OSC << D10_MCLK_SHIFT),           // mode
556     0,0                                         // unused[2]
557 };
560 const SAP_D10_Rx_Params SAP_D10_RX_HDMI_STEREO =
562     sizeof (SAP_D10_Rx_Params),                 // size
563     "SAP",                                      // name
564     MCASP_DEV0,                                 // moduleNum --> mcasp #
565     //(Void *)&rxConfigDIR,                     // pConfig
566     (Void *)&LLDconfigRxHDMIStereo,             // pConfig
567     4,                                          // wordSize (unused)
568     -1,                                         // precision (unused)
569     D10_sapControl,                             // control
570     0x00001000,                                 // pinMask
571     (D10_MODE_HDMI << D10_MODE_SHIFT) |
572     (D10_MCLK_HDMI << D10_MCLK_SHIFT),          // mode
573     0,0                                         // unused[2]
574 };
576 const SAP_D10_Rx_Params SAP_D10_RX_HDMI =
578     sizeof (SAP_D10_Rx_Params),                 // size
579     "SAP",                                      // name
580     MCASP_DEV0,                                 // moduleNum --> mcasp #
581 //    (Void *)&rxConfigDIR,                       // pConfig
582     (Void *)&LLDconfigRxHDMI,
583      4,                                         // wordSize (unused)
584     -1,                                         // precision (unused)
585     D10_sapControl,                             // control
586     0x0000F000,                                 // pinMask
587     (D10_MODE_HDMI << D10_MODE_SHIFT) |
588     (D10_MCLK_HDMI << D10_MCLK_SHIFT),           // mode
589     0,0                                         // unused[2]
590 };
592 // -----------------------------------------------------------------------------
593 // SAP Output Parameter Definitions
595 const SAP_D10_Tx_Params SAP_D10_TX_DAC =
597     sizeof (SAP_D10_Tx_Params),                 // size
598     "SAP",                                      // name
599     MCASP_DEV0,                                 // moduleNum --> mcasp #
600     //(Void *)&txConfigDAC,                       // pConfig
601     (Void *)&LLDconfigTxDAC,
602     4,                                          // wordSize (in bytes)
603     24,                                         // precision (in bits)
604     D10_sapControl,                             // control
605     0x1600000F,                                 // pinMask
606         (D10_MCLK_HDMI << D10_MCLK_SHIFT),          // mode
607     0,0,0                                       // unused[3]
608 };
609 /* - SAP_D10_TX_STEREO_DAC is not used
610 const SAP_D10_Tx_Params SAP_D10_TX_STEREO_DAC =
612     sizeof (SAP_D10_Tx_Params),                 // size
613     "SAP",                                      // name
614     MCASP_DEV0,                                 // moduleNum --> mcasp #
615     (Void *)&txConfigDAC,                       // pConfig
616     4,                                          // wordSize (in bytes)
617     24,                                         // precision (in bits)
618     D10_sapControl,                             // control
619     0x16000001,                                 // pinMask
620     0,                                          // mode
621     0,0,0                                       // unused[3]
622 };
623 */
624 const SAP_D10_Tx_Params SAP_D10_TX_DIT =
626     sizeof (SAP_D10_Tx_Params),                 // size
627     "SAP",                                      // name
628     MCASP_DEV2,                                 // moduleNum --> mcasp #
629     (Void *) &txConfigDIT,                      // pConfig
630     3,                                          // wordSize (in bytes)
631     24,                                         // precision (in bits)
632     D10_sapControl,                             // control
633     0x1C000001,                                 // pinMask
634     0,                                          // mode
635     0,0,0                                       // unused[3]
636 };
638 const SAP_D10_Tx_Params SAP_D10_TX_DAC_SLAVE =
640     sizeof (SAP_D10_Tx_Params),                 // size
641     "SAP",                                      // name
642     MCASP_DEV0,                                 // moduleNum --> mcasp #
643     //(Void *)&txConfigDACSlave,                       // pConfig
644     (Void *)&LLDconfigTxDACSlave,
645     4,                                          // wordSize (in bytes)
646     24,                                         // precision (in bits)
647     D10_sapControl,                             // control
648     0x1E00000F,                                                                 // pinMask
649     (D10_MCLK_OSC << D10_MCLK_SHIFT),           // mode
650     0,0,0                                       // unused[3]
651 };
653 const SAP_D10_Tx_Params SAP_D10_TX_STEREO_DAC_SLAVE =
655     sizeof (SAP_D10_Tx_Params),                 // size
656     "SAP",                                      // name
657     MCASP_DEV0,                                 // moduleNum --> mcasp #
658     //(Void *)&txConfigDAC,                       // pConfig
659     (Void *)&LLDconfigTxDACStereoSlave,
660     4,                                          // wordSize (in bytes)
661     24,                                         // precision (in bits)
662     D10_sapControl,                             // control
663     0x16000001,                                 // pinMask
664     0,                                          // mode
665     0,0,0                                       // unused[3]
666 };
668 const SAP_D10_Tx_Params SAP_D10_TX_DAC_12CH =
670     sizeof (SAP_D10_Tx_Params),                 // size
671     "SAP",                                      // name
672     MCASP_DEV0,                                 // moduleNum --> mcasp #
673     //(Void *)&txConfigDAC,                       // pConfig
674     (Void *)&LLDconfigTxDAC12ch,
675     4,                                          // wordSize (in bytes)
676     24,                                         // precision (in bits)
677     D10_sapControl,                             // control
678     0x1600003F,                                 // pinMask
679     (D10_MCLK_HDMI << D10_MCLK_SHIFT),          // mode
680     0,0,0                                       // unused[3]
681 };
683 const SAP_D10_Tx_Params SAP_D10_TX_DAC_16CH =
685     sizeof (SAP_D10_Tx_Params),                 // size
686     "SAP",                                      // name
687     MCASP_DEV0,                                 // moduleNum --> mcasp #
688     //(Void *)&txConfigDAC,                       // pConfig
689     (Void *)&LLDconfigTxDAC16ch,
690     4,                                          // wordSize (in bytes)
691     24,                                         // precision (in bits)
692     D10_sapControl,                             // control
693     0x160000FF,                                 // pinMask
694     (D10_MCLK_HDMI << D10_MCLK_SHIFT),          // mode
695     0,0,0                                       // unused[3]
696 };
699 // -----------------------------------------------------------------------------
700 // One time initialization of the DA10x audio hardware.
702 /* DAC default configuration parameters */
703 DacConfig  dacCfg =
705         AUD_DAC_AMUTE_CTRL_SCKI_LOST,       /* Amute event */
706         0,                                  /* Amute control */
707         AUD_DAC_SAMPLING_MODE_SINGLE_RATE,  /* Sampling mode */
708         AUD_DAC_DATA_FORMAT_I2S,            /* Data format */
709         0,                                  /* Soft mute control */
710         AUD_DAC_ATTENUATION_WIDE_RANGE,     /* Attenuation mode */
711         AUD_DAC_DEEMP_44KHZ,                /* De-emph control */
712         100                                 /* Volume */
713 };
714 /* ADC default configuration parameters */
715 AdcConfig adcCfg =
717         90,                      /* ADC gain */
718         AUD_ADC_INL_SE_VINL1,    /* Left input mux for ADC1L */
719         AUD_ADC_INL_SE_VINL2,    /* Left input mux for ADC2L */
720         AUD_ADC_INR_SE_VINR1,    /* Right input mux for ADC1R */
721         AUD_ADC_INR_SE_VINR2,    /* Right input mux for ADC2R */
722         AUD_ADC_RX_WLEN_24BIT,   /* ADC word length */
723         AUD_ADC_DATA_FORMAT_I2S, /* ADC data format */
724         0
725 };
727 Aud_STATUS setAudioDacConfig(void)
729         Aud_STATUS status;
731         /* Initialize Audio DAC module */
732         status = audioDacConfig(AUD_DAC_DEVICE_ALL, &dacCfg); // defined in sap\audio_dc_cfg.c
733         if (status)
734                 Log_info0("SAP_D10: Audio DAC Configuration Failed!!!\n");
735         return status;
739 // Configure GPIO for HSR HDMI signaling. This needs to be added to aud_AudioInit()
740 // in ti\addon\aud\src\aud.c.
741 Aud_STATUS aud_AudioInit_Extra()
743         /* Configure GPIO for HSR HDMI Signaling - GPIO0 104 (~RESET) & 105 (~HMINT) */
744         aud_pinMuxSetMode(114, AUD_PADCONFIG_MUX_MODE_QUATERNARY);
745         aud_gpioSetDirection(AUD_GPIO_PORT_0, AUD_AUDIO_HSR_HMINTz_GPIO, AUD_GPIO_IN);
747         aud_pinMuxSetMode(113, AUD_PADCONFIG_MUX_MODE_QUATERNARY);
748         aud_gpioSetDirection(AUD_GPIO_PORT_0, AUD_AUDIO_HSR_RESETz_GPIO, AUD_GPIO_OUT);
749         aud_gpioSetOutput(AUD_GPIO_PORT_0, AUD_AUDIO_HSR_RESETz_GPIO);
751         return Aud_EOK;
754 static inline XDAS_Int32 initD10 (DEV2_Handle device)
756         Aud_STATUS status = Aud_EOK;
758         /* Initialize common audio configurations */
759         status = aud_AudioInit(); // defined in in ti\addon\aud\src\aud.c
760         if(status != Aud_EOK)
761         {
762                 Log_info0("aud_AudioInit Failed!\n");
763                 return status;
764         }
765         else
766                 Log_info0("aud_AudioInit Passed!\n");
768         status = (Aud_STATUS)aud_AudioInit_Extra();
769         if(status != Aud_EOK)
770         {
771                 Log_info0("aud_AudioInit_Extra Failed!\n");
772                 return status;
773         }
774         else
775                 Log_info0("aud_AudioInit_Extra Passed!\n");
777         /* Initialize Audio ADC module */
778         status = audioAdcConfig(AUD_ADC_DEVICE_ALL, &adcCfg);
779         if(status != Aud_EOK)
780         {
781                 Log_info0("Audio ADC Configuration Failed!\n");
782                 return status;
783         }
784         else
785                 Log_info0("Audio ADC Configuration Passed!\n");
787         /* Setup DIR 9001 for SPDIF input operation */
788         //status = platformAudioSelectClkSrc(AUDIO_CLK_SRC_DIR);
789         status = audioDirConfig();
790         if(status != Aud_EOK)
791         {
792                 Log_info0("Audio DIR Init Failed!\n");
793                 return status;
794         }
795         else
796                 Log_info0("Audio DIR Init Passed!\n");
798 #if 1
799         /* Setup HSR41 for HDMI input operation */
800         //status = platformAudioSelectClkSrc(AUDIO_CLK_SRC_I2S);
801         /* Initialize the HDMI Card      */
802     while(HDMIGpioGetState());
803         status = audioHDMIConfig();
804         if(status != Aud_EOK)
805         {
806                 Log_info0("Audio HDMI Init Failed!\n");
807                 return status;
808         }
809         else
810                 Log_info0("Audio HDMI Init Passed!\n");
811 #endif
813         status = aud_AudioSelectClkSrc(AUD_AUDIO_CLK_SRC_DIR);
814         aud_delay(50000); // Without delay between these 2 calls system aborts.
815         status = setAudioDacConfig();
817         Log_info1("Leaving initD10 with status = %d", status);
819     return status;
821 } //initD10
823 // -----------------------------------------------------------------------------
824 // The McASP TX section is *only* used as a master clock mux.
825 // Mux functionality is achieved by selecting either  external high
826 // speed clocks (DIR/HDMI) or the internal AUXCLK (Audio_OSC). This is divided down
827 // output via ACLKX0 which is connected to the high speed input
828 // of TX0 (DAC) and TX2 (DIT).
829 static XDAS_Int32 clockMuxTx (int sel, int force)
831         Aud_STATUS status = 0;
832     // select clkxDiv table
833     if (sel == D10_MCLK_DIR)
834     {
835         status = aud_AudioSelectClkSrc(AUD_AUDIO_CLK_SRC_DIR);
836         pClkxDiv = (unsigned char *) clkxDivDIR;
837     }
838     else if (sel == D10_MCLK_HDMI)
839     {
840         status = aud_AudioSelectClkSrc(AUD_AUDIO_CLK_SRC_I2S);
841         pClkxDiv = (unsigned char *) clkxDivHDMI;
842     }
843     else if (sel == D10_MCLK_OSC)
844     {
845         status = aud_AudioSelectClkSrc((AudAudioClkSrc)AUD_AUDIO_CLK_SRC_OSC);
846         pClkxDiv = (unsigned char *) clkxDivADC;
847         }
848     Log_info1("SAP_D10: Inside clockMuxTx with sel = %d", sel);
850     aud_delay(20000);
852     return status;
853 } //clockMuxTx
856 // -----------------------------------------------------------------------------
857 // This function returns the input status of the specified device.
858 // This is called once when the device is opened
859 // (PAF_SIO_CONTROL_OPEN) and periodically thereafter
860 // (PAF_SIO_CONTROL_GET_INPUT_STATUS).
861 int gHmint_ctr = 0, gNonAudio = 0, gLockStatus=0, gPrevAudio=0, gPrevLock=0;
862 int gSync_ctr, gLock_ctr, gAudioErr_ctr, gNonAudio_ctr = 0;
864 static int manageInput (DEV2_Handle device, const SAP_D10_Rx_Params *pParams, PAF_SIO_InputStatus *pStatusOut)
866     PAF_SIO_InputStatus *pStatusIn = &primaryStatus;
867     //volatile Uint32 *mcasp0 = (volatile Uint32 *) _MCASP_BASE_PORT0;
868     //volatile Uint32 *mcasp1 = (volatile Uint32 *) _MCASP_BASE_PORT1;
869     //volatile Uint32 *mcasp2 = (volatile Uint32 *) _MCASP_BASE_PORT2;
871         //Platform_STATUS status;
873     static int PrevSampRate = 0;
874         int RateHdmi =0;
876         /* Mode & MCLK info embedded statically in the Rx IO definition for SPDIF Input */
877     if ((((pParams->d10rx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT) == D10_MCLK_DIR) &
878         (((pParams->d10rx.mode & D10_MODE_MASK) >> D10_MODE_SHIFT) == D10_MODE_STD))
879     {
880         pStatusIn->lock = !(aud_AudioDirGetClkStatus());
881         pStatusIn->nonaudio = !(aud_AudioDirGetAudioStatus());
882         pStatusIn->emphasis = aud_AudioDirGetEmphStatus();
883         pStatusIn->sampleRateMeasured = RateTable_spdif[aud_AudioDirGetFsOut()];
884                 pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
885                 PrevSampRate = pStatusIn->sampleRateMeasured;
887                 // GJ: Is this needed? Probably not.
888                 // GJ: Mute Control during input-change seemingly intended.
889         //mcasp0[_MCASP_PDOUT_OFFSET] = 0x000 ;
890         //mcasp0[_MCASP_PDOUT_OFFSET] = 0x400 ;
892     }
893     /* Mode & MCLK info embedded statically in the Rx IO definition for ANALOG/ADC Input */
894     else if ((((pParams->d10rx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT) == D10_MCLK_OSC) &
895              (((pParams->d10rx.mode & D10_MODE_MASK) >> D10_MODE_SHIFT) == D10_MODE_STD)) {
896         int adcRate = (pParams->d10rx.mode & D10_RATE_MASK) >> D10_RATE_SHIFT;
898         pStatusIn->lock = 1;
899         pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_AUDIO;
900         pStatusIn->emphasis = PAF_IEC_PREEMPHASIS_NO;
901         pStatusIn->sampleRateMeasured = oscRateTable[adcRate];
902         pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
904     }
905     /* Mode & MCLK info embedded statically in the Rx IO definition for HDMI */
906     else if ((((pParams->d10rx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT) == D10_MCLK_HDMI) &
907              (((pParams->d10rx.mode & D10_MODE_MASK) >> D10_MODE_SHIFT) == D10_MODE_HDMI))
908     {
910         pStatusIn->emphasis = PAF_IEC_PREEMPHASIS_NO;
912 #ifndef ___ENABLE_BENCHMARK_PCMHSR_SRC_CAR_  //TODO: For all the cases it works. 
913         //
914         // Input interface rate hard-coded to 192 kHz to avoid I2C transactions.
915         // Temporary fix works for EC3 and MLP/MAT formats.
916         //
917         pStatusIn->lock = 1;
918         pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_AUDIO;
919         /*RateHdmi = HSDIO_AudioFreq_192K;
920         pStatusIn->sampleRateMeasured = RateTable_hdmi[RateHdmi];
921         pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured; */
922         if(!HDMIGpioGetState())
923                 {
924                         clear_hdmi_hmint();
925                         gHmint_ctr++;
927                         RateHdmi=read_hdmi_samprate();
928                         pStatusIn->sampleRateMeasured = RateTable_hdmi[RateHdmi];
929                         pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
930                         PrevSampRate = pStatusIn->sampleRateMeasured;
931                 }
932         else
933                 {
934                         pStatusIn->sampleRateMeasured = PrevSampRate;
935                         pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
936                 }
937 #else // _ENABLE_BENCHMARK_PCMHSR_SRC_CAR_
938         //
939         // Need to update input interface rate by consulting HSR4 over I2C for benchmarking configuration.
940         //
941         if(!HDMIGpioGetState())
942         {
943                 clear_hdmi_hmint();
944                 gHmint_ctr++;
946                 RateHdmi=read_hdmi_samprate();
947                         pStatusIn->sampleRateMeasured = RateTable_hdmi[RateHdmi];
948                         pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
949                         PrevSampRate = pStatusIn->sampleRateMeasured;
950 /*
951                 switch(read_hdmi_errstatus())
952                         {
953                                 case HSDIO_AudioErr_NO_ERROR:
954                                 {
955                                         gPrevLock=pStatusIn->lock;
956                                         gPrevAudio=pStatusIn->nonaudio;
957                                         pStatusIn->lock = 1;
958                                         pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_AUDIO;
959                                         break;
960                                 }
961                                 case HSDIO_AudioErr_AUDIO_NO_PLL_LOCK:
962                                 {
963                                         gLock_ctr++;
964                                         pStatusIn->lock = 0;
965                                         //pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_AUDIO;
966                                         break;
967                                 }
968                                 case HSDIO_AudioErr_AUDIO_NO_AUDIO:
969                                 {
970                                         gAudioErr_ctr++;
971                                         //pStatusIn->lock = 1;
972                                         pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_NONAUDIO;
973                                         break;
974                                 }
975                                 default:
976                                         while(1);               // Control shouldn't be here.
977                         }
979                 if(HSDIO_AudioMClk_128X != read_hdmi_clockstatus())
980                 {
981                         gLock_ctr++;
982                         pStatusIn->lock = 0;
983                 }
984                 else if (HSDIO_AudioPresent_HAS_AUDIO != read_hdmi_audiostatus())
985                         {
986                                 gNonAudio_ctr++;
987                                 pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_NONAUDIO;
988                         }*/
989                         
990         }
991         else
992         {
993                 pStatusIn->sampleRateMeasured = PrevSampRate;
994                 pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
995         }
996 #endif // _ENABLE_BENCHMARK_PCMHSR_SRC_CAR_
997         }
999     else
1000        return -1;               // Control shouldn't be here!
1002     gNonAudio=pStatusIn->nonaudio;
1003     gLockStatus=pStatusIn->lock;
1005     // update another status if requested
1006     if (pStatusOut)
1007         *pStatusOut = *pStatusIn;
1009     return 0;
1010 } //manageInput
1013 // -----------------------------------------------------------------------------
1014 // This function configures the McASP TX clock dividers based on the
1015 // master clock rate. This is called once when the device is opened
1016 // (PAF_SIO_CONTROL_OPEN) and periodically thereafter (PAF_SIO_CONTROL_SET_RATEX).
1018 static int manageOutput (DEV2_Handle device, const SAP_D10_Tx_Params *pParams, float rateX)
1020     volatile Uint32 *mcasp = mcaspAddr[pParams->sio.moduleNum];
1021     PAF_SIO_InputStatus *pStatusIn = &primaryStatus;
1022     Uint32 divider;
1025     if (!pClkxDiv)
1026         return SIO2_EINVAL;
1028     // set clock divider
1029     if (rateX < .354)
1030         rateX = 0.25;
1031     else if (rateX < .707)
1032         rateX = 0.50;
1033     else if (rateX < 1.6)
1034         rateX = 1.00;
1035     else if (rateX < 2.828)
1036         rateX = 2.00;
1037     else
1038         rateX = 4.00;
1039     // if asynchronous then force clock change (assumes osc master)
1040     /*if (pParams->d10tx.mode & D10_SYNC_MASK) {
1041         int dacRate = (pParams->d10tx.mode & D10_RATE_MASK) >> D10_RATE_SHIFT;
1042         divider = pClkxDiv[oscRateTable[dacRate]];
1043     }
1044     else*/
1045         divider = pClkxDiv[pStatusIn->sampleRateMeasured];
1046     divider /= rateX;
1048     Log_info3("SAP_D10: Inside manageOutput with divider = %d, rateX = %f & input_rate = %d", divider, rateX, pStatusIn->sampleRateMeasured);
1050     // DIT requires 2x clock
1051     if ((mcasp[_MCASP_AFSXCTL_OFFSET] & _MCASP_AFSXCTL_XMOD_MASK) ==
1052         (MCASP_AFSXCTL_XMOD_OF(0x180) << _MCASP_AFSXCTL_XMOD_SHIFT)) {
1053         if (divider < 2)
1054             return (SIO2_EINVAL);
1055         divider >>= 1;
1056     }
1058         mcasp[_MCASP_ACLKXCTL_OFFSET] =
1059          (mcasp[_MCASP_ACLKXCTL_OFFSET] & ~_MCASP_ACLKXCTL_CLKXDIV_MASK) |
1060      (MCASP_ACLKXCTL_CLKXDIV_OF(divider-1) << _MCASP_ACLKXCTL_CLKXDIV_SHIFT);
1061            return 0;
1062 } //manageOutput
1064 // -----------------------------------------------------------------------------
1065 // This function is called by the peripheral driver (DAP) in response to
1066 // various SIO_ctrl() calls made by the framework.
1068 XDAS_Int32 D10_sapControl (DEV2_Handle device, const PAF_SIO_Params *pParams, XDAS_Int32 code, XDAS_Int32 arg)
1070     const SAP_D10_Rx_Params *pDapD10RxParams = (const SAP_D10_Rx_Params *)pParams;
1071     const SAP_D10_Tx_Params *pDapD10TxParams = (const SAP_D10_Tx_Params *)pParams;
1072     //Platform_STATUS status;
1074     volatile Uint32 *mcasp = mcaspAddr[pParams->sio.moduleNum];
1075     XDAS_Int32 result = 0;
1077     // perform one time hardware initialization
1078     if (!initDone) {
1079         result = initD10 (device);
1080                 if (result)
1081             return result;
1082         initDone = 1;
1083     }
1085     switch (code) {
1087 // .............................................................................
1088 // This case provides a regular entry point for managing the specified
1089 // input device. Nominally, this is used to provide lock and sample rate
1090 // status to the framework.
1092         case PAF_SIO_CONTROL_GET_INPUT_STATUS:
1093             if (device->mode != DEV2_INPUT)
1094                 return SIO2_EINVAL;
1095                         
1096             manageInput (device, pDapD10RxParams, (PAF_SIO_InputStatus *) arg);
1097             break;
1099 // .............................................................................
1100 // This case provides a regular entry point for managing the specified
1101 // output device. Nominally this is used to change the output clock dividers
1102 // in the case of double rate output (e.g. DTS 96/24).
1104         case PAF_SIO_CONTROL_SET_RATEX:
1105             // Support only output rate control, for now
1106             if (device->mode != DEV2_OUTPUT)
1107                 return (SIO2_EINVAL);
1109             // configure clock divider (bit and frame clocks)
1110             manageOutput (device, pDapD10TxParams, *((float *) arg));
1111             break;
1113 // .............................................................................
1114 // This case is called once when the device is opened/allocated by the framework.
1115 // Here, for both input and output, this allows for configuring all needed
1116 // clocks for proper operation.
1118         case PAF_SIO_CONTROL_OPEN:
1119             if (device->mode == DEV2_INPUT) {
1120                         
1121                 // determine the master clock based on the mode element of the
1122                 // parameter configuration.
1123                 int sel = (pDapD10RxParams->d10rx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT;
1124                 manageInput (device, pDapD10RxParams, NULL);
1126                 // select appropriate master clock (but dont force)
1128                 clockMuxTx (sel, -1);
1130             }
1131             else {
1133                     // Since DAC is a slave to the chosen input, operate the clksel switch appropriately
1134                     // Also, this is a create-time (i.e, CTRL_OPEN) only call & not appropriate under
1135                     // the periodic manage_output calls.
1136                     int sel = (pDapD10TxParams->d10tx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT;
1137                     clockMuxTx (sel, -1);
1138                     aud_delay(50000); // GJ REVISIT: Without delay between Tx McASP & DAC configs, system aborts.
1139                     setAudioDacConfig();
1140                                         dacHardUnMute ();
1142                 // configure clock divider (bit and frame clocks)
1143                 manageOutput (device, pDapD10TxParams, 1.0);
1144             }
1145             break;
1147 // .............................................................................
1148 // This case is called once when the device is closed/freed by the framework.
1150         case PAF_SIO_CONTROL_CLOSE:
1151             // If TX0 then signal it is no longer in use by the DACs and
1152             // configure manually to generate ADC clocks. Also hard mute
1153             // the DACs since they are not in use.
1154             if ((device->mode == DEV2_OUTPUT) && (pParams->sio.moduleNum == MCASP_DEV0)) {
1155                
1156                 dacHardMute ();
1158                 // if async then clear forced clock mux
1159                 // if asynchronous then force clock change
1160                 if (pDapD10TxParams->d10tx.mode & D10_SYNC_MASK)
1161                     clockMuxTx (0, 0);
1162             }
1163             break;
1165 // .............................................................................
1166 // These cases are called as appropriate by the framework when there is
1167 // valid output data (UNMUTE) or no valid output (MUTE).
1169         case PAF_SIO_CONTROL_MUTE:
1170             if ((device->mode == DEV2_OUTPUT) && (pParams->sio.moduleNum == MCASP_DEV0))
1171                 dacSoftMute ();
1172             break;
1174         case PAF_SIO_CONTROL_UNMUTE:
1175             if ((device->mode == DEV2_OUTPUT) && (pParams->sio.moduleNum == MCASP_DEV0))
1176                 dacSoftUnMute ();
1177             break;
1179 // .............................................................................
1180 // This case is called when the device is idled.
1181 // There is no specific handling -- but needed to avoid error return.
1183         case PAF_SIO_CONTROL_IDLE:
1184             break;
1186 // .............................................................................
1187 // Called from the IDL Loop to allow for clock management and the like
1188 // The call is protected by a TSK_disable and HWI_disable so it is safe
1189 // to read/write shared resources.
1191         case PAF_SIO_CONTROL_WATCHDOG:
1192             // call manageInput in case the sample rate has changed resulting
1193             // in no output clocks which may have blocked the audio processing
1194             // thread. This call will reconfigure the AK4588 and restart the clocks.
1195             if (device->mode == DEV2_INPUT)
1196                 manageInput (device, pDapD10RxParams, (PAF_SIO_InputStatus *) arg);
1197             break;
1199 // .............................................................................
1200 // Called from DOB_issue to allow for different values of the channel status
1201 // fields of the SPDIF output.
1203         case PAF_SIO_CONTROL_SET_DITSTATUS:
1204             // No action necessary.
1205             break;
1207         case PAF_SIO_CONTROL_SET_WORDSIZE:
1208                 if(((pDapD10RxParams->d10rx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT) != D10_MCLK_OSC)
1209                 {
1210                 if ((device->mode == DEV2_INPUT) && (arg == 2))
1211                 {
1212                         Log_info0("Inside SAP_D10Control PAF_SIO_CONTROL_SET_WORDSIZE for arg=2");
1213                         mcasp[_MCASP_RFMT_OFFSET] = (mcasp[_MCASP_RFMT_OFFSET] & ~_MCASP_RFMT_RROT_MASK) | MCASP_RFMT_RROT_16BITS;
1214                 }
1215                 else if ((device->mode == DEV2_INPUT) && (arg == 4))
1216                 {
1217                         Log_info0("Inside SAP_D10Control PAF_SIO_CONTROL_SET_WORDSIZE for arg=4");
1218                                 mcasp[_MCASP_RFMT_OFFSET] = (mcasp[_MCASP_RFMT_OFFSET] & ~_MCASP_RFMT_RROT_MASK) | MCASP_RFMT_RROT_NONE;
1219                 }
1220                 }
1221                         break;
1222 // .............................................................................
1223 // Any other cases are not handled and return an error.
1225         default:
1226             return SIO2_EINVAL;
1227     }
1229     return result;
1230 } //D10_sapControl
1232 // -----------------------------------------------------------------------------
1235 unsigned int HDMIGpioGetState (void) {
1236         return(aud_gpioReadInput(AUD_GPIO_PORT_0, AUD_AUDIO_HSR_HMINTz_GPIO));
1239 void setD10ClkMux(UInt16 mode)
1241     int sel = (mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT;
1243     // select appropriate master clock
1244     clockMuxTx (sel, 0);
1247 XDAS_Int32 D10_init(void *pD10Params)
1249     XDAS_Int32 result = 0;
1250     SAP_D10_Rx_Params *pD10RxParams;
1252     // perform one time hardware initialization
1253     if (!initDone) {
1254         result = initD10 (NULL);
1255         if (result) {
1256             return result;
1257         }
1258         initDone = 1;
1259     }
1261     pD10RxParams = (SAP_D10_Rx_Params *)pD10Params;
1262     setD10ClkMux(pD10RxParams->d10rx.mode);
1264     return result;
1267 XDAS_Int32 D10_RxControl(const void *pD10RxParams,
1268                          XDAS_Int32 code, XDAS_Int32 arg)
1270     XDAS_Int32 result = 0;
1272     switch (code) {
1273         case PAF_SIO_CONTROL_GET_INPUT_STATUS:
1274             manageInput(NULL, (const SAP_D10_Rx_Params *)pD10RxParams,
1275                         (PAF_SIO_InputStatus *)arg);
1276         break;
1278         default:
1279         break;
1280     }
1282     return result;
1285 // EOF