Matthias Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd-electronics.com |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Matthias Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | |
Stefan Roese | a0f13d5 | 2007-08-15 21:06:27 +0200 | [diff] [blame] | 10 | #if defined(CONFIG_CMD_NAND) |
Matthias Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <nand.h> |
| 13 | |
| 14 | /* |
| 15 | * hardware specific access to control-lines |
| 16 | */ |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 17 | static void esd405ep_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
Matthias Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 18 | { |
William Juul | 9e9c2c1 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 19 | struct nand_chip *this = mtd->priv; |
| 20 | if (ctrl & NAND_CTRL_CHANGE) { |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 21 | if ( ctrl & NAND_CLE ) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 22 | out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_CLE); |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 23 | else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 24 | out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_NAND_CLE); |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 25 | if ( ctrl & NAND_ALE ) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 26 | out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_ALE); |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 27 | else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 28 | out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_NAND_ALE); |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 29 | if ( ctrl & NAND_NCE ) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 30 | out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_NAND_CE); |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 31 | else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 32 | out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_CE); |
Matthias Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 33 | } |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 34 | |
William Juul | 9e9c2c1 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 35 | if (cmd != NAND_CMD_NONE) |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 36 | writeb(cmd, this->IO_ADDR_W); |
Matthias Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | |
| 40 | /* |
| 41 | * read device ready pin |
| 42 | */ |
| 43 | static int esd405ep_nand_device_ready(struct mtd_info *mtdinfo) |
| 44 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | if (in_be32((void *)GPIO0_IR) & CONFIG_SYS_NAND_RDY) |
Matthias Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 46 | return 1; |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | int board_nand_init(struct nand_chip *nand) |
| 52 | { |
| 53 | /* |
| 54 | * Set NAND-FLASH GPIO signals to defaults |
| 55 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 56 | 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 Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Initialize nand_chip structure |
| 61 | */ |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 62 | nand->cmd_ctrl = esd405ep_nand_hwcontrol; |
Matthias Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 63 | nand->dev_ready = esd405ep_nand_device_ready; |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 64 | nand->ecc.mode = NAND_ECC_SOFT; |
Matthias Fuchs | c0d6f11 | 2007-07-09 10:10:04 +0200 | [diff] [blame] | 65 | nand->chip_delay = NAND_BIG_DELAY_US; |
| 66 | nand->options = NAND_SAMSUNG_LP_OPTIONS; |
| 67 | return 0; |
| 68 | } |
Stefan Roese | a0f13d5 | 2007-08-15 21:06:27 +0200 | [diff] [blame] | 69 | #endif |