mtd: rawnand: Use nanddev_mtd_max_bad_blocks()
authorBoris Brezillon <bbrezillon@kernel.org>
Sun, 4 Nov 2018 13:50:28 +0000 (14:50 +0100)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 8 Apr 2019 08:21:14 +0000 (10:21 +0200)
nanddev_mtd_max_bad_blocks() is implemented by the generic NAND layer
and is already doing what we need. Reuse this function instead of
having our own implementation.

While at it, get rid of the ->max_bb_per_die and ->blocks_per_die
fields which are now unused.

Signed-off-by: Boris Brezillon <bbrezillon@kernel.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
drivers/mtd/nand/raw/nand_base.c
drivers/mtd/nand/raw/nand_onfi.c
include/linux/mtd/rawnand.h

index 26aeea06035b97d71ba277b9edbe40e6994bd67d..035b9cf327a6f3e8b0ee3d2ebee03ffdcbba96b5 100644 (file)
@@ -4297,42 +4297,6 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
        return nand_block_markbad_lowlevel(mtd_to_nand(mtd), ofs);
 }
 
-/**
- * nand_max_bad_blocks - [MTD Interface] Max number of bad blocks for an mtd
- * @mtd: MTD device structure
- * @ofs: offset relative to mtd start
- * @len: length of mtd
- */
-static int nand_max_bad_blocks(struct mtd_info *mtd, loff_t ofs, size_t len)
-{
-       struct nand_chip *chip = mtd_to_nand(mtd);
-       u32 part_start_block;
-       u32 part_end_block;
-       u32 part_start_die;
-       u32 part_end_die;
-
-       /*
-        * max_bb_per_die and blocks_per_die used to determine
-        * the maximum bad block count.
-        */
-       if (!chip->max_bb_per_die || !chip->blocks_per_die)
-               return -ENOTSUPP;
-
-       /* Get the start and end of the partition in erase blocks. */
-       part_start_block = mtd_div_by_eb(ofs, mtd);
-       part_end_block = mtd_div_by_eb(len, mtd) + part_start_block - 1;
-
-       /* Get the start and end LUNs of the partition. */
-       part_start_die = part_start_block / chip->blocks_per_die;
-       part_end_die = part_end_block / chip->blocks_per_die;
-
-       /*
-        * Look up the bad blocks per unit and multiply by the number of units
-        * that the partition spans.
-        */
-       return chip->max_bb_per_die * (part_end_die - part_start_die + 1);
-}
-
 /**
  * nand_suspend - [MTD Interface] Suspend the NAND flash
  * @mtd: MTD device structure
@@ -5819,7 +5783,7 @@ static int nand_scan_tail(struct nand_chip *chip)
        mtd->_block_isreserved = nand_block_isreserved;
        mtd->_block_isbad = nand_block_isbad;
        mtd->_block_markbad = nand_block_markbad;
-       mtd->_max_bad_blocks = nand_max_bad_blocks;
+       mtd->_max_bad_blocks = nanddev_mtd_max_bad_blocks;
 
        /*
         * Initialize bitflip_threshold to its default prior scan_bbt() call.
index f3f59cf37d7f4f8e77e05513b5566358ce5e1e29..3ca9c8923a309c5e7a4642c23833ec7e11663f34 100644 (file)
@@ -251,9 +251,6 @@ int nand_onfi_detect(struct nand_chip *chip)
        memorg->bits_per_cell = p->bits_per_cell;
        chip->bits_per_cell = p->bits_per_cell;
 
-       chip->max_bb_per_die = le16_to_cpu(p->bb_per_lun);
-       chip->blocks_per_die = le32_to_cpu(p->blocks_per_lun);
-
        if (le16_to_cpu(p->features) & ONFI_FEATURE_16_BIT_BUS)
                chip->options |= NAND_BUSWIDTH_16;
 
index 99250dc848e8536716b230f759be521d29796788..9d0cdae4e2040516d710fcf7fd481fdfd650a97f 100644 (file)
@@ -1015,9 +1015,6 @@ struct nand_legacy {
  * @id:                        [INTERN] holds NAND ID
  * @parameters:                [INTERN] holds generic parameters under an easily
  *                     readable form.
- * @max_bb_per_die:    [INTERN] the max number of bad blocks each die of a
- *                     this nand device will encounter their life times.
- * @blocks_per_die:    [INTERN] The number of PEBs in a die
  * @data_interface:    [INTERN] NAND interface timing information
  * @cur_cs:            currently selected target. -1 means no target selected,
  *                     otherwise we should always have cur_cs >= 0 &&
@@ -1076,8 +1073,6 @@ struct nand_chip {
 
        struct nand_id id;
        struct nand_parameters parameters;
-       u16 max_bb_per_die;
-       u32 blocks_per_die;
 
        struct nand_data_interface data_interface;