xref: /openbmc/u-boot/board/freescale/m5373evb/nand.c (revision e4f69d1b)
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 
41f64cb652SScott Wood static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
421ac559d4STsiChungLiew {
431ac559d4STsiChungLiew 	struct nand_chip *this = mtdinfo->priv;
44*e4f69d1bSTsiChung 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 
49*e4f69d1bSTsiChung Liew 		IO_ADDR_W &= ~(SET_ALE | SET_CLE);
50*e4f69d1bSTsiChung Liew 		*nCE &= 0xFFFB;
51*e4f69d1bSTsiChung Liew 
52*e4f69d1bSTsiChung Liew 		if (ctrl & NAND_NCE)
53*e4f69d1bSTsiChung Liew 			*nCE |= 0x0004;
54f64cb652SScott Wood 		if (ctrl & NAND_CLE)
55f64cb652SScott Wood 			IO_ADDR_W |= SET_CLE;
56f64cb652SScott Wood 		if (ctrl & NAND_ALE)
57f64cb652SScott Wood 			IO_ADDR_W |= SET_ALE;
58f64cb652SScott Wood 
59f64cb652SScott Wood 		this->IO_ADDR_W = (void *)IO_ADDR_W;
60f64cb652SScott Wood 
611ac559d4STsiChungLiew 	}
621ac559d4STsiChungLiew 
63f64cb652SScott Wood 	if (cmd != NAND_CMD_NONE)
64f64cb652SScott Wood 		writeb(cmd, this->IO_ADDR_W);
651ac559d4STsiChungLiew }
661ac559d4STsiChungLiew 
671ac559d4STsiChungLiew int board_nand_init(struct nand_chip *nand)
681ac559d4STsiChungLiew {
691ac559d4STsiChungLiew 	volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
70f64cb652SScott Wood 	volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
711ac559d4STsiChungLiew 
72f64cb652SScott Wood 	fbcs->csmr2 &= ~FBCS_CSMR_WP;
731ac559d4STsiChungLiew 
74*e4f69d1bSTsiChung Liew 	/*
75*e4f69d1bSTsiChung Liew 	 * set up pin configuration - enabled 2nd output buffer's signals
76*e4f69d1bSTsiChung Liew 	 * (nand_ngpio - nCE USB1/2_PWR_EN, LATCH_GPIOs, LCD_VEEEN, etc)
77*e4f69d1bSTsiChung Liew 	 * to use nCE signal
78*e4f69d1bSTsiChung Liew 	 */
791ac559d4STsiChungLiew 	gpio->par_timer &= ~GPIO_PAR_TIN3_TIN3;
801ac559d4STsiChungLiew 	gpio->pddr_timer |= 0x08;
811ac559d4STsiChungLiew 	gpio->ppd_timer |= 0x08;
821ac559d4STsiChungLiew 	gpio->pclrr_timer = 0;
831ac559d4STsiChungLiew 	gpio->podr_timer = 0;
841ac559d4STsiChungLiew 
851ac559d4STsiChungLiew 	nand->chip_delay = 50;
86f64cb652SScott Wood 	nand->ecc.mode = NAND_ECC_SOFT;
87f64cb652SScott Wood 	nand->cmd_ctrl = nand_hwcontrol;
881ac559d4STsiChungLiew 
891ac559d4STsiChungLiew 	return 0;
901ac559d4STsiChungLiew }
911ac559d4STsiChungLiew #endif
92