* [PATCH] cmx270-nand: Make CMDLINE_PARTS usable
@ 2006-09-13 12:50 Raphael Assenat
2006-09-22 9:36 ` David Woodhouse
0 siblings, 1 reply; 7+ messages in thread
From: Raphael Assenat @ 2006-09-13 12:50 UTC (permalink / raw)
To: linux-mtd
[-- Attachment #1: Type: text/plain, Size: 311 bytes --]
This patch gives a name to the cmx270 nand mtd, making it possible to use command line
partitioning.
eg:
mtdparts=cmx270-nand:32m(root),8m(data),-(spare)"
does not work without this patch. The default (one full device partition)
hardcoded in the driver is used.
Signed-off-by: Raphael Assenat <raph@8d.com>
[-- Attachment #2: cmx270-nand-cmdlinepart.diff --]
[-- Type: text/plain, Size: 712 bytes --]
This patch gives a name to the cmx270 nand mtd, making it possible to use command line
partitioning.
eg:
mtdparts=cmx270-nand:32m(root),8m(data),-(spare)"
does not work without this patch. The default (one full device partition)
hardcoded in the driver is used.
Signed-off-by: Raphael Assenat <raph@8d.com>
--- linux-2.6.18-rc2-8d-unionfs/drivers/mtd/nand/cmx270-nand.c 2006-08-17 15:32:02.000000000 -0400
+++ linux-2.6.18-rc2-8d2/drivers/mtd/nand/cmx270-nand.c 2006-09-05 10:23:16.000000000 -0400
@@ -218,6 +218,7 @@
goto err2;
}
+ cmx270_nand_mtd->name = "cmx270-nand";
#ifdef CONFIG_MTD_CMDLINE_PARTS
mtd_parts_nb = parse_mtd_partitions(cmx270_nand_mtd, part_probes,
&mtd_parts, 0);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] cmx270-nand: Make CMDLINE_PARTS usable
2006-09-13 12:50 [PATCH] cmx270-nand: Make CMDLINE_PARTS usable Raphael Assenat
@ 2006-09-22 9:36 ` David Woodhouse
2006-09-22 14:15 ` Raphael Assenat
0 siblings, 1 reply; 7+ messages in thread
From: David Woodhouse @ 2006-09-22 9:36 UTC (permalink / raw)
To: Raphael Assenat; +Cc: linux-mtd
On Wed, 2006-09-13 at 08:50 -0400, Raphael Assenat wrote:
> This patch gives a name to the cmx270 nand mtd, making it possible to
> use command line partitioning.
Er, there _is_ no cmx270 nand board driver in my tree.
--
dwmw2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] cmx270-nand: Make CMDLINE_PARTS usable
2006-09-22 9:36 ` David Woodhouse
@ 2006-09-22 14:15 ` Raphael Assenat
2006-09-22 14:44 ` David Woodhouse
0 siblings, 1 reply; 7+ messages in thread
From: Raphael Assenat @ 2006-09-22 14:15 UTC (permalink / raw)
To: David Woodhouse; +Cc: linux-mtd
David Woodhouse wrote:
> On Wed, 2006-09-13 at 08:50 -0400, Raphael Assenat wrote:
>
>>This patch gives a name to the cmx270 nand mtd, making it possible to
>>use command line partitioning.
>
>
> Er, there _is_ no cmx270 nand board driver in my tree.
>
Oh, sorry. My patch applies over the patch Mike Rapoport sent to the list on July 18
([PATCH] [MTD] CM-x270 NAND flash support), which I thought was already accepted. Was
there anything wrong with it? Maybe you just missed it...
I also sent a patch to the list on July 21 which added NAND flash support for the cm-x255
boards ([PATCH] Add support for NAND flash on cm-x255) but received no feedback. I can
resend it if you wish.
(BTW, every time I send to the linux-mtd list my message is held for moderator approval
for reason 'Message has a suspicious header'. Who should I contact for more information?
I'd like to know exactly what header(s) is/are 'suspicious' and fix them if possible).
Best regards,
--
Raphael Assenat
8D Technologies Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] cmx270-nand: Make CMDLINE_PARTS usable
2006-09-22 14:15 ` Raphael Assenat
@ 2006-09-22 14:44 ` David Woodhouse
2006-09-25 13:07 ` Raphael Assenat
2006-09-25 14:22 ` [PATCH][RESEND] [MTD] CM-x270 NAND flash support (Was [PATCH] cmx270-nand: Make CMDLINE_PARTS usable) Mike Rapoport
0 siblings, 2 replies; 7+ messages in thread
From: David Woodhouse @ 2006-09-22 14:44 UTC (permalink / raw)
To: Raphael Assenat; +Cc: linux-mtd
On Fri, 2006-09-22 at 10:15 -0400, Raphael Assenat wrote:
> Oh, sorry. My patch applies over the patch Mike Rapoport sent to the list on July 18
> ([PATCH] [MTD] CM-x270 NAND flash support), which I thought was already accepted. Was
> there anything wrong with it? Maybe you just missed it...
>
> I also sent a patch to the list on July 21 which added NAND flash support for the cm-x255
> boards ([PATCH] Add support for NAND flash on cm-x255) but received no feedback. I can
> resend it if you wish.
July and August weren't really a good time for sending stuff that you
expect me to pay attention to; sorry. Yes -- please retest and resend.
Can you explain how these two boards differ, and why they need two
separate drivers?
> (BTW, every time I send to the linux-mtd list my message is held for moderator approval
> for reason 'Message has a suspicious header'. Who should I contact for more information?
> I'd like to know exactly what header(s) is/are 'suspicious' and fix them if possible).
It just doesn't like attachments. Send patches inline and they shouldn't
get trapped.
--
dwmw2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] cmx270-nand: Make CMDLINE_PARTS usable
2006-09-22 14:44 ` David Woodhouse
@ 2006-09-25 13:07 ` Raphael Assenat
2006-09-25 14:57 ` Raphael Assenat
2006-09-25 14:22 ` [PATCH][RESEND] [MTD] CM-x270 NAND flash support (Was [PATCH] cmx270-nand: Make CMDLINE_PARTS usable) Mike Rapoport
1 sibling, 1 reply; 7+ messages in thread
From: Raphael Assenat @ 2006-09-25 13:07 UTC (permalink / raw)
To: David Woodhouse; +Cc: linux-mtd
David Woodhouse wrote:
> On Fri, 2006-09-22 at 10:15 -0400, Raphael Assenat wrote:
>
>>Oh, sorry. My patch applies over the patch Mike Rapoport sent to the list on July 18
>>([PATCH] [MTD] CM-x270 NAND flash support), which I thought was already accepted. Was
>>there anything wrong with it? Maybe you just missed it...
>>
>>I also sent a patch to the list on July 21 which added NAND flash support for the cm-x255
>>boards ([PATCH] Add support for NAND flash on cm-x255) but received no feedback. I can
>>resend it if you wish.
>
>
> July and August weren't really a good time for sending stuff that you
> expect me to pay attention to; sorry. Yes -- please retest and resend.
>
> Can you explain how these two boards differ, and why they need two
> separate drivers?
Yes.
NAND on cm-x255:
- Uses physical address 0x04000000
- CS, ALE, CLE and RB mapped to pxa GPIOs 5,4,3,10 respectively.
NAND on cm-x270:
- CS and RB mapped to pxa GPIOs 11 and 89
- Read/Write with ALE/CLE inactive: 0x04000000
- Read/Write with ALE active: 0x04000008
- Read/Write with CLE active: 0x04000004
The base address is the same, but GPIOs used differ and the control signals
are controlled differently.
>>(BTW, every time I send to the linux-mtd list my message is held for moderator approval
>>for reason 'Message has a suspicious header'. Who should I contact for more information?
>>I'd like to know exactly what header(s) is/are 'suspicious' and fix them if possible).
>
>
> It just doesn't like attachments. Send patches inline and they shouldn't
> get trapped.
Best regards,
--
Raphael Assenat
8D Technologies Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH][RESEND] [MTD] CM-x270 NAND flash support (Was [PATCH] cmx270-nand: Make CMDLINE_PARTS usable)
2006-09-22 14:44 ` David Woodhouse
2006-09-25 13:07 ` Raphael Assenat
@ 2006-09-25 14:22 ` Mike Rapoport
1 sibling, 0 replies; 7+ messages in thread
From: Mike Rapoport @ 2006-09-25 14:22 UTC (permalink / raw)
To: David Woodhouse; +Cc: linux-mtd, Raphael Assenat
David Woodhouse wrote:
>On Fri, 2006-09-22 at 10:15 -0400, Raphael Assenat wrote:
>
>
>>Oh, sorry. My patch applies over the patch Mike Rapoport sent to the list on July 18
>>([PATCH] [MTD] CM-x270 NAND flash support), which I thought was already accepted. Was
>>there anything wrong with it? Maybe you just missed it...
>>
>>I also sent a patch to the list on July 21 which added NAND flash support for the cm-x255
>>boards ([PATCH] Add support for NAND flash on cm-x255) but received no feedback. I can
>>resend it if you wish.
>>
>>
>
>July and August weren't really a good time for sending stuff that you
>expect me to pay attention to; sorry. Yes -- please retest and resend.
>
>
This patch provides MTD support for NAND flash device on CM-x270 modules.
This is the same patch I've sent earlier.
Unfortunately I'm currently overloaded to update it for the recent
kernels and retest.
>Can you explain how these two boards differ, and why they need two
>separate drivers?
>
>
>
>>(BTW, every time I send to the linux-mtd list my message is held for moderator approval
>>for reason 'Message has a suspicious header'. Who should I contact for more information?
>>I'd like to know exactly what header(s) is/are 'suspicious' and fix them if possible).
>>
>>
>
>It just doesn't like attachments. Send patches inline and they shouldn't
>get trapped.
>
>
>
--
Sincerely yours,
Mike Rapoport
=========================================================
This patch provides MTD support for NAND flash device on CM-x270 modules.
Signed-off-by: Mike Rapoport <mike@compulab.co.il>
=========================================================
drivers/mtd/nand/Kconfig | 4 +
drivers/mtd/nand/Makefile | 1
drivers/mtd/nand/cmx270-nand.c | 271 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 276 insertions(+), 0 deletions(-)
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 3db77ee..4c212fd 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -232,6 +232,10 @@ config MTD_NAND_CS553X
If you say "m", the module will be called "cs553x_nand.ko".
+config MTD_NAND_CM_X270
+ tristate "Support for NAND Flash on CM-X270 modules"
+ depends on MTD_NAND && MACH_CM_X270
+
config MTD_NAND_NANDSIM
tristate "Support for NAND Flash Simulator"
depends on MTD_NAND && MTD_PARTITIONS
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index f747593..f2718aa 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -22,5 +22,6 @@ obj-$(CONFIG_MTD_NAND_TS7250) += ts7250
obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o
obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o
obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
+obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270-nand.o
nand-objs = nand_base.o nand_bbt.o
diff --git a/drivers/mtd/nand/cmx270-nand.c b/drivers/mtd/nand/cmx270-nand.c
new file mode 100644
index 0000000..8a1911c
--- /dev/null
+++ b/drivers/mtd/nand/cmx270-nand.c
@@ -0,0 +1,271 @@
+/*
+ * linux/drivers/mtd/nand/cmx270-nand.c
+ *
+ * Copyright (C) 2006 Compulab, Ltd.
+ * Mike Rapoport <mike@compulab.co.il>
+ *
+ * Derived from drivers/mtd/nand/h1910.c
+ * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
+ * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Overview:
+ * This is a device driver for the NAND flash device found on the
+ * CM-X270 board.
+ */
+
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/io.h>
+#include <asm/irq.h>
+
+#include <asm/arch/hardware.h>
+#include <asm/arch/pxa-regs.h>
+
+#define GPIO_NAND_CS (11)
+#define GPIO_NAND_RB (89)
+
+/* This macro needed to ensure in-order operation of GPIO and local
+ * bus. Without both asm command and dummy uncached read there're
+ * states when NAND access is broken. I've looked for such macro(s) in
+ * include/asm-arm but found nothing approptiate.
+ * dmac_clean_range is close, but is makes cache invalidation
+ * unnecessary here and it cannot be used in module
+ */
+#define DRAIN_WB() \
+ do { \
+ unsigned char dummy; \
+ asm volatile ("mcr p15, 0, r0, c7, c10, 4":::"r0"); \
+ dummy=*((unsigned char*)UNCACHED_ADDR); \
+ } while(0)
+
+/* MTD structure for CM-X270 board */
+static struct mtd_info *cmx270_nand_mtd;
+
+/* remaped IO address of the device */
+static void __iomem *cmx270_nand_io;
+
+/*
+ * Define static partitions for flash device
+ */
+static struct mtd_partition partition_info[] = {
+ {
+ .name = "cmx270-0",
+ .offset = 0,
+ .size = MTDPART_SIZ_FULL
+ }
+};
+#define NUM_PARTITIONS (ARRAY_SIZE(partition_info))
+
+const char *part_probes[] = { "cmdlinepart", NULL };
+
+static u_char cmx270_read_byte(struct mtd_info *mtd)
+{
+ struct nand_chip *this = mtd->priv;
+
+ return (readl(this->IO_ADDR_R) >> 16);
+}
+
+static void cmx270_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
+{
+ int i;
+ struct nand_chip *this = mtd->priv;
+
+ for (i=0; i<len; i++)
+ writel((*buf++ << 16), this->IO_ADDR_W);
+}
+
+static void cmx270_read_buf(struct mtd_info *mtd, u_char *buf, int len)
+{
+ int i;
+ struct nand_chip *this = mtd->priv;
+
+ for (i=0; i<len; i++)
+ *buf++ = readl(this->IO_ADDR_R) >> 16;
+}
+
+static int cmx270_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
+{
+ int i;
+ struct nand_chip *this = mtd->priv;
+
+ for (i=0; i<len; i++)
+ if (buf[i] != (u_char)(readl(this->IO_ADDR_R) >> 16))
+ return -EFAULT;
+
+ return 0;
+}
+
+static inline void nand_cs_on(void)
+{
+ GPCR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
+}
+
+static void nand_cs_off(void)
+{
+ DRAIN_WB();
+
+ GPSR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
+}
+
+/*
+ * hardware specific access to control-lines
+ */
+static void cmx270_hwcontrol(struct mtd_info *mtd, int dat,
+ unsigned int ctrl)
+{
+ struct nand_chip* this = mtd->priv;
+ unsigned int nandaddr = (unsigned int)this->IO_ADDR_W;
+
+ DRAIN_WB();
+
+ if (ctrl & NAND_CTRL_CHANGE) {
+ if ( ctrl & NAND_ALE )
+ nandaddr |= (1 << 3);
+ else
+ nandaddr &= ~(1 << 3);
+ if ( ctrl & NAND_CLE )
+ nandaddr |= (1 << 2);
+ else
+ nandaddr &= ~(1 << 2);
+ if ( ctrl & NAND_NCE )
+ nand_cs_on();
+ else
+ nand_cs_off();
+ }
+
+ DRAIN_WB();
+ this->IO_ADDR_W = (void __iomem*)nandaddr;
+ if (dat != NAND_CMD_NONE)
+ writel((dat << 16), this->IO_ADDR_W);
+
+ DRAIN_WB();
+}
+
+/*
+ * read device ready pin
+ */
+static int cmx270_device_ready(struct mtd_info *mtd)
+{
+ DRAIN_WB();
+
+ return (GPLR(GPIO_NAND_RB) & GPIO_bit(GPIO_NAND_RB));
+}
+
+/*
+ * Main initialization routine
+ */
+static int __devinit cmx270_init(void)
+{
+ struct nand_chip *this;
+ const char *part_type;
+ struct mtd_partition *mtd_parts;
+ int mtd_parts_nb = 0;
+ int ret;
+
+ /* Allocate memory for MTD device structure and private data */
+ cmx270_nand_mtd = kzalloc(sizeof(struct mtd_info) +
+ sizeof(struct nand_chip),
+ GFP_KERNEL);
+ if (!cmx270_nand_mtd) {
+ printk("Unable to allocate CM-X270 NAND MTD device structure.\n");
+ return -ENOMEM;
+ }
+
+ cmx270_nand_io = ioremap(PXA_CS1_PHYS, 12);
+ if (!cmx270_nand_io) {
+ printk("Unable to ioremap NAND device\n");
+ ret = -EINVAL;
+ goto err1;
+ }
+
+ /* Get pointer to private data */
+ this = (struct nand_chip *)(&cmx270_nand_mtd[1]);
+
+ /* Link the private data with the MTD structure */
+ cmx270_nand_mtd->owner = THIS_MODULE;
+ cmx270_nand_mtd->priv = this;
+
+ /* insert callbacks */
+ this->IO_ADDR_R = cmx270_nand_io;
+ this->IO_ADDR_W = cmx270_nand_io;
+ this->cmd_ctrl = cmx270_hwcontrol;
+ this->dev_ready = cmx270_device_ready;
+
+ /* 15 us command delay time */
+ this->chip_delay = 20;
+ this->ecc.mode = NAND_ECC_SOFT;
+
+ /* read/write functions */
+ this->read_byte = cmx270_read_byte;
+ this->read_buf = cmx270_read_buf;
+ this->write_buf = cmx270_write_buf;
+ this->verify_buf = cmx270_verify_buf;
+
+ /* Scan to find existence of the device */
+ if (nand_scan (cmx270_nand_mtd, 1)) {
+ printk(KERN_NOTICE "No NAND device\n");
+ ret = -ENXIO;
+ goto err2;
+ }
+
+#ifdef CONFIG_MTD_CMDLINE_PARTS
+ mtd_parts_nb = parse_mtd_partitions(cmx270_nand_mtd, part_probes,
+ &mtd_parts, 0);
+ if (mtd_parts_nb > 0)
+ part_type = "command line";
+ else
+ mtd_parts_nb = 0;
+#endif
+ if (!mtd_parts_nb) {
+ mtd_parts = partition_info;
+ mtd_parts_nb = NUM_PARTITIONS;
+ part_type = "static";
+ }
+
+ /* Register the partitions */
+ printk(KERN_NOTICE "Using %s partition definition\n", part_type);
+ ret = add_mtd_partitions(cmx270_nand_mtd, mtd_parts, mtd_parts_nb);
+ if (ret)
+ goto err2;
+
+ /* Return happy */
+ return 0;
+
+err2:
+ iounmap(cmx270_nand_io);
+err1:
+ kfree(cmx270_nand_mtd);
+
+ return ret;
+
+}
+module_init(cmx270_init);
+
+/*
+ * Clean up routine
+ */
+static void __devexit cmx270_cleanup(void)
+{
+ /* Release resources, unregister device */
+ nand_release(cmx270_nand_mtd);
+
+ iounmap(cmx270_nand_io);
+
+ /* Free the MTD device structure */
+ kfree (cmx270_nand_mtd);
+}
+module_exit(cmx270_cleanup);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
+MODULE_DESCRIPTION("NAND flash driver for Compulab CM-X270 Module");
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] cmx270-nand: Make CMDLINE_PARTS usable
2006-09-25 13:07 ` Raphael Assenat
@ 2006-09-25 14:57 ` Raphael Assenat
0 siblings, 0 replies; 7+ messages in thread
From: Raphael Assenat @ 2006-09-25 14:57 UTC (permalink / raw)
To: Raphael Assenat; +Cc: linux-mtd, David Woodhouse
On Mon, Sep 25, 2006 at 09:07:55AM -0400, Raphael Assenat wrote:
> David Woodhouse wrote:
> > On Fri, 2006-09-22 at 10:15 -0400, Raphael Assenat wrote:
> >
> >>Oh, sorry. My patch applies over the patch Mike Rapoport sent to the list on July 18
> >>([PATCH] [MTD] CM-x270 NAND flash support), which I thought was already accepted. Was
> >>there anything wrong with it? Maybe you just missed it...
> >>
> >>I also sent a patch to the list on July 21 which added NAND flash support for the cm-x255
> >>boards ([PATCH] Add support for NAND flash on cm-x255) but received no feedback. I can
> >>resend it if you wish.
> >
> >
> > July and August weren't really a good time for sending stuff that you
> > expect me to pay attention to; sorry. Yes -- please retest and resend.
Here comes the resend.
This patch adds support for the NAND flash present on Compulab's cm-x255
boards. Since Compulab chose to discontinue cm-x255 support, I decided
to submit and support this driver myself.
Note: This is the driver I wrote as part of my Compulab kernel fork
project (see http://raph.people.8d.com/armcore_kernel.php). It is not
based on the driver Mike posted to the list.
Applies to 2.6.18
Signed-off-by: Raphael Assenat <raph@8d.com>
diff -Nru linux-2.6.18-rc2/drivers/mtd/nand/Kconfig linux-2.6.18-rc2-mtd/drivers/mtd/nand/Kconfig
--- linux-2.6.18-rc2/drivers/mtd/nand/Kconfig 2006-07-17 15:19:57.000000000 -0400
+++ linux-2.6.18-rc2-mtd/drivers/mtd/nand/Kconfig 2006-07-21 14:36:03.000000000 -0400
@@ -239,4 +239,11 @@
The simulator may simulate various NAND flash chips for the
MTD nand layer.
+config MTD_NAND_CM_X255
+ tristate "Support for NAND Flash on Compulab cm-x255"
+ depends on MTD_NAND && MACH_CM_X255
+ help
+ This enables the driver for the NAND flash present
+ on the cm-x255 board from Compulab.
+
endmenu
diff -Nru linux-2.6.18-rc2/drivers/mtd/nand/Makefile linux-2.6.18-rc2-mtd/drivers/mtd/nand/Makefile
--- linux-2.6.18-rc2/drivers/mtd/nand/Makefile 2006-07-17 15:19:57.000000000 -0400
+++ linux-2.6.18-rc2-mtd/drivers/mtd/nand/Makefile 2006-07-21 14:36:31.000000000 -0400
@@ -22,5 +22,6 @@
obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o
obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o
obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
+obj-$(CONFIG_MTD_NAND_CM_X255) += cm-x255.o
nand-objs = nand_base.o nand_bbt.o
diff -Nru linux-2.6.18-rc2/drivers/mtd/nand/cm-x255.c linux-2.6.18-rc2-mtd/drivers/mtd/nand/cm-x255.c
--- linux-2.6.18-rc2/drivers/mtd/nand/cm-x255.c 1969-12-31 19:00:00.000000000 -0500
+++ linux-2.6.18-rc2-mtd/drivers/mtd/nand/cm-x255.c 2006-07-21 15:02:02.000000000 -0400
@@ -0,0 +1,183 @@
+/*
+ * drivers/mtd/nand/cm-x255.c
+ *
+ * Copyright (c) 2006, 8D Technologies inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Overview:
+ * This is a device driver for the NAND flash device found on the
+ * cm-x255 compulab sbc (formerly known as armcore).
+ *
+ * Changelog:
+ * - April 2006, Raphael Assenat <raph@8d.com>:
+ * Creation of the driver.
+ *
+ * - Jul 18, 2006: Raphael Assenat <raph@8d.com>:
+ * Updates for 2.6.18
+ */
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/partitions.h>
+#include <linux/delay.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/cm-x255.h>
+
+#define GPIO_NAND_CS 5
+#define GPIO_NAND_ALE 4
+#define GPIO_NAND_CLE 3
+#define GPIO_NAND_RB 10
+
+#define DRAIN_WRITE_BUFFER() do { \
+ asm volatile ("mcr p15, 0, r0, c7, c10, 4\n":::"r0"); \
+ dummy=*((volatile unsigned char*)UNCACHED_ADDR); \
+ } while(0)
+
+static struct mtd_info *armcore_mtd = NULL;
+static void __iomem *armcore_nand_io_base;
+static long armcore_nand_phys_base = 0x04000000;
+
+#define DEFAULT_NUM_PARTITIONS 1
+static int nr_partitions;
+static struct mtd_partition armcore_default_partition_info[] = {
+ {
+ .name = "rootfs",
+ .offset = 0,
+ .size = MTDPART_SIZ_FULL,
+ },
+};
+
+static void armcore_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
+ unsigned int ctrl)
+{
+ struct nand_chip *chip = mtd->priv;
+ unsigned char dummy;
+
+ DRAIN_WRITE_BUFFER();
+
+ if (ctrl & NAND_CTRL_CHANGE)
+ {
+ if (ctrl & NAND_NCE)
+ GPCR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
+ else
+ GPSR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
+
+ if (ctrl & NAND_CLE)
+ GPSR(GPIO_NAND_CLE) = GPIO_bit(GPIO_NAND_CLE);
+ else
+ GPCR(GPIO_NAND_CLE) = GPIO_bit(GPIO_NAND_CLE);
+
+ if (ctrl & NAND_ALE)
+ GPSR(GPIO_NAND_ALE) = GPIO_bit(GPIO_NAND_ALE);
+ else
+ GPCR(GPIO_NAND_ALE) = GPIO_bit(GPIO_NAND_ALE);
+
+ }
+
+ DRAIN_WRITE_BUFFER();
+
+ if (cmd != NAND_CMD_NONE)
+ writeb(cmd, chip->IO_ADDR_W);
+}
+
+static int armcore_nand_device_ready(struct mtd_info *mtd)
+{
+ return GPLR(GPIO_NAND_RB) & GPIO_bit(GPIO_NAND_RB);
+}
+
+#ifdef CONFIG_MTD_PARTITIONS
+const char *part_probes[] = { "cmdlinepart", NULL };
+#endif
+
+int __init armcore_nand_init(void)
+{
+ struct nand_chip *this;
+ struct mtd_partition* armcore_partition_info;
+ int err = 0;
+
+ pxa_gpio_mode(GPIO_NAND_RB);
+ pxa_gpio_mode(GPIO_NAND_CS | GPIO_OUT | GPIO_DFLT_HIGH);
+ pxa_gpio_mode(GPIO_NAND_ALE | GPIO_OUT | GPIO_DFLT_LOW);
+ pxa_gpio_mode(GPIO_NAND_CLE | GPIO_OUT | GPIO_DFLT_LOW);
+
+ /* Allocate memory for MTD device structure and private data */
+ armcore_mtd = kmalloc( sizeof(struct mtd_info) +
+ sizeof(struct nand_chip),
+ GFP_KERNEL);
+ if (!armcore_mtd) {
+ printk(KERN_WARNING
+ "Unable to allocate cm-x255 nand mtd device structure.\n");
+ err = -ENOMEM;
+ goto out;
+ }
+
+ /* map physical adress */
+ armcore_nand_io_base = ioremap(armcore_nand_phys_base, 0x100);
+ if (!armcore_nand_io_base) {
+ printk(KERN_WARNING "ioremap for cm-x255 NAND chip failed\n");
+ err = -EIO;
+ goto out_mtd;
+ }
+
+ /* Get pointer to private data */
+ this = (struct nand_chip *) (&armcore_mtd[1]);
+
+ /* Initialize structures */
+ memset((char *) armcore_mtd, 0, sizeof(struct mtd_info));
+ memset((char *) this, 0, sizeof(struct nand_chip));
+
+ /* Link the private data with the MTD structure */
+ armcore_mtd->priv = this;
+
+ this->IO_ADDR_R = armcore_nand_io_base;
+ this->IO_ADDR_W = armcore_nand_io_base;
+ this->cmd_ctrl = armcore_nand_cmd_ctrl;
+ this->dev_ready = armcore_nand_device_ready;
+ this->chip_delay = 15;
+ this->ecc.mode = NAND_ECC_SOFT;
+
+ /* Scan to find existance of the device */
+ if (nand_scan(armcore_mtd, 1)) {
+ printk(KERN_WARNING
+ "nand_scan() failed to scan cm-x255 nand flash\n");
+ err = -ENXIO;
+ goto out_ior;
+ }
+
+ /* Register the partitions */
+ armcore_mtd->name = "armcore-nand";
+ nr_partitions = parse_mtd_partitions(armcore_mtd, part_probes,
+ &armcore_partition_info, 0);
+ if (nr_partitions <= 0) {
+ nr_partitions = DEFAULT_NUM_PARTITIONS;
+ armcore_partition_info = armcore_default_partition_info;
+ }
+
+ add_mtd_partitions(armcore_mtd, armcore_partition_info, nr_partitions);
+
+ goto out;
+
+out_ior:
+ iounmap((void*) armcore_nand_io_base);
+out_mtd:
+ kfree(armcore_mtd);
+out:
+ return err;
+}
+module_init(armcore_nand_init);
+
+static void __exit armcore_nand_cleanup(void)
+{
+ nand_release(armcore_mtd);
+ iounmap((void*)armcore_nand_io_base);
+ kfree(armcore_mtd);
+}
+module_exit(armcore_nand_cleanup);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Raphael Assenat <raph@8d.com>");
+MODULE_DESCRIPTION("NAND flash driver for cm-x255 boards");
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-09-25 15:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-13 12:50 [PATCH] cmx270-nand: Make CMDLINE_PARTS usable Raphael Assenat
2006-09-22 9:36 ` David Woodhouse
2006-09-22 14:15 ` Raphael Assenat
2006-09-22 14:44 ` David Woodhouse
2006-09-25 13:07 ` Raphael Assenat
2006-09-25 14:57 ` Raphael Assenat
2006-09-25 14:22 ` [PATCH][RESEND] [MTD] CM-x270 NAND flash support (Was [PATCH] cmx270-nand: Make CMDLINE_PARTS usable) Mike Rapoport
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox