xref: /rk3399_rockchip-uboot/drivers/mtd/nand/raw/mxc_nand.h (revision cfcc706c901d603707657919484e4f65467be9ff)
1*cfcc706cSMiquel Raynal /*
2*cfcc706cSMiquel Raynal  * (c) 2009 Magnus Lilja <lilja.magnus@gmail.com>
3*cfcc706cSMiquel Raynal  *
4*cfcc706cSMiquel Raynal  * SPDX-License-Identifier:	GPL-2.0+
5*cfcc706cSMiquel Raynal  */
6*cfcc706cSMiquel Raynal 
7*cfcc706cSMiquel Raynal #ifndef __MXC_NAND_H
8*cfcc706cSMiquel Raynal #define __MXC_NAND_H
9*cfcc706cSMiquel Raynal 
10*cfcc706cSMiquel Raynal /*
11*cfcc706cSMiquel Raynal  * Register map and bit definitions for the Freescale NAND Flash Controller
12*cfcc706cSMiquel Raynal  * present in various i.MX devices.
13*cfcc706cSMiquel Raynal  *
14*cfcc706cSMiquel Raynal  * MX31 and MX27 have version 1, which has:
15*cfcc706cSMiquel Raynal  *	4 512-byte main buffers and
16*cfcc706cSMiquel Raynal  *	4 16-byte spare buffers
17*cfcc706cSMiquel Raynal  *	to support up to 2K byte pagesize nand.
18*cfcc706cSMiquel Raynal  *	Reading or writing a 2K page requires 4 FDI/FDO cycles.
19*cfcc706cSMiquel Raynal  *
20*cfcc706cSMiquel Raynal  * MX25 and MX35 have version 2.1, and MX51 and MX53 have version 3.2, which
21*cfcc706cSMiquel Raynal  * have:
22*cfcc706cSMiquel Raynal  *	8 512-byte main buffers and
23*cfcc706cSMiquel Raynal  *	8 64-byte spare buffers
24*cfcc706cSMiquel Raynal  *	to support up to 4K byte pagesize nand.
25*cfcc706cSMiquel Raynal  *	Reading or writing a 2K or 4K page requires only 1 FDI/FDO cycle.
26*cfcc706cSMiquel Raynal  *	Also some of registers are moved and/or changed meaning as seen below.
27*cfcc706cSMiquel Raynal  */
28*cfcc706cSMiquel Raynal #if defined(CONFIG_MX27) || defined(CONFIG_MX31)
29*cfcc706cSMiquel Raynal #define MXC_NFC_V1
30*cfcc706cSMiquel Raynal #define is_mxc_nfc_1()		1
31*cfcc706cSMiquel Raynal #define is_mxc_nfc_21()		0
32*cfcc706cSMiquel Raynal #define is_mxc_nfc_32()		0
33*cfcc706cSMiquel Raynal #elif defined(CONFIG_MX25) || defined(CONFIG_MX35)
34*cfcc706cSMiquel Raynal #define MXC_NFC_V2_1
35*cfcc706cSMiquel Raynal #define is_mxc_nfc_1()		0
36*cfcc706cSMiquel Raynal #define is_mxc_nfc_21()		1
37*cfcc706cSMiquel Raynal #define is_mxc_nfc_32()		0
38*cfcc706cSMiquel Raynal #elif defined(CONFIG_MX51) || defined(CONFIG_MX53)
39*cfcc706cSMiquel Raynal #define MXC_NFC_V3
40*cfcc706cSMiquel Raynal #define MXC_NFC_V3_2
41*cfcc706cSMiquel Raynal #define is_mxc_nfc_1()		0
42*cfcc706cSMiquel Raynal #define is_mxc_nfc_21()		0
43*cfcc706cSMiquel Raynal #define is_mxc_nfc_32()		1
44*cfcc706cSMiquel Raynal #else
45*cfcc706cSMiquel Raynal #error "MXC NFC implementation not supported"
46*cfcc706cSMiquel Raynal #endif
47*cfcc706cSMiquel Raynal #define is_mxc_nfc_3()		is_mxc_nfc_32()
48*cfcc706cSMiquel Raynal 
49*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V1)
50*cfcc706cSMiquel Raynal #define NAND_MXC_NR_BUFS		4
51*cfcc706cSMiquel Raynal #define NAND_MXC_SPARE_BUF_SIZE		16
52*cfcc706cSMiquel Raynal #define NAND_MXC_REG_OFFSET		0xe00
53*cfcc706cSMiquel Raynal #define NAND_MXC_2K_MULTI_CYCLE
54*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V2_1) || defined(MXC_NFC_V3_2)
55*cfcc706cSMiquel Raynal #define NAND_MXC_NR_BUFS		8
56*cfcc706cSMiquel Raynal #define NAND_MXC_SPARE_BUF_SIZE		64
57*cfcc706cSMiquel Raynal #define NAND_MXC_REG_OFFSET		0x1e00
58*cfcc706cSMiquel Raynal #endif
59*cfcc706cSMiquel Raynal 
60*cfcc706cSMiquel Raynal struct mxc_nand_regs {
61*cfcc706cSMiquel Raynal 	u8 main_area[NAND_MXC_NR_BUFS][0x200];
62*cfcc706cSMiquel Raynal 	u8 spare_area[NAND_MXC_NR_BUFS][NAND_MXC_SPARE_BUF_SIZE];
63*cfcc706cSMiquel Raynal 	/*
64*cfcc706cSMiquel Raynal 	 * reserved size is offset of nfc registers
65*cfcc706cSMiquel Raynal 	 * minus total main and spare sizes
66*cfcc706cSMiquel Raynal 	 */
67*cfcc706cSMiquel Raynal 	u8 reserved1[NAND_MXC_REG_OFFSET
68*cfcc706cSMiquel Raynal 		- NAND_MXC_NR_BUFS * (512 + NAND_MXC_SPARE_BUF_SIZE)];
69*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V1)
70*cfcc706cSMiquel Raynal 	u16 buf_size;
71*cfcc706cSMiquel Raynal 	u16 reserved2;
72*cfcc706cSMiquel Raynal 	u16 buf_addr;
73*cfcc706cSMiquel Raynal 	u16 flash_addr;
74*cfcc706cSMiquel Raynal 	u16 flash_cmd;
75*cfcc706cSMiquel Raynal 	u16 config;
76*cfcc706cSMiquel Raynal 	u16 ecc_status_result;
77*cfcc706cSMiquel Raynal 	u16 rsltmain_area;
78*cfcc706cSMiquel Raynal 	u16 rsltspare_area;
79*cfcc706cSMiquel Raynal 	u16 wrprot;
80*cfcc706cSMiquel Raynal 	u16 unlockstart_blkaddr;
81*cfcc706cSMiquel Raynal 	u16 unlockend_blkaddr;
82*cfcc706cSMiquel Raynal 	u16 nf_wrprst;
83*cfcc706cSMiquel Raynal 	u16 config1;
84*cfcc706cSMiquel Raynal 	u16 config2;
85*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V2_1)
86*cfcc706cSMiquel Raynal 	u16 reserved2[2];
87*cfcc706cSMiquel Raynal 	u16 buf_addr;
88*cfcc706cSMiquel Raynal 	u16 flash_addr;
89*cfcc706cSMiquel Raynal 	u16 flash_cmd;
90*cfcc706cSMiquel Raynal 	u16 config;
91*cfcc706cSMiquel Raynal 	u32 ecc_status_result;
92*cfcc706cSMiquel Raynal 	u16 spare_area_size;
93*cfcc706cSMiquel Raynal 	u16 wrprot;
94*cfcc706cSMiquel Raynal 	u16 reserved3[2];
95*cfcc706cSMiquel Raynal 	u16 nf_wrprst;
96*cfcc706cSMiquel Raynal 	u16 config1;
97*cfcc706cSMiquel Raynal 	u16 config2;
98*cfcc706cSMiquel Raynal 	u16 reserved4;
99*cfcc706cSMiquel Raynal 	u16 unlockstart_blkaddr;
100*cfcc706cSMiquel Raynal 	u16 unlockend_blkaddr;
101*cfcc706cSMiquel Raynal 	u16 unlockstart_blkaddr1;
102*cfcc706cSMiquel Raynal 	u16 unlockend_blkaddr1;
103*cfcc706cSMiquel Raynal 	u16 unlockstart_blkaddr2;
104*cfcc706cSMiquel Raynal 	u16 unlockend_blkaddr2;
105*cfcc706cSMiquel Raynal 	u16 unlockstart_blkaddr3;
106*cfcc706cSMiquel Raynal 	u16 unlockend_blkaddr3;
107*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V3_2)
108*cfcc706cSMiquel Raynal 	u32 flash_cmd;
109*cfcc706cSMiquel Raynal 	u32 flash_addr[12];
110*cfcc706cSMiquel Raynal 	u32 config1;
111*cfcc706cSMiquel Raynal 	u32 ecc_status_result;
112*cfcc706cSMiquel Raynal 	u32 status_sum;
113*cfcc706cSMiquel Raynal 	u32 launch;
114*cfcc706cSMiquel Raynal #endif
115*cfcc706cSMiquel Raynal };
116*cfcc706cSMiquel Raynal 
117*cfcc706cSMiquel Raynal #ifdef MXC_NFC_V3_2
118*cfcc706cSMiquel Raynal struct mxc_nand_ip_regs {
119*cfcc706cSMiquel Raynal 	u32 wrprot;
120*cfcc706cSMiquel Raynal 	u32 wrprot_unlock_blkaddr[8];
121*cfcc706cSMiquel Raynal 	u32 config2;
122*cfcc706cSMiquel Raynal 	u32 config3;
123*cfcc706cSMiquel Raynal 	u32 ipc;
124*cfcc706cSMiquel Raynal 	u32 err_addr;
125*cfcc706cSMiquel Raynal 	u32 delay_line;
126*cfcc706cSMiquel Raynal };
127*cfcc706cSMiquel Raynal #endif
128*cfcc706cSMiquel Raynal 
129*cfcc706cSMiquel Raynal /* Set FCMD to 1, rest to 0 for Command operation */
130*cfcc706cSMiquel Raynal #define NFC_CMD				0x1
131*cfcc706cSMiquel Raynal 
132*cfcc706cSMiquel Raynal /* Set FADD to 1, rest to 0 for Address operation */
133*cfcc706cSMiquel Raynal #define NFC_ADDR			0x2
134*cfcc706cSMiquel Raynal 
135*cfcc706cSMiquel Raynal /* Set FDI to 1, rest to 0 for Input operation */
136*cfcc706cSMiquel Raynal #define NFC_INPUT			0x4
137*cfcc706cSMiquel Raynal 
138*cfcc706cSMiquel Raynal /* Set FDO to 001, rest to 0 for Data Output operation */
139*cfcc706cSMiquel Raynal #define NFC_OUTPUT			0x8
140*cfcc706cSMiquel Raynal 
141*cfcc706cSMiquel Raynal /* Set FDO to 010, rest to 0 for Read ID operation */
142*cfcc706cSMiquel Raynal #define NFC_ID				0x10
143*cfcc706cSMiquel Raynal 
144*cfcc706cSMiquel Raynal /* Set FDO to 100, rest to 0 for Read Status operation */
145*cfcc706cSMiquel Raynal #define NFC_STATUS			0x20
146*cfcc706cSMiquel Raynal 
147*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
148*cfcc706cSMiquel Raynal #define NFC_CONFIG1_SP_EN		(1 << 2)
149*cfcc706cSMiquel Raynal #define NFC_CONFIG1_RST			(1 << 6)
150*cfcc706cSMiquel Raynal #define NFC_CONFIG1_CE			(1 << 7)
151*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V3_2)
152*cfcc706cSMiquel Raynal #define NFC_CONFIG1_SP_EN		(1 << 0)
153*cfcc706cSMiquel Raynal #define NFC_CONFIG1_CE			(1 << 1)
154*cfcc706cSMiquel Raynal #define NFC_CONFIG1_RST			(1 << 2)
155*cfcc706cSMiquel Raynal #endif
156*cfcc706cSMiquel Raynal #define NFC_V1_V2_CONFIG1_ECC_EN	(1 << 3)
157*cfcc706cSMiquel Raynal #define NFC_V1_V2_CONFIG1_INT_MSK	(1 << 4)
158*cfcc706cSMiquel Raynal #define NFC_V1_V2_CONFIG1_BIG		(1 << 5)
159*cfcc706cSMiquel Raynal #define NFC_V2_CONFIG1_ECC_MODE_4	(1 << 0)
160*cfcc706cSMiquel Raynal #define NFC_V2_CONFIG1_ONE_CYCLE	(1 << 8)
161*cfcc706cSMiquel Raynal #define NFC_V2_CONFIG1_FP_INT		(1 << 11)
162*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG1_RBA_MASK		(0x7 << 4)
163*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG1_RBA(x)		(((x) & 0x7) << 4)
164*cfcc706cSMiquel Raynal 
165*cfcc706cSMiquel Raynal #define NFC_V1_V2_CONFIG2_INT		(1 << 15)
166*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_PS_MASK		(0x3 << 0)
167*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_PS_512		(0 << 0)
168*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_PS_2048		(1 << 0)
169*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_PS_4096		(2 << 0)
170*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_ONE_CYCLE	(1 << 2)
171*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_ECC_EN		(1 << 3)
172*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_2CMD_PHASES	(1 << 4)
173*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_NUM_ADDR_PH0	(1 << 5)
174*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_ECC_MODE_8	(1 << 6)
175*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_PPB_MASK		(0x3 << 7)
176*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_PPB(x)		(((x) & 0x3) << 7)
177*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_EDC_MASK		(0x7 << 9)
178*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_EDC(x)		(((x) & 0x7) << 9)
179*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_NUM_ADDR_PH1(x)	(((x) & 0x3) << 12)
180*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_INT_MSK		(1 << 15)
181*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_SPAS_MASK	(0xff << 16)
182*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_SPAS(x)		(((x) & 0xff) << 16)
183*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_ST_CMD_MASK	(0xff << 24)
184*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG2_ST_CMD(x)	(((x) & 0xff) << 24)
185*cfcc706cSMiquel Raynal 
186*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG3_ADD_OP(x)	(((x) & 0x3) << 0)
187*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG3_FW8		(1 << 3)
188*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG3_SBB(x)		(((x) & 0x7) << 8)
189*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG3_NUM_OF_DEVS(x)	(((x) & 0x7) << 12)
190*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG3_RBB_MODE		(1 << 15)
191*cfcc706cSMiquel Raynal #define NFC_V3_CONFIG3_NO_SDMA		(1 << 20)
192*cfcc706cSMiquel Raynal 
193*cfcc706cSMiquel Raynal #define NFC_V3_WRPROT_UNLOCK		(1 << 2)
194*cfcc706cSMiquel Raynal #define NFC_V3_WRPROT_BLS_UNLOCK	(2 << 6)
195*cfcc706cSMiquel Raynal 
196*cfcc706cSMiquel Raynal #define NFC_V3_IPC_CREQ			(1 << 0)
197*cfcc706cSMiquel Raynal #define NFC_V3_IPC_INT			(1 << 31)
198*cfcc706cSMiquel Raynal 
199*cfcc706cSMiquel Raynal #if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
200*cfcc706cSMiquel Raynal #define operation	config2
201*cfcc706cSMiquel Raynal #define readnfc		readw
202*cfcc706cSMiquel Raynal #define writenfc	writew
203*cfcc706cSMiquel Raynal #elif defined(MXC_NFC_V3_2)
204*cfcc706cSMiquel Raynal #define operation	launch
205*cfcc706cSMiquel Raynal #define readnfc		readl
206*cfcc706cSMiquel Raynal #define writenfc	writel
207*cfcc706cSMiquel Raynal #endif
208*cfcc706cSMiquel Raynal 
209*cfcc706cSMiquel Raynal #endif /* __MXC_NAND_H */
210