blob: 1c7f3a2e227d808628a16e90db02b167efa1bb18 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Magnus Lilja4133f652009-06-13 20:50:01 +02002/*
Magnus Lilja4133f652009-06-13 20:50:01 +02003 * (c) 2009 Magnus Lilja <lilja.magnus@gmail.com>
Magnus Lilja4133f652009-06-13 20:50:01 +02004 */
5
Benoît Thébaudeauefb7c002013-04-11 09:35:51 +00006#ifndef __MXC_NAND_H
7#define __MXC_NAND_H
Magnus Lilja4133f652009-06-13 20:50:01 +02008
9/*
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020010 * Register map and bit definitions for the Freescale NAND Flash Controller
11 * present in various i.MX devices.
John Rigby4c94c452010-01-26 19:24:17 -070012 *
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020013 * MX31 and MX27 have version 1, which has:
14 * 4 512-byte main buffers and
15 * 4 16-byte spare buffers
16 * to support up to 2K byte pagesize nand.
17 * Reading or writing a 2K page requires 4 FDI/FDO cycles.
John Rigby4c94c452010-01-26 19:24:17 -070018 *
Benoît Thébaudeau8f265962013-04-11 09:35:37 +000019 * MX25 and MX35 have version 2.1, and MX51 and MX53 have version 3.2, which
20 * have:
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020021 * 8 512-byte main buffers and
22 * 8 64-byte spare buffers
23 * to support up to 4K byte pagesize nand.
24 * Reading or writing a 2K or 4K page requires only 1 FDI/FDO cycle.
25 * Also some of registers are moved and/or changed meaning as seen below.
Magnus Lilja4133f652009-06-13 20:50:01 +020026 */
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020027#if defined(CONFIG_MX27) || defined(CONFIG_MX31)
John Rigby4c94c452010-01-26 19:24:17 -070028#define MXC_NFC_V1
Benoît Thébaudeauc5b4eb12012-08-13 22:50:53 +020029#define is_mxc_nfc_1() 1
30#define is_mxc_nfc_21() 0
Benoît Thébaudeau8f265962013-04-11 09:35:37 +000031#define is_mxc_nfc_32() 0
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020032#elif defined(CONFIG_MX25) || defined(CONFIG_MX35)
Benoît Thébaudeauc5b4eb12012-08-13 22:50:53 +020033#define MXC_NFC_V2_1
34#define is_mxc_nfc_1() 0
35#define is_mxc_nfc_21() 1
Benoît Thébaudeau8f265962013-04-11 09:35:37 +000036#define is_mxc_nfc_32() 0
37#elif defined(CONFIG_MX51) || defined(CONFIG_MX53)
38#define MXC_NFC_V3
39#define MXC_NFC_V3_2
40#define is_mxc_nfc_1() 0
41#define is_mxc_nfc_21() 0
42#define is_mxc_nfc_32() 1
John Rigby4c94c452010-01-26 19:24:17 -070043#else
Benoît Thébaudeau27d64532012-08-13 22:50:42 +020044#error "MXC NFC implementation not supported"
John Rigby4c94c452010-01-26 19:24:17 -070045#endif
Benoît Thébaudeau8f265962013-04-11 09:35:37 +000046#define is_mxc_nfc_3() is_mxc_nfc_32()
John Rigby4c94c452010-01-26 19:24:17 -070047
48#if defined(MXC_NFC_V1)
49#define NAND_MXC_NR_BUFS 4
50#define NAND_MXC_SPARE_BUF_SIZE 16
51#define NAND_MXC_REG_OFFSET 0xe00
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020052#define NAND_MXC_2K_MULTI_CYCLE
Benoît Thébaudeau8f265962013-04-11 09:35:37 +000053#elif defined(MXC_NFC_V2_1) || defined(MXC_NFC_V3_2)
John Rigby4c94c452010-01-26 19:24:17 -070054#define NAND_MXC_NR_BUFS 8
55#define NAND_MXC_SPARE_BUF_SIZE 64
56#define NAND_MXC_REG_OFFSET 0x1e00
John Rigby4c94c452010-01-26 19:24:17 -070057#endif
Magnus Lilja4133f652009-06-13 20:50:01 +020058
Benoît Thébaudeauefb7c002013-04-11 09:35:51 +000059struct mxc_nand_regs {
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020060 u8 main_area[NAND_MXC_NR_BUFS][0x200];
61 u8 spare_area[NAND_MXC_NR_BUFS][NAND_MXC_SPARE_BUF_SIZE];
John Rigby4c94c452010-01-26 19:24:17 -070062 /*
63 * reserved size is offset of nfc registers
64 * minus total main and spare sizes
65 */
66 u8 reserved1[NAND_MXC_REG_OFFSET
67 - NAND_MXC_NR_BUFS * (512 + NAND_MXC_SPARE_BUF_SIZE)];
68#if defined(MXC_NFC_V1)
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020069 u16 buf_size;
Magnus Lilja4133f652009-06-13 20:50:01 +020070 u16 reserved2;
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020071 u16 buf_addr;
72 u16 flash_addr;
Magnus Lilja4133f652009-06-13 20:50:01 +020073 u16 flash_cmd;
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020074 u16 config;
Magnus Lilja4133f652009-06-13 20:50:01 +020075 u16 ecc_status_result;
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020076 u16 rsltmain_area;
77 u16 rsltspare_area;
78 u16 wrprot;
79 u16 unlockstart_blkaddr;
80 u16 unlockend_blkaddr;
81 u16 nf_wrprst;
82 u16 config1;
83 u16 config2;
Benoît Thébaudeauc5b4eb12012-08-13 22:50:53 +020084#elif defined(MXC_NFC_V2_1)
John Rigby4c94c452010-01-26 19:24:17 -070085 u16 reserved2[2];
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020086 u16 buf_addr;
87 u16 flash_addr;
John Rigby4c94c452010-01-26 19:24:17 -070088 u16 flash_cmd;
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020089 u16 config;
Benoît Thébaudeaud29aeba2012-08-13 22:49:42 +020090 u32 ecc_status_result;
John Rigby4c94c452010-01-26 19:24:17 -070091 u16 spare_area_size;
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020092 u16 wrprot;
John Rigby4c94c452010-01-26 19:24:17 -070093 u16 reserved3[2];
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020094 u16 nf_wrprst;
95 u16 config1;
96 u16 config2;
John Rigby4c94c452010-01-26 19:24:17 -070097 u16 reserved4;
Benoît Thébaudeau3f775192012-08-13 22:48:12 +020098 u16 unlockstart_blkaddr;
99 u16 unlockend_blkaddr;
100 u16 unlockstart_blkaddr1;
101 u16 unlockend_blkaddr1;
102 u16 unlockstart_blkaddr2;
103 u16 unlockend_blkaddr2;
104 u16 unlockstart_blkaddr3;
105 u16 unlockend_blkaddr3;
Benoît Thébaudeau8f265962013-04-11 09:35:37 +0000106#elif defined(MXC_NFC_V3_2)
107 u32 flash_cmd;
108 u32 flash_addr[12];
109 u32 config1;
110 u32 ecc_status_result;
111 u32 status_sum;
112 u32 launch;
John Rigby4c94c452010-01-26 19:24:17 -0700113#endif
Magnus Lilja4133f652009-06-13 20:50:01 +0200114};
Benoît Thébaudeau8f265962013-04-11 09:35:37 +0000115
116#ifdef MXC_NFC_V3_2
Benoît Thébaudeauefb7c002013-04-11 09:35:51 +0000117struct mxc_nand_ip_regs {
Benoît Thébaudeau8f265962013-04-11 09:35:37 +0000118 u32 wrprot;
119 u32 wrprot_unlock_blkaddr[8];
120 u32 config2;
121 u32 config3;
122 u32 ipc;
123 u32 err_addr;
124 u32 delay_line;
125};
126#endif
Magnus Lilja4133f652009-06-13 20:50:01 +0200127
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000128/* Set FCMD to 1, rest to 0 for Command operation */
129#define NFC_CMD 0x1
Magnus Lilja4133f652009-06-13 20:50:01 +0200130
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000131/* Set FADD to 1, rest to 0 for Address operation */
132#define NFC_ADDR 0x2
Magnus Lilja4133f652009-06-13 20:50:01 +0200133
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000134/* Set FDI to 1, rest to 0 for Input operation */
135#define NFC_INPUT 0x4
Magnus Lilja4133f652009-06-13 20:50:01 +0200136
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000137/* Set FDO to 001, rest to 0 for Data Output operation */
138#define NFC_OUTPUT 0x8
Magnus Lilja4133f652009-06-13 20:50:01 +0200139
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000140/* Set FDO to 010, rest to 0 for Read ID operation */
141#define NFC_ID 0x10
Magnus Lilja4133f652009-06-13 20:50:01 +0200142
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000143/* Set FDO to 100, rest to 0 for Read Status operation */
144#define NFC_STATUS 0x20
Magnus Lilja4133f652009-06-13 20:50:01 +0200145
Benoît Thébaudeau8f265962013-04-11 09:35:37 +0000146#if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000147#define NFC_CONFIG1_SP_EN (1 << 2)
148#define NFC_CONFIG1_RST (1 << 6)
149#define NFC_CONFIG1_CE (1 << 7)
Benoît Thébaudeau8f265962013-04-11 09:35:37 +0000150#elif defined(MXC_NFC_V3_2)
151#define NFC_CONFIG1_SP_EN (1 << 0)
152#define NFC_CONFIG1_CE (1 << 1)
153#define NFC_CONFIG1_RST (1 << 2)
154#endif
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000155#define NFC_V1_V2_CONFIG1_ECC_EN (1 << 3)
156#define NFC_V1_V2_CONFIG1_INT_MSK (1 << 4)
157#define NFC_V1_V2_CONFIG1_BIG (1 << 5)
158#define NFC_V2_CONFIG1_ECC_MODE_4 (1 << 0)
159#define NFC_V2_CONFIG1_ONE_CYCLE (1 << 8)
160#define NFC_V2_CONFIG1_FP_INT (1 << 11)
Benoît Thébaudeau8f265962013-04-11 09:35:37 +0000161#define NFC_V3_CONFIG1_RBA_MASK (0x7 << 4)
162#define NFC_V3_CONFIG1_RBA(x) (((x) & 0x7) << 4)
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000163
164#define NFC_V1_V2_CONFIG2_INT (1 << 15)
Benoît Thébaudeau8f265962013-04-11 09:35:37 +0000165#define NFC_V3_CONFIG2_PS_MASK (0x3 << 0)
166#define NFC_V3_CONFIG2_PS_512 (0 << 0)
167#define NFC_V3_CONFIG2_PS_2048 (1 << 0)
168#define NFC_V3_CONFIG2_PS_4096 (2 << 0)
169#define NFC_V3_CONFIG2_ONE_CYCLE (1 << 2)
170#define NFC_V3_CONFIG2_ECC_EN (1 << 3)
171#define NFC_V3_CONFIG2_2CMD_PHASES (1 << 4)
172#define NFC_V3_CONFIG2_NUM_ADDR_PH0 (1 << 5)
173#define NFC_V3_CONFIG2_ECC_MODE_8 (1 << 6)
174#define NFC_V3_CONFIG2_PPB_MASK (0x3 << 7)
175#define NFC_V3_CONFIG2_PPB(x) (((x) & 0x3) << 7)
176#define NFC_V3_CONFIG2_EDC_MASK (0x7 << 9)
177#define NFC_V3_CONFIG2_EDC(x) (((x) & 0x7) << 9)
178#define NFC_V3_CONFIG2_NUM_ADDR_PH1(x) (((x) & 0x3) << 12)
179#define NFC_V3_CONFIG2_INT_MSK (1 << 15)
180#define NFC_V3_CONFIG2_SPAS_MASK (0xff << 16)
181#define NFC_V3_CONFIG2_SPAS(x) (((x) & 0xff) << 16)
182#define NFC_V3_CONFIG2_ST_CMD_MASK (0xff << 24)
183#define NFC_V3_CONFIG2_ST_CMD(x) (((x) & 0xff) << 24)
184
185#define NFC_V3_CONFIG3_ADD_OP(x) (((x) & 0x3) << 0)
186#define NFC_V3_CONFIG3_FW8 (1 << 3)
187#define NFC_V3_CONFIG3_SBB(x) (((x) & 0x7) << 8)
188#define NFC_V3_CONFIG3_NUM_OF_DEVS(x) (((x) & 0x7) << 12)
189#define NFC_V3_CONFIG3_RBB_MODE (1 << 15)
190#define NFC_V3_CONFIG3_NO_SDMA (1 << 20)
Magnus Lilja4133f652009-06-13 20:50:01 +0200191
Benoît Thébaudeau8f265962013-04-11 09:35:37 +0000192#define NFC_V3_WRPROT_UNLOCK (1 << 2)
193#define NFC_V3_WRPROT_BLS_UNLOCK (2 << 6)
194
195#define NFC_V3_IPC_CREQ (1 << 0)
196#define NFC_V3_IPC_INT (1 << 31)
197
198#if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
Benoît Thébaudeau555bba12013-04-11 09:35:36 +0000199#define operation config2
200#define readnfc readw
201#define writenfc writew
Benoît Thébaudeau8f265962013-04-11 09:35:37 +0000202#elif defined(MXC_NFC_V3_2)
203#define operation launch
204#define readnfc readl
205#define writenfc writel
206#endif
Magnus Lilja4133f652009-06-13 20:50:01 +0200207
Benoît Thébaudeauefb7c002013-04-11 09:35:51 +0000208#endif /* __MXC_NAND_H */