RTEMS 6.1-rc4
Loading...
Searching...
No Matches
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#ifndef __rtems__
185#include "xstatus.h"
186#endif
187#include "xqspipsu_hw.h"
188#ifndef __rtems__
189#include "xil_cache.h"
190#include "xil_mem.h"
191#if defined (XCLOCKING)
192#include "xil_clocking.h"
193#endif
194#else
195#include <bsp/xil-compat.h>
196#endif
197
198/**************************** Type Definitions *******************************/
217typedef void (*XQspiPsu_StatusHandler) (const void *CallBackRef, u32 StatusEvent,
218 u32 ByteCount);
219
223typedef struct {
228 u32 Flags;
236
240typedef struct {
242 UINTPTR BaseAddress;
247#if defined (XCLOCKING)
248 u32 RefClk;
249#endif
251
257typedef struct {
268#ifdef __rtems__
269 volatile
270#endif
271 u32 IsBusy;
275 s32 NumMsg;
276 s32 MsgCnt;
281 void *StatusRef;
282} XQspiPsu;
283
284/***************** Macros (Inline Functions) Definitions *********************/
285
290#define BYTES256_PER_PAGE 256U
291#define BYTES512_PER_PAGE 512U
292#define BYTES1024_PER_PAGE 1024U
293#define PAGES16_PER_SECTOR 16U
294#define PAGES128_PER_SECTOR 128U
295#define PAGES256_PER_SECTOR 256U
296#define PAGES512_PER_SECTOR 512U
297#define PAGES1024_PER_SECTOR 1024U
298#define NUM_OF_SECTORS2 2U
299#define NUM_OF_SECTORS4 4U
300#define NUM_OF_SECTORS8 8U
301#define NUM_OF_SECTORS16 16U
302#define NUM_OF_SECTORS32 32U
303#define NUM_OF_SECTORS64 64U
304#define NUM_OF_SECTORS128 128U
305#define NUM_OF_SECTORS256 256U
306#define NUM_OF_SECTORS512 512U
307#define NUM_OF_SECTORS1024 1024U
308#define NUM_OF_SECTORS2048 2048U
309#define NUM_OF_SECTORS4096 4096U
310#define NUM_OF_SECTORS8192 8192U
311#define SECTOR_SIZE_64K 0X10000U
312#define SECTOR_SIZE_128K 0X20000U
313#define SECTOR_SIZE_256K 0X40000U
314#define SECTOR_SIZE_512K 0X80000U
317#define XQSPIPSU_READMODE_DMA 0x0U
318#define XQSPIPSU_READMODE_IO 0x1U
320#define XQSPIPSU_SELECT_FLASH_CS_LOWER 0x1U
321#define XQSPIPSU_SELECT_FLASH_CS_UPPER 0x2U
322#define XQSPIPSU_SELECT_FLASH_CS_BOTH 0x3U
324#define XQSPIPSU_SELECT_FLASH_BUS_LOWER 0x1U
325#define XQSPIPSU_SELECT_FLASH_BUS_UPPER 0x2U
326#define XQSPIPSU_SELECT_FLASH_BUS_BOTH 0x3U
328#define XQSPIPSU_SELECT_MODE_SPI 0x1U
329#define XQSPIPSU_SELECT_MODE_DUALSPI 0x2U
330#define XQSPIPSU_SELECT_MODE_QUADSPI 0x4U
332#define XQSPIPSU_GENFIFO_CS_SETUP 0x05U
333#define XQSPIPSU_GENFIFO_CS_HOLD 0x04U
335#define XQSPIPSU_CLK_ACTIVE_LOW_OPTION 0x2U
336#define XQSPIPSU_CLK_PHASE_1_OPTION 0x4U
337#define XQSPIPSU_MANUAL_START_OPTION 0x8U
338#if !defined (versal)
339#define XQSPIPSU_LQSPI_MODE_OPTION 0x20U
341#define XQSPIPSU_LQSPI_LESS_THEN_SIXTEENMB 1U
342#endif
343
344#define XQSPIPSU_GENFIFO_EXP_START 0x100U
346#define XQSPIPSU_DMA_BYTES_MAX 0x10000000U
348#define XQSPIPSU_CLK_PRESCALE_2 0x00U
349#define XQSPIPSU_CLK_PRESCALE_4 0x01U
350#define XQSPIPSU_CLK_PRESCALE_8 0x02U
351#define XQSPIPSU_CLK_PRESCALE_16 0x03U
352#define XQSPIPSU_CLK_PRESCALE_32 0x04U
353#define XQSPIPSU_CLK_PRESCALE_64 0x05U
354#define XQSPIPSU_CLK_PRESCALE_128 0x06U
355#define XQSPIPSU_CLK_PRESCALE_256 0x07U
356#define XQSPIPSU_CR_PRESC_MAXIMUM 7U
358#define XQSPIPSU_CONNECTION_MODE_SINGLE 0U
359#define XQSPIPSU_CONNECTION_MODE_STACKED 1U
360#define XQSPIPSU_CONNECTION_MODE_PARALLEL 2U
362/*QSPI Frequencies*/
363#define XQSPIPSU_FREQ_37_5MHZ 37500000U
364#define XQSPIPSU_FREQ_40MHZ 40000000U
365#define XQSPIPSU_FREQ_100MHZ 100000000U
366#define XQSPIPSU_FREQ_150MHZ 150000000U
368/* Add more flags as required */
369#define XQSPIPSU_MSG_FLAG_STRIPE 0x1U
370#define XQSPIPSU_MSG_FLAG_RX 0x2U
371#define XQSPIPSU_MSG_FLAG_TX 0x4U
372#define XQSPIPSU_MSG_FLAG_POLL 0x8U
374#define XQSPIPSU_RXADDR_OVER_32BIT 0x100000000U
376#define XQSPIPSU_SET_WP 1
381#define XQspiPsu_Select(InstancePtr, Mask) \
382 XQspiPsu_Out32(((InstancePtr)->Config.BaseAddress) + \
383 XQSPIPSU_SEL_OFFSET, (Mask))
384
388#define XQspiPsu_Enable(InstancePtr) \
389 XQspiPsu_Out32(((InstancePtr)->Config.BaseAddress) + \
390 XQSPIPSU_EN_OFFSET, XQSPIPSU_EN_MASK)
391
394#define XQspiPsu_Disable(InstancePtr) \
395 XQspiPsu_Out32(((InstancePtr)->Config.BaseAddress) + \
396 XQSPIPSU_EN_OFFSET, 0x0U)
397
401#if !defined (versal)
402#define XQspiPsu_GetLqspiConfigReg(InstancePtr) \
403 XQspiPsu_In32((XQSPIPS_BASEADDR) + \
404 XQSPIPSU_LQSPI_CR_OFFSET)
405#endif
406
407/*****************************************************************************/
419static inline void XQspiPsu_ManualStartEnable(XQspiPsu *InstancePtr)
420{
421 Xil_AssertVoid(InstancePtr != NULL);
422 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
423#ifdef DEBUG
424 xil_printf("\nXQspiPsu_ManualStartEnable\r\n");
425#endif
426
427 if (InstancePtr->IsManualstart == (u8)TRUE) {
428#ifdef DEBUG
429 xil_printf("\nManual Start\r\n");
430#endif
433 XQSPIPSU_CFG_START_GEN_FIFO_MASK);
434 }
435}
436/*****************************************************************************/
448static inline void XQspiPsu_GenFifoEntryCSAssert(const XQspiPsu *InstancePtr)
449{
450 u32 GenFifoEntry;
451
452 Xil_AssertVoid(InstancePtr != NULL);
453 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
454#ifdef DEBUG
455 xil_printf("\nXQspiPsu_GenFifoEntryCSAssert\r\n");
456#endif
457
458 GenFifoEntry = 0x0U;
459 GenFifoEntry |= (XQSPIPSU_GENFIFO_MODE_SPI | InstancePtr->GenFifoCS |
461#ifdef DEBUG
462 xil_printf("\nFifoEntry=%08x\r\n", GenFifoEntry);
463#endif
465 XQSPIPSU_GEN_FIFO_OFFSET, GenFifoEntry);
466}
467
468/*****************************************************************************/
480static inline void XQspiPsu_GenFifoEntryCSDeAssert(const XQspiPsu *InstancePtr)
481{
482 u32 GenFifoEntry;
483
484 Xil_AssertVoid(InstancePtr != NULL);
485 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
486#ifdef DEBUG
487 xil_printf("\nXQspiPsu_GenFifoEntryCSDeAssert\r\n");
488#endif
489
490 GenFifoEntry = 0x0U;
491 GenFifoEntry |= (XQSPIPSU_GENFIFO_MODE_SPI | InstancePtr->GenFifoBus |
493#ifdef DEBUG
494 xil_printf("\nFifoEntry=%08x\r\n", GenFifoEntry);
495#endif
497 XQSPIPSU_GEN_FIFO_OFFSET, GenFifoEntry);
498}
499
500/*****************************************************************************/
516static inline void StubStatusHandler(const void *CallBackRef, u32 StatusEvent,
517 u32 ByteCount)
518{
519 (const void) CallBackRef;
520 (void) StatusEvent;
521 (void) ByteCount;
522
523 Xil_AssertVoidAlways();
524}
525/************************** Function Prototypes ******************************/
526
527/* Initialization and reset */
528XQspiPsu_Config *XQspiPsu_LookupConfig(u16 DeviceId);
529s32 XQspiPsu_CfgInitialize(XQspiPsu *InstancePtr,
530 const XQspiPsu_Config *ConfigPtr,
531 UINTPTR EffectiveAddr);
532void XQspiPsu_Reset(XQspiPsu *InstancePtr);
533void XQspiPsu_Abort(XQspiPsu *InstancePtr);
534
535/* Transfer functions and handlers */
536s32 XQspiPsu_PolledTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg,
537 u32 NumMsg);
539 u32 NumMsg);
540s32 XQspiPsu_InterruptHandler(XQspiPsu *InstancePtr);
541void XQspiPsu_SetStatusHandler(XQspiPsu *InstancePtr, void *CallBackRef,
542 XQspiPsu_StatusHandler FuncPointer);
543
544/* Non blocking Transfer functions */
545s32 XQspiPsu_StartDmaTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg,
546 u32 NumMsg);
547s32 XQspiPsu_CheckDmaDone(XQspiPsu *InstancePtr);
548
549/* Configuration functions */
550s32 XQspiPsu_SetClkPrescaler(const XQspiPsu *InstancePtr, u8 Prescaler);
551void XQspiPsu_SelectFlash(XQspiPsu *InstancePtr, u8 FlashCS, u8 FlashBus);
552s32 XQspiPsu_SetOptions(XQspiPsu *InstancePtr, u32 Options);
553s32 XQspiPsu_ClearOptions(XQspiPsu *InstancePtr, u32 Options);
554u32 XQspiPsu_GetOptions(const XQspiPsu *InstancePtr);
555s32 XQspiPsu_SetReadMode(XQspiPsu *InstancePtr, u32 Mode);
556void XQspiPsu_SetWP(const XQspiPsu *InstancePtr, u8 Value);
557void XQspiPsu_WriteProtectToggle(const XQspiPsu *InstancePtr, u32 Toggle);
558void XQspiPsu_Idle(const XQspiPsu *InstancePtr);
559
560/************************** Variable Prototypes ******************************/
561
566#ifndef __rtems__
567extern XQspiPsu_Config XQspiPsu_ConfigTable[XPAR_XQSPIPSU_NUM_INSTANCES];
568#endif /* __rtems__ */
569
570#ifdef __cplusplus
571}
572#endif
573
574
575#endif /* XQSPIPSU_H_ */
void XQspiPsu_SetStatusHandler(XQspiPsu *InstancePtr, void *CallBackRef, XQspiPsu_StatusHandler FuncPointer)
Definition: xqspipsu.c:890
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:918
#define XQSPIPSU_CFG_OFFSET
Definition: xqspipsu_hw.h:100
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:491
void XQspiPsu_Idle(const XQspiPsu *InstancePtr)
Definition: xqspipsu.c:211
void XQspiPsu_SetWP(const XQspiPsu *InstancePtr, u8 Value)
Definition: xqspipsu_options.c:519
#define XQspiPsu_WriteReg(BaseAddress, RegOffset, RegisterValue)
Definition: xqspipsu_hw.h:1001
s32 XQspiPsu_PolledTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg, u32 NumMsg)
Definition: xqspipsu.c:449
s32 XQspiPsu_InterruptTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg, u32 NumMsg)
Definition: xqspipsu.c:604
s32 XQspiPsu_CheckDmaDone(XQspiPsu *InstancePtr)
Definition: xqspipsu.c:1047
#define XQSPIPSU_GENFIFO_CS_HOLD
Definition: xqspipsu.h:333
s32 XQspiPsu_StartDmaTransfer(XQspiPsu *InstancePtr, XQspiPsu_Msg *Msg, u32 NumMsg)
Definition: xqspipsu.c:958
void XQspiPsu_Reset(XQspiPsu *InstancePtr)
Definition: xqspipsu.c:251
s32 XQspiPsu_CfgInitialize(XQspiPsu *InstancePtr, const XQspiPsu_Config *ConfigPtr, UINTPTR EffectiveAddr)
Definition: xqspipsu.c:131
void(* XQspiPsu_StatusHandler)(const void *CallBackRef, u32 StatusEvent, u32 ByteCount)
Definition: xqspipsu.h:217
s32 XQspiPsu_SetClkPrescaler(const XQspiPsu *InstancePtr, u8 Prescaler)
Definition: xqspipsu_options.c:319
#define XQSPIPSU_GENFIFO_CS_SETUP
Definition: xqspipsu.h:332
s32 XQspiPsu_InterruptHandler(XQspiPsu *InstancePtr)
Definition: xqspipsu.c:700
void XQspiPsu_Abort(XQspiPsu *InstancePtr)
Definition: xqspipsu.c:278
u32 XQspiPsu_GetOptions(const XQspiPsu *InstancePtr)
Definition: xqspipsu_options.c:278
#define XQspiPsu_ReadReg(BaseAddress, RegOffset)
Definition: xqspipsu_hw.h:983
s32 XQspiPsu_SetOptions(XQspiPsu *InstancePtr, u32 Options)
Definition: xqspipsu_options.c:116
Definition: xqspipsu.h:240
u8 IsCacheCoherent
Definition: xqspipsu.h:246
UINTPTR BaseAddress
Definition: xqspipsu.h:242
u16 DeviceId
Definition: xqspipsu.h:241
u32 InputClockHz
Definition: xqspipsu.h:243
u8 ConnectionMode
Definition: xqspipsu.h:244
u8 BusWidth
Definition: xqspipsu.h:245
Definition: xqspipsu.h:223
u8 * TxBfrPtr
Definition: xqspipsu.h:224
u8 PollData
Definition: xqspipsu.h:229
u8 * RxBfrPtr
Definition: xqspipsu.h:225
u32 Flags
Definition: xqspipsu.h:228
u8 PollBusMask
Definition: xqspipsu.h:232
u32 ByteCount
Definition: xqspipsu.h:226
u8 PollStatusCmd
Definition: xqspipsu.h:231
u64 RxAddr64bit
Definition: xqspipsu.h:233
u32 PollTimeout
Definition: xqspipsu.h:230
u8 Xfer64bit
Definition: xqspipsu.h:234
u32 BusWidth
Definition: xqspipsu.h:227
Definition: xqspipsu.h:257
u32 GenFifoBus
Definition: xqspipsu.h:274
u8 IsManualstart
Definition: xqspipsu.h:278
s32 IsUnaligned
Definition: xqspipsu.h:277
XQspiPsu_Msg * Msg
Definition: xqspipsu.h:279
u8 * SendBufferPtr
Definition: xqspipsu.h:261
XQspiPsu_StatusHandler StatusHandler
Definition: xqspipsu.h:280
s32 TxBytes
Definition: xqspipsu.h:265
u8 * RecvBufferPtr
Definition: xqspipsu.h:262
u64 RecvBuffer
Definition: xqspipsu.h:263
XQspiPsu_Config Config
Definition: xqspipsu.h:258
void * StatusRef
Definition: xqspipsu.h:281
u32 IsBusy
Definition: xqspipsu.h:271
u32 ReadMode
Definition: xqspipsu.h:272
s32 GenFifoEntries
Definition: xqspipsu.h:267
s32 RxBytes
Definition: xqspipsu.h:266
s32 MsgCnt
Definition: xqspipsu.h:276
u32 GenFifoCS
Definition: xqspipsu.h:273
u8 * GenFifoBufferPtr
Definition: xqspipsu.h:264
u32 IsReady
Definition: xqspipsu.h:259
s32 NumMsg
Definition: xqspipsu.h:275