v1.5 branch refresh based upon upstream master @ c8677ca89e53e3be7988d54280fce166cc894a7e
[librecmc/librecmc.git] / target / linux / generic / pending-4.14 / 470-mtd-spi-nor-support-limiting-4K-sectors-support-base.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sat, 4 Nov 2017 07:40:23 +0100
3 Subject: [PATCH] mtd: spi-nor: support limiting 4K sectors support based on
4  flash size
5
6 Some devices need 4K sectors to be able to deal with small flash chips.
7 For instance, w25x05 is 64 KiB in size, and without 4K sectors, the
8 entire chip is just one erase block.
9 On bigger flash chip sizes, using 4K sectors can significantly slow down
10 many operations, including using a writable filesystem. There are several
11 platforms where it makes sense to use a single kernel on both kinds of
12 devices.
13
14 To support this properly, allow configuring an upper flash chip size
15 limit for 4K sectors support.
16
17 Signed-off-by: Felix Fietkau <nbd@nbd.name>
18 ---
19
20 --- a/drivers/mtd/spi-nor/Kconfig
21 +++ b/drivers/mtd/spi-nor/Kconfig
22 @@ -39,6 +39,17 @@ config SPI_ASPEED_SMC
23           and support for the SPI flash memory controller (SPI) for
24           the host firmware. The implementation only supports SPI NOR.
25  
26 +config MTD_SPI_NOR_USE_4K_SECTORS_LIMIT
27 +       int "Maximum flash chip size to use 4K sectors on (in KiB)"
28 +       depends on MTD_SPI_NOR_USE_4K_SECTORS
29 +       default "4096"
30 +       help
31 +         There are many flash chips that support 4K sectors, but are so large
32 +         that using them significantly slows down writing large amounts of
33 +         data or using a writable filesystem.
34 +         Any flash chip larger than the size specified in this option will
35 +         not use 4K sectors.
36 +
37  config SPI_ATMEL_QUADSPI
38         tristate "Atmel Quad SPI Controller"
39         depends on ARCH_AT91 || (ARM && COMPILE_TEST)
40 --- a/drivers/mtd/spi-nor/spi-nor.c
41 +++ b/drivers/mtd/spi-nor/spi-nor.c
42 @@ -2555,10 +2555,12 @@ static int spi_nor_select_erase(struct s
43  
44  #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
45         /* prefer "small sector" erase if possible */
46 -       if (info->flags & SECT_4K) {
47 +       if ((info->flags & SECT_4K) && (mtd->size <=
48 +           CONFIG_MTD_SPI_NOR_USE_4K_SECTORS_LIMIT * 1024)) {
49                 nor->erase_opcode = SPINOR_OP_BE_4K;
50                 mtd->erasesize = 4096;
51 -       } else if (info->flags & SECT_4K_PMC) {
52 +       } else if ((info->flags & SECT_4K_PMC) && (mtd->size <=
53 +                  CONFIG_MTD_SPI_NOR_USE_4K_SECTORS_LIMIT * 1024)) {
54                 nor->erase_opcode = SPINOR_OP_BE_4K_PMC;
55                 mtd->erasesize = 4096;
56         } else