]> 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
Add back Zynq demo - this time using SDK V14.2.
[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 * (c) Copyright 2013  Xilinx, Inc. All rights reserved.
4 *
5 * This file contains confidential and proprietary information of Xilinx, Inc.
6 * and is protected under U.S. and international copyright and other
7 * intellectual property laws.
8 *
9 * DISCLAIMER
10 * This disclaimer is not a license and does not grant any rights to the
11 * materials distributed herewith. Except as otherwise provided in a valid
12 * license issued to you by Xilinx, and to the maximum extent permitted by
13 * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
14 * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
15 * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
16 * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
17 * and (2) Xilinx shall not be liable (whether in contract or tort, including
18 * negligence, or under any other theory of liability) for any loss or damage
19 * of any kind or nature related to, arising under or in connection with these
20 * materials, including for any direct, or any indirect, special, incidental,
21 * or consequential loss or damage (including loss of data, profits, goodwill,
22 * or any type of loss or damage suffered as a result of any action brought by
23 * a third party) even if such damage or loss was reasonably foreseeable or
24 * Xilinx had been advised of the possibility of the same.
25 *
26 * CRITICAL APPLICATIONS
27 * Xilinx products are not designed or intended to be fail-safe, or for use in
28 * any application requiring fail-safe performance, such as life-support or
29 * safety devices or systems, Class III medical devices, nuclear facilities,
30 * applications related to the deployment of airbags, or any other applications
31 * that could lead to death, personal injury, or severe property or
32 * environmental damage (individually and collectively, "Critical
33 * Applications"). Customer assumes the sole risk and liability of any use of
34 * Xilinx products in Critical Applications, subject only to applicable laws
35 * and regulations governing limitations on product liability.
36 *
37 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
38 * AT ALL TIMES.
39 *
40 ******************************************************************************/
41 /*****************************************************************************/
42 /**
43 *
44 * @file xil_misc_reset.c
45 *
46 * This file contains the implementation of the reset sequence for various
47 * zynq ps devices like DDR,OCM,Slcr,Ethernet,Usb.. controllers. The reset
48 * sequence provided to the interfaces is based on the provision in  
49 * slcr reset functional blcok.
50 *
51 * <pre>
52 * MODIFICATION HISTORY:
53 *
54 * Ver   Who    Date   Changes
55 * ----- ---- -------- -------------------------------------------------------
56 * 1.00b kpc   03/07/13 First release 
57 * </pre>
58 *
59 ******************************************************************************/
60
61
62 /***************************** Include Files *********************************/
63 #include "xil_misc_psreset_api.h"
64
65 /************************** Constant Definitions *****************************/
66
67
68 /**************************** Type Definitions *******************************/
69
70
71 /***************** Macros (Inline Functions) Definitions *********************/
72
73
74 /************************** Function Prototypes ******************************/
75
76
77 /*****************************************************************************/
78 /**
79 * This function contains the implementation for ddr reset.
80
81 * @param   N/A.
82 *
83 * @return   N/A.
84 *
85 * @note     None.
86 *
87 ******************************************************************************/
88 void XDdr_ResetHw()
89 {
90         u32 RegVal;
91         
92         /* Unlock the slcr register access lock */
93          Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE); 
94         /* Assert and deassert the ddr softreset bit */ 
95      RegVal =   Xil_In32(XDDRC_CTRL_BASEADDR);
96          RegVal &= ~XDDRPS_CTRL_RESET_MASK;
97          Xil_Out32(XDDRC_CTRL_BASEADDR,RegVal); 
98          RegVal |= XDDRPS_CTRL_RESET_MASK;       
99          Xil_Out32(XDDRC_CTRL_BASEADDR,RegVal);          
100
101 }
102
103 /*****************************************************************************/
104 /**
105 * This function contains the implementation for remapping the ocm memory region
106
107 * @param   N/A.
108 *
109 * @return   N/A.
110 *
111 * @note     None.
112 *
113 ******************************************************************************/
114 void XOcm_Remap()
115 {
116         u32 RegVal;
117         
118         /* Unlock the slcr register access lock */
119         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
120         /* Map the ocm region to postbootrom state */   
121         RegVal = Xil_In32(XSLCR_OCM_CFG_ADDR);
122         RegVal = (RegVal & ~XSLCR_OCM_CFG_HIADDR_MASK) | XSLCR_OCM_CFG_RESETVAL;
123         Xil_Out32(XSLCR_OCM_CFG_ADDR, RegVal);
124 }
125
126 /*****************************************************************************/
127 /**
128 * This function contains the implementation for SMC reset sequence
129
130 * @param   BaseAddress of the interface
131 *
132 * @return   N/A.
133 *
134 * @note     None.
135 *
136 ******************************************************************************/
137 void XSmc_ResetHw(u32 BaseAddress)
138 {
139         u32 RegVal;
140         
141         /* Clear the interuupts */
142         RegVal = Xil_In32(BaseAddress + XSMC_MEMC_CLR_CONFIG_OFFSET);
143         RegVal = RegVal | XSMC_MEMC_CLR_CONFIG_MASK; 
144         Xil_Out32(BaseAddress + XSMC_MEMC_CLR_CONFIG_OFFSET, RegVal);
145         /* Clear the idle counter registers */  
146         Xil_Out32(BaseAddress + XSMC_REFRESH_PERIOD_0_OFFSET, 0x0);     
147         Xil_Out32(BaseAddress + XSMC_REFRESH_PERIOD_1_OFFSET, 0x0);     
148         /* Update the ecc registers with reset values */        
149         Xil_Out32(BaseAddress + XSMC_ECC_MEMCFG1_OFFSET, 
150                                                         XSMC_ECC_MEMCFG1_RESET_VAL);    
151         Xil_Out32(BaseAddress + XSMC_ECC_MEMCMD1_OFFSET,
152                                                         XSMC_ECC_MEMCMD1_RESET_VAL);    
153         Xil_Out32(BaseAddress + XSMC_ECC_MEMCMD2_OFFSET, 
154                                                         XSMC_ECC_MEMCMD2_RESET_VAL);    
155
156 }
157
158 /*****************************************************************************/
159 /**
160 * This function contains the implementation for updating the slcr mio registers 
161 * with reset values
162 * @param   N/A.
163 *
164 * @return   N/A.
165 *
166 * @note     None.
167 *
168 ******************************************************************************/
169 void XSlcr_MioWriteResetValues()
170 {
171         u32 i;
172         
173         /* Unlock the slcr register access lock */
174         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
175         /* Update all the MIO registers with reset values */    
176     for (i=0; i<=1;i++);
177         {
178                 Xil_Out32((XSLCR_MIO_PIN_00_ADDR + (i * 4)), 
179                                                                 XSLCR_MIO_PIN_00_RESET_VAL);    
180         }
181         for (; i<=8;i++);
182         {
183                 Xil_Out32((XSLCR_MIO_PIN_00_ADDR + (i * 4)),
184                                                                 XSLCR_MIO_PIN_02_RESET_VAL);    
185         }
186         for (; i<=53 ;i++);
187         {
188                 Xil_Out32((XSLCR_MIO_PIN_00_ADDR + (i * 4)), 
189                                                                 XSLCR_MIO_PIN_00_RESET_VAL);    
190         }       
191         
192
193 }
194
195 /*****************************************************************************/
196 /**
197 * This function contains the implementation for updating the slcr pll registers 
198 * with reset values
199 * @param   N/A.
200 *
201 * @return   N/A.
202 *
203 * @note     None.
204 *
205 ******************************************************************************/
206 void XSlcr_PllWriteResetValues()
207 {
208
209         /* Unlock the slcr register access lock */
210         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
211         
212         /* update the pll control registers with reset values */        
213         Xil_Out32(XSLCR_IO_PLL_CTRL_ADDR, XSLCR_IO_PLL_CTRL_RESET_VAL);
214         Xil_Out32(XSLCR_ARM_PLL_CTRL_ADDR, XSLCR_ARM_PLL_CTRL_RESET_VAL);
215         Xil_Out32(XSLCR_DDR_PLL_CTRL_ADDR, XSLCR_DDR_PLL_CTRL_RESET_VAL);       
216         /* update the pll config registers with reset values */         
217         Xil_Out32(XSLCR_IO_PLL_CFG_ADDR, XSLCR_IO_PLL_CFG_RESET_VAL);
218         Xil_Out32(XSLCR_ARM_PLL_CFG_ADDR, XSLCR_ARM_PLL_CFG_RESET_VAL);
219         Xil_Out32(XSLCR_DDR_PLL_CFG_ADDR, XSLCR_DDR_PLL_CFG_RESET_VAL); 
220         /* update the clock control registers with reset values */                      
221         Xil_Out32(XSLCR_ARM_CLK_CTRL_ADDR, XSLCR_ARM_CLK_CTRL_RESET_VAL);       
222         Xil_Out32(XSLCR_DDR_CLK_CTRL_ADDR, XSLCR_DDR_CLK_CTRL_RESET_VAL);               
223 }
224
225 /*****************************************************************************/
226 /**
227 * This function contains the implementation for disabling the level shifters
228
229 * @param   N/A.
230 *
231 * @return   N/A.
232 *
233 * @note     None.
234 *
235 ******************************************************************************/
236 void XSlcr_DisableLevelShifters()
237 {
238         u32 RegVal;
239         /* Unlock the slcr register access lock */      
240         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
241         /* Disable the level shifters */
242         RegVal = Xil_In32(XSLCR_LVL_SHFTR_EN_ADDR);
243         RegVal = RegVal & ~XSLCR_LVL_SHFTR_EN_MASK; 
244         Xil_Out32(XSLCR_LVL_SHFTR_EN_ADDR, RegVal);
245         
246 }
247 /*****************************************************************************/
248 /**
249 * This function contains the implementation for OCM software reset from the 
250 * slcr 
251
252 * @param   N/A.
253 *
254 * @return   N/A.
255 *
256 * @note     None.
257 *
258 ******************************************************************************/
259 void XSlcr_OcmReset(void)
260 {
261         u32 RegVal;
262         /* Unlock the slcr register access lock */      
263         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
264         /* Assert the reset */
265         RegVal = Xil_In32(XSLCR_OCM_RST_CTRL_ADDR);
266         RegVal = RegVal | XSLCR_OCM_RST_CTRL_VAL;
267         Xil_Out32(XSLCR_OCM_RST_CTRL_ADDR, RegVal);
268         /* Release the reset */ 
269         RegVal = Xil_In32(XSLCR_OCM_RST_CTRL_ADDR);
270         RegVal = RegVal & ~XSLCR_OCM_RST_CTRL_VAL;
271         Xil_Out32(XSLCR_OCM_RST_CTRL_ADDR, RegVal);     
272 }
273
274 /*****************************************************************************/
275 /**
276 * This function contains the implementation for Ethernet software reset from 
277 * the slcr 
278 * @param   N/A.
279 *
280 * @return   N/A.
281 *
282 * @note     None.
283 *
284 ******************************************************************************/
285 void XSlcr_EmacPsReset(void)
286 {
287         u32 RegVal;
288         /* Unlock the slcr register access lock */      
289         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
290         /* Assert the reset */
291         RegVal = Xil_In32(XSLCR_GEM_RST_CTRL_ADDR);
292         RegVal = RegVal | XSLCR_GEM_RST_CTRL_VAL;
293         Xil_Out32(XSLCR_GEM_RST_CTRL_ADDR, RegVal);
294         /* Release the reset */ 
295         RegVal = Xil_In32(XSLCR_GEM_RST_CTRL_ADDR);
296         RegVal = RegVal & ~XSLCR_GEM_RST_CTRL_VAL;
297         Xil_Out32(XSLCR_GEM_RST_CTRL_ADDR, RegVal);             
298 }
299
300 /*****************************************************************************/
301 /**
302 * This function contains the implementation for USB software reset from the 
303 * slcr 
304
305 * @param   N/A.
306 *
307 * @return   N/A.
308 *
309 * @note     None.
310 *
311 ******************************************************************************/
312 void XSlcr_UsbPsReset(void)
313 {
314         u32 RegVal;
315         /* Unlock the slcr register access lock */      
316         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
317         /* Assert the reset */
318         RegVal = Xil_In32(XSLCR_USB_RST_CTRL_ADDR);
319         RegVal = RegVal | XSLCR_USB_RST_CTRL_VAL;
320         Xil_Out32(XSLCR_USB_RST_CTRL_ADDR, RegVal);
321         /* Release the reset */ 
322         RegVal = Xil_In32(XSLCR_USB_RST_CTRL_ADDR);
323         RegVal = RegVal & ~XSLCR_USB_RST_CTRL_VAL;
324         Xil_Out32(XSLCR_USB_RST_CTRL_ADDR, RegVal);     
325 }
326 /*****************************************************************************/
327 /**
328 * This function contains the implementation for QSPI software reset from the
329 * slcr 
330
331 * @param   N/A.
332 *
333 * @return   N/A.
334 *
335 * @note     None.
336 *
337 ******************************************************************************/
338 void XSlcr_QspiPsReset(void)
339 {
340         u32 RegVal;
341         /* Unlock the slcr register access lock */      
342         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
343         /* Assert the reset */
344         RegVal = Xil_In32(XSLCR_LQSPI_RST_CTRL_ADDR);
345         RegVal = RegVal | XSLCR_QSPI_RST_CTRL_VAL;
346         Xil_Out32(XSLCR_LQSPI_RST_CTRL_ADDR, RegVal);
347         /* Release the reset */ 
348         RegVal = Xil_In32(XSLCR_LQSPI_RST_CTRL_ADDR);
349         RegVal = RegVal & ~XSLCR_QSPI_RST_CTRL_VAL;
350         Xil_Out32(XSLCR_LQSPI_RST_CTRL_ADDR, RegVal);
351 }
352 /*****************************************************************************/
353 /**
354 * This function contains the implementation for SPI software reset from the 
355 * slcr 
356
357 * @param   N/A.
358 *
359 * @return   N/A.
360 *
361 * @note     None.
362 *
363 ******************************************************************************/
364 void XSlcr_SpiPsReset(void)
365 {
366         u32 RegVal;
367         /* Unlock the slcr register access lock */      
368         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
369         /* Assert the reset */
370         RegVal = Xil_In32(XSLCR_SPI_RST_CTRL_ADDR);
371         RegVal = RegVal | XSLCR_SPI_RST_CTRL_VAL;
372         Xil_Out32(XSLCR_SPI_RST_CTRL_ADDR, RegVal);
373         /* Release the reset */ 
374         RegVal = Xil_In32(XSLCR_SPI_RST_CTRL_ADDR);
375         RegVal = RegVal & ~XSLCR_SPI_RST_CTRL_VAL;
376         Xil_Out32(XSLCR_SPI_RST_CTRL_ADDR, RegVal);     
377 }
378 /*****************************************************************************/
379 /**
380 * This function contains the implementation for i2c software reset from the slcr 
381
382 * @param   N/A.
383 *
384 * @return   N/A.
385 *
386 * @note     None.
387 *
388 ******************************************************************************/
389 void XSlcr_I2cPsReset(void)
390 {
391         u32 RegVal;
392         /* Unlock the slcr register access lock */      
393         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
394         /* Assert the reset */
395         RegVal = Xil_In32(XSLCR_I2C_RST_CTRL_ADDR);
396         RegVal = RegVal | XSLCR_I2C_RST_CTRL_VAL;
397         Xil_Out32(XSLCR_I2C_RST_CTRL_ADDR, RegVal);
398         /* Release the reset */ 
399         RegVal = Xil_In32(XSLCR_I2C_RST_CTRL_ADDR);
400         RegVal = RegVal & ~XSLCR_I2C_RST_CTRL_VAL;
401         Xil_Out32(XSLCR_I2C_RST_CTRL_ADDR, RegVal);             
402 }
403 /*****************************************************************************/
404 /**
405 * This function contains the implementation for UART software reset from the
406 * slcr 
407
408 * @param   N/A.
409 *
410 * @return   N/A.
411 *
412 * @note     None.
413 *
414 ******************************************************************************/
415 void XSlcr_UartPsReset(void)
416 {
417         u32 RegVal;
418         /* Unlock the slcr register access lock */      
419         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
420         /* Assert the reset */
421         RegVal = Xil_In32(XSLCR_UART_RST_CTRL_ADDR);
422         RegVal = RegVal | XSLCR_UART_RST_CTRL_VAL;
423         Xil_Out32(XSLCR_UART_RST_CTRL_ADDR, RegVal);
424         /* Release the reset */ 
425         RegVal = Xil_In32(XSLCR_UART_RST_CTRL_ADDR);
426         RegVal = RegVal & ~XSLCR_UART_RST_CTRL_VAL;
427         Xil_Out32(XSLCR_UART_RST_CTRL_ADDR, RegVal);            
428 }
429 /*****************************************************************************/
430 /**
431 * This function contains the implementation for CAN software reset from slcr 
432 * registers
433
434 * @param   N/A.
435 *
436 * @return   N/A.
437 *
438 * @note     None.
439 *
440 ******************************************************************************/
441 void XSlcr_CanPsReset(void)
442 {
443         u32 RegVal;
444         /* Unlock the slcr register access lock */      
445         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
446         /* Assert the reset */
447         RegVal = Xil_In32(XSLCR_CAN_RST_CTRL_ADDR);
448         RegVal = RegVal | XSLCR_CAN_RST_CTRL_VAL;
449         Xil_Out32(XSLCR_CAN_RST_CTRL_ADDR, RegVal);
450         /* Release the reset */ 
451         RegVal = Xil_In32(XSLCR_CAN_RST_CTRL_ADDR);
452         RegVal = RegVal & ~XSLCR_CAN_RST_CTRL_VAL;
453         Xil_Out32(XSLCR_CAN_RST_CTRL_ADDR, RegVal);             
454 }
455 /*****************************************************************************/
456 /**
457 * This function contains the implementation for SMC software reset from the slcr
458
459 * @param   N/A.
460 *
461 * @return   N/A.
462 *
463 * @note     None.
464 *
465 ******************************************************************************/
466 void XSlcr_SmcPsReset(void)
467 {
468         u32 RegVal;
469         /* Unlock the slcr register access lock */      
470         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
471         /* Assert the reset */
472         RegVal = Xil_In32(XSLCR_SMC_RST_CTRL_ADDR);
473         RegVal = RegVal | XSLCR_SMC_RST_CTRL_VAL;
474         Xil_Out32(XSLCR_SMC_RST_CTRL_ADDR, RegVal);
475         /* Release the reset */ 
476         RegVal = Xil_In32(XSLCR_SMC_RST_CTRL_ADDR);
477         RegVal = RegVal & ~XSLCR_SMC_RST_CTRL_VAL;
478         Xil_Out32(XSLCR_SMC_RST_CTRL_ADDR, RegVal);     
479 }
480 /*****************************************************************************/
481 /**
482 * This function contains the implementation for DMA controller software reset
483 * from the slcr 
484
485 * @param   N/A.
486 *
487 * @return   N/A.
488 *
489 * @note     None.
490 *
491 ******************************************************************************/
492 void XSlcr_DmaPsReset(void)
493 {
494         u32 RegVal;
495         /* Unlock the slcr register access lock */      
496         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
497         /* Assert the reset */
498         RegVal = Xil_In32(XSLCR_DMAC_RST_CTRL_ADDR);
499         RegVal = RegVal | XSLCR_DMAC_RST_CTRL_VAL;
500         Xil_Out32(XSLCR_DMAC_RST_CTRL_ADDR, RegVal);
501         /* Release the reset */ 
502         RegVal = Xil_In32(XSLCR_DMAC_RST_CTRL_ADDR);
503         RegVal = RegVal & ~XSLCR_DMAC_RST_CTRL_VAL;
504         Xil_Out32(XSLCR_DMAC_RST_CTRL_ADDR, RegVal);
505 }
506 /*****************************************************************************/
507 /**
508 * This function contains the implementation for Gpio AMBA software reset from 
509 * the slcr
510
511 * @param   N/A.
512 *
513 * @return   N/A.
514 *
515 * @note     None.
516 *
517 ******************************************************************************/
518 void XSlcr_GpioPsReset(void)
519 {
520         u32 RegVal;
521         /* Unlock the slcr register access lock */      
522         Xil_Out32(XSLCR_UNLOCK_ADDR, XSLCR_UNLOCK_CODE);
523         /* Assert the reset */
524         RegVal = Xil_In32(XSLCR_GPIO_RST_CTRL_ADDR);
525         RegVal = RegVal | XSLCR_GPIO_RST_CTRL_VAL;
526         Xil_Out32(XSLCR_GPIO_RST_CTRL_ADDR, RegVal);
527         /* Release the reset */ 
528         RegVal = Xil_In32(XSLCR_GPIO_RST_CTRL_ADDR);
529         RegVal = RegVal & ~XSLCR_GPIO_RST_CTRL_VAL;
530         Xil_Out32(XSLCR_GPIO_RST_CTRL_ADDR, RegVal);
531 }