1 /******************************************************************************
3 * Copyright (C) 2013 - 2014 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /*****************************************************************************/
37 * Contains low level functions, primarily reset related.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- --- -------- -----------------------------------------------
44 * 2.03a hk 09/17/13 First release
48 ******************************************************************************/
50 /***************************** Include Files *********************************/
52 #include "xqspips_hw.h"
55 /************************** Constant Definitions *****************************/
57 /** @name Pre-scaler value for divided by 4
59 * Pre-scaler value for divided by 4
63 #define XQSPIPS_CR_PRESC_DIV_BY_4 0x01
66 /**************************** Type Definitions *******************************/
68 /***************** Macros (Inline Functions) Definitions *********************/
70 /************************** Function Prototypes ******************************/
72 /************************** Variable Definitions *****************************/
75 /*****************************************************************************/
78 * Resets QSPI by disabling the device and bringing it to reset state through
87 ******************************************************************************/
88 void XQspiPs_ResetHw(u32 BaseAddress)
95 XQspiPs_WriteReg(BaseAddress, XQSPIPS_IDR_OFFSET,
96 XQSPIPS_IXR_DISABLE_ALL);
101 XQspiPs_WriteReg(BaseAddress, XQSPIPS_ER_OFFSET,
105 * De-assert slave select lines.
107 ConfigReg = XQspiPs_ReadReg(BaseAddress, XQSPIPS_CR_OFFSET);
108 ConfigReg |= (XQSPIPS_CR_SSCTRL_MASK | XQSPIPS_CR_SSFORCE_MASK);
109 XQspiPs_WriteReg(BaseAddress, XQSPIPS_CR_OFFSET, ConfigReg);
112 * Write default value to RX and TX threshold registers
113 * RX threshold should be set to 1 here because the corresponding
114 * status bit is used next to clear the RXFIFO
116 XQspiPs_WriteReg(BaseAddress, XQSPIPS_TXWR_OFFSET,
117 (XQSPIPS_TXWR_RESET_VALUE & XQSPIPS_TXWR_MASK));
118 XQspiPs_WriteReg(BaseAddress, XQSPIPS_RXWR_OFFSET,
119 (XQSPIPS_RXWR_RESET_VALUE & XQSPIPS_RXWR_MASK));
124 while ((XQspiPs_ReadReg(BaseAddress,XQSPIPS_SR_OFFSET) &
125 XQSPIPS_IXR_RXNEMPTY_MASK) != 0) {
126 XQspiPs_ReadReg(BaseAddress, XQSPIPS_RXD_OFFSET);
130 * Clear status register by reading register and
131 * writing 1 to clear the write to clear bits
133 XQspiPs_ReadReg(BaseAddress, XQSPIPS_SR_OFFSET);
134 XQspiPs_WriteReg(BaseAddress, XQSPIPS_SR_OFFSET,
135 XQSPIPS_IXR_WR_TO_CLR_MASK);
138 * Write default value to configuration register
140 XQspiPs_WriteReg(BaseAddress, XQSPIPS_CR_OFFSET,
141 XQSPIPS_CR_RESET_STATE);
145 * De-select linear mode
147 XQspiPs_WriteReg(BaseAddress, XQSPIPS_LQSPI_CR_OFFSET,
152 /*****************************************************************************/
155 * Initializes QSPI to Linear mode with default QSPI boot settings.
163 ******************************************************************************/
164 void XQspiPs_LinearInit(u32 BaseAddress)
170 * Baud rate divisor for dividing by 4. Value of CR bits [5:3]
171 * should be set to 0x001; hence shift the value and use the mask.
173 BaudRateDiv = ( (XQSPIPS_CR_PRESC_DIV_BY_4) <<
174 XQSPIPS_CR_PRESC_SHIFT) & XQSPIPS_CR_PRESC_MASK;
176 * Write configuration register with default values, slave selected &
177 * pre-scaler value for divide by 4
179 XQspiPs_WriteReg(BaseAddress, XQSPIPS_CR_OFFSET,
180 ((XQSPIPS_CR_RESET_STATE |
181 XQSPIPS_CR_HOLD_B_MASK | BaudRateDiv) &
182 (~XQSPIPS_CR_SSCTRL_MASK) ));
185 * Write linear configuration register with default value -
186 * enable linear mode and use fast read.
189 if(XPAR_PS7_QSPI_0_QSPI_MODE == XQSPIPS_CONNECTION_MODE_SINGLE){
191 LinearCfg = XQSPIPS_LQSPI_CR_RST_STATE;
193 }else if(XPAR_PS7_QSPI_0_QSPI_MODE ==
194 XQSPIPS_CONNECTION_MODE_STACKED){
196 LinearCfg = XQSPIPS_LQSPI_CR_RST_STATE |
197 XQSPIPS_LQSPI_CR_TWO_MEM_MASK;
199 }else if(XPAR_PS7_QSPI_0_QSPI_MODE ==
200 XQSPIPS_CONNECTION_MODE_PARALLEL){
202 LinearCfg = XQSPIPS_LQSPI_CR_RST_STATE |
203 XQSPIPS_LQSPI_CR_TWO_MEM_MASK |
204 XQSPIPS_LQSPI_CR_SEP_BUS_MASK;
208 XQspiPs_WriteReg(BaseAddress, XQSPIPS_LQSPI_CR_OFFSET,
214 XQspiPs_WriteReg(BaseAddress, XQSPIPS_ER_OFFSET,
215 XQSPIPS_ER_ENABLE_MASK);