Skip to contentSkip to conversation

Nand driver for Nomadik 8815 SoC (on NHK8815 board)

PATCH Superseded Alessandro Rubini 2 participants 2 messages Mar 12, 2009 – Apr 13, 2009

Subsystems (5)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Nand driver for Nomadik 8815 SoC (on NHK8815 board)

From: Alessandro Rubini <[email protected]>

The patch is incremental over base Nomadik support as posted to linux-arm-kernel.
---

V2: rebased over cleaned-up base nomadik support.

The new nomadik patch is available in full from

http://gnudd.com/pub/patches/nomadik/

         Add-basic-support-for-ST-Nomadik-8815-SoC-V2.patch

The version posted to linux-arm-kernel misses the
default configuration file for size reasons.

 arch/arm/configs/nhk15_defconfig              |    1 +
 arch/arm/mach-nomadik/board-8815nhk.c         |   93 +++++++-
 arch/arm/mach-nomadik/include/mach/fsmc.h     |   36 +++
 arch/arm/mach-nomadik/include/mach/hardware.h |    5 +-
 arch/arm/mach-nomadik/include/mach/nand.h     |   16 ++
 drivers/mtd/nand/Kconfig                      |    6 +
 drivers/mtd/nand/Makefile                     |    1 +
 drivers/mtd/nand/nomadik_nand.c               |  329 +++++++++++++++++++++++++
 8 files changed, 484 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-nomadik/include/mach/fsmc.h
 create mode 100644 arch/arm/mach-nomadik/include/mach/nand.h
 create mode 100644 drivers/mtd/nand/nomadik_nand.c
arch/arm/configs/nhk15_defconfig +1 -0
index cf11d79..1697efe 100644
@@ -476,6 +476,7 @@ CONFIG_MTD_NAND_IDS=y
 # CONFIG_MTD_NAND_DISKONCHIP is not set
 # CONFIG_MTD_NAND_NANDSIM is not set
 # CONFIG_MTD_NAND_PLATFORM is not set
+CONFIG_MTD_NAND_NOMADIK=y
 # CONFIG_MTD_ONENAND is not set
 
 #
arch/arm/mach-nomadik/board-8815nhk.c +92 -1

107 lines not on this page · raw message

arch/arm/mach-nomadik/include/mach/fsmc.h new file +36 -0
new file mode 100644
index 0000000..f81621c
@@ -0,0 +1,36 @@
+
+/* Definitions for the Nomadik FSMC "Flexible Static Memory controller" */
+
+#ifndef __ASM_ARCH_FSMC_H
+#define __ASM_ARCH_FSMC_H
+
+#include <mach/hardware.h>
+/*
+ * Register list
+ */
+
+/* control and timing registers for CS0..CS3 */
+#define FSMC_BCR0	((void __iomem *)(NOMADIK_FSMC_VA + 0x00))
+#define FSMC_BTR0	((void __iomem *)(NOMADIK_FSMC_VA + 0x04))
+#define FSMC_BCR1	((void __iomem *)(NOMADIK_FSMC_VA + 0x08))
+#define FSMC_BTR1	((void __iomem *)(NOMADIK_FSMC_VA + 0x0c))
+#define FSMC_BCR2	((void __iomem *)(NOMADIK_FSMC_VA + 0x10))
+#define FSMC_BTR2	((void __iomem *)(NOMADIK_FSMC_VA + 0x14))
+#define FSMC_BCR3	((void __iomem *)(NOMADIK_FSMC_VA + 0x18))
+#define FSMC_BTR3	((void __iomem *)(NOMADIK_FSMC_VA + 0x1c))
+
+/* pc-card and nand flash */
+#define FSMC_PCR0	((void __iomem *)(NOMADIK_FSMC_VA + 0x40))
+#define FSMC_PMEM0	((void __iomem *)(NOMADIK_FSMC_VA + 0x48))
+#define FSMC_PATT0	((void __iomem *)(NOMADIK_FSMC_VA + 0x4c))
+#define FSMC_PIO0	((void __iomem *)(NOMADIK_FSMC_VA + 0x50))
+#define FSMC_PECCR0	((void __iomem *)(NOMADIK_FSMC_VA + 0x54))
+
+#define FSMC_PCR1	((void __iomem *)(NOMADIK_FSMC_VA + 0x60))
+#define FSMC_PMEM1	((void __iomem *)(NOMADIK_FSMC_VA + 0x68))
+#define FSMC_PATT1	((void __iomem *)(NOMADIK_FSMC_VA + 0x6c))
+#define FSMC_PIO1	((void __iomem *)(NOMADIK_FSMC_VA + 0x70))
+#define FSMC_PECCR1	((void __iomem *)(NOMADIK_FSMC_VA + 0x74))
+
+
+#endif /* __ASM_ARCH_FSMC_H */
arch/arm/mach-nomadik/include/mach/hardware.h +3 -2
index 8cdee9b..05ea93b 100644
@@ -82,7 +82,8 @@
 #define NOMADIK_HAMACA_DMEM	0xA0200000	/* HAMACA Data Memory Space */
 
 
-#define NOMADIK_MTU0_VA (IO_ADDRESS(NOMADIK_MTU0_BASE))
-#define NOMADIK_MTU1_VA (IO_ADDRESS(NOMADIK_MTU1_BASE))
+#define NOMADIK_FSMC_VA		IO_ADDRESS(NOMADIK_FSMC_BASE)
+#define NOMADIK_MTU0_VA		IO_ADDRESS(NOMADIK_MTU0_BASE)
+#define NOMADIK_MTU1_VA		IO_ADDRESS(NOMADIK_MTU1_BASE)
 
 #endif /* __ASM_ARCH_HARDWARE_H */
arch/arm/mach-nomadik/include/mach/nand.h new file +16 -0
new file mode 100644
index 0000000..c3c8254
@@ -0,0 +1,16 @@
+#ifndef __ASM_ARCH_NAND_H
+#define __ASM_ARCH_NAND_H
+
+struct nomadik_nand_platform_data {
+	struct mtd_partition *parts;
+	int nparts;
+	int options;
+	int (*init) (void);
+	int (*exit) (void);
+};
+
+#define NAND_IO_DATA	0x40000000
+#define NAND_IO_CMD	0x40800000
+#define NAND_IO_ADDR	0x41000000
+
+#endif				/* __ASM_ARCH_NAND_H */
drivers/mtd/nand/Kconfig +6 -0
index 8b12e6e..41b4fc7 100644
@@ -420,6 +420,12 @@ config MTD_NAND_MXC
 	  This enables the driver for the NAND flash controller on the
 	  MXC processors.
 
+config MTD_NAND_NOMADIK
+	tristate "ST Nomadik 8815 NAND support"
+	depends on ARCH_NOMADIK
+	help
+	  Driver for the NAND flash controller on the Nomadik, with ECC.
+
 config MTD_NAND_SH_FLCTL
 	tristate "Support for NAND on Renesas SuperH FLCTL"
 	depends on MTD_NAND && SUPERH && CPU_SUBTYPE_SH7723
drivers/mtd/nand/Makefile +1 -0
index b661586..06acb94 100644
@@ -36,5 +36,6 @@ obj-$(CONFIG_MTD_NAND_FSL_ELBC)		+= fsl_elbc_nand.o
 obj-$(CONFIG_MTD_NAND_FSL_UPM)		+= fsl_upm.o
 obj-$(CONFIG_MTD_NAND_SH_FLCTL)		+= sh_flctl.o
 obj-$(CONFIG_MTD_NAND_MXC)		+= mxc_nand.o
+obj-$(CONFIG_MTD_NAND_NOMADIK)		+= nomadik_nand.o
 
 nand-objs := nand_base.o nand_bbt.o
drivers/mtd/nand/nomadik_nand.c new file +329 -0

329 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 94 lines · Alessandro Rubini

From: Alessandro Rubini <[email protected]>

The patch is incremental over base Nomadik support as posted to linux-arm-kernel.
---

V2: rebased over cleaned-up base nomadik support.

The new nomadik patch is available in full from

http://gnudd.com/pub/patches/nomadik/

         Add-basic-support-for-ST-Nomadik-8815-SoC-V2.patch

The version posted to linux-arm-kernel misses the
default configuration file for size reasons.

 arch/arm/configs/nhk15_defconfig              |    1 +
 arch/arm/mach-nomadik/board-8815nhk.c         |   93 +++++++-
 arch/arm/mach-nomadik/include/mach/fsmc.h     |   36 +++
 arch/arm/mach-nomadik/include/mach/hardware.h |    5 +-
 arch/arm/mach-nomadik/include/mach/nand.h     |   16 ++
 drivers/mtd/nand/Kconfig                      |    6 +
 drivers/mtd/nand/Makefile                     |    1 +
 drivers/mtd/nand/nomadik_nand.c               |  329 +++++++++++++++++++++++++
 8 files changed, 484 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-nomadik/include/mach/fsmc.h
 create mode 100644 arch/arm/mach-nomadik/include/mach/nand.h
 create mode 100644 drivers/mtd/nand/nomadik_nand.c
arch/arm/configs/nhk15_defconfig +1 -0
index cf11d79..1697efe 100644
@@ -476,6 +476,7 @@ CONFIG_MTD_NAND_IDS=y
 # CONFIG_MTD_NAND_DISKONCHIP is not set
 # CONFIG_MTD_NAND_NANDSIM is not set
 # CONFIG_MTD_NAND_PLATFORM is not set
+CONFIG_MTD_NAND_NOMADIK=y
 # CONFIG_MTD_ONENAND is not set
 
 #
arch/arm/mach-nomadik/board-8815nhk.c +39 -0
index 5dda007..1e5b332 100644
@@ -19,15 +19,106 @@
 #include <linux/io.h>
 #include <linux/param.h>
 #include <asm/setup.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/partitions.h>
+#include <asm/sizes.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/irq.h>
 
 #include <mach/hardware.h>
 #include <mach/setup.h>
+#include <mach/nand.h>
+#include <mach/fsmc.h>
+
+/* These adresses span 16MB, so use three individual pages */
+static struct resource nhk8815_nand_resources[] = {
+	{
+		.name = "nand_addr",
+		.start = NAND_IO_ADDR,
+		.end = NAND_IO_ADDR + 0xfff,
+		.flags = IORESOURCE_MEM,
+	}, {
+		.name = "nand_cmd",
+		.start = NAND_IO_CMD,
+		.end = NAND_IO_CMD + 0xfff,
+		.flags = IORESOURCE_MEM,
+	}, {
+		.name = "nand_data",
+		.start = NAND_IO_DATA,
+		.end = NAND_IO_DATA + 0xfff,
+		.flags = IORESOURCE_MEM,
+	}
+};
+
+static int nhk8815_nand_init(void)
+{
+	/* FSMC setup for nand chip select (8-bit nand in 8815NHK) */
+	writel(0x0000000E, FSMC_PCR0);
+	writel(0x000D0A00, FSMC_PMEM0);
+	writel(0x00100A00, FSMC_PATT0);
+
+	/* enable access to the chip select area */
+	writel(readl(FSMC_PCR0) | 0x04, FSMC_PCR0);
+
+	return 0;
+}

arch/arm/mach-nomadik/board-8815nhk.c line 76

Quoted 10 lines
arch/arm/mach-nomadik/board-8815nhk.c +10 -0
+
+static struct mtd_partition nhk8815_partitions[] = {
+	{
+		.name	= "X-Loader(NAND)",
+		.offset = 0,
+		.size	= SZ_256K,
+	}, {
+		.name	= "MemInit(NAND)",
+		.offset	= MTDPART_OFS_APPEND,
+		.size	= SZ_256K,

MemInit?
why do you need this?

arch/arm/mach-nomadik/board-8815nhk.c line 81

Quoted 5 lines
arch/arm/mach-nomadik/board-8815nhk.c +5 -0
+	}, {
+		.name	= "BootLoader(NAND)",
+		.offset	= MTDPART_OFS_APPEND,
+		.size	= SZ_2M,
+	}, {

2M for U-Boot? it's quite big

Quoted 32 lines
arch/arm/mach-nomadik/board-8815nhk.c +32 -0
+		.name	= "Kernel zImage(NAND)",
+		.offset	= MTDPART_OFS_APPEND,
+		.size	= 3 * SZ_1M,
+	}, {
+		.name	= "Root Filesystem(NAND)",
+		.offset	= MTDPART_OFS_APPEND,
+		.size	= 22* SZ_1M,
+	}, {
+		/* This can't be SIZ_FULL as we have the u-boot env */
+		.name	= "User Filesystem(NAND)",
+		.offset	= MTDPART_OFS_APPEND,
+		.size	= 100 * SZ_1M,
+	}, {
+		.name	= "U-Boot Environment",
+		.offset	= 0x8000000 - SZ_128K,
+		.size	= SZ_128K,
+	}
+};
+
+static struct nomadik_nand_platform_data nhk8815_nand_data = {
+	.parts		= nhk8815_partitions,
+	.nparts		= ARRAY_SIZE(nhk8815_partitions),
+	.options	= NAND_COPYBACK | NAND_CACHEPRG | NAND_NO_PADDING \
+			| NAND_NO_READRDY | NAND_NO_AUTOINCR,
+	.init		= nhk8815_nand_init,
+};
+
+static struct platform_device nhk8815_nand_device = {
+	.name		= "nomadik_nand",
+	.dev		= {
+				.platform_data = &nhk8815_nand_data,
+	},

arch/arm/mach-nomadik/board-8815nhk.c line 122

Quoted 10 lines
arch/arm/mach-nomadik/board-8815nhk.c +6 -1
+	.resource	= nhk8815_nand_resources,
+	.num_resources	= ARRAY_SIZE(nhk8815_nand_resources),
+};
+
 
 static struct platform_device *nhk8815_platform_devices[] __initdata = {
-	/* currently empty, will add keypad, touchscreen etc */
+	&nhk8815_nand_device,
+	/* will add keypad, touchscreen etc */
 };

it will be better to create a devices file as done for at91 to simplify board addung

Quoted 18 lines
arch/arm/mach-nomadik/board-8815nhk.c +0 -0
 static void __init nhk8815_map_io(void)
arch/arm/mach-nomadik/include/mach/fsmc.h new file +10 -0
new file mode 100644
index 0000000..f81621c
@@ -0,0 +1,36 @@
+
+/* Definitions for the Nomadik FSMC "Flexible Static Memory controller" */
+
+#ifndef __ASM_ARCH_FSMC_H
+#define __ASM_ARCH_FSMC_H
+
+#include <mach/hardware.h>
+/*
+ * Register list
+ */

arch/arm/mach-nomadik/include/mach/fsmc.h line 20

Quoted 10 lines
arch/arm/mach-nomadik/include/mach/fsmc.h new file +10 -0
+
+/* control and timing registers for CS0..CS3 */
+#define FSMC_BCR0	((void __iomem *)(NOMADIK_FSMC_VA + 0x00))
+#define FSMC_BTR0	((void __iomem *)(NOMADIK_FSMC_VA + 0x04))
+#define FSMC_BCR1	((void __iomem *)(NOMADIK_FSMC_VA + 0x08))
+#define FSMC_BTR1	((void __iomem *)(NOMADIK_FSMC_VA + 0x0c))
+#define FSMC_BCR2	((void __iomem *)(NOMADIK_FSMC_VA + 0x10))
+#define FSMC_BTR2	((void __iomem *)(NOMADIK_FSMC_VA + 0x14))
+#define FSMC_BCR3	((void __iomem *)(NOMADIK_FSMC_VA + 0x18))
+#define FSMC_BTR3	((void __iomem *)(NOMADIK_FSMC_VA + 0x1c))

why not this

/* control and timing registers for CS0..CS3 */
#define FSMC_BCR(x) (NOMADIK_FSMC_VA + (x << 3))
#define FSMC_BTR(x) (NOMADIK_FSMC_VA + (x << 3) + 0x04)

#define FSMC_PCR(x) (NOMADIK_FSMC_VA + ((2 + x) << 5) + 0x00)
#define FSMC_PMEM(x) (NOMADIK_FSMC_VA + ((2 + x) << 5) + 0x08)
#define FSMC_PATT(x) (NOMADIK_FSMC_VA + ((2 + x) << 5) + 0x0c)
#define FSMC_PIO(x) (NOMADIK_FSMC_VA + ((2 + x) << 5) + 0x10)
#define FSMC_PECCR(x) (NOMADIK_FSMC_VA + ((2 + x) << 5) + 0x14)

I think void __iomem * is not needed
otherwise you will not be allow to use is in ASM as example

by the a description of each register will be nice

Quoted 8 lines
arch/arm/mach-nomadik/include/mach/fsmc.h new file +3 -0
+
+
+#endif /* __ASM_ARCH_FSMC_H */
arch/arm/mach-nomadik/include/mach/hardware.h +0 -0
index 8cdee9b..05ea93b 100644

arch/arm/mach-nomadik/include/mach/hardware.h line 87

Quoted 8 lines
arch/arm/mach-nomadik/include/mach/hardware.h +3 -2
@@ -82,7 +82,8 @@
 #define NOMADIK_HAMACA_DMEM	0xA0200000	/* HAMACA Data Memory Space */
 
 
-#define NOMADIK_MTU0_VA (IO_ADDRESS(NOMADIK_MTU0_BASE))
-#define NOMADIK_MTU1_VA (IO_ADDRESS(NOMADIK_MTU1_BASE))
+#define NOMADIK_FSMC_VA		IO_ADDRESS(NOMADIK_FSMC_BASE)
+#define NOMADIK_MTU0_VA		IO_ADDRESS(NOMADIK_MTU0_BASE)
+#define NOMADIK_MTU1_VA		IO_ADDRESS(NOMADIK_MTU1_BASE)

NOMADIK_MTU_VA(x) will be better

Quoted 100 lines
arch/arm/mach-nomadik/include/mach/hardware.h +0 -0
 #endif /* __ASM_ARCH_HARDWARE_H */
arch/arm/mach-nomadik/include/mach/nand.h new file +16 -0
new file mode 100644
index 0000000..c3c8254
@@ -0,0 +1,16 @@
+#ifndef __ASM_ARCH_NAND_H
+#define __ASM_ARCH_NAND_H
+
+struct nomadik_nand_platform_data {
+	struct mtd_partition *parts;
+	int nparts;
+	int options;
+	int (*init) (void);
+	int (*exit) (void);
+};
+
+#define NAND_IO_DATA	0x40000000
+#define NAND_IO_CMD	0x40800000
+#define NAND_IO_ADDR	0x41000000
+
+#endif				/* __ASM_ARCH_NAND_H */
drivers/mtd/nand/Kconfig +6 -0
index 8b12e6e..41b4fc7 100644
@@ -420,6 +420,12 @@ config MTD_NAND_MXC
 	  This enables the driver for the NAND flash controller on the
 	  MXC processors.
 
+config MTD_NAND_NOMADIK
+	tristate "ST Nomadik 8815 NAND support"
+	depends on ARCH_NOMADIK
+	help
+	  Driver for the NAND flash controller on the Nomadik, with ECC.
+
 config MTD_NAND_SH_FLCTL
 	tristate "Support for NAND on Renesas SuperH FLCTL"
 	depends on MTD_NAND && SUPERH && CPU_SUBTYPE_SH7723
drivers/mtd/nand/Makefile +1 -0
index b661586..06acb94 100644
@@ -36,5 +36,6 @@ obj-$(CONFIG_MTD_NAND_FSL_ELBC)		+= fsl_elbc_nand.o
 obj-$(CONFIG_MTD_NAND_FSL_UPM)		+= fsl_upm.o
 obj-$(CONFIG_MTD_NAND_SH_FLCTL)		+= sh_flctl.o
 obj-$(CONFIG_MTD_NAND_MXC)		+= mxc_nand.o
+obj-$(CONFIG_MTD_NAND_NOMADIK)		+= nomadik_nand.o
 
 nand-objs := nand_base.o nand_bbt.o
drivers/mtd/nand/nomadik_nand.c new file +42 -0
new file mode 100644
index 0000000..bbd1925
@@ -0,0 +1,329 @@
+/*
+ *  drivers/mtd/nand/nomadik_nand.c
+ *
+ *  Overview:
+ *  	Driver for on-board NAND flash on Nomadik Platforms
+ *
+ * Copyright (C) 2007 STMicroelectronics Pvt. Ltd.
+ * Author: Sachin Verma <[email protected]>
+ *
+ * Copyright (C) 2009 Alessandro Rubini
+ *
+ * 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.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/partitions.h>
+#include <linux/io.h>
+#include <mach/nand.h>
+#include <mach/fsmc.h>
+
+#include <mtd/mtd-abi.h>
+
+struct nomadik_nand_host {
+	struct mtd_info		mtd;
+	struct nand_chip	nand;
+	void __iomem *data_va;
+	void __iomem *cmd_va;
+	void __iomem *addr_va;

drivers/mtd/nand/nomadik_nand.c line 52

Quoted 10 lines
drivers/mtd/nand/nomadik_nand.c new file +10 -0
+	struct nand_bbt_descr *bbt_desc;
+};
+
+static inline int parity(int b) /* uses low 8 bits: returns 0 or all-1 */
+{
+	b = b ^ (b >> 4);
+	b = b ^ (b >> 2);
+	return (b ^ (b >> 1)) & 1
+		? ~0 : 0;
+}

in U-Boot you chose to use the asembly implementation it will we nice if you can keep it sync

Best Regards,
J.