3 * Heiko Schocher, DENX Software Engineering, hs@denx.de
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #define CONFIG_NAND_MODE_REG (void *)(CONFIG_SYS_NAND_BASE + 0x20000)
29 #define CONFIG_NAND_DATA_REG (void *)(CONFIG_SYS_NAND_BASE + 0x30000)
31 #define read_mode() in_8(CONFIG_NAND_MODE_REG)
32 #define write_mode(val) out_8(CONFIG_NAND_MODE_REG, val)
33 #define read_data() in_8(CONFIG_NAND_DATA_REG)
34 #define write_data(val) out_8(CONFIG_NAND_DATA_REG, val)
36 #define KPN_RDY2 (1 << 7)
37 #define KPN_RDY1 (1 << 6)
38 #define KPN_WPN (1 << 4)
39 #define KPN_CE2N (1 << 3)
40 #define KPN_CE1N (1 << 2)
41 #define KPN_ALE (1 << 1)
42 #define KPN_CLE (1 << 0)
44 #define KPN_DEFAULT_CHIP_DELAY 50
46 static int kpn_chip_ready(void)
48 if (read_mode() & KPN_RDY1)
54 static void kpn_wait_rdy(void)
58 while (--cnt && !kpn_chip_ready())
62 printf ("timeout while waiting for RDY\n");
65 static void kpn_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
67 u8 reg_val = read_mode();
69 if (ctrl & NAND_CTRL_CHANGE) {
70 reg_val = reg_val & ~(KPN_ALE + KPN_CLE);
73 reg_val = reg_val | KPN_CLE;
75 reg_val = reg_val | KPN_ALE;
77 reg_val = reg_val & ~KPN_CE1N;
79 reg_val = reg_val | KPN_CE1N;
83 if (cmd != NAND_CMD_NONE)
86 /* wait until flash is ready */
90 static u_char kpn_nand_read_byte(struct mtd_info *mtd)
95 static void kpn_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
99 for (i = 0; i < len; i++) {
105 static void kpn_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
109 for (i = 0; i < len; i++)
110 buf[i] = read_data();
113 static int kpn_nand_dev_ready(struct mtd_info *mtd)
120 int board_nand_init(struct nand_chip *nand)
122 #if defined(CONFIG_NAND_ECC_BCH)
123 nand->ecc.mode = NAND_ECC_SOFT_BCH;
125 nand->ecc.mode = NAND_ECC_SOFT;
128 /* Reference hardware control function */
129 nand->cmd_ctrl = kpn_nand_hwcontrol;
130 nand->read_byte = kpn_nand_read_byte;
131 nand->write_buf = kpn_nand_write_buf;
132 nand->read_buf = kpn_nand_read_buf;
133 nand->dev_ready = kpn_nand_dev_ready;
134 nand->chip_delay = KPN_DEFAULT_CHIP_DELAY;
136 /* reset mode register */
137 write_mode(KPN_CE1N + KPN_CE2N + KPN_WPN);