blob: 766ee95bb3034e134587ce62947055dc469baa5f [file] [log] [blame]
Gary Jennejohn73ccb342008-04-28 14:04:32 +02001/*
2 * (C) Copyright 2008
3 * Gary Jennejohn, DENX Software Engineering GmbH, garyj@denx.de
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <config.h>
26#if defined(CONFIG_CMD_NAND)
27#include <asm/gpio.h>
Scott Woodba22d102008-08-13 18:03:40 -050028#include <asm/io.h>
Gary Jennejohn73ccb342008-04-28 14:04:32 +020029#include <nand.h>
30
31/*
32 * hardware specific access to control-lines
33 */
Scott Woodba22d102008-08-13 18:03:40 -050034static void quad100hd_hwcontrol(struct mtd_info *mtd,
35 int cmd, unsigned int ctrl)
Gary Jennejohn73ccb342008-04-28 14:04:32 +020036{
Scott Woodba22d102008-08-13 18:03:40 -050037 struct nand_chip *this = mtd->priv;
Gary Jennejohn73ccb342008-04-28 14:04:32 +020038
Scott Woodba22d102008-08-13 18:03:40 -050039 if (ctrl & NAND_CTRL_CHANGE) {
40 gpio_write_bit(CFG_NAND_CLE, !!(ctrl & NAND_CLE));
41 gpio_write_bit(CFG_NAND_ALE, !!(ctrl & NAND_ALE));
42 gpio_write_bit(CFG_NAND_CE, !(ctrl & NAND_NCE));
Gary Jennejohn73ccb342008-04-28 14:04:32 +020043 }
Scott Woodba22d102008-08-13 18:03:40 -050044
45 if (cmd != NAND_CMD_NONE)
46 writeb(cmd, this->IO_ADDR_W);
Gary Jennejohn73ccb342008-04-28 14:04:32 +020047}
48
49static int quad100hd_nand_ready(struct mtd_info *mtd)
50{
51 return gpio_read_in_bit(CFG_NAND_RDY);
52}
53
54/*
55 * Main initialization routine
56 */
57int board_nand_init(struct nand_chip *nand)
58{
59 /* Set address of hardware control function */
Scott Woodba22d102008-08-13 18:03:40 -050060 nand->cmd_ctrl = quad100hd_hwcontrol;
Gary Jennejohn73ccb342008-04-28 14:04:32 +020061 nand->dev_ready = quad100hd_nand_ready;
Scott Woodba22d102008-08-13 18:03:40 -050062 nand->ecc.mode = NAND_ECC_SOFT;
Gary Jennejohn73ccb342008-04-28 14:04:32 +020063 /* 15 us command delay time */
64 nand->chip_delay = 20;
65
66 /* Return happy */
67 return 0;
68}
69#endif /* CONFIG_CMD_NAND */