]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/standalone_v5_4/src/xil_misc_psreset_api.c
Update the Microblaze hardware design and BSP to the latest IP and tool versions.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / standalone_v5_4 / src / xil_misc_psreset_api.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2013 - 2014 Xilinx, Inc. All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xil_misc_reset.c
36 *
37 * This file contains the implementation of the reset sequence for various
38 * zynq ps devices like DDR,OCM,Slcr,Ethernet,Usb.. controllers. The reset
39 * sequence provided to the interfaces is based on the provision in
40 * slcr reset functional blcok.
41 *
42 * <pre>
43 * MODIFICATION HISTORY:
44 *
45 * Ver   Who    Date   Changes
46 * ----- ---- -------- -------------------------------------------------------
47 * 1.00b kpc   03/07/13 First release
48 * 5.4   pkp       16/11/15 Change the description for XOcm_Remap function
49 * </pre>
50 *
51 ******************************************************************************/
52
53
54 /***************************** Include Files *********************************/
55 #include "xil_misc_psreset_api.h"
56
57 /************************** Constant Definitions *****************************/
58
59
60 /**************************** Type Definitions *******************************/
61
62
63 /***************** Macros (Inline Functions) Definitions *********************/
64
65
66 /************************** Function Prototypes ******************************/
67
68
69 /*****************************************************************************/
70 /**
71 * This function contains the implementation for ddr reset.
72 *
73 * @param   N/A.
74 *
75 * @return   N/A.
76 *
77 * @note     None.
78 *
79 ******************************************************************************/
80 void XDdr_ResetHw(void)
81 {
82         u32 RegVal;
83
84         /* Unlock the slcr register access lock */
85          Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
86         /* Assert and deassert the ddr softreset bit */
87      RegVal =   Xil_In32(XDDRC_CTRL_BASEADDR);
88          RegVal &= (u32)(~XDDRPS_CTRL_RESET_MASK);
89          Xil_Out32(XDDRC_CTRL_BASEADDR,RegVal);
90          RegVal |= XDDRPS_CTRL_RESET_MASK;
91          Xil_Out32(XDDRC_CTRL_BASEADDR,RegVal);
92
93 }
94
95 /*****************************************************************************/
96 /**
97 * This function contains the implementation for remapping the ocm memory region
98 * to postbootrom state.
99 *
100 * @param   N/A.
101 *
102 * @return   N/A.
103 *
104 * @note     None.
105 *
106 ******************************************************************************/
107 void XOcm_Remap(void)
108 {
109         u32 RegVal;
110
111         /* Unlock the slcr register access lock */
112         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
113         /* Map the ocm region to postbootrom state */
114         RegVal = Xil_In32(XSLCR_OCM_CFG_ADDR);
115         RegVal = (RegVal & (u32)(~XSLCR_OCM_CFG_HIADDR_MASK)) | (u32)XSLCR_OCM_CFG_RESETVAL;
116         Xil_Out32(XSLCR_OCM_CFG_ADDR, RegVal);
117 }
118
119 /*****************************************************************************/
120 /**
121 * This function contains the implementation for SMC reset sequence
122 *
123 * @param   BaseAddress of the interface
124 *
125 * @return   N/A.
126 *
127 * @note     None.
128 *
129 ******************************************************************************/
130 void XSmc_ResetHw(u32 BaseAddress)
131 {
132         u32 RegVal;
133
134         /* Clear the interuupts */
135         RegVal = Xil_In32(BaseAddress + XSMC_MEMC_CLR_CONFIG_OFFSET);
136         RegVal |= XSMC_MEMC_CLR_CONFIG_MASK;
137         Xil_Out32(BaseAddress + XSMC_MEMC_CLR_CONFIG_OFFSET, RegVal);
138         /* Clear the idle counter registers */
139         Xil_Out32(BaseAddress + XSMC_REFRESH_PERIOD_0_OFFSET, 0x0U);
140         Xil_Out32(BaseAddress + XSMC_REFRESH_PERIOD_1_OFFSET, 0x0U);
141         /* Update the ecc registers with reset values */
142         Xil_Out32(BaseAddress + XSMC_ECC_MEMCFG1_OFFSET,
143                                                         XSMC_ECC_MEMCFG1_RESET_VAL);
144         Xil_Out32(BaseAddress + XSMC_ECC_MEMCMD1_OFFSET,
145                                                         XSMC_ECC_MEMCMD1_RESET_VAL);
146         Xil_Out32(BaseAddress + XSMC_ECC_MEMCMD2_OFFSET,
147                                                         XSMC_ECC_MEMCMD2_RESET_VAL);
148
149 }
150
151 /*****************************************************************************/
152 /**
153 * This function contains the implementation for updating the slcr mio registers
154 * with reset values
155 * @param   N/A.
156 *
157 * @return   N/A.
158 *
159 * @note     None.
160 *
161 ******************************************************************************/
162 void XSlcr_MioWriteResetValues(void)
163 {
164         u32 i;
165
166         /* Unlock the slcr register access lock */
167         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
168         /* Update all the MIO registers with reset values */
169     for (i=0U; i<=1U;i++)
170         {
171                 Xil_Out32((XSLCR_MIO_PIN_00_ADDR + (i * 4U)),
172                                                                 XSLCR_MIO_PIN_00_RESET_VAL);
173         }
174         for (; i<=8U;i++)
175         {
176                 Xil_Out32((XSLCR_MIO_PIN_00_ADDR + (i * 4U)),
177                                                                 XSLCR_MIO_PIN_02_RESET_VAL);
178         }
179         for (; i<=53U ;i++)
180         {
181                 Xil_Out32((XSLCR_MIO_PIN_00_ADDR + (i * 4U)),
182                                                                 XSLCR_MIO_PIN_00_RESET_VAL);
183         }
184
185
186 }
187
188 /*****************************************************************************/
189 /**
190 * This function contains the implementation for updating the slcr pll registers
191 * with reset values
192 * @param   N/A.
193 *
194 * @return   N/A.
195 *
196 * @note     None.
197 *
198 ******************************************************************************/
199 void XSlcr_PllWriteResetValues(void)
200 {
201
202         /* Unlock the slcr register access lock */
203         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
204
205         /* update the pll control registers with reset values */
206         Xil_Out32(XSLCR_IO_PLL_CTRL_ADDR, XSLCR_IO_PLL_CTRL_RESET_VAL);
207         Xil_Out32(XSLCR_ARM_PLL_CTRL_ADDR, XSLCR_ARM_PLL_CTRL_RESET_VAL);
208         Xil_Out32(XSLCR_DDR_PLL_CTRL_ADDR, XSLCR_DDR_PLL_CTRL_RESET_VAL);
209         /* update the pll config registers with reset values */
210         Xil_Out32(XSLCR_IO_PLL_CFG_ADDR, XSLCR_IO_PLL_CFG_RESET_VAL);
211         Xil_Out32(XSLCR_ARM_PLL_CFG_ADDR, XSLCR_ARM_PLL_CFG_RESET_VAL);
212         Xil_Out32(XSLCR_DDR_PLL_CFG_ADDR, XSLCR_DDR_PLL_CFG_RESET_VAL);
213         /* update the clock control registers with reset values */
214         Xil_Out32(XSLCR_ARM_CLK_CTRL_ADDR, XSLCR_ARM_CLK_CTRL_RESET_VAL);
215         Xil_Out32(XSLCR_DDR_CLK_CTRL_ADDR, XSLCR_DDR_CLK_CTRL_RESET_VAL);
216 }
217
218 /*****************************************************************************/
219 /**
220 * This function contains the implementation for disabling the level shifters
221 *
222 * @param   N/A.
223 *
224 * @return   N/A.
225 *
226 * @note     None.
227 *
228 ******************************************************************************/
229 void XSlcr_DisableLevelShifters(void)
230 {
231         u32 RegVal;
232         /* Unlock the slcr register access lock */
233         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
234         /* Disable the level shifters */
235         RegVal = Xil_In32(XSLCR_LVL_SHFTR_EN_ADDR);
236         RegVal = RegVal & (u32)(~XSLCR_LVL_SHFTR_EN_MASK);
237         Xil_Out32(XSLCR_LVL_SHFTR_EN_ADDR, RegVal);
238
239 }
240 /*****************************************************************************/
241 /**
242 * This function contains the implementation for OCM software reset from the
243 * slcr
244 *
245 * @param   N/A.
246 *
247 * @return   N/A.
248 *
249 * @note     None.
250 *
251 ******************************************************************************/
252 void XSlcr_OcmReset(void)
253 {
254         u32 RegVal;
255         /* Unlock the slcr register access lock */
256         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
257         /* Assert the reset */
258         RegVal = Xil_In32(XSLCR_OCM_RST_CTRL_ADDR);
259         RegVal |= XSLCR_OCM_RST_CTRL_VAL;
260         Xil_Out32(XSLCR_OCM_RST_CTRL_ADDR, RegVal);
261         /* Release the reset */
262         RegVal = Xil_In32(XSLCR_OCM_RST_CTRL_ADDR);
263         RegVal = RegVal & (u32)(~XSLCR_OCM_RST_CTRL_VAL);
264         Xil_Out32(XSLCR_OCM_RST_CTRL_ADDR, RegVal);
265 }
266
267 /*****************************************************************************/
268 /**
269 * This function contains the implementation for Ethernet software reset from
270 * the slcr
271 * @param   N/A.
272 *
273 * @return   N/A.
274 *
275 * @note     None.
276 *
277 ******************************************************************************/
278 void XSlcr_EmacPsReset(void)
279 {
280         u32 RegVal;
281         /* Unlock the slcr register access lock */
282         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
283         /* Assert the reset */
284         RegVal = Xil_In32(XSLCR_GEM_RST_CTRL_ADDR);
285         RegVal |= XSLCR_GEM_RST_CTRL_VAL;
286         Xil_Out32(XSLCR_GEM_RST_CTRL_ADDR, RegVal);
287         /* Release the reset */
288         RegVal = Xil_In32(XSLCR_GEM_RST_CTRL_ADDR);
289         RegVal &= (u32)(~XSLCR_GEM_RST_CTRL_VAL);
290         Xil_Out32(XSLCR_GEM_RST_CTRL_ADDR, RegVal);
291 }
292
293 /*****************************************************************************/
294 /**
295 * This function contains the implementation for USB software reset from the
296 * slcr
297 *
298 * @param   N/A.
299 *
300 * @return   N/A.
301 *
302 * @note     None.
303 *
304 ******************************************************************************/
305 void XSlcr_UsbPsReset(void)
306 {
307         u32 RegVal;
308         /* Unlock the slcr register access lock */
309         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
310         /* Assert the reset */
311         RegVal = Xil_In32(XSLCR_USB_RST_CTRL_ADDR);
312         RegVal |= XSLCR_USB_RST_CTRL_VAL;
313         Xil_Out32(XSLCR_USB_RST_CTRL_ADDR, RegVal);
314         /* Release the reset */
315         RegVal = Xil_In32(XSLCR_USB_RST_CTRL_ADDR);
316         RegVal = RegVal & (u32)(~XSLCR_USB_RST_CTRL_VAL);
317         Xil_Out32(XSLCR_USB_RST_CTRL_ADDR, RegVal);
318 }
319 /*****************************************************************************/
320 /**
321 * This function contains the implementation for QSPI software reset from the
322 * slcr
323 *
324 * @param   N/A.
325 *
326 * @return   N/A.
327 *
328 * @note     None.
329 *
330 ******************************************************************************/
331 void XSlcr_QspiPsReset(void)
332 {
333         u32 RegVal;
334         /* Unlock the slcr register access lock */
335         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
336         /* Assert the reset */
337         RegVal = Xil_In32(XSLCR_LQSPI_RST_CTRL_ADDR);
338         RegVal |= XSLCR_QSPI_RST_CTRL_VAL;
339         Xil_Out32(XSLCR_LQSPI_RST_CTRL_ADDR, RegVal);
340         /* Release the reset */
341         RegVal = Xil_In32(XSLCR_LQSPI_RST_CTRL_ADDR);
342         RegVal = RegVal & (u32)(~XSLCR_QSPI_RST_CTRL_VAL);
343         Xil_Out32(XSLCR_LQSPI_RST_CTRL_ADDR, RegVal);
344 }
345 /*****************************************************************************/
346 /**
347 * This function contains the implementation for SPI software reset from the
348 * slcr
349 *
350 * @param   N/A.
351 *
352 * @return   N/A.
353 *
354 * @note     None.
355 *
356 ******************************************************************************/
357 void XSlcr_SpiPsReset(void)
358 {
359         u32 RegVal;
360         /* Unlock the slcr register access lock */
361         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
362         /* Assert the reset */
363         RegVal = Xil_In32(XSLCR_SPI_RST_CTRL_ADDR);
364         RegVal |= XSLCR_SPI_RST_CTRL_VAL;
365         Xil_Out32(XSLCR_SPI_RST_CTRL_ADDR, RegVal);
366         /* Release the reset */
367         RegVal = Xil_In32(XSLCR_SPI_RST_CTRL_ADDR);
368         RegVal = RegVal & (u32)(~XSLCR_SPI_RST_CTRL_VAL);
369         Xil_Out32(XSLCR_SPI_RST_CTRL_ADDR, RegVal);
370 }
371 /*****************************************************************************/
372 /**
373 * This function contains the implementation for i2c software reset from the slcr
374 *
375 * @param   N/A.
376 *
377 * @return   N/A.
378 *
379 * @note     None.
380 *
381 ******************************************************************************/
382 void XSlcr_I2cPsReset(void)
383 {
384         u32 RegVal;
385         /* Unlock the slcr register access lock */
386         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
387         /* Assert the reset */
388         RegVal = Xil_In32(XSLCR_I2C_RST_CTRL_ADDR);
389         RegVal |= XSLCR_I2C_RST_CTRL_VAL;
390         Xil_Out32(XSLCR_I2C_RST_CTRL_ADDR, RegVal);
391         /* Release the reset */
392         RegVal = Xil_In32(XSLCR_I2C_RST_CTRL_ADDR);
393         RegVal = RegVal & (u32)(~XSLCR_I2C_RST_CTRL_VAL);
394         Xil_Out32(XSLCR_I2C_RST_CTRL_ADDR, RegVal);
395 }
396 /*****************************************************************************/
397 /**
398 * This function contains the implementation for UART software reset from the
399 * slcr
400 *
401 * @param   N/A.
402 *
403 * @return   N/A.
404 *
405 * @note     None.
406 *
407 ******************************************************************************/
408 void XSlcr_UartPsReset(void)
409 {
410         u32 RegVal;
411         /* Unlock the slcr register access lock */
412         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
413         /* Assert the reset */
414         RegVal = Xil_In32(XSLCR_UART_RST_CTRL_ADDR);
415         RegVal |= XSLCR_UART_RST_CTRL_VAL;
416         Xil_Out32(XSLCR_UART_RST_CTRL_ADDR, RegVal);
417         /* Release the reset */
418         RegVal = Xil_In32(XSLCR_UART_RST_CTRL_ADDR);
419         RegVal = RegVal & (u32)(~XSLCR_UART_RST_CTRL_VAL);
420         Xil_Out32(XSLCR_UART_RST_CTRL_ADDR, RegVal);
421 }
422 /*****************************************************************************/
423 /**
424 * This function contains the implementation for CAN software reset from slcr
425 * registers
426 *
427 * @param   N/A.
428 *
429 * @return   N/A.
430 *
431 * @note     None.
432 *
433 ******************************************************************************/
434 void XSlcr_CanPsReset(void)
435 {
436         u32 RegVal;
437         /* Unlock the slcr register access lock */
438         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
439         /* Assert the reset */
440         RegVal = Xil_In32(XSLCR_CAN_RST_CTRL_ADDR);
441         RegVal |= XSLCR_CAN_RST_CTRL_VAL;
442         Xil_Out32(XSLCR_CAN_RST_CTRL_ADDR, RegVal);
443         /* Release the reset */
444         RegVal = Xil_In32(XSLCR_CAN_RST_CTRL_ADDR);
445         RegVal = RegVal & (u32)(~XSLCR_CAN_RST_CTRL_VAL);
446         Xil_Out32(XSLCR_CAN_RST_CTRL_ADDR, RegVal);
447 }
448 /*****************************************************************************/
449 /**
450 * This function contains the implementation for SMC software reset from the slcr
451 *
452 * @param   N/A.
453 *
454 * @return   N/A.
455 *
456 * @note     None.
457 *
458 ******************************************************************************/
459 void XSlcr_SmcPsReset(void)
460 {
461         u32 RegVal;
462         /* Unlock the slcr register access lock */
463         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
464         /* Assert the reset */
465         RegVal = Xil_In32(XSLCR_SMC_RST_CTRL_ADDR);
466         RegVal |= XSLCR_SMC_RST_CTRL_VAL;
467         Xil_Out32(XSLCR_SMC_RST_CTRL_ADDR, RegVal);
468         /* Release the reset */
469         RegVal = Xil_In32(XSLCR_SMC_RST_CTRL_ADDR);
470         RegVal = RegVal & (u32)(~XSLCR_SMC_RST_CTRL_VAL);
471         Xil_Out32(XSLCR_SMC_RST_CTRL_ADDR, RegVal);
472 }
473 /*****************************************************************************/
474 /**
475 * This function contains the implementation for DMA controller software reset
476 * from the slcr
477 *
478 * @param   N/A.
479 *
480 * @return   N/A.
481 *
482 * @note     None.
483 *
484 ******************************************************************************/
485 void XSlcr_DmaPsReset(void)
486 {
487         u32 RegVal;
488         /* Unlock the slcr register access lock */
489         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
490         /* Assert the reset */
491         RegVal = Xil_In32(XSLCR_DMAC_RST_CTRL_ADDR);
492         RegVal |= XSLCR_DMAC_RST_CTRL_VAL;
493         Xil_Out32(XSLCR_DMAC_RST_CTRL_ADDR, RegVal);
494         /* Release the reset */
495         RegVal = Xil_In32(XSLCR_DMAC_RST_CTRL_ADDR);
496         RegVal = RegVal & (u32)(~XSLCR_DMAC_RST_CTRL_VAL);
497         Xil_Out32(XSLCR_DMAC_RST_CTRL_ADDR, RegVal);
498 }
499 /*****************************************************************************/
500 /**
501 * This function contains the implementation for Gpio AMBA software reset from
502 * the slcr
503 *
504 * @param   N/A.
505 *
506 * @return   N/A.
507 *
508 * @note     None.
509 *
510 ******************************************************************************/
511 void XSlcr_GpioPsReset(void)
512 {
513         u32 RegVal;
514         /* Unlock the slcr register access lock */
515         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
516         /* Assert the reset */
517         RegVal = Xil_In32(XSLCR_GPIO_RST_CTRL_ADDR);
518         RegVal |= XSLCR_GPIO_RST_CTRL_VAL;
519         Xil_Out32(XSLCR_GPIO_RST_CTRL_ADDR, RegVal);
520         /* Release the reset */
521         RegVal = Xil_In32(XSLCR_GPIO_RST_CTRL_ADDR);
522         RegVal = RegVal & (u32)(~XSLCR_GPIO_RST_CTRL_VAL);
523         Xil_Out32(XSLCR_GPIO_RST_CTRL_ADDR, RegVal);
524 }