From: Rafał Miłecki Date: Thu, 9 Feb 2017 07:34:20 +0000 (+0100) Subject: kernel: backport bcm47xxsflash support for reading 32 MiB flashes X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=76eb62e5afeac6ca5d90fb26eb34ac66df91a82e;p=openwrt%2Fstaging%2Fjow.git kernel: backport bcm47xxsflash support for reading 32 MiB flashes Signed-off-by: Rafał Miłecki --- diff --git a/target/linux/generic/patches-4.4/042-0005-mtd-bcm47xxsflash-use-platform_-set-get-_drvdata.patch b/target/linux/generic/patches-4.4/042-0005-mtd-bcm47xxsflash-use-platform_-set-get-_drvdata.patch new file mode 100644 index 0000000000..a68eaa4594 --- /dev/null +++ b/target/linux/generic/patches-4.4/042-0005-mtd-bcm47xxsflash-use-platform_-set-get-_drvdata.patch @@ -0,0 +1,63 @@ +From be5e5099183301fb7920f8f6b66bd3ac1f820a97 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Mon, 16 Jan 2017 17:28:18 +0100 +Subject: [PATCH] mtd: bcm47xxsflash: use platform_(set|get)_drvdata +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +We have generic place & helpers for storing platform driver data so +there is no reason for using custom priv pointer. + +This allows cleaning up struct bcma_sflash from unneeded fields. + +Signed-off-by: Rafał Miłecki +Acked-by: Kalle Valo +Acked-by: Boris Brezillon +Signed-off-by: Brian Norris +--- + drivers/mtd/devices/bcm47xxsflash.c | 6 +++--- + include/linux/bcma/bcma_driver_chipcommon.h | 3 --- + 2 files changed, 3 insertions(+), 6 deletions(-) + +--- a/drivers/mtd/devices/bcm47xxsflash.c ++++ b/drivers/mtd/devices/bcm47xxsflash.c +@@ -284,7 +284,6 @@ static int bcm47xxsflash_bcma_probe(stru + b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL); + if (!b47s) + return -ENOMEM; +- sflash->priv = b47s; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { +@@ -334,6 +333,8 @@ static int bcm47xxsflash_bcma_probe(stru + b47s->size = sflash->size; + bcm47xxsflash_fill_mtd(b47s, &pdev->dev); + ++ platform_set_drvdata(pdev, b47s); ++ + err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0); + if (err) { + pr_err("Failed to register MTD device: %d\n", err); +@@ -349,8 +350,7 @@ static int bcm47xxsflash_bcma_probe(stru + + static int bcm47xxsflash_bcma_remove(struct platform_device *pdev) + { +- struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev); +- struct bcm47xxsflash *b47s = sflash->priv; ++ struct bcm47xxsflash *b47s = platform_get_drvdata(pdev); + + mtd_device_unregister(&b47s->mtd); + iounmap(b47s->window); +--- a/include/linux/bcma/bcma_driver_chipcommon.h ++++ b/include/linux/bcma/bcma_driver_chipcommon.h +@@ -591,9 +591,6 @@ struct bcma_sflash { + u32 blocksize; + u16 numblocks; + u32 size; +- +- struct mtd_info *mtd; +- void *priv; + }; + #endif + diff --git a/target/linux/generic/patches-4.4/042-0006-mtd-bcm47xxsflash-support-reading-flash-out-of-mappi.patch b/target/linux/generic/patches-4.4/042-0006-mtd-bcm47xxsflash-support-reading-flash-out-of-mappi.patch new file mode 100644 index 0000000000..ecdae2a871 --- /dev/null +++ b/target/linux/generic/patches-4.4/042-0006-mtd-bcm47xxsflash-support-reading-flash-out-of-mappi.patch @@ -0,0 +1,81 @@ +From ccc38234fdc70120be79e7fb2df5c27ca5cd4c8a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Wed, 8 Feb 2017 23:53:44 +0100 +Subject: [PATCH] mtd: bcm47xxsflash: support reading flash out of mapping + window +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +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 +Acked-by: Marek Vasut +Signed-off-by: Brian Norris +--- + drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++++--- + drivers/mtd/devices/bcm47xxsflash.h | 3 +++ + 2 files changed, 24 insertions(+), 3 deletions(-) + +--- a/drivers/mtd/devices/bcm47xxsflash.c ++++ b/drivers/mtd/devices/bcm47xxsflash.c +@@ -105,15 +105,33 @@ static int bcm47xxsflash_read(struct mtd + 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, +--- a/drivers/mtd/devices/bcm47xxsflash.h ++++ b/drivers/mtd/devices/bcm47xxsflash.h +@@ -3,6 +3,8 @@ + + #include + ++#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 */ +@@ -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 diff --git a/target/linux/generic/patches-4.9/060-0001-mtd-bcm47xxpart-fix-parsing-first-block-after-aligne.patch b/target/linux/generic/patches-4.9/060-0001-mtd-bcm47xxpart-fix-parsing-first-block-after-aligne.patch new file mode 100644 index 0000000000..7eed77775a --- /dev/null +++ b/target/linux/generic/patches-4.9/060-0001-mtd-bcm47xxpart-fix-parsing-first-block-after-aligne.patch @@ -0,0 +1,40 @@ +From bd5d21310133921021d78995ad6346f908483124 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Sun, 20 Nov 2016 16:09:30 +0100 +Subject: [PATCH] mtd: bcm47xxpart: fix parsing first block after aligned TRX +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +After parsing TRX we should skip to the first block placed behind it. +Our code was working only with TRX with length not aligned to the +blocksize. In other cases (length aligned) it was missing the block +places right after TRX. + +This fixes calculation and simplifies the comment. + +Signed-off-by: Rafał Miłecki +Signed-off-by: Brian Norris +--- + drivers/mtd/bcm47xxpart.c | 10 ++++------ + 1 file changed, 4 insertions(+), 6 deletions(-) + +--- a/drivers/mtd/bcm47xxpart.c ++++ b/drivers/mtd/bcm47xxpart.c +@@ -229,12 +229,10 @@ static int bcm47xxpart_parse(struct mtd_ + + last_trx_part = curr_part - 1; + +- /* +- * We have whole TRX scanned, skip to the next part. Use +- * roundown (not roundup), as the loop will increase +- * offset in next step. +- */ +- offset = rounddown(offset + trx->length, blocksize); ++ /* Jump to the end of TRX */ ++ offset = roundup(offset + trx->length, blocksize); ++ /* Next loop iteration will increase the offset */ ++ offset -= blocksize; + continue; + } + diff --git a/target/linux/generic/patches-4.9/060-0002-mtd-bcm47xxsflash-use-platform_-set-get-_drvdata.patch b/target/linux/generic/patches-4.9/060-0002-mtd-bcm47xxsflash-use-platform_-set-get-_drvdata.patch new file mode 100644 index 0000000000..d975a26202 --- /dev/null +++ b/target/linux/generic/patches-4.9/060-0002-mtd-bcm47xxsflash-use-platform_-set-get-_drvdata.patch @@ -0,0 +1,63 @@ +From be5e5099183301fb7920f8f6b66bd3ac1f820a97 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Mon, 16 Jan 2017 17:28:18 +0100 +Subject: [PATCH] mtd: bcm47xxsflash: use platform_(set|get)_drvdata +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +We have generic place & helpers for storing platform driver data so +there is no reason for using custom priv pointer. + +This allows cleaning up struct bcma_sflash from unneeded fields. + +Signed-off-by: Rafał Miłecki +Acked-by: Kalle Valo +Acked-by: Boris Brezillon +Signed-off-by: Brian Norris +--- + drivers/mtd/devices/bcm47xxsflash.c | 6 +++--- + include/linux/bcma/bcma_driver_chipcommon.h | 3 --- + 2 files changed, 3 insertions(+), 6 deletions(-) + +--- a/drivers/mtd/devices/bcm47xxsflash.c ++++ b/drivers/mtd/devices/bcm47xxsflash.c +@@ -284,7 +284,6 @@ static int bcm47xxsflash_bcma_probe(stru + b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL); + if (!b47s) + return -ENOMEM; +- sflash->priv = b47s; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { +@@ -320,6 +319,8 @@ static int bcm47xxsflash_bcma_probe(stru + b47s->size = sflash->size; + bcm47xxsflash_fill_mtd(b47s, &pdev->dev); + ++ platform_set_drvdata(pdev, b47s); ++ + err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0); + if (err) { + pr_err("Failed to register MTD device: %d\n", err); +@@ -335,8 +336,7 @@ static int bcm47xxsflash_bcma_probe(stru + + static int bcm47xxsflash_bcma_remove(struct platform_device *pdev) + { +- struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev); +- struct bcm47xxsflash *b47s = sflash->priv; ++ struct bcm47xxsflash *b47s = platform_get_drvdata(pdev); + + mtd_device_unregister(&b47s->mtd); + iounmap(b47s->window); +--- a/include/linux/bcma/bcma_driver_chipcommon.h ++++ b/include/linux/bcma/bcma_driver_chipcommon.h +@@ -593,9 +593,6 @@ struct bcma_sflash { + u32 blocksize; + u16 numblocks; + u32 size; +- +- struct mtd_info *mtd; +- void *priv; + }; + #endif + diff --git a/target/linux/generic/patches-4.9/060-0003-mtd-bcm47xxsflash-support-reading-flash-out-of-mappi.patch b/target/linux/generic/patches-4.9/060-0003-mtd-bcm47xxsflash-support-reading-flash-out-of-mappi.patch new file mode 100644 index 0000000000..ecdae2a871 --- /dev/null +++ b/target/linux/generic/patches-4.9/060-0003-mtd-bcm47xxsflash-support-reading-flash-out-of-mappi.patch @@ -0,0 +1,81 @@ +From ccc38234fdc70120be79e7fb2df5c27ca5cd4c8a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Wed, 8 Feb 2017 23:53:44 +0100 +Subject: [PATCH] mtd: bcm47xxsflash: support reading flash out of mapping + window +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +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 +Acked-by: Marek Vasut +Signed-off-by: Brian Norris +--- + drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++++--- + drivers/mtd/devices/bcm47xxsflash.h | 3 +++ + 2 files changed, 24 insertions(+), 3 deletions(-) + +--- a/drivers/mtd/devices/bcm47xxsflash.c ++++ b/drivers/mtd/devices/bcm47xxsflash.c +@@ -105,15 +105,33 @@ static int bcm47xxsflash_read(struct mtd + 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, +--- a/drivers/mtd/devices/bcm47xxsflash.h ++++ b/drivers/mtd/devices/bcm47xxsflash.h +@@ -3,6 +3,8 @@ + + #include + ++#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 */ +@@ -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 diff --git a/target/linux/generic/patches-4.9/060-mtd-bcm47xxpart-fix-parsing-first-block-after-aligne.patch b/target/linux/generic/patches-4.9/060-mtd-bcm47xxpart-fix-parsing-first-block-after-aligne.patch deleted file mode 100644 index 7eed77775a..0000000000 --- a/target/linux/generic/patches-4.9/060-mtd-bcm47xxpart-fix-parsing-first-block-after-aligne.patch +++ /dev/null @@ -1,40 +0,0 @@ -From bd5d21310133921021d78995ad6346f908483124 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Sun, 20 Nov 2016 16:09:30 +0100 -Subject: [PATCH] mtd: bcm47xxpart: fix parsing first block after aligned TRX -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -After parsing TRX we should skip to the first block placed behind it. -Our code was working only with TRX with length not aligned to the -blocksize. In other cases (length aligned) it was missing the block -places right after TRX. - -This fixes calculation and simplifies the comment. - -Signed-off-by: Rafał Miłecki -Signed-off-by: Brian Norris ---- - drivers/mtd/bcm47xxpart.c | 10 ++++------ - 1 file changed, 4 insertions(+), 6 deletions(-) - ---- a/drivers/mtd/bcm47xxpart.c -+++ b/drivers/mtd/bcm47xxpart.c -@@ -229,12 +229,10 @@ static int bcm47xxpart_parse(struct mtd_ - - last_trx_part = curr_part - 1; - -- /* -- * We have whole TRX scanned, skip to the next part. Use -- * roundown (not roundup), as the loop will increase -- * offset in next step. -- */ -- offset = rounddown(offset + trx->length, blocksize); -+ /* Jump to the end of TRX */ -+ offset = roundup(offset + trx->length, blocksize); -+ /* Next loop iteration will increase the offset */ -+ offset -= blocksize; - continue; - } -