blob: 30f2ed78f8b925161d44b468ef3b2b32be39d28c [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * Linux driver for NAND NV Flash Translation Layer
3 * Copyright (C) 2016, ZIXC Corporation.
4 */
5
6
7#ifndef __MTD_NV_FTL_H__
8#define __MTD_NV_FTL_H__
9
10#include <linux/mtd/mtd.h>
11#include <linux/mtd/zftl_ecc.h>
12
13
14
15/* error define */
16#define CAN_NOT_FIND_FREE_BLOCK 5 /* ÕÒ²»µ½¿ÕÏп飬½¨ÒéÔö¼ÓZFTL·ÖÇøµÄ´óС */
17#define NAND_READ_WRITE_ERROR 6
18
19/*
20 * zftl partition
21 */
22
23
24/* these info are used in blockRepTable */
25#define BLOCK_NIL 0xFFFF /* ´Ë¿éûÓÐÓ³Éä¹ØÏµ */
26
27
28/* these info are used in BlockTable */
29#define BLOCK_FREE 0x00
30#define BLOCK_USED 0x55
31#define BLOCK_BAD 0xAA
32#define BLOCK_DIRTY 0x11
33
34
35struct ZFTLrecord {
36 nand_info_t *nand;
37 unsigned char *blockbuf; /* ¿é»º´æ */
38 unsigned char *oobbuf; /* OOB»º´æ */
39 unsigned char *blockTable;
40 unsigned short *blockRepTable;
41 unsigned short *versionTable; /* Ö»ÓÃÔÚ¿ª»ú¹ÒÔØµÄʱºò */
42 uint32_t erasesize;
43 uint32_t writesize;
44 unsigned int erasesize_shift;
45 unsigned int writesize_shift;
46 uint32_t oobsize;
47 uint32_t firstBlock; /* µÚÒ»¿éµÄ¿éºÅ */
48 uint32_t numBlocks; /* ×ܵĿéÊý */
49 uint32_t lastFreeBlock;
50};
51
52struct zftl_oob {
53 __u8 head[CONFIG_ZFLT_HEAD_BYTE]; /* zftlÍ· */
54 __u8 used;
55 __u8 version;
56 __u16 logicBlockID; /* ·ÖÇøÄ򵀮«ÒÆ¿éºÅ */
57}__attribute__((packed));
58
59
60
61
62struct zftl_packed_tags {
63 struct zftl_oob t;
64 struct zftl_ecc_other ecc;
65};
66
67
68void * zftl_get_ZFTLrecord(uint32_t offset);
69int zftl_write(struct ZFTLrecord *zftl, uint32_t to, uint32_t len, u_char *buf);
70int zftl_read(struct ZFTLrecord *zftl, uint32_t from, uint32_t len, u_char *buffer);
71
72#endif /* __MTD_NFTL_H__ */