@@ -1463,23 +1463,13 @@ static void spi_nor_unlock_and_unprep_rd(struct spi_nor *nor, loff_t start, size
1463
1463
spi_nor_unprep (nor );
1464
1464
}
1465
1465
1466
- static u32 spi_nor_convert_addr (struct spi_nor * nor , loff_t addr )
1467
- {
1468
- if (!nor -> params -> convert_addr )
1469
- return addr ;
1470
-
1471
- return nor -> params -> convert_addr (nor , addr );
1472
- }
1473
-
1474
1466
/*
1475
1467
* Initiate the erasure of a single sector
1476
1468
*/
1477
1469
int spi_nor_erase_sector (struct spi_nor * nor , u32 addr )
1478
1470
{
1479
1471
int i ;
1480
1472
1481
- addr = spi_nor_convert_addr (nor , addr );
1482
-
1483
1473
if (nor -> spimem ) {
1484
1474
struct spi_mem_op op =
1485
1475
SPI_NOR_SECTOR_ERASE_OP (nor -> erase_opcode ,
@@ -1986,7 +1976,6 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
1986
1976
& spi_nor_spansion ,
1987
1977
& spi_nor_sst ,
1988
1978
& spi_nor_winbond ,
1989
- & spi_nor_xilinx ,
1990
1979
& spi_nor_xmc ,
1991
1980
};
1992
1981
@@ -2065,8 +2054,6 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
2065
2054
while (len ) {
2066
2055
loff_t addr = from ;
2067
2056
2068
- addr = spi_nor_convert_addr (nor , addr );
2069
-
2070
2057
ret = spi_nor_read_data (nor , addr , len , buf );
2071
2058
if (ret == 0 ) {
2072
2059
/* We shouldn't see 0-length reads */
@@ -2099,7 +2086,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
2099
2086
size_t * retlen , const u_char * buf )
2100
2087
{
2101
2088
struct spi_nor * nor = mtd_to_spi_nor (mtd );
2102
- size_t page_offset , page_remain , i ;
2089
+ size_t i ;
2103
2090
ssize_t ret ;
2104
2091
u32 page_size = nor -> params -> page_size ;
2105
2092
@@ -2112,23 +2099,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
2112
2099
for (i = 0 ; i < len ; ) {
2113
2100
ssize_t written ;
2114
2101
loff_t addr = to + i ;
2115
-
2116
- /*
2117
- * If page_size is a power of two, the offset can be quickly
2118
- * calculated with an AND operation. On the other cases we
2119
- * need to do a modulus operation (more expensive).
2120
- */
2121
- if (is_power_of_2 (page_size )) {
2122
- page_offset = addr & (page_size - 1 );
2123
- } else {
2124
- u64 aux = addr ;
2125
-
2126
- page_offset = do_div (aux , page_size );
2127
- }
2102
+ size_t page_offset = addr & (page_size - 1 );
2128
2103
/* the size of data remaining on the first page */
2129
- page_remain = min_t (size_t , page_size - page_offset , len - i );
2130
-
2131
- addr = spi_nor_convert_addr (nor , addr );
2104
+ size_t page_remain = min_t (size_t , page_size - page_offset , len - i );
2132
2105
2133
2106
ret = spi_nor_lock_device (nor );
2134
2107
if (ret )
@@ -2581,8 +2554,51 @@ static int spi_nor_select_erase(struct spi_nor *nor)
2581
2554
return 0 ;
2582
2555
}
2583
2556
2584
- static int spi_nor_default_setup (struct spi_nor * nor ,
2585
- const struct spi_nor_hwcaps * hwcaps )
2557
+ static int spi_nor_set_addr_nbytes (struct spi_nor * nor )
2558
+ {
2559
+ if (nor -> params -> addr_nbytes ) {
2560
+ nor -> addr_nbytes = nor -> params -> addr_nbytes ;
2561
+ } else if (nor -> read_proto == SNOR_PROTO_8_8_8_DTR ) {
2562
+ /*
2563
+ * In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
2564
+ * in this protocol an odd addr_nbytes cannot be used because
2565
+ * then the address phase would only span a cycle and a half.
2566
+ * Half a cycle would be left over. We would then have to start
2567
+ * the dummy phase in the middle of a cycle and so too the data
2568
+ * phase, and we will end the transaction with half a cycle left
2569
+ * over.
2570
+ *
2571
+ * Force all 8D-8D-8D flashes to use an addr_nbytes of 4 to
2572
+ * avoid this situation.
2573
+ */
2574
+ nor -> addr_nbytes = 4 ;
2575
+ } else if (nor -> info -> addr_nbytes ) {
2576
+ nor -> addr_nbytes = nor -> info -> addr_nbytes ;
2577
+ } else {
2578
+ nor -> addr_nbytes = 3 ;
2579
+ }
2580
+
2581
+ if (nor -> addr_nbytes == 3 && nor -> params -> size > 0x1000000 ) {
2582
+ /* enable 4-byte addressing if the device exceeds 16MiB */
2583
+ nor -> addr_nbytes = 4 ;
2584
+ }
2585
+
2586
+ if (nor -> addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES ) {
2587
+ dev_dbg (nor -> dev , "The number of address bytes is too large: %u\n" ,
2588
+ nor -> addr_nbytes );
2589
+ return - EINVAL ;
2590
+ }
2591
+
2592
+ /* Set 4byte opcodes when possible. */
2593
+ if (nor -> addr_nbytes == 4 && nor -> flags & SNOR_F_4B_OPCODES &&
2594
+ !(nor -> flags & SNOR_F_HAS_4BAIT ))
2595
+ spi_nor_set_4byte_opcodes (nor );
2596
+
2597
+ return 0 ;
2598
+ }
2599
+
2600
+ static int spi_nor_setup (struct spi_nor * nor ,
2601
+ const struct spi_nor_hwcaps * hwcaps )
2586
2602
{
2587
2603
struct spi_nor_flash_parameter * params = nor -> params ;
2588
2604
u32 ignored_mask , shared_mask ;
@@ -2639,64 +2655,6 @@ static int spi_nor_default_setup(struct spi_nor *nor,
2639
2655
return err ;
2640
2656
}
2641
2657
2642
- return 0 ;
2643
- }
2644
-
2645
- static int spi_nor_set_addr_nbytes (struct spi_nor * nor )
2646
- {
2647
- if (nor -> params -> addr_nbytes ) {
2648
- nor -> addr_nbytes = nor -> params -> addr_nbytes ;
2649
- } else if (nor -> read_proto == SNOR_PROTO_8_8_8_DTR ) {
2650
- /*
2651
- * In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
2652
- * in this protocol an odd addr_nbytes cannot be used because
2653
- * then the address phase would only span a cycle and a half.
2654
- * Half a cycle would be left over. We would then have to start
2655
- * the dummy phase in the middle of a cycle and so too the data
2656
- * phase, and we will end the transaction with half a cycle left
2657
- * over.
2658
- *
2659
- * Force all 8D-8D-8D flashes to use an addr_nbytes of 4 to
2660
- * avoid this situation.
2661
- */
2662
- nor -> addr_nbytes = 4 ;
2663
- } else if (nor -> info -> addr_nbytes ) {
2664
- nor -> addr_nbytes = nor -> info -> addr_nbytes ;
2665
- } else {
2666
- nor -> addr_nbytes = 3 ;
2667
- }
2668
-
2669
- if (nor -> addr_nbytes == 3 && nor -> params -> size > 0x1000000 ) {
2670
- /* enable 4-byte addressing if the device exceeds 16MiB */
2671
- nor -> addr_nbytes = 4 ;
2672
- }
2673
-
2674
- if (nor -> addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES ) {
2675
- dev_dbg (nor -> dev , "The number of address bytes is too large: %u\n" ,
2676
- nor -> addr_nbytes );
2677
- return - EINVAL ;
2678
- }
2679
-
2680
- /* Set 4byte opcodes when possible. */
2681
- if (nor -> addr_nbytes == 4 && nor -> flags & SNOR_F_4B_OPCODES &&
2682
- !(nor -> flags & SNOR_F_HAS_4BAIT ))
2683
- spi_nor_set_4byte_opcodes (nor );
2684
-
2685
- return 0 ;
2686
- }
2687
-
2688
- static int spi_nor_setup (struct spi_nor * nor ,
2689
- const struct spi_nor_hwcaps * hwcaps )
2690
- {
2691
- int ret ;
2692
-
2693
- if (nor -> params -> setup )
2694
- ret = nor -> params -> setup (nor , hwcaps );
2695
- else
2696
- ret = spi_nor_default_setup (nor , hwcaps );
2697
- if (ret )
2698
- return ret ;
2699
-
2700
2658
return spi_nor_set_addr_nbytes (nor );
2701
2659
}
2702
2660
@@ -2965,15 +2923,10 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
2965
2923
params -> page_size = info -> page_size ?: SPI_NOR_DEFAULT_PAGE_SIZE ;
2966
2924
params -> n_banks = info -> n_banks ?: SPI_NOR_DEFAULT_N_BANKS ;
2967
2925
2968
- if (!( info -> flags & SPI_NOR_NO_FR )) {
2969
- /* Default to Fast Read for DT and non-DT platform devices. */
2926
+ /* Default to Fast Read for non-DT and enable it if requested by DT. */
2927
+ if (! np || of_property_read_bool ( np , "m25p,fast-read" ))
2970
2928
params -> hwcaps .mask |= SNOR_HWCAPS_READ_FAST ;
2971
2929
2972
- /* Mask out Fast Read if not requested at DT instantiation. */
2973
- if (np && !of_property_read_bool (np , "m25p,fast-read" ))
2974
- params -> hwcaps .mask &= ~SNOR_HWCAPS_READ_FAST ;
2975
- }
2976
-
2977
2930
/* (Fast) Read settings. */
2978
2931
params -> hwcaps .mask |= SNOR_HWCAPS_READ ;
2979
2932
spi_nor_set_read_settings (& params -> reads [SNOR_CMD_READ ],
@@ -3055,7 +3008,14 @@ static int spi_nor_init_params(struct spi_nor *nor)
3055
3008
spi_nor_init_params_deprecated (nor );
3056
3009
}
3057
3010
3058
- return spi_nor_late_init_params (nor );
3011
+ ret = spi_nor_late_init_params (nor );
3012
+ if (ret )
3013
+ return ret ;
3014
+
3015
+ if (WARN_ON (!is_power_of_2 (nor -> params -> page_size )))
3016
+ return - EINVAL ;
3017
+
3018
+ return 0 ;
3059
3019
}
3060
3020
3061
3021
/** spi_nor_set_octal_dtr() - enable or disable Octal DTR I/O.
@@ -3338,32 +3298,28 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
3338
3298
3339
3299
if (name )
3340
3300
info = spi_nor_match_name (nor , name );
3341
- /* Try to auto-detect if chip name wasn't specified or not found */
3342
- if (!info )
3343
- return spi_nor_detect (nor );
3344
-
3345
3301
/*
3346
- * If caller has specified name of flash model that can normally be
3347
- * detected using JEDEC, let's verify it.
3302
+ * Auto-detect if chip name wasn't specified or not found, or the chip
3303
+ * has an ID. If the chip supposedly has an ID, we also do an
3304
+ * auto-detection to compare it later.
3348
3305
*/
3349
- if (name && info -> id ) {
3306
+ if (! info || info -> id ) {
3350
3307
const struct flash_info * jinfo ;
3351
3308
3352
3309
jinfo = spi_nor_detect (nor );
3353
- if (IS_ERR (jinfo )) {
3310
+ if (IS_ERR (jinfo ))
3354
3311
return jinfo ;
3355
- } else if (jinfo != info ) {
3356
- /*
3357
- * JEDEC knows better, so overwrite platform ID. We
3358
- * can't trust partitions any longer, but we'll let
3359
- * mtd apply them anyway, since some partitions may be
3360
- * marked read-only, and we don't want to loose that
3361
- * information, even if it's not 100% accurate.
3362
- */
3312
+
3313
+ /*
3314
+ * If caller has specified name of flash model that can normally
3315
+ * be detected using JEDEC, let's verify it.
3316
+ */
3317
+ if (info && jinfo != info )
3363
3318
dev_warn (nor -> dev , "found %s, expected %s\n" ,
3364
3319
jinfo -> name , info -> name );
3365
- info = jinfo ;
3366
- }
3320
+
3321
+ /* If info was set before, JEDEC knows better. */
3322
+ info = jinfo ;
3367
3323
}
3368
3324
3369
3325
return info ;
0 commit comments