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
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 For reading flash content we use MMIO but it's possible to read only
11 first 16 MiB this way. It's simply an arch design/limitation.
12 To support flash sizes bigger than 16 MiB implement indirect access
13 using ChipCommon registers.
14 This has been tested using MX25L25635F.
16 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 Acked-by: Marek Vasut <marek.vasut@gmail.com>
18 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
20 drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++++---
21 drivers/mtd/devices/bcm47xxsflash.h | 3 +++
22 2 files changed, 24 insertions(+), 3 deletions(-)
24 --- a/drivers/mtd/devices/bcm47xxsflash.c
25 +++ b/drivers/mtd/devices/bcm47xxsflash.c
26 @@ -105,15 +105,33 @@ static int bcm47xxsflash_read(struct mtd
27 size_t *retlen, u_char *buf)
29 struct bcm47xxsflash *b47s = mtd->priv;
30 + size_t orig_len = len;
32 /* Check address range */
33 if ((from + len) > mtd->size)
36 - memcpy_fromio(buf, b47s->window + from, len);
38 + /* Read as much as possible using fast MMIO window */
39 + if (from < BCM47XXSFLASH_WINDOW_SZ) {
43 + memcpy_len = min(len, (size_t)(BCM47XXSFLASH_WINDOW_SZ - from));
44 + memcpy_fromio(buf, b47s->window + from, memcpy_len);
50 + /* Use indirect access for content out of the window */
51 + for (; len; len--) {
52 + b47s->cc_write(b47s, BCMA_CC_FLASHADDR, from++);
53 + bcm47xxsflash_cmd(b47s, OPCODE_ST_READ4B);
54 + *buf++ = b47s->cc_read(b47s, BCMA_CC_FLASHDATA);
62 static int bcm47xxsflash_write_st(struct mtd_info *mtd, u32 offset, size_t len,
63 --- a/drivers/mtd/devices/bcm47xxsflash.h
64 +++ b/drivers/mtd/devices/bcm47xxsflash.h
67 #include <linux/mtd/mtd.h>
69 +#define BCM47XXSFLASH_WINDOW_SZ SZ_16M
71 /* Used for ST flashes only. */
72 #define OPCODE_ST_WREN 0x0006 /* Write Enable */
73 #define OPCODE_ST_WRDIS 0x0004 /* Write Disable */
75 #define OPCODE_ST_RES 0x03ab /* Read Electronic Signature */
76 #define OPCODE_ST_CSA 0x1000 /* Keep chip select asserted */
77 #define OPCODE_ST_SSE 0x0220 /* Sub-sector Erase */
78 +#define OPCODE_ST_READ4B 0x6313 /* Read Data Bytes in 4Byte addressing mode */
80 /* Used for Atmel flashes only. */
81 #define OPCODE_AT_READ 0x07e8