Skip to content

Commit

Permalink
mtd: nand: Make flags for bad block marker position more granular
Browse files Browse the repository at this point in the history
To be able to check and set bad block markers in the first and
second page of a block independently of each other, we create
separate flags for both cases.

Previously NAND_BBM_SECONDPAGE meant, that both, the first and the
second page were used. With this patch NAND_BBM_FIRSTPAGE stands for
using the first page and NAND_BBM_SECONDPAGE for using the second
page.

This patch is only for preparation of subsequent changes and does
not implement the logic to actually handle both flags separately.

Signed-off-by: Frieder Schrempf <[email protected]>
Reviewed-by: Boris Brezillon <[email protected]>
Reviewed-by: Miquel Raynal <[email protected]>
Signed-off-by: Miquel Raynal <[email protected]>
  • Loading branch information
fschrempf authored and miquelraynal committed Apr 18, 2019
1 parent c902467 commit bb59254
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/nand_amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void amd_nand_decode_id(struct nand_chip *chip)
static int amd_nand_init(struct nand_chip *chip)
{
if (nand_is_slc(chip))
chip->options |= NAND_BBM_SECONDPAGE;
chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;

return 0;
}
Expand Down
6 changes: 4 additions & 2 deletions drivers/mtd/nand/raw/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ static int nand_block_bad(struct nand_chip *chip, loff_t ofs)
ofs += mtd->erasesize - mtd->writesize;

page = (int)(ofs >> chip->page_shift) & chip->pagemask;
page_end = page + ((chip->options & NAND_BBM_SECONDPAGE) ? 2 : 1);
page_end = page + (((chip->options & NAND_BBM_FIRSTPAGE) &&
(chip->options & NAND_BBM_SECONDPAGE)) ? 2 : 1);

for (; page < page_end; page++) {
res = chip->ecc.read_oob(chip, page);
Expand Down Expand Up @@ -516,7 +517,8 @@ static int nand_default_block_markbad(struct nand_chip *chip, loff_t ofs)

i++;
ofs += mtd->writesize;
} while ((chip->options & NAND_BBM_SECONDPAGE) && i < 2);
} while ((chip->options & NAND_BBM_FIRSTPAGE) &&
(chip->options & NAND_BBM_SECONDPAGE) && i < 2);

return ret;
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/mtd/nand/raw/nand_bbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ static int create_bbt(struct nand_chip *this, uint8_t *buf,

pr_info("Scanning device for bad blocks\n");

if (this->options & NAND_BBM_SECONDPAGE)
if ((this->options & NAND_BBM_FIRSTPAGE) &&
(this->options & NAND_BBM_SECONDPAGE))
numpages = 2;
else
numpages = 1;
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/nand_esmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void esmt_nand_decode_id(struct nand_chip *chip)
static int esmt_nand_init(struct nand_chip *chip)
{
if (nand_is_slc(chip))
chip->options |= NAND_BBM_SECONDPAGE;
chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/nand_hynix.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ static int hynix_nand_init(struct nand_chip *chip)
if (!nand_is_slc(chip))
chip->options |= NAND_BBM_LASTPAGE;
else
chip->options |= NAND_BBM_SECONDPAGE;
chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;

hynix = kzalloc(sizeof(*hynix), GFP_KERNEL);
if (!hynix)
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/nand_macronix.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
static int macronix_nand_init(struct nand_chip *chip)
{
if (nand_is_slc(chip))
chip->options |= NAND_BBM_SECONDPAGE;
chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;

macronix_nand_fix_broken_get_timings(chip);

Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/nand_micron.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ static int micron_nand_init(struct nand_chip *chip)
goto err_free_manuf_data;

if (mtd->writesize == 2048)
chip->options |= NAND_BBM_SECONDPAGE;
chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;

ondie = micron_supports_on_die_ecc(chip);

Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/nand_samsung.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static int samsung_nand_init(struct nand_chip *chip)
if (!nand_is_slc(chip))
chip->options |= NAND_BBM_LASTPAGE;
else
chip->options |= NAND_BBM_SECONDPAGE;
chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/nand_toshiba.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void toshiba_nand_decode_id(struct nand_chip *chip)
static int toshiba_nand_init(struct nand_chip *chip)
{
if (nand_is_slc(chip))
chip->options |= NAND_BBM_SECONDPAGE;
chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;

/* Check that chip is BENAND and ECC mode is on-die */
if (nand_is_slc(chip) && chip->ecc.mode == NAND_ECC_ON_DIE &&
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/nand/raw/sh_flctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ static int flctl_probe(struct platform_device *pdev)
if (pdata->flcmncr_val & SEL_16BIT)
nand->options |= NAND_BUSWIDTH_16;

nand->options |= NAND_BBM_SECONDPAGE;
nand->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;

pm_runtime_enable(&pdev->dev);
pm_runtime_resume(&pdev->dev);
Expand Down
1 change: 1 addition & 0 deletions include/linux/mtd/rawnand.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ enum nand_ecc_algo {
* Position within the block: Each of these pages needs to be checked for a
* bad block marking pattern.
*/
#define NAND_BBM_FIRSTPAGE 0x01000000
#define NAND_BBM_SECONDPAGE 0x02000000
#define NAND_BBM_LASTPAGE 0x04000000

Expand Down

0 comments on commit bb59254

Please sign in to comment.