1 /******************************************************************************
3 * (c) Copyright 2010-13 Xilinx, Inc. All rights reserved.
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.
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.
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.
37 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
40 ******************************************************************************/
41 /*****************************************************************************/
44 * @file xqspips_options.c
46 * Contains functions for the configuration of the XQspiPs driver component.
49 * MODIFICATION HISTORY:
51 * Ver Who Date Changes
52 * ----- --- -------- -----------------------------------------------
53 * 1.00 sdm 11/25/10 First release
54 * 2.00a kka 07/25/12 Removed the selection for the following options:
55 * Master mode (XQSPIPS_MASTER_OPTION) and
56 * Flash interface mode (XQSPIPS_FLASH_MODE_OPTION) option
57 * as the QSPI driver supports the Master mode
58 * and Flash Interface mode. The driver doesnot support
59 * Slave mode or the legacy mode.
60 * Added the option for setting the Holdb_dr bit in the
61 * configuration options, XQSPIPS_HOLD_B_DRIVE_OPTION
62 * is the option to be used for setting this bit in the
63 * configuration register.
64 * 2.01a sg 02/03/13 SetDelays and GetDelays API's include DelayNss parameter.
66 * 2.02a hk 26/03/13 Removed XQspi_Reset() in Set_Options() function when
67 * LQSPI_MODE_OPTION is set. Moved Enable() to XQpsiPs_LqspiRead().
70 ******************************************************************************/
72 /***************************** Include Files *********************************/
76 /************************** Constant Definitions *****************************/
78 /**************************** Type Definitions *******************************/
80 /***************** Macros (Inline Functions) Definitions *********************/
82 /************************** Function Prototypes ******************************/
84 /************************** Variable Definitions *****************************/
87 * Create the table of options which are processed to get/set the device
88 * options. These options are table driven to allow easy maintenance and
89 * expansion of the options.
96 static OptionsMap OptionsTable[] = {
97 {XQSPIPS_CLK_ACTIVE_LOW_OPTION, XQSPIPS_CR_CPOL_MASK},
98 {XQSPIPS_CLK_PHASE_1_OPTION, XQSPIPS_CR_CPHA_MASK},
99 {XQSPIPS_FORCE_SSELECT_OPTION, XQSPIPS_CR_SSFORCE_MASK},
100 {XQSPIPS_MANUAL_START_OPTION, XQSPIPS_CR_MANSTRTEN_MASK},
101 {XQSPIPS_HOLD_B_DRIVE_OPTION, XQSPIPS_CR_HOLD_B_MASK},
104 #define XQSPIPS_NUM_OPTIONS (sizeof(OptionsTable) / sizeof(OptionsMap))
106 /*****************************************************************************/
109 * This function sets the options for the QSPI device driver. The options control
110 * how the device behaves relative to the QSPI bus. The device must be idle
111 * rather than busy transferring data before setting these device options.
113 * @param InstancePtr is a pointer to the XQspiPs instance.
114 * @param Options contains the specified options to be set. This is a bit
115 * mask where a 1 means to turn the option on, and a 0 means to
116 * turn the option off. One or more bit values may be contained in
117 * the mask. See the bit definitions named XQSPIPS_*_OPTIONS in
118 * the file xqspips.h.
121 * - XST_SUCCESS if options are successfully set.
122 * - XST_DEVICE_BUSY if the device is currently transferring data.
123 * The transfer must complete or be aborted before setting options.
126 * This function is not thread-safe.
128 ******************************************************************************/
129 int XQspiPs_SetOptions(XQspiPs *InstancePtr, u32 Options)
135 Xil_AssertNonvoid(InstancePtr != NULL);
136 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
139 * Do not allow to modify the Control Register while a transfer is in
140 * progress. Not thread-safe.
142 if (InstancePtr->IsBusy) {
143 return XST_DEVICE_BUSY;
146 QspiOptions = Options & XQSPIPS_LQSPI_MODE_OPTION;
147 Options &= ~XQSPIPS_LQSPI_MODE_OPTION;
149 ConfigReg = XQspiPs_ReadReg(InstancePtr->Config.BaseAddress,
153 * Loop through the options table, turning the option on or off
154 * depending on whether the bit is set in the incoming options flag.
156 for (Index = 0; Index < XQSPIPS_NUM_OPTIONS; Index++) {
157 if (Options & OptionsTable[Index].Option) {
159 ConfigReg |= OptionsTable[Index].Mask;
162 ConfigReg &= ~(OptionsTable[Index].Mask);
167 * Now write the control register. Leave it to the upper layers
168 * to restart the device.
170 XQspiPs_WriteReg(InstancePtr->Config.BaseAddress, XQSPIPS_CR_OFFSET,
174 * Check for the LQSPI configuration options.
176 ConfigReg = XQspiPs_ReadReg(InstancePtr->Config.BaseAddress,
177 XQSPIPS_LQSPI_CR_OFFSET);
180 if (QspiOptions & XQSPIPS_LQSPI_MODE_OPTION) {
181 XQspiPs_WriteReg(InstancePtr->Config.BaseAddress,
182 XQSPIPS_LQSPI_CR_OFFSET,
183 XQSPIPS_LQSPI_CR_RST_STATE);
184 XQspiPs_SetSlaveSelect(InstancePtr);
186 ConfigReg &= ~XQSPIPS_LQSPI_CR_LINEAR_MASK;
187 XQspiPs_WriteReg(InstancePtr->Config.BaseAddress,
188 XQSPIPS_LQSPI_CR_OFFSET, ConfigReg);
194 /*****************************************************************************/
197 * This function gets the options for the QSPI device. The options control how
198 * the device behaves relative to the QSPI bus.
200 * @param InstancePtr is a pointer to the XQspiPs instance.
204 * Options contains the specified options currently set. This is a bit value
205 * where a 1 means the option is on, and a 0 means the option is off.
206 * See the bit definitions named XQSPIPS_*_OPTIONS in file xqspips.h.
210 ******************************************************************************/
211 u32 XQspiPs_GetOptions(XQspiPs *InstancePtr)
217 Xil_AssertNonvoid(InstancePtr != NULL);
218 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
221 * Get the current options from QSPI configuration register.
223 ConfigReg = XQspiPs_ReadReg(InstancePtr->Config.BaseAddress,
227 * Loop through the options table to grab options
229 for (Index = 0; Index < XQSPIPS_NUM_OPTIONS; Index++) {
230 if (ConfigReg & OptionsTable[Index].Mask) {
231 OptionsFlag |= OptionsTable[Index].Option;
236 * Check for the LQSPI configuration options.
238 ConfigReg = XQspiPs_ReadReg(InstancePtr->Config.BaseAddress,
239 XQSPIPS_LQSPI_CR_OFFSET);
241 if ((ConfigReg & XQSPIPS_LQSPI_CR_LINEAR_MASK) != 0) {
242 OptionsFlag |= XQSPIPS_LQSPI_MODE_OPTION;
248 /*****************************************************************************/
251 * This function sets the clock prescaler for an QSPI device. The device
252 * must be idle rather than busy transferring data before setting these device
255 * @param InstancePtr is a pointer to the XQspiPs instance.
256 * @param Prescaler is the value that determine how much the clock should
257 * be divided by. Use the XQSPIPS_CLK_PRESCALE_* constants defined
258 * in xqspips.h for this setting.
261 * - XST_SUCCESS if options are successfully set.
262 * - XST_DEVICE_BUSY if the device is currently transferring data.
263 * The transfer must complete or be aborted before setting options.
266 * This function is not thread-safe.
268 ******************************************************************************/
269 int XQspiPs_SetClkPrescaler(XQspiPs *InstancePtr, u8 Prescaler)
273 Xil_AssertNonvoid(InstancePtr != NULL);
274 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
275 Xil_AssertNonvoid(Prescaler <= XQSPIPS_CR_PRESC_MAXIMUM);
278 * Do not allow the slave select to change while a transfer is in
279 * progress. Not thread-safe.
281 if (InstancePtr->IsBusy) {
282 return XST_DEVICE_BUSY;
286 * Read the configuration register, mask out the interesting bits, and set
287 * them with the shifted value passed into the function. Write the
288 * results back to the configuration register.
290 ConfigReg = XQspiPs_ReadReg(InstancePtr->Config.BaseAddress,
293 ConfigReg &= ~XQSPIPS_CR_PRESC_MASK;
294 ConfigReg |= (u32) (Prescaler & XQSPIPS_CR_PRESC_MAXIMUM) <<
295 XQSPIPS_CR_PRESC_SHIFT;
297 XQspiPs_WriteReg(InstancePtr->Config.BaseAddress,
304 /*****************************************************************************/
307 * This function gets the clock prescaler of an QSPI device.
309 * @param InstancePtr is a pointer to the XQspiPs instance.
311 * @return The prescaler value.
316 ******************************************************************************/
317 u8 XQspiPs_GetClkPrescaler(XQspiPs *InstancePtr)
321 Xil_AssertNonvoid(InstancePtr != NULL);
322 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
324 ConfigReg = XQspiPs_ReadReg(InstancePtr->Config.BaseAddress,
327 ConfigReg &= XQSPIPS_CR_PRESC_MASK;
329 return (u8)(ConfigReg >> XQSPIPS_CR_PRESC_SHIFT);
332 /*****************************************************************************/
335 * This function sets the delay register for the QSPI device driver.
336 * The delay register controls the Delay Between Transfers, Delay After
337 * Transfers, and the Delay Initially. The default value is 0x0. The range of
338 * each delay value is 0-255.
340 * @param InstancePtr is a pointer to the XQspiPs instance.
341 * @param DelayNss is the delay to de-assert slave select between
342 * two word transfers.
343 * @param DelayBtwn is the delay between one Slave Select being
344 * de-activated and the activation of another slave. The delay is
345 * the number of master clock periods given by DelayBtwn + 2.
346 * @param DelayAfter define the delay between the last bit of the current
347 * byte transfer and the first bit of the next byte transfer.
348 * The delay in number of master clock periods is given as:
349 * CHPA=0:DelayInit+DelayAfter+3
350 * CHPA=1:DelayAfter+1
351 * @param DelayInit is the delay between asserting the slave select signal
352 * and the first bit transfer. The delay int number of master clock
353 * periods is DelayInit+1.
356 * - XST_SUCCESS if delays are successfully set.
357 * - XST_DEVICE_BUSY if the device is currently transferring data.
358 * The transfer must complete or be aborted before setting options.
362 ******************************************************************************/
363 int XQspiPs_SetDelays(XQspiPs *InstancePtr, u8 DelayNss, u8 DelayBtwn,
364 u8 DelayAfter, u8 DelayInit)
368 Xil_AssertNonvoid(InstancePtr != NULL);
369 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
372 * Do not allow the delays to change while a transfer is in
373 * progress. Not thread-safe.
375 if (InstancePtr->IsBusy) {
376 return XST_DEVICE_BUSY;
379 /* Shift, Mask and OR the values to build the register settings */
380 DelayRegister = (u32) DelayNss << XQSPIPS_DR_NSS_SHIFT;
381 DelayRegister |= (u32) DelayBtwn << XQSPIPS_DR_BTWN_SHIFT;
382 DelayRegister |= (u32) DelayAfter << XQSPIPS_DR_AFTER_SHIFT;
383 DelayRegister |= (u32) DelayInit;
385 XQspiPs_WriteReg(InstancePtr->Config.BaseAddress,
386 XQSPIPS_DR_OFFSET, DelayRegister);
391 /*****************************************************************************/
394 * This function gets the delay settings for an QSPI device.
395 * The delay register controls the Delay Between Transfers, Delay After
396 * Transfers, and the Delay Initially. The default value is 0x0.
398 * @param InstancePtr is a pointer to the XQspiPs instance.
399 * @param DelayNss is a pointer to the Delay to de-assert slave select
400 * between two word transfers.
401 * @param DelayBtwn is a pointer to the Delay Between transfers value.
402 * This is a return parameter.
403 * @param DelayAfter is a pointer to the Delay After transfer value.
404 * This is a return parameter.
405 * @param DelayInit is a pointer to the Delay Initially value. This is
406 * a return parameter.
412 ******************************************************************************/
413 void XQspiPs_GetDelays(XQspiPs *InstancePtr, u8 *DelayNss, u8 *DelayBtwn,
414 u8 *DelayAfter, u8 *DelayInit)
418 Xil_AssertVoid(InstancePtr != NULL);
419 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
421 DelayRegister = XQspiPs_ReadReg(InstancePtr->Config.BaseAddress,
424 *DelayInit = (u8)(DelayRegister & XQSPIPS_DR_INIT_MASK);
426 *DelayAfter = (u8)((DelayRegister & XQSPIPS_DR_AFTER_MASK) >>
427 XQSPIPS_DR_AFTER_SHIFT);
429 *DelayBtwn = (u8)((DelayRegister & XQSPIPS_DR_BTWN_MASK) >>
430 XQSPIPS_DR_BTWN_SHIFT);
432 *DelayNss = (u8)((DelayRegister & XQSPIPS_DR_NSS_MASK) >>
433 XQSPIPS_DR_NSS_SHIFT);