RTEMS 6.1-rc5
Loading...
Searching...
No Matches
xnandpsu.h
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (C) 2015 - 2022 Xilinx, Inc. All rights reserved.
3* SPDX-License-Identifier: MIT
4******************************************************************************/
5
6/*****************************************************************************/
162#ifndef XNANDPSU_H /* prevent circular inclusions */
163#define XNANDPSU_H /* by using protection macros */
164
165#ifdef __cplusplus
166extern "C" {
167#endif
168
169/***************************** Include Files *********************************/
170#ifndef __rtems__
171#include "xil_types.h"
172#include <string.h>
173#include "xstatus.h"
174#include "xil_assert.h"
175#include "xnandpsu_hw.h"
176#include "xnandpsu_onfi.h"
177#include "xil_cache.h"
178#if defined (XCLOCKING)
179#include "xil_clocking.h"
180#endif
181#else
182#include <bsp/xil-compat.h>
183#include <string.h>
184#include "xnandpsu_hw.h"
185#include "xnandpsu_onfi.h"
186#endif
187/************************** Constant Definitions *****************************/
188
189#define XNANDPSU_DEBUG
190
191#ifdef __rtems__
192#define XNANDPSU_MAX_TARGETS 2U
193#else
194#define XNANDPSU_MAX_TARGETS 1U
195#endif
196#define XNANDPSU_MAX_PKT_SIZE 0x7FFU
197#define XNANDPSU_MAX_PKT_COUNT 0xFFFU
199#define XNANDPSU_PAGE_SIZE_512 512U
200#define XNANDPSU_PAGE_SIZE_2K 2048U
201#define XNANDPSU_PAGE_SIZE_4K 4096U
202#define XNANDPSU_PAGE_SIZE_8K 8192U
203#define XNANDPSU_PAGE_SIZE_16K 16384U
204#define XNANDPSU_PAGE_SIZE_1K_16BIT 1024U
205#define XNANDPSU_MAX_PAGE_SIZE 16384U
207#define XNANDPSU_HAMMING 0x1U
208#define XNANDPSU_BCH 0x2U
210#define XNANDPSU_MAX_BLOCKS 16384U
211#define XNANDPSU_MAX_SPARE_SIZE 0x800U
213#define XNANDPSU_MAX_LUNS 8U
214#define XNANDPSU_MAX_PAGES_PER_BLOCK 512U
216#define XNANDPSU_INTR_POLL_TIMEOUT 0xF000000U
217
218#define XNANDPSU_SDR_CLK ((u16)100U * (u16)1000U * (u16)1000U)
219#define XNANDPSU_NVDDR_CLK_0 ((u16)20U * (u16)1000U * (u16)1000U)
220#define XNANDPSU_NVDDR_CLK_1 ((u16)33U * (u16)1000U * (u16)1000U)
221#define XNANDPSU_NVDDR_CLK_2 ((u16)50U * (u16)1000U * (u16)1000U)
222#define XNANDPSU_NVDDR_CLK_3 ((u16)66U * (u16)1000U * (u16)1000U)
223#define XNANDPSU_NVDDR_CLK_4 ((u16)83U * (u16)1000U * (u16)1000U)
224#define XNANDPSU_NVDDR_CLK_5 ((u16)100U * (u16)1000U * (u16)1000U)
225
226#define XNANDPSU_MAX_TIMING_MODE 5
227
228#ifdef __rtems__
229#define XNANDPSU_PAGE_CACHE_UNAVAILABLE -2
230#define XNANDPSU_PAGE_CACHE_NONE -1
231#endif
232
237typedef struct {
241#if defined (XCLOCKING)
242 u32 RefClk;
243#endif
245
249typedef enum {
253
257typedef enum {
258 XNANDPSU_SDR0 = 0U,
259 XNANDPSU_SDR1,
260 XNANDPSU_SDR2,
261 XNANDPSU_SDR3,
262 XNANDPSU_SDR4,
263 XNANDPSU_SDR5,
264 XNANDPSU_NVDDR0,
265 XNANDPSU_NVDDR1,
266 XNANDPSU_NVDDR2,
267 XNANDPSU_NVDDR3,
268 XNANDPSU_NVDDR4,
269 XNANDPSU_NVDDR5
271
275typedef enum {
279
283typedef enum {
288
292typedef enum {
293 XNANDPSU_NONE = 0,
294 XNANDPSU_HWECC,
295 XNANDPSU_EZNAND,
296 XNANDPSU_ONDIE
298
302typedef struct {
303 u32 PageOffset[XNANDPSU_MAX_TARGETS];
309 char Signature[5];
312 u32 Valid;
314
318typedef struct {
320 u32 Offset;
321 u32 Length;
322 u8 Pattern[2];
324
328typedef struct {
329 /* Parameter page information */
340 /* Driver specific information */
350
354typedef struct {
355 u32 NvDdr;
356 u32 EzNand;
357 u32 OnDie;
358 u32 ExtPrmPage;
360
364typedef struct {
365 u16 PageSize;
366 u16 CodeWordSize;
367 u8 NumEccBits;
368 u8 IsBCH;
369 u16 EccAddr;
370 u16 EccSize;
372
376typedef struct {
377 u16 EccAddr;
378 u16 EccSize;
379 u16 CodeWordSize;
380 u8 NumEccBits;
381 u8 IsBCH;
383
390#ifdef __ICCARM__
391#pragma pack(push, 1)
392#endif
393typedef struct {
395 XNandPsu_Config Config;
398 XNandPsu_DataInterface DataInterface;
399 XNandPsu_TimingMode TimingMode;
406#ifdef __rtems__
407 int32_t PartialDataPageIndex;
408#endif
409#ifdef __ICCARM__
410 u8 PartialDataBuf[XNANDPSU_MAX_PAGE_SIZE];
411#pragma pack(pop)
412#else
413 u8 PartialDataBuf[XNANDPSU_MAX_PAGE_SIZE] __attribute__ ((aligned(64)));
414#endif
415 /* Bad block table definitions */
420 u8 Bbt[XNANDPSU_MAX_BLOCKS >> 2];
421} XNandPsu;
422
423/******************* Macro Definitions (Inline Functions) *******************/
424
425/*****************************************************************************/
439#define XNandPsu_SetBits(InstancePtr, RegOffset, BitMask) \
440 XNandPsu_WriteReg((InstancePtr)->Config.BaseAddress, \
441 (RegOffset), \
442 ((u32)(XNandPsu_ReadReg((InstancePtr)->Config.BaseAddress, \
443 (RegOffset)) | (BitMask))))
444
445/*****************************************************************************/
459#define XNandPsu_ClrBits(InstancePtr, RegOffset, BitMask) \
460 XNandPsu_WriteReg((InstancePtr)->Config.BaseAddress, \
461 (RegOffset), \
462 ((u32)(XNandPsu_ReadReg((InstancePtr)->Config.BaseAddress, \
463 (RegOffset)) & ~(BitMask))))
464
465/*****************************************************************************/
480#define XNandPsu_ReadModifyWrite(InstancePtr, RegOffset, Mask, Value) \
481 XNandPsu_WriteReg((InstancePtr)->Config.BaseAddress, \
482 (RegOffset), \
483 ((u32)((u32)(XNandPsu_ReadReg((InstancePtr)->Config.BaseAddress,\
484 (u32)(RegOffset)) & (u32)(~(Mask))) | (u32)(Value))))
485
486/*****************************************************************************/
498#define XNandPsu_IntrSigEnable(InstancePtr, Mask) \
499 XNandPsu_SetBits((InstancePtr), \
500 XNANDPSU_INTR_SIG_EN_OFFSET, \
501 (Mask))
502
503/*****************************************************************************/
515#define XNandPsu_IntrSigClear(InstancePtr, Mask) \
516 XNandPsu_ClrBits((InstancePtr), \
517 XNANDPSU_INTR_SIG_EN_OFFSET, \
518 (Mask))
519
520/*****************************************************************************/
532#define XNandPsu_IntrStsEnable(InstancePtr, Mask) \
533 XNandPsu_SetBits((InstancePtr), \
534 XNANDPSU_INTR_STS_EN_OFFSET, \
535 (Mask))
536
537/*****************************************************************************/
546#define IS_ONFI(Buff) \
547 ((Buff)[0] == (u8)'O') && ((Buff)[1] == (u8)'N') && \
548 ((Buff)[2] == (u8)'F') && ((Buff)[3] == (u8)'I')
549
550/************************** Function Prototypes *****************************/
551
552s32 XNandPsu_CfgInitialize(XNandPsu *InstancePtr, XNandPsu_Config *ConfigPtr,
553 u32 EffectiveAddr);
554
555s32 XNandPsu_Erase(XNandPsu *InstancePtr, u64 Offset, u64 Length);
556
557s32 XNandPsu_Write(XNandPsu *InstancePtr, u64 Offset, u64 Length,
558 u8 *SrcBuf);
559
560s32 XNandPsu_Read(XNandPsu *InstancePtr, u64 Offset, u64 Length,
561 u8 *DestBuf);
562
563s32 XNandPsu_EraseBlock(XNandPsu *InstancePtr, u32 Target, u32 Block);
564
565s32 XNandPsu_WriteSpareBytes(XNandPsu *InstancePtr, u32 Page, u8 *Buf);
566
567s32 XNandPsu_ReadSpareBytes(XNandPsu *InstancePtr, u32 Page, u8 *Buf);
568
569s32 XNandPsu_ChangeTimingMode(XNandPsu *InstancePtr,
571 XNandPsu_TimingMode NewMode);
572
573s32 XNandPsu_GetFeature(XNandPsu *InstancePtr, u32 Target, u8 Feature,
574 u8 *Buf);
575
576s32 XNandPsu_SetFeature(XNandPsu *InstancePtr, u32 Target, u8 Feature,
577 u8 *Buf);
578
579s32 XNandPsu_ScanBbt(XNandPsu *InstancePtr);
580
581s32 XNandPsu_MarkBlockBad(XNandPsu *InstancePtr, u32 Block);
582
583#ifdef __rtems__
584#include <stdbool.h>
585/*****************************************************************************/
598s32 XNandPsu_MarkBlock(XNandPsu *InstancePtr, u32 Block, u8 BlockMark);
599
600/*****************************************************************************/
613bool XNandPsu_StageBlockMark(XNandPsu *InstancePtr, u32 Block, u8 BlockMark);
614
615/*****************************************************************************/
626s32 XNandPsu_UpdateBbt(XNandPsu *InstancePtr, u32 Target);
627#endif
628
629void XNandPsu_EnableDmaMode(XNandPsu *InstancePtr);
630
631void XNandPsu_DisableDmaMode(XNandPsu *InstancePtr);
632
633void XNandPsu_EnableEccMode(XNandPsu *InstancePtr);
634
635void XNandPsu_DisableEccMode(XNandPsu *InstancePtr);
636
637void XNandPsu_Prepare_Cmd(XNandPsu *InstancePtr, u8 Cmd1, u8 Cmd2, u8 EccState,
638 u8 DmaMode, u8 AddrCycles);
639
640/* XNandPsu_LookupConfig in xnandpsu_sinit.c */
641XNandPsu_Config *XNandPsu_LookupConfig(u16 DevID);
642
643
644#ifdef __cplusplus
645}
646#endif
647
648#endif /* XNANDPSU_H end of protection macro */
void XNandPsu_DisableEccMode(XNandPsu *InstancePtr)
Definition: xnandpsu.c:820
void XNandPsu_EnableEccMode(XNandPsu *InstancePtr)
Definition: xnandpsu.c:798
s32 XNandPsu_ReadSpareBytes(XNandPsu *InstancePtr, u32 Page, u8 *Buf)
Definition: xnandpsu.c:2158
XNandPsu_SWMode
Definition: xnandpsu.h:275
#define XNANDPSU_MAX_TARGETS
Definition: xnandpsu.h:194
s32 XNandPsu_ChangeTimingMode(XNandPsu *InstancePtr, XNandPsu_DataInterface NewIntf, XNandPsu_TimingMode NewMode)
Definition: xnandpsu.c:2436
void XNandPsu_EnableDmaMode(XNandPsu *InstancePtr)
Definition: xnandpsu.c:754
XNandPsu_DmaMode
Definition: xnandpsu.h:283
#define XNANDPSU_MAX_BLOCKS
Definition: xnandpsu.h:210
s32 XNandPsu_EraseBlock(XNandPsu *InstancePtr, u32 Target, u32 Block)
Definition: xnandpsu.c:2233
#define XNANDPSU_MAX_PAGE_SIZE
Definition: xnandpsu.h:205
s32 XNandPsu_SetFeature(XNandPsu *InstancePtr, u32 Target, u8 Feature, u8 *Buf)
Definition: xnandpsu.c:2354
s32 XNandPsu_WriteSpareBytes(XNandPsu *InstancePtr, u32 Page, u8 *Buf)
Definition: xnandpsu.c:1885
s32 XNandPsu_Erase(XNandPsu *InstancePtr, u64 Offset, u64 Length)
Definition: xnandpsu.c:1708
s32 XNandPsu_CfgInitialize(XNandPsu *InstancePtr, XNandPsu_Config *ConfigPtr, u32 EffectiveAddr)
Definition: xnandpsu.c:227
s32 XNandPsu_ScanBbt(XNandPsu *InstancePtr)
Definition: xnandpsu_bbm.c:259
s32 XNandPsu_MarkBlockBad(XNandPsu *InstancePtr, u32 Block)
Definition: xnandpsu_bbm.c:931
XNandPsu_EccMode
Definition: xnandpsu.h:292
XNandPsu_TimingMode
Definition: xnandpsu.h:257
void XNandPsu_DisableDmaMode(XNandPsu *InstancePtr)
Definition: xnandpsu.c:776
s32 XNandPsu_GetFeature(XNandPsu *InstancePtr, u32 Target, u8 Feature, u8 *Buf)
Definition: xnandpsu.c:2295
void XNandPsu_Prepare_Cmd(XNandPsu *InstancePtr, u8 Cmd1, u8 Cmd2, u8 EccState, u8 DmaMode, u8 AddrCycles)
Definition: xnandpsu.c:2764
XNandPsu_DataInterface
Definition: xnandpsu.h:249
s32 XNandPsu_Read(XNandPsu *InstancePtr, u64 Offset, u64 Length, u8 *DestBuf)
Definition: xnandpsu.c:1562
s32 XNandPsu_Write(XNandPsu *InstancePtr, u64 Offset, u64 Length, u8 *SrcBuf)
Definition: xnandpsu.c:1437
@ XNANDPSU_POLLING
Definition: xnandpsu.h:276
@ XNANDPSU_INTERRUPT
Definition: xnandpsu.h:277
@ XNANDPSU_MDMA
Definition: xnandpsu.h:286
@ XNANDPSU_PIO
Definition: xnandpsu.h:284
@ XNANDPSU_SDMA
Definition: xnandpsu.h:285
@ XNANDPSU_SDR
Definition: xnandpsu.h:250
@ XNANDPSU_NVDDR
Definition: xnandpsu.h:251
Definition: xnandpsu.h:318
u32 Options
Definition: xnandpsu.h:319
u32 Length
Definition: xnandpsu.h:321
u32 Offset
Definition: xnandpsu.h:320
Definition: xnandpsu.h:302
u32 MaxBlocks
Definition: xnandpsu.h:308
u32 VerOffset
Definition: xnandpsu.h:306
u32 SigOffset
Definition: xnandpsu.h:305
u32 SigLength
Definition: xnandpsu.h:307
u32 Valid
Definition: xnandpsu.h:312
Definition: xnandpsu.h:237
u16 DeviceId
Definition: xnandpsu.h:238
u8 IsCacheCoherent
Definition: xnandpsu.h:240
u32 BaseAddress
Definition: xnandpsu.h:239
Definition: xnandpsu.h:376
Definition: xnandpsu.h:364
Definition: xnandpsu.h:354
Definition: xnandpsu.h:328
u8 NumBitsPerCell
Definition: xnandpsu.h:337
u32 NumTargetPages
Definition: xnandpsu.h:342
u8 NumLuns
Definition: xnandpsu.h:334
u32 BlocksPerLun
Definition: xnandpsu.h:333
u8 NumBitsECC
Definition: xnandpsu.h:338
u32 PagesPerBlock
Definition: xnandpsu.h:332
u32 EccCodeWordSize
Definition: xnandpsu.h:339
u64 DeviceSize
Definition: xnandpsu.h:348
u32 BlockSize
Definition: xnandpsu.h:341
u8 ColAddrCycles
Definition: xnandpsu.h:336
u64 TargetSize
Definition: xnandpsu.h:344
u32 NumBlocks
Definition: xnandpsu.h:347
u8 NumTargets
Definition: xnandpsu.h:345
u32 NumPages
Definition: xnandpsu.h:346
u32 NumTargetBlocks
Definition: xnandpsu.h:343
u16 SpareBytesPerPage
Definition: xnandpsu.h:331
u32 BytesPerPage
Definition: xnandpsu.h:330
u8 RowAddrCycles
Definition: xnandpsu.h:335
Definition: xnandpsu.h:393
XNandPsu_EccMode EccMode
Definition: xnandpsu.h:402
XNandPsu_Features Features
Definition: xnandpsu.h:405
XNandPsu_BadBlockPattern BbPattern
Definition: xnandpsu.h:418
XNandPsu_SWMode Mode
Definition: xnandpsu.h:400
XNandPsu_EccCfg EccCfg
Definition: xnandpsu.h:403
u32 Ecc_Stats_total_flips
Definition: xnandpsu.h:397
XNandPsu_BbtDesc BbtMirrorDesc
Definition: xnandpsu.h:417
XNandPsu_BbtDesc BbtDesc
Definition: xnandpsu.h:416
XNandPsu_Geometry Geometry
Definition: xnandpsu.h:404
XNandPsu_DmaMode DmaMode
Definition: xnandpsu.h:401
u32 IsReady
Definition: xnandpsu.h:394
u32 Ecc_Stat_PerPage_flips
Definition: xnandpsu.h:396
Definition: xnandpsu_onfi.h:185