]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/include/asm/arch-am33xx/nand.h
AM33xx NAND driver
[karo-tx-uboot.git] / arch / arm / include / asm / arch-am33xx / nand.h
1 /*
2  * (C) Copyright 2010-2011 Texas Instruments, <www.ti.com>
3  * Mansoor Ahamed <mansoor.ahamed@ti.com>
4  *
5  * Derived from work done by Rohit Choraria <rohitkc@ti.com> for omap3
6  *
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307 USA
24  */
25 #ifndef __ASM_ARCH_OMAP_GPMC_H
26 #define __ASM_ARCH_OMAP_GPMC_H
27
28 #include <linux/mtd/nand.h>
29
30 #define GPMC_BUF_EMPTY          0
31 #define GPMC_BUF_FULL           1
32
33 #define ECCCLEAR                (0x1 << 8)
34 #define ECCRESULTREG1           (0x1 << 0)
35 #define ECCSIZE512BYTE          0xFF
36 #define ECCSIZE1                (ECCSIZE512BYTE << 22)
37 #define ECCSIZE0                (ECCSIZE512BYTE << 12)
38 #define ECCSIZE0SEL             (0x000 << 0)
39
40 /* Generic ECC Layouts */
41 /* Large Page x8 NAND device Layout */
42 #ifdef GPMC_NAND_ECC_LP_x8_LAYOUT
43 #define GPMC_NAND_HW_ECC_LAYOUT {\
44         .eccbytes = 12,\
45         .eccpos = {1, 2, 3, 4, 5, 6, 7, 8,\
46                 9, 10, 11, 12},\
47         .oobfree = {\
48                 {.offset = 13,\
49                  .length = 51 } } \
50 }
51 #endif
52
53 /* Large Page x16 NAND device Layout */
54 #ifdef GPMC_NAND_ECC_LP_x16_LAYOUT
55 #define GPMC_NAND_HW_ECC_LAYOUT {\
56         .eccbytes = 12,\
57         .eccpos = {2, 3, 4, 5, 6, 7, 8, 9,\
58                 10, 11, 12, 13},\
59         .oobfree = {\
60                 {.offset = 14,\
61                  .length = 50 } } \
62 }
63 #endif
64
65 /* NAND device layout in synch with the kernel */
66 #ifdef GPMC_NAND_ECC_LP_x16_LAYOUT
67 #define GPMC_NAND_HW_ECC_LAYOUT_KERNEL {\
68         .eccbytes = 12,\
69         .eccpos = {\
70                    40, 41, 42, 43, 44, 45, 46, 47,\
71                    48, 49, 50, 51},\
72         .oobfree = {\
73                 {.offset = 2,\
74                  .length = 38} } \
75 }
76 #endif
77
78 /* Small Page x8 NAND device Layout */
79 #ifdef GPMC_NAND_ECC_SP_x8_LAYOUT
80 #define GPMC_NAND_HW_ECC_LAYOUT {\
81         .eccbytes = 3,\
82         .eccpos = {1, 2, 3},\
83         .oobfree = {\
84                 {.offset = 4,\
85                  .length = 12 } } \
86 }
87 #endif
88
89 /* Small Page x16 NAND device Layout */
90 #ifdef GPMC_NAND_ECC_SP_x16_LAYOUT
91 #define GPMC_NAND_HW_ECC_LAYOUT {\
92         .eccbytes = 3,\
93         .eccpos = {2, 3, 4},\
94         .oobfree = {\
95                 {.offset = 58,\
96                  .length = 6 } } \
97 }
98 #endif
99
100 #define GPMC_NAND_HW_BCH4_ECC_LAYOUT {\
101         .eccbytes = 32,\
102         .eccpos = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\
103                                 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,\
104                                 28, 29, 30, 31, 32, 33},\
105         .oobfree = {\
106                 {.offset = 34,\
107                  .length = 30 } } \
108 }
109
110 #define GPMC_NAND_HW_BCH8_ECC_LAYOUT {\
111         .eccbytes = 56,\
112         .eccpos = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\
113                                 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,\
114                                 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,\
115                                 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\
116                                 52, 53, 54, 55, 56, 57},\
117         .oobfree = {\
118                 {.offset = 58,\
119                  .length = 6 } } \
120 }
121
122 #define GPMC_NAND_HW_BCH16_ECC_LAYOUT {\
123         .eccbytes = 104,\
124         .eccpos = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\
125                                 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,\
126                                 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,\
127                                 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\
128                                 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,\
129                                 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,\
130                                 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,\
131                                 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,\
132                                 100, 101, 102, 103, 104, 105},\
133         .oobfree = {\
134                 {.offset = 106,\
135                  .length = 8 } } \
136 }
137
138 /*
139  * ELM Module Registers
140  */
141
142 /* ELM registers bit fields */
143 #define ELM_SYSCONFIG_SOFTRESET_MASK                    (0x2)
144 #define ELM_SYSCONFIG_SOFTRESET                 (0x2)
145 #define ELM_SYSSTATUS_RESETDONE_MASK                    (0x1)
146 #define ELM_SYSSTATUS_RESETDONE                 (0x1)
147 #define ELM_LOCATION_CONFIG_ECC_BCH_LEVEL_MASK          (0x3)
148 #define ELM_LOCATION_CONFIG_ECC_SIZE_MASK               (0x7FF0000)
149 #define ELM_LOCATION_CONFIG_ECC_SIZE_POS                (16)
150 #define ELM_SYNDROME_FRAGMENT_6_SYNDROME_VALID          (0x00010000)
151 #define ELM_LOCATION_STATUS_ECC_CORRECTABLE_MASK        (0x100)
152 #define ELM_LOCATION_STATUS_ECC_NB_ERRORS_MASK          (0x1F)
153
154 #ifndef __KERNEL_STRICT_NAMES
155 #ifndef __ASSEMBLY__
156
157 enum bch_level {
158         BCH_4_BIT = 0,
159         BCH_8_BIT,
160         BCH_16_BIT
161 };
162
163
164 /* BCH syndrome registers */
165 struct syndrome {
166         u32 syndrome_fragment_x[7];     /* 0x400, 0x404.... 0x418 */
167         u8 res1[36];                    /* 0x41c */
168 };
169
170 /* BCH error status & location register */
171 struct location {
172         u32 location_status;            /* 0x800 */
173         u8 res1[124];                   /* 0x804 */
174         u32 error_location_x[16];       /* 0x880.... */
175         u8 res2[64];                    /* 0x8c0 */
176 };
177
178 /* BCH ELM register map - do not try to allocate memmory for this structure.
179  * We have used plenty of reserved variables to fill the slots in the ELM
180  * register memory map.
181  * Directly initialize the struct pointer to ELM base address.
182  */
183 struct elm {
184         u32 rev;                                /* 0x000 */
185         u8 res1[12];                            /* 0x004 */
186         u32 sysconfig;                          /* 0x010 */
187         u32 sysstatus;                          /* 0x014 */
188         u32 irqstatus;                          /* 0x018 */
189         u32 irqenable;                          /* 0x01c */
190         u32 location_config;                    /* 0x020 */
191         u8 res2[92];                            /* 0x024 */
192         u32 page_ctrl;                          /* 0x080 */
193         u8 res3[892];                           /* 0x084 */
194         struct  syndrome syndrome_fragments[8]; /* 0x400 */
195         u8 res4[512];                           /* 0x600 */
196         struct location  error_location[8];     /* 0x800 */
197 };
198
199 int elm_check_error(u8 *syndrome, u32 nibbles, u32 *error_count,
200                 u32 *error_locations);
201 int elm_config(enum bch_level level);
202 void elm_reset(void);
203 void elm_init(void);
204 void am33xx_nand_switch_ecc(nand_ecc_modes_t hardware, int32_t mode);
205 #endif /* __ASSEMBLY__ */
206 #endif /* __KERNEL_STRICT_NAMES */
207
208
209 #endif /* __ASM_ARCH_OMAP_GPMC_H */
210