diff mbox series

[OpenWrt-Devel,1/2] kernel: mtd: spinand: backport-4.19: Chip support through 5.1

Message ID 20190605201706.27462-2-lede@allycomm.com
State Superseded
Headers show
Series kernel: mtd: spinand: backport-4.19: Add'l chip support | expand

Commit Message

Jeff Kletsky June 5, 2019, 8:17 p.m. UTC
From: Jeff Kletsky <git-commits@allycomm.com>

Several SPI NAND chips were added between 4.19 and 5.1
including GigaDevice, Toshiba, and Winbond.
A fix to Macronix chips' ECC was also included.

 * Add support for GigaDevice GD5F1GQ4UExxG
 * Add support for all Toshiba Memory products
 * macronix: Fix ECC Status Read
 * add support for GigaDevice GD5FxGQ4xA
 * Add initial support for Toshiba TC58CVG2S0H
 * winbond: Add support for W25N01GV

The following two commits from 5.0 appear already backported upstream
so are not included here:

 * Fix the error/cleanup path in spinand_init()
 * Handle the case where PROGRAM LOAD does not reset the cache

Existing GigaDevice patches reordered to maintain upstream content

Upstream patches refreshed against 4.19.47

Run-tested-on: ath79/nand (4.19.47, WIP)

Signed-off-by: Jeff Kletsky <git-commits@allycomm.com>
---
 ...nbond-Add-support-for-W25N01GV.patch (new) |  42 ++++
 ...l-support-for-Toshiba-TC58CVG2.patch (new) | 188 ++++++++++++++++++
 ...d-support-for-GigaDevice-GD5FxGQ4xA.patch} |  12 +-
 ...d-macronix-Fix-ECC-Status-Read.patch (new) |  44 ++++
 ...t-for-all-Toshiba-Memory-produ.patch (new) | 141 +++++++++++++
 ...upport-for-GigaDevice-GD5F1GQ4UExxG.patch} |  13 +-
 6 files changed, 430 insertions(+), 10 deletions(-)

Comments

Petr Štetiar June 5, 2019, 8:54 p.m. UTC | #1
Jeff Kletsky <lede@allycomm.com> [2019-06-05 13:17:05]:

Hi,

I'll put aside, that it's 4.19 (we should still focus on 4.14), can you please
explain in more detail, why we would need all this bacported patches?

>  * macronix: Fix ECC Status Read

I can understand this one.

>  * winbond: Add support for W25N01GV

This one as well, but then you need to remove existing one in the ipq40xx
patches or you're going to introduce build failure.

>  * Add support for GigaDevice GD5F1GQ4UExxG
>  * Add support for all Toshiba Memory products
>  * add support for GigaDevice GD5FxGQ4xA
>  * Add initial support for Toshiba TC58CVG2S0H

What devices currently in the tree need (or want) this? I mean, the more
patches, the more work during kernel bumps, so we should avoid it if the
patches are not necessary.

-- ynezz
Jeff Kletsky June 5, 2019, 11:34 p.m. UTC | #2
On 6/5/19 1:54 PM, Petr Štetiar wrote:

> Jeff Kletsky <lede@allycomm.com> [2019-06-05 13:17:05]:
>
> Hi,
>
> I'll put aside, that it's 4.19 (we should still focus on 4.14), can you please
> explain in more detail, why we would need all this bacported patches?
>
>>   * macronix: Fix ECC Status Read
> I can understand this one.
>
>>   * winbond: Add support for W25N01GV
> This one as well, but then you need to remove existing one in the ipq40xx
> patches or you're going to introduce build failure.
>
>>   * Add support for GigaDevice GD5F1GQ4UExxG
>>   * Add support for all Toshiba Memory products
>>   * add support for GigaDevice GD5FxGQ4xA
>>   * Add initial support for Toshiba TC58CVG2S0H
> What devices currently in the tree need (or want) this? I mean, the more
> patches, the more work during kernel bumps, so we should avoid it if the
> patches are not necessary.
>
> -- ynezz

Thanks for your time in review, insight, and comments.

The "focus" on 4.19 is for the ath79 target to be able to use SPI NAND
with the upstream support that became available to OpenWrt with 4.19

This will also help OEM/ODMs who have both been told to move off
the ar71xx platform, yet are stymied by the lack of "OpenWrt-approved"
SPI NAND support.

As one example:
https://github.com/openwrt/openwrt/pull/1428#issuecomment-441594401

     mkresin commented on Nov 26, 2018

     But [SPI-NAND support] requires 4.19 to not have to backport
     pretty much the whole MTD and SPI subsystems

     Please re-spin the patch as soon as we have kernel 4.19 support.
     The approach was already NAK'ed upstream and I don't see much gain
     in adding the hack if the next major kernel in OpenWrt
     will provide a suitable solution.

That direction is embodied in complete and tested local work,
easily extensible to other boards, once accepted by OpenWRT.
However, it requires support of the chips employed in the boards.


The GL.iNet GL-AR300M and GL-AR750S units have been shipped with:

   Paragon    PN26G01Axxxxx
   GigaDevice GD5F1GQ4UExxx
   GigaDevice GD5F1GQ4UFxxx

Both of these units have now been successfully ported to OpenWrt with
full NAND support on the ath79/nand target (4.19), including sysupgrade
and, on the AR300M, dual-firmware boot with automated fall-back.
(The GL-AR750S U-Boot only loads the kernel NOR at this time.)

The GigaDevice "F" chips are being used in currently available units.
I understand that Marty (cc-ed), who has worked on the AR300M as well,
has a Paragon-based device, so these chips exist "in the wild" as well.
  
These widely available units also address the similar question about[1]
[OpenWrt-Devel,2/2] kernel: mtd: spinand: Backport GigaDevice "F" from linux/next

The Paragon driver is complete, tested, and literally just submitted
to Linux MTD for review[2].

As this driver has not yet undergone upstream review and that there are
Paragon-based units that would otherwise not boot, I am holding the
patch series for these units until the Paragon driver is "cleared" upstream.



The main reason for including the Toshiba devices is to *simplify* bumps.
They all "intermingle" in spinand.h and core.c. Establishing a list consistent
with upstream Linux means that any potential patches should apply smoothly.
By "filling out" the supported devices, the upstream patches in this patch set
apply without significant changes.

   git log --pretty='%h %s'stable/linux-5.1.y ^v4.19.74 -- \
     drivers/mtd/nand/spi/ include/linux/mtd/spinand.h

indicates that there are no further patches that impact these files prior to 5.2
Of that list, as called out in the cover to this series and the related commit,
two have already been backported to 4.19.74.

Also, as these patches reflect the state of upstream Linux, they would be removed
in their entirely when the next LTS kernel is available, sometime after 5.2.

These drivers are only compiled when CONFIG_MTD_SPI_NAND=y is set by the target.

These targets are only pistachio and ipq4019, with ath79/nand (not /generic) WIP.

As a result, they do not impact "tiny" boards, or the often "value-focused"
and low-resource ar71xx, ath79/generic, and ramips boards.

A quick check of removing support of the Toshiba SPI NAND from a local build here
shows a change in kernel size in the image of only 366 bytes. This is consistent
with the changes being a set of structs defining the device, and two, brief bits
of code, one for decoding the return status of ECC, the other to check the MID/DID.

The run-time impact is effectively zero; if the MID doesn't match, the s/r returns.
It is only invoked only during driver-attachment probes, not during "run time".



Thank you for pointing out
patches-4.19/082-v4.20-mtd-spinand-winbond-Add-support-for-W25N01GV.patch

It appears to be the same patch as present as part of this commit.

I did not find "winbond" elsewhere under target/linux in the context of SPI NAND.

If deemed appropriate, that patch could be removed from the ipq40x target
and the "generic" one be used, minimizing the number of patches managed by OpenWrt.



Jeff



[1] [OpenWrt-Devel,2/2] kernel: mtd: spinand: Backport GigaDevice "F" from linux/next
     https://patchwork.ozlabs.org/patch/1110664/

[2] [Linux-MTD] mtd: spinand: Support Paragon PN26G01A and PN26G02A
     https://patchwork.ozlabs.org/patch/1110785/
diff mbox series

Patch

diff --git a/target/linux/generic/backport-4.19/421-v5.0-mtd-spinand-winbond-Add-support-for-W25N01GV.patch b/target/linux/generic/backport-4.19/421-v5.0-mtd-spinand-winbond-Add-support-for-W25N01GV.patch
new file mode 100644
index 0000000000..7fae1ad2d6
--- /dev/null
+++ b/target/linux/generic/backport-4.19/421-v5.0-mtd-spinand-winbond-Add-support-for-W25N01GV.patch
@@ -0,0 +1,42 @@ 
+From 9a4d83074769d6ecf1f5c3fef0f183b09abf3726 Mon Sep 17 00:00:00 2001
+From: Robert Marko <robimarko@gmail.com>
+Date: Sat, 6 Oct 2018 17:36:42 +0200
+Subject: [PATCH 1/8] mtd: spinand: winbond: Add support for W25N01GV
+
+W25N01GV is a single die version of the already supported
+W25M02GV with half the capacity. Everything else is the
+same so introduce support for W25N01GV.
+
+Datasheet:http://www.winbond.com/resource-files/w25n01gv%20revl%20050918%20unsecured.pdf
+
+Tested on 8devices Jalapeno dev board under OpenWrt running 4.19-rc5.
+
+Signed-off-by: Robert Marko <robimarko@gmail.com>
+Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>
+Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
+---
+ drivers/mtd/nand/spi/winbond.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/drivers/mtd/nand/spi/winbond.c b/drivers/mtd/nand/spi/winbond.c
+index 67baa1b32c00..5d944580b898 100644
+--- a/drivers/mtd/nand/spi/winbond.c
++++ b/drivers/mtd/nand/spi/winbond.c
+@@ -84,6 +84,14 @@ static const struct spinand_info winbond_spinand_table[] = {
+ 		     0,
+ 		     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
+ 		     SPINAND_SELECT_TARGET(w25m02gv_select_target)),
++	SPINAND_INFO("W25N01GV", 0xAA,
++		     NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
++		     NAND_ECCREQ(1, 512),
++		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
++					      &write_cache_variants,
++					      &update_cache_variants),
++		     0,
++		     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
+ };
+ 
+ /**
+-- 
+2.20.1
+
diff --git a/target/linux/generic/backport-4.19/422-v5.0-mtd-spinand-Add-initial-support-for-Toshiba-TC58CVG2.patch b/target/linux/generic/backport-4.19/422-v5.0-mtd-spinand-Add-initial-support-for-Toshiba-TC58CVG2.patch
new file mode 100644
index 0000000000..ed42f0024b
--- /dev/null
+++ b/target/linux/generic/backport-4.19/422-v5.0-mtd-spinand-Add-initial-support-for-Toshiba-TC58CVG2.patch
@@ -0,0 +1,188 @@ 
+From 10949af1681d5bb5cdbcc012815c6e40eec17d02 Mon Sep 17 00:00:00 2001
+From: Schrempf Frieder <frieder.schrempf@kontron.De>
+Date: Thu, 8 Nov 2018 08:32:11 +0000
+Subject: [PATCH 2/8] mtd: spinand: Add initial support for Toshiba TC58CVG2S0H
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Add minimal support for the Toshiba TC58CVG2S0H SPI NAND chip.
+
+Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
+Acked-by: Clément Péron <peron.clem@gmail.com>
+Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
+---
+ drivers/mtd/nand/spi/Makefile  |   2 +-
+ drivers/mtd/nand/spi/core.c    |   1 +
+ drivers/mtd/nand/spi/toshiba.c | 137 +++++++++++++++++++++++++++++++++
+ include/linux/mtd/spinand.h    |   1 +
+ 4 files changed, 140 insertions(+), 1 deletion(-)
+ create mode 100644 drivers/mtd/nand/spi/toshiba.c
+
+--- a/drivers/mtd/nand/spi/Makefile
++++ b/drivers/mtd/nand/spi/Makefile
+@@ -1,3 +1,3 @@
+ # SPDX-License-Identifier: GPL-2.0
+-spinand-objs := core.o macronix.o micron.o winbond.o
++spinand-objs := core.o macronix.o micron.o toshiba.o winbond.o
+ obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
+--- a/drivers/mtd/nand/spi/core.c
++++ b/drivers/mtd/nand/spi/core.c
+@@ -764,6 +764,7 @@ static const struct nand_ops spinand_ops
+ static const struct spinand_manufacturer *spinand_manufacturers[] = {
+ 	&macronix_spinand_manufacturer,
+ 	&micron_spinand_manufacturer,
++	&toshiba_spinand_manufacturer,
+ 	&winbond_spinand_manufacturer,
+ };
+ 
+--- /dev/null
++++ b/drivers/mtd/nand/spi/toshiba.c
+@@ -0,0 +1,137 @@
++// SPDX-License-Identifier: GPL-2.0
++/*
++ * Copyright (c) 2018 exceet electronics GmbH
++ * Copyright (c) 2018 Kontron Electronics GmbH
++ *
++ * Author: Frieder Schrempf <frieder.schrempf@kontron.de>
++ */
++
++#include <linux/device.h>
++#include <linux/kernel.h>
++#include <linux/mtd/spinand.h>
++
++#define SPINAND_MFR_TOSHIBA		0x98
++#define TOSH_STATUS_ECC_HAS_BITFLIPS_T	(3 << 4)
++
++static SPINAND_OP_VARIANTS(read_cache_variants,
++		SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
++		SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
++		SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
++		SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
++
++static SPINAND_OP_VARIANTS(write_cache_variants,
++		SPINAND_PROG_LOAD(true, 0, NULL, 0));
++
++static SPINAND_OP_VARIANTS(update_cache_variants,
++		SPINAND_PROG_LOAD(false, 0, NULL, 0));
++
++static int tc58cvg2s0h_ooblayout_ecc(struct mtd_info *mtd, int section,
++				     struct mtd_oob_region *region)
++{
++	if (section > 7)
++		return -ERANGE;
++
++	region->offset = 128 + 16 * section;
++	region->length = 16;
++
++	return 0;
++}
++
++static int tc58cvg2s0h_ooblayout_free(struct mtd_info *mtd, int section,
++				      struct mtd_oob_region *region)
++{
++	if (section > 0)
++		return -ERANGE;
++
++	/* 2 bytes reserved for BBM */
++	region->offset = 2;
++	region->length = 126;
++
++	return 0;
++}
++
++static const struct mtd_ooblayout_ops tc58cvg2s0h_ooblayout = {
++	.ecc = tc58cvg2s0h_ooblayout_ecc,
++	.free = tc58cvg2s0h_ooblayout_free,
++};
++
++static int tc58cvg2s0h_ecc_get_status(struct spinand_device *spinand,
++				      u8 status)
++{
++	struct nand_device *nand = spinand_to_nand(spinand);
++	u8 mbf = 0;
++	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
++
++	switch (status & STATUS_ECC_MASK) {
++	case STATUS_ECC_NO_BITFLIPS:
++		return 0;
++
++	case STATUS_ECC_UNCOR_ERROR:
++		return -EBADMSG;
++
++	case STATUS_ECC_HAS_BITFLIPS:
++	case TOSH_STATUS_ECC_HAS_BITFLIPS_T:
++		/*
++		 * Let's try to retrieve the real maximum number of bitflips
++		 * in order to avoid forcing the wear-leveling layer to move
++		 * data around if it's not necessary.
++		 */
++		if (spi_mem_exec_op(spinand->spimem, &op))
++			return nand->eccreq.strength;
++
++		mbf >>= 4;
++
++		if (WARN_ON(mbf > nand->eccreq.strength || !mbf))
++			return nand->eccreq.strength;
++
++		return mbf;
++
++	default:
++		break;
++	}
++
++	return -EINVAL;
++}
++
++static const struct spinand_info toshiba_spinand_table[] = {
++	SPINAND_INFO("TC58CVG2S0H", 0xCD,
++		     NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
++		     NAND_ECCREQ(8, 512),
++		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
++					      &write_cache_variants,
++					      &update_cache_variants),
++		     SPINAND_HAS_QE_BIT,
++		     SPINAND_ECCINFO(&tc58cvg2s0h_ooblayout,
++				     tc58cvg2s0h_ecc_get_status)),
++};
++
++static int toshiba_spinand_detect(struct spinand_device *spinand)
++{
++	u8 *id = spinand->id.data;
++	int ret;
++
++	/*
++	 * Toshiba SPI NAND read ID needs a dummy byte,
++	 * so the first byte in id is garbage.
++	 */
++	if (id[1] != SPINAND_MFR_TOSHIBA)
++		return 0;
++
++	ret = spinand_match_and_init(spinand, toshiba_spinand_table,
++				     ARRAY_SIZE(toshiba_spinand_table),
++				     id[2]);
++	if (ret)
++		return ret;
++
++	return 1;
++}
++
++static const struct spinand_manufacturer_ops toshiba_spinand_manuf_ops = {
++	.detect = toshiba_spinand_detect,
++};
++
++const struct spinand_manufacturer toshiba_spinand_manufacturer = {
++	.id = SPINAND_MFR_TOSHIBA,
++	.name = "Toshiba",
++	.ops = &toshiba_spinand_manuf_ops,
++};
+--- a/include/linux/mtd/spinand.h
++++ b/include/linux/mtd/spinand.h
+@@ -196,6 +196,7 @@ struct spinand_manufacturer {
+ /* SPI NAND manufacturers */
+ extern const struct spinand_manufacturer macronix_spinand_manufacturer;
+ extern const struct spinand_manufacturer micron_spinand_manufacturer;
++extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
+ extern const struct spinand_manufacturer winbond_spinand_manufacturer;
+ 
+ /**
diff --git a/target/linux/generic/backport-4.19/450-v5.0-mtd-spinand-add-support-for-GigaDevice-GD5FxGQ4xA.patch b/target/linux/generic/backport-4.19/423-v5.0-mtd-spinand-add-support-for-GigaDevice-GD5FxGQ4xA.patch
similarity index 94%
rename from target/linux/generic/backport-4.19/450-v5.0-mtd-spinand-add-support-for-GigaDevice-GD5FxGQ4xA.patch
rename to target/linux/generic/backport-4.19/423-v5.0-mtd-spinand-add-support-for-GigaDevice-GD5FxGQ4xA.patch
index 15f761ab9d..4e6f18a4cb 100644
--- a/target/linux/generic/backport-4.19/450-v5.0-mtd-spinand-add-support-for-GigaDevice-GD5FxGQ4xA.patch
+++ b/target/linux/generic/backport-4.19/423-v5.0-mtd-spinand-add-support-for-GigaDevice-GD5FxGQ4xA.patch
@@ -1,7 +1,7 @@ 
 From c93c613214ac70c87beab5422a60077bf126b855 Mon Sep 17 00:00:00 2001
 From: Chuanhong Guo <gch981213@gmail.com>
 Date: Wed, 28 Nov 2018 21:07:25 +0800
-Subject: [PATCH] mtd: spinand: add support for GigaDevice GD5FxGQ4xA
+Subject: [PATCH 3/8] mtd: spinand: add support for GigaDevice GD5FxGQ4xA
 
 Add support for GigaDevice GD5F1G/2G/4GQ4xA SPI NAND.
 
@@ -11,7 +11,7 @@  Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
 ---
  drivers/mtd/nand/spi/Makefile     |   2 +-
  drivers/mtd/nand/spi/core.c       |   1 +
- drivers/mtd/nand/spi/gigadevice.c | 148 ++++++++++++++++++++++++++++++++++++++
+ drivers/mtd/nand/spi/gigadevice.c | 148 ++++++++++++++++++++++++++++++
  include/linux/mtd/spinand.h       |   1 +
  4 files changed, 151 insertions(+), 1 deletion(-)
  create mode 100644 drivers/mtd/nand/spi/gigadevice.c
@@ -20,8 +20,8 @@  Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
 +++ b/drivers/mtd/nand/spi/Makefile
 @@ -1,3 +1,3 @@
  # SPDX-License-Identifier: GPL-2.0
--spinand-objs := core.o macronix.o micron.o winbond.o
-+spinand-objs := core.o gigadevice.o macronix.o micron.o winbond.o
+-spinand-objs := core.o macronix.o micron.o toshiba.o winbond.o
++spinand-objs := core.o gigadevice.o macronix.o micron.o toshiba.o winbond.o
  obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
 --- a/drivers/mtd/nand/spi/core.c
 +++ b/drivers/mtd/nand/spi/core.c
@@ -32,7 +32,7 @@  Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
 +	&gigadevice_spinand_manufacturer,
  	&macronix_spinand_manufacturer,
  	&micron_spinand_manufacturer,
- 	&winbond_spinand_manufacturer,
+ 	&toshiba_spinand_manufacturer,
 --- /dev/null
 +++ b/drivers/mtd/nand/spi/gigadevice.c
 @@ -0,0 +1,148 @@
@@ -193,4 +193,4 @@  Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
 +extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
  extern const struct spinand_manufacturer macronix_spinand_manufacturer;
  extern const struct spinand_manufacturer micron_spinand_manufacturer;
- extern const struct spinand_manufacturer winbond_spinand_manufacturer;
+ extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
diff --git a/target/linux/generic/backport-4.19/426-v5.1-mtd-spinand-macronix-Fix-ECC-Status-Read.patch b/target/linux/generic/backport-4.19/426-v5.1-mtd-spinand-macronix-Fix-ECC-Status-Read.patch
new file mode 100644
index 0000000000..3f1e24a01c
--- /dev/null
+++ b/target/linux/generic/backport-4.19/426-v5.1-mtd-spinand-macronix-Fix-ECC-Status-Read.patch
@@ -0,0 +1,44 @@ 
+From f4cb4d7b46f6409382fd981eec9556e1f3c1dc5d Mon Sep 17 00:00:00 2001
+From: Emil Lenngren <emil.lenngren@gmail.com>
+Date: Thu, 20 Dec 2018 13:46:58 +0100
+Subject: [PATCH 6/8] mtd: spinand: macronix: Fix ECC Status Read
+
+The datasheet specifies the upper four bits are reserved.
+Testing on real hardware shows that these bits can indeed be nonzero.
+
+Signed-off-by: Emil Lenngren <emil.lenngren@gmail.com>
+Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>
+Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
+---
+ drivers/mtd/nand/spi/macronix.c | 8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
+index 98f6b9c4b684..d16b57081c95 100644
+--- a/drivers/mtd/nand/spi/macronix.c
++++ b/drivers/mtd/nand/spi/macronix.c
+@@ -10,6 +10,7 @@
+ #include <linux/mtd/spinand.h>
+ 
+ #define SPINAND_MFR_MACRONIX		0xC2
++#define MACRONIX_ECCSR_MASK		0x0F
+ 
+ static SPINAND_OP_VARIANTS(read_cache_variants,
+ 		SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+@@ -55,7 +56,12 @@ static int mx35lf1ge4ab_get_eccsr(struct spinand_device *spinand, u8 *eccsr)
+ 					  SPI_MEM_OP_DUMMY(1, 1),
+ 					  SPI_MEM_OP_DATA_IN(1, eccsr, 1));
+ 
+-	return spi_mem_exec_op(spinand->spimem, &op);
++	int ret = spi_mem_exec_op(spinand->spimem, &op);
++	if (ret)
++		return ret;
++
++	*eccsr &= MACRONIX_ECCSR_MASK;
++	return 0;
+ }
+ 
+ static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand,
+-- 
+2.20.1
+
diff --git a/target/linux/generic/backport-4.19/427-v5.1-mtd-spinand-Add-support-for-all-Toshiba-Memory-produ.patch b/target/linux/generic/backport-4.19/427-v5.1-mtd-spinand-Add-support-for-all-Toshiba-Memory-produ.patch
new file mode 100644
index 0000000000..d762de4271
--- /dev/null
+++ b/target/linux/generic/backport-4.19/427-v5.1-mtd-spinand-Add-support-for-all-Toshiba-Memory-produ.patch
@@ -0,0 +1,141 @@ 
+From db214513f62fd13c0a9af3bd5c5d634dba37e65d Mon Sep 17 00:00:00 2001
+From: Yoshio Furuyama <tmcmc-mb-yfuruyama7@ml.toshiba.co.jp>
+Date: Wed, 16 Jan 2019 14:53:19 +0900
+Subject: [PATCH 7/8] mtd: spinand: Add support for all Toshiba Memory products
+
+Add device table for Toshiba Memory products.
+Also, generalize OOB layout structure and function names.
+
+Signed-off-by: Yoshio Furuyama <tmcmc-mb-yfuruyama7@ml.toshiba.co.jp>
+Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
+Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
+---
+ drivers/mtd/nand/spi/toshiba.c | 79 ++++++++++++++++++++++++++++------
+ 1 file changed, 65 insertions(+), 14 deletions(-)
+
+diff --git a/drivers/mtd/nand/spi/toshiba.c b/drivers/mtd/nand/spi/toshiba.c
+index 081265557e70..db8021da45b5 100644
+--- a/drivers/mtd/nand/spi/toshiba.c
++++ b/drivers/mtd/nand/spi/toshiba.c
+@@ -25,19 +25,19 @@ static SPINAND_OP_VARIANTS(write_cache_variants,
+ static SPINAND_OP_VARIANTS(update_cache_variants,
+ 		SPINAND_PROG_LOAD(false, 0, NULL, 0));
+ 
+-static int tc58cvg2s0h_ooblayout_ecc(struct mtd_info *mtd, int section,
++static int tc58cxgxsx_ooblayout_ecc(struct mtd_info *mtd, int section,
+ 				     struct mtd_oob_region *region)
+ {
+-	if (section > 7)
++	if (section > 0)
+ 		return -ERANGE;
+ 
+-	region->offset = 128 + 16 * section;
+-	region->length = 16;
++	region->offset = mtd->oobsize / 2;
++	region->length = mtd->oobsize / 2;
+ 
+ 	return 0;
+ }
+ 
+-static int tc58cvg2s0h_ooblayout_free(struct mtd_info *mtd, int section,
++static int tc58cxgxsx_ooblayout_free(struct mtd_info *mtd, int section,
+ 				      struct mtd_oob_region *region)
+ {
+ 	if (section > 0)
+@@ -45,17 +45,17 @@ static int tc58cvg2s0h_ooblayout_free(struct mtd_info *mtd, int section,
+ 
+ 	/* 2 bytes reserved for BBM */
+ 	region->offset = 2;
+-	region->length = 126;
++	region->length = (mtd->oobsize / 2) - 2;
+ 
+ 	return 0;
+ }
+ 
+-static const struct mtd_ooblayout_ops tc58cvg2s0h_ooblayout = {
+-	.ecc = tc58cvg2s0h_ooblayout_ecc,
+-	.free = tc58cvg2s0h_ooblayout_free,
++static const struct mtd_ooblayout_ops tc58cxgxsx_ooblayout = {
++	.ecc = tc58cxgxsx_ooblayout_ecc,
++	.free = tc58cxgxsx_ooblayout_free,
+ };
+ 
+-static int tc58cvg2s0h_ecc_get_status(struct spinand_device *spinand,
++static int tc58cxgxsx_ecc_get_status(struct spinand_device *spinand,
+ 				      u8 status)
+ {
+ 	struct nand_device *nand = spinand_to_nand(spinand);
+@@ -94,15 +94,66 @@ static int tc58cvg2s0h_ecc_get_status(struct spinand_device *spinand,
+ }
+ 
+ static const struct spinand_info toshiba_spinand_table[] = {
+-	SPINAND_INFO("TC58CVG2S0H", 0xCD,
++	/* 3.3V 1Gb */
++	SPINAND_INFO("TC58CVG0S3", 0xC2,
++		     NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
++		     NAND_ECCREQ(8, 512),
++		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
++					      &write_cache_variants,
++					      &update_cache_variants),
++		     0,
++		     SPINAND_ECCINFO(&tc58cxgxsx_ooblayout,
++				     tc58cxgxsx_ecc_get_status)),
++	/* 3.3V 2Gb */
++	SPINAND_INFO("TC58CVG1S3", 0xCB,
++		     NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
++		     NAND_ECCREQ(8, 512),
++		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
++					      &write_cache_variants,
++					      &update_cache_variants),
++		     0,
++		     SPINAND_ECCINFO(&tc58cxgxsx_ooblayout,
++				     tc58cxgxsx_ecc_get_status)),
++	/* 3.3V 4Gb */
++	SPINAND_INFO("TC58CVG2S0", 0xCD,
++		     NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
++		     NAND_ECCREQ(8, 512),
++		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
++					      &write_cache_variants,
++					      &update_cache_variants),
++		     0,
++		     SPINAND_ECCINFO(&tc58cxgxsx_ooblayout,
++				     tc58cxgxsx_ecc_get_status)),
++	/* 1.8V 1Gb */
++	SPINAND_INFO("TC58CYG0S3", 0xB2,
++		     NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
++		     NAND_ECCREQ(8, 512),
++		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
++					      &write_cache_variants,
++					      &update_cache_variants),
++		     0,
++		     SPINAND_ECCINFO(&tc58cxgxsx_ooblayout,
++				     tc58cxgxsx_ecc_get_status)),
++	/* 1.8V 2Gb */
++	SPINAND_INFO("TC58CYG1S3", 0xBB,
++		     NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
++		     NAND_ECCREQ(8, 512),
++		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
++					      &write_cache_variants,
++					      &update_cache_variants),
++		     0,
++		     SPINAND_ECCINFO(&tc58cxgxsx_ooblayout,
++				     tc58cxgxsx_ecc_get_status)),
++	/* 1.8V 4Gb */
++	SPINAND_INFO("TC58CYG2S0", 0xBD,
+ 		     NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1),
+ 		     NAND_ECCREQ(8, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+ 					      &write_cache_variants,
+ 					      &update_cache_variants),
+-		     SPINAND_HAS_QE_BIT,
+-		     SPINAND_ECCINFO(&tc58cvg2s0h_ooblayout,
+-				     tc58cvg2s0h_ecc_get_status)),
++		     0,
++		     SPINAND_ECCINFO(&tc58cxgxsx_ooblayout,
++				     tc58cxgxsx_ecc_get_status)),
+ };
+ 
+ static int toshiba_spinand_detect(struct spinand_device *spinand)
+-- 
+2.20.1
+
diff --git a/target/linux/generic/backport-4.19/451-v5.1-mtd-spinand-Add-support-for-GigaDevice-GD5F1GQ4UExxG.patch b/target/linux/generic/backport-4.19/428-v5.1-mtd-spinand-Add-support-for-GigaDevice-GD5F1GQ4UExxG.patch
similarity index 89%
rename from target/linux/generic/backport-4.19/451-v5.1-mtd-spinand-Add-support-for-GigaDevice-GD5F1GQ4UExxG.patch
rename to target/linux/generic/backport-4.19/428-v5.1-mtd-spinand-Add-support-for-GigaDevice-GD5F1GQ4UExxG.patch
index f6d6764707..36cfab671e 100644
--- a/target/linux/generic/backport-4.19/451-v5.1-mtd-spinand-Add-support-for-GigaDevice-GD5F1GQ4UExxG.patch
+++ b/target/linux/generic/backport-4.19/428-v5.1-mtd-spinand-Add-support-for-GigaDevice-GD5F1GQ4UExxG.patch
@@ -1,7 +1,7 @@ 
 From c40c7a990a46e5102a1cc4190557bf315d32d80d Mon Sep 17 00:00:00 2001
 From: Stefan Roese <sr@denx.de>
 Date: Thu, 24 Jan 2019 13:48:06 +0100
-Subject: [PATCH] mtd: spinand: Add support for GigaDevice GD5F1GQ4UExxG
+Subject: [PATCH 8/8] mtd: spinand: Add support for GigaDevice GD5F1GQ4UExxG
 
 Add support for GigaDevice GD5F1GQ4UExxG SPI NAND chip.
 
@@ -13,9 +13,11 @@  Cc: Boris Brezillon <bbrezillon@kernel.org>
 Reviewed-by: Boris Brezillon <bbrezillon@kernel.org>
 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
 ---
- drivers/mtd/nand/spi/gigadevice.c | 83 +++++++++++++++++++++++++++++++++++++++
+ drivers/mtd/nand/spi/gigadevice.c | 83 +++++++++++++++++++++++++++++++
  1 file changed, 83 insertions(+)
 
+diff --git a/drivers/mtd/nand/spi/gigadevice.c b/drivers/mtd/nand/spi/gigadevice.c
+index e4141c20947a..0b49d8264bef 100644
 --- a/drivers/mtd/nand/spi/gigadevice.c
 +++ b/drivers/mtd/nand/spi/gigadevice.c
 @@ -12,6 +12,8 @@
@@ -27,7 +29,7 @@  Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
  static SPINAND_OP_VARIANTS(read_cache_variants,
  		SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
  		SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
-@@ -81,11 +83,83 @@ static int gd5fxgq4xa_ecc_get_status(str
+@@ -81,11 +83,83 @@ static int gd5fxgq4xa_ecc_get_status(struct spinand_device *spinand,
  	return -EINVAL;
  }
  
@@ -111,7 +113,7 @@  Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
  static const struct spinand_info gigadevice_spinand_table[] = {
  	SPINAND_INFO("GD5F1GQ4xA", 0xF1,
  		     NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
-@@ -114,6 +188,15 @@ static const struct spinand_info gigadev
+@@ -114,6 +188,15 @@ static const struct spinand_info gigadevice_spinand_table[] = {
  		     0,
  		     SPINAND_ECCINFO(&gd5fxgq4xa_ooblayout,
  				     gd5fxgq4xa_ecc_get_status)),
@@ -127,3 +129,6 @@  Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
  };
  
  static int gigadevice_spinand_detect(struct spinand_device *spinand)
+-- 
+2.20.1
+