ecdae2a8715c4c334c90e03049bb84936bb6c9de
[openwrt/staging/jow.git] /
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
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.
15
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>
19 ---
20 drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++++---
21 drivers/mtd/devices/bcm47xxsflash.h | 3 +++
22 2 files changed, 24 insertions(+), 3 deletions(-)
23
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)
28 {
29 struct bcm47xxsflash *b47s = mtd->priv;
30 + size_t orig_len = len;
31
32 /* Check address range */
33 if ((from + len) > mtd->size)
34 return -EINVAL;
35
36 - memcpy_fromio(buf, b47s->window + from, len);
37 - *retlen = len;
38 + /* Read as much as possible using fast MMIO window */
39 + if (from < BCM47XXSFLASH_WINDOW_SZ) {
40 + size_t memcpy_len;
41
42 - return len;
43 + memcpy_len = min(len, (size_t)(BCM47XXSFLASH_WINDOW_SZ - from));
44 + memcpy_fromio(buf, b47s->window + from, memcpy_len);
45 + from += memcpy_len;
46 + len -= memcpy_len;
47 + buf += memcpy_len;
48 + }
49 +
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);
55 + }
56 +
57 + *retlen = orig_len;
58 +
59 + return orig_len;
60 }
61
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
65 @@ -3,6 +3,8 @@
66
67 #include <linux/mtd/mtd.h>
68
69 +#define BCM47XXSFLASH_WINDOW_SZ SZ_16M
70 +
71 /* Used for ST flashes only. */
72 #define OPCODE_ST_WREN 0x0006 /* Write Enable */
73 #define OPCODE_ST_WRDIS 0x0004 /* Write Disable */
74 @@ -16,6 +18,7 @@
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 */
79
80 /* Used for Atmel flashes only. */
81 #define OPCODE_AT_READ 0x07e8