bcm53xx: backport spi-nor changes and update bcm53xxspiflash
[openwrt.git] / target / linux / bcm53xx / patches-3.14 / 002-mtd-spi-nor-from-3.18.patch
1 --- a/drivers/mtd/spi-nor/spi-nor.c
2 +++ b/drivers/mtd/spi-nor/spi-nor.c
3 @@ -28,6 +28,8 @@
4  
5  #define JEDEC_MFR(_jedec_id)   ((_jedec_id) >> 16)
6  
7 +static const struct spi_device_id *spi_nor_match_id(const char *name);
8 +
9  /*
10   * Read the status register, returning its value in the location
11   * Return the status register value.
12 @@ -473,7 +475,7 @@ struct flash_info {
13   * more nor chips.  This current list focusses on newer chips, which
14   * have been converging on command sets which including JEDEC ID.
15   */
16 -const struct spi_device_id spi_nor_ids[] = {
17 +static const struct spi_device_id spi_nor_ids[] = {
18         /* Atmel -- some are (confusingly) marketed as "DataFlash" */
19         { "at25fs010",  INFO(0x1f6601, 0, 32 * 1024,   4, SECT_4K) },
20         { "at25fs040",  INFO(0x1f6604, 0, 64 * 1024,   8, SECT_4K) },
21 @@ -611,6 +613,7 @@ const struct spi_device_id spi_nor_ids[]
22         { "m25px32-s0", INFO(0x207316,  0, 64 * 1024, 64, SECT_4K) },
23         { "m25px32-s1", INFO(0x206316,  0, 64 * 1024, 64, SECT_4K) },
24         { "m25px64",    INFO(0x207117,  0, 64 * 1024, 128, 0) },
25 +       { "m25px80",    INFO(0x207114,  0, 64 * 1024, 16, 0) },
26  
27         /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */
28         { "w25x10", INFO(0xef3011, 0, 64 * 1024,  2,  SECT_4K) },
29 @@ -623,7 +626,6 @@ const struct spi_device_id spi_nor_ids[]
30         { "w25q32dw", INFO(0xef6016, 0, 64 * 1024,  64, SECT_4K) },
31         { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) },
32         { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) },
33 -       { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) },
34         { "w25q80", INFO(0xef5014, 0, 64 * 1024,  16, SECT_4K) },
35         { "w25q80bl", INFO(0xef4014, 0, 64 * 1024,  16, SECT_4K) },
36         { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) },
37 @@ -637,7 +639,6 @@ const struct spi_device_id spi_nor_ids[]
38         { "cat25128", CAT25_INFO(2048, 8, 64, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) },
39         { },
40  };
41 -EXPORT_SYMBOL_GPL(spi_nor_ids);
42  
43  static const struct spi_device_id *spi_nor_read_id(struct spi_nor *nor)
44  {
45 @@ -671,11 +672,6 @@ static const struct spi_device_id *spi_n
46         return ERR_PTR(-ENODEV);
47  }
48  
49 -static const struct spi_device_id *jedec_probe(struct spi_nor *nor)
50 -{
51 -       return nor->read_id(nor);
52 -}
53 -
54  static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
55                         size_t *retlen, u_char *buf)
56  {
57 @@ -916,11 +912,10 @@ static int spi_nor_check(struct spi_nor
58         return 0;
59  }
60  
61 -int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
62 -                       enum read_mode mode)
63 +int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
64  {
65 +       const struct spi_device_id      *id = NULL;
66         struct flash_info               *info;
67 -       struct flash_platform_data      *data;
68         struct device *dev = nor->dev;
69         struct mtd_info *mtd = nor->mtd;
70         struct device_node *np = dev->of_node;
71 @@ -931,34 +926,16 @@ int spi_nor_scan(struct spi_nor *nor, co
72         if (ret)
73                 return ret;
74  
75 -       /* Platform data helps sort out which chip type we have, as
76 -        * well as how this board partitions it.  If we don't have
77 -        * a chip ID, try the JEDEC id commands; they'll work for most
78 -        * newer chips, even if we don't recognize the particular chip.
79 -        */
80 -       data = dev_get_platdata(dev);
81 -       if (data && data->type) {
82 -               const struct spi_device_id *plat_id;
83 -
84 -               for (i = 0; i < ARRAY_SIZE(spi_nor_ids) - 1; i++) {
85 -                       plat_id = &spi_nor_ids[i];
86 -                       if (strcmp(data->type, plat_id->name))
87 -                               continue;
88 -                       break;
89 -               }
90 -
91 -               if (i < ARRAY_SIZE(spi_nor_ids) - 1)
92 -                       id = plat_id;
93 -               else
94 -                       dev_warn(dev, "unrecognized id %s\n", data->type);
95 -       }
96 +       id = spi_nor_match_id(name);
97 +       if (!id)
98 +               return -ENOENT;
99  
100         info = (void *)id->driver_data;
101  
102         if (info->jedec_id) {
103                 const struct spi_device_id *jid;
104  
105 -               jid = jedec_probe(nor);
106 +               jid = nor->read_id(nor);
107                 if (IS_ERR(jid)) {
108                         return PTR_ERR(jid);
109                 } else if (jid != id) {
110 @@ -990,11 +967,8 @@ int spi_nor_scan(struct spi_nor *nor, co
111                 write_sr(nor, 0);
112         }
113  
114 -       if (data && data->name)
115 -               mtd->name = data->name;
116 -       else
117 +       if (!mtd->name)
118                 mtd->name = dev_name(dev);
119 -
120         mtd->type = MTD_NORFLASH;
121         mtd->writesize = 1;
122         mtd->flags = MTD_CAP_NORFLASH;
123 @@ -1018,6 +992,7 @@ int spi_nor_scan(struct spi_nor *nor, co
124             nor->wait_till_ready == spi_nor_wait_till_ready)
125                 nor->wait_till_ready = spi_nor_wait_till_fsr_ready;
126  
127 +#ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
128         /* prefer "small sector" erase if possible */
129         if (info->flags & SECT_4K) {
130                 nor->erase_opcode = SPINOR_OP_BE_4K;
131 @@ -1025,7 +1000,9 @@ int spi_nor_scan(struct spi_nor *nor, co
132         } else if (info->flags & SECT_4K_PMC) {
133                 nor->erase_opcode = SPINOR_OP_BE_4K_PMC;
134                 mtd->erasesize = 4096;
135 -       } else {
136 +       } else
137 +#endif
138 +       {
139                 nor->erase_opcode = SPINOR_OP_SE;
140                 mtd->erasesize = info->sector_size;
141         }
142 @@ -1141,7 +1118,7 @@ int spi_nor_scan(struct spi_nor *nor, co
143  }
144  EXPORT_SYMBOL_GPL(spi_nor_scan);
145  
146 -const struct spi_device_id *spi_nor_match_id(char *name)
147 +static const struct spi_device_id *spi_nor_match_id(const char *name)
148  {
149         const struct spi_device_id *id = spi_nor_ids;
150  
151 @@ -1152,7 +1129,6 @@ const struct spi_device_id *spi_nor_matc
152         }
153         return NULL;
154  }
155 -EXPORT_SYMBOL_GPL(spi_nor_match_id);
156  
157  MODULE_LICENSE("GPL");
158  MODULE_AUTHOR("Huang Shijie <shijie8@gmail.com>");
159 --- a/drivers/mtd/spi-nor/Kconfig
160 +++ b/drivers/mtd/spi-nor/Kconfig
161 @@ -7,6 +7,20 @@ menuconfig MTD_SPI_NOR
162  
163  if MTD_SPI_NOR
164  
165 +config MTD_SPI_NOR_USE_4K_SECTORS
166 +       bool "Use small 4096 B erase sectors"
167 +       default y
168 +       help
169 +         Many flash memories support erasing small (4096 B) sectors. Depending
170 +         on the usage this feature may provide performance gain in comparison
171 +         to erasing whole blocks (32/64 KiB).
172 +         Changing a small part of the flash's contents is usually faster with
173 +         small sectors. On the other hand erasing should be faster when using
174 +         64 KiB block instead of 16 × 4 KiB sectors.
175 +
176 +         Please note that some tools/drivers/filesystems may not work with
177 +         4096 B erase size (e.g. UBIFS requires 15 KiB as a minimum).
178 +
179  config SPI_FSL_QUADSPI
180         tristate "Freescale Quad SPI controller"
181         depends on ARCH_MXC
182 --- a/include/linux/mtd/spi-nor.h
183 +++ b/include/linux/mtd/spi-nor.h
184 @@ -187,32 +187,17 @@ struct spi_nor {
185  /**
186   * spi_nor_scan() - scan the SPI NOR
187   * @nor:       the spi_nor structure
188 - * @id:                the spi_device_id provided by the driver
189 + * @name:      the chip type name
190   * @mode:      the read mode supported by the driver
191   *
192   * The drivers can use this fuction to scan the SPI NOR.
193   * In the scanning, it will try to get all the necessary information to
194   * fill the mtd_info{} and the spi_nor{}.
195   *
196 - * The board may assigns a spi_device_id with @id which be used to compared with
197 - * the spi_device_id detected by the scanning.
198 + * The chip type name can be provided through the @name parameter.
199   *
200   * Return: 0 for success, others for failure.
201   */
202 -int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
203 -                       enum read_mode mode);
204 -extern const struct spi_device_id spi_nor_ids[];
205 -
206 -/**
207 - * spi_nor_match_id() - find the spi_device_id by the name
208 - * @name:      the name of the spi_device_id
209 - *
210 - * The drivers use this function to find the spi_device_id
211 - * specified by the @name.
212 - *
213 - * Return: returns the right spi_device_id pointer on success,
214 - *         and returns NULL on failure.
215 - */
216 -const struct spi_device_id *spi_nor_match_id(char *name);
217 +int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode);
218  
219  #endif