Skip to content

Commit

Permalink
mtd: bcm47xxsflash: support reading flash out of mapping window
Browse files Browse the repository at this point in the history
For reading flash content we use MMIO but it's possible to read only
first 16 MiB this way. It's simply an arch design/limitation.
To support flash sizes bigger than 16 MiB implement indirect access
using ChipCommon registers.
This has been tested using MX25L25635F.

Signed-off-by: Rafał Miłecki <[email protected]>
Acked-by: Marek Vasut <[email protected]>
Signed-off-by: Brian Norris <[email protected]>
  • Loading branch information
Rafał Miłecki authored and computersforpeace committed Feb 8, 2017
1 parent 9c8d7ff commit ccc3823
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
24 changes: 21 additions & 3 deletions drivers/mtd/devices/bcm47xxsflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,33 @@ static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf)
{
struct bcm47xxsflash *b47s = mtd->priv;
size_t orig_len = len;

/* Check address range */
if ((from + len) > mtd->size)
return -EINVAL;

memcpy_fromio(buf, b47s->window + from, len);
*retlen = len;
/* Read as much as possible using fast MMIO window */
if (from < BCM47XXSFLASH_WINDOW_SZ) {
size_t memcpy_len;

return len;
memcpy_len = min(len, (size_t)(BCM47XXSFLASH_WINDOW_SZ - from));
memcpy_fromio(buf, b47s->window + from, memcpy_len);
from += memcpy_len;
len -= memcpy_len;
buf += memcpy_len;
}

/* Use indirect access for content out of the window */
for (; len; len--) {
b47s->cc_write(b47s, BCMA_CC_FLASHADDR, from++);
bcm47xxsflash_cmd(b47s, OPCODE_ST_READ4B);
*buf++ = b47s->cc_read(b47s, BCMA_CC_FLASHDATA);
}

*retlen = orig_len;

return orig_len;
}

static int bcm47xxsflash_write_st(struct mtd_info *mtd, u32 offset, size_t len,
Expand Down
3 changes: 3 additions & 0 deletions drivers/mtd/devices/bcm47xxsflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <linux/mtd/mtd.h>

#define BCM47XXSFLASH_WINDOW_SZ SZ_16M

/* Used for ST flashes only. */
#define OPCODE_ST_WREN 0x0006 /* Write Enable */
#define OPCODE_ST_WRDIS 0x0004 /* Write Disable */
Expand All @@ -16,6 +18,7 @@
#define OPCODE_ST_RES 0x03ab /* Read Electronic Signature */
#define OPCODE_ST_CSA 0x1000 /* Keep chip select asserted */
#define OPCODE_ST_SSE 0x0220 /* Sub-sector Erase */
#define OPCODE_ST_READ4B 0x6313 /* Read Data Bytes in 4Byte addressing mode */

/* Used for Atmel flashes only. */
#define OPCODE_AT_READ 0x07e8
Expand Down

0 comments on commit ccc3823

Please sign in to comment.