29
29
#define SPI_NOR_MAX_ID_LEN 6
30
30
31
31
struct flash_info {
32
+ char * name ;
33
+
32
34
/*
33
35
* This array stores the ID bytes.
34
36
* The first three bytes are the JEDIC ID.
@@ -59,7 +61,7 @@ struct flash_info {
59
61
60
62
#define JEDEC_MFR (info ) ((info)->id[0])
61
63
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 );
63
65
64
66
/*
65
67
* 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)
169
171
}
170
172
171
173
/* 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 ,
173
175
int enable )
174
176
{
175
177
int status ;
@@ -469,7 +471,6 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
469
471
470
472
/* Used when the "_ext_id" is two bytes at most */
471
473
#define INFO (_jedec_id , _ext_id , _sector_size , _n_sectors , _flags ) \
472
- ((kernel_ulong_t)&(struct flash_info) { \
473
474
.id = { \
474
475
((_jedec_id) >> 16) & 0xff, \
475
476
((_jedec_id) >> 8) & 0xff, \
@@ -481,11 +482,9 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
481
482
.sector_size = (_sector_size), \
482
483
.n_sectors = (_n_sectors), \
483
484
.page_size = 256, \
484
- .flags = (_flags), \
485
- })
485
+ .flags = (_flags),
486
486
487
487
#define INFO6 (_jedec_id , _ext_id , _sector_size , _n_sectors , _flags ) \
488
- ((kernel_ulong_t)&(struct flash_info) { \
489
488
.id = { \
490
489
((_jedec_id) >> 16) & 0xff, \
491
490
((_jedec_id) >> 8) & 0xff, \
@@ -498,17 +497,14 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
498
497
.sector_size = (_sector_size), \
499
498
.n_sectors = (_n_sectors), \
500
499
.page_size = 256, \
501
- .flags = (_flags), \
502
- })
500
+ .flags = (_flags),
503
501
504
502
#define CAT25_INFO (_sector_size , _n_sectors , _page_size , _addr_width , _flags ) \
505
- ((kernel_ulong_t)&(struct flash_info) { \
506
503
.sector_size = (_sector_size), \
507
504
.n_sectors = (_n_sectors), \
508
505
.page_size = (_page_size), \
509
506
.addr_width = (_addr_width), \
510
- .flags = (_flags), \
511
- })
507
+ .flags = (_flags),
512
508
513
509
/* NOTE: double check command sets and memory organization when you add
514
510
* 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)
521
517
* For historical (and compatibility) reasons (before we got above config) some
522
518
* old entries may be missing 4K flag.
523
519
*/
524
- static const struct spi_device_id spi_nor_ids [] = {
520
+ static const struct flash_info spi_nor_ids [] = {
525
521
/* Atmel -- some are (confusingly) marketed as "DataFlash" */
526
522
{ "at25fs010" , INFO (0x1f6601 , 0 , 32 * 1024 , 4 , SECT_4K ) },
527
523
{ "at25fs040" , INFO (0x1f6604 , 0 , 64 * 1024 , 8 , SECT_4K ) },
@@ -703,11 +699,11 @@ static const struct spi_device_id spi_nor_ids[] = {
703
699
{ },
704
700
};
705
701
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 )
707
703
{
708
704
int tmp ;
709
705
u8 id [SPI_NOR_MAX_ID_LEN ];
710
- struct flash_info * info ;
706
+ const struct flash_info * info ;
711
707
712
708
tmp = nor -> read_reg (nor , SPINOR_OP_RDID , id , SPI_NOR_MAX_ID_LEN );
713
709
if (tmp < 0 ) {
@@ -716,7 +712,7 @@ static const struct spi_device_id *spi_nor_read_id(struct spi_nor *nor)
716
712
}
717
713
718
714
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 ];
720
716
if (info -> id_len ) {
721
717
if (!memcmp (info -> id , id , info -> id_len ))
722
718
return & spi_nor_ids [tmp ];
@@ -962,7 +958,7 @@ static int micron_quad_enable(struct spi_nor *nor)
962
958
return 0 ;
963
959
}
964
960
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 )
966
962
{
967
963
int status ;
968
964
@@ -1004,8 +1000,7 @@ static int spi_nor_check(struct spi_nor *nor)
1004
1000
1005
1001
int spi_nor_scan (struct spi_nor * nor , const char * name , enum read_mode mode )
1006
1002
{
1007
- const struct spi_device_id * id = NULL ;
1008
- struct flash_info * info ;
1003
+ const struct flash_info * info = NULL ;
1009
1004
struct device * dev = nor -> dev ;
1010
1005
struct mtd_info * mtd = nor -> mtd ;
1011
1006
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)
1017
1012
return ret ;
1018
1013
1019
1014
if (name )
1020
- id = spi_nor_match_id (name );
1015
+ info = spi_nor_match_id (name );
1021
1016
/* 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 ))
1025
1020
return - ENOENT ;
1026
1021
1027
- info = (void * )id -> driver_data ;
1028
-
1029
1022
/*
1030
1023
* If caller has specified name of flash model that can normally be
1031
1024
* detected using JEDEC, let's verify it.
1032
1025
*/
1033
1026
if (name && info -> id_len ) {
1034
- const struct spi_device_id * jid ;
1027
+ const struct flash_info * jinfo ;
1035
1028
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 ) {
1040
1033
/*
1041
1034
* JEDEC knows better, so overwrite platform ID. We
1042
1035
* 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)
1045
1038
* information, even if it's not 100% accurate.
1046
1039
*/
1047
1040
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 ;
1051
1043
}
1052
1044
}
1053
1045
@@ -1197,7 +1189,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
1197
1189
1198
1190
nor -> read_dummy = spi_nor_read_dummy_cycles (nor );
1199
1191
1200
- dev_info (dev , "%s (%lld Kbytes)\n" , id -> name ,
1192
+ dev_info (dev , "%s (%lld Kbytes)\n" , info -> name ,
1201
1193
(long long )mtd -> size >> 10 );
1202
1194
1203
1195
dev_dbg (dev ,
@@ -1220,9 +1212,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
1220
1212
}
1221
1213
EXPORT_SYMBOL_GPL (spi_nor_scan );
1222
1214
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 )
1224
1216
{
1225
- const struct spi_device_id * id = spi_nor_ids ;
1217
+ const struct flash_info * id = spi_nor_ids ;
1226
1218
1227
1219
while (id -> name [0 ]) {
1228
1220
if (!strcmp (name , id -> name ))
0 commit comments