Skip to content

Commit d0ddd88

Browse files
ambarusPratyush Yadav
authored andcommitted
mtd: spi-nor: Introduce spi_nor_match_id()
Similar to spi_nor_match_name() extend the search of flash_info through all the manufacturers, this time doing the match by ID. There's no reason to limit the search per manufacturer yet, do it globally, search the flash in all the parts of all manufacturers in a single method. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Signed-off-by: Pratyush Yadav <p.yadav@ti.com> Reviewed-by: Pratyush Yadav <p.yadav@ti.com> Reviewed-by: Michael Walle <michael@walle.cc> Link: https://lore.kernel.org/r/20220420103427.47867-3-tudor.ambarus@microchip.com
1 parent b1145d6 commit d0ddd88

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,16 +1638,21 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
16381638
&spi_nor_xmc,
16391639
};
16401640

1641-
static const struct flash_info *
1642-
spi_nor_search_part_by_id(const struct flash_info *parts, unsigned int nparts,
1643-
const u8 *id)
1641+
static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
1642+
const u8 *id)
16441643
{
1645-
unsigned int i;
1644+
const struct flash_info *part;
1645+
unsigned int i, j;
16461646

1647-
for (i = 0; i < nparts; i++) {
1648-
if (parts[i].id_len &&
1649-
!memcmp(parts[i].id, id, parts[i].id_len))
1650-
return &parts[i];
1647+
for (i = 0; i < ARRAY_SIZE(manufacturers); i++) {
1648+
for (j = 0; j < manufacturers[i]->nparts; j++) {
1649+
part = &manufacturers[i]->parts[j];
1650+
if (part->id_len &&
1651+
!memcmp(part->id, id, part->id_len)) {
1652+
nor->manufacturer = manufacturers[i];
1653+
return part;
1654+
}
1655+
}
16511656
}
16521657

16531658
return NULL;
@@ -1657,7 +1662,6 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
16571662
{
16581663
const struct flash_info *info;
16591664
u8 *id = nor->bouncebuf;
1660-
unsigned int i;
16611665
int ret;
16621666

16631667
if (nor->spimem) {
@@ -1677,19 +1681,13 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
16771681
return ERR_PTR(ret);
16781682
}
16791683

1680-
for (i = 0; i < ARRAY_SIZE(manufacturers); i++) {
1681-
info = spi_nor_search_part_by_id(manufacturers[i]->parts,
1682-
manufacturers[i]->nparts,
1683-
id);
1684-
if (info) {
1685-
nor->manufacturer = manufacturers[i];
1686-
return info;
1687-
}
1684+
info = spi_nor_match_id(nor, id);
1685+
if (!info) {
1686+
dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
1687+
SPI_NOR_MAX_ID_LEN, id);
1688+
return ERR_PTR(-ENODEV);
16881689
}
1689-
1690-
dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
1691-
SPI_NOR_MAX_ID_LEN, id);
1692-
return ERR_PTR(-ENODEV);
1690+
return info;
16931691
}
16941692

16951693
static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,

0 commit comments

Comments
 (0)