xref: /openbmc/u-boot/board/freescale/m5373evb/nand.c (revision aa0d99fc)
11ac559d4STsiChungLiew /*
21ac559d4STsiChungLiew  * (C) Copyright 2000-2003
31ac559d4STsiChungLiew  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
41ac559d4STsiChungLiew  *
5*aa0d99fcSAlison Wang  * Copyright (C) 2004-2007, 2012 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 
41f64cb652SScott Wood static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
421ac559d4STsiChungLiew {
431ac559d4STsiChungLiew 	struct nand_chip *this = mtdinfo->priv;
44e4f69d1bSTsiChung Liew 	volatile u16 *nCE = (u16 *) CONFIG_SYS_LATCH_ADDR;
451ac559d4STsiChungLiew 
46f64cb652SScott Wood 	if (ctrl & NAND_CTRL_CHANGE) {
47f64cb652SScott Wood 		ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
48f64cb652SScott Wood 
49e4f69d1bSTsiChung Liew 		IO_ADDR_W &= ~(SET_ALE | SET_CLE);
50e4f69d1bSTsiChung Liew 
51e4f69d1bSTsiChung Liew 		if (ctrl & NAND_NCE)
529017d932STsiChung Liew 			*nCE &= 0xFFFB;
539017d932STsiChung Liew 		else
54e4f69d1bSTsiChung Liew 			*nCE |= 0x0004;
559017d932STsiChung Liew 
56f64cb652SScott Wood 		if (ctrl & NAND_CLE)
57f64cb652SScott Wood 			IO_ADDR_W |= SET_CLE;
58f64cb652SScott Wood 		if (ctrl & NAND_ALE)
59f64cb652SScott Wood 			IO_ADDR_W |= SET_ALE;
60f64cb652SScott Wood 
61f64cb652SScott Wood 		this->IO_ADDR_W = (void *)IO_ADDR_W;
62f64cb652SScott Wood 
631ac559d4STsiChungLiew 	}
641ac559d4STsiChungLiew 
65f64cb652SScott Wood 	if (cmd != NAND_CMD_NONE)
66f64cb652SScott Wood 		writeb(cmd, this->IO_ADDR_W);
671ac559d4STsiChungLiew }
681ac559d4STsiChungLiew 
691ac559d4STsiChungLiew int board_nand_init(struct nand_chip *nand)
701ac559d4STsiChungLiew {
71*aa0d99fcSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
72*aa0d99fcSAlison Wang 	fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
731ac559d4STsiChungLiew 
74*aa0d99fcSAlison Wang 	clrbits_be32(&fbcs->csmr2, FBCS_CSMR_WP);
751ac559d4STsiChungLiew 
76e4f69d1bSTsiChung Liew 	/*
77e4f69d1bSTsiChung Liew 	 * set up pin configuration - enabled 2nd output buffer's signals
78e4f69d1bSTsiChung Liew 	 * (nand_ngpio - nCE USB1/2_PWR_EN, LATCH_GPIOs, LCD_VEEEN, etc)
79e4f69d1bSTsiChung Liew 	 * to use nCE signal
80e4f69d1bSTsiChung Liew 	 */
81*aa0d99fcSAlison Wang 	clrbits_8(&gpio->par_timer, GPIO_PAR_TIN3_TIN3);
82*aa0d99fcSAlison Wang 	setbits_8(&gpio->pddr_timer, 0x08);
83*aa0d99fcSAlison Wang 	setbits_8(&gpio->ppd_timer, 0x08);
84*aa0d99fcSAlison Wang 	out_8(&gpio->pclrr_timer, 0);
85*aa0d99fcSAlison Wang 	out_8(&gpio->podr_timer, 0);
861ac559d4STsiChungLiew 
879017d932STsiChung Liew 	nand->chip_delay = 60;
88f64cb652SScott Wood 	nand->ecc.mode = NAND_ECC_SOFT;
89f64cb652SScott Wood 	nand->cmd_ctrl = nand_hwcontrol;
901ac559d4STsiChungLiew 
911ac559d4STsiChungLiew 	return 0;
921ac559d4STsiChungLiew }
931ac559d4STsiChungLiew #endif
94