From 691e187381f209355399f27dd58d81732a687435 Mon Sep 17 00:00:00 2001
From: Florian Fainelli <florian@openwrt.org>
Date: Mon, 20 Oct 2008 12:55:28 +0000
Subject: [PATCH] Add definitions for bcm96350vw, add back bcm63xx mtd driver,
 be careful when testing with 8MB devices

SVN-Revision: 13015
---
 target/linux/brcm63xx/config-2.6.27           |  1 +
 .../files/drivers/mtd/maps/bcm963xx-flash.c   |  4 +-
 target/linux/brcm63xx/image/Makefile          |  2 +
 .../patches-2.6.27/013-bcm96358vw.patch       | 42 +++++++++++
 .../040-bcm963xx_flashmap.patch               | 73 +++++++++++++++++++
 5 files changed, 120 insertions(+), 2 deletions(-)
 create mode 100644 target/linux/brcm63xx/patches-2.6.27/013-bcm96358vw.patch
 create mode 100644 target/linux/brcm63xx/patches-2.6.27/040-bcm963xx_flashmap.patch

diff --git a/target/linux/brcm63xx/config-2.6.27 b/target/linux/brcm63xx/config-2.6.27
index d633ec03cf..adadfa4a07 100644
--- a/target/linux/brcm63xx/config-2.6.27
+++ b/target/linux/brcm63xx/config-2.6.27
@@ -167,6 +167,7 @@ CONFIG_MODULE_FORCE_UNLOAD=y
 CONFIG_MODVERSIONS=y
 CONFIG_MTD=y
 # CONFIG_MTD_ABSENT is not set
+CONFIG_MTD_BCM963XX=y
 CONFIG_MTD_BLKDEVS=y
 CONFIG_MTD_BLOCK=y
 # CONFIG_MTD_BLOCK2MTD is not set
diff --git a/target/linux/brcm63xx/files/drivers/mtd/maps/bcm963xx-flash.c b/target/linux/brcm63xx/files/drivers/mtd/maps/bcm963xx-flash.c
index c4c4526b49..7d01a9e8f0 100644
--- a/target/linux/brcm63xx/files/drivers/mtd/maps/bcm963xx-flash.c
+++ b/target/linux/brcm63xx/files/drivers/mtd/maps/bcm963xx-flash.c
@@ -30,14 +30,14 @@
  *
  */
 
-#include <asm/io.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/mtd/map.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/vmalloc.h>
-#include <board.h>
+
+#include <asm/io.h>
 
 #define WINDOW_ADDR 0x1FC00000         /* Real address of the flash */
 #define WINDOW_SIZE 0x400000           /* Size of flash */
diff --git a/target/linux/brcm63xx/image/Makefile b/target/linux/brcm63xx/image/Makefile
index 47c1df730d..e64d2c8c3f 100644
--- a/target/linux/brcm63xx/image/Makefile
+++ b/target/linux/brcm63xx/image/Makefile
@@ -73,6 +73,8 @@ endef
 define Image/Build
 	$(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/openwrt-$(BOARD)-$(1).trx -f $(KDIR)/loader.gz -f $(KDIR)/vmlinux.lzma $(call trxalign/$(1)) -f $(KDIR)/root.$(1)
 	$(call Image/Build/CFE,$(1),96345GW2,6345)
+	# Neufbox4
+	$(call Image/Build/CFE,$(1),96358VW,6358)
 endef
 
 $(eval $(call BuildImage))
diff --git a/target/linux/brcm63xx/patches-2.6.27/013-bcm96358vw.patch b/target/linux/brcm63xx/patches-2.6.27/013-bcm96358vw.patch
new file mode 100644
index 0000000000..f7f16a6012
--- /dev/null
+++ b/target/linux/brcm63xx/patches-2.6.27/013-bcm96358vw.patch
@@ -0,0 +1,42 @@
+diff -urN linux-2.6.27/arch/mips/bcm63xx/boards/board_bcm963xx.c linux-2.6.27.new/arch/mips/bcm63xx/boards/board_bcm963xx.c
+--- linux-2.6.27/arch/mips/bcm63xx/boards/board_bcm963xx.c	2008-10-20 14:24:02.000000000 +0200
++++ linux-2.6.27.new/arch/mips/bcm63xx/boards/board_bcm963xx.c	2008-10-20 14:28:15.000000000 +0200
+@@ -68,6 +68,30 @@
+  * known 6358 boards
+  */
+ #ifdef CONFIG_BCM63XX_CPU_6358
++static struct board_info __initdata board_96358vw = {
++	.name				= "96358VW",
++	.expected_cpu_id		= 0x6358,
++
++	.has_enet0			= 1,
++	.has_enet1			= 1,
++	.has_pci			= 1,
++
++	.enet0 = {
++		.has_phy		= 1,
++		.use_internal_phy	= 1,
++	},
++
++	.enet1 = {
++		.force_speed_100	= 1,
++		.force_duplex_full	= 1,
++	},
++
++
++	.has_ohci0 = 1,
++	.has_pccard = 1,
++	.has_ehci0 = 1,
++};
++
+ static struct board_info __initdata board_96358vw2 = {
+ 	.name				= "96358VW2",
+ 	.expected_cpu_id		= 0x6358,
+@@ -103,6 +127,7 @@
+ #endif
+ 
+ #ifdef CONFIG_BCM63XX_CPU_6358
++	&board_96358vw,
+ 	&board_96358vw2,
+ #endif
+ };
diff --git a/target/linux/brcm63xx/patches-2.6.27/040-bcm963xx_flashmap.patch b/target/linux/brcm63xx/patches-2.6.27/040-bcm963xx_flashmap.patch
new file mode 100644
index 0000000000..c7c1afdc92
--- /dev/null
+++ b/target/linux/brcm63xx/patches-2.6.27/040-bcm963xx_flashmap.patch
@@ -0,0 +1,73 @@
+From e734ace5baa04e0e8af1d4483475fbd6bd2b32a1 Mon Sep 17 00:00:00 2001
+From: Axel Gembe <ago@bastart.eu.org>
+Date: Mon, 12 May 2008 18:54:09 +0200
+Subject: [PATCH] bcm963xx: flashmap support
+
+
+Signed-off-by: Axel Gembe <ago@bastart.eu.org>
+---
+ drivers/mtd/maps/Kconfig  |    7 +++++++
+ drivers/mtd/maps/Makefile |    1 +
+ drivers/mtd/redboot.c     |   13 ++++++++++---
+ 3 files changed, 18 insertions(+), 3 deletions(-)
+
+--- a/drivers/mtd/maps/Kconfig
++++ b/drivers/mtd/maps/Kconfig
+@@ -262,6 +262,13 @@
+ 	  Flash memory access on 4G Systems MTX-1 Board. If you have one of
+ 	  these boards and would like to use the flash chips on it, say 'Y'.
+ 
++config MTD_BCM963XX
++        tristate "BCM963xx Flash device"
++        depends on MIPS && BCM63XX
++        help
++	  Flash memory access on BCM963xx boards. Currently only works with
++	  RedBoot and CFE.
++
+ config MTD_DILNETPC
+ 	tristate "CFI Flash device mapped on DIL/Net PC"
+ 	depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT
+--- a/drivers/mtd/redboot.c
++++ b/drivers/mtd/redboot.c
+@@ -39,7 +39,7 @@
+ 	return 1;
+ }
+ 
+-static int parse_redboot_partitions(struct mtd_info *master,
++int parse_redboot_partitions(struct mtd_info *master,
+                              struct mtd_partition **pparts,
+                              unsigned long fis_origin)
+ {
+@@ -161,6 +161,14 @@
+ 		goto out;
+ 	}
+ 
++	if (!fis_origin) {
++		for (i = 0; i < numslots; i++) {
++			if (!strncmp(buf[i].name, "RedBoot", 8)) {
++				fis_origin = (buf[i].flash_base & (master->size << 1) - 1);
++			}
++		}
++	}
++
+ 	for (i = 0; i < numslots; i++) {
+ 		struct fis_list *new_fl, **prev;
+ 
+@@ -183,9 +191,8 @@
+ 		new_fl->img = &buf[i];
+                 if (fis_origin) {
+                         buf[i].flash_base -= fis_origin;
+-                } else {
+-                        buf[i].flash_base &= master->size-1;
+                 }
++		buf[i].flash_base &= (master->size << 1) - 1;
+ 
+ 		/* I'm sure the JFFS2 code has done me permanent damage.
+ 		 * I now think the following is _normal_
+--- linux-2.6.27/drivers/mtd/maps/Makefile	2008-10-10 00:13:53.000000000 +0200
++++ linux-2.6.27.new/drivers/mtd/maps/Makefile	2008-10-20 14:22:52.000000000 +0200
+@@ -65,3 +65,4 @@
+ obj-$(CONFIG_MTD_OMAP_NOR)	+= omap_nor.o
+ obj-$(CONFIG_MTD_INTEL_VR_NOR)	+= intel_vr_nor.o
+ obj-$(CONFIG_MTD_BFIN_ASYNC)	+= bfin-async-flash.o
++obj-$(CONFIG_MTD_BCM963XX)	+= bcm963xx-flash.o
-- 
2.30.2