blob: a02d6e0a5ab36dda572646653083bd7754f96aad [file] [log] [blame]
Magnus Lilja40c642b2009-06-13 20:50:01 +02001/*
Magnus Lilja40c642b2009-06-13 20:50:01 +02002 * (c) 2009 Magnus Lilja <lilja.magnus@gmail.com>
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Magnus Lilja40c642b2009-06-13 20:50:01 +02005 */
6
Benoît Thébaudeauda962b72013-04-11 09:35:51 +00007#ifndef __MXC_NAND_H
8#define __MXC_NAND_H
Magnus Lilja40c642b2009-06-13 20:50:01 +02009
10/*
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020011 * Register map and bit definitions for the Freescale NAND Flash Controller
12 * present in various i.MX devices.
John Rigbyf3bb63a2010-01-26 19:24:17 -070013 *
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020014 * MX31 and MX27 have version 1, which has:
15 * 4 512-byte main buffers and
16 * 4 16-byte spare buffers
17 * to support up to 2K byte pagesize nand.
18 * Reading or writing a 2K page requires 4 FDI/FDO cycles.
John Rigbyf3bb63a2010-01-26 19:24:17 -070019 *
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +000020 * MX25 and MX35 have version 2.1, and MX51 and MX53 have version 3.2, which
21 * have:
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020022 * 8 512-byte main buffers and
23 * 8 64-byte spare buffers
24 * to support up to 4K byte pagesize nand.
25 * Reading or writing a 2K or 4K page requires only 1 FDI/FDO cycle.
26 * Also some of registers are moved and/or changed meaning as seen below.
Magnus Lilja40c642b2009-06-13 20:50:01 +020027 */
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020028#if defined(CONFIG_MX27) || defined(CONFIG_MX31)
John Rigbyf3bb63a2010-01-26 19:24:17 -070029#define MXC_NFC_V1
Benoît Thébaudeau9c60e752012-08-13 22:50:53 +020030#define is_mxc_nfc_1() 1
31#define is_mxc_nfc_21() 0
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +000032#define is_mxc_nfc_32() 0
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020033#elif defined(CONFIG_MX25) || defined(CONFIG_MX35)
Benoît Thébaudeau9c60e752012-08-13 22:50:53 +020034#define MXC_NFC_V2_1
35#define is_mxc_nfc_1() 0
36#define is_mxc_nfc_21() 1
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +000037#define is_mxc_nfc_32() 0
38#elif defined(CONFIG_MX51) || defined(CONFIG_MX53)
39#define MXC_NFC_V3
40#define MXC_NFC_V3_2
41#define is_mxc_nfc_1() 0
42#define is_mxc_nfc_21() 0
43#define is_mxc_nfc_32() 1
John Rigbyf3bb63a2010-01-26 19:24:17 -070044#else
Benoît Thébaudeau1884d652012-08-13 22:50:42 +020045#error "MXC NFC implementation not supported"
John Rigbyf3bb63a2010-01-26 19:24:17 -070046#endif
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +000047#define is_mxc_nfc_3() is_mxc_nfc_32()
John Rigbyf3bb63a2010-01-26 19:24:17 -070048
49#if defined(MXC_NFC_V1)
50#define NAND_MXC_NR_BUFS 4
51#define NAND_MXC_SPARE_BUF_SIZE 16
52#define NAND_MXC_REG_OFFSET 0xe00
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020053#define NAND_MXC_2K_MULTI_CYCLE
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +000054#elif defined(MXC_NFC_V2_1) || defined(MXC_NFC_V3_2)
John Rigbyf3bb63a2010-01-26 19:24:17 -070055#define NAND_MXC_NR_BUFS 8
56#define NAND_MXC_SPARE_BUF_SIZE 64
57#define NAND_MXC_REG_OFFSET 0x1e00
John Rigbyf3bb63a2010-01-26 19:24:17 -070058#endif
Magnus Lilja40c642b2009-06-13 20:50:01 +020059
Benoît Thébaudeauda962b72013-04-11 09:35:51 +000060struct mxc_nand_regs {
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020061 u8 main_area[NAND_MXC_NR_BUFS][0x200];
62 u8 spare_area[NAND_MXC_NR_BUFS][NAND_MXC_SPARE_BUF_SIZE];
John Rigbyf3bb63a2010-01-26 19:24:17 -070063 /*
64 * reserved size is offset of nfc registers
65 * minus total main and spare sizes
66 */
67 u8 reserved1[NAND_MXC_REG_OFFSET
68 - NAND_MXC_NR_BUFS * (512 + NAND_MXC_SPARE_BUF_SIZE)];
69#if defined(MXC_NFC_V1)
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020070 u16 buf_size;
Magnus Lilja40c642b2009-06-13 20:50:01 +020071 u16 reserved2;
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020072 u16 buf_addr;
73 u16 flash_addr;
Magnus Lilja40c642b2009-06-13 20:50:01 +020074 u16 flash_cmd;
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020075 u16 config;
Magnus Lilja40c642b2009-06-13 20:50:01 +020076 u16 ecc_status_result;
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020077 u16 rsltmain_area;
78 u16 rsltspare_area;
79 u16 wrprot;
80 u16 unlockstart_blkaddr;
81 u16 unlockend_blkaddr;
82 u16 nf_wrprst;
83 u16 config1;
84 u16 config2;
Benoît Thébaudeau9c60e752012-08-13 22:50:53 +020085#elif defined(MXC_NFC_V2_1)
John Rigbyf3bb63a2010-01-26 19:24:17 -070086 u16 reserved2[2];
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020087 u16 buf_addr;
88 u16 flash_addr;
John Rigbyf3bb63a2010-01-26 19:24:17 -070089 u16 flash_cmd;
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020090 u16 config;
Benoît Thébaudeauc1db8dd2012-08-13 22:49:42 +020091 u32 ecc_status_result;
John Rigbyf3bb63a2010-01-26 19:24:17 -070092 u16 spare_area_size;
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020093 u16 wrprot;
John Rigbyf3bb63a2010-01-26 19:24:17 -070094 u16 reserved3[2];
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020095 u16 nf_wrprst;
96 u16 config1;
97 u16 config2;
John Rigbyf3bb63a2010-01-26 19:24:17 -070098 u16 reserved4;
Benoît Thébaudeau80c8ab72012-08-13 22:48:12 +020099 u16 unlockstart_blkaddr;
100 u16 unlockend_blkaddr;
101 u16 unlockstart_blkaddr1;
102 u16 unlockend_blkaddr1;
103 u16 unlockstart_blkaddr2;
104 u16 unlockend_blkaddr2;
105 u16 unlockstart_blkaddr3;
106 u16 unlockend_blkaddr3;
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +0000107#elif defined(MXC_NFC_V3_2)
108 u32 flash_cmd;
109 u32 flash_addr[12];
110 u32 config1;
111 u32 ecc_status_result;
112 u32 status_sum;
113 u32 launch;
John Rigbyf3bb63a2010-01-26 19:24:17 -0700114#endif
Magnus Lilja40c642b2009-06-13 20:50:01 +0200115};
116
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +0000117#ifdef MXC_NFC_V3_2
Benoît Thébaudeauda962b72013-04-11 09:35:51 +0000118struct mxc_nand_ip_regs {
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +0000119 u32 wrprot;
120 u32 wrprot_unlock_blkaddr[8];
121 u32 config2;
122 u32 config3;
123 u32 ipc;
124 u32 err_addr;
125 u32 delay_line;
126};
127#endif
128
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000129/* Set FCMD to 1, rest to 0 for Command operation */
130#define NFC_CMD 0x1
Magnus Lilja40c642b2009-06-13 20:50:01 +0200131
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000132/* Set FADD to 1, rest to 0 for Address operation */
133#define NFC_ADDR 0x2
Magnus Lilja40c642b2009-06-13 20:50:01 +0200134
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000135/* Set FDI to 1, rest to 0 for Input operation */
136#define NFC_INPUT 0x4
Magnus Lilja40c642b2009-06-13 20:50:01 +0200137
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000138/* Set FDO to 001, rest to 0 for Data Output operation */
139#define NFC_OUTPUT 0x8
Magnus Lilja40c642b2009-06-13 20:50:01 +0200140
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000141/* Set FDO to 010, rest to 0 for Read ID operation */
142#define NFC_ID 0x10
Magnus Lilja40c642b2009-06-13 20:50:01 +0200143
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000144/* Set FDO to 100, rest to 0 for Read Status operation */
145#define NFC_STATUS 0x20
Magnus Lilja40c642b2009-06-13 20:50:01 +0200146
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +0000147#if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000148#define NFC_CONFIG1_SP_EN (1 << 2)
149#define NFC_CONFIG1_RST (1 << 6)
150#define NFC_CONFIG1_CE (1 << 7)
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +0000151#elif defined(MXC_NFC_V3_2)
152#define NFC_CONFIG1_SP_EN (1 << 0)
153#define NFC_CONFIG1_CE (1 << 1)
154#define NFC_CONFIG1_RST (1 << 2)
155#endif
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000156#define NFC_V1_V2_CONFIG1_ECC_EN (1 << 3)
157#define NFC_V1_V2_CONFIG1_INT_MSK (1 << 4)
158#define NFC_V1_V2_CONFIG1_BIG (1 << 5)
159#define NFC_V2_CONFIG1_ECC_MODE_4 (1 << 0)
160#define NFC_V2_CONFIG1_ONE_CYCLE (1 << 8)
161#define NFC_V2_CONFIG1_FP_INT (1 << 11)
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +0000162#define NFC_V3_CONFIG1_RBA_MASK (0x7 << 4)
163#define NFC_V3_CONFIG1_RBA(x) (((x) & 0x7) << 4)
Magnus Lilja40c642b2009-06-13 20:50:01 +0200164
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000165#define NFC_V1_V2_CONFIG2_INT (1 << 15)
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +0000166#define NFC_V3_CONFIG2_PS_MASK (0x3 << 0)
167#define NFC_V3_CONFIG2_PS_512 (0 << 0)
168#define NFC_V3_CONFIG2_PS_2048 (1 << 0)
169#define NFC_V3_CONFIG2_PS_4096 (2 << 0)
170#define NFC_V3_CONFIG2_ONE_CYCLE (1 << 2)
171#define NFC_V3_CONFIG2_ECC_EN (1 << 3)
172#define NFC_V3_CONFIG2_2CMD_PHASES (1 << 4)
173#define NFC_V3_CONFIG2_NUM_ADDR_PH0 (1 << 5)
174#define NFC_V3_CONFIG2_ECC_MODE_8 (1 << 6)
175#define NFC_V3_CONFIG2_PPB_MASK (0x3 << 7)
176#define NFC_V3_CONFIG2_PPB(x) (((x) & 0x3) << 7)
177#define NFC_V3_CONFIG2_EDC_MASK (0x7 << 9)
178#define NFC_V3_CONFIG2_EDC(x) (((x) & 0x7) << 9)
179#define NFC_V3_CONFIG2_NUM_ADDR_PH1(x) (((x) & 0x3) << 12)
180#define NFC_V3_CONFIG2_INT_MSK (1 << 15)
181#define NFC_V3_CONFIG2_SPAS_MASK (0xff << 16)
182#define NFC_V3_CONFIG2_SPAS(x) (((x) & 0xff) << 16)
183#define NFC_V3_CONFIG2_ST_CMD_MASK (0xff << 24)
184#define NFC_V3_CONFIG2_ST_CMD(x) (((x) & 0xff) << 24)
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000185
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +0000186#define NFC_V3_CONFIG3_ADD_OP(x) (((x) & 0x3) << 0)
187#define NFC_V3_CONFIG3_FW8 (1 << 3)
188#define NFC_V3_CONFIG3_SBB(x) (((x) & 0x7) << 8)
189#define NFC_V3_CONFIG3_NUM_OF_DEVS(x) (((x) & 0x7) << 12)
190#define NFC_V3_CONFIG3_RBB_MODE (1 << 15)
191#define NFC_V3_CONFIG3_NO_SDMA (1 << 20)
192
193#define NFC_V3_WRPROT_UNLOCK (1 << 2)
194#define NFC_V3_WRPROT_BLS_UNLOCK (2 << 6)
195
196#define NFC_V3_IPC_CREQ (1 << 0)
197#define NFC_V3_IPC_INT (1 << 31)
198
199#if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
Benoît Thébaudeau2dc0aa02013-04-11 09:35:36 +0000200#define operation config2
201#define readnfc readw
202#define writenfc writew
Benoît Thébaudeau35537bc2013-04-11 09:35:37 +0000203#elif defined(MXC_NFC_V3_2)
204#define operation launch
205#define readnfc readl
206#define writenfc writel
207#endif
Magnus Lilja40c642b2009-06-13 20:50:01 +0200208
Benoît Thébaudeauda962b72013-04-11 09:35:51 +0000209#endif /* __MXC_NAND_H */