@@ -2554,8 +2554,51 @@ static int spi_nor_select_erase(struct spi_nor *nor)
25542554 return 0 ;
25552555}
25562556
2557- static int spi_nor_default_setup (struct spi_nor * nor ,
2558- 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 )
25592602{
25602603 struct spi_nor_flash_parameter * params = nor -> params ;
25612604 u32 ignored_mask , shared_mask ;
@@ -2612,64 +2655,6 @@ static int spi_nor_default_setup(struct spi_nor *nor,
26122655 return err ;
26132656 }
26142657
2615- return 0 ;
2616- }
2617-
2618- static int spi_nor_set_addr_nbytes (struct spi_nor * nor )
2619- {
2620- if (nor -> params -> addr_nbytes ) {
2621- nor -> addr_nbytes = nor -> params -> addr_nbytes ;
2622- } else if (nor -> read_proto == SNOR_PROTO_8_8_8_DTR ) {
2623- /*
2624- * In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
2625- * in this protocol an odd addr_nbytes cannot be used because
2626- * then the address phase would only span a cycle and a half.
2627- * Half a cycle would be left over. We would then have to start
2628- * the dummy phase in the middle of a cycle and so too the data
2629- * phase, and we will end the transaction with half a cycle left
2630- * over.
2631- *
2632- * Force all 8D-8D-8D flashes to use an addr_nbytes of 4 to
2633- * avoid this situation.
2634- */
2635- nor -> addr_nbytes = 4 ;
2636- } else if (nor -> info -> addr_nbytes ) {
2637- nor -> addr_nbytes = nor -> info -> addr_nbytes ;
2638- } else {
2639- nor -> addr_nbytes = 3 ;
2640- }
2641-
2642- if (nor -> addr_nbytes == 3 && nor -> params -> size > 0x1000000 ) {
2643- /* enable 4-byte addressing if the device exceeds 16MiB */
2644- nor -> addr_nbytes = 4 ;
2645- }
2646-
2647- if (nor -> addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES ) {
2648- dev_dbg (nor -> dev , "The number of address bytes is too large: %u\n" ,
2649- nor -> addr_nbytes );
2650- return - EINVAL ;
2651- }
2652-
2653- /* Set 4byte opcodes when possible. */
2654- if (nor -> addr_nbytes == 4 && nor -> flags & SNOR_F_4B_OPCODES &&
2655- !(nor -> flags & SNOR_F_HAS_4BAIT ))
2656- spi_nor_set_4byte_opcodes (nor );
2657-
2658- return 0 ;
2659- }
2660-
2661- static int spi_nor_setup (struct spi_nor * nor ,
2662- const struct spi_nor_hwcaps * hwcaps )
2663- {
2664- int ret ;
2665-
2666- if (nor -> params -> setup )
2667- ret = nor -> params -> setup (nor , hwcaps );
2668- else
2669- ret = spi_nor_default_setup (nor , hwcaps );
2670- if (ret )
2671- return ret ;
2672-
26732658 return spi_nor_set_addr_nbytes (nor );
26742659}
26752660
0 commit comments