Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2006 DENX Software Engineering |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 8 | #include <asm/io.h> |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 9 | |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 10 | #if defined(CONFIG_CMD_NAND) |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 11 | |
| 12 | #include <nand.h> |
| 13 | |
| 14 | /* |
| 15 | * hardware specific access to control-lines |
| 16 | * function borrowed from Linux 2.6 (drivers/mtd/nand/ppchameleonevb.c) |
| 17 | */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 18 | static void ppchameleonevb_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 19 | { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 20 | struct nand_chip *this = mtd->priv; |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 21 | ulong base = (ulong) this->IO_ADDR_W; |
| 22 | |
William Juul | 5e1dae5 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 23 | if (ctrl & NAND_CTRL_CHANGE) { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 24 | if ( ctrl & NAND_CLE ) |
| 25 | MACRO_NAND_CTL_SETCLE((unsigned long)base); |
| 26 | else |
| 27 | MACRO_NAND_CTL_CLRCLE((unsigned long)base); |
| 28 | if ( ctrl & NAND_ALE ) |
| 29 | MACRO_NAND_CTL_CLRCLE((unsigned long)base); |
| 30 | else |
| 31 | MACRO_NAND_CTL_CLRALE((unsigned long)base); |
| 32 | if ( ctrl & NAND_NCE ) |
| 33 | MACRO_NAND_ENABLE_CE((unsigned long)base); |
| 34 | else |
| 35 | MACRO_NAND_DISABLE_CE((unsigned long)base); |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 36 | } |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 37 | |
William Juul | 5e1dae5 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 38 | if (cmd != NAND_CMD_NONE) |
William Juul | 4cbb651 | 2007-11-08 10:39:53 +0100 | [diff] [blame] | 39 | writeb(cmd, this->IO_ADDR_W); |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | |
| 43 | /* |
| 44 | * read device ready pin |
| 45 | * function +/- borrowed from Linux 2.6 (drivers/mtd/nand/ppchameleonevb.c) |
| 46 | */ |
| 47 | static int ppchameleonevb_device_ready(struct mtd_info *mtdinfo) |
| 48 | { |
| 49 | struct nand_chip *this = mtdinfo->priv; |
| 50 | ulong rb_gpio_pin; |
| 51 | |
| 52 | /* use the base addr to find out which chip are we dealing with */ |
| 53 | switch((ulong) this->IO_ADDR_W) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 54 | case CONFIG_SYS_NAND0_BASE: |
| 55 | rb_gpio_pin = CONFIG_SYS_NAND0_RDY; |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 56 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 57 | case CONFIG_SYS_NAND1_BASE: |
| 58 | rb_gpio_pin = CONFIG_SYS_NAND1_RDY; |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 59 | break; |
| 60 | default: /* this should never happen */ |
| 61 | return 0; |
| 62 | break; |
| 63 | } |
| 64 | |
Wolfgang Denk | bfc8125 | 2006-03-06 13:03:37 +0100 | [diff] [blame] | 65 | if (in32(GPIO0_IR) & rb_gpio_pin) |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 66 | return 1; |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /* |
| 72 | * Board-specific NAND initialization. The following members of the |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 73 | * argument are board-specific (per include/linux/mtd/nand.h): |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 74 | * - IO_ADDR_R?: address to read the 8 I/O lines of the flash device |
| 75 | * - IO_ADDR_W?: address to write the 8 I/O lines of the flash device |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 76 | * - cmd_ctrl: hardwarespecific function for accesing control-lines |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 77 | * - dev_ready: hardwarespecific function for accesing device ready/busy line |
| 78 | * - enable_hwecc?: function to enable (reset) hardware ecc generator. Must |
| 79 | * only be provided if a hardware ECC is available |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 80 | * - ecc.mode: mode of ecc, see defines |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 81 | * - chip_delay: chip dependent delay for transfering data from array to |
| 82 | * read regs (tR) |
| 83 | * - options: various chip options. They can partly be set to inform |
| 84 | * nand_scan about special functionality. See the defines for further |
| 85 | * explanation |
| 86 | * Members with a "?" were not set in the merged testing-NAND branch, |
| 87 | * so they are not set here either. |
| 88 | */ |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 89 | int board_nand_init(struct nand_chip *nand) |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 90 | { |
| 91 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 92 | nand->cmd_ctrl = ppchameleonevb_hwcontrol; |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 93 | nand->dev_ready = ppchameleonevb_device_ready; |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 94 | nand->ecc.mode = NAND_ECC_SOFT; |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 95 | nand->chip_delay = NAND_BIG_DELAY_US; |
| 96 | nand->options = NAND_SAMSUNG_LP_OPTIONS; |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 97 | return 0; |
Bartlomiej Sieka | 038ccac | 2006-02-24 09:37:22 +0100 | [diff] [blame] | 98 | } |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 99 | #endif |