PDK-6945: Board: am64x evm eeprom test validated for board ID read
[processor-sdk/pdk.git] / packages / ti / board / diag / eeprom / src / eeprom_test_v2.c
1 /******************************************************************************
2  * Copyright (c) 2018-2020 Texas Instruments Incorporated - http://www.ti.com
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions
6  *  are met:
7  *
8  *    Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  *    Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the
14  *    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
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  *****************************************************************************/
34 /**
35  *  \file   eeprom_test_v2.c
36  *
37  *  \brief  eeprom application.
38  *
39  *  Targeted Functionality: Verifying board id contents.                          
40  *
41  *  Operation: This test display the board details by reading
42  *                         Board id EEPROM
43  *
44  *  Supported SoCs: AM65XX, J721E, J7200, TPR12, AM64x.
45  *
46  *  Supported Platforms: am65xx_evm, am65xx_idk, j721e_evm, j7200_evm, tpr12_evm,
47  *                       am64x_evm
48  *
49  */
51 #include "eeprom_test_v2.h"
53 #if defined(am65xx_evm) || defined(am65xx_idk)
54 boardProgInfo_t boardProgInfo[MAX_NUM_OF_BOARDS] = {
55     {"CP Board\0",                  CP_EEPROM_SLAVE_ADDR,       true},
56     {"Application Card\0",          APP_EEPROM_SLAVE_ADDR,      false},
57     {"LCD Display Board\0",         LCD_EEPROM_SLAVE_ADDR,      false},
58     {"SERDES Personality Card\0",   SERDES_EEPROM_SLAVE_ADDR,   false}
59 };
60 #elif defined(j7200_evm)
61 boardProgInfo_t boardProgInfo[MAX_NUM_OF_BOARDS] = {
62     {"SoM Board\0",                             BOARD_SOM_EEPROM_SLAVE_ADDR,    true},
63     {"CP Board\0",                              BOARD_CP_EEPROM_SLAVE_ADDR,             true},
64     {"GESI Board\0",                    BOARD_GESI_EEPROM_SLAVE_ADDR,   false},
65     {"Quad ENET expansion\0",   BOARD_ENET_EEPROM_SLAVE_ADDR,   false}
66 };
67 Board_I2cInitCfg_t boardI2cInitCfg[MAX_NUM_OF_BOARDS] = {
68     {0,     BOARD_SOC_DOMAIN_WKUP, false},
69     {0,     BOARD_SOC_DOMAIN_WKUP, false},
70     {0,     BOARD_SOC_DOMAIN_WKUP, false},
71     {0,     BOARD_SOC_DOMAIN_WKUP, false},
72 };
73 #elif defined(SOC_TPR12)
74 boardProgInfo_t boardProgInfo[MAX_NUM_OF_BOARDS] = {
75     {"EVM Board\0",                 BOARD_I2C_EEPROM_ADDR,     true}
76 };
77 #elif defined(am64x_evm)
78 boardProgInfo_t boardProgInfo[MAX_NUM_OF_BOARDS] = {
79     {"AM64x EVM\0",                 EVM_EEPROM_SLAVE_ADDR,       true},
80     {"AM64x IO-Link Board\0",       IOLINK_EEPROM_SLAVE_ADDR,    false}
81 };
82 Board_I2cInitCfg_t boardI2cInitCfg[MAX_NUM_OF_BOARDS] = {
83     {0,     BOARD_SOC_DOMAIN_MAIN, false},
84     {0,     BOARD_SOC_DOMAIN_MAIN, false}
85 };
86 #else
88 boardProgInfo_t boardProgInfo[MAX_NUM_OF_BOARDS] = {
89     {"SoM Board\0",                 SOM_EEPROM_SLAVE_ADDR,          true},
90     {"CP Board\0",                  CP_EEPROM_SLAVE_ADDR,           true},
91     {"GESI Board\0",                EXP_CONN_EEPROM_SLAVE_ADDR,     false},
92     {"Infotainment board\0",        EXP_CONN_EEPROM_SLAVE_ADDR,     false},
93     {"Fusion 2 Board\0",            CSI2_EXP_EEPROM_SLAVE_ADDR,     false},
94     {"MV expansion\0",              CSI2_EXP_EEPROM_SLAVE_ADDR,     false},
95     {"LI expansion\0",              CSI2_EXP_EEPROM_SLAVE_ADDR,     false},
96     {"Quad ENET expansion\0",       ENET_EXP_EEPROM_SLAVE_ADDR,     false},
97     {"Display adapter board\0",     DISPLAY_ADP_EEPROM_SLAVE_ADDR,  false}
98 };
99 Board_I2cInitCfg_t boardI2cInitCfg[MAX_NUM_OF_BOARDS] = {
100     {0,     BOARD_SOC_DOMAIN_WKUP, false},
101     {0,     BOARD_SOC_DOMAIN_WKUP, false},
102     {0,     BOARD_SOC_DOMAIN_WKUP, false},
103     {0,     BOARD_SOC_DOMAIN_WKUP, false},
104     {6,     BOARD_SOC_DOMAIN_MAIN, false},
105     {6,     BOARD_SOC_DOMAIN_MAIN, false},
106     {6,     BOARD_SOC_DOMAIN_MAIN, false},
107     {0,     BOARD_SOC_DOMAIN_WKUP, false},
108     {0,     BOARD_SOC_DOMAIN_WKUP, false}
109 };
110 #endif
112 /**
113  *  \brief    This function is used to read the contents of Board id EEPROM
114  *            and display in uart console
115  *
116  *  \param    slaveAddress      [IN]    Slave Address of Board id EEPROM
117  *
118  *  \return   int8_t
119  *               0 - in case of success
120  *              -1 - in case of failure.
121  *
122  */
123 int8_t eepromTest(uint8_t slaveAddress)
125     Board_STATUS status;
126     Board_IDInfo_v2 info = {0};
127     uint8_t index = 0, count = 0, i;
129     status = Board_getIDInfo_v2(&info, slaveAddress);
130     if(status != BOARD_SOK)
131     {
132         return -1;
133     }
135     UART_printf("\nDisplaying Header Fields");
136     UART_printf("\n========================\n");
137     UART_printf("\tHeader ID: 0x%02x\n", info.headerInfo.magicNumber);
139     UART_printf("\nDisplaying Board Info Fields");
140     UART_printf("\n============================");
141     UART_printf("\n\tBoard Name: ");
142     UART_dataWrite((char *)&info.boardInfo.boardName, BOARD_BOARD_NAME_LEN);
143     UART_printf("\n\tDesign Revision: ");
144     UART_dataWrite((char *)&info.boardInfo.designRev, BOARD_DESIGN_REV_LEN);
145     UART_printf("\n\tPROC Number: ");
146     UART_dataWrite((char *)&info.boardInfo.procNum, BOARD_PROC_NUM_LEN);
147     UART_printf("\n\tVariant: ");
148     UART_dataWrite((char *)&info.boardInfo.variant, BOARD_VARIANT_LEN);
149     UART_printf("\n\tPCB Revision: ");
150     UART_dataWrite((char *)&info.boardInfo.pcbRev, BOARD_PCBREV_LEN);
151 #if defined(SOC_AM65XX) || defined(SOC_TPR12)
152     UART_printf("\n\tSchematic and BOM Revision: ");
153     UART_dataWrite((char *)&info.boardInfo.schbomRev, BOARD_SCHMBOM_REV_LEN);
154 #else
155     UART_printf("\n\tSchematic Revision: ");
156     UART_dataWrite((char *)&info.boardInfo.pcbRev, BOARD_PCBREV_LEN);
157     UART_dataWrite((char *)&info.boardInfo.schbomRev, BOARD_SCHMBOM_REV_LEN);
158 #endif
159     UART_printf("\n\tSoftware Revision: ");
160     UART_dataWrite((char *)&info.boardInfo.swRev, BOARD_SWREV_LEN);
161     UART_printf("\n\tVendor ID: ");
162     UART_dataWrite((char *)&info.boardInfo.vendorID, BOARD_VENDORID_LEN);
163     UART_printf("\n\tBuild Week: ");
164     UART_dataWrite((char *)&info.boardInfo.buildWeek, BOARD_BUILD_WEEK_LEN);
165     UART_printf("\n\tBuild Year: ");
166     UART_dataWrite((char *)&info.boardInfo.buildYear, BOARD_BUILD_YEAR_LEN);
167     UART_printf("\n\tBoard ID: ");
168     UART_dataWrite((char *)&info.boardInfo.boardID, BOARD_BOARDID_LEN);
169     UART_printf("\n\tSerial Number: ");
170     UART_dataWrite((char *)&info.boardInfo.serialNum, BOARD_SERIAL_NUM_LEN);
172     /* Displaying DDR fields, if it is there */
173     if(info.ddrInfo.ddrStructType == BOARD_DDR_FIELD_TYPE)
174     {
175         UART_printf("\nDisplaying DDR Fields");
176         UART_printf("\n=====================");
177         UART_printf("\n\tDDR Control Word: %02x\n", info.ddrInfo.ddrCtrl);
178     }
180     /* Displaying MAC id fields, if it is there */
181     if(info.macInfo.macStructType == BOARD_MACINFO_FIELD_TYPE)
182     {
183         UART_printf("\nDisplaying MAC Info Fields");
184         UART_printf("\n==========================\n");
185         UART_printf("\tMAC Control Word: %02x", info.macInfo.macControl);
187         do
188         {
189             UART_printf("\n\tMAC ADDR%d: %x", count, info.macInfo.macAddress[index]);
190             index++;
191             for(i = 1; i < 6; i++)
192             {
193                 UART_printf("-%x", info.macInfo.macAddress[index]);
194                 index++;
195             }
196             count++;
197         }while(info.macInfo.macAddress[index] != '\0');
198     }
200     return 0;
203 #if defined(am65xx_evm) || defined(am65xx_idk)
204 /**
205  *  \brief   This function is used to enabling 
206  *           I2C wakeup domain
207  *
208  */
209 static void enableWKUPI2C(void)
211     I2C_HwAttrs i2cCfg;
213     I2C_socGetInitCfg(I2C_INSTANCE, &i2cCfg);
215     i2cCfg.baseAddr = CSL_WKUP_I2C0_CFG_BASE;
216     i2cCfg.enableIntr = 0;
218     I2C_socSetInitCfg(I2C_INSTANCE, &i2cCfg);
220 #endif
222 /**
223  *  \brief   eeprom read test main function.
224  *
225  *  \return  int - Board ID Programming test status
226  *             0     - in case of success
227  *            -1     - in case of failure.
228  *
229  */
230 int main(void)
232     Board_STATUS status;
233     Board_initCfg boardCfg;
234 #if defined(SOC_AM65XX)
235     boardPresDetect_t isBoardDetect = APP_CARD_DETECT;
236 #elif !defined(SOC_TPR12)
237     uint8_t isBoardDetect = 0U;
238 #endif
239     uint8_t index;
240     int8_t ret = 0;
241     int8_t testSts = 0;
243 #ifdef PDK_RAW_BOOT
244     boardCfg = BOARD_INIT_MODULE_CLOCK |
245                BOARD_INIT_PINMUX_CONFIG |
246                BOARD_INIT_UART_STDIO;
247 #else
248     boardCfg = BOARD_INIT_UART_STDIO | BOARD_INIT_PINMUX_CONFIG;
249 #endif
250     status = Board_init(boardCfg);
251     if (status != BOARD_SOK)
252     {
253         return -1;
254     }
256     UART_printf("\n*********************************************\n"); 
257         UART_printf  ("*              EEPROM Test                  *\n");
258         UART_printf  ("*********************************************\n");
260 #if defined(am65xx_evm) || defined(am65xx_idk)
261     /* Detecting Boards */
262     enableWKUPI2C();
263 #endif
264 #if !(defined(SOC_TPR12))
265         for(index = STARTING_BOARD_NUM; index < MAX_NUM_OF_BOARDS; index++)
266     {
267         boardProgInfo[index].isBoardPresent = Board_detectBoard(isBoardDetect);
268                 isBoardDetect++;
269     }
270 #endif
271     for(index = 0; index < MAX_NUM_OF_BOARDS; index++)
272     {
273         if (boardProgInfo[index].isBoardPresent)
274         {
275 #if !((defined(am65xx_evm) || defined(am65xx_idk) || defined(SOC_TPR12)))
276             Board_setI2cInitConfig(&boardI2cInitCfg[index]);
277 #endif
278             UART_printf("\n%s:", boardProgInfo[index].boardName);
279             ret = eepromTest(boardProgInfo[index].slaveAddr);
280                         if (ret != 0)
281                         {
282                 UART_printf("\nTest Failed");
283                                 testSts = -1;
284                         }
285         }
286     }
287     if (testSts != 0)
288     {
289         UART_printf("\nEEPROM Test Failed");
290         return -1;
291     }
292     else
293     {
294         UART_printf("\nEEPROM Test Passed");
295         return 0;
296     }