Signed-off-by: Jonas Gorski <jogo@openwrt.org>
---
- arch/mips/bcm63xx/dev-flash.c | 36 ++++++++++++++++++++++++++++++++++++
- 1 file changed, 36 insertions(+)
+ arch/mips/bcm63xx/dev-flash.c | 51 ++++++++++++++++++++++++++++++++++++
+ 1 file changed, 51 insertions(+)
--- a/arch/mips/bcm63xx/dev-flash.c
+++ b/arch/mips/bcm63xx/dev-flash.c
-@@ -110,9 +110,46 @@ static int __init bcm63xx_detect_flash_t
+@@ -16,6 +16,7 @@
+ #include <linux/mtd/mtd.h>
+ #include <linux/mtd/partitions.h>
+ #include <linux/mtd/physmap.h>
++#include <linux/mtd/spi-nor.h>
+
+ #include <bcm63xx_cpu.h>
+ #include <bcm63xx_dev_flash.h>
+@@ -110,9 +111,59 @@ static int __init bcm63xx_detect_flash_t
}
}
+#define FLASH_CTRL_ADDR_BYTES_2 (0 << 8)
+#define FLASH_CTRL_ADDR_BYTES_3 (1 << 8)
+#define FLASH_CTRL_ADDR_BYTES_4 (2 << 8)
++#define FLASH_CTRL_DUMMY_BYTES_SHIFT 10
++#define FLASH_CTRL_DUMMY_BYTES_MASK (0x3 << FLASH_CTRL_DUMMY_BYTES_SHIFT)
+#define FLASH_CTRL_MB_EN (1 << 23)
+
void __init bcm63xx_flash_detect(void)
{
flash_type = bcm63xx_detect_flash_type();
+
-+ /* reduce flash mapping to single i/o reads for safety */
++ /* ensure flash mapping has sane values */
+ if (flash_type == BCM63XX_FLASH_TYPE_SERIAL &&
+ (BCMCPU_IS_6318() || BCMCPU_IS_6328() || BCMCPU_IS_6362() ||
+ BCMCPU_IS_63268())) {
+ u32 val = bcm_rset_readl(RSET_HSSPI, HSSPI_FLASH_CTRL_REG);
+
-+ if (!(val & FLASH_CTRL_MB_EN))
-+ return;
++ if (val & FLASH_CTRL_MB_EN) {
++ /* cfe might configure non working dual-io mode */
++ val &= ~FLASH_CTRL_MB_EN;
++ val &= ~FLASH_CTRL_READ_OPCODE_MASK;
++ val &= ~FLASH_CTRL_DUMMY_BYTES_MASK;
++ val |= 1 << FLASH_CTRL_DUMMY_BYTES_SHIFT;
++
++ switch (val & FLASH_CTRL_ADDR_BYTES_MASK) {
++ case FLASH_CTRL_ADDR_BYTES_3:
++ val |= SPINOR_OP_READ_FAST;
++ break;
++ case FLASH_CTRL_ADDR_BYTES_4:
++ val |= SPINOR_OP_READ4_FAST;
++ break;
++ case FLASH_CTRL_ADDR_BYTES_2:
++ default:
++ pr_warn("unsupported address byte mode (%x), not fixing up\n",
++ val & FLASH_CTRL_ADDR_BYTES_MASK);
++ return;
++ }
++ } else {
++ /* ensure dummy bytes is set to 1 for _FAST reads */
++ u8 cmd = val & FLASH_CTRL_READ_OPCODE_MASK;
+
-+ val &= ~FLASH_CTRL_MB_EN;
-+ val &= ~FLASH_CTRL_READ_OPCODE_MASK;
++ if (cmd != SPINOR_OP_READ_FAST && cmd != SPINOR_OP_READ4_FAST)
++ return;
+
-+ switch (val & FLASH_CTRL_ADDR_BYTES_MASK) {
-+ case FLASH_CTRL_ADDR_BYTES_3:
-+ val |= 0x0b; /* OPCODE_FAST_READ */
-+ break;
-+ case FLASH_CTRL_ADDR_BYTES_4:
-+ val |= 0x0c; /* OPCODE_FAST_READ_4B */
-+ break;
-+ case FLASH_CTRL_ADDR_BYTES_2:
-+ default:
-+ pr_warn("unsupported address byte mode (%x), not fixing up\n",
-+ val & FLASH_CTRL_ADDR_BYTES_MASK);
-+ return;
++ val &= ~FLASH_CTRL_DUMMY_BYTES_MASK;
++ val |= 1 << FLASH_CTRL_DUMMY_BYTES_SHIFT;
+ }
+
+ bcm_rset_writel(RSET_HSSPI, val, HSSPI_FLASH_CTRL_REG);
--- a/arch/mips/bcm63xx/dev-flash.c
+++ b/arch/mips/bcm63xx/dev-flash.c
-@@ -57,6 +57,12 @@ static struct platform_device mtd_dev =
+@@ -58,6 +58,12 @@ static struct platform_device mtd_dev =
},
};
static int __init bcm63xx_detect_flash_type(void)
{
u32 val;
-@@ -158,12 +164,15 @@ int __init bcm63xx_flash_register(void)
+@@ -172,12 +178,15 @@ int __init bcm63xx_flash_register(void)
switch (flash_type) {
case BCM63XX_FLASH_TYPE_PARALLEL:
--- a/arch/mips/bcm63xx/dev-flash.c
+++ b/arch/mips/bcm63xx/dev-flash.c
-@@ -22,6 +22,8 @@
+@@ -23,6 +23,8 @@
#include <bcm63xx_regs.h>
#include <bcm63xx_io.h>
static int flash_type;
static struct mtd_partition mtd_partitions[] = {
-@@ -164,6 +166,9 @@ int __init bcm63xx_flash_register(void)
+@@ -178,6 +180,9 @@ int __init bcm63xx_flash_register(void)
switch (flash_type) {
case BCM63XX_FLASH_TYPE_PARALLEL:
--- a/arch/mips/bcm63xx/dev-flash.c
+++ b/arch/mips/bcm63xx/dev-flash.c
-@@ -34,7 +34,7 @@ static struct mtd_partition mtd_partitio
+@@ -35,7 +35,7 @@ static struct mtd_partition mtd_partitio
}
};
--- a/arch/mips/bcm63xx/dev-flash.c
+++ b/arch/mips/bcm63xx/dev-flash.c
-@@ -16,9 +16,12 @@
- #include <linux/mtd/mtd.h>
+@@ -17,9 +17,12 @@
#include <linux/mtd/partitions.h>
#include <linux/mtd/physmap.h>
+ #include <linux/mtd/spi-nor.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/flash.h>
#include <bcm63xx_regs.h>
#include <bcm63xx_io.h>
-@@ -65,6 +68,21 @@ void __init bcm63xx_flash_force_phys_bas
+@@ -66,6 +69,21 @@ void __init bcm63xx_flash_force_phys_bas
mtd_resources[0].end = end;
}
static int __init bcm63xx_detect_flash_type(void)
{
u32 val;
-@@ -72,9 +90,15 @@ static int __init bcm63xx_detect_flash_t
+@@ -73,9 +91,15 @@ static int __init bcm63xx_detect_flash_t
switch (bcm63xx_get_cpu_id()) {
case BCM6318_CPU_ID:
/* only support serial flash */
if (val & STRAPBUS_6328_BOOT_SEL_SERIAL)
return BCM63XX_FLASH_TYPE_SERIAL;
else
-@@ -93,12 +117,20 @@ static int __init bcm63xx_detect_flash_t
+@@ -94,12 +118,20 @@ static int __init bcm63xx_detect_flash_t
return BCM63XX_FLASH_TYPE_SERIAL;
case BCM6362_CPU_ID:
val = bcm_misc_readl(MISC_STRAPBUS_6362_REG);
switch (val & STRAPBUS_6368_BOOT_SEL_MASK) {
case STRAPBUS_6368_BOOT_SEL_NAND:
return BCM63XX_FLASH_TYPE_NAND;
-@@ -109,6 +141,11 @@ static int __init bcm63xx_detect_flash_t
+@@ -110,6 +142,11 @@ static int __init bcm63xx_detect_flash_t
}
case BCM63268_CPU_ID:
val = bcm_misc_readl(MISC_STRAPBUS_63268_REG);
if (val & STRAPBUS_63268_BOOT_SEL_SERIAL)
return BCM63XX_FLASH_TYPE_SERIAL;
else
-@@ -181,8 +218,15 @@ int __init bcm63xx_flash_register(void)
+@@ -195,8 +232,15 @@ int __init bcm63xx_flash_register(void)
return platform_device_register(&mtd_dev);
case BCM63XX_FLASH_TYPE_SERIAL:
--- a/arch/mips/bcm63xx/dev-flash.c
+++ b/arch/mips/bcm63xx/dev-flash.c
-@@ -236,3 +236,8 @@ int __init bcm63xx_flash_register(void)
+@@ -250,3 +250,8 @@ int __init bcm63xx_flash_register(void)
return -ENODEV;
}
}
while (led_count < ARRAY_SIZE(board.leds) && board.leds[led_count].name)
--- a/arch/mips/bcm63xx/dev-flash.c
+++ b/arch/mips/bcm63xx/dev-flash.c
-@@ -37,12 +37,15 @@ static struct mtd_partition mtd_partitio
+@@ -38,12 +38,15 @@ static struct mtd_partition mtd_partitio
}
};
};
static struct resource mtd_resources[] = {
-@@ -70,6 +73,7 @@ void __init bcm63xx_flash_force_phys_bas
+@@ -71,6 +74,7 @@ void __init bcm63xx_flash_force_phys_bas
static struct flash_platform_data bcm63xx_flash_data = {
.part_probe_types = bcm63xx_part_types,
};
static struct spi_board_info bcm63xx_spi_flash_info[] = {
-@@ -197,9 +201,13 @@ void __init bcm63xx_flash_detect(void)
+@@ -211,9 +215,13 @@ void __init bcm63xx_flash_detect(void)
}
}
}
--- a/arch/mips/bcm63xx/dev-flash.c
+++ b/arch/mips/bcm63xx/dev-flash.c
-@@ -201,7 +201,7 @@ void __init bcm63xx_flash_detect(void)
+@@ -215,7 +215,7 @@ void __init bcm63xx_flash_detect(void)
}
}
cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
--- a/arch/mips/bcm63xx/dev-flash.c
+++ b/arch/mips/bcm63xx/dev-flash.c
-@@ -19,6 +19,7 @@
+@@ -20,6 +20,7 @@
#include <linux/spi/spi.h>
#include <linux/spi/flash.h>
#include <bcm63xx_cpu.h>
#include <bcm63xx_dev_flash.h>
#include <bcm63xx_dev_hsspi.h>
-@@ -220,6 +221,13 @@ int __init bcm63xx_flash_register(int nu
+@@ -234,6 +235,13 @@ int __init bcm63xx_flash_register(int nu
val = bcm_mpi_readl(MPI_CSBASE_REG(0));
val &= MPI_CSBASE_BASE_MASK;