blob: b2d2682a8835235d1a48e2bf67817cf15f0c3eb3 [file] [log] [blame]
Nikolay Petukhov7c27b7b2010-03-19 10:49:27 +05001/*
2 * Error Corrected Code Controller (ECC) - System peripherals regsters.
3 * Based on AT91SAM9260 datasheet revision B.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Nikolay Petukhov7c27b7b2010-03-19 10:49:27 +05006 */
7
8#ifndef ATMEL_NAND_ECC_H
9#define ATMEL_NAND_ECC_H
10
11#define ATMEL_ECC_CR 0x00 /* Control register */
12#define ATMEL_ECC_RST (1 << 0) /* Reset parity */
13
14#define ATMEL_ECC_MR 0x04 /* Mode register */
15#define ATMEL_ECC_PAGESIZE (3 << 0) /* Page Size */
16#define ATMEL_ECC_PAGESIZE_528 (0)
17#define ATMEL_ECC_PAGESIZE_1056 (1)
18#define ATMEL_ECC_PAGESIZE_2112 (2)
19#define ATMEL_ECC_PAGESIZE_4224 (3)
20
21#define ATMEL_ECC_SR 0x08 /* Status register */
22#define ATMEL_ECC_RECERR (1 << 0) /* Recoverable Error */
23#define ATMEL_ECC_ECCERR (1 << 1) /* ECC Single Bit Error */
24#define ATMEL_ECC_MULERR (1 << 2) /* Multiple Errors */
25
26#define ATMEL_ECC_PR 0x0c /* Parity register */
27#define ATMEL_ECC_BITADDR (0xf << 0) /* Bit Error Address */
28#define ATMEL_ECC_WORDADDR (0xfff << 4) /* Word Error Address */
29
30#define ATMEL_ECC_NPR 0x10 /* NParity register */
31#define ATMEL_ECC_NPARITY (0xffff << 0) /* NParity */
32
Wu, Joshbdfd59a2012-08-23 00:05:36 +000033/* Register access macros for PMECC */
34#define pmecc_readl(addr, reg) \
35 readl(&addr->reg)
36
Wu, Josh14b3b442014-06-24 18:18:06 +080037#define pmecc_readb(addr, reg) \
38 readb(&addr->reg)
39
Wu, Joshbdfd59a2012-08-23 00:05:36 +000040#define pmecc_writel(addr, reg, value) \
41 writel((value), &addr->reg)
42
43/* PMECC Register Definitions */
44#define PMECC_MAX_SECTOR_NUM 8
45struct pmecc_regs {
46 u32 cfg; /* 0x00 PMECC Configuration Register */
47 u32 sarea; /* 0x04 PMECC Spare Area Size Register */
48 u32 saddr; /* 0x08 PMECC Start Address Register */
49 u32 eaddr; /* 0x0C PMECC End Address Register */
50 u32 clk; /* 0x10 PMECC Clock Control Register */
51 u32 ctrl; /* 0x14 PMECC Control Register */
52 u32 sr; /* 0x18 PMECC Status Register */
53 u32 ier; /* 0x1C PMECC Interrupt Enable Register */
54 u32 idr; /* 0x20 PMECC Interrupt Disable Register */
55 u32 imr; /* 0x24 PMECC Interrupt Mask Register */
56 u32 isr; /* 0x28 PMECC Interrupt Status Register */
57 u32 reserved0[5]; /* 0x2C-0x3C Reserved */
58
59 /* 0x40 + sector_num * (0x40), Redundancy Registers */
60 struct {
61 u8 ecc[44]; /* PMECC Generated Redundancy Byte Per Sector */
62 u32 reserved1[5];
63 } ecc_port[PMECC_MAX_SECTOR_NUM];
64
65 /* 0x240 + sector_num * (0x40) Remainder Registers */
66 struct {
67 u32 rem[12];
68 u32 reserved2[4];
69 } rem_port[PMECC_MAX_SECTOR_NUM];
70 u32 reserved3[16]; /* 0x440-0x47C Reserved */
71};
72
73/* For PMECC Configuration Register */
74#define PMECC_CFG_BCH_ERR2 (0 << 0)
75#define PMECC_CFG_BCH_ERR4 (1 << 0)
76#define PMECC_CFG_BCH_ERR8 (2 << 0)
77#define PMECC_CFG_BCH_ERR12 (3 << 0)
78#define PMECC_CFG_BCH_ERR24 (4 << 0)
79
80#define PMECC_CFG_SECTOR512 (0 << 4)
81#define PMECC_CFG_SECTOR1024 (1 << 4)
82
83#define PMECC_CFG_PAGE_1SECTOR (0 << 8)
84#define PMECC_CFG_PAGE_2SECTORS (1 << 8)
85#define PMECC_CFG_PAGE_4SECTORS (2 << 8)
86#define PMECC_CFG_PAGE_8SECTORS (3 << 8)
87
88#define PMECC_CFG_READ_OP (0 << 12)
89#define PMECC_CFG_WRITE_OP (1 << 12)
90
91#define PMECC_CFG_SPARE_ENABLE (1 << 16)
92#define PMECC_CFG_SPARE_DISABLE (0 << 16)
93
94#define PMECC_CFG_AUTO_ENABLE (1 << 20)
95#define PMECC_CFG_AUTO_DISABLE (0 << 20)
96
97/* For PMECC Clock Control Register */
98#define PMECC_CLK_133MHZ (2 << 0)
99
100/* For PMECC Control Register */
101#define PMECC_CTRL_RST (1 << 0)
102#define PMECC_CTRL_DATA (1 << 1)
103#define PMECC_CTRL_USER (1 << 2)
104#define PMECC_CTRL_ENABLE (1 << 4)
105#define PMECC_CTRL_DISABLE (1 << 5)
106
107/* For PMECC Status Register */
108#define PMECC_SR_BUSY (1 << 0)
109#define PMECC_SR_ENABLE (1 << 4)
110
111/* PMERRLOC Register Definitions */
112struct pmecc_errloc_regs {
113 u32 elcfg; /* 0x00 Error Location Configuration Register */
114 u32 elprim; /* 0x04 Error Location Primitive Register */
115 u32 elen; /* 0x08 Error Location Enable Register */
116 u32 eldis; /* 0x0C Error Location Disable Register */
117 u32 elsr; /* 0x10 Error Location Status Register */
118 u32 elier; /* 0x14 Error Location Interrupt Enable Register */
119 u32 elidr; /* 0x08 Error Location Interrupt Disable Register */
120 u32 elimr; /* 0x0C Error Location Interrupt Mask Register */
121 u32 elisr; /* 0x20 Error Location Interrupt Status Register */
122 u32 reserved0; /* 0x24 Reserved */
123 u32 sigma[25]; /* 0x28-0x88 Error Location Sigma Registers */
124 u32 el[24]; /* 0x8C-0xE8 Error Location Registers */
125 u32 reserved1[5]; /* 0xEC-0xFC Reserved */
Wu, Josh0e48dc52015-01-16 11:54:46 +0800126
127 /*
128 * 0x100-0x1F8:
129 * Reserved for AT91SAM9X5, AT91SAM9N12.
130 * HSMC registers for SAMA5D3, SAMA5D4.
131 */
132 u32 reserved2[63];
133
134 /*
135 * 0x1FC:
136 * PMECC version for AT91SAM9X5, AT91SAM9N12.
137 * HSMC version for SAMA5D3, SAMA5D4. Can refer as PMECC version.
138 */
139 u32 version;
Wu, Joshbdfd59a2012-08-23 00:05:36 +0000140};
141
142/* For Error Location Configuration Register */
143#define PMERRLOC_ELCFG_SECTOR_512 (0 << 0)
144#define PMERRLOC_ELCFG_SECTOR_1024 (1 << 0)
145#define PMERRLOC_ELCFG_NUM_ERRORS(n) ((n) << 16)
146
147/* For Error Location Disable Register */
148#define PMERRLOC_DISABLE (1 << 0)
149
150/* For Error Location Interrupt Status Register */
151#define PMERRLOC_ERR_NUM_MASK (0x1f << 8)
152#define PMERRLOC_CALC_DONE (1 << 0)
153
Wu, Josh0e48dc52015-01-16 11:54:46 +0800154/* PMECC IP version */
155#define PMECC_VERSION_SAMA5D4 0x113
156#define PMECC_VERSION_SAMA5D3 0x112
157#define PMECC_VERSION_AT91SAM9N12 0x102
158#define PMECC_VERSION_AT91SAM9X5 0x101
159
Wu, Joshbdfd59a2012-08-23 00:05:36 +0000160/* Galois field dimension */
161#define PMECC_GF_DIMENSION_13 13
162#define PMECC_GF_DIMENSION_14 14
163
Josh Wu7df44862014-11-10 15:24:00 +0800164/* Primitive Polynomial used by PMECC */
165#define PMECC_GF_13_PRIMITIVE_POLY 0x201b
166#define PMECC_GF_14_PRIMITIVE_POLY 0x4443
167
Wu, Joshbdfd59a2012-08-23 00:05:36 +0000168#define PMECC_INDEX_TABLE_SIZE_512 0x2000
169#define PMECC_INDEX_TABLE_SIZE_1024 0x4000
170
171#define PMECC_MAX_TIMEOUT_US (100 * 1000)
172
Nikolay Petukhov7c27b7b2010-03-19 10:49:27 +0500173#endif