]> 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_2_eng/packages/ti/board/diag/hdmi/src/hdmi_test.c
PASDK-319:Update PDK eng to 1.0.1.2.
[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_2_eng / packages / ti / board / diag / hdmi / src / hdmi_test.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  hdmi_test.c
37  *
38  * \brief This file contains hdmi test functions.
39  *
40  ******************************************************************************/
42 #include "hdmi_test.h"
43 #include "platform_internal.h"
45 #if 1
46 lcdCfg_t hdmiCfg = {
47         640,        /** LcdWidth    */
48         480,       /** LcdHeight    */
49         24750000,  /** LcdPclk      */
50         92,        /** HsyncWidth   */
51                 34,       /** HFrontPorch  */
52         34,        /** HBackPorch   */
53         3,        /** VsyncWidth   */
54         3,        /** VFrontPorch  */
55         42,        /** VBackPorch   */
56 };
57 #endif
58 #if 0
59 lcdCfg_t hdmiCfg = {
60         640,        /** LcdWidth    */
61         480,       /** LcdHeight    */
62         27000000,  /** LcdPclk      */
63         44,        /** HsyncWidth   */
64         21,       /** HFrontPorch  */
65         113,        /** HBackPorch   */
66         3,        /** VsyncWidth   */
67         10,        /** VFrontPorch  */
68         30,        /** VBackPorch   */
69 };
70 #endif
71 #if 0
72 lcdCfg_t hdmiCfg = {
73         1280,        /** LcdWidth    */
74         720,       /** LcdHeight    */
75         74250000,  /** LcdPclk      */
76         81,        /** HsyncWidth   */
77         73,        /** HFrontPorch  */
78         217,        /** HBackPorch   */
79                 6,        /** VsyncWidth   */
80                 3,       /** VFrontPorch  */
81                 22,        /** VBackPorch   */
82 };
83 #endif
85 //#define ENABLE_HDMI_AUDIO_TEST   (1)
87 #ifdef ENABLE_HDMI_AUDIO_TEST
88 TEST_STATUS audioPlayback(void *testArgs);
90 /**
91  * \brief Reads state of the audio dc board detect pin
92  *
93  * \return
94  * \n      0 - Audio DC is connected
95  * \n      1 - Audio DC is not connected
96  *
97  */
98 static uint32_t check_audiodc_detect(void)
99 {
100         uint32_t gpioState = 0;
102     pinMuxSetMode(21, PADCONFIG_MUX_MODE_QUATERNARY);
103     gpioSetDirection(0, 21, GPIO_IN);
104         gpioState = gpioReadInput(0, 21);
106     return(gpioState);
108 #endif
110 /**
111  * \brief Function to display color and read user input or
112  *        wait for some time after HDMI display
113  *
114  *  \param    input [IN]   Flag to indicate wait for user input
115  *  \param    color [IN]   Value of Color
116  *  \param    name  [IN]   Name of the pattern displayed on HDMI
117  *
118  * \return
119  * \n      TEST_PASS  - Test Passed
120  * \n      TEST_FAIL  - Test Failed
121  *
122  */
123 static TEST_STATUS displayColor(uint8_t input, int color, char *name)
125         uint8_t c = 0;
127         if(input == FALSE)
128         {
129                 UART_printf("\rDisplaying %s... WAIT  Press 'y' if %s is displayed, any other key for failure: ", name, name);
131                 hdmiColorDisplay(&hdmiCfg, color);
133                 UART_scanFmt("%c", &c);
134                 if((c == 'y') || (c == 'Y'))
135                 {
136                         UART_printf("\rDisplay %s - PASS                                                                            \n", name);
137                 }
138                 else
139                 {
140                         UART_printf("\rDisplay %s - FAIL                                                                            \n", name);
141                         return (TEST_FAIL);
142                 }
143         }
144         else
145         {
146                 UART_printf("\rDisplaying %s...\n", name);
147                 hdmiColorDisplay(&hdmiCfg, color);
148         delay_secs(HDMI_DISPLAY_DELAY);
149         }
151         return (TEST_PASS);
154 /**
155  *  \brief    This function performs HDMI, DSS initialization
156  *            and verifies HDMI display
157  *
158  *  \param    testArgs [IN]   Test arguments
159  *
160  * \return
161  * \n      TEST_PASS  - Test Passed
162  * \n      TEST_FAIL  - Test Failed
163  */
164 static TEST_STATUS run_hdmi_test(void *testArgs)
166         hdmiTestArgs_t *args = (hdmiTestArgs_t *)testArgs;
167         TEST_STATUS status = TEST_PASS;
168         uint8_t c = 0;
169 #ifdef ENABLE_HDMI_AUDIO_TEST
170     audioTestArgs_t audioTestArgs;
171     uint32_t        audioDCDetect = 0;
173     audioDCDetect = check_audiodc_detect();
175     audioTestArgs.autoRun  = 0;
176     audioTestArgs.mode     = AUDIO_TEST_MODE_PLAYBACK;
178     if(audioDCDetect)
179     {
180         audioTestArgs.mcaspNum = MCASP_PORT_0;
181         }
182         else
183         {
184                 audioTestArgs.mcaspNum = MCASP_PORT_2;
185         }
187 #endif
189 #if 0
190         uint8_t edid[HDMI_EDID_MAX_LENGTH];
191 #endif
192         uint8_t ver;
194         /* HDMI i2c init */
195         hdmiInit();
197         UART_printf("Running HDMI Device Detect Test\n");
199         status = hdmiProbeChipVersion(&ver);
200         if (status)
201         {
202                 UART_printf("ERROR: Reading HDMI version Id\n");
203                 UART_printf("HDMI Device Detect Test Failed\n");
204                 goto err;
205         }
206         else
207         {
208                 if (ver != HDMI_CHIPID_902x)
209                 {
210                         UART_printf("Not a valid verId: 0x%x\n", ver);
211                         UART_printf("HDMI Device Detect Test Failed\n");
212                         goto err;
213                 }
214                 else
215                 {
216                         UART_printf("sil9022 HDMI Chip version ="
217                                                    " %x\n", ver);
218                 }
219         }
221         UART_printf("HDMI Device Detect Test Passed\n\n");
223         status = hdmiConnect();
224         if (status)
225         {
226                 UART_printf("Error in Enabling power for HDMI\n");
227         goto err;
228         }
230         status = hdmiHwEnable();
231         if (status)
232         {
233                 UART_printf("Error during enabling HDMI\n");
234         goto err;
235         }
236 #if 0
237         status = hdmiReadEdid(edid, 256);
238         if (status)
239         {
240                 UART_printf("ERROR: Reading HDMI EDID.\n");
241         goto err;
242         }
243         else
244         {
245                 UART_printf("edid[0] = 0x%x edid[1] = 0x%x edid[2]"
246                                            " = 0x%x\n",edid[0], edid[1], edid[2]);
247         }
248 #endif
249         status = hdmiPanelInit(&hdmiCfg);
250         if (status != DSS_RET_OK)
251         {
252                 UART_printf("ERROR: Initializing HDMI Panel\n");
253         goto err;
254         }
256         if(args->autoRun == FALSE)
257         {
258                 UART_printf("\rDisplaying Colorbar... WAIT  Press 'y' if Colorbar is displayed, any other key for failure: ");
259         }
260         else
261         {
262                 UART_printf("\rDisplaying Colorbar...\n");
263         }
265         hdmiColorBarDisplay(&hdmiCfg);
267         if(args->autoRun == FALSE)
268         {
269                 UART_scanFmt("%c", &c);
270                 if((c == 'y') || (c == 'Y'))
271                 {
272                         UART_printf("\rDisplay Colorbar   - PASS                                                                            \n");
273                 }
274                 else
275                 {
276                         UART_printf("\rDisplay Colorbar   - FAIL                                                                            \n");
277                         return (TEST_FAIL);
278                 }
279         }
280         else
281         {
282         delay_secs(HDMI_DISPLAY_DELAY);
283         }
285         if(displayColor(args->autoRun, HDMI_WHITE, "WHITE"))
286         {
287                 return (TEST_FAIL);
288         }
290         if(displayColor(args->autoRun, HDMI_BLUE, "BLUE"))
291         {
292                 return (TEST_FAIL);
293         }
295         if(displayColor(args->autoRun, HDMI_GREEN, "GREEN"))
296         {
297                 return (TEST_FAIL);
298         }
300         if(displayColor(args->autoRun, HDMI_RED, "RED"))
301         {
302                 return (TEST_FAIL);
303         }
305         if(displayColor(args->autoRun, HDMI_PURPLE, "PURPLE"))
306         {
307                 return (TEST_FAIL);
308         }
310         if(displayColor(args->autoRun, HDMI_PINK, "PINK"))
311         {
312                 return (TEST_FAIL);
313         }
315         if(displayColor(args->autoRun, HDMI_BLACK, "BLACK"))
316         {
317                 return (TEST_FAIL);
318         }
320         if(displayColor(args->autoRun, HDMI_YELLOW, "YELLOW"))
321         {
322                 return (TEST_FAIL);
323         }
325 #ifdef ENABLE_HDMI_AUDIO_TEST
327         UART_printf("\nRunning HDMI Audio Test\n");
328         UART_printf("Audio Tone Should be Played on HDMI Device Connected\n");
330         if(audioDCDetect)
331         {
332                 UART_printf("\nINFO: Audio DC is not Connected\n");
333         }
334         else
335         {
336                 UART_printf("\nINFO: Audio DC is Connected\n");
337         }
339         status = hdmiAudioConfigure();
340         if (status != 0)
341         {
342                 UART_printf("ERROR: Initializing HDMI Audio\n");
343         goto err;
344         }
346         hdmiColorBarDisplay(&hdmiCfg);
348         if(hdmiAudioPlayback(&audioTestArgs))
349         {
350                 UART_printf("\nHDMI Audio Test Failed!\n");
351                 status = TEST_FAIL;
352         }
353         else
354         {
355                 status = TEST_PASS;
356         }
357 #endif
359 err :   return (status);
362 /**
363  * \brief This function performs hdmi test
364  *
365  * \param testArgs  - Test arguments
366  *
367  * \return
368  * \n      TEST_PASS  - Test Passed
369  * \n      TEST_FAIL  - Test Failed
370  *
371  */
372 TEST_STATUS hdmiTest(void *testArgs)
374         TEST_STATUS testStatus = TEST_PASS;
375         hdmiTestArgs_t *args = (hdmiTestArgs_t *)testArgs;
377         UART_printf("\n***********************\n");
378         UART_printf(  "       HDMI Test       \n");
379         UART_printf(  "***********************\n");
381         testStatus = run_hdmi_test(args);
382         if(testStatus != TEST_PASS)
383         {
384                 UART_printf("\nHDMI Test Failed!\n");
385         }
386         else
387         {
388                 //UART_printf("\nHDMI Test Passed!\n");
389         }
391         UART_printf("\nHDMI Tests Completed!!\n");
392         UART_printf("\n-----------------X-----------------\n\n\n");
394         return (testStatus);
396 } // hdmiTest
398 /**
399  * \brief Invokes hdmi test functions
400  *
401  */
402 int main(void)
404     TEST_STATUS     testStatus;
405     hdmiTestArgs_t  testArgs;
406     Board_initCfg      boardCfg;
408     testArgs.autoRun = 0;
410 #ifdef PDK_RAW_BOOT
411     boardCfg = BOARD_INIT_PINMUX_CONFIG |
412         BOARD_INIT_UART_STDIO;
413 #else
414     boardCfg = BOARD_INIT_UART_STDIO;
415 #endif
416     Board_init(boardCfg);
418     /* Invoke HDMI Test */
419     testStatus = hdmiTest(&testArgs);
420     if(testStatus != TEST_PASS)
421     {
422         return (-1);
423     }
425     return (0);
428 /* Nothing past this point */