ramips: preliminary support for 4.14
[oweals/openwrt.git] / target / linux / ramips / patches-4.14 / 303-spi-nor-enable-4B-opcodes-for-mx66l51235l.patch
1 --- a/drivers/mtd/spi-nor/spi-nor.c
2 +++ b/drivers/mtd/spi-nor/spi-nor.c
3 @@ -1083,7 +1083,7 @@ static const struct flash_info spi_nor_i
4         { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
5         { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_4B_OPCODES) },
6         { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
7 -       { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
8 +       { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
9         { "mx66u51235f", INFO(0xc2253a, 0, 64 * 1024, 1024, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
10         { "mx66l1g45g",  INFO(0xc2201b, 0, 64 * 1024, 2048, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
11         { "mx66l1g55g",  INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) },
12 @@ -1947,7 +1947,11 @@ static int spi_nor_read_sfdp(struct spi_
13         nor->read_dummy = 8;
14  
15         while (len) {
16 -               ret = nor->read(nor, addr, len, (u8 *)buf);
17 +               size_t _len = len;
18 +
19 +               if (nor->chunk_size)
20 +                       _len = min(len, nor->chunk_size);
21 +               ret = nor->read(nor, addr, _len, (u8 *)buf);
22                 if (!ret || ret > len) {
23                         ret = -EIO;
24                         goto read_err;
25 @@ -2791,6 +2795,7 @@ int spi_nor_scan(struct spi_nor *nor, co
26         struct device *dev = nor->dev;
27         struct mtd_info *mtd = &nor->mtd;
28         struct device_node *np = spi_nor_get_flash_node(nor);
29 +       u32 val;
30         int ret;
31         int i;
32  
33 @@ -2803,6 +2808,9 @@ int spi_nor_scan(struct spi_nor *nor, co
34         nor->read_proto = SNOR_PROTO_1_1_1;
35         nor->write_proto = SNOR_PROTO_1_1_1;
36  
37 +       if (np && !of_property_read_u32(np, "m25p,chunked-io", &val))
38 +               nor->chunk_size = val;
39 +
40         if (name)
41                 info = spi_nor_match_id(name);
42         /* Try to auto-detect if chip name wasn't specified or not found */
43 @@ -2916,19 +2924,16 @@ int spi_nor_scan(struct spi_nor *nor, co
44         mtd->writebufsize = nor->page_size;
45  
46         if (np) {
47 -               u32 val;
48 -
49                 /* If we were instantiated by DT, use it */
50                 if (of_property_read_bool(np, "m25p,fast-read"))
51                         params.hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
52                 else
53                         params.hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
54  
55 -               if (!of_property_read_u32(np, "m25p,chunked-io", &val)) {
56 -                       dev_info(dev, "using chunked io (size=%d)\n", val);
57 +               if (nor->chunk_size) {
58 +                       dev_info(dev, "using chunked io (size=%d)\n", nor->chunk_size);
59                         mtd->_read = spi_nor_chunked_read;
60                         mtd->_write = spi_nor_chunked_write;
61 -                       nor->chunk_size = val;
62                 }
63         } else {
64                 /* If we weren't instantiated by DT, default to fast-read */