3 * Platform independend driver for NDFC (NanD Flash Controller)
4 * integrated into EP440 cores
7 * Stefan Roese, DENX Software Engineering, sr@denx.de.
9 * Based on original work by
13 * See file CREDITS for list of people who contributed to this
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 #if (CONFIG_COMMANDS & CFG_CMD_NAND) && !defined(CFG_NAND_LEGACY) && \
35 (defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
36 defined(CONFIG_440EPX) || defined(CONFIG_440GRX))
39 #include <linux/mtd/ndfc.h>
40 #include <asm/processor.h>
45 static void ndfc_hwcontrol(struct mtd_info
*mtdinfo
, int cmd
)
66 static void ndfc_write_byte(struct mtd_info
*mtdinfo
, u_char byte
)
68 struct nand_chip
*this = mtdinfo
->priv
;
69 ulong base
= (ulong
) this->IO_ADDR_W
& 0xfffffffc;
72 out8(base
+ NDFC_CMD
, byte
);
74 out8(base
+ NDFC_ALE
, byte
);
76 out8(base
+ NDFC_DATA
, byte
);
79 static u_char
ndfc_read_byte(struct mtd_info
*mtdinfo
)
81 struct nand_chip
*this = mtdinfo
->priv
;
82 ulong base
= (ulong
) this->IO_ADDR_W
& 0xfffffffc;
84 return (in8(base
+ NDFC_DATA
));
87 static int ndfc_dev_ready(struct mtd_info
*mtdinfo
)
89 struct nand_chip
*this = mtdinfo
->priv
;
90 ulong base
= (ulong
) this->IO_ADDR_W
& 0xfffffffc;
92 while (!(in32(base
+ NDFC_STAT
) & NDFC_STAT_IS_READY
))
98 #ifndef CONFIG_NAND_SPL
100 * Don't use these speedup functions in NAND boot image, since the image
101 * has to fit into 4kByte.
105 * Speedups for buffer read/write/verify
107 * NDFC allows 32bit read/write of data. So we can speed up the buffer
108 * functions. No further checking, as nand_base will always read/write
111 static void ndfc_read_buf(struct mtd_info
*mtdinfo
, uint8_t *buf
, int len
)
113 struct nand_chip
*this = mtdinfo
->priv
;
114 ulong base
= (ulong
) this->IO_ADDR_W
& 0xfffffffc;
115 uint32_t *p
= (uint32_t *) buf
;
117 for (;len
> 0; len
-= 4)
118 *p
++ = in32(base
+ NDFC_DATA
);
121 static void ndfc_write_buf(struct mtd_info
*mtdinfo
, const uint8_t *buf
, int len
)
123 struct nand_chip
*this = mtdinfo
->priv
;
124 ulong base
= (ulong
) this->IO_ADDR_W
& 0xfffffffc;
125 uint32_t *p
= (uint32_t *) buf
;
127 for (; len
> 0; len
-= 4)
128 out32(base
+ NDFC_DATA
, *p
++);
131 static int ndfc_verify_buf(struct mtd_info
*mtdinfo
, const uint8_t *buf
, int len
)
133 struct nand_chip
*this = mtdinfo
->priv
;
134 ulong base
= (ulong
) this->IO_ADDR_W
& 0xfffffffc;
135 uint32_t *p
= (uint32_t *) buf
;
137 for (; len
> 0; len
-= 4)
138 if (*p
++ != in32(base
+ NDFC_DATA
))
143 #endif /* #ifndef CONFIG_NAND_SPL */
145 void board_nand_select_device(struct nand_chip
*nand
, int chip
)
148 * Don't use "chip" to address the NAND device,
149 * generate the cs from the address where it is encoded.
151 int cs
= (ulong
)nand
->IO_ADDR_W
& 0x00000003;
152 ulong base
= (ulong
)nand
->IO_ADDR_W
& 0xfffffffc;
154 /* Set NandFlash Core Configuration Register */
156 out32(base
+ NDFC_CCR
, 0x00000000 | (cs
<< 24));
159 void board_nand_init(struct nand_chip
*nand
)
161 int cs
= (ulong
)nand
->IO_ADDR_W
& 0x00000003;
162 ulong base
= (ulong
)nand
->IO_ADDR_W
& 0xfffffffc;
164 nand
->eccmode
= NAND_ECC_SOFT
;
166 nand
->hwcontrol
= ndfc_hwcontrol
;
167 nand
->read_byte
= ndfc_read_byte
;
168 nand
->write_byte
= ndfc_write_byte
;
169 nand
->dev_ready
= ndfc_dev_ready
;
171 #ifndef CONFIG_NAND_SPL
172 nand
->write_buf
= ndfc_write_buf
;
173 nand
->read_buf
= ndfc_read_buf
;
174 nand
->verify_buf
= ndfc_verify_buf
;
177 * Setup EBC (CS0 only right now)
179 mtdcr(ebccfga
, xbcfg
);
180 mtdcr(ebccfgd
, 0xb8400000);
182 mtebc(pb0cr
, CFG_EBC_PB0CR
);
183 mtebc(pb0ap
, CFG_EBC_PB0AP
);
187 * Select required NAND chip in NDFC
189 board_nand_select_device(nand
, cs
);
190 out32(base
+ NDFC_BCFG0
+ (cs
<< 2), 0x80002222);