[U-Boot] [PATCH 8/9] Add NAND support for TS-7800

Michael Spang mspang at csclub.uwaterloo.ca
Thu Mar 17 20:47:02 CET 2011


The NAND control functions were written by Alexander Clouter and
copied here from Linux.

Signed-off-by: Michael Spang <mspang at csclub.uwaterloo.ca>
---
 drivers/mtd/nand/Makefile      |    1 +
 drivers/mtd/nand/ts7800_nand.c |   68 ++++++++++++++++++++++++++++++++++++++++
 include/configs/ts7800.h       |   47 ++++++++++++++++++++++++++--
 3 files changed, 113 insertions(+), 3 deletions(-)
 create mode 100644 drivers/mtd/nand/ts7800_nand.c

diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index 8b598f6..897e6c2 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -49,6 +49,7 @@ COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o
 COBJS-$(CONFIG_NAND_S3C64XX) += s3c64xx.o
 COBJS-$(CONFIG_NAND_SPEAR) += spr_nand.o
 COBJS-$(CONFIG_NAND_OMAP_GPMC) += omap_gpmc.o
+COBJS-$(CONFIG_NAND_TS7800) += ts7800_nand.o
 COBJS-$(CONFIG_NAND_PLAT) += nand_plat.o
 endif
 
diff --git a/drivers/mtd/nand/ts7800_nand.c b/drivers/mtd/nand/ts7800_nand.c
new file mode 100644
index 0000000..8b9fe0c
--- /dev/null
+++ b/drivers/mtd/nand/ts7800_nand.c
@@ -0,0 +1,68 @@
+/*
+ * Based on arch/arm/mach-orion5x/ts78xx-setup.c from Linux
+ * by Alexander Clouter <alex at digriz.org.uk>.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <nand.h>
+
+/*
+ * hardware specific access to control-lines
+ *
+ * ctrl:
+ * NAND_NCE: bit 0 -> bit 2
+ * NAND_CLE: bit 1 -> bit 1
+ * NAND_ALE: bit 2 -> bit 0
+ */
+static void ts78xx_ts_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
+			unsigned int ctrl)
+{
+	struct nand_chip *this = mtd->priv;
+
+	if (ctrl & NAND_CTRL_CHANGE) {
+		unsigned char bits;
+
+		bits = (ctrl & NAND_NCE) << 2;
+		bits |= ctrl & NAND_CLE;
+		bits |= (ctrl & NAND_ALE) >> 2;
+
+		writeb((readb(TS_NAND_CTRL) & ~0x7) | bits, TS_NAND_CTRL);
+	}
+
+	if (cmd != NAND_CMD_NONE)
+		writeb(cmd, this->IO_ADDR_W);
+}
+
+static int ts78xx_ts_nand_dev_ready(struct mtd_info *mtd)
+{
+	return readb(TS_NAND_CTRL) & 0x20;
+}
+
+int board_nand_init(struct nand_chip *nand)
+{
+	nand->options = NAND_USE_FLASH_BBT;
+	nand->ecc.mode = NAND_ECC_SOFT;
+	nand->cmd_ctrl = ts78xx_ts_nand_cmd_ctrl;
+	nand->dev_ready = ts78xx_ts_nand_dev_ready;
+	nand->chip_delay = 15;
+	return 0;
+}
diff --git a/include/configs/ts7800.h b/include/configs/ts7800.h
index c07d132..0d8cc10 100644
--- a/include/configs/ts7800.h
+++ b/include/configs/ts7800.h
@@ -33,10 +33,11 @@
 #define CONFIG_BOOTDELAY	3
 
 /*
- * Flash Driver
+ * Flash Configuration
  */
 
-#define CONFIG_SYS_NO_FLASH
+#define CONFIG_SYS_NO_FLASH		/* TS-7800 has only NAND flash */
+#define CONFIG_USE_NAND		0	/* Disable NAND by default */
 
 /*
  * Commands Configuration
@@ -46,6 +47,11 @@
 #define CONFIG_CMD_PING
 #define CONFIG_CMD_MII
 
+#if CONFIG_USE_NAND
+#define CONFIG_CMD_NAND
+#define CONFIG_CMD_MTDPARTS
+#endif
+
 /*
  * Serial Port Configuration
  */
@@ -57,9 +63,21 @@
  * Environment Configuration
  */
 
-#define CONFIG_ENV_IS_NOWHERE	1
+#if CONFIG_USE_NAND
+
+#define CONFIG_ENV_IS_IN_NAND
+
+#define CONFIG_ENV_OFFSET	0x00320000 /* 128k(mbr) + 3m(kernel) */
+#define CONFIG_ENV_SIZE		0x00020000 /* 128k */
+#define CONFIG_ENV_RANGE	0x00100000 /* 1m(env) */
+
+#else
+
+#define CONFIG_ENV_IS_NOWHERE
 #define CONFIG_ENV_SIZE		0x2000
 
+#endif
+
 /*
  * Limits
  */
@@ -112,6 +130,29 @@
 #define CONFIG_SYS_MEMTEST_START	0x00001000
 #define CONFIG_SYS_MEMTEST_END		0x07e00000
 
+#define ORION5X_ADR_PCI_MEM	0xe8000000 /* Match Linux (FPGA) */
+#define ORION5X_SZ_PCI_MEM	0x08000000
+
+/*
+ * Flash Driver
+ */
+
+#ifdef CONFIG_CMD_NAND
+
+#define TS_NAND_CTRL	0xe8000800
+#define TS_NAND_DATA	0xe8000804
+
+#define CONFIG_NAND_TS7800
+#define CONFIG_SYS_NAND_BASE		TS_NAND_DATA
+#define CONFIG_SYS_MAX_NAND_DEVICE	1
+
+#define CONFIG_MTD_DEVICE
+#define MTDIDS_DEFAULT		"nand0=gen_nand"
+#define MTDPARTS_DEFAULT \
+	"mtdparts=gen_nand:128k(mbr),3m(uboot),1m(env),4m(linux),-(rootfs)"
+
+#endif
+
 /*
  * UART Driver
  */
-- 
1.7.2.3



More information about the U-Boot mailing list