RTEMS 6.1-rc1
xqspipsu.h
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (C) 2014 - 2022 Xilinx, Inc. All rights reserved.
3* SPDX-License-Identifier: MIT
4******************************************************************************/
5
6
7/*****************************************************************************/
175#ifndef XQSPIPSU_H_
176#define XQSPIPSU_H_
178#ifdef __cplusplus
179extern "C" {
180#endif
181
182/***************************** Include Files *********************************/
183
184#include "xstatus.h"
185#include "xqspipsu_hw.h"
186#include "xil_cache.h"
187#include "xil_mem.h"
188#if defined (XCLOCKING)
189#include "xil_clocking.h"
190#endif
191
192/**************************** Type Definitions *******************************/
211typedef void (*XQspiPsu_StatusHandler) (const void *CallBackRef, u32 StatusEvent,
212 u32 ByteCount);
213
217typedef struct {
222 u32 Flags;
230
234typedef struct {
236 UINTPTR BaseAddress;
241#if defined (XCLOCKING)
242 u32 RefClk;
243#endif
245
251typedef struct {
262#ifdef __rtems__
263 volatile
264#endif
265 u32 IsBusy;
269 s32 NumMsg;
270 s32 MsgCnt;
275 void *StatusRef;
276} XQspiPsu;
277
278/***************** Macros (Inline Functions) Definitions *********************/
279
284#define BYTES256_PER_PAGE 256U
285#define BYTES512_PER_PAGE 512U
286#define BYTES1024_PER_PAGE 1024U
287#define PAGES16_PER_SECTOR 16U
288#define PAGES128_PER_SECTOR 128U
289#define PAGES256_PER_SECTOR 256U
290#define PAGES512_PER_SECTOR 512U
291#define PAGES1024_PER_SECTOR 1024U
292#define NUM_OF_SECTORS2 2U
293#define NUM_OF_SECTORS4 4U
294#define NUM_OF_SECTORS8 8U
295#define NUM_OF_SECTORS16 16U
296#define NUM_OF_SECTORS32 32U
297#define NUM_OF_SECTORS64 64U
298#define NUM_OF_SECTORS128 128U
299#define NUM_OF_SECTORS256 256U
300#define NUM_OF_SECTORS512 512U
301#define NUM_OF_SECTORS1024 1024U
302#define NUM_OF_SECTORS2048 2048U
303#define NUM_OF_SECTORS4096 4096U
304#define NUM_OF_SECTORS8192 8192U
305#define SECTOR_SIZE_64K 0X10000U
306#define SECTOR_SIZE_128K 0X20000U
307#define SECTOR_SIZE_256K 0X40000U
308#define SECTOR_SIZE_512K 0X80000U
311#define XQSPIPSU_READMODE_DMA 0x0U
312#define XQSPIPSU_READMODE_IO 0x1U
314#define XQSPIPSU_SELECT_FLASH_CS_LOWER 0x1U
315#define XQSPIPSU_SELECT_FLASH_CS_UPPER 0x2U
316#define XQSPIPSU_SELECT_FLASH_CS_BOTH 0x3U
318#define XQSPIPSU_SELECT_FLASH_BUS_LOWER 0x1U
319#define XQSPIPSU_SELECT_FLASH_BUS_UPPER 0x2U
320#define XQSPIPSU_SELECT_FLASH_BUS_BOTH 0x3U
322#define XQSPIPSU_SELECT_MODE_SPI 0x1U
323#define XQSPIPSU_SELECT_MODE_DUALSPI 0x2U
324#define XQSPIPSU_SELECT_MODE_QUADSPI 0x4U
326#define XQSPIPSU_GENFIFO_CS_SETUP 0x05U
327#define XQSPIPSU_GENFIFO_CS_HOLD 0x04U
329#define XQSPIPSU_CLK_ACTIVE_LOW_OPTION 0x2U
330#define XQSPIPSU_CLK_PHASE_1_OPTION 0x4U
331#define XQSPIPSU_MANUAL_START_OPTION 0x8U
332#if !defined (versal)
333#define XQSPIPSU_LQSPI_MODE_OPTION 0x20U
335#define XQSPIPSU_LQSPI_LESS_THEN_SIXTEENMB 1U
336#endif
337
338#define XQSPIPSU_GENFIFO_EXP_START 0x100U
340#define XQSPIPSU_DMA_BYTES_MAX 0x10000000U
342#define XQSPIPSU_CLK_PRESCALE_2 0x00U
343#define XQSPIPSU_CLK_PRESCALE_4 0x01U
344#define XQSPIPSU_CLK_PRESCALE_8 0x02U
345#define XQSPIPSU_CLK_PRESCALE_16 0x03U
346#define XQSPIPSU_CLK_PRESCALE_32 0x04U
347#define XQSPIPSU_CLK_PRESCALE_64 0x05U
348#define XQSPIPSU_CLK_PRESCALE_128 0x06U
349#define XQSPIPSU_CLK_PRESCALE_256 0x07U
350#define XQSPIPSU_CR_PRESC_MAXIMUM 7U
352#define XQSPIPSU_CONNECTION_MODE_SINGLE 0U
353#define XQSPIPSU_CONNECTION_MODE_STACKED 1U
354#define XQSPIPSU_CONNECTION_MODE_PARALLEL 2U
356/*QSPI Frequencies*/
357#define XQSPIPSU_FREQ_37_5MHZ 37500000U
358#define XQSPIPSU_FREQ_40MHZ 40000000U
359#define XQSPIPSU_FREQ_100MHZ 100000000U
360#define XQSPIPSU_FREQ_150MHZ 150000000U
362/* Add more flags as required */
363#define XQSPIPSU_MSG_FLAG_STRIPE 0x1U
364#define XQSPIPSU_MSG_FLAG_RX 0x2U
365#define XQSPIPSU_MSG_FLAG_TX 0x4U
366#define XQSPIPSU_MSG_FLAG_POLL 0x8U
368#define XQSPIPSU_RXADDR_OVER_32BIT 0x100000000U
370#define XQSPIPSU_SET_WP 1
375#define XQspiPsu_Select(InstancePtr, Mask) \
376 XQspiPsu_Out32(((InstancePtr)->Config.BaseAddress) + \
377 XQSPIPSU_SEL_OFFSET, (Mask))
378
382#define XQspiPsu_Enable(InstancePtr) \
383 XQspiPsu_Out32(((InstancePtr)->Config.BaseAddress) + \
384 XQSPIPSU_EN_OFFSET, XQSPIPSU_EN_MASK)
385
388#define XQspiPsu_Disable(InstancePtr) \
389 XQspiPsu_Out32(((InstancePtr)->Config.BaseAddress) + \
390 XQSPIPSU_EN_OFFSET, 0x0U)
391
395#if !defined (versal)
396#define XQspiPsu_GetLqspiConfigReg(InstancePtr) \
397 XQspiPsu_In32((XQSPIPS_BASEADDR) + \
398 XQSPIPSU_LQSPI_CR_OFFSET)
399#endif
400
401/*****************************************************************************/
413static inline void XQspiPsu_ManualStartEnable(XQspiPsu *InstancePtr)
414{
415 Xil_AssertVoid(InstancePtr != NULL);
417#ifdef DEBUG
418 xil_printf("\nXQspiPsu_ManualStartEnable\r\n");
419#endif
420
421 if (InstancePtr->IsManualstart == (u8)TRUE) {
422#ifdef DEBUG
423 xil_printf("\nManual Start\r\n");
424#endif
427 XQSPIPSU_CFG_START_GEN_FIFO_MASK);
428 }
429}
430/*****************************************************************************/
442static inline void XQspiPsu_GenFifoEntryCSAssert(const XQspiPsu *InstancePtr)
443{
444 u32 GenFifoEntry;
445
446 Xil_AssertVoid(InstancePtr != NULL);
448#ifdef DEBUG
449 xil_printf("\nXQspiPsu_GenFifoEntryCSAssert\r\n");
450#endif
451
452 GenFifoEntry = 0x0U;
453 GenFifoEntry |= (XQSPIPSU_GENFIFO_MODE_SPI | InstancePtr->GenFifoCS |
455#ifdef DEBUG
456 xil_printf("\nFifoEntry=%08x\r\n", GenFifoEntry);
457#endif
459 XQSPIPSU_GEN_FIFO_OFFSET, GenFifoEntry);
460}
461
462/*****************************************************************************/
474static inline void XQspiPsu_GenFifoEntryCSDeAssert(const XQspiPsu *InstancePtr)
475{
476 u32 GenFifoEntry;
477
478 Xil_AssertVoid(InstancePtr != NULL);
480#ifdef DEBUG
481 xil_printf("\nXQspiPsu_GenFifoEntryCSDeAssert\r\n");
482#endif
483
484 GenFifoEntry = 0x0U;
485 GenFifoEntry |= (XQSPIPSU_GENFIFO_MODE_SPI | InstancePtr->GenFifoBus |
487#ifdef DEBUG
488 xil_printf("\nFifoEntry=%08x\r\n", GenFifoEntry);
489#endif
491 XQSPIPSU_GEN_FIFO_OFFSET, GenFifoEntry);
492}
493
494/*****************************************************************************/
510static inline void StubStatusHandler(const void *CallBackRef, u32 StatusEvent,
511 u32 ByteCount)
512{
513 (const void) CallBackRef;
514 (void) StatusEvent;
515 (void) ByteCount;
516
518}
519/************************** Function Prototypes ******************************/
520
521/* Initialization and reset */
522XQspiPsu_Config *XQspiPsu_LookupConfig(u16 DeviceId);
523s32 XQspiPsu_CfgInitialize(XQspiPsu *InstancePtr,
524 const XQspiPsu_Config *ConfigPtr,
525 UINTPTR EffectiveAddr);
526void XQspiPsu_Reset(XQspiPsu *InstancePtr);
527void XQspiPsu_Abort(XQspiPsu *InstancePtr);
528
529/* Transfer functions and handlers */
530s32 XQspiPsu_PolledTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg,
531 u32 NumMsg);
533 u32 NumMsg);
534s32 XQspiPsu_InterruptHandler(XQspiPsu *InstancePtr);
535void XQspiPsu_SetStatusHandler(XQspiPsu *InstancePtr, void *CallBackRef,
536 XQspiPsu_StatusHandler FuncPointer);
537
538/* Non blocking Transfer functions */
539s32 XQspiPsu_StartDmaTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg,
540 u32 NumMsg);
541s32 XQspiPsu_CheckDmaDone(XQspiPsu *InstancePtr);
542
543/* Configuration functions */
544s32 XQspiPsu_SetClkPrescaler(const XQspiPsu *InstancePtr, u8 Prescaler);
545void XQspiPsu_SelectFlash(XQspiPsu *InstancePtr, u8 FlashCS, u8 FlashBus);
546s32 XQspiPsu_SetOptions(XQspiPsu *InstancePtr, u32 Options);
547s32 XQspiPsu_ClearOptions(XQspiPsu *InstancePtr, u32 Options);
548u32 XQspiPsu_GetOptions(const XQspiPsu *InstancePtr);
549s32 XQspiPsu_SetReadMode(XQspiPsu *InstancePtr, u32 Mode);
550void XQspiPsu_SetWP(const XQspiPsu *InstancePtr, u8 Value);
551void XQspiPsu_WriteProtectToggle(const XQspiPsu *InstancePtr, u32 Toggle);
552void XQspiPsu_Idle(const XQspiPsu *InstancePtr);
553
554/************************** Variable Prototypes ******************************/
555
560#ifndef __rtems__
561extern XQspiPsu_Config XQspiPsu_ConfigTable[XPAR_XQSPIPSU_NUM_INSTANCES];
562#endif /* __rtems__ */
563
564#ifdef __cplusplus
565}
566#endif
567
568
569#endif /* XQSPIPSU_H_ */
void XQspiPsu_SetStatusHandler(XQspiPsu *InstancePtr, void *CallBackRef, XQspiPsu_StatusHandler FuncPointer)
Definition: xqspipsu.c:873
s32 XQspiPsu_ClearOptions(XQspiPsu *InstancePtr, u32 Options)
Definition: xqspipsu_options.c:214
XQspiPsu_Config XQspiPsu_ConfigTable[XPAR_XQSPIPSU_NUM_INSTANCES]
void XQspiPsu_WriteProtectToggle(const XQspiPsu *InstancePtr, u32 Toggle)
This API enables/ disables Write Protect pin on the flash parts.
Definition: xqspipsu.c:901
#define XQSPIPSU_CFG_OFFSET
Definition: xqspipsu_hw.h:96
void XQspiPsu_SelectFlash(XQspiPsu *InstancePtr, u8 FlashCS, u8 FlashBus)
Definition: xqspipsu_options.c:381
s32 XQspiPsu_SetReadMode(XQspiPsu *InstancePtr, u32 Mode)
Definition: xqspipsu_options.c:457
#define XQSPIPSU_GEN_FIFO_OFFSET
Definition: xqspipsu_hw.h:487
void XQspiPsu_Idle(const XQspiPsu *InstancePtr)
Definition: xqspipsu.c:209
void XQspiPsu_SetWP(const XQspiPsu *InstancePtr, u8 Value)
Definition: xqspipsu_options.c:519
#define XQspiPsu_WriteReg(BaseAddress, RegOffset, RegisterValue)
Definition: xqspipsu_hw.h:997
s32 XQspiPsu_PolledTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg, u32 NumMsg)
Definition: xqspipsu.c:432
s32 XQspiPsu_InterruptTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg, u32 NumMsg)
Definition: xqspipsu.c:587
s32 XQspiPsu_CheckDmaDone(XQspiPsu *InstancePtr)
Definition: xqspipsu.c:1030
#define XQSPIPSU_GENFIFO_CS_HOLD
Definition: xqspipsu.h:327
s32 XQspiPsu_StartDmaTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg, u32 NumMsg)
Definition: xqspipsu.c:941
void XQspiPsu_Reset(XQspiPsu *InstancePtr)
Definition: xqspipsu.c:249
s32 XQspiPsu_CfgInitialize(XQspiPsu *InstancePtr, const XQspiPsu_Config *ConfigPtr, UINTPTR EffectiveAddr)
Definition: xqspipsu.c:129
void(* XQspiPsu_StatusHandler)(const void *CallBackRef, u32 StatusEvent, u32 ByteCount)
Definition: xqspipsu.h:211
s32 XQspiPsu_SetClkPrescaler(const XQspiPsu *InstancePtr, u8 Prescaler)
Definition: xqspipsu_options.c:319
#define XQSPIPSU_GENFIFO_CS_SETUP
Definition: xqspipsu.h:326
s32 XQspiPsu_InterruptHandler(XQspiPsu *InstancePtr)
Definition: xqspipsu.c:683
void XQspiPsu_Abort(XQspiPsu *InstancePtr)
Definition: xqspipsu.c:276
u32 XQspiPsu_GetOptions(const XQspiPsu *InstancePtr)
Definition: xqspipsu_options.c:278
#define XQspiPsu_ReadReg(BaseAddress, RegOffset)
Definition: xqspipsu_hw.h:979
s32 XQspiPsu_SetOptions(XQspiPsu *InstancePtr, u32 Options)
Definition: xqspipsu_options.c:116
#define TRUE
If TRUE is undefined, then TRUE is defined to 1.
Definition: basedefs.h:872
#define Xil_AssertVoid(Expression)
This assert macro is to be used for void functions. This in conjunction with the Xil_AssertWait boole...
Definition: xil_assert.h:86
#define Xil_AssertVoidAlways()
Always assert. This assert macro is to be used for void functions. Use for instances where an assert ...
Definition: xil_assert.h:131
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54
#define XIL_COMPONENT_IS_READY
Definition: xil_types.h:57
Definition: xqspipsu.h:234
u8 IsCacheCoherent
Definition: xqspipsu.h:240
UINTPTR BaseAddress
Definition: xqspipsu.h:236
u16 DeviceId
Definition: xqspipsu.h:235
u32 InputClockHz
Definition: xqspipsu.h:237
u8 ConnectionMode
Definition: xqspipsu.h:238
u8 BusWidth
Definition: xqspipsu.h:239
Definition: xqspipsu.h:217
u8 * TxBfrPtr
Definition: xqspipsu.h:218
u8 PollData
Definition: xqspipsu.h:223
u8 * RxBfrPtr
Definition: xqspipsu.h:219
u32 Flags
Definition: xqspipsu.h:222
u8 PollBusMask
Definition: xqspipsu.h:226
u32 ByteCount
Definition: xqspipsu.h:220
u8 PollStatusCmd
Definition: xqspipsu.h:225
u64 RxAddr64bit
Definition: xqspipsu.h:227
u32 PollTimeout
Definition: xqspipsu.h:224
u8 Xfer64bit
Definition: xqspipsu.h:228
u32 BusWidth
Definition: xqspipsu.h:221
Definition: xqspipsu.h:251
u32 GenFifoBus
Definition: xqspipsu.h:268
u8 IsManualstart
Definition: xqspipsu.h:272
s32 IsUnaligned
Definition: xqspipsu.h:271
XQspiPsu_Msg * Msg
Definition: xqspipsu.h:273
u8 * SendBufferPtr
Definition: xqspipsu.h:255
XQspiPsu_StatusHandler StatusHandler
Definition: xqspipsu.h:274
s32 TxBytes
Definition: xqspipsu.h:259
u8 * RecvBufferPtr
Definition: xqspipsu.h:256
u64 RecvBuffer
Definition: xqspipsu.h:257
XQspiPsu_Config Config
Definition: xqspipsu.h:252
void * StatusRef
Definition: xqspipsu.h:275
u32 IsBusy
Definition: xqspipsu.h:265
u32 ReadMode
Definition: xqspipsu.h:266
s32 GenFifoEntries
Definition: xqspipsu.h:261
s32 RxBytes
Definition: xqspipsu.h:260
s32 MsgCnt
Definition: xqspipsu.h:270
u32 GenFifoCS
Definition: xqspipsu.h:267
u8 * GenFifoBufferPtr
Definition: xqspipsu.h:258
u32 IsReady
Definition: xqspipsu.h:253
s32 NumMsg
Definition: xqspipsu.h:269