xref: /openbmc/u-boot/board/freescale/m5329evb/nand.c (revision e4f69d1b)
11a33ce65STsiChungLiew /*
21a33ce65STsiChungLiew  * (C) Copyright 2000-2003
31a33ce65STsiChungLiew  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
41a33ce65STsiChungLiew  *
51a33ce65STsiChungLiew  * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
61a33ce65STsiChungLiew  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
71a33ce65STsiChungLiew  *
81a33ce65STsiChungLiew  * See file CREDITS for list of people who contributed to this
91a33ce65STsiChungLiew  * project.
101a33ce65STsiChungLiew  *
111a33ce65STsiChungLiew  * This program is free software; you can redistribute it and/or
121a33ce65STsiChungLiew  * modify it under the terms of the GNU General Public License as
131a33ce65STsiChungLiew  * published by the Free Software Foundation; either version 2 of
141a33ce65STsiChungLiew  * the License, or (at your option) any later version.
151a33ce65STsiChungLiew  *
161a33ce65STsiChungLiew  * This program is distributed in the hope that it will be useful,
171a33ce65STsiChungLiew  * but WITHOUT ANY WARRANTY; without even the implied warranty of
181a33ce65STsiChungLiew  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
191a33ce65STsiChungLiew  * GNU General Public License for more details.
201a33ce65STsiChungLiew  *
211a33ce65STsiChungLiew  * You should have received a copy of the GNU General Public License
221a33ce65STsiChungLiew  * along with this program; if not, write to the Free Software
231a33ce65STsiChungLiew  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
241a33ce65STsiChungLiew  * MA 02111-1307 USA
251a33ce65STsiChungLiew  */
261a33ce65STsiChungLiew 
271a33ce65STsiChungLiew #include <config.h>
281a33ce65STsiChungLiew #include <common.h>
291a33ce65STsiChungLiew #include <asm/io.h>
301a33ce65STsiChungLiew #include <asm/immap.h>
311a33ce65STsiChungLiew 
321a33ce65STsiChungLiew DECLARE_GLOBAL_DATA_PTR;
331a33ce65STsiChungLiew 
34ab77bc54STsiChungLiew #if defined(CONFIG_CMD_NAND)
351a33ce65STsiChungLiew #include <nand.h>
361a33ce65STsiChungLiew #include <linux/mtd/mtd.h>
371a33ce65STsiChungLiew 
381a33ce65STsiChungLiew #define SET_CLE		0x10
391a33ce65STsiChungLiew #define SET_ALE		0x08
401a33ce65STsiChungLiew 
41*e4f69d1bSTsiChung Liew static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
421a33ce65STsiChungLiew {
431a33ce65STsiChungLiew 	struct nand_chip *this = mtdinfo->priv;
44*e4f69d1bSTsiChung Liew 	volatile u16 *nCE = (u16 *) CONFIG_SYS_LATCH_ADDR;
451a33ce65STsiChungLiew 
46cfa460adSWilliam Juul 	if (ctrl & NAND_CTRL_CHANGE) {
47*e4f69d1bSTsiChung Liew 		ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
48*e4f69d1bSTsiChung Liew 
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;
54cfa460adSWilliam Juul 		if (ctrl & NAND_CLE)
55*e4f69d1bSTsiChung Liew 			IO_ADDR_W |= SET_CLE;
56cfa460adSWilliam Juul 		if (ctrl & NAND_ALE)
57*e4f69d1bSTsiChung Liew 			IO_ADDR_W |= SET_ALE;
58*e4f69d1bSTsiChung Liew 
59*e4f69d1bSTsiChung Liew 		this->IO_ADDR_W = (void *)IO_ADDR_W;
601a33ce65STsiChungLiew 	}
61cfa460adSWilliam Juul 
62cfa460adSWilliam Juul 	if (cmd != NAND_CMD_NONE)
63cfa460adSWilliam Juul 		writeb(cmd, this->IO_ADDR_W);
641a33ce65STsiChungLiew }
651a33ce65STsiChungLiew 
661a33ce65STsiChungLiew int board_nand_init(struct nand_chip *nand)
671a33ce65STsiChungLiew {
681a33ce65STsiChungLiew 	volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
691a33ce65STsiChungLiew 
70*e4f69d1bSTsiChung Liew 	/*
71*e4f69d1bSTsiChung Liew 	 * set up pin configuration - enabled 2nd output buffer's signals
72*e4f69d1bSTsiChung Liew 	 * (nand_ngpio - nCE USB1/2_PWR_EN, LATCH_GPIOs, LCD_VEEEN, etc)
73*e4f69d1bSTsiChung Liew 	 * to use nCE signal
74*e4f69d1bSTsiChung Liew 	 */
751a33ce65STsiChungLiew 	gpio->par_timer &= ~GPIO_PAR_TIN3_TIN3;
761a33ce65STsiChungLiew 	gpio->pddr_timer |= 0x08;
771a33ce65STsiChungLiew 	gpio->ppd_timer |= 0x08;
781a33ce65STsiChungLiew 	gpio->pclrr_timer = 0;
791a33ce65STsiChungLiew 	gpio->podr_timer = 0;
801a33ce65STsiChungLiew 
811a33ce65STsiChungLiew 	nand->chip_delay = 50;
82cfa460adSWilliam Juul 	nand->ecc.mode = NAND_ECC_SOFT;
83cfa460adSWilliam Juul 	nand->cmd_ctrl = nand_hwcontrol;
841a33ce65STsiChungLiew 
851a33ce65STsiChungLiew 	return 0;
861a33ce65STsiChungLiew }
871a33ce65STsiChungLiew #endif
88