1 /******************************************************************************
2 * Copyright (c) 2019-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 *****************************************************************************/
33 /**
34 * \file board_init.c
35 *
36 * \brief Board library main file
37 *
38 * Board library provides basic functions to initialize the interfaces
39 * on a given HW platform. It takes care of configuring and enabling different
40 * modules like PLL, clocks inside SoC and HW components on the board which are
41 * required to make sure board is ready for running the application software.
42 *
43 * A common standard API Board_init() is exposed to the applications to invoke
44 * different board initialization routines. This function is common across the
45 * platforms maitaining the portability and can receive different input
46 * configuration flags based on the board capabilities allowing extendibility.
47 *
48 * Board library shall eliminate the use of any additional configurations like
49 * GEL files to initialize the board except the cases like DDR initialization
50 * for loading the code into DDR before calling the Board init function.
51 * Give this limitation, applications invoking board library functions to
52 * initialize PLL, DDR and pinmux are supposed to run from SoC internal memory.
53 *
54 */
56 #include "board_internal.h"
57 #include "board_ethernet_config.h"
58 #include "board_utils.h"
59 #include "board_serdes_cfg.h"
60 #include <ti/drv/sciclient/sciclient.h>
61 #include <ti/drv/sciclient/sciserver.h>
63 static bool gBoardSysInitDone = 0;
65 /**
66 * \brief Board global initializations
67 *
68 * \return BOARD_SOK in case of success or appropriate error code
69 *
70 */
71 static Board_STATUS Board_sysInit(void)
72 {
73 Board_STATUS status = BOARD_SOK;
74 int32_t ret;
75 Sciclient_ConfigPrms_t config;
77 if(gBoardSysInitDone == 0)
78 {
79 Sciclient_configPrmsInit(&config);
81 ret = Sciclient_init(&config);
82 if(ret != 0)
83 {
84 status = BOARD_FAIL;
85 }
87 if(status == BOARD_SOK)
88 {
89 gBoardSysInitDone = 1;
90 }
91 }
93 return status;
94 }
96 /**
97 * \brief Board global de-initializations
98 *
99 * \return BOARD_SOK in case of success or appropriate error code
100 *
101 */
102 static Board_STATUS Board_sysDeinit(void)
103 {
104 Board_STATUS status = BOARD_SOK;
105 int32_t ret;
107 if(gBoardSysInitDone == 1)
108 {
109 ret = Sciclient_deinit();
110 if(ret != 0)
111 {
112 status = BOARD_FAIL;
113 }
115 if(status == BOARD_SOK)
116 {
117 gBoardSysInitDone = 0;
118 }
119 }
121 return status;
122 }
124 /**
125 * \brief Board library initialization function
126 *
127 * Different board initialization routines are invoked by using configuration
128 * flags as described below
129 * BOARD_INIT_UNLOCK_MMR -
130 * Unlocks the MMR registers of the SoC. MMR registers should be
131 * enabled before any write access to MMR register address space.
132 *
133 * BOARD_INIT_PLL -
134 * Configures different PLL controller modules. This enables all the PLL
135 * controllers on the SoC with default configurations. Any custom values
136 * required for PLL output needs to be done separately
137 *
138 * BOARD_INIT_PLL_MCU -
139 * Configures different PLL controller modules in the MCU domain. This
140 * enables all the PLL controllers in the MCUSS with default configurations.
141 * Any custom values required for PLL output needs to be done separately
142 *
143 * BOARD_INIT_PLL_MAIN -
144 * Configures different PLL controller modules in the MAIN domain. This
145 * enables all the PLL controllers in the MAIN domain with default configurations.
146 * Any custom values required for PLL output needs to be done separately
147 *
148 * BOARD_INIT_DDR -
149 * Initializes the DDR timing parameters. Sets the DDR timing parameters
150 * based in the DDR PLL controller configuration done by the board library.
151 * Any changes to DDR PLL requires change to DDR timing.
152 *
153 * BOARD_INIT_PINMUX_CONFIG -
154 * Enables pinmux for the board interfaces. Pin mux is done based on the
155 * default/primary functionality of the board. Any pins shared by multiple
156 * interfaces need to be reconfigured to access the secondary functionality.
157 *
158 * BOARD_INIT_UART_STDIO -
159 * Configures the UART module to use for serial console messages.
160 *
161 * BOARD_INIT_MODULE_CLOCK -
162 * Enables different power domains and peripheral clocks of the SoC.
163 * Some of the power domains and peripherals will be off by default.
164 * Enabling the power domains is mandatory before accessing using
165 * board interfaces connected to those peripherals.
166 *
167 * BOARD_INIT_MODULE_CLOCK_MCU -
168 * Enables different power domains and peripheral clocks in the MCU domain.
169 * Some of the power domains and peripherals will be off by default.
170 * Enabling the power domains is mandatory before accessing using
171 * board interfaces connected to those peripherals.
172 *
173 * BOARD_INIT_MODULE_CLOCK_MAIN -
174 * Enables different power domains and peripheral clocks in the MAIN domain.
175 * Some of the power domains and peripherals will be off by default.
176 * Enabling the power domains is mandatory before accessing using
177 * board interfaces connected to those peripherals.
178 *
179 * BOARD_INIT_ENETCTRL_CPSW2G -
180 * Enabled configurations for CPSW2G Ethernet ports with the respective modes
181 *
182 * BOARD_INIT_ENETCTRL_CPSW9G -
183 * Enabled configurations for CPSW9G Ethernet ports with the respective modes
184 *
185 * BOARD_INIT_ENETCTRL_ICSS -
186 * Enabled configurations for ICSS Ethernet ports with the respective modes
187 *
188 * \param cfg [IN] Board configuration flags
189 *
190 * \return BOARD_SOK in case of success or appropriate error code
191 */
192 Board_STATUS Board_init(Board_initCfg cfg)
193 {
194 Board_STATUS ret = BOARD_SOK;
196 if(!gBoardSysInitDone)
197 {
198 Board_sysInit();
199 }
201 if (cfg & BOARD_INIT_UNLOCK_MMR)
202 ret = Board_unlockMMR();
203 if (ret != BOARD_SOK)
204 return ret;
206 if (cfg & BOARD_INIT_ENETCTRL_CPSW2G)
207 ret = Board_ethConfigCpsw2g();
208 if (ret != BOARD_SOK)
209 return ret;
211 if (cfg & BOARD_INIT_ENETCTRL_CPSW9G)
212 ret = Board_ethConfigCpsw9g();
213 if (ret != BOARD_SOK)
214 return ret;
216 if (cfg & BOARD_INIT_ENETCTRL_ICSS)
217 ret = Board_ethConfigIcss();
218 if (ret != BOARD_SOK)
219 return ret;
221 if (cfg & BOARD_INIT_MODULE_CLOCK)
222 {
223 ret = Board_moduleClockInitMcu();
224 if (ret != BOARD_SOK)
225 return ret;
226 ret = Board_moduleClockInitMain();
227 if (ret != BOARD_SOK)
228 return ret;
229 }
231 if (cfg & BOARD_INIT_MODULE_CLOCK_MCU)
232 ret = Board_moduleClockInitMcu();
233 if (ret != BOARD_SOK)
234 return ret;
236 if (cfg & BOARD_INIT_MODULE_CLOCK_MAIN)
237 ret = Board_moduleClockInitMain();
238 if (ret != BOARD_SOK)
239 return ret;
241 if (cfg & BOARD_INIT_PINMUX_CONFIG)
242 ret = Board_pinmuxConfig();
243 if (ret != BOARD_SOK)
244 return ret;
246 if (cfg & BOARD_INIT_PINMUX_CONFIG_MAIN)
247 ret = Board_pinmuxConfigMain();
248 if (ret != BOARD_SOK)
249 return ret;
251 if (cfg & BOARD_INIT_PINMUX_CONFIG_MCU)
252 ret = Board_pinmuxConfigWkup();
253 if (ret != BOARD_SOK)
254 return ret;
256 if (cfg & BOARD_INIT_PLL)
257 {
258 ret = Board_PLLInitMcu();
259 if (ret != BOARD_SOK)
260 return ret;
261 ret = Board_PLLInitMain();
262 if (ret != BOARD_SOK)
263 return ret;
264 }
266 if (cfg & BOARD_INIT_PLL_MCU)
267 ret = Board_PLLInitMcu();
268 if (ret != BOARD_SOK)
269 return ret;
271 if (cfg & BOARD_INIT_PLL_MAIN)
272 ret = Board_PLLInitMain();
273 if (ret != BOARD_SOK)
274 return ret;
276 if (cfg & BOARD_INIT_DDR)
277 {
278 if (cfg & BOARD_INIT_DDR_ECC)
279 {
280 ret = Board_DDRInit(true);
281 }
282 else
283 {
284 ret = Board_DDRInit(false);
285 }
286 }
288 if (ret != BOARD_SOK)
289 return ret;
291 if (cfg & BOARD_INIT_ETH_PHY)
292 ret = Board_cpsw2gEthPhyConfig();
293 if (ret != BOARD_SOK)
294 return ret;
296 if (cfg & BOARD_INIT_ICSS_ETH_PHY)
297 ret = Board_icssEthPhyConfig();
298 if (ret != BOARD_SOK)
299 return ret;
301 if (cfg & BOARD_INIT_CPSW9G_ETH_PHY)
302 ret = Board_cpsw9gEthPhyConfig();
303 if (ret != BOARD_SOK)
304 return ret;
306 if (cfg & BOARD_INIT_UART_STDIO)
307 ret = Board_uartStdioInit();
308 if (ret != BOARD_SOK)
309 return ret;
311 return ret;
312 }
314 /**
315 * \brief Board library de-initialization function
316 *
317 * Different board de-initialization routines are invoked by using configuration
318 * flags as described below
319 * BOARD_DEINIT_LOCK_MMR -
320 * Locks the MMR registers of the SoC.
321 *
322 * BOARD_DEINIT_UART_STDIO -
323 * Closes the board UART instance configured for serial console logs
324 *
325 * BOARD_DEINIT_MODULE_CLOCK -
326 * Disables PSC modules clocks which are enabled by Board_init function
327 *
328 * BOARD_DEINIT_UART_STDIO -
329 * Deinitializes the UART module.
330 *
331 * \param cfg [IN] Board configuration flags
332 *
333 * \return BOARD_SOK in case of success or appropriate error code
334 */
335 Board_STATUS Board_deinit(Board_initCfg cfg)
336 {
337 Board_STATUS ret = BOARD_SOK;
339 Board_sysDeinit();
341 if (cfg & BOARD_DEINIT_UART_STDIO)
342 ret = Board_uartDeInit();
343 if (ret != BOARD_SOK)
344 return ret;
346 if (cfg & BOARD_DEINIT_MODULE_CLOCK)
347 {
348 ret = Board_moduleClockDeinitMcu();
349 if (ret != BOARD_SOK)
350 return ret;
351 ret = Board_moduleClockDeinitMain();
352 if (ret != BOARD_SOK)
353 return ret;
354 }
356 if (cfg & BOARD_DEINIT_LOCK_MMR)
357 ret = Board_lockMMR();
358 if (ret != BOARD_SOK)
359 return ret;
361 return ret;
362 }