Skip to content

Commit 6c836d5

Browse files
bbrezillonmiquelraynal
authored andcommitted
mtd: rawnand: Get rid of chip->chipsize
The target size can now be returned by nanddev_get_targetsize(). Get rid of the chip->chipsize field and use this helper instead. Signed-off-by: Boris Brezillon <bbrezillon@kernel.org> Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 2981516 commit 6c836d5

File tree

13 files changed

+38
-36
lines changed

13 files changed

+38
-36
lines changed

drivers/mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n)
428428
}
429429

430430
/* Configure FLASH */
431-
chipsize = b47n->nand_chip.chipsize >> 20;
431+
chipsize = nanddev_target_size(&b47n->nand_chip.base) >> 20;
432432
tbits = ffs(chipsize); /* find first bit set */
433433
if (!tbits || tbits != fls(chipsize)) {
434434
pr_err("Invalid flash size: 0x%lX\n", chipsize);

drivers/mtd/nand/raw/denali.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,6 @@ static int denali_multidev_fixup(struct denali_nand_info *denali)
11341134
mtd->erasesize <<= 1;
11351135
mtd->writesize <<= 1;
11361136
mtd->oobsize <<= 1;
1137-
chip->chipsize <<= 1;
11381137
chip->page_shift += 1;
11391138
chip->phys_erase_shift += 1;
11401139
chip->bbt_erase_shift += 1;

drivers/mtd/nand/raw/fsl_elbc_nand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ static int fsl_elbc_attach_chip(struct nand_chip *chip)
655655
dev_dbg(priv->dev, "fsl_elbc_init: nand->numchips = %d\n",
656656
chip->numchips);
657657
dev_dbg(priv->dev, "fsl_elbc_init: nand->chipsize = %lld\n",
658-
chip->chipsize);
658+
nanddev_target_size(&chip->base));
659659
dev_dbg(priv->dev, "fsl_elbc_init: nand->pagemask = %8x\n",
660660
chip->pagemask);
661661
dev_dbg(priv->dev, "fsl_elbc_init: nand->legacy.chip_delay = %d\n",

drivers/mtd/nand/raw/fsl_ifc_nand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ static int fsl_ifc_attach_chip(struct nand_chip *chip)
724724
dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__,
725725
chip->numchips);
726726
dev_dbg(priv->dev, "%s: nand->chipsize = %lld\n", __func__,
727-
chip->chipsize);
727+
nanddev_target_size(&chip->base));
728728
dev_dbg(priv->dev, "%s: nand->pagemask = %8x\n", __func__,
729729
chip->pagemask);
730730
dev_dbg(priv->dev, "%s: nand->legacy.chip_delay = %d\n", __func__,

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ static int mx23_boot_init(struct gpmi_nand_data *this)
17531753
dev_dbg(dev, "Transcribing bad block marks...\n");
17541754

17551755
/* Compute the number of blocks in the entire medium. */
1756-
block_count = chip->chipsize >> chip->phys_erase_shift;
1756+
block_count = nanddev_eraseblocks_per_target(&chip->base);
17571757

17581758
/*
17591759
* Loop over all the blocks in the medium, transcribing block marks as

drivers/mtd/nand/raw/ingenic/jz4740_nand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static int jz_nand_detect_bank(struct platform_device *pdev,
356356
/* Update size of the MTD. */
357357
chip->numchips++;
358358
memorg->ntargets++;
359-
mtd->size += chip->chipsize;
359+
mtd->size += nanddev_target_size(&chip->base);
360360
}
361361

362362
dev_info(&pdev->dev, "Found chip %zu on bank %i\n", chipnr, bank);

drivers/mtd/nand/raw/nand_base.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4542,7 +4542,6 @@ static bool find_full_id_nand(struct nand_chip *chip,
45424542
mtd->oobsize = memorg->oobsize;
45434543

45444544
memorg->bits_per_cell = nand_get_bits_per_cell(id_data[2]);
4545-
chip->chipsize = (uint64_t)type->chipsize << 20;
45464545
memorg->eraseblocks_per_lun =
45474546
DIV_ROUND_DOWN_ULL((u64)type->chipsize << 20,
45484547
memorg->pagesize *
@@ -4633,6 +4632,7 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
46334632
int busw, ret;
46344633
u8 *id_data = chip->id.data;
46354634
u8 maf_id, dev_id;
4635+
u64 targetsize;
46364636

46374637
/*
46384638
* Let's start by initializing memorg fields that might be left
@@ -4737,8 +4737,6 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
47374737
if (!chip->parameters.model)
47384738
return -ENOMEM;
47394739

4740-
chip->chipsize = (uint64_t)type->chipsize << 20;
4741-
47424740
if (!type->pagesize)
47434741
nand_manufacturer_detect(chip);
47444742
else
@@ -4780,14 +4778,15 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
47804778
/* Calculate the address shift from the page size */
47814779
chip->page_shift = ffs(mtd->writesize) - 1;
47824780
/* Convert chipsize to number of pages per chip -1 */
4783-
chip->pagemask = (chip->chipsize >> chip->page_shift) - 1;
4781+
targetsize = nanddev_target_size(&chip->base);
4782+
chip->pagemask = (targetsize >> chip->page_shift) - 1;
47844783

47854784
chip->bbt_erase_shift = chip->phys_erase_shift =
47864785
ffs(mtd->erasesize) - 1;
4787-
if (chip->chipsize & 0xffffffff)
4788-
chip->chip_shift = ffs((unsigned)chip->chipsize) - 1;
4786+
if (targetsize & 0xffffffff)
4787+
chip->chip_shift = ffs((unsigned)targetsize) - 1;
47894788
else {
4790-
chip->chip_shift = ffs((unsigned)(chip->chipsize >> 32));
4789+
chip->chip_shift = ffs((unsigned)(targetsize >> 32));
47914790
chip->chip_shift += 32 - 1;
47924791
}
47934792

@@ -4803,7 +4802,7 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
48034802
pr_info("%s %s\n", nand_manufacturer_name(manufacturer),
48044803
chip->parameters.model);
48054804
pr_info("%d MiB, %s, erase size: %d KiB, page size: %d, OOB size: %d\n",
4806-
(int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC",
4805+
(int)(targetsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC",
48074806
mtd->erasesize >> 10, mtd->writesize, mtd->oobsize);
48084807
return 0;
48094808

@@ -5054,7 +5053,7 @@ static int nand_scan_ident(struct nand_chip *chip, unsigned int maxchips,
50545053
/* Store the number of chips and calc total size for mtd */
50555054
memorg->ntargets = i;
50565055
chip->numchips = i;
5057-
mtd->size = i * chip->chipsize;
5056+
mtd->size = i * nanddev_target_size(&chip->base);
50585057

50595058
return 0;
50605059
}

drivers/mtd/nand/raw/nand_bbt.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,19 @@ static int read_abs_bbt(struct nand_chip *this, uint8_t *buf,
264264
struct nand_bbt_descr *td, int chip)
265265
{
266266
struct mtd_info *mtd = nand_to_mtd(this);
267+
u64 targetsize = nanddev_target_size(&this->base);
267268
int res = 0, i;
268269

269270
if (td->options & NAND_BBT_PERCHIP) {
270271
int offs = 0;
271272
for (i = 0; i < this->numchips; i++) {
272273
if (chip == -1 || chip == i)
273274
res = read_bbt(this, buf, td->pages[i],
274-
this->chipsize >> this->bbt_erase_shift,
275+
targetsize >> this->bbt_erase_shift,
275276
td, offs);
276277
if (res)
277278
return res;
278-
offs += this->chipsize >> this->bbt_erase_shift;
279+
offs += targetsize >> this->bbt_erase_shift;
279280
}
280281
} else {
281282
res = read_bbt(this, buf, td->pages[0],
@@ -459,6 +460,7 @@ static int scan_block_fast(struct nand_chip *this, struct nand_bbt_descr *bd,
459460
static int create_bbt(struct nand_chip *this, uint8_t *buf,
460461
struct nand_bbt_descr *bd, int chip)
461462
{
463+
u64 targetsize = nanddev_target_size(&this->base);
462464
struct mtd_info *mtd = nand_to_mtd(this);
463465
int i, numblocks, numpages;
464466
int startblock;
@@ -481,7 +483,7 @@ static int create_bbt(struct nand_chip *this, uint8_t *buf,
481483
chip + 1, this->numchips);
482484
return -EINVAL;
483485
}
484-
numblocks = this->chipsize >> this->bbt_erase_shift;
486+
numblocks = targetsize >> this->bbt_erase_shift;
485487
startblock = chip * numblocks;
486488
numblocks += startblock;
487489
from = (loff_t)startblock << this->bbt_erase_shift;
@@ -529,6 +531,7 @@ static int create_bbt(struct nand_chip *this, uint8_t *buf,
529531
static int search_bbt(struct nand_chip *this, uint8_t *buf,
530532
struct nand_bbt_descr *td)
531533
{
534+
u64 targetsize = nanddev_target_size(&this->base);
532535
struct mtd_info *mtd = nand_to_mtd(this);
533536
int i, chips;
534537
int startblock, block, dir;
@@ -548,7 +551,7 @@ static int search_bbt(struct nand_chip *this, uint8_t *buf,
548551
/* Do we have a bbt per chip? */
549552
if (td->options & NAND_BBT_PERCHIP) {
550553
chips = this->numchips;
551-
bbtblocks = this->chipsize >> this->bbt_erase_shift;
554+
bbtblocks = targetsize >> this->bbt_erase_shift;
552555
startblock &= bbtblocks - 1;
553556
} else {
554557
chips = 1;
@@ -576,7 +579,7 @@ static int search_bbt(struct nand_chip *this, uint8_t *buf,
576579
break;
577580
}
578581
}
579-
startblock += this->chipsize >> this->bbt_erase_shift;
582+
startblock += targetsize >> this->bbt_erase_shift;
580583
}
581584
/* Check, if we found a bbt for each requested chip */
582585
for (i = 0; i < chips; i++) {
@@ -626,6 +629,7 @@ static void search_read_bbts(struct nand_chip *this, uint8_t *buf,
626629
static int get_bbt_block(struct nand_chip *this, struct nand_bbt_descr *td,
627630
struct nand_bbt_descr *md, int chip)
628631
{
632+
u64 targetsize = nanddev_target_size(&this->base);
629633
int startblock, dir, page, numblocks, i;
630634

631635
/*
@@ -637,7 +641,7 @@ static int get_bbt_block(struct nand_chip *this, struct nand_bbt_descr *td,
637641
return td->pages[chip] >>
638642
(this->bbt_erase_shift - this->page_shift);
639643

640-
numblocks = (int)(this->chipsize >> this->bbt_erase_shift);
644+
numblocks = (int)(targetsize >> this->bbt_erase_shift);
641645
if (!(td->options & NAND_BBT_PERCHIP))
642646
numblocks *= this->numchips;
643647

@@ -717,6 +721,7 @@ static int write_bbt(struct nand_chip *this, uint8_t *buf,
717721
struct nand_bbt_descr *td, struct nand_bbt_descr *md,
718722
int chipsel)
719723
{
724+
u64 targetsize = nanddev_target_size(&this->base);
720725
struct mtd_info *mtd = nand_to_mtd(this);
721726
struct erase_info einfo;
722727
int i, res, chip = 0;
@@ -737,7 +742,7 @@ static int write_bbt(struct nand_chip *this, uint8_t *buf,
737742
rcode = 0xff;
738743
/* Write bad block table per chip rather than per device? */
739744
if (td->options & NAND_BBT_PERCHIP) {
740-
numblocks = (int)(this->chipsize >> this->bbt_erase_shift);
745+
numblocks = (int)(targetsize >> this->bbt_erase_shift);
741746
/* Full device write or specific chip? */
742747
if (chipsel == -1) {
743748
nrchips = this->numchips;
@@ -1099,14 +1104,15 @@ static int nand_update_bbt(struct nand_chip *this, loff_t offs)
10991104
*/
11001105
static void mark_bbt_region(struct nand_chip *this, struct nand_bbt_descr *td)
11011106
{
1107+
u64 targetsize = nanddev_target_size(&this->base);
11021108
struct mtd_info *mtd = nand_to_mtd(this);
11031109
int i, j, chips, block, nrblocks, update;
11041110
uint8_t oldval;
11051111

11061112
/* Do we have a bbt per chip? */
11071113
if (td->options & NAND_BBT_PERCHIP) {
11081114
chips = this->numchips;
1109-
nrblocks = (int)(this->chipsize >> this->bbt_erase_shift);
1115+
nrblocks = (int)(targetsize >> this->bbt_erase_shift);
11101116
} else {
11111117
chips = 1;
11121118
nrblocks = (int)(mtd->size >> this->bbt_erase_shift);
@@ -1159,6 +1165,7 @@ static void mark_bbt_region(struct nand_chip *this, struct nand_bbt_descr *td)
11591165
*/
11601166
static void verify_bbt_descr(struct nand_chip *this, struct nand_bbt_descr *bd)
11611167
{
1168+
u64 targetsize = nanddev_target_size(&this->base);
11621169
struct mtd_info *mtd = nand_to_mtd(this);
11631170
u32 pattern_len;
11641171
u32 bits;
@@ -1187,7 +1194,7 @@ static void verify_bbt_descr(struct nand_chip *this, struct nand_bbt_descr *bd)
11871194
}
11881195

11891196
if (bd->options & NAND_BBT_PERCHIP)
1190-
table_size = this->chipsize >> this->bbt_erase_shift;
1197+
table_size = targetsize >> this->bbt_erase_shift;
11911198
else
11921199
table_size = mtd->size >> this->bbt_erase_shift;
11931200
table_size >>= 3;

drivers/mtd/nand/raw/nand_jedec.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ int nand_jedec_detect(struct nand_chip *chip)
101101
/* Please reference to the comment for nand_flash_detect_onfi. */
102102
memorg->eraseblocks_per_lun =
103103
1 << (fls(le32_to_cpu(p->blocks_per_lun)) - 1);
104-
chip->chipsize = memorg->eraseblocks_per_lun;
105-
chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count;
106104
memorg->bits_per_cell = p->bits_per_cell;
107105

108106
if (le16_to_cpu(p->features) & JEDEC_FEATURE_16_BIT_BUS)

drivers/mtd/nand/raw/nand_onfi.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ int nand_onfi_detect(struct nand_chip *chip)
246246
memorg->eraseblocks_per_lun =
247247
1 << (fls(le32_to_cpu(p->blocks_per_lun)) - 1);
248248
memorg->max_bad_eraseblocks_per_lun = le32_to_cpu(p->blocks_per_lun);
249-
chip->chipsize = memorg->eraseblocks_per_lun;
250-
chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count;
251249
memorg->bits_per_cell = p->bits_per_cell;
252250

253251
if (le16_to_cpu(p->features) & ONFI_FEATURE_16_BIT_BUS)

0 commit comments

Comments
 (0)