Skip to content

Commit 06bb6f5

Browse files
rmileckicomputersforpeace
authored andcommitted
mtd: spi-nor: stop (ab)using struct spi_device_id
Using struct spi_device_id for storing list of flash devices comes from early SPI NOR framework days. Thanks to the commit 70f3ce0 ("mtd: spi-nor: make spi_nor_scan() take a chip type name, not spi_device_id") we can stop using spi_device_id and just switch to our own struct. Signed-off-by: Rafał Miłecki <zajec5@gmail.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
1 parent 0cb8504 commit 06bb6f5

File tree

1 file changed

+27
-35
lines changed

1 file changed

+27
-35
lines changed

drivers/mtd/spi-nor/spi-nor.c

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define SPI_NOR_MAX_ID_LEN 6
3030

3131
struct flash_info {
32+
char *name;
33+
3234
/*
3335
* This array stores the ID bytes.
3436
* The first three bytes are the JEDIC ID.
@@ -59,7 +61,7 @@ struct flash_info {
5961

6062
#define JEDEC_MFR(info) ((info)->id[0])
6163

62-
static const struct spi_device_id *spi_nor_match_id(const char *name);
64+
static const struct flash_info *spi_nor_match_id(const char *name);
6365

6466
/*
6567
* Read the status register, returning its value in the location
@@ -169,7 +171,7 @@ static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
169171
}
170172

171173
/* Enable/disable 4-byte addressing mode. */
172-
static inline int set_4byte(struct spi_nor *nor, struct flash_info *info,
174+
static inline int set_4byte(struct spi_nor *nor, const struct flash_info *info,
173175
int enable)
174176
{
175177
int status;
@@ -469,7 +471,6 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
469471

470472
/* Used when the "_ext_id" is two bytes at most */
471473
#define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
472-
((kernel_ulong_t)&(struct flash_info) { \
473474
.id = { \
474475
((_jedec_id) >> 16) & 0xff, \
475476
((_jedec_id) >> 8) & 0xff, \
@@ -481,11 +482,9 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
481482
.sector_size = (_sector_size), \
482483
.n_sectors = (_n_sectors), \
483484
.page_size = 256, \
484-
.flags = (_flags), \
485-
})
485+
.flags = (_flags),
486486

487487
#define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
488-
((kernel_ulong_t)&(struct flash_info) { \
489488
.id = { \
490489
((_jedec_id) >> 16) & 0xff, \
491490
((_jedec_id) >> 8) & 0xff, \
@@ -498,17 +497,14 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
498497
.sector_size = (_sector_size), \
499498
.n_sectors = (_n_sectors), \
500499
.page_size = 256, \
501-
.flags = (_flags), \
502-
})
500+
.flags = (_flags),
503501

504502
#define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_width, _flags) \
505-
((kernel_ulong_t)&(struct flash_info) { \
506503
.sector_size = (_sector_size), \
507504
.n_sectors = (_n_sectors), \
508505
.page_size = (_page_size), \
509506
.addr_width = (_addr_width), \
510-
.flags = (_flags), \
511-
})
507+
.flags = (_flags),
512508

513509
/* NOTE: double check command sets and memory organization when you add
514510
* more nor chips. This current list focusses on newer chips, which
@@ -521,7 +517,7 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
521517
* For historical (and compatibility) reasons (before we got above config) some
522518
* old entries may be missing 4K flag.
523519
*/
524-
static const struct spi_device_id spi_nor_ids[] = {
520+
static const struct flash_info spi_nor_ids[] = {
525521
/* Atmel -- some are (confusingly) marketed as "DataFlash" */
526522
{ "at25fs010", INFO(0x1f6601, 0, 32 * 1024, 4, SECT_4K) },
527523
{ "at25fs040", INFO(0x1f6604, 0, 64 * 1024, 8, SECT_4K) },
@@ -703,11 +699,11 @@ static const struct spi_device_id spi_nor_ids[] = {
703699
{ },
704700
};
705701

706-
static const struct spi_device_id *spi_nor_read_id(struct spi_nor *nor)
702+
static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
707703
{
708704
int tmp;
709705
u8 id[SPI_NOR_MAX_ID_LEN];
710-
struct flash_info *info;
706+
const struct flash_info *info;
711707

712708
tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN);
713709
if (tmp < 0) {
@@ -716,7 +712,7 @@ static const struct spi_device_id *spi_nor_read_id(struct spi_nor *nor)
716712
}
717713

718714
for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
719-
info = (void *)spi_nor_ids[tmp].driver_data;
715+
info = &spi_nor_ids[tmp];
720716
if (info->id_len) {
721717
if (!memcmp(info->id, id, info->id_len))
722718
return &spi_nor_ids[tmp];
@@ -962,7 +958,7 @@ static int micron_quad_enable(struct spi_nor *nor)
962958
return 0;
963959
}
964960

965-
static int set_quad_mode(struct spi_nor *nor, struct flash_info *info)
961+
static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
966962
{
967963
int status;
968964

@@ -1004,8 +1000,7 @@ static int spi_nor_check(struct spi_nor *nor)
10041000

10051001
int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
10061002
{
1007-
const struct spi_device_id *id = NULL;
1008-
struct flash_info *info;
1003+
const struct flash_info *info = NULL;
10091004
struct device *dev = nor->dev;
10101005
struct mtd_info *mtd = nor->mtd;
10111006
struct device_node *np = dev->of_node;
@@ -1017,26 +1012,24 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
10171012
return ret;
10181013

10191014
if (name)
1020-
id = spi_nor_match_id(name);
1015+
info = spi_nor_match_id(name);
10211016
/* Try to auto-detect if chip name wasn't specified or not found */
1022-
if (!id)
1023-
id = spi_nor_read_id(nor);
1024-
if (IS_ERR_OR_NULL(id))
1017+
if (!info)
1018+
info = spi_nor_read_id(nor);
1019+
if (IS_ERR_OR_NULL(info))
10251020
return -ENOENT;
10261021

1027-
info = (void *)id->driver_data;
1028-
10291022
/*
10301023
* If caller has specified name of flash model that can normally be
10311024
* detected using JEDEC, let's verify it.
10321025
*/
10331026
if (name && info->id_len) {
1034-
const struct spi_device_id *jid;
1027+
const struct flash_info *jinfo;
10351028

1036-
jid = spi_nor_read_id(nor);
1037-
if (IS_ERR(jid)) {
1038-
return PTR_ERR(jid);
1039-
} else if (jid != id) {
1029+
jinfo = spi_nor_read_id(nor);
1030+
if (IS_ERR(jinfo)) {
1031+
return PTR_ERR(jinfo);
1032+
} else if (jinfo != info) {
10401033
/*
10411034
* JEDEC knows better, so overwrite platform ID. We
10421035
* can't trust partitions any longer, but we'll let
@@ -1045,9 +1038,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
10451038
* information, even if it's not 100% accurate.
10461039
*/
10471040
dev_warn(dev, "found %s, expected %s\n",
1048-
jid->name, id->name);
1049-
id = jid;
1050-
info = (void *)jid->driver_data;
1041+
jinfo->name, info->name);
1042+
info = jinfo;
10511043
}
10521044
}
10531045

@@ -1197,7 +1189,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
11971189

11981190
nor->read_dummy = spi_nor_read_dummy_cycles(nor);
11991191

1200-
dev_info(dev, "%s (%lld Kbytes)\n", id->name,
1192+
dev_info(dev, "%s (%lld Kbytes)\n", info->name,
12011193
(long long)mtd->size >> 10);
12021194

12031195
dev_dbg(dev,
@@ -1220,9 +1212,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
12201212
}
12211213
EXPORT_SYMBOL_GPL(spi_nor_scan);
12221214

1223-
static const struct spi_device_id *spi_nor_match_id(const char *name)
1215+
static const struct flash_info *spi_nor_match_id(const char *name)
12241216
{
1225-
const struct spi_device_id *id = spi_nor_ids;
1217+
const struct flash_info *id = spi_nor_ids;
12261218

12271219
while (id->name[0]) {
12281220
if (!strcmp(name, id->name))

0 commit comments

Comments
 (0)