blob: a191a0c3a920d05758a0a8dcfe3f76bdbfbb60f8 [file] [log] [blame]
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +01001/*
2 * (C) Copyright 2006 DENX Software Engineering
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +01005 */
6
7#include <common.h>
William Juulcfa460a2007-10-31 13:53:06 +01008#include <asm/io.h>
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +01009
Jon Loeligerb9307262007-07-09 18:24:55 -050010#if defined(CONFIG_CMD_NAND)
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010011
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 Juulcfa460a2007-10-31 13:53:06 +010018static void ppchameleonevb_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010019{
William Juulcfa460a2007-10-31 13:53:06 +010020 struct nand_chip *this = mtd->priv;
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010021 ulong base = (ulong) this->IO_ADDR_W;
22
William Juul5e1dae52007-11-09 13:32:30 +010023 if (ctrl & NAND_CTRL_CHANGE) {
William Juulcfa460a2007-10-31 13:53:06 +010024 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 Sieka038ccac2006-02-24 09:37:22 +010036 }
William Juulcfa460a2007-10-31 13:53:06 +010037
William Juul5e1dae52007-11-09 13:32:30 +010038 if (cmd != NAND_CMD_NONE)
William Juul4cbb6512007-11-08 10:39:53 +010039 writeb(cmd, this->IO_ADDR_W);
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010040}
41
42
43/*
44 * read device ready pin
45 * function +/- borrowed from Linux 2.6 (drivers/mtd/nand/ppchameleonevb.c)
46 */
47static 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-VILLARD6d0f6bc2008-10-16 15:01:15 +020054 case CONFIG_SYS_NAND0_BASE:
55 rb_gpio_pin = CONFIG_SYS_NAND0_RDY;
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010056 break;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020057 case CONFIG_SYS_NAND1_BASE:
58 rb_gpio_pin = CONFIG_SYS_NAND1_RDY;
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010059 break;
60 default: /* this should never happen */
61 return 0;
62 break;
63 }
64
Wolfgang Denkbfc81252006-03-06 13:03:37 +010065 if (in32(GPIO0_IR) & rb_gpio_pin)
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010066 return 1;
67 return 0;
68}
69
70
71/*
72 * Board-specific NAND initialization. The following members of the
Bartlomiej Siekaaddb2e12006-03-05 18:57:33 +010073 * argument are board-specific (per include/linux/mtd/nand.h):
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010074 * - 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 Juulcfa460a2007-10-31 13:53:06 +010076 * - cmd_ctrl: hardwarespecific function for accesing control-lines
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010077 * - 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 Juulcfa460a2007-10-31 13:53:06 +010080 * - ecc.mode: mode of ecc, see defines
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010081 * - 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 Schocherfa230442006-12-21 17:17:02 +010089int board_nand_init(struct nand_chip *nand)
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010090{
91
William Juulcfa460a2007-10-31 13:53:06 +010092 nand->cmd_ctrl = ppchameleonevb_hwcontrol;
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010093 nand->dev_ready = ppchameleonevb_device_ready;
William Juulcfa460a2007-10-31 13:53:06 +010094 nand->ecc.mode = NAND_ECC_SOFT;
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010095 nand->chip_delay = NAND_BIG_DELAY_US;
96 nand->options = NAND_SAMSUNG_LP_OPTIONS;
Heiko Schocherfa230442006-12-21 17:17:02 +010097 return 0;
Bartlomiej Sieka038ccac2006-02-24 09:37:22 +010098}
Jon Loeligerb9307262007-07-09 18:24:55 -050099#endif