b77ab89e666e5dae330a605a875cf3786e131b4b
[oweals/openwrt.git] / target / linux / ipq40xx / patches-4.14 / 303-spi-nor-enable-4B-opcodes-for-mx25l25635f.patch
1 --- a/drivers/mtd/spi-nor/spi-nor.c
2 +++ b/drivers/mtd/spi-nor/spi-nor.c
3 @@ -1032,6 +1032,7 @@ static const struct flash_info spi_nor_i
4         { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
5         { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
6         { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
7 +       { "mx25l25635f", INFO(0xc22019, 0, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
8         { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_4B_OPCODES) },
9         { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
10         { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
11 @@ -1205,11 +1206,12 @@ static const struct flash_info spi_nor_i
12         { },
13  };
14  
15 -static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
16 +static const struct flash_info *spi_nor_read_id(struct spi_nor *nor,
17 +                                               const char *name)
18  {
19         int                     tmp;
20         u8                      id[SPI_NOR_MAX_ID_LEN];
21 -       const struct flash_info *info;
22 +       const struct flash_info *info, *first_match = NULL;
23  
24         tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN);
25         if (tmp < 0) {
26 @@ -1220,10 +1222,16 @@ static const struct flash_info *spi_nor_
27         for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
28                 info = &spi_nor_ids[tmp];
29                 if (info->id_len) {
30 -                       if (!memcmp(info->id, id, info->id_len))
31 -                               return &spi_nor_ids[tmp];
32 +                       if (!memcmp(info->id, id, info->id_len)) {
33 +                               if (!name || !strcmp(name, info->name))
34 +                                       return info;
35 +                               if (!first_match)
36 +                                       first_match = info;
37 +                       }
38                 }
39         }
40 +       if (first_match)
41 +               return first_match;
42         dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %02x, %02x\n",
43                 id[0], id[1], id[2]);
44         return ERR_PTR(-ENODEV);
45 @@ -2683,7 +2691,7 @@ int spi_nor_scan(struct spi_nor *nor, co
46                 info = spi_nor_match_id(name);
47         /* Try to auto-detect if chip name wasn't specified or not found */
48         if (!info)
49 -               info = spi_nor_read_id(nor);
50 +               info = spi_nor_read_id(nor, NULL);
51         if (IS_ERR_OR_NULL(info))
52                 return -ENOENT;
53  
54 @@ -2694,7 +2702,7 @@ int spi_nor_scan(struct spi_nor *nor, co
55         if (name && info->id_len) {
56                 const struct flash_info *jinfo;
57  
58 -               jinfo = spi_nor_read_id(nor);
59 +               jinfo = spi_nor_read_id(nor, name);
60                 if (IS_ERR(jinfo)) {
61                         return PTR_ERR(jinfo);
62                 } else if (jinfo != info) {