[U-Boot] [PATCH] mtd: nand: vf610_nfc: resync with upstream Linux version

2015-10-13 Thread Stefan Agner
This resyncs the driver changes with the Linux version of the
driver. The driver received some feedback in the LKML and got
recently acceppted, the latest version can be found here:
https://lkml.org/lkml/2015/9/2/678

Notable changes are:
- On ECC error, reread OOB and count bit flips in OOB too.
  If flipped bits are below threshold, also return an empty
  OOB buffer.
- Return the amount of bit flips in vf610_nfc_read_page.
- Use endianness aware vf610_nfc_read to read ECC status.
- Do not enable IDLE IRQ (since we do not operate with an
  interrupt service routine).
- Use type safe struct for buffer variants (vf610_nfc_alt_buf).
- Renamed variables in struct vf610_nfc (column and page_sz)
  to reflect better what they really representing.

The U-Boot version currently does not support RAW NAND write
when using the HW ECC engine.

Signed-off-by: Bhuvanchandra DV 
Signed-off-by: Stefan Agner 
---
 drivers/mtd/nand/vf610_nfc.c | 247 ---
 1 file changed, 138 insertions(+), 109 deletions(-)

diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c
index 5c11ac9..06266f3 100644
--- a/drivers/mtd/nand/vf610_nfc.c
+++ b/drivers/mtd/nand/vf610_nfc.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2014 Freescale Semiconductor, Inc. and others
+ * Copyright 2009-2015 Freescale Semiconductor, Inc. and others
  *
  * Description: MPC5125, VF610, MCF54418 and Kinetis K70 Nand driver.
  * Ported to U-Boot by Stefan Agner
@@ -19,9 +19,10 @@
  *
  * Limitations:
  * - Untested on MPC5125 and M54418.
- * - DMA not used.
+ * - DMA and pipelining not used.
  * - 2K pages or less.
- * - Only 2K page w. 64+OOB and hardware ECC.
+ * - HW ECC: Only 2K page with 64+ OOB.
+ * - HW ECC: Only 24 and 32-bit error correction implemented.
  */
 
 #include 
@@ -53,6 +54,7 @@
 
 #define PAGE_2K0x0800
 #define OOB_64 0x0040
+#define OOB_MAX0x0100
 
 /*
  * NFC_CMD2[CODE] values. See section:
@@ -127,32 +129,33 @@
 
 #define NFC_TIMEOUT(1000)
 
-/* ECC status placed at end of buffers. */
-#define ECC_SRAM_ADDR  ((PAGE_2K+256-8) >> 3)
-#define ECC_STATUS_MASK0x80
-#define ECC_ERR_COUNT  0x3F
-
 /*
- * ECC status is stored at NFC_CFG[ECCADD] +4 for little-endian
- * and +7 for big-endian SOC.
+ * ECC status - seems to consume 8 bytes (double word). The documented
+ * status byte is located in the lowest byte of the second word (which is
+ * the 4th or 7th byte depending on endianness).
+ * Calculate an offset to store the ECC status at the end of the buffer.
  */
-#ifdef CONFIG_VF610
-#define ECC_OFFSET 4
-#else
-#define ECC_OFFSET 7
-#endif
+#define ECC_SRAM_ADDR  (PAGE_2K + OOB_MAX - 8)
+
+#define ECC_STATUS 0x4
+#define ECC_STATUS_MASK0x80
+#define ECC_STATUS_ERR_COUNT   0x3F
+
+enum vf610_nfc_alt_buf {
+   ALT_BUF_DATA = 0,
+   ALT_BUF_ID = 1,
+   ALT_BUF_STAT = 2,
+   ALT_BUF_ONFI = 3,
+};
 
 struct vf610_nfc {
-   struct mtd_info   *mtd;
-   struct nand_chip   chip;
-   void __iomem  *regs;
-   uint   column;
+   struct mtd_info *mtd;
+   struct nand_chip chip;
+   void __iomem *regs;
+   uint buf_offset;
+   int write_sz;
/* Status and ID are in alternate locations. */
-   intalt_buf;
-#define ALT_BUF_ID   1
-#define ALT_BUF_STAT 2
-#define ALT_BUF_ONFI 3
-   struct clk*clk;
+   enum vf610_nfc_alt_buf alt_buf;
 };
 
 #define mtd_to_nfc(_mtd) \
@@ -170,8 +173,8 @@ static struct nand_ecclayout vf610_nfc_ecc = {
   48, 49, 50, 51, 52, 53, 54, 55,
   56, 57, 58, 59, 60, 61, 62, 63},
.oobfree = {
-   {.offset = 8,
-.length = 11} }
+   {.offset = 2,
+.length = 17} }
 };
 #elif defined(CONFIG_SYS_NAND_VF610_NFC_60_ECC_BYTES)
 #define ECC_HW_MODE ECC_60_BYTE
@@ -226,8 +229,12 @@ static inline void vf610_nfc_set_field(struct mtd_info 
*mtd, u32 reg,
 static inline void vf610_nfc_memcpy(void *dst, const void *src, size_t n)
 {
/*
-* Use this accessor for the interal SRAM buffers. On ARM we can
-* treat the SRAM buffer as if its memory, hence use memcpy
+* Use this accessor for the internal SRAM buffers. On the ARM
+* Freescale Vybrid SoC it's known that the driver can treat
+* the SRAM buffer as if it's memory. Other platform might need
+* to treat the buffers differently.
+*
+* For the time being, use memcpy
 */
memcpy(dst, src, n);
 }
@@ -242,7 +249,7 @@ static inline void vf610_nfc_clear_status(void __iomem 
*regbase)
 }
 
 /* Wait for complete operation */
-static inline void vf610_nfc_done(struct mtd_info *mtd)
+static void vf610_nfc_done(struct mtd_info *mtd)
 {
struct vf610_nfc *nfc = mtd_to_nfc(mtd);
uint start;
@@ -260,7 +267,7 @@ static inl

Re: [U-Boot] [PATCH] mtd: nand: vf610_nfc: resync with upstream Linux version

2015-10-14 Thread Albert ARIBAUD
Hello Stefan,

On Tue, 13 Oct 2015 22:11:42 -0700, Stefan Agner 
wrote:
> This resyncs the driver changes with the Linux version of the
> driver. The driver received some feedback in the LKML and got
> recently acceppted, the latest version can be found here:
> https://lkml.org/lkml/2015/9/2/678
> 
> Notable changes are:
> - On ECC error, reread OOB and count bit flips in OOB too.
>   If flipped bits are below threshold, also return an empty
>   OOB buffer.
> - Return the amount of bit flips in vf610_nfc_read_page.
> - Use endianness aware vf610_nfc_read to read ECC status.
> - Do not enable IDLE IRQ (since we do not operate with an
>   interrupt service routine).
> - Use type safe struct for buffer variants (vf610_nfc_alt_buf).
> - Renamed variables in struct vf610_nfc (column and page_sz)
>   to reflect better what they really representing.
> 
> The U-Boot version currently does not support RAW NAND write
> when using the HW ECC engine.
>  
> Signed-off-by: Bhuvanchandra DV 
> Signed-off-by: Stefan Agner 

If tests were made on vf610twr and colibri_vf, then it would be nice if
testers could send their Tested-By; I think that with these, plus the
one I'll make ASAP under my 3ADEV hat on pcm052, we could take this in
2015.10 along with:

http://patchwork.ozlabs.org/patch/530017/
http://patchwork.ozlabs.org/patch/529986/
http://patchwork.ozlabs.org/patch/529985/

Tom: assuming  tests being
reported as requested, I could pull all these in ARM, test on pcm052,
and PR to main. Ok?

Amicalement,
-- 
Albert.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mtd: nand: vf610_nfc: resync with upstream Linux version

2015-10-14 Thread Albert ARIBAUD
On Wed, 14 Oct 2015 10:43:27 +0200, Albert ARIBAUD
 wrote:

> If tests were made on vf610twr and colibri_vf, then it would be nice if
> testers could send their Tested-By; I think that with these, plus the
> one I'll make ASAP under my 3ADEV hat on pcm052, we could take this in
> 2015.10 along with:
> 
>   http://patchwork.ozlabs.org/patch/530017/
>   http://patchwork.ozlabs.org/patch/529986/
>   http://patchwork.ozlabs.org/patch/529985/

Make that

http://patchwork.ozlabs.org/patch/530017/
http://patchwork.ozlabs.org/patch/529986/
http://patchwork.ozlabs.org/patch/528422/

(removed Fabio's duplicate colibri bstlen fix and added Anthony's vf610twr fix)

Amicalement,
-- 
Albert.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mtd: nand: vf610_nfc: resync with upstream Linux version

2015-10-14 Thread Albert ARIBAUD (3ADEV)
Hello Stefan,

On Tue, 13 Oct 2015 22:11:42 -0700, Stefan Agner 
wrote:
> This resyncs the driver changes with the Linux version of the
> driver. The driver received some feedback in the LKML and got
> recently acceppted, the latest version can be found here:
> https://lkml.org/lkml/2015/9/2/678
> 
> Notable changes are:
> - On ECC error, reread OOB and count bit flips in OOB too.
>   If flipped bits are below threshold, also return an empty
>   OOB buffer.
> - Return the amount of bit flips in vf610_nfc_read_page.
> - Use endianness aware vf610_nfc_read to read ECC status.
> - Do not enable IDLE IRQ (since we do not operate with an
>   interrupt service routine).
> - Use type safe struct for buffer variants (vf610_nfc_alt_buf).
> - Renamed variables in struct vf610_nfc (column and page_sz)
>   to reflect better what they really representing.
> 
> The U-Boot version currently does not support RAW NAND write
> when using the HW ECC engine.
> 
> Signed-off-by: Bhuvanchandra DV 
> Signed-off-by: Stefan Agner 

Tested-by: Albert ARIBAUD (3ADEV) 

Works on pcm052.

Amicalement,
-- 
Albert.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mtd: nand: vf610_nfc: resync with upstream Linux version

2015-10-14 Thread Albert ARIBAUD
On Wed, 14 Oct 2015 13:21:41 +0200, Albert ARIBAUD (3ADEV)
 wrote:
> Hello Stefan,
> 
> On Tue, 13 Oct 2015 22:11:42 -0700, Stefan Agner 
> wrote:
> > This resyncs the driver changes with the Linux version of the
> > driver. The driver received some feedback in the LKML and got
> > recently acceppted, the latest version can be found here:
> > https://lkml.org/lkml/2015/9/2/678
> > 
> > Notable changes are:
> > - On ECC error, reread OOB and count bit flips in OOB too.
> >   If flipped bits are below threshold, also return an empty
> >   OOB buffer.
> > - Return the amount of bit flips in vf610_nfc_read_page.
> > - Use endianness aware vf610_nfc_read to read ECC status.
> > - Do not enable IDLE IRQ (since we do not operate with an
> >   interrupt service routine).
> > - Use type safe struct for buffer variants (vf610_nfc_alt_buf).
> > - Renamed variables in struct vf610_nfc (column and page_sz)
> >   to reflect better what they really representing.
> > 
> > The U-Boot version currently does not support RAW NAND write
> > when using the HW ECC engine.
> > 
> > Signed-off-by: Bhuvanchandra DV 
> > Signed-off-by: Stefan Agner 
> 
> Tested-by: Albert ARIBAUD (3ADEV) 

Putting Stefano Babic in To: list since this is IMX-like stuff.

Stefano,

I can pick this plus Stefan's other two and Anthony's vf610-related
patches if you want, or you can. Either way, Tom will take them as they
are essentially bugfixes.

Amicalement,
-- 
Albert.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mtd: nand: vf610_nfc: resync with upstream Linux version

2015-10-14 Thread Stefan Agner
On 2015-10-14 04:21, Albert ARIBAUD (3ADEV) wrote:
> Hello Stefan,
> 
> On Tue, 13 Oct 2015 22:11:42 -0700, Stefan Agner 
> wrote:
>> This resyncs the driver changes with the Linux version of the
>> driver. The driver received some feedback in the LKML and got
>> recently acceppted, the latest version can be found here:
>> https://lkml.org/lkml/2015/9/2/678
>>
>> Notable changes are:
>> - On ECC error, reread OOB and count bit flips in OOB too.
>>   If flipped bits are below threshold, also return an empty
>>   OOB buffer.
>> - Return the amount of bit flips in vf610_nfc_read_page.
>> - Use endianness aware vf610_nfc_read to read ECC status.
>> - Do not enable IDLE IRQ (since we do not operate with an
>>   interrupt service routine).
>> - Use type safe struct for buffer variants (vf610_nfc_alt_buf).
>> - Renamed variables in struct vf610_nfc (column and page_sz)
>>   to reflect better what they really representing.
>>
>> The U-Boot version currently does not support RAW NAND write
>> when using the HW ECC engine.
>>
>> Signed-off-by: Bhuvanchandra DV 
>> Signed-off-by: Stefan Agner 
> 
> Tested-by: Albert ARIBAUD (3ADEV) 
> 
> Works on pcm052.
> 

Hi Albert,

Sorry I missed mentioning that: We tested extensively on Colibri VF50
and VF61. I tested briefly on the Vybrid Tower board yesterday, NAND
chip is detected properly and read write seems to work.

So, you can also add my tested by tag if you wish:
Tested-by: Stefan Agner 

--
Stefan
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mtd: nand: vf610_nfc: resync with upstream Linux version

2015-10-14 Thread Scott Wood
On Wed, 2015-10-14 at 13:27 +0200, Albert ARIBAUD wrote:
> On Wed, 14 Oct 2015 13:21:41 +0200, Albert ARIBAUD (3ADEV)
>  wrote:
> > Hello Stefan,
> > 
> > On Tue, 13 Oct 2015 22:11:42 -0700, Stefan Agner 
> > wrote:
> > > This resyncs the driver changes with the Linux version of the
> > > driver. The driver received some feedback in the LKML and got
> > > recently acceppted, the latest version can be found here:
> > > https://lkml.org/lkml/2015/9/2/678
> > > 
> > > Notable changes are:
> > > - On ECC error, reread OOB and count bit flips in OOB too.
> > >   If flipped bits are below threshold, also return an empty
> > >   OOB buffer.
> > > - Return the amount of bit flips in vf610_nfc_read_page.
> > > - Use endianness aware vf610_nfc_read to read ECC status.
> > > - Do not enable IDLE IRQ (since we do not operate with an
> > >   interrupt service routine).
> > > - Use type safe struct for buffer variants (vf610_nfc_alt_buf).
> > > - Renamed variables in struct vf610_nfc (column and page_sz)
> > >   to reflect better what they really representing.
> > > 
> > > The U-Boot version currently does not support RAW NAND write
> > > when using the HW ECC engine.
> > > 
> > > Signed-off-by: Bhuvanchandra DV 
> > > Signed-off-by: Stefan Agner 
> > 
> > Tested-by: Albert ARIBAUD (3ADEV) 
> 
> Putting Stefano Babic in To: list since this is IMX-like stuff.
> 
> Stefano,
> 
> I can pick this plus Stefan's other two and Anthony's vf610-related
> patches if you want, or you can. Either way, Tom will take them as they
> are essentially bugfixes.

Acked-by: Scott Wood 

-Scott

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mtd: nand: vf610_nfc: resync with upstream Linux version

2015-10-15 Thread Stefano Babic
On 15/10/2015 06:00, Scott Wood wrote:
> On Wed, 2015-10-14 at 13:27 +0200, Albert ARIBAUD wrote:
>> On Wed, 14 Oct 2015 13:21:41 +0200, Albert ARIBAUD (3ADEV)
>>  wrote:
>>> Hello Stefan,
>>>
>>> On Tue, 13 Oct 2015 22:11:42 -0700, Stefan Agner 
>>> wrote:
 This resyncs the driver changes with the Linux version of the
 driver. The driver received some feedback in the LKML and got
 recently acceppted, the latest version can be found here:
 https://lkml.org/lkml/2015/9/2/678

 Notable changes are:
 - On ECC error, reread OOB and count bit flips in OOB too.
   If flipped bits are below threshold, also return an empty
   OOB buffer.
 - Return the amount of bit flips in vf610_nfc_read_page.
 - Use endianness aware vf610_nfc_read to read ECC status.
 - Do not enable IDLE IRQ (since we do not operate with an
   interrupt service routine).
 - Use type safe struct for buffer variants (vf610_nfc_alt_buf).
 - Renamed variables in struct vf610_nfc (column and page_sz)
   to reflect better what they really representing.

 The U-Boot version currently does not support RAW NAND write
 when using the HW ECC engine.

 Signed-off-by: Bhuvanchandra DV 
 Signed-off-by: Stefan Agner 
>>>
>>> Tested-by: Albert ARIBAUD (3ADEV) 
>>
>> Putting Stefano Babic in To: list since this is IMX-like stuff.
>>
>> Stefano,
>>
>> I can pick this plus Stefan's other two and Anthony's vf610-related
>> patches if you want, or you can. Either way, Tom will take them as they
>> are essentially bugfixes.
>
> Acked-by: Scott Wood 
>


Thanks Scott. I am picking this one and a couple of other patches and I
will send my PR to Tom.

Best regards,
Stefano



-- 
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot