xref: /openbmc/u-boot/board/freescale/m5329evb/nand.c (revision ab77bc54)
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 
34*ab77bc54STsiChungLiew #if defined(CONFIG_CMD_NAND)
351a33ce65STsiChungLiew #include <nand.h>
361a33ce65STsiChungLiew #include <linux/mtd/mtd.h>
371a33ce65STsiChungLiew 
381a33ce65STsiChungLiew #define SET_CLE		0x10
391a33ce65STsiChungLiew #define CLR_CLE		~SET_CLE
401a33ce65STsiChungLiew #define SET_ALE		0x08
411a33ce65STsiChungLiew #define CLR_ALE		~SET_ALE
421a33ce65STsiChungLiew 
431a33ce65STsiChungLiew static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd)
441a33ce65STsiChungLiew {
451a33ce65STsiChungLiew 	struct nand_chip *this = mtdinfo->priv;
461a33ce65STsiChungLiew 	volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
471a33ce65STsiChungLiew 	u32 nand_baseaddr = (u32) this->IO_ADDR_W;
481a33ce65STsiChungLiew 
491a33ce65STsiChungLiew 	switch (cmd) {
501a33ce65STsiChungLiew 	case NAND_CTL_SETNCE:
511a33ce65STsiChungLiew 	case NAND_CTL_CLRNCE:
521a33ce65STsiChungLiew 		break;
531a33ce65STsiChungLiew 	case NAND_CTL_SETCLE:
541a33ce65STsiChungLiew 		nand_baseaddr |= SET_CLE;
551a33ce65STsiChungLiew 		break;
561a33ce65STsiChungLiew 	case NAND_CTL_CLRCLE:
571a33ce65STsiChungLiew 		nand_baseaddr &= CLR_CLE;
581a33ce65STsiChungLiew 		break;
591a33ce65STsiChungLiew 	case NAND_CTL_SETALE:
601a33ce65STsiChungLiew 		nand_baseaddr |= SET_ALE;
611a33ce65STsiChungLiew 		break;
621a33ce65STsiChungLiew 	case NAND_CTL_CLRALE:
631a33ce65STsiChungLiew 		nand_baseaddr |= CLR_ALE;
641a33ce65STsiChungLiew 		break;
651a33ce65STsiChungLiew 	case NAND_CTL_SETWP:
661a33ce65STsiChungLiew 		fbcs->csmr2 |= CSMR_WP;
671a33ce65STsiChungLiew 		break;
681a33ce65STsiChungLiew 	case NAND_CTL_CLRWP:
691a33ce65STsiChungLiew 		fbcs->csmr2 &= ~CSMR_WP;
701a33ce65STsiChungLiew 		break;
711a33ce65STsiChungLiew 	}
721a33ce65STsiChungLiew 	this->IO_ADDR_W = (void __iomem *)(nand_baseaddr);
731a33ce65STsiChungLiew }
741a33ce65STsiChungLiew 
751a33ce65STsiChungLiew static void nand_write_byte(struct mtd_info *mtdinfo, u_char byte)
761a33ce65STsiChungLiew {
771a33ce65STsiChungLiew 	struct nand_chip *this = mtdinfo->priv;
781a33ce65STsiChungLiew 	*((volatile u8 *)(this->IO_ADDR_W)) = byte;
791a33ce65STsiChungLiew }
801a33ce65STsiChungLiew 
811a33ce65STsiChungLiew static u8 nand_read_byte(struct mtd_info *mtdinfo)
821a33ce65STsiChungLiew {
831a33ce65STsiChungLiew 	struct nand_chip *this = mtdinfo->priv;
841a33ce65STsiChungLiew 	return (u8) (*((volatile u8 *)this->IO_ADDR_R));
851a33ce65STsiChungLiew }
861a33ce65STsiChungLiew 
871a33ce65STsiChungLiew static int nand_dev_ready(struct mtd_info *mtdinfo)
881a33ce65STsiChungLiew {
891a33ce65STsiChungLiew 	return 1;
901a33ce65STsiChungLiew }
911a33ce65STsiChungLiew 
921a33ce65STsiChungLiew int board_nand_init(struct nand_chip *nand)
931a33ce65STsiChungLiew {
941a33ce65STsiChungLiew 	volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
951a33ce65STsiChungLiew 
961a33ce65STsiChungLiew 	*((volatile u16 *)CFG_LATCH_ADDR) |= 0x0004;
971a33ce65STsiChungLiew 
981a33ce65STsiChungLiew 	/* set up pin configuration */
991a33ce65STsiChungLiew 	gpio->par_timer &= ~GPIO_PAR_TIN3_TIN3;
1001a33ce65STsiChungLiew 	gpio->pddr_timer |= 0x08;
1011a33ce65STsiChungLiew 	gpio->ppd_timer |= 0x08;
1021a33ce65STsiChungLiew 	gpio->pclrr_timer = 0;
1031a33ce65STsiChungLiew 	gpio->podr_timer = 0;
1041a33ce65STsiChungLiew 
1051a33ce65STsiChungLiew 	nand->chip_delay = 50;
1061a33ce65STsiChungLiew 	nand->eccmode = NAND_ECC_SOFT;
1071a33ce65STsiChungLiew 	nand->hwcontrol = nand_hwcontrol;
1081a33ce65STsiChungLiew 	nand->read_byte = nand_read_byte;
1091a33ce65STsiChungLiew 	nand->write_byte = nand_write_byte;
1101a33ce65STsiChungLiew 	nand->dev_ready = nand_dev_ready;
1111a33ce65STsiChungLiew 
1121a33ce65STsiChungLiew 	return 0;
1131a33ce65STsiChungLiew }
1141a33ce65STsiChungLiew #endif
115