Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-03-15 Thread Tathagata Das
Hi Hauke,
 Thanks for adding that patch. I tested it and it worked on my device.

Regards,
Tatha

-Original Message-
From: Hauke Mehrtens [mailto:ha...@hauke-m.de] 
Sent: 15 March 2012 05:02
To: Tathagata Das
Cc: 'OpenWrt Development List'; 'Florian Fainelli'
Subject: Re: [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA 
NAND flash

On 03/12/2012 08:31 AM, Tathagata Das wrote:
 Hi Hauke,
  That code works on my device as well. Attached is the updated kernel patch 
 to support brcm47xx BCMA NAND flash.
 
 Regards,
 Tatha
 
 -Original Message-
 From: Hauke Mehrtens [mailto:ha...@hauke-m.de] 
 Sent: 10 March 2012 05:01
 To: Tathagata Das
 Cc: 'OpenWrt Development List'; 'Florian Fainelli'
 Subject: Re: [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA 
 NAND flash
 
 Hi Tatha,
 
 sorry for answering so late I am currently very busy.
 
 If I set CONFIG_BCMA_SFLASH=y and CONFIG_BCMA_NFLASH=y in the kernel
 config, which I want to do for the default image in OpenWrt the image
 will not work on by device with serial flash any more because
 bus-drv_cc.flash_type will contain BCMA_NFLASH and not BCMA_SFLASH. The
 patch in the mail I linked does not work as is with the current version
 of your patch but you should be able to modify it. ;-)
 The code in the linked mail should be able to detect nand flash at
 runtime. Without this modification it does not work on my device, which
 uses serial flash, but I do not know if it works on your device with
 nand flash.
 

Hi Tatha,

the patch was finally added with some small modifications in commit
r30943. Could you please try if current trunk is working on your device.

Hauke





___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-03-14 Thread Hauke Mehrtens
On 03/12/2012 08:31 AM, Tathagata Das wrote:
 Hi Hauke,
  That code works on my device as well. Attached is the updated kernel patch 
 to support brcm47xx BCMA NAND flash.
 
 Regards,
 Tatha
 
 -Original Message-
 From: Hauke Mehrtens [mailto:ha...@hauke-m.de] 
 Sent: 10 March 2012 05:01
 To: Tathagata Das
 Cc: 'OpenWrt Development List'; 'Florian Fainelli'
 Subject: Re: [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA 
 NAND flash
 
 Hi Tatha,
 
 sorry for answering so late I am currently very busy.
 
 If I set CONFIG_BCMA_SFLASH=y and CONFIG_BCMA_NFLASH=y in the kernel
 config, which I want to do for the default image in OpenWrt the image
 will not work on by device with serial flash any more because
 bus-drv_cc.flash_type will contain BCMA_NFLASH and not BCMA_SFLASH. The
 patch in the mail I linked does not work as is with the current version
 of your patch but you should be able to modify it. ;-)
 The code in the linked mail should be able to detect nand flash at
 runtime. Without this modification it does not work on my device, which
 uses serial flash, but I do not know if it works on your device with
 nand flash.
 

Hi Tatha,

the patch was finally added with some small modifications in commit
r30943. Could you please try if current trunk is working on your device.

Hauke



___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-03-09 Thread Hauke Mehrtens
Hi Tatha,

sorry for answering so late I am currently very busy.

If I set CONFIG_BCMA_SFLASH=y and CONFIG_BCMA_NFLASH=y in the kernel
config, which I want to do for the default image in OpenWrt the image
will not work on by device with serial flash any more because
bus-drv_cc.flash_type will contain BCMA_NFLASH and not BCMA_SFLASH. The
patch in the mail I linked does not work as is with the current version
of your patch but you should be able to modify it. ;-)
The code in the linked mail should be able to detect nand flash at
runtime. Without this modification it does not work on my device, which
uses serial flash, but I do not know if it works on your device with
nand flash.

Hauke

On 03/01/2012 06:06 AM, Tathagata Das wrote:
 Hi Hauke,
  Changes mentioned in 
 https://lists.openwrt.org/pipermail/openwrt-devel/2012-January/013481.html 
 will not work now as there is no such bcma_nflash_init() function anymore. 
 Now flash detection is done only once and that is in NAND flash section using 
 generic function nand_scan_ident.
 
 Regards,
 Tatha
 
 -Original Message-
 From: Hauke Mehrtens [mailto:ha...@hauke-m.de] 
 Sent: 01 March 2012 04:39
 To: Tathagata Das
 Cc: 'OpenWrt Development List'; 'Florian Fainelli'
 Subject: Re: [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA 
 NAND flash
 
 On 02/27/2012 09:44 AM, Tathagata Das wrote:
 Hi Hauke,
  I have modified my patch according to your comments except in two cases.

 We want to build one image supporting devices with serial and with nand 
 flash. This makes it just possible to support one flash type at a time.
 Right now flash type can be either NAND or SERIAL. If we want to have two 
 flash simultaneously then I think we need to have another parameter similar 
 to bcma_flash_type flash_type What is your opinion ?
 I want to build one image which can be flashed onto a device which uses
 NAND flash or a device using serial flash. I have never seen any device
 with two (different) flash chips, so this does not have to be supported.
 In the last patch it is only possible to build an image which will use
 NAND flash or an image which will support serial flash, they are
 exclusive or. I want to have it like it is for parallel and serial flash
 where you are able to build an image with support for both and it auto
 detects it when booting and loads the correct driver.
 
 What about using this code, it work correctly on my device with serial
 flash, but I do not know if it correctly detects nand flash?
 https://lists.openwrt.org/pipermail/openwrt-devel/2012-January/013481.html
 
 cpu_relax();
  Why is this needed?
 Above change was done according to Florian's comment. 
 
 using cpu_relax() is correct there, I just read some documentations
 about it.
 

 Florian,
  Can you clarify it ?

 Once these above cases resolve I will provide you the updated patch.

 Regards,
 Tatha

 -Original Message-
 From: Hauke Mehrtens [mailto:ha...@hauke-m.de] 
 Sent: 25 February 2012 19:08
 To: Tathagata Das
 Cc: 'OpenWrt Development List'; 'Florian Fainelli'
 Subject: Re: [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA 
 NAND flash

 Hi Tathagata Das,

 I had a look at bthe patch and added some comments, if bcma_nflash_init
 is not needed any more where is struct bcma_nflash initilized?

 Hauke

 On 02/23/2012 02:27 PM, Tathagata Das wrote:
 Hi,
   Attached is the updated kernel patch to support brcm47xx BCMA NAND flash. 
 I have used latest trunk source code to create this patch.
 Thanks to Florian and Hauke for their comments.

 Regards,
 Tathagata tathag...@alumnux.com

 diff -Naur a/arch/mips/bcm47xx/bus.c b/arch/mips/bcm47xx/bus.c
 --- a/arch/mips/bcm47xx/bus.c   2012-02-17 16:34:21.0 +0530
 +++ b/arch/mips/bcm47xx/bus.c   2012-02-23 18:22:17.0 +0530
 @@ -2,6 +2,7 @@
   * BCM947xx nvram variable access
   *
   * Copyright (C) 2011 Hauke Mehrtens ha...@hauke-m.de
 + * Copyright (C) 2011-2012 Tathagata Das tathag...@alumnux.com
   *
   * 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
 @@ -92,3 +93,9 @@
 sflash-numblocks = scc-sflash.numblocks;
 sflash-size = scc-sflash.size;
  }
 +
 +void bcm47xx_nflash_struct_bcma_init(struct bcm47xx_nflash *nflash, struct 
 bcma_drv_cc *bcc)
 +{
 +   nflash-nflash_type = BCM47XX_BUS_TYPE_BCMA;
 +   nflash-bcc = bcc;
 +}
 diff -Naur a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
 --- a/arch/mips/bcm47xx/nvram.c 2012-02-17 16:34:22.0 +0530
 +++ b/arch/mips/bcm47xx/nvram.c 2012-02-23 18:20:57.0 +0530
 @@ -4,6 +4,7 @@
   * Copyright (C) 2005 Broadcom Corporation
   * Copyright (C) 2006 Felix Fietkau n...@openwrt.org
   * Copyright (C) 2010-2011 Hauke Mehrtens ha...@hauke-m.de
 + * Copyright (C) 2011-2012 Tathagata Das tathag...@alumnux.com
   *
   * This program is free software; you can redistribute  it and/or modify it
   * under  

[OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-02-29 Thread Tathagata Das
Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND flash. It 
contains fix of issue in write small length.
I have used latest trunk source code to create this patch. I have tested it on 
Netgear WNR3500Lv2.

Thanks all who gave comments.

Regards,
Tathagata tathag...@alumnux.com


9991-bcm47xx-bcma-nandflash.patch
Description: Binary data
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-02-28 Thread Tathagata Das
Hi Florian,
  Please find my inline comments.

Regards,
Tatha

-Original Message-
From: Florian Fainelli [mailto:f.faine...@gmail.com] On Behalf Of Florian 
Fainelli
Sent: 28 February 2012 14:54
To: Tathagata Das
Cc: 'OpenWrt Development List'; 'Hauke Mehrtens'
Subject: Re: [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA 
NAND flash

Hello Tatha,

Le 02/28/12 07:50, Tathagata Das a écrit :
 Hi,
Attached is the updated kernel patch to support brcm47xx BCMA NAND flash.
 I have used latest trunk source code to create this patch. I have tested it 
 on Netgear WNR3500Lv2.

 Thanks to Florian and Hauke for their comments.

And thank you for your efforts on this, I am sorry, but I found a couple 
of small issues in your patch, which I attached inline for easier 
commenting:

9991-bcm47xx-bcma-nandflash.patch


diff -Naur a/arch/mips/bcm47xx/bus.c b/arch/mips/bcm47xx/bus.c
--- a/arch/mips/bcm47xx/bus.c   2012-02-17 16:34:21.0 +0530
+++ b/arch/mips/bcm47xx/bus.c   2012-02-23 18:22:17.0 +0530
@@ -2,6 +2,7 @@
   * BCM947xx nvram variable access
   *
   * Copyright (C) 2011 Hauke Mehrtensha...@hauke-m.de
+ * Copyright (C) 2011-2012 Tathagata Dastathag...@alumnux.com
   *
   * 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
@@ -92,3 +93,9 @@
sflash-numblocks = scc-sflash.numblocks;
sflash-size = scc-sflash.size;
  }
+
+void bcm47xx_nflash_struct_bcma_init(struct bcm47xx_nflash *nflash, struct 
bcma_drv_cc *bcc)
+{
+   nflash-nflash_type = BCM47XX_BUS_TYPE_BCMA;
+   nflash-bcc = bcc;
+}
diff -Naur a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
--- a/arch/mips/bcm47xx/nvram.c 2012-02-17 16:34:22.0 +0530
+++ b/arch/mips/bcm47xx/nvram.c 2012-02-23 18:20:57.0 +0530
@@ -4,6 +4,7 @@
   * Copyright (C) 2005 Broadcom Corporation
   * Copyright (C) 2006 Felix Fietkaun...@openwrt.org
   * Copyright (C) 2010-2011 Hauke Mehrtensha...@hauke-m.de
+ * Copyright (C) 2011-2012 Tathagata Dastathag...@alumnux.com
   *
   * 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
@@ -21,6 +22,7 @@
  #includeasm/mach-bcm47xx/nvram.h
  #includeasm/mach-bcm47xx/bcm47xx.h
  #includeasm/mach-bcm47xx/bus.h
+#includelinux/mtd/bcm47xx_nand.h

  char nvram_buf[NVRAM_SPACE];
  EXPORT_SYMBOL(nvram_buf);
@@ -159,6 +161,53 @@
return 0;
  }

+static int early_nvram_init_nflash(void)
+{
+   struct nvram_header *header;
+   u32 off;
+   int ret;
+   int len;
+   u32 flash_size = bcm47xx_nflash.size;
+   u8 tmpbuf[NFL_SECTOR_SIZE];
+   int i;
+   u32 *src, *dst;
+
+   /* check if the struct is already initilized */
+   if (!flash_size)
+   return -1;
+   
+   cfe_env = 0;
+
+   off = FLASH_MIN;
+   while (off= flash_size) {
+   ret = bcma_nflash_read(bcm47xx_nflash.bcc, off, 
NFL_SECTOR_SIZE, tmpbuf);
+   if (ret != NFL_SECTOR_SIZE) {
+   goto done;
+   }

The brackets here are not required.

[Tatha]: Done.

  + header = (struct nvram_header *)tmpbuf;
+   if (header-magic == NVRAM_HEADER) {
+   goto found;
+   }

They are not required here too.

[Tatha]: Done.

  + off= 1;
+   }
+
+   ret = -1;
+   goto done;
+
+found:
+   len = header-len;
+   header = (struct nvram_header *) KSEG1ADDR(NAND_FLASH1 + off);
+   src = (u32 *) header;
+   dst = (u32 *) nvram_buf;
+   for (i = 0; i  sizeof(struct nvram_header); i += 4)
+   *dst++ = *src++;
+   for (; i  len  i  NVRAM_SPACE; i += 4)
+   *dst++ = *src++;

Did you have to do this because memcpy() did not work, due to byte access 
instead of word access?

[Tatha]: Yes, you are right.

  + ret = 0;
+done:
+   return ret;
+}
+
[snip]

+
+/* Issue a nand flash command */
+static inline void bcma_nflash_cmd(struct bcma_drv_cc *cc, u32 opcode)
+{
+   bcma_cc_write32(cc, NAND_CMD_START, opcode);
+   bcma_cc_read32(cc,  NAND_CMD_START);
+}
+
+/* Check offset and length */
+static int bcma_nflash_offset_is_valid(struct bcma_drv_cc *cc, u32 offset, u32 
len, u32 mask)
+{
+   if ((offset  mask) != 0 || (len  mask) != 0) {
+   pr_err(%s(): Address is not aligned. offset: %x, len: %x, 
mask: %x\n, __func__, offset, len, mask);
+   BUG_ON(1);
+   return 1;
+   }

a BUG_ON() here is a little hard, just the printk should be sufficient in case 
someone is doing unaligned accesses.

[Tatha]: Done.

  +
+   if offset + len)  20)  cc-nflash.size) ||
+   offset + len)  20) == cc-nflash.size)

these two lines are equal to:

((offset + len)  20)= cc-nflash.size

[Tatha]: Done. 

  + (((offset + len)  

Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-02-28 Thread Tathagata Das
I have found one issue in write function.
If the length of writing data is smaller than pagesize then it fails to write. 
I am now solving this issue.

Regards,
Tathagata

-Original Message-
From: Tathagata Das [mailto:tathag...@alumnux.com] 
Sent: 28 February 2012 12:20
To: 'OpenWrt Development List'
Cc: 'Florian Fainelli'; 'Hauke Mehrtens'
Subject: [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND 
flash

Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND flash.
I have used latest trunk source code to create this patch. I have tested it on 
Netgear WNR3500Lv2.

Thanks to Florian and Hauke for their comments.

Regards,
Tathagata tathag...@alumnux.com

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-02-28 Thread Florian Fainelli

Hello Tatha,

Le 02/28/12 07:50, Tathagata Das a écrit :

Hi,
   Attached is the updated kernel patch to support brcm47xx BCMA NAND flash.
I have used latest trunk source code to create this patch. I have tested it on 
Netgear WNR3500Lv2.

Thanks to Florian and Hauke for their comments.


And thank you for your efforts on this, I am sorry, but I found a couple 
of small issues in your patch, which I attached inline for easier 
commenting:


9991-bcm47xx-bcma-nandflash.patch


diff -Naur a/arch/mips/bcm47xx/bus.c b/arch/mips/bcm47xx/bus.c
--- a/arch/mips/bcm47xx/bus.c   2012-02-17 16:34:21.0 +0530
+++ b/arch/mips/bcm47xx/bus.c   2012-02-23 18:22:17.0 +0530
@@ -2,6 +2,7 @@
  * BCM947xx nvram variable access
  *
  * Copyright (C) 2011 Hauke Mehrtensha...@hauke-m.de
+ * Copyright (C) 2011-2012 Tathagata Dastathag...@alumnux.com
  *
  * 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
@@ -92,3 +93,9 @@
sflash-numblocks = scc-sflash.numblocks;
sflash-size = scc-sflash.size;
 }
+
+void bcm47xx_nflash_struct_bcma_init(struct bcm47xx_nflash *nflash, struct 
bcma_drv_cc *bcc)
+{
+   nflash-nflash_type = BCM47XX_BUS_TYPE_BCMA;
+   nflash-bcc = bcc;
+}
diff -Naur a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
--- a/arch/mips/bcm47xx/nvram.c 2012-02-17 16:34:22.0 +0530
+++ b/arch/mips/bcm47xx/nvram.c 2012-02-23 18:20:57.0 +0530
@@ -4,6 +4,7 @@
  * Copyright (C) 2005 Broadcom Corporation
  * Copyright (C) 2006 Felix Fietkaun...@openwrt.org
  * Copyright (C) 2010-2011 Hauke Mehrtensha...@hauke-m.de
+ * Copyright (C) 2011-2012 Tathagata Dastathag...@alumnux.com
  *
  * 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
@@ -21,6 +22,7 @@
 #includeasm/mach-bcm47xx/nvram.h
 #includeasm/mach-bcm47xx/bcm47xx.h
 #includeasm/mach-bcm47xx/bus.h
+#includelinux/mtd/bcm47xx_nand.h

 char nvram_buf[NVRAM_SPACE];
 EXPORT_SYMBOL(nvram_buf);
@@ -159,6 +161,53 @@
return 0;
 }

+static int early_nvram_init_nflash(void)
+{
+   struct nvram_header *header;
+   u32 off;
+   int ret;
+   int len;
+   u32 flash_size = bcm47xx_nflash.size;
+   u8 tmpbuf[NFL_SECTOR_SIZE];
+   int i;
+   u32 *src, *dst;
+
+   /* check if the struct is already initilized */
+   if (!flash_size)
+   return -1;
+   
+   cfe_env = 0;
+
+   off = FLASH_MIN;
+   while (off= flash_size) {
+   ret = bcma_nflash_read(bcm47xx_nflash.bcc, off, 
NFL_SECTOR_SIZE, tmpbuf);
+   if (ret != NFL_SECTOR_SIZE) {
+   goto done;
+   }

The brackets here are not required.

 +  header = (struct nvram_header *)tmpbuf;
+   if (header-magic == NVRAM_HEADER) {
+   goto found;
+   }

They are not required here too.

 +  off= 1;
+   }
+
+   ret = -1;
+   goto done;
+
+found:
+   len = header-len;
+   header = (struct nvram_header *) KSEG1ADDR(NAND_FLASH1 + off);
+   src = (u32 *) header;
+   dst = (u32 *) nvram_buf;
+   for (i = 0; i  sizeof(struct nvram_header); i += 4)
+   *dst++ = *src++;
+   for (; i  len  i  NVRAM_SPACE; i += 4)
+   *dst++ = *src++;

Did you have to do this because memcpy() did not work, due to byte access 
instead of word access?

 +  ret = 0;
+done:
+   return ret;
+}
+
[snip]

+
+/* Issue a nand flash command */
+static inline void bcma_nflash_cmd(struct bcma_drv_cc *cc, u32 opcode)
+{
+   bcma_cc_write32(cc, NAND_CMD_START, opcode);
+   bcma_cc_read32(cc,  NAND_CMD_START);
+}
+
+/* Check offset and length */
+static int bcma_nflash_offset_is_valid(struct bcma_drv_cc *cc, u32 offset, u32 
len, u32 mask)
+{
+   if ((offset  mask) != 0 || (len  mask) != 0) {
+   pr_err(%s(): Address is not aligned. offset: %x, len: %x, mask: 
%x\n, __func__, offset, len, mask);
+   BUG_ON(1);
+   return 1;
+   }

a BUG_ON() here is a little hard, just the printk should be sufficient in case 
someone is doing unaligned accesses.

 +
+   if offset + len)  20)  cc-nflash.size) ||
+   offset + len)  20) == cc-nflash.size)

these two lines are equal to:

((offset + len)  20)= cc-nflash.size

 +  (((offset + len)  ((1  20) - 1)) != 0))) {
+   pr_err(%s(): Address is outside Flash memory region. offset: %x, 
len: %x, mask: %x\n, __func__, offset, len, mask);
+   return 1;
+   }
+
+   return 0;
+}

Everything else is fine from my perspective otherwise.

Thank you.
--
Florian

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-02-27 Thread Tathagata Das
Hi Hauke,
 I have modified my patch according to your comments except in two cases.

We want to build one image supporting devices with serial and with nand flash. 
This makes it just possible to support one flash type at a time.
Right now flash type can be either NAND or SERIAL. If we want to have two flash 
simultaneously then I think we need to have another parameter similar to 
bcma_flash_type flash_type What is your opinion ?

cpu_relax();
 Why is this needed?
Above change was done according to Florian's comment. 

Florian,
 Can you clarify it ?

Once these above cases resolve I will provide you the updated patch.

Regards,
Tatha

-Original Message-
From: Hauke Mehrtens [mailto:ha...@hauke-m.de] 
Sent: 25 February 2012 19:08
To: Tathagata Das
Cc: 'OpenWrt Development List'; 'Florian Fainelli'
Subject: Re: [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA 
NAND flash

Hi Tathagata Das,

I had a look at bthe patch and added some comments, if bcma_nflash_init
is not needed any more where is struct bcma_nflash initilized?

Hauke

On 02/23/2012 02:27 PM, Tathagata Das wrote:
 Hi,
   Attached is the updated kernel patch to support brcm47xx BCMA NAND flash. I 
 have used latest trunk source code to create this patch.
 Thanks to Florian and Hauke for their comments.
 
 Regards,
 Tathagata tathag...@alumnux.com
 
 diff -Naur a/arch/mips/bcm47xx/bus.c b/arch/mips/bcm47xx/bus.c
 --- a/arch/mips/bcm47xx/bus.c 2012-02-17 16:34:21.0 +0530
 +++ b/arch/mips/bcm47xx/bus.c 2012-02-23 18:22:17.0 +0530
 @@ -2,6 +2,7 @@
   * BCM947xx nvram variable access
   *
   * Copyright (C) 2011 Hauke Mehrtens ha...@hauke-m.de
 + * Copyright (C) 2011-2012 Tathagata Das tathag...@alumnux.com
   *
   * 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
 @@ -92,3 +93,9 @@
   sflash-numblocks = scc-sflash.numblocks;
   sflash-size = scc-sflash.size;
  }
 +
 +void bcm47xx_nflash_struct_bcma_init(struct bcm47xx_nflash *nflash, struct 
 bcma_drv_cc *bcc)
 +{
 + nflash-nflash_type = BCM47XX_BUS_TYPE_BCMA;
 + nflash-bcc = bcc;
 +}
 diff -Naur a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
 --- a/arch/mips/bcm47xx/nvram.c   2012-02-17 16:34:22.0 +0530
 +++ b/arch/mips/bcm47xx/nvram.c   2012-02-23 18:20:57.0 +0530
 @@ -4,6 +4,7 @@
   * Copyright (C) 2005 Broadcom Corporation
   * Copyright (C) 2006 Felix Fietkau n...@openwrt.org
   * Copyright (C) 2010-2011 Hauke Mehrtens ha...@hauke-m.de
 + * Copyright (C) 2011-2012 Tathagata Das tathag...@alumnux.com
   *
   * 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
 @@ -21,6 +22,7 @@
  #include asm/mach-bcm47xx/nvram.h
  #include asm/mach-bcm47xx/bcm47xx.h
  #include asm/mach-bcm47xx/bus.h
 +#include linux/mtd/bcm47xx_nand.h
  
  char nvram_buf[NVRAM_SPACE];
  EXPORT_SYMBOL(nvram_buf);
 @@ -159,6 +161,53 @@
   return 0;
  }
  
 +static int early_nvram_init_nflash(void)
 +{
 + struct nvram_header *header;
 + u32 off;
 + int ret;
 + int len;
 + u32 flash_size = bcm47xx_nflash.size;
 + u8 tmpbuf[NFL_SECTOR_SIZE];
 + int i;
 + u32 *src, *dst;
 +
 + /* check if the struct is already initilized */
 + if (!flash_size)
 + return -1;
 + 
 + cfe_env = 0;
 +
 + off = FLASH_MIN;
 + while (off = flash_size) {
 + ret = bcma_nflash_read(bcm47xx_nflash.bcc, off, 
 NFL_SECTOR_SIZE, tmpbuf);
 + if (ret != NFL_SECTOR_SIZE) {
 + goto done;
 + }
 + header = (struct nvram_header *)tmpbuf;
 + if (header-magic == NVRAM_HEADER) {
 + goto found;
 + }
 + off = 1;
 + }
 +
 + ret = -1;
 + goto done;
 +
 +found:
 + len = header-len;
 + header = (struct nvram_header *) KSEG1ADDR(NAND_FLASH1 + off);
 + src = (u32 *) header;
 + dst = (u32 *) nvram_buf;
 + for (i = 0; i  sizeof(struct nvram_header); i += 4)
 + *dst++ = *src++;
 + for (; i  len  i  NVRAM_SPACE; i += 4)
 + *dst++ = *src++;
 + ret = 0;
 +done:
 + return ret;
 +}
 +
  static void early_nvram_init(void)
  {
   int err = 0;
 @@ -185,6 +234,10 @@
   err = early_nvram_init_sflash();
   if (err  0)
   printk(KERN_WARNING can not read from flash: 
 %i\n, err);
 + } else if (bcm47xx_bus.bcma.bus.drv_cc.flash_type == 
 BCMA_NFLASH) {
 + err = early_nvram_init_nflash();
 + if (err  0)
 + printk(KERN_WARNING can not read from nflash: 
 %i\n, err);
   } else {
   printk(KERN_WARNING unknow flash type\n);
   }
I am not happy with the flash driver 

[OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-02-27 Thread Tathagata Das
Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND flash. 
I have used latest trunk source code to create this patch. I have tested it on 
Netgear WNR3500Lv2.

Thanks to Florian and Hauke for their comments.

Regards,
Tathagata tathag...@alumnux.com


9991-bcm47xx-bcma-nandflash.patch
Description: Binary data
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-02-25 Thread Hauke Mehrtens
Hi Tathagata Das,

I had a look at bthe patch and added some comments, if bcma_nflash_init
is not needed any more where is struct bcma_nflash initilized?

Hauke

On 02/23/2012 02:27 PM, Tathagata Das wrote:
 Hi,
   Attached is the updated kernel patch to support brcm47xx BCMA NAND flash. I 
 have used latest trunk source code to create this patch.
 Thanks to Florian and Hauke for their comments.
 
 Regards,
 Tathagata tathag...@alumnux.com
 
 diff -Naur a/arch/mips/bcm47xx/bus.c b/arch/mips/bcm47xx/bus.c
 --- a/arch/mips/bcm47xx/bus.c 2012-02-17 16:34:21.0 +0530
 +++ b/arch/mips/bcm47xx/bus.c 2012-02-23 18:22:17.0 +0530
 @@ -2,6 +2,7 @@
   * BCM947xx nvram variable access
   *
   * Copyright (C) 2011 Hauke Mehrtens ha...@hauke-m.de
 + * Copyright (C) 2011-2012 Tathagata Das tathag...@alumnux.com
   *
   * 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
 @@ -92,3 +93,9 @@
   sflash-numblocks = scc-sflash.numblocks;
   sflash-size = scc-sflash.size;
  }
 +
 +void bcm47xx_nflash_struct_bcma_init(struct bcm47xx_nflash *nflash, struct 
 bcma_drv_cc *bcc)
 +{
 + nflash-nflash_type = BCM47XX_BUS_TYPE_BCMA;
 + nflash-bcc = bcc;
 +}
 diff -Naur a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
 --- a/arch/mips/bcm47xx/nvram.c   2012-02-17 16:34:22.0 +0530
 +++ b/arch/mips/bcm47xx/nvram.c   2012-02-23 18:20:57.0 +0530
 @@ -4,6 +4,7 @@
   * Copyright (C) 2005 Broadcom Corporation
   * Copyright (C) 2006 Felix Fietkau n...@openwrt.org
   * Copyright (C) 2010-2011 Hauke Mehrtens ha...@hauke-m.de
 + * Copyright (C) 2011-2012 Tathagata Das tathag...@alumnux.com
   *
   * 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
 @@ -21,6 +22,7 @@
  #include asm/mach-bcm47xx/nvram.h
  #include asm/mach-bcm47xx/bcm47xx.h
  #include asm/mach-bcm47xx/bus.h
 +#include linux/mtd/bcm47xx_nand.h
  
  char nvram_buf[NVRAM_SPACE];
  EXPORT_SYMBOL(nvram_buf);
 @@ -159,6 +161,53 @@
   return 0;
  }
  
 +static int early_nvram_init_nflash(void)
 +{
 + struct nvram_header *header;
 + u32 off;
 + int ret;
 + int len;
 + u32 flash_size = bcm47xx_nflash.size;
 + u8 tmpbuf[NFL_SECTOR_SIZE];
 + int i;
 + u32 *src, *dst;
 +
 + /* check if the struct is already initilized */
 + if (!flash_size)
 + return -1;
 + 
 + cfe_env = 0;
 +
 + off = FLASH_MIN;
 + while (off = flash_size) {
 + ret = bcma_nflash_read(bcm47xx_nflash.bcc, off, 
 NFL_SECTOR_SIZE, tmpbuf);
 + if (ret != NFL_SECTOR_SIZE) {
 + goto done;
 + }
 + header = (struct nvram_header *)tmpbuf;
 + if (header-magic == NVRAM_HEADER) {
 + goto found;
 + }
 + off = 1;
 + }
 +
 + ret = -1;
 + goto done;
 +
 +found:
 + len = header-len;
 + header = (struct nvram_header *) KSEG1ADDR(NAND_FLASH1 + off);
 + src = (u32 *) header;
 + dst = (u32 *) nvram_buf;
 + for (i = 0; i  sizeof(struct nvram_header); i += 4)
 + *dst++ = *src++;
 + for (; i  len  i  NVRAM_SPACE; i += 4)
 + *dst++ = *src++;
 + ret = 0;
 +done:
 + return ret;
 +}
 +
  static void early_nvram_init(void)
  {
   int err = 0;
 @@ -185,6 +234,10 @@
   err = early_nvram_init_sflash();
   if (err  0)
   printk(KERN_WARNING can not read from flash: 
 %i\n, err);
 + } else if (bcm47xx_bus.bcma.bus.drv_cc.flash_type == 
 BCMA_NFLASH) {
 + err = early_nvram_init_nflash();
 + if (err  0)
 + printk(KERN_WARNING can not read from nflash: 
 %i\n, err);
   } else {
   printk(KERN_WARNING unknow flash type\n);
   }
I am not happy with the flash driver usage in arch/bcm47xx/ entirely and
will change it some time so I am ok with this.
 diff -Naur a/arch/mips/bcm47xx/setup.c b/arch/mips/bcm47xx/setup.c
 --- a/arch/mips/bcm47xx/setup.c   2012-02-17 16:34:22.0 +0530
 +++ b/arch/mips/bcm47xx/setup.c   2012-02-23 18:21:15.0 +0530
 @@ -4,6 +4,7 @@
   *  Copyright (C) 2006 Michael Buesch m...@bu3sch.de
   *  Copyright (C) 2010 Waldemar Brodkorb w...@openadk.org
   *  Copyright (C) 2010-2011 Hauke Mehrtens ha...@hauke-m.de
 + *  Copyright (C) 2011-2012 Tathagata Das tathag...@alumnux.com
   *
   *  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
 @@ -47,6 +48,7 @@
  EXPORT_SYMBOL(bcm47xx_bus_type);
  
  struct bcm47xx_sflash bcm47xx_sflash;
 +struct bcm47xx_nflash bcm47xx_nflash;
  
  static void bcm47xx_machine_restart(char 

[OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-02-23 Thread Tathagata Das
Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND flash. I 
have used latest trunk source code to create this patch.
Thanks to Florian and Hauke for their comments.

Regards,
Tathagata tathag...@alumnux.com


9991-bcm47xx-bcma-nandflash.patch
Description: Binary data
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-02-15 Thread Tathagata Das
Hi Hauke,
 Yes, I am still working on that patch. I am now integrating Florian
comments. Also I found couple of issues in write and erase functions. I have
solved them too.
I will submit my patch quickly.

Regards,
Tathagata

-Original Message-
From: Hauke Mehrtens [mailto:ha...@hauke-m.de] 
Sent: 14 February 2012 15:16
To: tathag...@alumnux.com; OpenWrt Development List
Cc: Florian Fainelli
Subject: Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to
support brcm47xx BCMA NAND flash

On 01/12/2012 02:48 PM, Tathagata Das wrote:
 Hi Florian,
  Thanks a lot for your comment. I will update the patch accordingly.
 
 Regards,
 Tathagata
 
Hi Tathagata,

are you still working on this patch? I would relay like to see NAND
flash support in OpenWrt. When you integrated Florian comments into the
patch it should be good enough to be integrated.

Hauke


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-01-13 Thread Hauke Mehrtens
Hi Tathagata,

My device uses serial flash and not nand flash. From the Broadcom SDK I
got the following code to detect a device using nflash. When using this
code in drivers/bcma/driver_mips.c instead of the detection you had in
it before bcma do not want to initialize nflash for my device and it
still works with serial flash. Does this code also work for you?

Hauke

--- a/drivers/bcma/driver_mips.c
+++ b/drivers/bcma/driver_mips.c
@@ -182,6 +182,21 @@ static void bcma_core_mips_flash_detect(struct
bcma_drv_mips *mcore)
 {
struct bcma_bus *bus = mcore-core-bus;

+   if (bus-drv_cc.core-id.rev == 38 
+   (bus-drv_cc.status  (1  4)) != 0) {
+#ifdef CONFIG_BCMA_NFLASH
+   pr_info(found nand flash.\n);
+   bus-drv_cc.flash_type = BCMA_NFLASH;
+   if (!bcma_nflash_init(bus-drv_cc)) {
+   pr_err(problem initializing nand flash);
+   return;
+   }
+#else
+   pr_info(NAND flash not supported.\n);
+#endif
+   return;
+   }
+
switch (bus-drv_cc.capabilities  BCMA_CC_CAP_FLASHT) {
case BCMA_CC_FLASHT_STSER:
case BCMA_CC_FLASHT_ATSER:

On 01/12/2012 12:41 PM, Tathagata Das wrote:
 Hi Hauke,
  I guess some NAND flash specific code are not under NAND flash tag.
 
 Regards,
 Tatha
 
 On 01/12/2012 04:51 PM, Hauke Mehrtens wrote:
 On 01/12/2012 04:13 AM, tathagata wrote:
 Hi Hauke,
   I will modify it and send updated patch.
 Which hardware are you using ?

 Regards,
 Tathagata
 Hi Tathagata,

 I am using a Netgear WNDR3400 with an BCM4716 with Serial flash. In the
 evening I will look where exactly it fails.

 Hauke

 On 12.01.2012 03:41, Hauke Mehrtens wrote:
 On 01/10/2012 01:00 PM, Tathagata Das wrote:
 Hi,
   Attached is the updated kernel patch to support brcm47xx BCMA NAND
 flash. This patch uses driver/mtd/nand/nand_base.c. I have used latest
 trunk source code to create this patch.

 Regards,
 Tathagatatathag...@alumnux.com
 Hi Tathagata,

 your patch causes my system to not boot any more. These are the last
 lines I see:
 [0.00] bcma: IRQ reconfiguration done
 [0.00] bcma: core 0x0800, irq : 2(S)* 3  4  5  6  D  I
 [0.00] bcma: core 0x082c, irq : 2(S)* 3  4  5  6  D  I
 [0.00] BUS Capability: 184801c9

 Some additional points I have:
 * The KConfig option MTD_NAND_BCM47XX should select BCMA_NFLASH.
 * brcm47xx does not build without MTD_NAND_BCM47XX set.
 * In some places your patch is wrongly formated, it should use tabs
 instead of spaces.

 Could you please post the patch inlined into the mail next time it
 makes
 reviewing a loot easier.

 Hauke


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-01-12 Thread Hauke Mehrtens
On 01/12/2012 04:13 AM, tathagata wrote:
 Hi Hauke,
  I will modify it and send updated patch.
 Which hardware are you using ?
 
 Regards,
 Tathagata

Hi Tathagata,

I am using a Netgear WNDR3400 with an BCM4716 with Serial flash. In the
evening I will look where exactly it fails.

Hauke

 
 On 12.01.2012 03:41, Hauke Mehrtens wrote:
 On 01/10/2012 01:00 PM, Tathagata Das wrote:
 Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND
 flash. This patch uses driver/mtd/nand/nand_base.c. I have used latest
 trunk source code to create this patch.

 Regards,
 Tathagata tathag...@alumnux.com

 Hi Tathagata,

 your patch causes my system to not boot any more. These are the last
 lines I see:
 [0.00] bcma: IRQ reconfiguration done
 [0.00] bcma: core 0x0800, irq : 2(S)* 3  4  5  6  D  I
 [0.00] bcma: core 0x082c, irq : 2(S)* 3  4  5  6  D  I
 [0.00] BUS Capability: 184801c9

 Some additional points I have:
 * The KConfig option MTD_NAND_BCM47XX should select BCMA_NFLASH.
 * brcm47xx does not build without MTD_NAND_BCM47XX set.
 * In some places your patch is wrongly formated, it should use tabs
 instead of spaces.

 Could you please post the patch inlined into the mail next time it makes
 reviewing a loot easier.

 Hauke
 

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-01-12 Thread Tathagata Das

Hi Hauke,
 I guess some NAND flash specific code are not under NAND flash tag.

Regards,
Tatha

On 01/12/2012 04:51 PM, Hauke Mehrtens wrote:

On 01/12/2012 04:13 AM, tathagata wrote:

Hi Hauke,
  I will modify it and send updated patch.
Which hardware are you using ?

Regards,
Tathagata

Hi Tathagata,

I am using a Netgear WNDR3400 with an BCM4716 with Serial flash. In the
evening I will look where exactly it fails.

Hauke


On 12.01.2012 03:41, Hauke Mehrtens wrote:

On 01/10/2012 01:00 PM, Tathagata Das wrote:

Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND
flash. This patch uses driver/mtd/nand/nand_base.c. I have used latest
trunk source code to create this patch.

Regards,
Tathagatatathag...@alumnux.com

Hi Tathagata,

your patch causes my system to not boot any more. These are the last
lines I see:
[0.00] bcma: IRQ reconfiguration done
[0.00] bcma: core 0x0800, irq : 2(S)* 3  4  5  6  D  I
[0.00] bcma: core 0x082c, irq : 2(S)* 3  4  5  6  D  I
[0.00] BUS Capability: 184801c9

Some additional points I have:
* The KConfig option MTD_NAND_BCM47XX should select BCMA_NFLASH.
* brcm47xx does not build without MTD_NAND_BCM47XX set.
* In some places your patch is wrongly formated, it should use tabs
instead of spaces.

Could you please post the patch inlined into the mail next time it makes
reviewing a loot easier.

Hauke



___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-01-12 Thread Florian Fainelli

Hello Tathagata,

On 01/10/12 13:00, Tathagata Das wrote:

Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND
flash. This patch uses driver/mtd/nand/nand_base.c. I have used latest
trunk source code to create this patch.


I have inlined some comments, how much throughput do you get out of the 
driver in read/write?




Regards,
Tathagata tathag...@alumnux.com

9991-bcm47xx-bcma-nandflash.patch


diff -Naur a/arch/mips/bcm47xx/bus.c b/arch/mips/bcm47xx/bus.c
--- a/arch/mips/bcm47xx/bus.c   2011-12-26 13:09:35.028170411 +0530
+++ b/arch/mips/bcm47xx/bus.c   2012-01-05 11:41:55.781832993 +0530
@@ -92,3 +92,46 @@
sflash-numblocks = scc-sflash.numblocks;
sflash-size = scc-sflash.size;
  }
+
+#ifdef CONFIG_BCMA_NFLASH
+static int bcm47xx_nflash_bcma_read(struct bcm47xx_nflash *dev, u32 offset, 
u32 len, u8 *buf)
+{
+   return bcma_nflash_read(dev-bcc, offset, len, buf);
+}
+
+static int bcm47xx_nflash_bcma_poll(struct bcm47xx_nflash *dev, u32 offset)
+{
+   return bcma_nflash_poll(dev-bcc);
+}
+
+static int bcm47xx_nflash_bcma_write(struct bcm47xx_nflash *dev, u32 offset, 
u32 len, const u8 *buf)
+{
+   return bcma_nflash_write(dev-bcc, offset, len, buf);
+}
+
+static int bcm47xx_nflash_bcma_erase(struct bcm47xx_nflash *dev, u32 offset)
+{
+   return bcma_nflash_erase(dev-bcc, offset);
+}
+
+void bcm47xx_nflash_struct_bcma_init(struct bcm47xx_nflash *nflash, struct 
bcma_drv_cc *bcc)
+{
+   int i;
+
+   nflash-nflash_type = BCM47XX_BUS_TYPE_BCMA;
+   nflash-bcc = bcc;
+
+   nflash-read = bcm47xx_nflash_bcma_read;
+   nflash-poll = bcm47xx_nflash_bcma_poll;
+   nflash-write = bcm47xx_nflash_bcma_write;
+   nflash-erase = bcm47xx_nflash_bcma_erase;
+
+   nflash-blocksize = bcc-nflash.blocksize;
+   nflash-numblocks = bcc-nflash.numblocks;
+   nflash-pagesize = bcc-nflash.pagesize;
+   nflash-size = bcc-nflash.size;
+
+   for (i=0; i5; i++)
+   nflash-id[i] = bcc-nflash.id[i];


Do you really need to read the flash id that early?


+}
+#endif /* CONFIG_BCMA_NFLASH */
diff -Naur a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
--- a/arch/mips/bcm47xx/nvram.c 2011-12-26 13:09:36.274170411 +0530
+++ b/arch/mips/bcm47xx/nvram.c 2012-01-10 14:48:15.981647409 +0530
@@ -21,6 +21,7 @@
  #includeasm/mach-bcm47xx/nvram.h
  #includeasm/mach-bcm47xx/bcm47xx.h
  #includeasm/mach-bcm47xx/bus.h
+#includelinux/mtd/bcm47xx_nand.h

  char nvram_buf[NVRAM_SPACE];
  EXPORT_SYMBOL(nvram_buf);
@@ -159,6 +160,55 @@
return 0;
  }

+static int early_nvram_init_nflash(void)
+{
+   struct nvram_header *header;
+   u32 off;
+   int ret;
+   int len;
+   u32 flash_size = bcm47xx_nflash.size * 1024 * 1024;
+   u8 *tmpbuf = NULL;
+   int i;
+   u32 *src, *dst;
+
+   /* check if the struct is already initilized */
+   if (!flash_size)
+   return -1;
+   
+   cfe_env = 0;
+
+   tmpbuf = (u8 *)kmalloc(NFL_SECTOR_SIZE, GFP_KERNEL);


Is not that a little early for using kmalloc? NFL_SECTOR_SIZE is only 
512 bytes, so either using a buffer marked with __initdata or allocating 
it on the stack should be okay.



+   off = FLASH_MIN;
+   while (off= flash_size) {
+   ret = bcm47xx_nflash.read(bcm47xx_nflash, off, 
NFL_SECTOR_SIZE, tmpbuf);
+   if (ret != NFL_SECTOR_SIZE) {
+   goto done;
+   }
+   header = (struct nvram_header *)tmpbuf;
+   if (header-magic == NVRAM_HEADER) {
+   goto found;
+   }
+   off= 1;
+   }
+
+   ret = -1;
+   goto done;
+
+found:
+   len = header-len;
+   header = (struct nvram_header *) KSEG1ADDR(NAND_FLASH1 + off);
+   src = (u32 *) header;
+   dst = (u32 *) nvram_buf;
+   for (i = 0; i  sizeof(struct nvram_header); i += 4)
+  *dst++ = *src++;
+   for (; i  len  i  NVRAM_SPACE; i += 4)
+  *dst++ = *src++;
+   ret = 0;
+done:
+   kfree(tmpbuf);
+   return ret;
+}


The identation of these lines is not coherent with the rest.


+
  static void early_nvram_init(void)
  {
int err = 0;
@@ -185,6 +235,10 @@
err = early_nvram_init_sflash();
if (err  0)
printk(KERN_WARNING can not read from flash: 
%i\n, err);
+   } else if (bcm47xx_bus.bcma.bus.drv_cc.flash_type == 
BCMA_NFLASH) {
+   err = early_nvram_init_nflash();
+   if (err  0)
+   printk(KERN_WARNING can not read from nflash: 
%i\n, err);
} else {
printk(KERN_WARNING unknow flash type\n);


Consider using a switch() case() statement here, two cases to handle is 
enough to start using it.



}
diff -Naur a/arch/mips/bcm47xx/setup.c b/arch/mips/bcm47xx/setup.c
--- a/arch/mips/bcm47xx/setup.c 

Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-01-12 Thread Tathagata Das

Hi Florian,
 Thanks a lot for your comment. I will update the patch accordingly.

Regards,
Tathagata

On 01/12/2012 06:40 PM, Florian Fainelli wrote:

Hello Tathagata,

On 01/10/12 13:00, Tathagata Das wrote:

Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND
flash. This patch uses driver/mtd/nand/nand_base.c. I have used latest
trunk source code to create this patch.


I have inlined some comments, how much throughput do you get out of 
the driver in read/write?




Regards,
Tathagata tathag...@alumnux.com

9991-bcm47xx-bcma-nandflash.patch


diff -Naur a/arch/mips/bcm47xx/bus.c b/arch/mips/bcm47xx/bus.c
--- a/arch/mips/bcm47xx/bus.c2011-12-26 13:09:35.028170411 +0530
+++ b/arch/mips/bcm47xx/bus.c2012-01-05 11:41:55.781832993 +0530
@@ -92,3 +92,46 @@
  sflash-numblocks = scc-sflash.numblocks;
  sflash-size = scc-sflash.size;
  }
+
+#ifdef CONFIG_BCMA_NFLASH
+static int bcm47xx_nflash_bcma_read(struct bcm47xx_nflash *dev, u32 
offset, u32 len, u8 *buf)

+{
+return bcma_nflash_read(dev-bcc, offset, len, buf);
+}
+
+static int bcm47xx_nflash_bcma_poll(struct bcm47xx_nflash *dev, u32 
offset)

+{
+return bcma_nflash_poll(dev-bcc);
+}
+
+static int bcm47xx_nflash_bcma_write(struct bcm47xx_nflash *dev, u32 
offset, u32 len, const u8 *buf)

+{
+return bcma_nflash_write(dev-bcc, offset, len, buf);
+}
+
+static int bcm47xx_nflash_bcma_erase(struct bcm47xx_nflash *dev, u32 
offset)

+{
+return bcma_nflash_erase(dev-bcc, offset);
+}
+
+void bcm47xx_nflash_struct_bcma_init(struct bcm47xx_nflash *nflash, 
struct bcma_drv_cc *bcc)

+{
+int i;
+
+nflash-nflash_type = BCM47XX_BUS_TYPE_BCMA;
+nflash-bcc = bcc;
+
+nflash-read = bcm47xx_nflash_bcma_read;
+nflash-poll = bcm47xx_nflash_bcma_poll;
+nflash-write = bcm47xx_nflash_bcma_write;
+nflash-erase = bcm47xx_nflash_bcma_erase;
+
+nflash-blocksize = bcc-nflash.blocksize;
+nflash-numblocks = bcc-nflash.numblocks;
+nflash-pagesize = bcc-nflash.pagesize;
+nflash-size = bcc-nflash.size;
+
+for (i=0; i5; i++)
+nflash-id[i] = bcc-nflash.id[i];


Do you really need to read the flash id that early?


+}
+#endif /* CONFIG_BCMA_NFLASH */
diff -Naur a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
--- a/arch/mips/bcm47xx/nvram.c2011-12-26 13:09:36.274170411 +0530
+++ b/arch/mips/bcm47xx/nvram.c2012-01-10 14:48:15.981647409 +0530
@@ -21,6 +21,7 @@
  #includeasm/mach-bcm47xx/nvram.h
  #includeasm/mach-bcm47xx/bcm47xx.h
  #includeasm/mach-bcm47xx/bus.h
+#includelinux/mtd/bcm47xx_nand.h

  char nvram_buf[NVRAM_SPACE];
  EXPORT_SYMBOL(nvram_buf);
@@ -159,6 +160,55 @@
  return 0;
  }

+static int early_nvram_init_nflash(void)
+{
+struct nvram_header *header;
+u32 off;
+int ret;
+int len;
+u32 flash_size = bcm47xx_nflash.size * 1024 * 1024;
+u8 *tmpbuf = NULL;
+int i;
+   u32 *src, *dst;
+
+/* check if the struct is already initilized */
+if (!flash_size)
+return -1;
+
+cfe_env = 0;
+
+tmpbuf = (u8 *)kmalloc(NFL_SECTOR_SIZE, GFP_KERNEL);


Is not that a little early for using kmalloc? NFL_SECTOR_SIZE is only 
512 bytes, so either using a buffer marked with __initdata or 
allocating it on the stack should be okay.



+off = FLASH_MIN;
+while (off= flash_size) {
+ret = bcm47xx_nflash.read(bcm47xx_nflash, off, 
NFL_SECTOR_SIZE, tmpbuf);

+if (ret != NFL_SECTOR_SIZE) {
+goto done;
+}
+header = (struct nvram_header *)tmpbuf;
+if (header-magic == NVRAM_HEADER) {
+goto found;
+}
+off= 1;
+}
+
+ret = -1;
+goto done;
+
+found:
+len = header-len;
+header = (struct nvram_header *) KSEG1ADDR(NAND_FLASH1 + off);
+   src = (u32 *) header;
+   dst = (u32 *) nvram_buf;
+   for (i = 0; i  sizeof(struct nvram_header); i += 4)
+  *dst++ = *src++;
+   for (; i  len  i  NVRAM_SPACE; i += 4)
+  *dst++ = *src++;
+ret = 0;
+done:
+kfree(tmpbuf);
+return ret;
+}


The identation of these lines is not coherent with the rest.


+
  static void early_nvram_init(void)
  {
  int err = 0;
@@ -185,6 +235,10 @@
  err = early_nvram_init_sflash();
  if (err  0)
  printk(KERN_WARNING can not read from flash: 
%i\n, err);
+} else if (bcm47xx_bus.bcma.bus.drv_cc.flash_type == 
BCMA_NFLASH) {

+err = early_nvram_init_nflash();
+if (err  0)
+printk(KERN_WARNING can not read from nflash: 
%i\n, err);

  } else {
  printk(KERN_WARNING unknow flash type\n);


Consider using a switch() case() statement here, two cases to handle 
is enough to start using it.



  }
diff -Naur a/arch/mips/bcm47xx/setup.c b/arch/mips/bcm47xx/setup.c
--- a/arch/mips/bcm47xx/setup.c2011-12-26 13:09:36.247170411 +0530
+++ b/arch/mips/bcm47xx/setup.c2012-01-05 11:41:55.880832992 +0530
@@ -4,6 +4,7 @@
   *  Copyright (C) 2006 

Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-01-11 Thread Hauke Mehrtens
On 01/10/2012 01:00 PM, Tathagata Das wrote:
 Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND
 flash. This patch uses driver/mtd/nand/nand_base.c. I have used latest
 trunk source code to create this patch.
 
 Regards,
 Tathagata tathag...@alumnux.com

Hi Tathagata,

your patch causes my system to not boot any more. These are the last
lines I see:
[0.00] bcma: IRQ reconfiguration done
[0.00] bcma: core 0x0800, irq : 2(S)* 3  4  5  6  D  I
[0.00] bcma: core 0x082c, irq : 2(S)* 3  4  5  6  D  I
[0.00] BUS Capability: 184801c9

Some additional points I have:
* The KConfig option MTD_NAND_BCM47XX should select BCMA_NFLASH.
* brcm47xx does not build without MTD_NAND_BCM47XX set.
* In some places your patch is wrongly formated, it should use tabs
instead of spaces.

Could you please post the patch inlined into the mail next time it makes
reviewing a loot easier.

Hauke
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2012-01-11 Thread tathagata

Hi Hauke,
 I will modify it and send updated patch.
Which hardware are you using ?

Regards,
Tathagata

On 12.01.2012 03:41, Hauke Mehrtens wrote:

On 01/10/2012 01:00 PM, Tathagata Das wrote:

Hi,
 Attached is the updated kernel patch to support brcm47xx BCMA NAND
flash. This patch uses driver/mtd/nand/nand_base.c. I have used 
latest

trunk source code to create this patch.

Regards,
Tathagata tathag...@alumnux.com


Hi Tathagata,

your patch causes my system to not boot any more. These are the last
lines I see:
[0.00] bcma: IRQ reconfiguration done
[0.00] bcma: core 0x0800, irq : 2(S)* 3  4  5  6  D  I
[0.00] bcma: core 0x082c, irq : 2(S)* 3  4  5  6  D  I
[0.00] BUS Capability: 184801c9

Some additional points I have:
* The KConfig option MTD_NAND_BCM47XX should select BCMA_NFLASH.
* brcm47xx does not build without MTD_NAND_BCM47XX set.
* In some places your patch is wrongly formated, it should use tabs
instead of spaces.

Could you please post the patch inlined into the mail next time it 
makes

reviewing a loot easier.

Hauke


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2011-12-22 Thread Tathagata Das

Hi,
 Thanks for your feedback.
I will modify the patch. Also I am trying to use 
driver/mtd/nand/nand_base.c as much as possible. I will submit modify 
patch quickly.


Regards,
Tathagata

On 12/23/2011 03:28 AM, Hauke Mehrtens wrote:

On 12/14/2011 05:51 AM, Tathagata Das wrote:

Hi,
  Attached is the updated kernel patch to support brcm47xx BCMA NAND
flash. I have removed SSB related code from this patch and I have used
latest trunk source code to create this patch.

Regards,
Tathagatatathag...@alumnux.com

Hi Tathagata,

--- a/drivers/bcma/driver_mips.c2011-12-12 10:48:59.651424561 +0530
+++ b/drivers/bcma/driver_mips.c2011-12-12 12:41:58.806423452 +0530
@@ -186,9 +186,15 @@
case BCMA_CC_FLASHT_STSER:
case BCMA_CC_FLASHT_ATSER:
  #ifdef CONFIG_BCMA_SFLASH
+#ifdef CONFIG_BCMA_NFLASH
+   printk(found nand flash.\n);
+   bus-drv_cc.flash_type = BCMA_NFLASH;
+   bcma_nflash_init(bus-drv_cc);
+#else
pr_info(found serial flash.\n);
bus-drv_cc.flash_type = BCMA_SFLASH;
bcma_sflash_init(bus-drv_cc);
+#endif

This is not nice, with this we could only build images supporting sflash
or nflash.
This could finds your nflash chip? It is strage because this should just
find sflash chips.

Could you instaed try this and report what condition found your nflash chip:

--- a/drivers/bcma/driver_mips.c
+++ b/drivers/bcma/driver_mips.c
@@ -182,6 +182,15 @@ static void bcma_core_mips_flash_detect(struct
bcma_drv_mips *mcore)
  {
struct bcma_bus *bus = mcore-core-bus;

+#ifdef CONFIG_BCMA_NFLASH
+   if (bus-drv_cc.capabilities  BCMA_CC_CAP_NFLASH) {
+   printk(found nand flash.\n);
+   bus-drv_cc.flash_type = BCMA_NFLASH;
+   bcma_nflash_init(bus-drv_cc);
+   return;
+   }
+#endif /* CONFIG_BCMA_NFLASH */
+
switch (bus-drv_cc.capabilities  BCMA_CC_CAP_FLASHT) {
case BCMA_CC_FLASHT_STSER:
case BCMA_CC_FLASHT_ATSER:
@@ -193,6 +202,15 @@ static void bcma_core_mips_flash_detect(struct
bcma_drv_mips *mcore)
pr_info(serial flash not supported.\n);
  #endif /* CONFIG_BCMA_SFLASH */
break;
+   case BCMA_CC_FLASHT_NFLASH:
+#ifdef CONFIG_BCMA_NFLASH
+   printk(found nand flash.\n);
+   bus-drv_cc.flash_type = BCMA_NFLASH;
+   bcma_nflash_init(bus-drv_cc);
+#else
+   pr_info(nand flash not supported.\n);
+#endif /* CONFIG_BCMA_NFLASH */
+   break;
case BCMA_CC_FLASHT_PARA:
pr_info(found parallel flash.\n);
bus-drv_cc.flash_type = BCMA_PFLASH;
--- a/include/linux/bcma/bcma_driver_chipcommon.h
+++ b/include/linux/bcma/bcma_driver_chipcommon.h
@@ -24,7 +24,7 @@
  #define   BCMA_CC_FLASHT_NONE 0x  /* No flash */
  #define   BCMA_CC_FLASHT_STSER0x0100  /* ST serial 
flash */
  #define   BCMA_CC_FLASHT_ATSER0x0200  /* Atmel serial 
flash */
-#define   BCMA_CC_FLASHT_NFLASH0x0200
+#define   BCMA_CC_FLASHT_NFLASH0x0300  /* NAND flash */
  #define BCMA_CC_FLASHT_PARA   0x0700  /* Parallel 
flash */
  #define  BCMA_CC_CAP_PLLT 0x00038000  /* PLL Type */
  #define   BCMA_PLLTYPE_NONE   0x
@@ -44,7 +44,8 @@
  #define  BCMA_CC_CAP_64BIT0x0800  /* 64-bit Backplane */
  #define  BCMA_CC_CAP_PMU  0x1000  /* PMU available (rev= 
20) */
  #define  BCMA_CC_CAP_ECI  0x2000  /* ECI available (rev= 
20) */
-#define  BCMA_CC_CAP_SPROM 0x4000  /* SPROM present */
+#define  BCMA_CC_CAP_SROM  0x4000  /* Srom Present (rev= 
32) */
+#define  BCMA_CC_CAP_NFLASH0x8000  /* Nand flash present 
(rev=
35) */
  #define BCMA_CC_CORECTL   0x0008
  #define  BCMA_CC_CORECTL_UARTCLK0 0x0001  /* Drive UART with
internal clock */
  #defineBCMA_CC_CORECTL_SE 0x0002  /* sync clk out 
enable (corerev

= 3) */



The bus abstraction in arch/mips/bcm47xx/bus.c is not needed. I made it
for sflash devices to use one code for bcma and ssb based devices but
sflash is just available on very recent bcma devices.

Hauke


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] Updated kernel patch in trunk to support brcm47xx BCMA NAND flash

2011-12-13 Thread Tathagata Das

Hi,
 Attached is the updated kernel patch to support brcm47xx BCMA NAND 
flash. I have removed SSB related code from this patch and I have used 
latest trunk source code to create this patch.


Regards,
Tathagatatathag...@alumnux.com
diff -Naur a/arch/mips/bcm47xx/bus.c b/arch/mips/bcm47xx/bus.c
--- a/arch/mips/bcm47xx/bus.c   2011-12-12 10:48:59.748424561 +0530
+++ b/arch/mips/bcm47xx/bus.c   2011-12-12 12:41:47.23453 +0530
@@ -92,3 +92,40 @@
sflash-numblocks = scc-sflash.numblocks;
sflash-size = scc-sflash.size;
 }
+
+#ifdef CONFIG_BCMA_NFLASH
+static int bcm47xx_nflash_bcma_read(struct bcm47xx_nflash *dev, u32 offset, 
u32 len, u8 *buf)
+{
+   return bcma_nflash_read(dev-bcc, offset, len, buf);
+}
+
+static int bcm47xx_nflash_bcma_poll(struct bcm47xx_nflash *dev, u32 offset)
+{
+   return bcma_nflash_poll(dev-bcc);
+}
+
+static int bcm47xx_nflash_bcma_write(struct bcm47xx_nflash *dev, u32 offset, 
u32 len, const u8 *buf)
+{
+   return bcma_nflash_write(dev-bcc, offset, len, buf);
+}
+
+static int bcm47xx_nflash_bcma_erase(struct bcm47xx_nflash *dev, u32 offset)
+{
+   return bcma_nflash_erase(dev-bcc, offset);
+}
+
+void bcm47xx_nflash_struct_bcma_init(struct bcm47xx_nflash *nflash, struct 
bcma_drv_cc *bcc)
+{
+   nflash-nflash_type = BCM47XX_BUS_TYPE_BCMA;
+   nflash-bcc = bcc;
+
+   nflash-read = bcm47xx_nflash_bcma_read;
+   nflash-poll = bcm47xx_nflash_bcma_poll;
+   nflash-write = bcm47xx_nflash_bcma_write;
+   nflash-erase = bcm47xx_nflash_bcma_erase;
+
+   nflash-blocksize = bcc-nflash.blocksize;
+   nflash-numblocks = bcc-nflash.numblocks;
+   nflash-size = bcc-nflash.size;
+}
+#endif /* CONFIG_BCMA_NFLASH */
diff -Naur a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
--- a/arch/mips/bcm47xx/nvram.c 2011-12-12 10:49:00.974424559 +0530
+++ b/arch/mips/bcm47xx/nvram.c 2011-12-12 12:41:47.23453 +0530
@@ -21,6 +21,7 @@
 #include asm/mach-bcm47xx/nvram.h
 #include asm/mach-bcm47xx/bcm47xx.h
 #include asm/mach-bcm47xx/bus.h
+#include linux/mtd/nflash.h
 
 char nvram_buf[NVRAM_SPACE];
 EXPORT_SYMBOL(nvram_buf);
@@ -159,6 +160,64 @@
return 0;
 }
 
+static int early_nvram_init_nflash(void)
+{
+   struct nvram_header *header;
+   u32 off;
+   int ret;
+   char *dst;
+   int len;
+   u32 flash_size = bcm47xx_nflash.size * 1024 * 1024;
+   u8 *tmpbuf = NULL;
+
+   /* check if the struct is already initilized */
+   if (!flash_size)
+   return -1;
+
+   tmpbuf = (u8 *)kmalloc(NFL_SECTOR_SIZE, GFP_KERNEL);
+   off = FLASH_MIN;
+   while (off = flash_size) {
+   ret = bcm47xx_nflash.read(bcm47xx_nflash, off - NVRAM_SPACE, 
NFL_SECTOR_SIZE, tmpbuf);
+   if (ret != NFL_SECTOR_SIZE) {
+   goto done;
+   }
+   header = (struct nvram_header *)tmpbuf;
+   if (header-magic == NVRAM_HEADER)
+   goto found;
+   off = 1;
+   }
+
+   off = FLASH_MIN;
+   while (off = flash_size) {
+   ret = bcm47xx_nflash.read(bcm47xx_nflash, off - (2 * 
NVRAM_SPACE), NFL_SECTOR_SIZE, tmpbuf);
+   if (ret != NFL_SECTOR_SIZE)
+   goto done;
+   header = (struct nvram_header *)tmpbuf;
+   if (header-magic == NVRAM_HEADER)
+   goto found;
+   off = 1;
+   }
+   
+   ret = -1;
+   goto done;
+
+found:
+   len = NVRAM_SPACE;
+   dst = nvram_buf;
+   while (len) {
+   ret = bcm47xx_nflash.read(bcm47xx_nflash, off - (2 * 
NVRAM_SPACE), len, dst);
+   if (ret  0)
+   goto done;
+   off += ret;
+   len -= ret;
+   dst += ret;
+   }
+   ret = 0;
+done:
+   kfree(tmpbuf);
+   return ret;
+}
+
 static void early_nvram_init(void)
 {
int err = 0;
@@ -185,6 +244,10 @@
err = early_nvram_init_sflash();
if (err  0)
printk(KERN_WARNING can not read from flash: 
%i\n, err);
+   } else if (bcm47xx_bus.bcma.bus.drv_cc.flash_type == 
BCMA_NFLASH) {
+   err = early_nvram_init_nflash();
+   if (err  0)
+   printk(KERN_WARNING can not read from nflash: 
%i\n, err);
} else {
printk(KERN_WARNING unknow flash type\n);
}
diff -Naur a/arch/mips/bcm47xx/setup.c b/arch/mips/bcm47xx/setup.c
--- a/arch/mips/bcm47xx/setup.c 2011-12-12 10:49:00.947424559 +0530
+++ b/arch/mips/bcm47xx/setup.c 2011-12-12 12:41:47.443423454 +0530
@@ -4,6 +4,7 @@
  *  Copyright (C) 2006 Michael Buesch m...@bu3sch.de
  *  Copyright (C) 2010 Waldemar Brodkorb w...@openadk.org
  *  Copyright (C) 2010-2011 Hauke Mehrtens ha...@hauke-m.de
+ *  Copyright (C) 2010-2011 Tathagata Das