xref: /openbmc/u-boot/board/freescale/m5373evb/nand.c (revision f64cb652)
11ac559d4STsiChungLiew /*
21ac559d4STsiChungLiew  * (C) Copyright 2000-2003
31ac559d4STsiChungLiew  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
41ac559d4STsiChungLiew  *
51ac559d4STsiChungLiew  * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
61ac559d4STsiChungLiew  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
71ac559d4STsiChungLiew  *
81ac559d4STsiChungLiew  * See file CREDITS for list of people who contributed to this
91ac559d4STsiChungLiew  * project.
101ac559d4STsiChungLiew  *
111ac559d4STsiChungLiew  * This program is free software; you can redistribute it and/or
121ac559d4STsiChungLiew  * modify it under the terms of the GNU General Public License as
131ac559d4STsiChungLiew  * published by the Free Software Foundation; either version 2 of
141ac559d4STsiChungLiew  * the License, or (at your option) any later version.
151ac559d4STsiChungLiew  *
161ac559d4STsiChungLiew  * This program is distributed in the hope that it will be useful,
171ac559d4STsiChungLiew  * but WITHOUT ANY WARRANTY; without even the implied warranty of
181ac559d4STsiChungLiew  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
191ac559d4STsiChungLiew  * GNU General Public License for more details.
201ac559d4STsiChungLiew  *
211ac559d4STsiChungLiew  * You should have received a copy of the GNU General Public License
221ac559d4STsiChungLiew  * along with this program; if not, write to the Free Software
231ac559d4STsiChungLiew  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
241ac559d4STsiChungLiew  * MA 02111-1307 USA
251ac559d4STsiChungLiew  */
261ac559d4STsiChungLiew 
271ac559d4STsiChungLiew #include <config.h>
281ac559d4STsiChungLiew #include <common.h>
291ac559d4STsiChungLiew #include <asm/io.h>
301ac559d4STsiChungLiew #include <asm/immap.h>
311ac559d4STsiChungLiew 
321ac559d4STsiChungLiew DECLARE_GLOBAL_DATA_PTR;
331ac559d4STsiChungLiew 
341ac559d4STsiChungLiew #if defined(CONFIG_CMD_NAND)
351ac559d4STsiChungLiew #include <nand.h>
361ac559d4STsiChungLiew #include <linux/mtd/mtd.h>
371ac559d4STsiChungLiew 
381ac559d4STsiChungLiew #define SET_CLE		0x10
391ac559d4STsiChungLiew #define SET_ALE		0x08
401ac559d4STsiChungLiew 
41*f64cb652SScott Wood static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
421ac559d4STsiChungLiew {
431ac559d4STsiChungLiew 	struct nand_chip *this = mtdinfo->priv;
441ac559d4STsiChungLiew 	volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
451ac559d4STsiChungLiew 	u32 nand_baseaddr = (u32) this->IO_ADDR_W;
461ac559d4STsiChungLiew 
47*f64cb652SScott Wood 	if (ctrl & NAND_CTRL_CHANGE) {
48*f64cb652SScott Wood 		ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
49*f64cb652SScott Wood 		IO_ADDR_W &= ~(SET_ALE | SE_CLE);
50*f64cb652SScott Wood 
51*f64cb652SScott Wood 		if (ctrl & NAND_CLE)
52*f64cb652SScott Wood 			IO_ADDR_W |= SET_CLE;
53*f64cb652SScott Wood 		if (ctrl & NAND_ALE)
54*f64cb652SScott Wood 			IO_ADDR_W |= SET_ALE;
55*f64cb652SScott Wood 
56*f64cb652SScott Wood 		at91_set_gpio_value(AT91_PIN_PD15, !(ctrl & NAND_NCE));
57*f64cb652SScott Wood 		this->IO_ADDR_W = (void *)IO_ADDR_W;
58*f64cb652SScott Wood 
591ac559d4STsiChungLiew 	}
601ac559d4STsiChungLiew 
61*f64cb652SScott Wood 	if (cmd != NAND_CMD_NONE)
62*f64cb652SScott Wood 		writeb(cmd, this->IO_ADDR_W);
631ac559d4STsiChungLiew }
641ac559d4STsiChungLiew 
651ac559d4STsiChungLiew int board_nand_init(struct nand_chip *nand)
661ac559d4STsiChungLiew {
671ac559d4STsiChungLiew 	volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
68*f64cb652SScott Wood 	volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
691ac559d4STsiChungLiew 
701ac559d4STsiChungLiew 	*((volatile u16 *)CFG_LATCH_ADDR) |= 0x0004;
71*f64cb652SScott Wood 	fbcs->csmr2 &= ~FBCS_CSMR_WP;
721ac559d4STsiChungLiew 
731ac559d4STsiChungLiew 	/* set up pin configuration */
741ac559d4STsiChungLiew 	gpio->par_timer &= ~GPIO_PAR_TIN3_TIN3;
751ac559d4STsiChungLiew 	gpio->pddr_timer |= 0x08;
761ac559d4STsiChungLiew 	gpio->ppd_timer |= 0x08;
771ac559d4STsiChungLiew 	gpio->pclrr_timer = 0;
781ac559d4STsiChungLiew 	gpio->podr_timer = 0;
791ac559d4STsiChungLiew 
801ac559d4STsiChungLiew 	nand->chip_delay = 50;
81*f64cb652SScott Wood 	nand->ecc.mode = NAND_ECC_SOFT;
82*f64cb652SScott Wood 	nand->cmd_ctrl = nand_hwcontrol;
831ac559d4STsiChungLiew 
841ac559d4STsiChungLiew 	return 0;
851ac559d4STsiChungLiew }
861ac559d4STsiChungLiew #endif
87