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 static bool gBoardSysInitDone = 0;\r
60 \r
61 /**\r
62 * \brief Board global initializations\r
63 *\r
64 * \return BOARD_SOK in case of success or appropriate error code\r
65 *\r
66 */\r
67 static Board_STATUS Board_sysInit(void)\r
68 {\r
69 Board_STATUS status = BOARD_SOK;\r
70 int32_t ret;\r
71 Sciclient_ConfigPrms_t config;\r
72 \r
73 if(gBoardSysInitDone == 0)\r
74 {\r
75 Sciclient_configPrmsInit(&config);\r
76 \r
77 ret = Sciclient_init(&config);\r
78 \r
79 if(ret != 0)\r
80 {\r
81 status = BOARD_FAIL;\r
82 }\r
83 \r
84 if(status == BOARD_SOK)\r
85 {\r
86 gBoardSysInitDone = 1;\r
87 }\r
88 }\r
89 \r
90 return status;\r
91 }\r
92 \r
93 /**\r
94 * \brief Board global de-initializations\r
95 *\r
96 * \return BOARD_SOK in case of success or appropriate error code\r
97 *\r
98 */\r
99 static Board_STATUS Board_sysDeinit(void)\r
100 {\r
101 Board_STATUS status = BOARD_SOK;\r
102 int32_t ret;\r
103 \r
104 if(gBoardSysInitDone == 1)\r
105 {\r
106 ret = Sciclient_deinit();\r
107 if(ret != 0)\r
108 {\r
109 status = BOARD_FAIL;\r
110 }\r
111 \r
112 if(status == BOARD_SOK)\r
113 {\r
114 gBoardSysInitDone = 0;\r
115 }\r
116 }\r
117 \r
118 return status;\r
119 }\r
120 \r
121 /**\r
122 * \brief Board library initialization function\r
123 *\r
124 * Different board initialization routines are invoked by using configuration\r
125 * flags as described below\r
126 * BOARD_INIT_UNLOCK_MMR -\r
127 * Unlocks the MMR registers of the SoC. MMR registers should be\r
128 * enabled before any write access to MMR register address space.\r
129 *\r
130 * BOARD_INIT_PLL -\r
131 * Configures different PLL controller modules. This enables all the PLL\r
132 * controllers on the SoC with default configurations. Any custom values\r
133 * required for PLL output needs to be done separately\r
134 *\r
135 * BOARD_INIT_DDR -\r
136 * Initializes the DDR timing parameters. Sets the DDR timing parameters\r
137 * based in the DDR PLL controller configuration done by the board library.\r
138 * Any changes to DDR PLL requires change to DDR timing.\r
139 *\r
140 * BOARD_INIT_PINMUX_CONFIG -\r
141 * Enables pinmux for the board interfaces. Pin mux is done based on the\r
142 * default/primary functionality of the board. Any pins shared by multiple\r
143 * interfaces need to be reconfigured to access the secondary functionality.\r
144 *\r
145 * BOARD_INIT_UART_STDIO -\r
146 * Configures the UART module to use for serial console messages.\r
147 *\r
148 * BOARD_INIT_MODULE_CLOCK -\r
149 * Enables different power domains and peripheral clocks of the SoC.\r
150 * Some of the power domains and peripherals will be off by default.\r
151 * Enabling the power domains is mandatory before accessing using\r
152 * board interfaces connected to those peripherals.\r
153 *\r
154 * \param cfg [IN] Board configuration flags\r
155 *\r
156 * \return BOARD_SOK in case of success or appropriate error code\r
157 */\r
158 Board_STATUS Board_init(Board_initCfg cfg)\r
159 { \r
160 Board_STATUS ret = BOARD_SOK;\r
161 \r
162 ret = Board_sysInit();\r
163 if (ret != BOARD_SOK)\r
164 return ret;\r
165 \r
166 if (cfg & BOARD_INIT_UNLOCK_MMR)\r
167 ret = Board_unlockMMR();\r
168 if (ret != BOARD_SOK)\r
169 return ret;\r
170 \r
171 if (cfg & BOARD_INIT_MODULE_CLOCK)\r
172 ret = Board_moduleClockInit();\r
173 if (ret != BOARD_SOK)\r
174 return ret;\r
175 \r
176 if (cfg & BOARD_INIT_PINMUX_CONFIG)\r
177 ret = Board_pinmuxConfig();\r
178 if (ret != BOARD_SOK)\r
179 return ret;\r
180 \r
181 if (cfg & BOARD_INIT_PLL)\r
182 ret = Board_PLLInitAll();\r
183 if (ret != BOARD_SOK)\r
184 return ret;\r
185 \r
186 if (cfg & BOARD_INIT_DDR)\r
187 {\r
188 if (cfg & BOARD_INIT_DDR_ECC)\r
189 {\r
190 ret = Board_DDRInit(true);\r
191 }\r
192 else\r
193 {\r
194 ret = Board_DDRInit(false);\r
195 }\r
196 }\r
197 \r
198 if (ret != BOARD_SOK)\r
199 return ret;\r
200 \r
201 if (cfg & BOARD_INIT_ETH_PHY)\r
202 ret = Board_mcuEthConfig();\r
203 if (ret != BOARD_SOK)\r
204 return ret;\r
205 \r
206 if (cfg & BOARD_INIT_ICSS_ETH_PHY)\r
207 ret = Board_icssEthConfig();\r
208 if (ret != BOARD_SOK)\r
209 return ret;\r
210 \r
211 if (cfg & BOARD_INIT_UART_STDIO)\r
212 ret = Board_uartStdioInit();\r
213 if (ret != BOARD_SOK)\r
214 return ret;\r
215 \r
216 if (cfg & BOARD_INIT_SERDES_PHY)\r
217 ret = Board_serdesCfg();\r
218 if (ret != BOARD_SOK)\r
219 return ret;\r
220 \r
221 return ret;\r
222 }\r
223 \r
224 /**\r
225 * \brief Board library de-initialization function\r
226 *\r
227 * Different board de-initialization routines are invoked by using configuration\r
228 * flags as described below\r
229 *\r
230 * BOARD_DEINIT_UART_STDIO -\r
231 * Closes the board UART instance configured for serial console logs\r
232 *\r
233 * \param cfg [IN] Board configuration flags\r
234 *\r
235 * \return BOARD_SOK in case of success or appropriate error code\r
236 */\r
237 Board_STATUS Board_deinit(Board_initCfg cfg)\r
238 {\r
239 Board_STATUS ret = BOARD_SOK;\r
240 \r
241 Board_sysDeinit();\r
242 \r
243 if (cfg & BOARD_DEINIT_UART_STDIO)\r
244 ret = Board_uartDeInit();\r
245 if (ret != BOARD_SOK)\r
246 return ret;\r
247 \r
248 return ret;\r
249 }\r