Skip to content

Commit 32813e2

Browse files
bbrezillonmiquelraynal
authored andcommitted
mtd: rawnand: Get rid of chip->numchips
The same information is provided by nanddev_ntargets(). 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>
1 parent 6c836d5 commit 32813e2

File tree

9 files changed

+20
-29
lines changed

9 files changed

+20
-29
lines changed

drivers/mtd/nand/raw/diskonchip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd)
12911291
struct doc_priv *doc = nand_get_controller_data(this);
12921292
struct mtd_partition parts[5];
12931293

1294-
if (this->numchips > doc->chips_per_floor) {
1294+
if (nanddev_ntargets(&this->base) > doc->chips_per_floor) {
12951295
pr_err("Multi-floor INFTL devices not yet supported.\n");
12961296
return -EIO;
12971297
}

drivers/mtd/nand/raw/fsl_elbc_nand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static int fsl_elbc_attach_chip(struct nand_chip *chip)
653653
priv->fmr |= al << FMR_AL_SHIFT;
654654

655655
dev_dbg(priv->dev, "fsl_elbc_init: nand->numchips = %d\n",
656-
chip->numchips);
656+
nanddev_ntargets(&chip->base));
657657
dev_dbg(priv->dev, "fsl_elbc_init: nand->chipsize = %lld\n",
658658
nanddev_target_size(&chip->base));
659659
dev_dbg(priv->dev, "fsl_elbc_init: nand->pagemask = %8x\n",

drivers/mtd/nand/raw/fsl_ifc_nand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ static int fsl_ifc_attach_chip(struct nand_chip *chip)
722722
struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
723723

724724
dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__,
725-
chip->numchips);
725+
nanddev_ntargets(&chip->base));
726726
dev_dbg(priv->dev, "%s: nand->chipsize = %lld\n", __func__,
727727
nanddev_target_size(&chip->base));
728728
dev_dbg(priv->dev, "%s: nand->pagemask = %8x\n", __func__,

drivers/mtd/nand/raw/hisi504_nand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ static int hisi_nfc_resume(struct device *dev)
849849
struct hinfc_host *host = dev_get_drvdata(dev);
850850
struct nand_chip *chip = &host->chip;
851851

852-
for (cs = 0; cs < chip->numchips; cs++)
852+
for (cs = 0; cs < nanddev_ntargets(&chip->base); cs++)
853853
hisi_nfc_send_cmd_reset(host, cs);
854854
hinfc_write(host, SET_HINFC504_PWIDTH(HINFC504_W_LATCH,
855855
HINFC504_R_LATCH, HINFC504_RW_LATCH), HINFC504_PWIDTH);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ static int jz_nand_detect_bank(struct platform_device *pdev,
354354
}
355355

356356
/* Update size of the MTD. */
357-
chip->numchips++;
358357
memorg->ntargets++;
359358
mtd->size += nanddev_target_size(&chip->base);
360359
}

drivers/mtd/nand/raw/internals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static inline int nand_exec_op(struct nand_chip *chip,
110110
if (!nand_has_exec_op(chip))
111111
return -ENOTSUPP;
112112

113-
if (WARN_ON(op->cs >= chip->numchips))
113+
if (WARN_ON(op->cs >= nanddev_ntargets(&chip->base)))
114114
return -EINVAL;
115115

116116
return chip->controller->ops->exec_op(chip, op, false);

drivers/mtd/nand/raw/nand_base.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ static int check_offs_len(struct nand_chip *chip, loff_t ofs, uint64_t len)
240240
void nand_select_target(struct nand_chip *chip, unsigned int cs)
241241
{
242242
/*
243-
* cs should always lie between 0 and chip->numchips, when that's not
244-
* the case it's a bug and the caller should be fixed.
243+
* cs should always lie between 0 and nanddev_ntargets(), when that's
244+
* not the case it's a bug and the caller should be fixed.
245245
*/
246-
if (WARN_ON(cs > chip->numchips))
246+
if (WARN_ON(cs > nanddev_ntargets(&chip->base)))
247247
return;
248248

249249
chip->cur_cs = cs;
@@ -4999,12 +4999,6 @@ static int nand_scan_ident(struct nand_chip *chip, unsigned int maxchips,
49994999
if (!mtd->name && mtd->dev.parent)
50005000
mtd->name = dev_name(mtd->dev.parent);
50015001

5002-
/*
5003-
* Start with chips->numchips = maxchips to let nand_select_target() do
5004-
* its job. chip->numchips will be adjusted after.
5005-
*/
5006-
chip->numchips = maxchips;
5007-
50085002
/* Set the default functions */
50095003
nand_set_defaults(chip);
50105004

@@ -5052,7 +5046,6 @@ static int nand_scan_ident(struct nand_chip *chip, unsigned int maxchips,
50525046

50535047
/* Store the number of chips and calc total size for mtd */
50545048
memorg->ntargets = i;
5055-
chip->numchips = i;
50565049
mtd->size = i * nanddev_target_size(&chip->base);
50575050

50585051
return 0;
@@ -5794,7 +5787,7 @@ static int nand_scan_tail(struct nand_chip *chip)
57945787
goto err_nanddev_cleanup;
57955788

57965789
/* Enter fastest possible mode on all dies. */
5797-
for (i = 0; i < chip->numchips; i++) {
5790+
for (i = 0; i < nanddev_ntargets(&chip->base); i++) {
57985791
ret = nand_setup_data_interface(chip, i);
57995792
if (ret)
58005793
goto err_nanddev_cleanup;

drivers/mtd/nand/raw/nand_bbt.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static int read_abs_bbt(struct nand_chip *this, uint8_t *buf,
269269

270270
if (td->options & NAND_BBT_PERCHIP) {
271271
int offs = 0;
272-
for (i = 0; i < this->numchips; i++) {
272+
for (i = 0; i < nanddev_ntargets(&this->base); i++) {
273273
if (chip == -1 || chip == i)
274274
res = read_bbt(this, buf, td->pages[i],
275275
targetsize >> this->bbt_erase_shift,
@@ -478,9 +478,9 @@ static int create_bbt(struct nand_chip *this, uint8_t *buf,
478478
startblock = 0;
479479
from = 0;
480480
} else {
481-
if (chip >= this->numchips) {
481+
if (chip >= nanddev_ntargets(&this->base)) {
482482
pr_warn("create_bbt(): chipnr (%d) > available chips (%d)\n",
483-
chip + 1, this->numchips);
483+
chip + 1, nanddev_ntargets(&this->base));
484484
return -EINVAL;
485485
}
486486
numblocks = targetsize >> this->bbt_erase_shift;
@@ -550,7 +550,7 @@ static int search_bbt(struct nand_chip *this, uint8_t *buf,
550550

551551
/* Do we have a bbt per chip? */
552552
if (td->options & NAND_BBT_PERCHIP) {
553-
chips = this->numchips;
553+
chips = nanddev_ntargets(&this->base);
554554
bbtblocks = targetsize >> this->bbt_erase_shift;
555555
startblock &= bbtblocks - 1;
556556
} else {
@@ -643,7 +643,7 @@ static int get_bbt_block(struct nand_chip *this, struct nand_bbt_descr *td,
643643

644644
numblocks = (int)(targetsize >> this->bbt_erase_shift);
645645
if (!(td->options & NAND_BBT_PERCHIP))
646-
numblocks *= this->numchips;
646+
numblocks *= nanddev_ntargets(&this->base);
647647

648648
/*
649649
* Automatic placement of the bad block table. Search direction
@@ -745,7 +745,7 @@ static int write_bbt(struct nand_chip *this, uint8_t *buf,
745745
numblocks = (int)(targetsize >> this->bbt_erase_shift);
746746
/* Full device write or specific chip? */
747747
if (chipsel == -1) {
748-
nrchips = this->numchips;
748+
nrchips = nanddev_ntargets(&this->base);
749749
} else {
750750
nrchips = chipsel + 1;
751751
chip = chipsel;
@@ -932,7 +932,7 @@ static int check_create(struct nand_chip *this, uint8_t *buf,
932932

933933
/* Do we have a bbt per chip? */
934934
if (td->options & NAND_BBT_PERCHIP)
935-
chips = this->numchips;
935+
chips = nanddev_ntargets(&this->base);
936936
else
937937
chips = 1;
938938

@@ -1111,7 +1111,7 @@ static void mark_bbt_region(struct nand_chip *this, struct nand_bbt_descr *td)
11111111

11121112
/* Do we have a bbt per chip? */
11131113
if (td->options & NAND_BBT_PERCHIP) {
1114-
chips = this->numchips;
1114+
chips = nanddev_ntargets(&this->base);
11151115
nrblocks = (int)(targetsize >> this->bbt_erase_shift);
11161116
} else {
11171117
chips = 1;

include/linux/mtd/rawnand.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,6 @@ struct nand_legacy {
10021002
* set to the actually used ONFI mode if the chip is
10031003
* ONFI compliant or deduced from the datasheet if
10041004
* the NAND chip is not ONFI compliant.
1005-
* @numchips: [INTERN] number of physical chips
10061005
* @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
10071006
* @data_buf: [INTERN] buffer for data, size is (page size + oobsize).
10081007
* @pagecache: Structure containing page cache related fields
@@ -1016,8 +1015,9 @@ struct nand_legacy {
10161015
* @data_interface: [INTERN] NAND interface timing information
10171016
* @cur_cs: currently selected target. -1 means no target selected,
10181017
* otherwise we should always have cur_cs >= 0 &&
1019-
* cur_cs < numchips. NAND Controller drivers should not
1020-
* modify this value, but they're allowed to read it.
1018+
* cur_cs < nanddev_ntargets(). NAND Controller drivers
1019+
* should not modify this value, but they're allowed to
1020+
* read it.
10211021
* @read_retries: [INTERN] the number of read retry modes supported
10221022
* @lock: lock protecting the suspended field. Also used to
10231023
* serialize accesses to the NAND device.
@@ -1051,7 +1051,6 @@ struct nand_chip {
10511051
int phys_erase_shift;
10521052
int bbt_erase_shift;
10531053
int chip_shift;
1054-
int numchips;
10551054
int pagemask;
10561055
u8 *data_buf;
10571056

0 commit comments

Comments
 (0)