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 CLR_CLE ~SET_CLE 401a33ce65STsiChungLiew #define SET_ALE 0x08 411a33ce65STsiChungLiew #define CLR_ALE ~SET_ALE 421a33ce65STsiChungLiew 43*cfa460adSWilliam Juul static void nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) 441a33ce65STsiChungLiew { 451a33ce65STsiChungLiew struct nand_chip *this = mtdinfo->priv; 46*cfa460adSWilliam Juul /* volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS; TODO: handle wp */ 471a33ce65STsiChungLiew u32 nand_baseaddr = (u32) this->IO_ADDR_W; 481a33ce65STsiChungLiew 49*cfa460adSWilliam Juul if (ctrl & NAND_CTRL_CHANGE) { 50*cfa460adSWilliam Juul if ( ctrl & NAND_CLE ) 511a33ce65STsiChungLiew nand_baseaddr |= SET_CLE; 52*cfa460adSWilliam Juul else 531a33ce65STsiChungLiew nand_baseaddr &= CLR_CLE; 54*cfa460adSWilliam Juul if ( ctrl & NAND_ALE ) 551a33ce65STsiChungLiew nand_baseaddr |= SET_ALE; 56*cfa460adSWilliam Juul else 57*cfa460adSWilliam Juul nand_baseaddr &= CLR_ALE; 581a33ce65STsiChungLiew } 591a33ce65STsiChungLiew this->IO_ADDR_W = (void __iomem *)(nand_baseaddr); 60*cfa460adSWilliam Juul 61*cfa460adSWilliam Juul if (cmd != NAND_CMD_NONE) 62*cfa460adSWilliam Juul writeb(cmd, this->IO_ADDR_W); 631a33ce65STsiChungLiew } 641a33ce65STsiChungLiew 651a33ce65STsiChungLiew static void nand_write_byte(struct mtd_info *mtdinfo, u_char byte) 661a33ce65STsiChungLiew { 671a33ce65STsiChungLiew struct nand_chip *this = mtdinfo->priv; 681a33ce65STsiChungLiew *((volatile u8 *)(this->IO_ADDR_W)) = byte; 691a33ce65STsiChungLiew } 701a33ce65STsiChungLiew 711a33ce65STsiChungLiew static u8 nand_read_byte(struct mtd_info *mtdinfo) 721a33ce65STsiChungLiew { 731a33ce65STsiChungLiew struct nand_chip *this = mtdinfo->priv; 741a33ce65STsiChungLiew return (u8) (*((volatile u8 *)this->IO_ADDR_R)); 751a33ce65STsiChungLiew } 761a33ce65STsiChungLiew 771a33ce65STsiChungLiew static int nand_dev_ready(struct mtd_info *mtdinfo) 781a33ce65STsiChungLiew { 791a33ce65STsiChungLiew return 1; 801a33ce65STsiChungLiew } 811a33ce65STsiChungLiew 821a33ce65STsiChungLiew int board_nand_init(struct nand_chip *nand) 831a33ce65STsiChungLiew { 841a33ce65STsiChungLiew volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO; 851a33ce65STsiChungLiew 861a33ce65STsiChungLiew *((volatile u16 *)CFG_LATCH_ADDR) |= 0x0004; 871a33ce65STsiChungLiew 881a33ce65STsiChungLiew /* set up pin configuration */ 891a33ce65STsiChungLiew gpio->par_timer &= ~GPIO_PAR_TIN3_TIN3; 901a33ce65STsiChungLiew gpio->pddr_timer |= 0x08; 911a33ce65STsiChungLiew gpio->ppd_timer |= 0x08; 921a33ce65STsiChungLiew gpio->pclrr_timer = 0; 931a33ce65STsiChungLiew gpio->podr_timer = 0; 941a33ce65STsiChungLiew 951a33ce65STsiChungLiew nand->chip_delay = 50; 96*cfa460adSWilliam Juul nand->ecc.mode = NAND_ECC_SOFT; 97*cfa460adSWilliam Juul nand->cmd_ctrl = nand_hwcontrol; 981a33ce65STsiChungLiew nand->read_byte = nand_read_byte; 991a33ce65STsiChungLiew nand->write_byte = nand_write_byte; 1001a33ce65STsiChungLiew nand->dev_ready = nand_dev_ready; 1011a33ce65STsiChungLiew 1021a33ce65STsiChungLiew return 0; 1031a33ce65STsiChungLiew } 1041a33ce65STsiChungLiew #endif 105