345-MIPS-BCM63XX-fixup-mapped-SPI-flash-access-on-boot.patch 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From 1cacd0f7b0d35f8e3d3f8a69ecb3b5e436d6b9e8 Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <jogo@openwrt.org>
  3. Date: Sun, 22 Dec 2013 13:25:25 +0100
  4. Subject: [PATCH 52/56] MIPS: BCM63XX: fixup mapped SPI flash access on boot
  5. Some bootloaders leave the flash access in an invalid state with dual
  6. read enabled; fix it by disabling it and falling back to simple fast
  7. reads.
  8. Signed-off-by: Jonas Gorski <jogo@openwrt.org>
  9. ---
  10. arch/mips/bcm63xx/dev-flash.c | 51 ++++++++++++++++++++++++++++++++++++
  11. 1 file changed, 51 insertions(+)
  12. --- a/arch/mips/bcm63xx/dev-flash.c
  13. +++ b/arch/mips/bcm63xx/dev-flash.c
  14. @@ -16,6 +16,7 @@
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <linux/mtd/physmap.h>
  18. +#include <linux/mtd/spi-nor.h>
  19. #include <bcm63xx_cpu.h>
  20. #include <bcm63xx_dev_flash.h>
  21. @@ -110,9 +111,59 @@ static int __init bcm63xx_detect_flash_t
  22. }
  23. }
  24. +#define HSSPI_FLASH_CTRL_REG 0x14
  25. +#define FLASH_CTRL_READ_OPCODE_MASK 0xff
  26. +#define FLASH_CTRL_ADDR_BYTES_MASK (0x3 << 8)
  27. +#define FLASH_CTRL_ADDR_BYTES_2 (0 << 8)
  28. +#define FLASH_CTRL_ADDR_BYTES_3 (1 << 8)
  29. +#define FLASH_CTRL_ADDR_BYTES_4 (2 << 8)
  30. +#define FLASH_CTRL_DUMMY_BYTES_SHIFT 10
  31. +#define FLASH_CTRL_DUMMY_BYTES_MASK (0x3 << FLASH_CTRL_DUMMY_BYTES_SHIFT)
  32. +#define FLASH_CTRL_MB_EN (1 << 23)
  33. +
  34. void __init bcm63xx_flash_detect(void)
  35. {
  36. flash_type = bcm63xx_detect_flash_type();
  37. +
  38. + /* ensure flash mapping has sane values */
  39. + if (flash_type == BCM63XX_FLASH_TYPE_SERIAL &&
  40. + (BCMCPU_IS_6318() || BCMCPU_IS_6328() || BCMCPU_IS_6362() ||
  41. + BCMCPU_IS_63268())) {
  42. + u32 val = bcm_rset_readl(RSET_HSSPI, HSSPI_FLASH_CTRL_REG);
  43. +
  44. + if (val & FLASH_CTRL_MB_EN) {
  45. + /* cfe might configure non working dual-io mode */
  46. + val &= ~FLASH_CTRL_MB_EN;
  47. + val &= ~FLASH_CTRL_READ_OPCODE_MASK;
  48. + val &= ~FLASH_CTRL_DUMMY_BYTES_MASK;
  49. + val |= 1 << FLASH_CTRL_DUMMY_BYTES_SHIFT;
  50. +
  51. + switch (val & FLASH_CTRL_ADDR_BYTES_MASK) {
  52. + case FLASH_CTRL_ADDR_BYTES_3:
  53. + val |= SPINOR_OP_READ_FAST;
  54. + break;
  55. + case FLASH_CTRL_ADDR_BYTES_4:
  56. + val |= SPINOR_OP_READ4_FAST;
  57. + break;
  58. + case FLASH_CTRL_ADDR_BYTES_2:
  59. + default:
  60. + pr_warn("unsupported address byte mode (%x), not fixing up\n",
  61. + val & FLASH_CTRL_ADDR_BYTES_MASK);
  62. + return;
  63. + }
  64. + } else {
  65. + /* ensure dummy bytes is set to 1 for _FAST reads */
  66. + u8 cmd = val & FLASH_CTRL_READ_OPCODE_MASK;
  67. +
  68. + if (cmd != SPINOR_OP_READ_FAST && cmd != SPINOR_OP_READ4_FAST)
  69. + return;
  70. +
  71. + val &= ~FLASH_CTRL_DUMMY_BYTES_MASK;
  72. + val |= 1 << FLASH_CTRL_DUMMY_BYTES_SHIFT;
  73. + }
  74. +
  75. + bcm_rset_writel(RSET_HSSPI, val, HSSPI_FLASH_CTRL_REG);
  76. + }
  77. }
  78. int __init bcm63xx_flash_register(void)