@@ -2474,8 +2474,26 @@ static const struct flash_info spi_nor_ids[] = {
24742474 { },
24752475};
24762476
2477+ static const struct spi_nor_manufacturer * manufacturers [0 ];
2478+
2479+ static const struct flash_info *
2480+ spi_nor_search_part_by_id (const struct flash_info * parts , unsigned int nparts ,
2481+ const u8 * id )
2482+ {
2483+ unsigned int i ;
2484+
2485+ for (i = 0 ; i < nparts ; i ++ ) {
2486+ if (parts [i ].id_len &&
2487+ !memcmp (parts [i ].id , id , parts [i ].id_len ))
2488+ return & parts [i ];
2489+ }
2490+
2491+ return NULL ;
2492+ }
2493+
24772494static const struct flash_info * spi_nor_read_id (struct spi_nor * nor )
24782495{
2496+ const struct flash_info * info ;
24792497 u8 * id = nor -> bouncebuf ;
24802498 unsigned int i ;
24812499 int ret ;
@@ -2497,11 +2515,21 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
24972515 return ERR_PTR (ret );
24982516 }
24992517
2500- for (i = 0 ; i < ARRAY_SIZE (spi_nor_ids ) - 1 ; i ++ ) {
2501- if (spi_nor_ids [i ].id_len &&
2502- !memcmp (spi_nor_ids [i ].id , id , spi_nor_ids [i ].id_len ))
2503- return & spi_nor_ids [i ];
2518+ for (i = 0 ; i < ARRAY_SIZE (manufacturers ); i ++ ) {
2519+ info = spi_nor_search_part_by_id (manufacturers [i ]-> parts ,
2520+ manufacturers [i ]-> nparts ,
2521+ id );
2522+ if (info ) {
2523+ nor -> manufacturer = manufacturers [i ];
2524+ return info ;
2525+ }
25042526 }
2527+
2528+ info = spi_nor_search_part_by_id (spi_nor_ids ,
2529+ ARRAY_SIZE (spi_nor_ids ) - 1 , id );
2530+ if (info )
2531+ return info ;
2532+
25052533 dev_err (nor -> dev , "unrecognized JEDEC id bytes: %*ph\n" ,
25062534 SPI_NOR_MAX_ID_LEN , id );
25072535 return ERR_PTR (- ENODEV );
@@ -2987,6 +3015,16 @@ int spi_nor_post_bfpt_fixups(struct spi_nor *nor,
29873015 const struct sfdp_bfpt * bfpt ,
29883016 struct spi_nor_flash_parameter * params )
29893017{
3018+ int ret ;
3019+
3020+ if (nor -> manufacturer && nor -> manufacturer -> fixups &&
3021+ nor -> manufacturer -> fixups -> post_bfpt ) {
3022+ ret = nor -> manufacturer -> fixups -> post_bfpt (nor , bfpt_header ,
3023+ bfpt , params );
3024+ if (ret )
3025+ return ret ;
3026+ }
3027+
29903028 if (nor -> info -> fixups && nor -> info -> fixups -> post_bfpt )
29913029 return nor -> info -> fixups -> post_bfpt (nor , bfpt_header , bfpt ,
29923030 params );
@@ -3296,6 +3334,10 @@ static void spi_nor_manufacturer_init_params(struct spi_nor *nor)
32963334 break ;
32973335 }
32983336
3337+ if (nor -> manufacturer && nor -> manufacturer -> fixups &&
3338+ nor -> manufacturer -> fixups -> default_init )
3339+ nor -> manufacturer -> fixups -> default_init (nor );
3340+
32993341 if (nor -> info -> fixups && nor -> info -> fixups -> default_init )
33003342 nor -> info -> fixups -> default_init (nor );
33013343}
@@ -3455,6 +3497,10 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
34553497 if (nor -> info -> flags & SPI_S3AN )
34563498 s3an_post_sfdp_fixups (nor );
34573499
3500+ if (nor -> manufacturer && nor -> manufacturer -> fixups &&
3501+ nor -> manufacturer -> fixups -> post_sfdp )
3502+ nor -> manufacturer -> fixups -> post_sfdp (nor );
3503+
34583504 if (nor -> info -> fixups && nor -> info -> fixups -> post_sfdp )
34593505 nor -> info -> fixups -> post_sfdp (nor );
34603506}
@@ -3617,15 +3663,25 @@ void spi_nor_restore(struct spi_nor *nor)
36173663}
36183664EXPORT_SYMBOL_GPL (spi_nor_restore );
36193665
3620- static const struct flash_info * spi_nor_match_id (const char * name )
3666+ static const struct flash_info * spi_nor_match_id (struct spi_nor * nor ,
3667+ const char * name )
36213668{
3622- const struct flash_info * id = spi_nor_ids ;
3669+ unsigned int i , j ;
36233670
3624- while (id -> name ) {
3625- if (!strcmp (name , id -> name ))
3626- return id ;
3627- id ++ ;
3671+ for (i = 0 ; i < ARRAY_SIZE (spi_nor_ids ) - 1 ; i ++ ) {
3672+ if (!strcmp (name , spi_nor_ids [i ].name ))
3673+ return & spi_nor_ids [i ];
36283674 }
3675+
3676+ for (i = 0 ; i < ARRAY_SIZE (manufacturers ); i ++ ) {
3677+ for (j = 0 ; j < manufacturers [i ]-> nparts ; j ++ ) {
3678+ if (!strcmp (name , manufacturers [i ]-> parts [j ].name )) {
3679+ nor -> manufacturer = manufacturers [i ];
3680+ return & manufacturers [i ]-> parts [j ];
3681+ }
3682+ }
3683+ }
3684+
36293685 return NULL ;
36303686}
36313687
@@ -3672,7 +3728,7 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
36723728 const struct flash_info * info = NULL ;
36733729
36743730 if (name )
3675- info = spi_nor_match_id (name );
3731+ info = spi_nor_match_id (nor , name );
36763732 /* Try to auto-detect if chip name wasn't specified or not found */
36773733 if (!info )
36783734 info = spi_nor_read_id (nor );
0 commit comments