[PATCH v2 2/2] Fix the issue for clearing status process

2021-04-05 Thread Yoshio Furuyama
In the unlikely event of bad block,
it should update its block status to BBT, 
In this case, there are 2 kind of issue for handling
a) Mark bad block status to BBT:  It was fixed by Patric's patch
b) Clear status to BBT:  I posted patch for this issue 

Patch:
Issue of handing BBT (Bad Block Table) for 
some particular blocks (Ex:10, 11)
Updating status is, first clear status, second set bad block status.
Patrick's patch is only fixed the issue for setting status process,
so this patch fix the clearing status process.

Signed-off-by: Yoshio Furuyama 
---
 drivers/mtd/nand/bbt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
index 64af6898131d..0780896eaafe 100644
--- a/drivers/mtd/nand/bbt.c
+++ b/drivers/mtd/nand/bbt.c
@@ -112,11 +112,13 @@ int nanddev_bbt_set_block_status(struct nand_device 
*nand, unsigned int entry,
 ((entry * bits_per_block) / BITS_PER_LONG);
unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
unsigned long val = status & GENMASK(bits_per_block - 1, 0);
+   unsigned long shift = ((bits_per_block + offs <= BITS_PER_LONG) ?
+   (offs + bits_per_block - 1) : 
(BITS_PER_LONG - 1));
 
if (entry >= nanddev_neraseblocks(nand))
return -ERANGE;
 
-   pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs);
+   pos[0] &= ~GENMASK(shift, offs);
pos[0] |= val << offs;
 
if (bits_per_block + offs > BITS_PER_LONG) {
-- 
2.25.1



[PATCH v2 1/2] Fix corner case in bad block table handling.

2021-04-05 Thread Yoshio Furuyama
From: "Doyle, Patrick" 

In the unlikely event that both blocks 10 and 11 are marked as bad (on a
32 bit machine), then the process of marking block 10 as bad stomps on
cached entry for block 11.  There are (of course) other examples.

Signed-off-by: Patrick Doyle 
Reviewed-by: Richard Weinberger 
---
 drivers/mtd/nand/bbt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
index 044adf913854..64af6898131d 100644
--- a/drivers/mtd/nand/bbt.c
+++ b/drivers/mtd/nand/bbt.c
@@ -123,7 +123,7 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, 
unsigned int entry,
unsigned int rbits = bits_per_block + offs - BITS_PER_LONG;
 
pos[1] &= ~GENMASK(rbits - 1, 0);
-   pos[1] |= val >> rbits;
+   pos[1] |= val >> (bits_per_block - rbits);
}
 
return 0;
-- 
2.25.1



[PATCH v2 0/2] Fix corner case in bad block table handling.

2021-04-05 Thread Yoshio Furuyama
Doyle, Patrick (1):
  Fix corner case in bad block table handling.

Yoshio Furuyama (1):
  Fix the issue for clearing status process

 drivers/mtd/nand/bbt.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

-- 
2.25.1



[no subject]

2021-02-15 Thread Yoshio Furuyama
>From Yoshio Furuyama # This line is ignored.
From: Yoshio Furuyama
Subject: 
In-Reply-To: 



[PATCH v1] mtd: nand: Fix BBT update issue

2021-02-15 Thread Yoshio Furuyama
Fixed issue of manages BBT (Bad Block Table).
It didn't mark correctly when a specific block was bad block.

This issue occurs when the bad block mark (3-bit chunk) is 
crosses over 32 bit (e.g. Block10, Block21...) unit.

Signed-off-by: Yoshio Furuyama 
---
 drivers/mtd/nand/bbt.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c
index 044adf913854..979c47e61381 100644
--- a/drivers/mtd/nand/bbt.c
+++ b/drivers/mtd/nand/bbt.c
@@ -112,18 +112,20 @@ int nanddev_bbt_set_block_status(struct nand_device 
*nand, unsigned int entry,
 ((entry * bits_per_block) / BITS_PER_LONG);
unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG;
unsigned long val = status & GENMASK(bits_per_block - 1, 0);
+   unsigned long shift = ((bits_per_block + offs <= BITS_PER_LONG) ?
+   (offs + bits_per_block - 1) : 
(BITS_PER_LONG - 1));
 
if (entry >= nanddev_neraseblocks(nand))
return -ERANGE;
 
-   pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs);
+   pos[0] &= ~GENMASK(shift, offs);
pos[0] |= val << offs;
 
if (bits_per_block + offs > BITS_PER_LONG) {
unsigned int rbits = bits_per_block + offs - BITS_PER_LONG;
 
pos[1] &= ~GENMASK(rbits - 1, 0);
-   pos[1] |= val >> rbits;
+   pos[1] |= (val >> (BITS_PER_LONG - offs));
}
 
return 0;
-- 
2.25.1


[PATCH] mtd: spinand: Add support for all Toshiba Memory products

2019-01-15 Thread Yoshio Furuyama
Add device table for Toshiba Memory products.
Also, generalize OOB layout structure and function names.

Signed-off-by: Yoshio Furuyama 

---
 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 0812655..0916962 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(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+0,
+SPINAND_ECCINFO(_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(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+0,
+SPINAND_ECCINFO(_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(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+0,
+SPINAND_ECCINFO(_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(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+0,
+SPINAND_ECCINFO(_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(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+0,
+SPINAND_ECCINFO(_ooblayout,
+tc58cxgxsx_ecc_get_status)),