@@ -1463,23 +1463,13 @@ static void spi_nor_unlock_and_unprep_rd(struct spi_nor *nor, loff_t start, size
14631463 spi_nor_unprep (nor );
14641464}
14651465
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-
14741466/*
14751467 * Initiate the erasure of a single sector
14761468 */
14771469int spi_nor_erase_sector (struct spi_nor * nor , u32 addr )
14781470{
14791471 int i ;
14801472
1481- addr = spi_nor_convert_addr (nor , addr );
1482-
14831473 if (nor -> spimem ) {
14841474 struct spi_mem_op op =
14851475 SPI_NOR_SECTOR_ERASE_OP (nor -> erase_opcode ,
@@ -1986,7 +1976,6 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
19861976 & spi_nor_spansion ,
19871977 & spi_nor_sst ,
19881978 & spi_nor_winbond ,
1989- & spi_nor_xilinx ,
19901979 & spi_nor_xmc ,
19911980};
19921981
@@ -2065,8 +2054,6 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
20652054 while (len ) {
20662055 loff_t addr = from ;
20672056
2068- addr = spi_nor_convert_addr (nor , addr );
2069-
20702057 ret = spi_nor_read_data (nor , addr , len , buf );
20712058 if (ret == 0 ) {
20722059 /* 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,
20992086 size_t * retlen , const u_char * buf )
21002087{
21012088 struct spi_nor * nor = mtd_to_spi_nor (mtd );
2102- size_t page_offset , page_remain , i ;
2089+ size_t i ;
21032090 ssize_t ret ;
21042091 u32 page_size = nor -> params -> page_size ;
21052092
@@ -2112,23 +2099,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
21122099 for (i = 0 ; i < len ; ) {
21132100 ssize_t written ;
21142101 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 );
21282103 /* 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 );
21322105
21332106 ret = spi_nor_lock_device (nor );
21342107 if (ret )
@@ -2581,8 +2554,51 @@ static int spi_nor_select_erase(struct spi_nor *nor)
25812554 return 0 ;
25822555}
25832556
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 )
25862602{
25872603 struct spi_nor_flash_parameter * params = nor -> params ;
25882604 u32 ignored_mask , shared_mask ;
@@ -2639,64 +2655,6 @@ static int spi_nor_default_setup(struct spi_nor *nor,
26392655 return err ;
26402656 }
26412657
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-
27002658 return spi_nor_set_addr_nbytes (nor );
27012659}
27022660
@@ -2965,15 +2923,10 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
29652923 params -> page_size = info -> page_size ?: SPI_NOR_DEFAULT_PAGE_SIZE ;
29662924 params -> n_banks = info -> n_banks ?: SPI_NOR_DEFAULT_N_BANKS ;
29672925
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" ))
29702928 params -> hwcaps .mask |= SNOR_HWCAPS_READ_FAST ;
29712929
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-
29772930 /* (Fast) Read settings. */
29782931 params -> hwcaps .mask |= SNOR_HWCAPS_READ ;
29792932 spi_nor_set_read_settings (& params -> reads [SNOR_CMD_READ ],
@@ -3055,7 +3008,14 @@ static int spi_nor_init_params(struct spi_nor *nor)
30553008 spi_nor_init_params_deprecated (nor );
30563009 }
30573010
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 ;
30593019}
30603020
30613021/** 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,
33383298
33393299 if (name )
33403300 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-
33453301 /*
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.
33483305 */
3349- if (name && info -> id ) {
3306+ if (! info || info -> id ) {
33503307 const struct flash_info * jinfo ;
33513308
33523309 jinfo = spi_nor_detect (nor );
3353- if (IS_ERR (jinfo )) {
3310+ if (IS_ERR (jinfo ))
33543311 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 )
33633318 dev_warn (nor -> dev , "found %s, expected %s\n" ,
33643319 jinfo -> name , info -> name );
3365- info = jinfo ;
3366- }
3320+
3321+ /* If info was set before, JEDEC knows better. */
3322+ info = jinfo ;
33673323 }
33683324
33693325 return info ;
0 commit comments