]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - psdk_cust/pdk_k2g_1_0_1_1_eng/packages/ti/board/diag/hdmi/src/evmk2g_hdmi.c
Modified messaging code after code review.
[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_1_eng / packages / ti / board / diag / hdmi / src / evmk2g_hdmi.c
1 /*
2  * Copyright (c) 2016, 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  *
36  * \file    evmk2g_hdmi.c
37  *
38  * \brief   This file contains the hdmi functions
39  *
40  ******************************************************************************/
42 #include "platform_internal.h"
43 #include "board_internal.h"
45 #include <ti/drv/i2c/I2C.h>
46 #include <ti/drv/i2c/soc/I2C_soc.h>
48 #include <ti/drv/gpio/GPIO.h>
49 #include <ti/csl/soc.h>
50 #include <ti/drv/gpio/soc/GPIO_soc.h>
52 /* Port and pin number mask for HDMI enable and interrupt pins.
53    Bits 7-0: Pin number  and Bits 15-8: Port number */
54 #define GPIO_HDMI_ENABLE    (HDMI_ENABLE_GPIO_PIN | (HDMI_ENABLE_GPIO_INSTANCE << 8))
55 #define GPIO_HDMI_INT       (HDMI_INT_GPIO_PIN | (HDMI_INT_GPIO_INSTANCE << 8))
57 /* GPIO Driver board specific pin configuration structure */
58 GPIO_PinConfig gpioPinConfigs[] = {
59         GPIO_HDMI_ENABLE | GPIO_CFG_OUTPUT,
60         GPIO_HDMI_INT | GPIO_CFG_INPUT
61 };
63 /* GPIO Driver call back functions */
64 GPIO_CallbackFxn gpioCallbackFunctions[] = {
65     NULL,
66     NULL
67 };
69 /* GPIO Driver configuration structure */
70 GPIO_v0_Config GPIO_v0_config = {
71     gpioPinConfigs,
72     gpioCallbackFunctions,
73     sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
74     sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
75     0,
76 };
78 static I2C_Params hdmiI2cParams;
79 static I2C_Handle hdmiI2cHandle = NULL;
81 /******************************************************************************
82  **                          GLOBAL DEFINITIONS
83  ******************************************************************************/
85 static uint8_t audioInfoFrame[15] = {
86         0xC2,    /* Audio InfoFrame Enable required for the HDMI Transmitter
87                     (programs register 0xBF) */
88         0x84,    /* frame type */
89         0x01,    /* version */
90         0x0A,    /* length */
91         0x00,    /* cksum */
92         HDMI_SH_PCM | HDMI_SH_TWO_CHANNELS,
93         HDMI_SH_44KHz | HDMI_SH_16BIT,
94         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
95 };
97 static uint8_t hdmi_reg_defs[] = {
98                 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
99                 0x06, 0x07, 0x08, 0x09, 0x0A, 0x1A,
100                 0x1B, 0x1E, 0x1F, 0x20, 0x21, 0x22,
101                 0x23, 0x24,     0x25, 0x26, 0x27, 0x29,
102                 0x2A, 0xBC, 0xBD, 0xBE, 0xC7};
105 /******************************************************************************
106  **                      INTERNAL FUNCTION DEFINITIONS
107  ******************************************************************************/
109 /**
110  *
111  * \brief    This function is used to write the data onto HDMI chip.
112  *
113  * \param    reg   [IN]  : HDMI register to write.
114  * \param    data  [IN]  : Data to be written into the register.
115  *
116  * \return   HDMI_SUCCESS       - On Success.
117  *           HDMI_ERR           - On Failure.
118  *
119  */
120 static int8_t hdmiWrite(uint8_t reg, uint8_t data)
122         I2C_Transaction i2cTransaction;
123         uint8_t slaveData[2];
124         bool ret;
126         slaveData[0] = reg;
127         slaveData[1] = data;
129     i2cTransaction.slaveAddress = HDMI_SLAVE_ADDR;
130     i2cTransaction.writeBuf     = (uint8_t *)&slaveData[0];
131     i2cTransaction.writeCount   = 2;
132     i2cTransaction.readCount    = 0;
134         /* Delay of 1 milli sec */
135         platform_delay(1000);
137         ret = I2C_transfer(hdmiI2cHandle, &i2cTransaction);
138         if (!ret) {
139                 IFPRINT(UART_printf("hdmiWrite: i2c Write error : ret = %d\n", ret));
140                 return (HDMI_ERR);
141         }
143         return (HDMI_SUCCESS);
146 /**
147  *
148  * \brief    This function is used to read the data from HDMI chip.
149  *
150  * \param    reg     [IN]       : Register to read the data.
151  * \param    data    [IN]       : Pointer to store the data read.
152  * \param    dataLen [IN]       : Length of the data to be read in bytes.
153  *
154  * \return   HDMI_SUCCESS       - On Success.
155  *           HDMI_ERR           - On Failure.
156  *
157  */
158 static int8_t hdmiRead(uint32_t reg, uint8_t *data, uint32_t dataLen)
160         I2C_Transaction i2cTransaction;
161         uint8_t txData[2];
162         bool ret;
164         txData[0] = reg;
166     i2cTransaction.slaveAddress = HDMI_SLAVE_ADDR;
167     i2cTransaction.writeBuf     = &txData[0];
168     i2cTransaction.writeCount   = 1;
169     i2cTransaction.readBuf      = data;
170     i2cTransaction.readCount    = 1;
172         ret = I2C_transfer(hdmiI2cHandle, &i2cTransaction);
173         if (!ret) {
174                 IFPRINT(UART_printf("hdmiRead: i2c Read error : read = %d\n", ret));
175                 return (HDMI_ERR);
176         }
178         return (HDMI_SUCCESS);
181 /**
182  *
183  * \brief    This function is used to mute or unmute the HDMI audio.
184  *
185  * \param    mute [IN]          : Mute/Unmute HDMI Audio.
186  *           HDMI_AUDIO_UNMUTE  : Unmute.
187  *           HDMI_AUDIO_MUTE    : Mute.
188  *
189  * \return   HDMI_SUCCESS       - On Success
190  *           HDMI_ERR           - On Failure
191  *
192  */
193 static int8_t hdmiAudioMute(uint8_t mute)
195         int8_t ret;
197         if (!mute) {
198         /* I2S, UnMute, PCM */
199                 ret = hdmiWrite(HDMI_REG_26, 0x81);
200                 if (ret) {
201                         goto err;
202                 }
203         }
204         else {
205                 /* I2S, Mute, PCM */
206                 ret = hdmiWrite(HDMI_REG_26, 0x91);
207         }
209 err :
210         return (ret);
213 /**
214  *
215  * \brief    This function is used to initialize HDMI Audio
216  *
217  * \return   HDMI_SUCCESS       - On Success.
218  *           HDMI_ERR           - On Failure.
219  *
220  */
221 static int8_t hdmiAudioSetup(void)
223         int8_t ret;
224         uint8_t val;
225         uint8_t ckSum;
226         uint8_t i;
227         uint8_t miscInfoFrameDataStart;
229         /* Power Up Transistor set to D0 power state 00 to 0x1E address */
230         val = 0;
231         ret = hdmiWrite(HDMI_TPI_POWER_STATE_CTRL_REG, val);
232         if (ret) {
233                 goto err;
234         }
236         /* security HDCP disabled */
237         ret = hdmiWrite(HDMI_TPI_HDCP_CONTROLDATA_REG, val);
238         if (ret) {
239                 goto err;
240         }
242         /* Delay of 64 milli sec */
243         platform_delay(64000);
245         do
246         {
247                 ret = hdmiRead(HDMI_TPI_HDCP_QUERYDATA_REG, &val, 1);
248                 if (ret) {
249                         goto err;
250                 }
251         } while(!((val & 0xF0) == 0x00));
253         /* Disable TMDS output, select HDMI */
254         val = 0x11;
255         ret = hdmiWrite(HDMI_SYS_CTRL_DATA_REG, val);
256         if (ret) {
257                 goto err;
258         }
260         /* Delay of 128 milli sec */
261         platform_delay(128000);
263         ret = hdmiRead(HDMI_SYS_CTRL_DATA_REG, &val, 1);
264         if (ret) {
265                 goto err;
266         }
267         IFPRINT (UART_printf("HDMI_SYS_CTRL_DATA_REG = 0x%x\n", val));
269         /* Mute audio */
270         ret = hdmiAudioMute(HDMI_AUDIO_MUTE);
271         if (ret) {
272                 IFPRINT (UART_printf("HDMI Audio Mute failed\n"));
273                 goto err;
274         }
276         /* I2S Input configuration : Rising, 256fs ,ws-low=left, left justify,
277            MSB 1st, 1 bit shift */
278         ret = hdmiWrite(HDMI_REG_20, 0x90);
279         if (ret) {
280                 goto err;
281         }
283         /* Select SD pin SD0 to be connected to FIFO */
284         ret = hdmiWrite(HDMI_REG_1F, 0x80);
285         if (ret) {
286                 goto err;
287         }
289         /* Disable SD pin SD1 */
290         ret = hdmiWrite(HDMI_REG_1F, 0x19);
291         if (ret) {
292                 goto err;
293         }
295         /* Disable SD pin SD2 */
296         ret = hdmiWrite(HDMI_REG_1F, 0x2A);
297         if (ret) {
298                 goto err;
299         }
301         /* Disable SD pin SD3 */
302         ret = hdmiWrite(HDMI_REG_1F, 0x3B);
303         if (ret) {
304                 goto err;
305         }
307         /* 16bit, 44.1kHz, 2 channel = 0x50 */
308         ret = hdmiWrite(HDMI_REG_27, 0x50);
309         if (ret) {
310                 goto err;
311         }
313         ret = hdmiWrite(HDMI_REG_21, 0x0);
314         if (ret) {
315                 goto err;
316         }
318         ret = hdmiWrite(HDMI_REG_22, 0x0);
319         if (ret) {
320                 goto err;
321         }
323         ret = hdmiWrite(HDMI_REG_23, 0x0);
324         if (ret) {
325                 goto err;
326         }
328         /* 44.1KHz Sampling frequency */
329         ret = hdmiWrite(HDMI_REG_24, 0x0);
330         if (ret) {
331                 goto err;
332         }
334         /* 16bit word length */
335         ret = hdmiWrite(HDMI_REG_25, 0x02);
336         if (ret) {
337                 goto err;
338         }
340         ret = hdmiRead(HDMI_REG_25, &val, 1);
341         if (ret) {
342                 goto err;
343         }
344         IFPRINT (UART_printf("HDMI_REG_25 = 0x%x\n", val));
346         ckSum = 0;
348         for (i = 1; i < 15; i++)
349         {
350                 ckSum += audioInfoFrame[i];
351         }
352         audioInfoFrame[4] = 0x100 - ckSum;
354         /* Audio InfoFrame information */
356         miscInfoFrameDataStart = 0xBF;
358         for (i = 0; i < sizeof(audioInfoFrame); i++)
359         {
360                 ret = hdmiWrite(miscInfoFrameDataStart, audioInfoFrame[i]);
361                 if (ret) {
362                         goto err;
363                 }
364                 ret = hdmiRead(miscInfoFrameDataStart, &val, 1);
365                 if (ret) {
366                         goto err;
367                 }
368                 IFPRINT (UART_printf("0x%x = 0x%x\n", miscInfoFrameDataStart,
369                                        val));
370                 miscInfoFrameDataStart++;
371         }
373         /* Decode Level 0 Packets */
374         ret = hdmiWrite(HDMI_REG_BC, 0x02);
375         if (ret) {
376                 goto err;
377         }
379         ret = hdmiWrite (HDMI_REG_BD, 0x24);
380         if (ret) {
381                 goto err;
382         }
384         ret = hdmiWrite(HDMI_REG_BE, 0x02);
385         if (ret) {
386                 goto err;
387         }
389         /* Unmute audio */
390         ret = hdmiAudioMute(HDMI_AUDIO_UNMUTE);
391         if (ret) {
392                 IFPRINT (UART_printf("HDMI Audio UnMute failed\n"));
393                 goto err;
394         }
396         /* Enable TMDS output */
397         ret = hdmiWrite(HDMI_SYS_CTRL_DATA_REG, 0x01);
399 err :
400         if (ret != 0) {
401                 IFPRINT (UART_printf("Error during HDMI audio setup - %d\n", ret));
402         }
404         return (ret);
406 /**
407  *
408  * \brief    Configures GPIO pins for HDMI controller.
409  *
410  * \return   NONE.
411  *
412  */
413 static void hdmiGpioSetup(void)
415         GPIO_init();
416         GPIO_write(0, 0);
419 /**
420  *
421  * \brief   Initializes the HDMI controller.
422  *
423  * \param   NULL.
424  *
425  * \return  NONE.
426  *
427  */
428 int8_t hdmiInit(void)
430         uint32_t index;
432         /* GPIO Initialization */
433         hdmiGpioSetup();
435         for (index = 0; I2C_config[index].fxnTablePtr != NULL; index++)
436         {
437                 ((I2C_HwAttrs *)I2C_config[index].hwAttrs)->enableIntr = false;
438         }
440         /* Initialize I2C module */
441     I2C_init();
442     I2C_Params_init(&hdmiI2cParams);
444     hdmiI2cHandle = I2C_open(HDMI_I2C_INSTANCE, &hdmiI2cParams);
445     if(hdmiI2cHandle == NULL)
446     {
447                 return (-1);
448         }
450         return (0);
453 /**
454  *
455  * \brief    This function is used to set all the registers to enable
456  *           the HDMI transmitter.
457  *
458  * \param    NULL.
459  *
460  * \return  HDMI_SUCCESS        - On Success.
461  *          HDMI_ERR            - On Failure.
462  *
463  */
464 int8_t hdmiHwEnable(void)
466         int8_t err, i;
467         uint8_t vals[14];
468         uint8_t val;
469         uint16_t horizontalRes;
470         uint16_t verticalRes;
471         uint16_t pixelClk;
472         uint8_t hdmi_reg_val[1] = {0};
474         memset(vals, 0, 14);
476         horizontalRes = 0;
477         verticalRes   = 0;
478         pixelClk      = 0;
480         /*  Fill the TPI Video Mode Data structure */
481         vals[0] = (pixelClk & 0xFF);                /* Pixel clock */
482         vals[1] = ((pixelClk & 0xFF00) >> 8);
483         vals[2] = VERTICAL_FREQ;                    /* Vertical freq */
485         /* register programming information on how vertical freq is to be
486            programmed to Hdmi not clear. Hence setting to 60 for now */
487         vals[3] = 0x00;
488         vals[4] = (horizontalRes & 0xFF);           /* Horizontal pixels*/
489         vals[5] = ((horizontalRes & 0xFF00) >> 8);
490         vals[6] = (verticalRes & 0xFF);             /* Vertical pixels */
491         vals[7] = ((verticalRes & 0xFF00) >> 8);
493         /*  Write out the TPI Video Mode Data */
494         for (i = 0; i <= 7; i++)
495         {
496                 err = hdmiWrite(HDMI_TPI_VIDEO_DATA_BASE_REG + i, vals[i]);
497                 if (err != 0) {
498                         IFPRINT(UART_printf("ERROR: writing TPI video mode"
499                                                " data\n"));
500                         return (err);
501                 }
502         }
504     /* Write out the TPI Input bus and pixel repetition Data:
505            (24 bit wide bus, falling edge, no pixel replication, 1:1
506            CLK ration) */
507         val = TPI_AVI_PIXEL_REP_BUS_24BIT |
508                   TPI_AVI_PIXEL_REP_FALLING_EDGE |
509                   TPI_AVI_PIXEL_REP_NONE | TPI_CLK_RATIO_1X;
511         err = hdmiWrite(HDMI_TPI_PIXEL_REPETITION_REG, val);
512         if (err != 0) {
513                 IFPRINT(UART_printf("ERROR: writing TPI pixel repetition data\n"));
514                 return (err);
515         }
517         /*  Write out the TPI AVI Input Format */
518         val = TPI_AVI_INPUT_BITMODE_8BIT |
519                   TPI_AVI_INPUT_RANGE_AUTO |
520                   TPI_AVI_INPUT_COLORSPACE_RGB;
522         err = hdmiWrite(HDMI_TPI_AVI_IN_FORMAT_REG, val);
523         if (err != 0) {
524                 IFPRINT(UART_printf("ERROR: writing TPI AVI Input format\n"));
525                 return (err);
526         }
528         /*  Write out the TPI AVI Output Format */
529         val = TPI_AVI_OUTPUT_CONV_BT709 |
530                 TPI_AVI_OUTPUT_RANGE_AUTO |
531                 TPI_AVI_OUTPUT_COLORSPACE_RGBHDMI;
533         err = hdmiWrite(HDMI_TPI_AVI_OUT_FORMAT_REG, val);
534         if (err != 0) {
535                 IFPRINT(UART_printf("ERROR: writing TPI AVI output format\n"));
536                 return (err);
537         }
539         /* Write out the TPI System Control Data to power down */
540         val = TPI_SYS_CTRL_POWER_DOWN;
541         err = hdmiWrite(HDMI_SYS_CTRL_DATA_REG, val);
542         if (err != 0) {
543                 IFPRINT(UART_printf("ERROR: writing TPI power down control"
544                                        " data\n"));
545                 return (err);
546         }
548         /* Move from ENABLED -> FULLY ENABLED Power State  */
549         val = TPI_AVI_POWER_STATE_D0;
550         err = hdmiWrite(HDMI_TPI_POWER_STATE_CTRL_REG, val);
551         if (err != 0) {
552                 IFPRINT(UART_printf("ERROR: Setting device power state to D0\n"));
553                 return (err);
554         }
556         /* Write out the TPI System Control Data to power up and
557          * select output mode
558          */
559         val = TPI_SYS_CTRL_POWER_ACTIVE | TPI_SYS_CTRL_OUTPUT_MODE_HDMI;
560         err = hdmiWrite(HDMI_SYS_CTRL_DATA_REG, val);
561         if (err != 0) {
562                 IFPRINT(UART_printf("ERROR: Writing system control data\n"));
563                 return (err);
564         }
566         /* Delay of 20 milli sec */
567         platform_delay(20000);
569         /*  Read back TPI System Control Data to latch settings */
570         err = hdmiRead(HDMI_SYS_CTRL_DATA_REG, &val, 1);
571         if (err != 0) {
572                 IFPRINT(UART_printf("ERROR: Reading system control data\n"));
573                 return (err);
574         }
576         /* HDCP */
577         val = 0; /* DISABLED */
578         err = hdmiWrite(HDMI_TPI_HDCP_CONTROLDATA_REG, val);
579         if (err != 0) {
580                 IFPRINT(UART_printf("ERROR: Writing HDCP control data"));
581                 return (err);
582         }
584         IFPRINT(UART_printf("hdmi enabled\n"));
586 #if 0
587         for (i = 0; i < sizeof(hdmi_reg_defs); i++) {
588                 err = hdmiRead(hdmi_reg_defs[i], hdmi_reg_val, 1);
589                 if (err != 0) {
590                         UART_printf("ERROR: Reading reg 0x%x\n", hdmi_reg_defs[i]);
591                 }
592                 else
593                         UART_printf("Value at reg 0x%x = 0x%x\n", hdmi_reg_defs[i], hdmi_reg_val[0]);
594         }
595 #endif
597         return HDMI_SUCCESS;
600 /**
601  * \brief    Enables the power state of HDMI controller.
602  *
603  * \return  HDMI_SUCCESS        -      On Success
604  *          HDMI_ERR            -      On Failure
605  *
606  */
607 int8_t hdmiConnect(void)
609         int err = 0;
611         IFPRINT(UART_printf("hdmiConnect: CONNECT\n"));
613         /* Move from LOW -> ENABLED Power state */
614         err = hdmiWrite(HDMI_TPI_POWER_STATE_CTRL_REG,
615                                 TPI_AVI_POWER_STATE_D2);
616         if (err != 0) {
617                 IFPRINT(UART_printf("ERROR: Setting device power state"
618                                        " to D2\n"));
619         }
621         return (err);
624 /**
625  * \brief    Reads the HDMI edid information.
626  *
627  * \param    data        [IN] Pointer to the data buffer
628  * \param    dataLen [IN] Length of edid data to be read.
629  *
630  * \return   HDMI_SUCCESS       - On Success
631  *           HDMI_ERR           - On Failure
632  *
633  */
634 int8_t hdmiReadEdid(uint8_t *data, uint32_t dataLen)
636         int8_t err =  0;
637         uint32_t len = dataLen;
638         uint8_t val = 0;
639         int8_t retries = 0;
641         len = (len < HDMI_EDID_MAX_LEN) ? len : HDMI_EDID_MAX_LEN;
643         /* Request DDC bus access to read EDID info from HDTV */
644         IFPRINT(UART_printf("Reading HDMI EDID\n"));
646         val = 0;
647         err = hdmiRead(0x3D, &val, 1);
648         if (err != 0) {
649                 IFPRINT(UART_printf(    "ERROR: Reading Monitor Status register\n"));
650                 return (err);
651         }
652         IFPRINT(UART_printf("Monitor status reg read Val = 0x%x\n", val));
653         if (val & 0x2) {
654                 IFPRINT(UART_printf(" MONITOR PRESENT \n"));
655         } else {
656                 IFPRINT(UART_printf(" MONITOR NOT PRESENT \n"));
657         }
659         /* Disable TMDS clock */
660         val = 0x11;
661         err = hdmiWrite(HDMI_SYS_CTRL_DATA_REG, val);
662         if (err != 0) {
663                 IFPRINT(UART_printf("ERROR: Failed to disable TMDS clock\n"));
664                 return (err);
665         }
666         val = 0;
668         /* Read TPI system control register*/
669         err = hdmiRead(HDMI_SYS_CTRL_DATA_REG, &val, 1);
670         if (err != 0) {
671                 IFPRINT(UART_printf("ERROR: Reading DDC BUS REQUEST\n"));
672                 return (err);
673         }
675         /* The host writes 0x1A[2]=1 to request the
676          * DDC(Display Data Channel) bus
677          */
678         val |= TPI_SYS_CTRL_DDC_BUS_REQUEST;
679         err = hdmiWrite(HDMI_SYS_CTRL_DATA_REG, val);
680         if (err != 0) {
681                 IFPRINT(UART_printf("ERROR: Writing DDC BUS REQUEST\n"));
682                 return (err);
683         }
685         /*  Poll for bus DDC Bus control to be granted */
686         IFPRINT(UART_printf("Poll for DDC bus access\n"));
687         val = 0;
688         do {
689                 err = hdmiRead(HDMI_SYS_CTRL_DATA_REG, &val, 1);
690                 if (retries++ > 100) {
691                         IFPRINT(UART_printf("Polling for DDC bus access failed\n"));
692                         return (err);
693                 }
695         } while ((val & TPI_SYS_CTRL_DDC_BUS_GRANTED) == 0);
697         /*  Close the switch to the DDC */
698         val |= TPI_SYS_CTRL_DDC_BUS_REQUEST | TPI_SYS_CTRL_DDC_BUS_GRANTED;
699         err = hdmiWrite(HDMI_SYS_CTRL_DATA_REG, val);
700         if (err != 0) {
701                 IFPRINT(UART_printf("ERROR: Close switch to DDC BUS REQUEST\n"));
702                 return (err);
703         }
705         memset(data, 0, len);
707     /* Change I2C SetSlaveAddress to HDMI_I2C_MONITOR_ADDRESS */
708         /* Read the EDID structure from the monitor I2C address  */
709         err = hdmiRead(0x00, data, len);
710         if (err != 0) {
711                 IFPRINT(UART_printf("ERROR: Reading EDID\n"));
712                 return (err);
713         }
715         /* Release DDC bus access */
716         val &= ~(TPI_SYS_CTRL_DDC_BUS_REQUEST | TPI_SYS_CTRL_DDC_BUS_GRANTED);
718         retries = 0;
719         do {
720                 err = hdmiWrite(HDMI_SYS_CTRL_DATA_REG, val);
721                 if (err >= 0) {
722                         break;
723                 }
724                 retries++;
725         } while (retries < 5);
727         if (err != 0) {
728                 IFPRINT(UART_printf("ERROR: Releasing DDC Bus Access\n"));
729                 return (err);
730         }
732         return HDMI_SUCCESS;
735 /**
736  *
737  * \brief    This function is used to check the HDMI chip version.
738  *
739  * \param    chipVer : Pointer to the buffer passed from test app.
740  *
741  * \return   HDMI_SUCCESS       - On Success.
742  *           HDMI_ERR           - On Failure.
743  *
744  */
745 int8_t hdmiProbeChipVersion(uint8_t *chipVer)
747         int8_t err = 0;
749         /* Probe for hdmi chip version*/
750         err = hdmiWrite(HDMI_REG_TPI_RQB, 0x00);
751         if (err != 0) {
752                 IFPRINT(UART_printf("ERROR: Writing HDMI configuration to "
753                                                "reg - SI9022_REG_TPI_RQB\n"));
754                 return (err);
755         }
757         err = hdmiRead(HDMI_REG_CHIPID0, chipVer, 1);
758         if (err != 0) {
759                 IFPRINT(UART_printf("ERROR: Reading chip ID\n"));
760         }
762         return (err);
765 /**
766  *
767  * \brief    Configures HDMI audio
768  *
769  * \param    NULL.
770  *
771  * \return   HDMI_SUCCESS       - On Success
772  *           HDMI_ERR           - On Failure
773  *
774  */
775 int8_t hdmiAudioConfigure(void)
777         int8_t ret;
779         ret = hdmiAudioSetup();
781         return (ret);
784 /* Nothing past this point */