blob: a41ff9f5b8776e2cab5f3a2173f70b391d34309e [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001
2#ifndef _SPI_NAND_H
3#define _SPI_NAND_H
4
5#include "Typedef.h"
6#include "Flash.h"
7#include "predefines.h"
8#include "spi_flash.h"
9
10/* feature registers */
11#define REG_BLOCK_LOCK 0xa0
12#define REG_CFG 0xb0
13#define REG_STATUS 0xc0
14#define REG_DIE_SELECT 0xd0
15
16/*Configuration register defines*/
17#define CFG_QE_MASK 0x01
18#define CFG_QE_ENABLE 0x01
19#define CFG_ECC_MASK 0X10
20#define CFG_ECC_ENABLE 0x10
21#define CFG_LOT_MASK 0x20
22#define CFG_LOT_ENABLE 0x20
23#define CFG_OTP_MASK 0xc2
24#define CFG_OTP_ENTER 0x40
25#define CFG_OTP_EXIT 0x00
26#define CFG_OTP_PROTECT 0xc0
27#define CFG_SNOR_ENABLE 0x82
28
29/* block lock */
30#define BL_ALL_LOCKED 0x7c
31#define BL_U_1_1024_LOCKED 0x08
32#define BL_U_1_512_LOCKED 0x10
33#define BL_U_1_256_LOCKED 0x18
34#define BL_U_1_128_LOCKED 0x20
35#define BL_U_1_64_LOCKED 0x28
36#define BL_U_1_32_LOCKED 0x30
37#define BL_U_1_16_LOCKED 0x38
38#define BL_U_1_8_LOCKED 0x40
39#define BL_U_1_4_LOCKED 0x48
40#define BL_U_1_2_LOCKED 0x50
41#define BL_L_1_1024_LOCKED 0x0c
42#define BL_L_1_512_LOCKED 0x14
43#define BL_L_1_256_LOCKED 0x1c
44#define BL_L_1_128_LOCKED 0x24
45#define BL_L_1_64_LOCKED 0x2c
46#define BL_L_1_32_LOCKED 0x34
47#define BL_L_1_16_LOCKED 0x3c
48#define BL_L_1_8_LOCKED 0x44
49#define BL_L_1_4_LOCKED 0x4c
50#define BL_L_1_2_LOCKED 0x54
51#define BL_ALL_UNLOCKED 0X00
52
53#define SPI_NAND_ECC_SHIFT 4
54#define SPI_NAND_ECC_MASK 0x30
55#define SPI_NAND_ECC_0_BIT 0x0
56#define SPI_NAND_ECC_1_3_BIT 0x1
57#define SPI_NAND_ECC_4_6_BIT 0x3
58#define SPI_NAND_ECC_UNCORR 0x2
59
60/*SPI NAND chip options*/
61#define SPINAND_NEED_PLANE_SELECT (1 << 0)
62#define SPINAND_NEED_DIE_SELECT (1 << 1)
63#define SPINAND_SUPPORT_DTR (1 << 2)
64
65/*
66 * If PROGRAM LOAD RANDOM DATA cmd only valid during Internal Data Move,
67 * need to send Page Read command to cache first.
68 */
69#define SPINAND_RDM_CMD_NEED_PAGE_READ (1 << 5)
70#define SPINAND_ECC_EN_ADDR_90H (1 << 6)
71#define SPINAND_NEED_SET_BFT (1 << 7)
72
73#define SPINAND_MAX_ID_LEN 4
74
75struct spi_nand_info {
76 char *name;
77 uint8_t mfr_id;
78 uint16_t dev_id;
79 uint32_t page_size;
80 uint32_t oob_size;
81 uint32_t pages_per_blk;
82 uint32_t blks_per_lun;
83 uint32_t luns_per_chip;
84 uint32_t ecc_strength;
85 uint32_t options;
86 uint32_t max_mhz;
87 uint8_t quad_cmd_index;
88 uint8_t quad_cmd_dtr_index;
89 uint32_t bitflip_threshold;
90 uint32_t tclqv; /* in nanosecond*/
91 uint32_t tset; /* in nanosecond*/
92 uint32_t thold; /* in nanosecond*/
93 void (*get_ecc_status)(struct spi_flash_chip *chip, uint8_t status,
94 uint32_t *corrected, uint32_t *ecc_error);
95};
96
97#define SPI_NAND_INFO_DTR(nm, mid, did, pagesz, oobsz, pg_per_blk,\
98 blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \
99 _tclqv, _tset, _thold, _max_mhz, _cmd_index, _dtr_index, _get_ecc_status) \
100 { .name = (nm), .mfr_id = (mid), .dev_id = (did),\
101 .page_size = (pagesz), .oob_size = (oobsz),\
102 .pages_per_blk = (pg_per_blk), .blks_per_lun = (blk_per_lun),\
103 .luns_per_chip = (lun_per_chip), \
104 .ecc_strength = (ecc_stren), .options = (opts),\
105 .bitflip_threshold = (_bitflip_threshold), \
106 .tclqv = (_tclqv), \
107 .tset = (_tset), \
108 .thold = (_thold), \
109 .max_mhz = (_max_mhz), \
110 .quad_cmd_index = (_cmd_index), \
111 .quad_cmd_dtr_index = _dtr_index, \
112 .get_ecc_status = (_get_ecc_status), }
113
114#define SPI_NAND_INFO(nm, mid, did, pagesz, oobsz, pg_per_blk,\
115 blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \
116 _max_mhz, _cmd_index, _get_ecc_status) \
117 SPI_NAND_INFO_DTR(nm, mid, did, pagesz, oobsz, pg_per_blk,\
118 blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \
119 0, 0, 0, _max_mhz, _cmd_index, 0, _get_ecc_status)
120
121#define SPI_NAND_INFO_TIMING(nm, mid, did, pagesz, oobsz, pg_per_blk,\
122 blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \
123 _tclqv, _tset, _thold, _max_mhz, _cmd_index, _get_ecc_status) \
124 SPI_NAND_INFO_DTR(nm, mid, did, pagesz, oobsz, pg_per_blk,\
125 blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \
126 _tclqv, _tset, _thold, _max_mhz, _cmd_index, 0, _get_ecc_status)
127
128/**
129 * struct mtd_oob_ops - oob operation operands
130 * @mode: operation mode
131 * @len: number of data bytes to write/read
132 * @retlen: number of data bytes written/read
133 * @ooblen: number of oob bytes to write/read
134 * @oobretlen: number of oob bytes written/read
135 * @ooboffs: offset of oob data in the oob area (only relevant when
136 * mode = MTD_OPS_PLACE_OOB or MTD_OPS_RAW)
137 * @datbuf: data buffer - if NULL only oob data are read/written
138 * @oobbuf: oob data buffer
139 *
140 * Note, it is allowed to read more than one OOB area at one go, but not write.
141 * The interface assumes that the OOB write requests program only one page's
142 * OOB area.
143 */
144//struct mtd_oob_ops {
145// unsigned int mode;
146// uint32_t len;
147// uint32_t retlen;
148// uint32_t ooblen;
149// uint32_t oobretlen;
150// uint32_t ooboffs;
151// uint8_t *datbuf;
152// uint8_t *oobbuf;
153//};
154
155//enum {
156// NORMAL_MODE,
157// OTP_MODE,
158// OTP_PROTECT_MODE,
159// SNOR_READ_ENABLE_MODE,
160//};
161
162struct spi_flash_chip *spi_nand_init(struct qspi_host *host, int cs,
163 int rx_mode, int tx_mode);
164UINT_T InitializeQSPINAND(UINT8_T FlashNum, FlashBootType_T FlashBootType,
165 UINT8_T* P_DefaultPartitionNum);
166
167#endif