kernel: Add support spi-nor, Eon EN25QH32
[openwrt/openwrt.git] / target / linux / generic / pending-4.9 / 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 @@ -29,6 +29,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 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 @@ -1642,10 +1642,12 @@ int spi_nor_scan(struct spi_nor *nor, co
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