]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v4_1/src/xil_misc_psreset_api.c
Preparing for next release...
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v4_1 / 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 * </pre>
49 *
50 ******************************************************************************/
51
52
53 /***************************** Include Files *********************************/
54 #include "xil_misc_psreset_api.h"
55
56 /************************** Constant Definitions *****************************/
57
58
59 /**************************** Type Definitions *******************************/
60
61
62 /***************** Macros (Inline Functions) Definitions *********************/
63
64
65 /************************** Function Prototypes ******************************/
66
67
68 /*****************************************************************************/
69 /**
70 * This function contains the implementation for ddr reset.
71 *
72 * @param   N/A.
73 *
74 * @return   N/A.
75 *
76 * @note     None.
77 *
78 ******************************************************************************/
79 void XDdr_ResetHw()
80 {
81         u32 RegVal;
82
83         /* Unlock the slcr register access lock */
84          Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
85         /* Assert and deassert the ddr softreset bit */
86      RegVal =   Xil_In32(XDDRC_CTRL_BASEADDR);
87          RegVal &= ~XDDRPS_CTRL_RESET_MASK;
88          Xil_Out32(XDDRC_CTRL_BASEADDR,RegVal);
89          RegVal |= XDDRPS_CTRL_RESET_MASK;
90          Xil_Out32(XDDRC_CTRL_BASEADDR,RegVal);
91
92 }
93
94 /*****************************************************************************/
95 /**
96 * This function contains the implementation for remapping the ocm memory region
97 *
98 * @param   N/A.
99 *
100 * @return   N/A.
101 *
102 * @note     None.
103 *
104 ******************************************************************************/
105 void XOcm_Remap()
106 {
107         u32 RegVal;
108
109         /* Unlock the slcr register access lock */
110         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
111         /* Map the ocm region to postbootrom state */
112         RegVal = Xil_In32(XSLCR_OCM_CFG_ADDR);
113         RegVal = (RegVal & ~XSLCR_OCM_CFG_HIADDR_MASK) | XSLCR_OCM_CFG_RESETVAL;
114         Xil_Out32(XSLCR_OCM_CFG_ADDR, RegVal);
115 }
116
117 /*****************************************************************************/
118 /**
119 * This function contains the implementation for SMC reset sequence
120 *
121 * @param   BaseAddress of the interface
122 *
123 * @return   N/A.
124 *
125 * @note     None.
126 *
127 ******************************************************************************/
128 void XSmc_ResetHw(u32 BaseAddress)
129 {
130         u32 RegVal;
131
132         /* Clear the interuupts */
133         RegVal = Xil_In32(BaseAddress + XSMC_MEMC_CLR_CONFIG_OFFSET);
134         RegVal = RegVal | XSMC_MEMC_CLR_CONFIG_MASK;
135         Xil_Out32(BaseAddress + XSMC_MEMC_CLR_CONFIG_OFFSET, RegVal);
136         /* Clear the idle counter registers */
137         Xil_Out32(BaseAddress + XSMC_REFRESH_PERIOD_0_OFFSET, 0x0);
138         Xil_Out32(BaseAddress + XSMC_REFRESH_PERIOD_1_OFFSET, 0x0);
139         /* Update the ecc registers with reset values */
140         Xil_Out32(BaseAddress + XSMC_ECC_MEMCFG1_OFFSET,
141                                                         XSMC_ECC_MEMCFG1_RESET_VAL);
142         Xil_Out32(BaseAddress + XSMC_ECC_MEMCMD1_OFFSET,
143                                                         XSMC_ECC_MEMCMD1_RESET_VAL);
144         Xil_Out32(BaseAddress + XSMC_ECC_MEMCMD2_OFFSET,
145                                                         XSMC_ECC_MEMCMD2_RESET_VAL);
146
147 }
148
149 /*****************************************************************************/
150 /**
151 * This function contains the implementation for updating the slcr mio registers
152 * with reset values
153 * @param   N/A.
154 *
155 * @return   N/A.
156 *
157 * @note     None.
158 *
159 ******************************************************************************/
160 void XSlcr_MioWriteResetValues()
161 {
162         u32 i;
163
164         /* Unlock the slcr register access lock */
165         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
166         /* Update all the MIO registers with reset values */
167     for (i=0; i<=1;i++);
168         {
169                 Xil_Out32((XSLCR_MIO_PIN_00_ADDR + (i * 4)),
170                                                                 XSLCR_MIO_PIN_00_RESET_VAL);
171         }
172         for (; i<=8;i++);
173         {
174                 Xil_Out32((XSLCR_MIO_PIN_00_ADDR + (i * 4)),
175                                                                 XSLCR_MIO_PIN_02_RESET_VAL);
176         }
177         for (; i<=53 ;i++);
178         {
179                 Xil_Out32((XSLCR_MIO_PIN_00_ADDR + (i * 4)),
180                                                                 XSLCR_MIO_PIN_00_RESET_VAL);
181         }
182
183
184 }
185
186 /*****************************************************************************/
187 /**
188 * This function contains the implementation for updating the slcr pll registers
189 * with reset values
190 * @param   N/A.
191 *
192 * @return   N/A.
193 *
194 * @note     None.
195 *
196 ******************************************************************************/
197 void XSlcr_PllWriteResetValues()
198 {
199
200         /* Unlock the slcr register access lock */
201         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
202
203         /* update the pll control registers with reset values */
204         Xil_Out32(XSLCR_IO_PLL_CTRL_ADDR, XSLCR_IO_PLL_CTRL_RESET_VAL);
205         Xil_Out32(XSLCR_ARM_PLL_CTRL_ADDR, XSLCR_ARM_PLL_CTRL_RESET_VAL);
206         Xil_Out32(XSLCR_DDR_PLL_CTRL_ADDR, XSLCR_DDR_PLL_CTRL_RESET_VAL);
207         /* update the pll config registers with reset values */
208         Xil_Out32(XSLCR_IO_PLL_CFG_ADDR, XSLCR_IO_PLL_CFG_RESET_VAL);
209         Xil_Out32(XSLCR_ARM_PLL_CFG_ADDR, XSLCR_ARM_PLL_CFG_RESET_VAL);
210         Xil_Out32(XSLCR_DDR_PLL_CFG_ADDR, XSLCR_DDR_PLL_CFG_RESET_VAL);
211         /* update the clock control registers with reset values */
212         Xil_Out32(XSLCR_ARM_CLK_CTRL_ADDR, XSLCR_ARM_CLK_CTRL_RESET_VAL);
213         Xil_Out32(XSLCR_DDR_CLK_CTRL_ADDR, XSLCR_DDR_CLK_CTRL_RESET_VAL);
214 }
215
216 /*****************************************************************************/
217 /**
218 * This function contains the implementation for disabling the level shifters
219 *
220 * @param   N/A.
221 *
222 * @return   N/A.
223 *
224 * @note     None.
225 *
226 ******************************************************************************/
227 void XSlcr_DisableLevelShifters()
228 {
229         u32 RegVal;
230         /* Unlock the slcr register access lock */
231         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
232         /* Disable the level shifters */
233         RegVal = Xil_In32(XSLCR_LVL_SHFTR_EN_ADDR);
234         RegVal = RegVal & ~XSLCR_LVL_SHFTR_EN_MASK;
235         Xil_Out32(XSLCR_LVL_SHFTR_EN_ADDR, RegVal);
236
237 }
238 /*****************************************************************************/
239 /**
240 * This function contains the implementation for OCM software reset from the
241 * slcr
242 *
243 * @param   N/A.
244 *
245 * @return   N/A.
246 *
247 * @note     None.
248 *
249 ******************************************************************************/
250 void XSlcr_OcmReset(void)
251 {
252         u32 RegVal;
253         /* Unlock the slcr register access lock */
254         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
255         /* Assert the reset */
256         RegVal = Xil_In32(XSLCR_OCM_RST_CTRL_ADDR);
257         RegVal = RegVal | XSLCR_OCM_RST_CTRL_VAL;
258         Xil_Out32(XSLCR_OCM_RST_CTRL_ADDR, RegVal);
259         /* Release the reset */
260         RegVal = Xil_In32(XSLCR_OCM_RST_CTRL_ADDR);
261         RegVal = RegVal & ~XSLCR_OCM_RST_CTRL_VAL;
262         Xil_Out32(XSLCR_OCM_RST_CTRL_ADDR, RegVal);
263 }
264
265 /*****************************************************************************/
266 /**
267 * This function contains the implementation for Ethernet software reset from
268 * the slcr
269 * @param   N/A.
270 *
271 * @return   N/A.
272 *
273 * @note     None.
274 *
275 ******************************************************************************/
276 void XSlcr_EmacPsReset(void)
277 {
278         u32 RegVal;
279         /* Unlock the slcr register access lock */
280         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
281         /* Assert the reset */
282         RegVal = Xil_In32(XSLCR_GEM_RST_CTRL_ADDR);
283         RegVal = RegVal | XSLCR_GEM_RST_CTRL_VAL;
284         Xil_Out32(XSLCR_GEM_RST_CTRL_ADDR, RegVal);
285         /* Release the reset */
286         RegVal = Xil_In32(XSLCR_GEM_RST_CTRL_ADDR);
287         RegVal = RegVal & ~XSLCR_GEM_RST_CTRL_VAL;
288         Xil_Out32(XSLCR_GEM_RST_CTRL_ADDR, RegVal);
289 }
290
291 /*****************************************************************************/
292 /**
293 * This function contains the implementation for USB software reset from the
294 * slcr
295 *
296 * @param   N/A.
297 *
298 * @return   N/A.
299 *
300 * @note     None.
301 *
302 ******************************************************************************/
303 void XSlcr_UsbPsReset(void)
304 {
305         u32 RegVal;
306         /* Unlock the slcr register access lock */
307         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
308         /* Assert the reset */
309         RegVal = Xil_In32(XSLCR_USB_RST_CTRL_ADDR);
310         RegVal = RegVal | XSLCR_USB_RST_CTRL_VAL;
311         Xil_Out32(XSLCR_USB_RST_CTRL_ADDR, RegVal);
312         /* Release the reset */
313         RegVal = Xil_In32(XSLCR_USB_RST_CTRL_ADDR);
314         RegVal = RegVal & ~XSLCR_USB_RST_CTRL_VAL;
315         Xil_Out32(XSLCR_USB_RST_CTRL_ADDR, RegVal);
316 }
317 /*****************************************************************************/
318 /**
319 * This function contains the implementation for QSPI software reset from the
320 * slcr
321 *
322 * @param   N/A.
323 *
324 * @return   N/A.
325 *
326 * @note     None.
327 *
328 ******************************************************************************/
329 void XSlcr_QspiPsReset(void)
330 {
331         u32 RegVal;
332         /* Unlock the slcr register access lock */
333         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
334         /* Assert the reset */
335         RegVal = Xil_In32(XSLCR_LQSPI_RST_CTRL_ADDR);
336         RegVal = RegVal | XSLCR_QSPI_RST_CTRL_VAL;
337         Xil_Out32(XSLCR_LQSPI_RST_CTRL_ADDR, RegVal);
338         /* Release the reset */
339         RegVal = Xil_In32(XSLCR_LQSPI_RST_CTRL_ADDR);
340         RegVal = RegVal & ~XSLCR_QSPI_RST_CTRL_VAL;
341         Xil_Out32(XSLCR_LQSPI_RST_CTRL_ADDR, RegVal);
342 }
343 /*****************************************************************************/
344 /**
345 * This function contains the implementation for SPI software reset from the
346 * slcr
347 *
348 * @param   N/A.
349 *
350 * @return   N/A.
351 *
352 * @note     None.
353 *
354 ******************************************************************************/
355 void XSlcr_SpiPsReset(void)
356 {
357         u32 RegVal;
358         /* Unlock the slcr register access lock */
359         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
360         /* Assert the reset */
361         RegVal = Xil_In32(XSLCR_SPI_RST_CTRL_ADDR);
362         RegVal = RegVal | XSLCR_SPI_RST_CTRL_VAL;
363         Xil_Out32(XSLCR_SPI_RST_CTRL_ADDR, RegVal);
364         /* Release the reset */
365         RegVal = Xil_In32(XSLCR_SPI_RST_CTRL_ADDR);
366         RegVal = RegVal & ~XSLCR_SPI_RST_CTRL_VAL;
367         Xil_Out32(XSLCR_SPI_RST_CTRL_ADDR, RegVal);
368 }
369 /*****************************************************************************/
370 /**
371 * This function contains the implementation for i2c software reset from the slcr
372 *
373 * @param   N/A.
374 *
375 * @return   N/A.
376 *
377 * @note     None.
378 *
379 ******************************************************************************/
380 void XSlcr_I2cPsReset(void)
381 {
382         u32 RegVal;
383         /* Unlock the slcr register access lock */
384         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
385         /* Assert the reset */
386         RegVal = Xil_In32(XSLCR_I2C_RST_CTRL_ADDR);
387         RegVal = RegVal | XSLCR_I2C_RST_CTRL_VAL;
388         Xil_Out32(XSLCR_I2C_RST_CTRL_ADDR, RegVal);
389         /* Release the reset */
390         RegVal = Xil_In32(XSLCR_I2C_RST_CTRL_ADDR);
391         RegVal = RegVal & ~XSLCR_I2C_RST_CTRL_VAL;
392         Xil_Out32(XSLCR_I2C_RST_CTRL_ADDR, RegVal);
393 }
394 /*****************************************************************************/
395 /**
396 * This function contains the implementation for UART software reset from the
397 * slcr
398 *
399 * @param   N/A.
400 *
401 * @return   N/A.
402 *
403 * @note     None.
404 *
405 ******************************************************************************/
406 void XSlcr_UartPsReset(void)
407 {
408         u32 RegVal;
409         /* Unlock the slcr register access lock */
410         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
411         /* Assert the reset */
412         RegVal = Xil_In32(XSLCR_UART_RST_CTRL_ADDR);
413         RegVal = RegVal | XSLCR_UART_RST_CTRL_VAL;
414         Xil_Out32(XSLCR_UART_RST_CTRL_ADDR, RegVal);
415         /* Release the reset */
416         RegVal = Xil_In32(XSLCR_UART_RST_CTRL_ADDR);
417         RegVal = RegVal & ~XSLCR_UART_RST_CTRL_VAL;
418         Xil_Out32(XSLCR_UART_RST_CTRL_ADDR, RegVal);
419 }
420 /*****************************************************************************/
421 /**
422 * This function contains the implementation for CAN software reset from slcr
423 * registers
424 *
425 * @param   N/A.
426 *
427 * @return   N/A.
428 *
429 * @note     None.
430 *
431 ******************************************************************************/
432 void XSlcr_CanPsReset(void)
433 {
434         u32 RegVal;
435         /* Unlock the slcr register access lock */
436         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
437         /* Assert the reset */
438         RegVal = Xil_In32(XSLCR_CAN_RST_CTRL_ADDR);
439         RegVal = RegVal | XSLCR_CAN_RST_CTRL_VAL;
440         Xil_Out32(XSLCR_CAN_RST_CTRL_ADDR, RegVal);
441         /* Release the reset */
442         RegVal = Xil_In32(XSLCR_CAN_RST_CTRL_ADDR);
443         RegVal = RegVal & ~XSLCR_CAN_RST_CTRL_VAL;
444         Xil_Out32(XSLCR_CAN_RST_CTRL_ADDR, RegVal);
445 }
446 /*****************************************************************************/
447 /**
448 * This function contains the implementation for SMC software reset from the slcr
449 *
450 * @param   N/A.
451 *
452 * @return   N/A.
453 *
454 * @note     None.
455 *
456 ******************************************************************************/
457 void XSlcr_SmcPsReset(void)
458 {
459         u32 RegVal;
460         /* Unlock the slcr register access lock */
461         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
462         /* Assert the reset */
463         RegVal = Xil_In32(XSLCR_SMC_RST_CTRL_ADDR);
464         RegVal = RegVal | XSLCR_SMC_RST_CTRL_VAL;
465         Xil_Out32(XSLCR_SMC_RST_CTRL_ADDR, RegVal);
466         /* Release the reset */
467         RegVal = Xil_In32(XSLCR_SMC_RST_CTRL_ADDR);
468         RegVal = RegVal & ~XSLCR_SMC_RST_CTRL_VAL;
469         Xil_Out32(XSLCR_SMC_RST_CTRL_ADDR, RegVal);
470 }
471 /*****************************************************************************/
472 /**
473 * This function contains the implementation for DMA controller software reset
474 * from the slcr
475 *
476 * @param   N/A.
477 *
478 * @return   N/A.
479 *
480 * @note     None.
481 *
482 ******************************************************************************/
483 void XSlcr_DmaPsReset(void)
484 {
485         u32 RegVal;
486         /* Unlock the slcr register access lock */
487         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
488         /* Assert the reset */
489         RegVal = Xil_In32(XSLCR_DMAC_RST_CTRL_ADDR);
490         RegVal = RegVal | XSLCR_DMAC_RST_CTRL_VAL;
491         Xil_Out32(XSLCR_DMAC_RST_CTRL_ADDR, RegVal);
492         /* Release the reset */
493         RegVal = Xil_In32(XSLCR_DMAC_RST_CTRL_ADDR);
494         RegVal = RegVal & ~XSLCR_DMAC_RST_CTRL_VAL;
495         Xil_Out32(XSLCR_DMAC_RST_CTRL_ADDR, RegVal);
496 }
497 /*****************************************************************************/
498 /**
499 * This function contains the implementation for Gpio AMBA software reset from
500 * the slcr
501 *
502 * @param   N/A.
503 *
504 * @return   N/A.
505 *
506 * @note     None.
507 *
508 ******************************************************************************/
509 void XSlcr_GpioPsReset(void)
510 {
511         u32 RegVal;
512         /* Unlock the slcr register access lock */
513         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
514         /* Assert the reset */
515         RegVal = Xil_In32(XSLCR_GPIO_RST_CTRL_ADDR);
516         RegVal = RegVal | XSLCR_GPIO_RST_CTRL_VAL;
517         Xil_Out32(XSLCR_GPIO_RST_CTRL_ADDR, RegVal);
518         /* Release the reset */
519         RegVal = Xil_In32(XSLCR_GPIO_RST_CTRL_ADDR);
520         RegVal = RegVal & ~XSLCR_GPIO_RST_CTRL_VAL;
521         Xil_Out32(XSLCR_GPIO_RST_CTRL_ADDR, RegVal);
522 }