xref: /openbmc/u-boot/board/freescale/m5329evb/nand.c (revision aa0d99fc)
11a33ce65STsiChungLiew /*
21a33ce65STsiChungLiew  * (C) Copyright 2000-2003
31a33ce65STsiChungLiew  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
41a33ce65STsiChungLiew  *
5*aa0d99fcSAlison Wang  * Copyright (C) 2004-2007, 2012 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 
41e4f69d1bSTsiChung Liew static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
421a33ce65STsiChungLiew {
431a33ce65STsiChungLiew 	struct nand_chip *this = mtdinfo->priv;
44e4f69d1bSTsiChung Liew 	volatile u16 *nCE = (u16 *) CONFIG_SYS_LATCH_ADDR;
451a33ce65STsiChungLiew 
46cfa460adSWilliam Juul 	if (ctrl & NAND_CTRL_CHANGE) {
47e4f69d1bSTsiChung Liew 		ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
48e4f69d1bSTsiChung Liew 
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 
56cfa460adSWilliam Juul 		if (ctrl & NAND_CLE)
57e4f69d1bSTsiChung Liew 			IO_ADDR_W |= SET_CLE;
58cfa460adSWilliam Juul 		if (ctrl & NAND_ALE)
59e4f69d1bSTsiChung Liew 			IO_ADDR_W |= SET_ALE;
60e4f69d1bSTsiChung Liew 
61e4f69d1bSTsiChung Liew 		this->IO_ADDR_W = (void *)IO_ADDR_W;
621a33ce65STsiChungLiew 	}
63cfa460adSWilliam Juul 
64cfa460adSWilliam Juul 	if (cmd != NAND_CMD_NONE)
65cfa460adSWilliam Juul 		writeb(cmd, this->IO_ADDR_W);
661a33ce65STsiChungLiew }
671a33ce65STsiChungLiew 
681a33ce65STsiChungLiew int board_nand_init(struct nand_chip *nand)
691a33ce65STsiChungLiew {
70*aa0d99fcSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
711a33ce65STsiChungLiew 
72e4f69d1bSTsiChung Liew 	/*
73e4f69d1bSTsiChung Liew 	 * set up pin configuration - enabled 2nd output buffer's signals
74e4f69d1bSTsiChung Liew 	 * (nand_ngpio - nCE USB1/2_PWR_EN, LATCH_GPIOs, LCD_VEEEN, etc)
75e4f69d1bSTsiChung Liew 	 * to use nCE signal
76e4f69d1bSTsiChung Liew 	 */
77*aa0d99fcSAlison Wang 	clrbits_8(&gpio->par_timer, GPIO_PAR_TIN3_TIN3);
78*aa0d99fcSAlison Wang 	setbits_8(&gpio->pddr_timer, 0x08);
79*aa0d99fcSAlison Wang 	setbits_8(&gpio->ppd_timer, 0x08);
80*aa0d99fcSAlison Wang 	out_8(&gpio->pclrr_timer, 0);
81*aa0d99fcSAlison Wang 	out_8(&gpio->podr_timer, 0);
821a33ce65STsiChungLiew 
839017d932STsiChung Liew 	nand->chip_delay = 60;
84cfa460adSWilliam Juul 	nand->ecc.mode = NAND_ECC_SOFT;
85cfa460adSWilliam Juul 	nand->cmd_ctrl = nand_hwcontrol;
861a33ce65STsiChungLiew 
871a33ce65STsiChungLiew 	return 0;
881a33ce65STsiChungLiew }
891a33ce65STsiChungLiew #endif
90