Re: [PATCHv2] drivers: mtd: spinand: Add generic spinand frameowrk.

2013-07-04 Thread Florian Fainelli
Hello,

Le jeudi 4 juillet 2013 10:13:43 Sourav Poddar a écrit :
> > 
> > Can this somehow be made a runtime thing?
> 
> Ahh..I think we might opt for a device tree entry and based on that
> check for ECC.

Ok, sounds good too.

> 
> > [snip]
> > 
> >> +   if (count<  oob_num&&  ops->oobbuf&&  chip->oobbuf) {
> >> +   int size;
> >> +   int offset, len, temp;
> >> +
> >> +   /* repack spare to oob */
> >> +   memset(chip->oobbuf, 0,
> >> info->ecclayout->oobavail);
> >> +
> >> +   temp = 0;
> >> +   offset = info->ecclayout->oobfree[0].offset;
> >> +   len = info->ecclayout->oobfree[0].length;
> >> +   memcpy(chip->oobbuf + temp,
> >> +   chip->buf + info->page_main_size +
> >> offset, len);> 
> > Sounds like a for look might be useful here
> 
> I dont think so, there is a while loop above under which it happens.
> We are increasing count at the bottom of the while loop. So, I think
> this should work fine.

What I meant here, is that you could use a for loop to repeat 4 times the same 
following pattern, such that it becomes:

for (j = 0; j < 4; j++0 {
temp += len;
offset = info->ecclayout->oobfree[j].offset;
len = info->ecclayout->oobfree[j].length;
memcpy(chip->oobbuf + temp,
chip->buf + info->page_main_size + offset, len);
}

Or even make it a helper function which is inlined if that is deemed more 
elegant.
-- 
Florian
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2] drivers: mtd: spinand: Add generic spinand frameowrk.

2013-07-03 Thread Sourav Poddar

Hi,
On Wednesday 03 July 2013 10:47 PM, Florian Fainelli wrote:

Hello,

2013/7/3 Sourav Poddar:

From: Mona Anonuevo

This patch adds support for a generic spinand framework(spinand_mtd.c).
This frameowrk can be used for other spi based flash devices. The idea
is to have a common model under drivers/mtd, as also present for other non spi
devices(there is a generic framework and device part simply attaches itself to 
it.)

Resending my comments since your previous submissino


Signed-off-by: Mona Anonuevo
Signed-off-by: Tuan Nguyen
Signed-off-by: Sourav Poddar



[snip]


+if MTD_SPINAND
+
+config MTD_SPINAND_ONDIEECC
+   bool "Use SPINAND internal ECC"
+   help
+Internel ECC
+
+config MTD_SPINAND_SWECC
+   bool "Use software ECC"
+   depends on MTD_NAND
+   help
+software ECC

Can this somehow be made a runtime thing?


Ahh..I think we might opt for a device tree entry and based on that
check for ECC.

[snip]


+   if (count<  oob_num&&  ops->oobbuf&&  chip->oobbuf) {
+   int size;
+   int offset, len, temp;
+
+   /* repack spare to oob */
+   memset(chip->oobbuf, 0, info->ecclayout->oobavail);
+
+   temp = 0;
+   offset = info->ecclayout->oobfree[0].offset;
+   len = info->ecclayout->oobfree[0].length;
+   memcpy(chip->oobbuf + temp,
+   chip->buf + info->page_main_size + offset, len);

Sounds like a for look might be useful here


I dont think so, there is a while loop above under which it happens.
We are increasing count at the bottom of the while loop. So, I think
this should work fine.

+
+   temp += len;
+   offset = info->ecclayout->oobfree[1].offset;
+   len = info->ecclayout->oobfree[1].length;
+   memcpy(chip->oobbuf + temp,
+   chip->buf + info->page_main_size + offset, len);
+
+   temp += len;
+   offset = info->ecclayout->oobfree[2].offset;
+   len = info->ecclayout->oobfree[2].length;
+   memcpy(chip->oobbuf + temp,
+   chip->buf + info->page_main_size + offset, len);
+
+   temp += len;
+   offset = info->ecclayout->oobfree[3].offset;
+   len = info->ecclayout->oobfree[3].length;
+   memcpy(chip->oobbuf + temp,
+   chip->buf + info->page_main_size + offset, len);
+

[snip]


+   /* repack oob to spare */
+   temp = 0;
+   offset = info->ecclayout->oobfree[0].offset;
+   len = info->ecclayout->oobfree[0].length;
+   memcpy(chip->buf + info->page_main_size + offset,
+   chip->oobbuf + temp, len);

And here too.



Same as above.

+
+   temp += len;
+   offset = info->ecclayout->oobfree[1].offset;
+   len = info->ecclayout->oobfree[1].length;
+   memcpy(chip->buf + info->page_main_size + offset,
+   chip->oobbuf + temp, len);
+
+   temp += len;
+   offset = info->ecclayout->oobfree[2].offset;
+   len = info->ecclayout->oobfree[2].length;
+   memcpy(chip->buf + info->page_main_size + offset,
+   chip->oobbuf + temp, len);
+
+   temp += len;
+   offset = info->ecclayout->oobfree[3].offset;
+   len = info->ecclayout->oobfree[3].length;
+   memcpy(chip->buf + info->page_main_size + offset,
+   chip->oobbuf + temp, len);
+   }

[snip]


+++ b/include/linux/mtd/spinand.h
@@ -0,0 +1,155 @@
+/*
+ *  linux/include/linux/mtd/spinand.h
+ *  Copyright (c) 2009-2010 Micron Technology, Inc.
+ *  This software is licensed under the terms of the GNU General Public
+ *  License version 2, as published by the Free Software Foundation, and
+ *  may be copied, distributed, and modified under those terms.
+
+ *  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.
+/bin/bash: 4: command not found
+ *
+ *  based on nand.h
+ */
+#ifndef __LINUX_MTD_SPI_NAND_H
+#define __LINUX_MTD_SPI_NAND_H
+
+#include
+#include
+#include
+
+/* cmd */
+#define CMD_READ   0x13
+#define CMD_READ_RDM   0x03
+#define CMD_PROG_PAGE_CLRCACHE 0x02
+#define CMD_PROG

Re: [PATCHv2] drivers: mtd: spinand: Add generic spinand frameowrk.

2013-07-03 Thread Florian Fainelli
Hello,

2013/7/3 Sourav Poddar :
> From: Mona Anonuevo 
>
> This patch adds support for a generic spinand framework(spinand_mtd.c).
> This frameowrk can be used for other spi based flash devices. The idea
> is to have a common model under drivers/mtd, as also present for other non spi
> devices(there is a generic framework and device part simply attaches itself 
> to it.)

Resending my comments since your previous submissino

>
> Signed-off-by: Mona Anonuevo 
> Signed-off-by: Tuan Nguyen 
> Signed-off-by: Sourav Poddar 
> 
>

[snip]

> +if MTD_SPINAND
> +
> +config MTD_SPINAND_ONDIEECC
> +   bool "Use SPINAND internal ECC"
> +   help
> +Internel ECC
> +
> +config MTD_SPINAND_SWECC
> +   bool "Use software ECC"
> +   depends on MTD_NAND
> +   help
> +software ECC

Can this somehow be made a runtime thing?

[snip]

> +   if (count < oob_num && ops->oobbuf && chip->oobbuf) {
> +   int size;
> +   int offset, len, temp;
> +
> +   /* repack spare to oob */
> +   memset(chip->oobbuf, 0, info->ecclayout->oobavail);
> +
> +   temp = 0;
> +   offset = info->ecclayout->oobfree[0].offset;
> +   len = info->ecclayout->oobfree[0].length;
> +   memcpy(chip->oobbuf + temp,
> +   chip->buf + info->page_main_size + offset, 
> len);

Sounds like a for look might be useful here

> +
> +   temp += len;
> +   offset = info->ecclayout->oobfree[1].offset;
> +   len = info->ecclayout->oobfree[1].length;
> +   memcpy(chip->oobbuf + temp,
> +   chip->buf + info->page_main_size + offset, 
> len);
> +
> +   temp += len;
> +   offset = info->ecclayout->oobfree[2].offset;
> +   len = info->ecclayout->oobfree[2].length;
> +   memcpy(chip->oobbuf + temp,
> +   chip->buf + info->page_main_size + offset, 
> len);
> +
> +   temp += len;
> +   offset = info->ecclayout->oobfree[3].offset;
> +   len = info->ecclayout->oobfree[3].length;
> +   memcpy(chip->oobbuf + temp,
> +   chip->buf + info->page_main_size + offset, 
> len);
> +

[snip]

> +   /* repack oob to spare */
> +   temp = 0;
> +   offset = info->ecclayout->oobfree[0].offset;
> +   len = info->ecclayout->oobfree[0].length;
> +   memcpy(chip->buf + info->page_main_size + offset,
> +   chip->oobbuf + temp, len);

And here too.

> +
> +   temp += len;
> +   offset = info->ecclayout->oobfree[1].offset;
> +   len = info->ecclayout->oobfree[1].length;
> +   memcpy(chip->buf + info->page_main_size + offset,
> +   chip->oobbuf + temp, len);
> +
> +   temp += len;
> +   offset = info->ecclayout->oobfree[2].offset;
> +   len = info->ecclayout->oobfree[2].length;
> +   memcpy(chip->buf + info->page_main_size + offset,
> +   chip->oobbuf + temp, len);
> +
> +   temp += len;
> +   offset = info->ecclayout->oobfree[3].offset;
> +   len = info->ecclayout->oobfree[3].length;
> +   memcpy(chip->buf + info->page_main_size + offset,
> +   chip->oobbuf + temp, len);
> +   }

[snip]

> +++ b/include/linux/mtd/spinand.h
> @@ -0,0 +1,155 @@
> +/*
> + *  linux/include/linux/mtd/spinand.h
> + *  Copyright (c) 2009-2010 Micron Technology, Inc.
> + *  This software is licensed under the terms of the GNU General Public
> + *  License version 2, as published by the Free Software Foundation, and
> + *  may be copied, distributed, and modified under those terms.
> +
> + *  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.
> +/bin/bash: 4: command not found
> + *
> + *  based on nand.h
> + */
> +#ifndef __LINUX_MTD_SPI_NAND_H
> +#define __LINUX_MTD_SPI_NAND_H
> +
> +#include 
> +#include 
> +#include 
> +
> +/* cmd */
> +#define CMD_READ   0x13
> +#define CMD_READ_RDM   0x03
> +#define CMD_PROG_PAGE_CLRCACHE 0x02
> +#define CMD_PROG_PAGE  0x84
> +#define CMD_PROG_PAGE_EXC  0x10
> +#define CMD_ERASE_BLK 

[PATCHv2] drivers: mtd: spinand: Add generic spinand frameowrk.

2013-07-03 Thread Sourav Poddar
From: Mona Anonuevo 

This patch adds support for a generic spinand framework(spinand_mtd.c).
This frameowrk can be used for other spi based flash devices. The idea
is to have a common model under drivers/mtd, as also present for other non spi
devices(there is a generic framework and device part simply attaches itself to 
it.)

Signed-off-by: Mona Anonuevo 
Signed-off-by: Tuan Nguyen 
Signed-off-by: Sourav Poddar 

This patch was sent as a part of a series[1];
but this can go in as a standalone patch.
[1]: https://lkml.org/lkml/2013/6/26/83

v1->v2:
seperated the specific micron driver,
flash devices can attach itself seperately to this
generic framework. 

 drivers/mtd/Kconfig   |2 +
 drivers/mtd/Makefile  |2 +
 drivers/mtd/spinand/Kconfig   |   24 ++
 drivers/mtd/spinand/Makefile  |8 +
 drivers/mtd/spinand/spinand_mtd.c |  690 +
 include/linux/mtd/spinand.h   |  155 +
 6 files changed, 881 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/spinand/Kconfig
 create mode 100644 drivers/mtd/spinand/Makefile
 create mode 100644 drivers/mtd/spinand/spinand_mtd.c
 create mode 100644 include/linux/mtd/spinand.h

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 5fab4e6..c9e6c60 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -318,6 +318,8 @@ source "drivers/mtd/nand/Kconfig"
 
 source "drivers/mtd/onenand/Kconfig"
 
+source "drivers/mtd/spinand/Kconfig"
+
 source "drivers/mtd/lpddr/Kconfig"
 
 source "drivers/mtd/ubi/Kconfig"
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 4cfb31e..cce68db 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -32,4 +32,6 @@ inftl-objs:= inftlcore.o inftlmount.o
 
 obj-y  += chips/ lpddr/ maps/ devices/ nand/ onenand/ tests/
 
+obj-y  += spinand/
+
 obj-$(CONFIG_MTD_UBI)  += ubi/
diff --git a/drivers/mtd/spinand/Kconfig b/drivers/mtd/spinand/Kconfig
new file mode 100644
index 000..38c739f
--- /dev/null
+++ b/drivers/mtd/spinand/Kconfig
@@ -0,0 +1,24 @@
+#
+# linux/drivers/mtd/spinand/Kconfig
+#
+
+menuconfig MTD_SPINAND
+   tristate "SPINAND Device Support"
+   depends on MTD
+   help
+This enables support for accessing Micron SPI NAND flash
+devices.
+
+if MTD_SPINAND
+
+config MTD_SPINAND_ONDIEECC
+   bool "Use SPINAND internal ECC"
+   help
+Internel ECC
+
+config MTD_SPINAND_SWECC
+   bool "Use software ECC"
+   depends on MTD_NAND
+   help
+software ECC
+endif
diff --git a/drivers/mtd/spinand/Makefile b/drivers/mtd/spinand/Makefile
new file mode 100644
index 000..be18de7
--- /dev/null
+++ b/drivers/mtd/spinand/Makefile
@@ -0,0 +1,8 @@
+#
+# Makefile for the SPI NAND MTD
+#
+
+# Core functionality.
+obj-$(CONFIG_MTD_SPINAND)  += spinand.o
+
+spinand-objs := spinand_mtd.o
diff --git a/drivers/mtd/spinand/spinand_mtd.c 
b/drivers/mtd/spinand/spinand_mtd.c
new file mode 100644
index 000..8bfff86
--- /dev/null
+++ b/drivers/mtd/spinand/spinand_mtd.c
@@ -0,0 +1,690 @@
+/*
+spinand_mtd.c
+
+Copyright (c) 2009-2010 Micron Technology, Inc.
+
+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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * spinand_get_device - [GENERIC] Get chip for selected access
+ * @param mtd  MTD device structure
+ * @param new_statethe state which is requested
+ *
+ * Get the device and lock it for exclusive access
+ */
+#define mu_spi_nand_driver_version "Beagle-MTD_01.00_Linux2.6.33_20100507"
+
+static int spinand_get_device(struct mtd_info *mtd, int new_state)
+{
+   struct spinand_chip *this = mtd->priv;
+   DECLARE_WAITQUEUE(wait, current);
+
+   /*
+* Grab the lock and see if the device is available
+*/
+   while (1) {
+   spin_lock(&this->chip_lock);
+   if (this->state == FL_READY) {
+   this->state = new_state;
+   spin_unlock(&this->chip_lock);
+   break;
+   }
+   if (new_state == FL_PM_SUSPENDED) {
+   spin_unlock(&this->chip_lock);
+   return (this->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN;
+   }
+   set_current_state(TASK_UNINTERRUPTIBLE);
+   add_wait_queue(&this->wq, &wait);
+   spin_unlock(&this->chip_lock);
+