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