03fbaec030f4ba53fb98e1254107a38a0c12a1b5
1 /******************************************************************************\r
2 * Copyright (c) 2019-2020 Texas Instruments Incorporated - http://www.ti.com\r
3 *\r
4 * Redistribution and use in source and binary forms, with or without\r
5 * modification, are permitted provided that the following conditions\r
6 * are met:\r
7 *\r
8 * Redistributions of source code must retain the above copyright\r
9 * notice, this list of conditions and the following disclaimer.\r
10 *\r
11 * Redistributions in binary form must reproduce the above copyright\r
12 * notice, this list of conditions and the following disclaimer in the\r
13 * documentation and/or other materials provided with the\r
14 * distribution.\r
15 *\r
16 * Neither the name of Texas Instruments Incorporated nor the names of\r
17 * its contributors may be used to endorse or promote products derived\r
18 * from this software without specific prior written permission.\r
19 *\r
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31 *\r
32 *****************************************************************************/\r
33 /**\r
34 * \file board_init.c\r
35 *\r
36 * \brief Board library main file\r
37 *\r
38 * Board library provides basic functions to initialize the interfaces\r
39 * on a given HW platform. It takes care of configuring and enabling different\r
40 * modules like PLL, clocks inside SoC and HW components on the board which are\r
41 * required to make sure board is ready for running the application software.\r
42 *\r
43 * A common standard API Board_init() is exposed to the applications to invoke\r
44 * different board initialization routines. This function is common across the\r
45 * platforms maitaining the portability and can receive different input\r
46 * configuration flags based on the board capabilities allowing extendibility.\r
47 *\r
48 * Board library shall eliminate the use of any additional configurations like\r
49 * GEL files to initialize the board except the cases like DDR initialization\r
50 * for loading the code into DDR before calling the Board init function.\r
51 * Give this limitation, applications invoking board library functions to\r
52 * initialize PLL, DDR and pinmux are supposed to run from SoC internal memory.\r
53 *\r
54 */\r
55 \r
56 #include "board_internal.h"\r
57 #include <ti/drv/sciclient/sciclient.h>\r
58 \r
59 Board_gblObj Board_obj = {NULL};\r
60 \r
61 static bool gBoardSysInitDone = 0;\r
62 \r
63 /**\r
64 * \brief Board global initializations\r
65 *\r
66 * \return BOARD_SOK in case of success or appropriate error code\r
67 *\r
68 */\r
69 static Board_STATUS Board_sysInit(void)\r
70 {\r
71 Board_STATUS status = BOARD_SOK;\r
72 int32_t ret;\r
73 Sciclient_ConfigPrms_t config;\r
74 \r
75 if(gBoardSysInitDone == 0)\r
76 {\r
77 Sciclient_configPrmsInit(&config);\r
78 \r
79 ret = Sciclient_init(&config);\r
80 \r
81 if(ret != 0)\r
82 {\r
83 status = BOARD_FAIL;\r
84 }\r
85 \r
86 if(status == BOARD_SOK)\r
87 {\r
88 gBoardSysInitDone = 1;\r
89 }\r
90 }\r
91 \r
92 return status;\r
93 }\r
94 \r
95 /**\r
96 * \brief Board global de-initializations\r
97 *\r
98 * \return BOARD_SOK in case of success or appropriate error code\r
99 *\r
100 */\r
101 static Board_STATUS Board_sysDeinit(void)\r
102 {\r
103 Board_STATUS status = BOARD_SOK;\r
104 int32_t ret;\r
105 \r
106 if(gBoardSysInitDone == 1)\r
107 {\r
108 ret = Sciclient_deinit();\r
109 if(ret != 0)\r
110 {\r
111 status = BOARD_FAIL;\r
112 }\r
113 \r
114 if(status == BOARD_SOK)\r
115 {\r
116 gBoardSysInitDone = 0;\r
117 }\r
118 }\r
119 \r
120 return status;\r
121 }\r
122 \r
123 /**\r
124 * \brief Board library initialization function\r
125 *\r
126 * Different board initialization routines are invoked by using configuration\r
127 * flags as described below\r
128 * BOARD_INIT_UNLOCK_MMR -\r
129 * Unlocks the MMR registers of the SoC. MMR registers should be\r
130 * enabled before any write access to MMR register address space.\r
131 *\r
132 * BOARD_INIT_PLL -\r
133 * Configures different PLL controller modules. This enables all the PLL\r
134 * controllers on the SoC with default configurations. Any custom values\r
135 * required for PLL output needs to be done separately\r
136 *\r
137 * BOARD_INIT_DDR -\r
138 * Initializes the DDR timing parameters. Sets the DDR timing parameters\r
139 * based in the DDR PLL controller configuration done by the board library.\r
140 * Any changes to DDR PLL requires change to DDR timing.\r
141 *\r
142 * BOARD_INIT_PINMUX_CONFIG -\r
143 * Enables pinmux for the board interfaces. Pin mux is done based on the\r
144 * default/primary functionality of the board. Any pins shared by multiple\r
145 * interfaces need to be reconfigured to access the secondary functionality.\r
146 *\r
147 * BOARD_INIT_UART_STDIO -\r
148 * Configures the UART module to use for serial console messages.\r
149 *\r
150 * BOARD_INIT_MODULE_CLOCK -\r
151 * Enables different power domains and peripheral clocks of the SoC.\r
152 * Some of the power domains and peripherals will be off by default.\r
153 * Enabling the power domains is mandatory before accessing using\r
154 * board interfaces connected to those peripherals.\r
155 *\r
156 * \param cfg [IN] Board configuration flags\r
157 *\r
158 * \return BOARD_SOK in case of success or appropriate error code\r
159 */\r
160 Board_STATUS Board_init(Board_initCfg cfg)\r
161 { \r
162 Board_STATUS ret = BOARD_SOK;\r
163 \r
164 ret = Board_sysInit();\r
165 if (ret != BOARD_SOK)\r
166 return ret;\r
167 \r
168 if (cfg & BOARD_INIT_UNLOCK_MMR)\r
169 ret = Board_unlockMMR();\r
170 if (ret != BOARD_SOK)\r
171 return ret;\r
172 \r
173 if (cfg & BOARD_INIT_MODULE_CLOCK)\r
174 ret = Board_moduleClockInit();\r
175 if (ret != BOARD_SOK)\r
176 return ret;\r
177 \r
178 if (cfg & BOARD_INIT_PINMUX_CONFIG)\r
179 ret = Board_pinmuxConfig();\r
180 if (ret != BOARD_SOK)\r
181 return ret;\r
182 \r
183 if (cfg & BOARD_INIT_PLL)\r
184 ret = Board_PLLInitAll();\r
185 if (ret != BOARD_SOK)\r
186 return ret;\r
187 \r
188 if (cfg & BOARD_INIT_DDR)\r
189 {\r
190 if (cfg & BOARD_INIT_DDR_ECC)\r
191 {\r
192 ret = Board_DDRInit(true);\r
193 }\r
194 else\r
195 {\r
196 ret = Board_DDRInit(false);\r
197 }\r
198 }\r
199 \r
200 if (ret != BOARD_SOK)\r
201 return ret;\r
202 \r
203 if (cfg & BOARD_INIT_ETH_PHY)\r
204 ret = Board_mcuEthConfig();\r
205 if (ret != BOARD_SOK)\r
206 return ret;\r
207 \r
208 if (cfg & BOARD_INIT_ICSS_ETH_PHY)\r
209 ret = Board_icssEthConfig();\r
210 if (ret != BOARD_SOK)\r
211 return ret;\r
212 \r
213 if (cfg & BOARD_INIT_UART_STDIO)\r
214 ret = Board_uartStdioInit();\r
215 if (ret != BOARD_SOK)\r
216 return ret;\r
217 \r
218 if (cfg & BOARD_INIT_SERDES_PHY)\r
219 ret = Board_serdesCfg();\r
220 if (ret != BOARD_SOK)\r
221 return ret;\r
222 \r
223 return ret;\r
224 }\r
225 \r
226 /**\r
227 * \brief Board library de-initialization function\r
228 *\r
229 * Different board de-initialization routines are invoked by using configuration\r
230 * flags as described below\r
231 *\r
232 * BOARD_DEINIT_UART_STDIO -\r
233 * Closes the board UART instance configured for serial console logs\r
234 *\r
235 * \param cfg [IN] Board configuration flags\r
236 *\r
237 * \return BOARD_SOK in case of success or appropriate error code\r
238 */\r
239 Board_STATUS Board_deinit(Board_initCfg cfg)\r
240 {\r
241 Board_STATUS ret = BOARD_SOK;\r
242 \r
243 Board_sysDeinit();\r
244 \r
245 if (cfg & BOARD_DEINIT_UART_STDIO)\r
246 ret = Board_uartDeInit();\r
247 if (ret != BOARD_SOK)\r
248 return ret;\r
249 \r
250 return ret;\r
251 }\r