CC: brcm63xx: ensure dummy byte is set for mapped spi flash with fast read
authorJonas Gorski <jogo@openwrt.org>
Sun, 23 Aug 2015 09:41:07 +0000 (09:41 +0000)
committerJonas Gorski <jogo@openwrt.org>
Sun, 23 Aug 2015 09:41:07 +0000 (09:41 +0000)
Some CFEs seem to misconfigure the mapped memory flash access with
fast read but without a dummy byte, causing all accesses to be prefixed
with 0xff.
This of course breaks reading out the nvram, so do not just move back to
single i/o accessors, but also ensure that the dummy byte is correctly
set.

Backport of r46707.

Signed-off-by: Jonas Gorski <jogo@openwrt.org>
SVN-Revision: 46709

target/linux/brcm63xx/patches-3.18/345-MIPS-BCM63XX-fixup-mapped-SPI-flash-access-on-boot.patch
target/linux/brcm63xx/patches-3.18/355-MIPS-BCM63XX-allow-board-implementations-to-force-fl.patch
target/linux/brcm63xx/patches-3.18/372_dont_register_pflash_when_available_in_dtb.patch
target/linux/brcm63xx/patches-3.18/400-bcm963xx_flashmap.patch
target/linux/brcm63xx/patches-3.18/411-MIPS-BCM63XX-Register-SPI-flash-if-present.patch
target/linux/brcm63xx/patches-3.18/415-MIPS-BCM63XX-export-the-attached-flash-type.patch
target/linux/brcm63xx/patches-3.18/418-MIPS-BCM63XX-pass-caldata-info-to-flash.patch
target/linux/brcm63xx/patches-3.18/422-BCM63XX-add-a-fixup-for-rt2x00-devices.patch
target/linux/brcm63xx/patches-3.18/511-board_V2500V.patch

index 2b19600776d6270717a1160dd385fc9910c8770b..c8bef13625845cfeb95ba07f7d5d5a4cffd650ad 100644 (file)
@@ -9,12 +9,20 @@ reads.
 
 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
        }
  }
  
@@ -24,36 +32,49 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
 +#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);
index 7e408f69fb98680dd256ccd4c68275f739ecc74d..bdbba036b592417622f429e329659033daef3dae 100644 (file)
@@ -14,7 +14,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
 
 --- 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 =
        },
  };
  
@@ -27,7 +27,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
  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:
index 88efc2360bc52f9bdf697df235c4a5072a787c69..25384ebb68d3381d19504211df7b33462bfef79a 100644 (file)
@@ -1,6 +1,6 @@
 --- 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>
  
@@ -9,7 +9,7 @@
  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:
index 03534c0aab073026de60615c25ae2fe40e956ba9..c693ace36324587bc76f49a617b738758b3be5cd 100644 (file)
@@ -12,7 +12,7 @@ Signed-off-by: Axel Gembe <ago@bastart.eu.org>
 
 --- 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
        }
  };
  
index 24a5888ef5d974b55c1876e4b08f23b6dce1afa7..23b3b834863a266de10059d10f317e1b211b58a8 100644 (file)
@@ -11,10 +11,10 @@ Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
 
 --- 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>
  
@@ -24,7 +24,7 @@ Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
  #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;
  }
  
@@ -46,7 +46,7 @@ Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
  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 */
@@ -62,7 +62,7 @@ Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
                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);
@@ -83,7 +83,7 @@ Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
                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);
@@ -95,7 +95,7 @@ Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
                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:
index 55639cafab756ca4a1bff54d9ed9186d568cd242..44763bb256cfe29bddc1b1ac1ed2d1da9d38a99c 100644 (file)
@@ -11,7 +11,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
 
 --- 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;
        }
  }
index b329c312f5e4a0fe0fce1991a905d922f5098c3f..484e1fd5a25b7a963ce96a09dd56360d83907ace 100644 (file)
@@ -22,7 +22,7 @@ Subject: [PATCH 69/80] MIPS: BCM63XX: pass caldata info to flash
        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
        }
  };
  
@@ -38,7 +38,7 @@ Subject: [PATCH 69/80] MIPS: BCM63XX: pass caldata info to flash
  };
  
  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,
@@ -46,7 +46,7 @@ Subject: [PATCH 69/80] MIPS: BCM63XX: pass caldata info to flash
  };
  
  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)
        }
  }
  
index bff489b960f9da89d4f49bf9288dc9fd4207c909..4a0a7b0a71c3033573276e12602290f5155c0155 100644 (file)
@@ -61,7 +61,7 @@ Subject: [PATCH 72/72] 446-BCM63XX-add-a-fixup-for-rt2x00-devices
  }
 --- 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)
        }
  }
  
index 2d8951fc0895310b1c506b6278f47068c22f0042..5b7c789dac382279810eef30529d5c991aeea3ee 100644 (file)
@@ -69,7 +69,7 @@
        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>
  
@@ -77,7 +77,7 @@
  #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;