2748192dd27506343f269ddb70a122513af27390
[openwrt/staging/ansuel.git] / target / linux / generic / pending-5.10 / 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 @@ -34,6 +34,17 @@ config MTD_SPI_NOR_USE_4K_SECTORS
23 Please note that some tools/drivers/filesystems may not work with
24 4096 B erase size (e.g. UBIFS requires 15 KiB as a minimum).
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 source "drivers/mtd/spi-nor/controllers/Kconfig"
38
39 endif # MTD_SPI_NOR
40 --- a/drivers/mtd/spi-nor/core.c
41 +++ b/drivers/mtd/spi-nor/core.c
42 @@ -2792,6 +2792,21 @@ static void spi_nor_info_init_params(str
43 */
44 erase_mask = 0;
45 i = 0;
46 +#ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
47 + if ((info->flags & SECT_4K_PMC) && (params->size <=
48 + CONFIG_MTD_SPI_NOR_USE_4K_SECTORS_LIMIT * 1024)) {
49 + erase_mask |= BIT(i);
50 + spi_nor_set_erase_type(&map->erase_type[i], 4096u,
51 + SPINOR_OP_BE_4K_PMC);
52 + i++;
53 + } else if ((info->flags & SECT_4K) && (params->size <=
54 + CONFIG_MTD_SPI_NOR_USE_4K_SECTORS_LIMIT * 1024)) {
55 + erase_mask |= BIT(i);
56 + spi_nor_set_erase_type(&map->erase_type[i], 4096u,
57 + SPINOR_OP_BE_4K);
58 + i++;
59 + }
60 +#else
61 if (info->flags & SECT_4K_PMC) {
62 erase_mask |= BIT(i);
63 spi_nor_set_erase_type(&map->erase_type[i], 4096u,
64 @@ -2803,6 +2818,7 @@ static void spi_nor_info_init_params(str
65 SPINOR_OP_BE_4K);
66 i++;
67 }
68 +#endif
69 erase_mask |= BIT(i);
70 spi_nor_set_erase_type(&map->erase_type[i], info->sector_size,
71 SPINOR_OP_SE);