2 * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
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:
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
17 * @brief This file contains the NAND Flash Controller register information.
23 #ifndef __MXC_NAND_H__
24 #define __MXC_NAND_H__
26 #include <asm/arch/mx35.h>
28 #define IS_2K_PAGE_NAND ((mtd->writesize / info->num_of_intlv) \
30 #define IS_4K_PAGE_NAND ((mtd->writesize / info->num_of_intlv) \
32 #define IS_LARGE_PAGE_NAND ((mtd->writesize / info->num_of_intlv) > 512)
34 #define GET_NAND_OOB_SIZE (mtd->oobsize / info->num_of_intlv)
35 #define GET_NAND_PAGE_SIZE (mtd->writesize / info->num_of_intlv)
37 #define NAND_PAGESIZE_2KB 2048
38 #define NAND_PAGESIZE_4KB 4096
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
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))
49 #define BAD_BLK_MARKER_MAIN_OFFS \
50 (GET_NAND_PAGE_SIZE - NAND_CHUNKS * NAND_OOB_PER_SECTION)
52 #define BAD_BLK_MARKER_SP_OFFS (NAND_CHUNKS * SPARE_LEN)
54 #define BAD_BLK_MARKER_OOB_OFFS (NAND_CHUNKS * NAND_OOB_PER_SECTION)
56 #define BAD_BLK_MARKER_MAIN \
57 ((u32)MAIN_AREA0 + BAD_BLK_MARKER_MAIN_OFFS)
59 #define BAD_BLK_MARKER_SP \
60 ((u32)SPARE_AREA0 + BAD_BLK_MARKER_SP_OFFS)
64 * Addresses for NFC registers
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)
80 * Addresses for NFC RAM BUFFER Main area 0
82 #define MAIN_AREA0 (u16 *)(NFC_BASE_ADDR + 0x000)
83 #define MAIN_AREA1 (u16 *)(NFC_BASE_ADDR + 0x200)
86 * Addresses for NFC SPARE BUFFER Spare area 0
88 #define SPARE_AREA0 (u16 *)(NFC_BASE_ADDR + 0x1000)
91 #define SPARE_SIZE (SPARE_LEN * SPARE_COUNT)
94 #define SPAS_SHIFT (0)
95 #define SPAS_MASK (0xFF00)
97 ((raw_read(REG_NFC_ECC_MODE) & NFC_ECC_MODE_4) >> 0)
99 #define NFC_SET_SPAS(v) \
100 raw_write(((raw_read(REG_NFC_SPAS) & SPAS_MASK) | \
101 ((v<<SPAS_SHIFT))), \
104 #define NFC_SET_ECC_MODE(v) \
106 if ((v) == NFC_SPAS_218) { \
107 raw_write((raw_read(REG_NFC_ECC_MODE) & \
111 raw_write((raw_read(REG_NFC_ECC_MODE) | \
117 #define GET_ECC_STATUS() \
118 __raw_readl(REG_NFC_ECC_STATUS_RESULT);
120 #define NFC_SET_NFMS(v) \
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); \
134 printk(KERN_ERR "Err for setting page/oob size"); \
136 NFC_SET_ECC_MODE(GET_NAND_OOB_SIZE >> 1); \
141 #define WRITE_NFC_IP_REG(val, reg) \
142 raw_write((raw_read(REG_NFC_OPS_STAT) & ~NFC_OPS_STAT), \
145 #define GET_NFC_ECC_STATUS() \
146 raw_read(REG_NFC_ECC_STATUS_RESULT);
149 * Set INT to 0, Set 1 to specific operation bit, rest to 0 in LAUNCH_NFC Register for
154 #define NFC_INPUT 0x4
155 #define NFC_OUTPUT 0x8
157 #define NFC_STATUS 0x20
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
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
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
204 /* NFC V1/V2 Specific MACRO functions definitions */
206 #define raw_write(v, a) __raw_writew(v, a)
207 #define raw_read(a) __raw_readw(a)
209 #define NFC_SET_BLS(val) val
211 #define UNLOCK_ADDR(start_addr, end_addr) \
213 raw_write(start_addr, REG_START_BLKADDR); \
214 raw_write(end_addr, REG_END_BLKADDR); \
217 #define NFC_SET_NFC_ACTIVE_CS(val)
218 #define NFC_SET_WPC(val) val
220 /* NULL Definitions */
222 #define NFC_SET_RBA(val) raw_write(val, REG_NFC_SET_RBA);
224 #define READ_PAGE() send_read_page(0)
225 #define PROG_PAGE() send_prog_page(0)
226 #define CHECK_NFC_RB 1
228 #endif /* __MXC_NAND_H__ */