blob: f46936ca3667223dc53d9e214ec62da6bc3bdcec [file] [log] [blame]
Matthias Fuchsc0d6f112007-07-09 10:10:04 +02001/*
2 * (C) Copyright 2007
3 * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd-electronics.com
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Matthias Fuchsc0d6f112007-07-09 10:10:04 +02006 */
7
8#include <common.h>
9
Stefan Roesea0f13d52007-08-15 21:06:27 +020010#if defined(CONFIG_CMD_NAND)
Matthias Fuchsc0d6f112007-07-09 10:10:04 +020011#include <asm/io.h>
12#include <nand.h>
13
14/*
15 * hardware specific access to control-lines
16 */
William Juul52c07962007-10-31 13:53:06 +010017static void esd405ep_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
Matthias Fuchsc0d6f112007-07-09 10:10:04 +020018{
William Juul9e9c2c12007-11-09 13:32:30 +010019 struct nand_chip *this = mtd->priv;
20 if (ctrl & NAND_CTRL_CHANGE) {
William Juul52c07962007-10-31 13:53:06 +010021 if ( ctrl & NAND_CLE )
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020022 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_CLE);
William Juul52c07962007-10-31 13:53:06 +010023 else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020024 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_NAND_CLE);
William Juul52c07962007-10-31 13:53:06 +010025 if ( ctrl & NAND_ALE )
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020026 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_ALE);
William Juul52c07962007-10-31 13:53:06 +010027 else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020028 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_NAND_ALE);
William Juul52c07962007-10-31 13:53:06 +010029 if ( ctrl & NAND_NCE )
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020030 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_NAND_CE);
William Juul52c07962007-10-31 13:53:06 +010031 else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020032 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_CE);
Matthias Fuchsc0d6f112007-07-09 10:10:04 +020033 }
William Juul52c07962007-10-31 13:53:06 +010034
William Juul9e9c2c12007-11-09 13:32:30 +010035 if (cmd != NAND_CMD_NONE)
William Juul52c07962007-10-31 13:53:06 +010036 writeb(cmd, this->IO_ADDR_W);
Matthias Fuchsc0d6f112007-07-09 10:10:04 +020037}
38
39
40/*
41 * read device ready pin
42 */
43static int esd405ep_nand_device_ready(struct mtd_info *mtdinfo)
44{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045 if (in_be32((void *)GPIO0_IR) & CONFIG_SYS_NAND_RDY)
Matthias Fuchsc0d6f112007-07-09 10:10:04 +020046 return 1;
47 return 0;
48}
49
50
51int board_nand_init(struct nand_chip *nand)
52{
53 /*
54 * Set NAND-FLASH GPIO signals to defaults
55 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020056 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~(CONFIG_SYS_NAND_CLE | CONFIG_SYS_NAND_ALE));
57 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_CE);
Matthias Fuchsc0d6f112007-07-09 10:10:04 +020058
59 /*
60 * Initialize nand_chip structure
61 */
William Juul52c07962007-10-31 13:53:06 +010062 nand->cmd_ctrl = esd405ep_nand_hwcontrol;
Matthias Fuchsc0d6f112007-07-09 10:10:04 +020063 nand->dev_ready = esd405ep_nand_device_ready;
William Juul52c07962007-10-31 13:53:06 +010064 nand->ecc.mode = NAND_ECC_SOFT;
Matthias Fuchsc0d6f112007-07-09 10:10:04 +020065 nand->chip_delay = NAND_BIG_DELAY_US;
66 nand->options = NAND_SAMSUNG_LP_OPTIONS;
67 return 0;
68}
Stefan Roesea0f13d52007-08-15 21:06:27 +020069#endif