]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/asm-arm/arch-mx35/mxc_nand.h
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / include / asm-arm / arch-mx35 / mxc_nand.h
1 /*
2  * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
3  */
4
5 /*
6  * The code contained herein is licensed under the GNU General Public
7  * License. You may obtain a copy of the GNU General Public License
8  * Version 2 or later at the following locations:
9  *
10  * http://www.opensource.org/licenses/gpl-license.html
11  * http://www.gnu.org/copyleft/gpl.html
12  */
13
14 /*!
15  * @file mxc_nd2.h
16  *
17  * @brief This file contains the NAND Flash Controller register information.
18  *
19  *
20  * @ingroup NAND_MTD
21  */
22
23 #ifndef __MXC_NAND_H__
24 #define __MXC_NAND_H__
25
26 #include <asm/arch/mx35.h>
27
28 #define IS_2K_PAGE_NAND         ((mtd->writesize / info->num_of_intlv) \
29                                                 == NAND_PAGESIZE_2KB)
30 #define IS_4K_PAGE_NAND         ((mtd->writesize / info->num_of_intlv) \
31                                                 == NAND_PAGESIZE_4KB)
32 #define IS_LARGE_PAGE_NAND      ((mtd->writesize / info->num_of_intlv) > 512)
33
34 #define GET_NAND_OOB_SIZE       (mtd->oobsize / info->num_of_intlv)
35 #define GET_NAND_PAGE_SIZE      (mtd->writesize / info->num_of_intlv)
36
37 #define NAND_PAGESIZE_2KB       2048
38 #define NAND_PAGESIZE_4KB       4096
39
40 /*
41  * main area for bad block marker is in the last data section
42  * the spare area for swapped bad block marker is the second
43  * byte of last spare section
44  */
45 #define NAND_SECTIONS        (GET_NAND_PAGE_SIZE >> 9)
46 #define NAND_OOB_PER_SECTION (((GET_NAND_OOB_SIZE / NAND_SECTIONS) >> 1) << 1)
47 #define NAND_CHUNKS          (GET_NAND_PAGE_SIZE / (512 + NAND_OOB_PER_SECTION))
48
49 #define BAD_BLK_MARKER_MAIN_OFFS \
50         (GET_NAND_PAGE_SIZE - NAND_CHUNKS * NAND_OOB_PER_SECTION)
51
52 #define BAD_BLK_MARKER_SP_OFFS (NAND_CHUNKS * SPARE_LEN)
53
54 #define BAD_BLK_MARKER_OOB_OFFS (NAND_CHUNKS * NAND_OOB_PER_SECTION)
55
56 #define BAD_BLK_MARKER_MAIN  \
57         ((u32)MAIN_AREA0 + BAD_BLK_MARKER_MAIN_OFFS)
58
59 #define BAD_BLK_MARKER_SP  \
60         ((u32)SPARE_AREA0 + BAD_BLK_MARKER_SP_OFFS)
61
62
63 /*
64  * Addresses for NFC registers
65  */
66 #define NFC_REG_BASE                    (NFC_BASE_ADDR + 0x1000)
67 #define NFC_BUF_ADDR                    (NFC_REG_BASE + 0xE04)
68 #define NFC_FLASH_ADDR                  (NFC_REG_BASE + 0xE06)
69 #define NFC_FLASH_CMD                   (NFC_REG_BASE + 0xE08)
70 #define NFC_CONFIG                      (NFC_REG_BASE + 0xE0A)
71 #define NFC_ECC_STATUS_RESULT           (NFC_REG_BASE + 0xE0C)
72 #define NFC_SPAS                        (NFC_REG_BASE + 0xE10)
73 #define NFC_WRPROT                      (NFC_REG_BASE + 0xE12)
74 #define NFC_UNLOCKSTART_BLKADDR         (NFC_REG_BASE + 0xE20)
75 #define NFC_UNLOCKEND_BLKADDR           (NFC_REG_BASE + 0xE22)
76 #define NFC_CONFIG1                     (NFC_REG_BASE + 0xE1A)
77 #define NFC_CONFIG2                     (NFC_REG_BASE + 0xE1C)
78
79 /*!
80  * Addresses for NFC RAM BUFFER Main area 0
81  */
82 #define MAIN_AREA0                      (u16 *)(NFC_BASE_ADDR + 0x000)
83 #define MAIN_AREA1                      (u16 *)(NFC_BASE_ADDR + 0x200)
84
85 /*!
86  * Addresses for NFC SPARE BUFFER Spare area 0
87  */
88 #define SPARE_AREA0                     (u16 *)(NFC_BASE_ADDR + 0x1000)
89 #define SPARE_LEN                       64
90 #define SPARE_COUNT                     8
91 #define SPARE_SIZE                      (SPARE_LEN * SPARE_COUNT)
92
93
94 #define SPAS_SHIFT      (0)
95 #define SPAS_MASK       (0xFF00)
96 #define IS_4BIT_ECC     \
97         ((raw_read(REG_NFC_ECC_MODE) & NFC_ECC_MODE_4) >> 0)
98
99 #define NFC_SET_SPAS(v)                 \
100         raw_write(((raw_read(REG_NFC_SPAS) & SPAS_MASK) | \
101         ((v<<SPAS_SHIFT))), \
102         REG_NFC_SPAS)
103
104 #define NFC_SET_ECC_MODE(v) \
105 do { \
106         if ((v) == NFC_SPAS_218)  { \
107                 raw_write((raw_read(REG_NFC_ECC_MODE) & \
108                 NFC_ECC_MODE_8), \
109                 REG_NFC_ECC_MODE); \
110         } else { \
111                 raw_write((raw_read(REG_NFC_ECC_MODE) | \
112                 NFC_ECC_MODE_4), \
113                 REG_NFC_ECC_MODE); \
114         } \
115 } while (0)
116
117 #define GET_ECC_STATUS() \
118         __raw_readl(REG_NFC_ECC_STATUS_RESULT);
119
120 #define NFC_SET_NFMS(v) \
121 do { \
122         if (((v) & (1 << NFMS_NF_PG_SZ))) { \
123                 if (IS_2K_PAGE_NAND) { \
124                         (NFMS |= 0x00000100); \
125                         (NFMS &= ~0x00000200); \
126                         NFC_SET_SPAS(NFC_SPAS_64); \
127                 } else if (IS_4K_PAGE_NAND) { \
128                         (NFMS &= ~0x00000100); \
129                         (NFMS |= 0x00000200); \
130                         GET_NAND_OOB_SIZE == 128 ? \
131                         NFC_SET_SPAS(NFC_SPAS_128) : \
132                         NFC_SET_SPAS(NFC_SPAS_218); \
133                 } else { \
134                         printk(KERN_ERR "Err for setting page/oob size"); \
135                 } \
136                 NFC_SET_ECC_MODE(GET_NAND_OOB_SIZE >> 1); \
137         } \
138 } while (0)
139
140
141 #define WRITE_NFC_IP_REG(val, reg) \
142         raw_write((raw_read(REG_NFC_OPS_STAT) & ~NFC_OPS_STAT), \
143         REG_NFC_OPS_STAT)
144
145 #define GET_NFC_ECC_STATUS() \
146         raw_read(REG_NFC_ECC_STATUS_RESULT);
147
148 /*!
149  * Set INT to 0, Set 1 to specific operation bit, rest to 0 in LAUNCH_NFC Register for
150  * Specific operation
151  */
152 #define NFC_CMD                         0x1
153 #define NFC_ADDR                        0x2
154 #define NFC_INPUT                       0x4
155 #define NFC_OUTPUT                      0x8
156 #define NFC_ID                          0x10
157 #define NFC_STATUS                      0x20
158
159 /* Bit Definitions */
160 #define NFC_OPS_STAT                    (1 << 15)
161 #define NFC_SP_EN                       (1 << 2)
162 #define NFC_ECC_EN                      (1 << 3)
163 #define NFC_INT_MSK                     (1 << 4)
164 #define NFC_BIG                         (1 << 5)
165 #define NFC_RST                         (1 << 6)
166 #define NFC_CE                          (1 << 7)
167 #define NFC_ONE_CYCLE                   (1 << 8)
168 #define NFC_BLS_LOCKED                  0
169 #define NFC_BLS_LOCKED_DEFAULT          1
170 #define NFC_BLS_UNLCOKED                2
171 #define NFC_WPC_LOCK_TIGHT              1
172 #define NFC_WPC_LOCK                    (1 << 1)
173 #define NFC_WPC_UNLOCK                  (1 << 2)
174 #define NFC_FLASH_ADDR_SHIFT            0
175 #define NFC_UNLOCK_END_ADDR_SHIFT       0
176
177 #define NFC_ECC_MODE_4                   (1<<0)
178 #define NFC_ECC_MODE_8                   (~(1<<0))
179 #define NFC_SPAS_16                      8
180 #define NFC_SPAS_64                      32
181 #define NFC_SPAS_128                     64
182 #define NFC_SPAS_218                     109
183
184 /* NFC Register Mapping */
185 #define REG_NFC_OPS_STAT                NFC_CONFIG2
186 #define REG_NFC_INTRRUPT                NFC_CONFIG1
187 #define REG_NFC_FLASH_ADDR              NFC_FLASH_ADDR
188 #define REG_NFC_FLASH_CMD               NFC_FLASH_CMD
189 #define REG_NFC_OPS                     NFC_CONFIG2
190 #define REG_NFC_SET_RBA                 NFC_BUF_ADDR
191 #define REG_NFC_ECC_EN                  NFC_CONFIG1
192 #define REG_NFC_ECC_STATUS_RESULT       NFC_ECC_STATUS_RESULT
193 #define REG_NFC_CE                      NFC_CONFIG1
194 #define REG_NFC_SP_EN                   NFC_CONFIG1
195 #define REG_NFC_BLS                     NFC_CONFIG
196 #define REG_NFC_WPC                     NFC_WRPROT
197 #define REG_START_BLKADDR               NFC_UNLOCKSTART_BLKADDR
198 #define REG_END_BLKADDR                 NFC_UNLOCKEND_BLKADDR
199 #define REG_NFC_RST                     NFC_CONFIG1
200 #define REG_NFC_ECC_MODE                NFC_CONFIG1
201 #define REG_NFC_SPAS                    NFC_SPAS
202
203
204 /* NFC V1/V2 Specific MACRO functions definitions */
205
206 #define raw_write(v, a)                 __raw_writew(v, a)
207 #define raw_read(a)                     __raw_readw(a)
208
209 #define NFC_SET_BLS(val)                val
210
211 #define UNLOCK_ADDR(start_addr, end_addr) \
212 { \
213         raw_write(start_addr, REG_START_BLKADDR); \
214         raw_write(end_addr, REG_END_BLKADDR); \
215 }
216
217 #define NFC_SET_NFC_ACTIVE_CS(val)
218 #define NFC_SET_WPC(val)        val
219
220 /* NULL Definitions */
221 #define ACK_OPS
222 #define NFC_SET_RBA(val) raw_write(val, REG_NFC_SET_RBA);
223
224 #define READ_PAGE()     send_read_page(0)
225 #define PROG_PAGE()     send_prog_page(0)
226 #define CHECK_NFC_RB            1
227
228 #endif                          /* __MXC_NAND_H__ */