042-0006-mtd-bcm47xxsflash-support-reading-flash-out-of-mappi.patch 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. From ccc38234fdc70120be79e7fb2df5c27ca5cd4c8a Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  3. Date: Wed, 8 Feb 2017 23:53:44 +0100
  4. Subject: [PATCH] mtd: bcm47xxsflash: support reading flash out of mapping
  5. window
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. For reading flash content we use MMIO but it's possible to read only
  10. first 16 MiB this way. It's simply an arch design/limitation.
  11. To support flash sizes bigger than 16 MiB implement indirect access
  12. using ChipCommon registers.
  13. This has been tested using MX25L25635F.
  14. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  15. Acked-by: Marek Vasut <marek.vasut@gmail.com>
  16. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  17. ---
  18. drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++++---
  19. drivers/mtd/devices/bcm47xxsflash.h | 3 +++
  20. 2 files changed, 24 insertions(+), 3 deletions(-)
  21. --- a/drivers/mtd/devices/bcm47xxsflash.c
  22. +++ b/drivers/mtd/devices/bcm47xxsflash.c
  23. @@ -105,15 +105,33 @@ static int bcm47xxsflash_read(struct mtd
  24. size_t *retlen, u_char *buf)
  25. {
  26. struct bcm47xxsflash *b47s = mtd->priv;
  27. + size_t orig_len = len;
  28. /* Check address range */
  29. if ((from + len) > mtd->size)
  30. return -EINVAL;
  31. - memcpy_fromio(buf, b47s->window + from, len);
  32. - *retlen = len;
  33. + /* Read as much as possible using fast MMIO window */
  34. + if (from < BCM47XXSFLASH_WINDOW_SZ) {
  35. + size_t memcpy_len;
  36. - return len;
  37. + memcpy_len = min(len, (size_t)(BCM47XXSFLASH_WINDOW_SZ - from));
  38. + memcpy_fromio(buf, b47s->window + from, memcpy_len);
  39. + from += memcpy_len;
  40. + len -= memcpy_len;
  41. + buf += memcpy_len;
  42. + }
  43. +
  44. + /* Use indirect access for content out of the window */
  45. + for (; len; len--) {
  46. + b47s->cc_write(b47s, BCMA_CC_FLASHADDR, from++);
  47. + bcm47xxsflash_cmd(b47s, OPCODE_ST_READ4B);
  48. + *buf++ = b47s->cc_read(b47s, BCMA_CC_FLASHDATA);
  49. + }
  50. +
  51. + *retlen = orig_len;
  52. +
  53. + return orig_len;
  54. }
  55. static int bcm47xxsflash_write_st(struct mtd_info *mtd, u32 offset, size_t len,
  56. --- a/drivers/mtd/devices/bcm47xxsflash.h
  57. +++ b/drivers/mtd/devices/bcm47xxsflash.h
  58. @@ -3,6 +3,8 @@
  59. #include <linux/mtd/mtd.h>
  60. +#define BCM47XXSFLASH_WINDOW_SZ SZ_16M
  61. +
  62. /* Used for ST flashes only. */
  63. #define OPCODE_ST_WREN 0x0006 /* Write Enable */
  64. #define OPCODE_ST_WRDIS 0x0004 /* Write Disable */
  65. @@ -16,6 +18,7 @@
  66. #define OPCODE_ST_RES 0x03ab /* Read Electronic Signature */
  67. #define OPCODE_ST_CSA 0x1000 /* Keep chip select asserted */
  68. #define OPCODE_ST_SSE 0x0220 /* Sub-sector Erase */
  69. +#define OPCODE_ST_READ4B 0x6313 /* Read Data Bytes in 4Byte addressing mode */
  70. /* Used for Atmel flashes only. */
  71. #define OPCODE_AT_READ 0x07e8