xref: /rk3399_rockchip-uboot/drivers/mtd/nand/raw/atmel_nand_ecc.h (revision cfcc706c901d603707657919484e4f65467be9ff)
1*cfcc706cSMiquel Raynal /*
2*cfcc706cSMiquel Raynal  * Error Corrected Code Controller (ECC) - System peripherals regsters.
3*cfcc706cSMiquel Raynal  * Based on AT91SAM9260 datasheet revision B.
4*cfcc706cSMiquel Raynal  *
5*cfcc706cSMiquel Raynal  * SPDX-License-Identifier:	GPL-2.0+
6*cfcc706cSMiquel Raynal  */
7*cfcc706cSMiquel Raynal 
8*cfcc706cSMiquel Raynal #ifndef ATMEL_NAND_ECC_H
9*cfcc706cSMiquel Raynal #define ATMEL_NAND_ECC_H
10*cfcc706cSMiquel Raynal 
11*cfcc706cSMiquel Raynal #define ATMEL_ECC_CR		0x00			/* Control register */
12*cfcc706cSMiquel Raynal #define		ATMEL_ECC_RST		(1 << 0)		/* Reset parity */
13*cfcc706cSMiquel Raynal 
14*cfcc706cSMiquel Raynal #define ATMEL_ECC_MR		0x04			/* Mode register */
15*cfcc706cSMiquel Raynal #define		ATMEL_ECC_PAGESIZE	(3 << 0)		/* Page Size */
16*cfcc706cSMiquel Raynal #define			ATMEL_ECC_PAGESIZE_528		(0)
17*cfcc706cSMiquel Raynal #define			ATMEL_ECC_PAGESIZE_1056		(1)
18*cfcc706cSMiquel Raynal #define			ATMEL_ECC_PAGESIZE_2112		(2)
19*cfcc706cSMiquel Raynal #define			ATMEL_ECC_PAGESIZE_4224		(3)
20*cfcc706cSMiquel Raynal 
21*cfcc706cSMiquel Raynal #define ATMEL_ECC_SR		0x08			/* Status register */
22*cfcc706cSMiquel Raynal #define		ATMEL_ECC_RECERR		(1 << 0)		/* Recoverable Error */
23*cfcc706cSMiquel Raynal #define		ATMEL_ECC_ECCERR		(1 << 1)		/* ECC Single Bit Error */
24*cfcc706cSMiquel Raynal #define		ATMEL_ECC_MULERR		(1 << 2)		/* Multiple Errors */
25*cfcc706cSMiquel Raynal 
26*cfcc706cSMiquel Raynal #define ATMEL_ECC_PR		0x0c			/* Parity register */
27*cfcc706cSMiquel Raynal #define		ATMEL_ECC_BITADDR	(0xf << 0)		/* Bit Error Address */
28*cfcc706cSMiquel Raynal #define		ATMEL_ECC_WORDADDR	(0xfff << 4)		/* Word Error Address */
29*cfcc706cSMiquel Raynal 
30*cfcc706cSMiquel Raynal #define ATMEL_ECC_NPR		0x10			/* NParity register */
31*cfcc706cSMiquel Raynal #define		ATMEL_ECC_NPARITY	(0xffff << 0)		/* NParity */
32*cfcc706cSMiquel Raynal 
33*cfcc706cSMiquel Raynal /* Register access macros for PMECC */
34*cfcc706cSMiquel Raynal #define pmecc_readl(addr, reg) \
35*cfcc706cSMiquel Raynal 	readl(&addr->reg)
36*cfcc706cSMiquel Raynal 
37*cfcc706cSMiquel Raynal #define pmecc_readb(addr, reg) \
38*cfcc706cSMiquel Raynal 	readb(&addr->reg)
39*cfcc706cSMiquel Raynal 
40*cfcc706cSMiquel Raynal #define pmecc_writel(addr, reg, value) \
41*cfcc706cSMiquel Raynal 	writel((value), &addr->reg)
42*cfcc706cSMiquel Raynal 
43*cfcc706cSMiquel Raynal /* PMECC Register Definitions */
44*cfcc706cSMiquel Raynal #define PMECC_MAX_SECTOR_NUM			8
45*cfcc706cSMiquel Raynal struct pmecc_regs {
46*cfcc706cSMiquel Raynal 	u32 cfg;		/* 0x00 PMECC Configuration Register */
47*cfcc706cSMiquel Raynal 	u32 sarea;		/* 0x04 PMECC Spare Area Size Register */
48*cfcc706cSMiquel Raynal 	u32 saddr;		/* 0x08 PMECC Start Address Register */
49*cfcc706cSMiquel Raynal 	u32 eaddr;		/* 0x0C PMECC End Address Register */
50*cfcc706cSMiquel Raynal 	u32 clk;		/* 0x10 PMECC Clock Control Register */
51*cfcc706cSMiquel Raynal 	u32 ctrl;		/* 0x14 PMECC Control Register */
52*cfcc706cSMiquel Raynal 	u32 sr;			/* 0x18 PMECC Status Register */
53*cfcc706cSMiquel Raynal 	u32 ier;		/* 0x1C PMECC Interrupt Enable Register */
54*cfcc706cSMiquel Raynal 	u32 idr;		/* 0x20 PMECC Interrupt Disable Register */
55*cfcc706cSMiquel Raynal 	u32 imr;		/* 0x24 PMECC Interrupt Mask Register */
56*cfcc706cSMiquel Raynal 	u32 isr;		/* 0x28 PMECC Interrupt Status Register */
57*cfcc706cSMiquel Raynal 	u32 reserved0[5];	/* 0x2C-0x3C Reserved */
58*cfcc706cSMiquel Raynal 
59*cfcc706cSMiquel Raynal 	/* 0x40 + sector_num * (0x40), Redundancy Registers */
60*cfcc706cSMiquel Raynal 	struct {
61*cfcc706cSMiquel Raynal #ifdef CONFIG_SAMA5D2
62*cfcc706cSMiquel Raynal 		u8 ecc[56];	/* PMECC Generated Redundancy Byte Per Sector */
63*cfcc706cSMiquel Raynal 		u32 reserved1[2];
64*cfcc706cSMiquel Raynal #else
65*cfcc706cSMiquel Raynal 		u8 ecc[44];	/* PMECC Generated Redundancy Byte Per Sector */
66*cfcc706cSMiquel Raynal 		u32 reserved1[5];
67*cfcc706cSMiquel Raynal #endif
68*cfcc706cSMiquel Raynal 	} ecc_port[PMECC_MAX_SECTOR_NUM];
69*cfcc706cSMiquel Raynal 
70*cfcc706cSMiquel Raynal 	/* 0x240 + sector_num * (0x40) Remainder Registers */
71*cfcc706cSMiquel Raynal 	struct {
72*cfcc706cSMiquel Raynal #ifdef CONFIG_SAMA5D2
73*cfcc706cSMiquel Raynal 		u32 rem[16];
74*cfcc706cSMiquel Raynal #else
75*cfcc706cSMiquel Raynal 		u32 rem[12];
76*cfcc706cSMiquel Raynal 		u32 reserved2[4];
77*cfcc706cSMiquel Raynal #endif
78*cfcc706cSMiquel Raynal 	} rem_port[PMECC_MAX_SECTOR_NUM];
79*cfcc706cSMiquel Raynal 	u32 reserved3[16];	/* 0x440-0x47C Reserved */
80*cfcc706cSMiquel Raynal };
81*cfcc706cSMiquel Raynal 
82*cfcc706cSMiquel Raynal /* For PMECC Configuration Register */
83*cfcc706cSMiquel Raynal #define		PMECC_CFG_BCH_ERR2		(0 << 0)
84*cfcc706cSMiquel Raynal #define		PMECC_CFG_BCH_ERR4		(1 << 0)
85*cfcc706cSMiquel Raynal #define		PMECC_CFG_BCH_ERR8		(2 << 0)
86*cfcc706cSMiquel Raynal #define		PMECC_CFG_BCH_ERR12		(3 << 0)
87*cfcc706cSMiquel Raynal #define		PMECC_CFG_BCH_ERR24		(4 << 0)
88*cfcc706cSMiquel Raynal #define		PMECC_CFG_BCH_ERR32		(5 << 0)
89*cfcc706cSMiquel Raynal 
90*cfcc706cSMiquel Raynal #define		PMECC_CFG_SECTOR512		(0 << 4)
91*cfcc706cSMiquel Raynal #define		PMECC_CFG_SECTOR1024		(1 << 4)
92*cfcc706cSMiquel Raynal 
93*cfcc706cSMiquel Raynal #define		PMECC_CFG_PAGE_1SECTOR		(0 << 8)
94*cfcc706cSMiquel Raynal #define		PMECC_CFG_PAGE_2SECTORS		(1 << 8)
95*cfcc706cSMiquel Raynal #define		PMECC_CFG_PAGE_4SECTORS		(2 << 8)
96*cfcc706cSMiquel Raynal #define		PMECC_CFG_PAGE_8SECTORS		(3 << 8)
97*cfcc706cSMiquel Raynal 
98*cfcc706cSMiquel Raynal #define		PMECC_CFG_READ_OP		(0 << 12)
99*cfcc706cSMiquel Raynal #define		PMECC_CFG_WRITE_OP		(1 << 12)
100*cfcc706cSMiquel Raynal 
101*cfcc706cSMiquel Raynal #define		PMECC_CFG_SPARE_ENABLE		(1 << 16)
102*cfcc706cSMiquel Raynal #define		PMECC_CFG_SPARE_DISABLE		(0 << 16)
103*cfcc706cSMiquel Raynal 
104*cfcc706cSMiquel Raynal #define		PMECC_CFG_AUTO_ENABLE		(1 << 20)
105*cfcc706cSMiquel Raynal #define		PMECC_CFG_AUTO_DISABLE		(0 << 20)
106*cfcc706cSMiquel Raynal 
107*cfcc706cSMiquel Raynal /* For PMECC Clock Control Register */
108*cfcc706cSMiquel Raynal #define		PMECC_CLK_133MHZ		(2 << 0)
109*cfcc706cSMiquel Raynal 
110*cfcc706cSMiquel Raynal /* For PMECC Control Register */
111*cfcc706cSMiquel Raynal #define		PMECC_CTRL_RST			(1 << 0)
112*cfcc706cSMiquel Raynal #define		PMECC_CTRL_DATA			(1 << 1)
113*cfcc706cSMiquel Raynal #define		PMECC_CTRL_USER			(1 << 2)
114*cfcc706cSMiquel Raynal #define		PMECC_CTRL_ENABLE		(1 << 4)
115*cfcc706cSMiquel Raynal #define		PMECC_CTRL_DISABLE		(1 << 5)
116*cfcc706cSMiquel Raynal 
117*cfcc706cSMiquel Raynal /* For PMECC Status Register */
118*cfcc706cSMiquel Raynal #define		PMECC_SR_BUSY			(1 << 0)
119*cfcc706cSMiquel Raynal #define		PMECC_SR_ENABLE			(1 << 4)
120*cfcc706cSMiquel Raynal 
121*cfcc706cSMiquel Raynal /* PMERRLOC Register Definitions */
122*cfcc706cSMiquel Raynal struct pmecc_errloc_regs {
123*cfcc706cSMiquel Raynal 	u32 elcfg;	/* 0x00 Error Location Configuration Register */
124*cfcc706cSMiquel Raynal 	u32 elprim;	/* 0x04 Error Location Primitive Register */
125*cfcc706cSMiquel Raynal 	u32 elen;	/* 0x08 Error Location Enable Register */
126*cfcc706cSMiquel Raynal 	u32 eldis;	/* 0x0C Error Location Disable Register */
127*cfcc706cSMiquel Raynal 	u32 elsr;	/* 0x10 Error Location Status Register */
128*cfcc706cSMiquel Raynal 	u32 elier;	/* 0x14 Error Location Interrupt Enable Register */
129*cfcc706cSMiquel Raynal 	u32 elidr;	/* 0x08 Error Location Interrupt Disable Register */
130*cfcc706cSMiquel Raynal 	u32 elimr;	/* 0x0C Error Location Interrupt Mask Register */
131*cfcc706cSMiquel Raynal 	u32 elisr;	/* 0x20 Error Location Interrupt Status Register */
132*cfcc706cSMiquel Raynal 	u32 reserved0;	/* 0x24 Reserved */
133*cfcc706cSMiquel Raynal #ifdef CONFIG_SAMA5D2
134*cfcc706cSMiquel Raynal 	u32 sigma[33];	/* 0x28-0xA8 Error Location Sigma Registers */
135*cfcc706cSMiquel Raynal 	u32 el[32];	/* 0xAC-0x128 Error Location Registers */
136*cfcc706cSMiquel Raynal 
137*cfcc706cSMiquel Raynal 	/*
138*cfcc706cSMiquel Raynal 	 * 0x12C-0x1FC:
139*cfcc706cSMiquel Raynal 	 *   Reserved for SAMA5D2.
140*cfcc706cSMiquel Raynal 	 */
141*cfcc706cSMiquel Raynal 	u32 reserved1[53];
142*cfcc706cSMiquel Raynal #else
143*cfcc706cSMiquel Raynal 	u32 sigma[25];	/* 0x28-0x88 Error Location Sigma Registers */
144*cfcc706cSMiquel Raynal 	u32 el[24];	/* 0x8C-0xE8 Error Location Registers */
145*cfcc706cSMiquel Raynal 	u32 reserved1[5];	/* 0xEC-0xFC Reserved */
146*cfcc706cSMiquel Raynal #endif
147*cfcc706cSMiquel Raynal 
148*cfcc706cSMiquel Raynal 	/*
149*cfcc706cSMiquel Raynal 	 * SAMA5 chip HSMC registers start here. But for 9X5 chip it is just
150*cfcc706cSMiquel Raynal 	 * reserved.
151*cfcc706cSMiquel Raynal 	 *
152*cfcc706cSMiquel Raynal 	 * Offset 0x00-0xF8:
153*cfcc706cSMiquel Raynal 	 */
154*cfcc706cSMiquel Raynal 	u32 reserved2[63];
155*cfcc706cSMiquel Raynal 
156*cfcc706cSMiquel Raynal 	/*
157*cfcc706cSMiquel Raynal 	 * Offset 0xFC:
158*cfcc706cSMiquel Raynal 	 *   PMECC version for AT91SAM9X5, AT91SAM9N12.
159*cfcc706cSMiquel Raynal 	 *   HSMC version for SAMA5D3, SAMA5D4. Can refer as PMECC version.
160*cfcc706cSMiquel Raynal 	 */
161*cfcc706cSMiquel Raynal 	u32 version;
162*cfcc706cSMiquel Raynal };
163*cfcc706cSMiquel Raynal 
164*cfcc706cSMiquel Raynal /* For Error Location Configuration Register */
165*cfcc706cSMiquel Raynal #define		PMERRLOC_ELCFG_SECTOR_512	(0 << 0)
166*cfcc706cSMiquel Raynal #define		PMERRLOC_ELCFG_SECTOR_1024	(1 << 0)
167*cfcc706cSMiquel Raynal #define		PMERRLOC_ELCFG_NUM_ERRORS(n)	((n) << 16)
168*cfcc706cSMiquel Raynal 
169*cfcc706cSMiquel Raynal /* For Error Location Disable Register */
170*cfcc706cSMiquel Raynal #define		PMERRLOC_DISABLE		(1 << 0)
171*cfcc706cSMiquel Raynal 
172*cfcc706cSMiquel Raynal /* For Error Location Interrupt Status Register */
173*cfcc706cSMiquel Raynal #ifdef CONFIG_SAMA5D2
174*cfcc706cSMiquel Raynal #define		PMERRLOC_ERR_NUM_MASK		(0x3f << 8)
175*cfcc706cSMiquel Raynal #else
176*cfcc706cSMiquel Raynal #define		PMERRLOC_ERR_NUM_MASK		(0x1f << 8)
177*cfcc706cSMiquel Raynal #endif
178*cfcc706cSMiquel Raynal 
179*cfcc706cSMiquel Raynal #define		PMERRLOC_CALC_DONE		(1 << 0)
180*cfcc706cSMiquel Raynal 
181*cfcc706cSMiquel Raynal /* PMECC IP version */
182*cfcc706cSMiquel Raynal #define PMECC_VERSION_SAMA5D2			0x210
183*cfcc706cSMiquel Raynal #define PMECC_VERSION_SAMA5D4			0x113
184*cfcc706cSMiquel Raynal #define PMECC_VERSION_SAMA5D3			0x112
185*cfcc706cSMiquel Raynal #define PMECC_VERSION_AT91SAM9N12		0x102
186*cfcc706cSMiquel Raynal #define PMECC_VERSION_AT91SAM9X5		0x101
187*cfcc706cSMiquel Raynal 
188*cfcc706cSMiquel Raynal /* Galois field dimension */
189*cfcc706cSMiquel Raynal #define PMECC_GF_DIMENSION_13			13
190*cfcc706cSMiquel Raynal #define PMECC_GF_DIMENSION_14			14
191*cfcc706cSMiquel Raynal 
192*cfcc706cSMiquel Raynal /* Primitive Polynomial used by PMECC */
193*cfcc706cSMiquel Raynal #define PMECC_GF_13_PRIMITIVE_POLY		0x201b
194*cfcc706cSMiquel Raynal #define PMECC_GF_14_PRIMITIVE_POLY		0x4443
195*cfcc706cSMiquel Raynal 
196*cfcc706cSMiquel Raynal #define PMECC_INDEX_TABLE_SIZE_512		0x2000
197*cfcc706cSMiquel Raynal #define PMECC_INDEX_TABLE_SIZE_1024		0x4000
198*cfcc706cSMiquel Raynal 
199*cfcc706cSMiquel Raynal #define PMECC_MAX_TIMEOUT_US		(100 * 1000)
200*cfcc706cSMiquel Raynal 
201*cfcc706cSMiquel Raynal /* Reserved bytes in oob area */
202*cfcc706cSMiquel Raynal #define PMECC_OOB_RESERVED_BYTES		2
203*cfcc706cSMiquel Raynal 
204*cfcc706cSMiquel Raynal #endif
205