[dvbmediasink] Remove WMV patch.
[vuplus_openvuplus_3.0] / meta-bsp / vuduo2 / recipes / linux / linux-vuplus-3.3.8 / nand_base.patch
1 diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
2 index 97a48c3..aaba655 100644
3 --- a/drivers/mtd/nand/nand_base.c
4 +++ b/drivers/mtd/nand/nand_base.c
5 @@ -2934,246 +2934,6 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
6  }
7  
8  /*
9 - * nand_id_has_period - Check if an ID string has a given wraparound period
10 - * @id_data: the ID string
11 - * @arrlen: the length of the @id_data array
12 - * @period: the period of repitition
13 - *
14 - * Check if an ID string is repeated within a given sequence of bytes at
15 - * specific repetition interval period (e.g., {0x20,0x01,0x7F,0x20} has a
16 - * period of 2). This is a helper function for nand_id_len(). Returns non-zero
17 - * if the repetition has a period of @period; otherwise, returns zero.
18 - */
19 -static int nand_id_has_period(u8 *id_data, int arrlen, int period)
20 -{
21 -       int i, j;
22 -       for (i = 0; i < period; i++)
23 -               for (j = i + period; j < arrlen; j += period)
24 -                       if (id_data[i] != id_data[j])
25 -                               return 0;
26 -       return 1;
27 -}
28 -
29 -/*
30 - * nand_id_len - Get the length of an ID string returned by CMD_READID
31 - * @id_data: the ID string
32 - * @arrlen: the length of the @id_data array
33 -
34 - * Returns the length of the ID string, according to known wraparound/trailing
35 - * zero patterns. If no pattern exists, returns the length of the array.
36 - */
37 -static int nand_id_len(u8 *id_data, int arrlen)
38 -{
39 -       int last_nonzero, period;
40 -
41 -       /* Find last non-zero byte */
42 -       for (last_nonzero = arrlen - 1; last_nonzero >= 0; last_nonzero--)
43 -               if (id_data[last_nonzero])
44 -                       break;
45 -
46 -       /* All zeros */
47 -       if (last_nonzero < 0)
48 -               return 0;
49 -
50 -       /* Calculate wraparound period */
51 -       for (period = 1; period < arrlen; period++)
52 -               if (nand_id_has_period(id_data, arrlen, period))
53 -                       break;
54 -
55 -       /* There's a repeated pattern */
56 -       if (period < arrlen)
57 -               return period;
58 -
59 -       /* There are trailing zeros */
60 -       if (last_nonzero < arrlen - 1)
61 -               return last_nonzero + 1;
62 -
63 -       /* No pattern detected */
64 -       return arrlen;
65 -}
66 -
67 -/*
68 - * Many new NAND share similar device ID codes, which represent the size of the
69 - * chip. The rest of the parameters must be decoded according to generic or
70 - * manufacturer-specific "extended ID" decoding patterns.
71 - */
72 -static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
73 -                               u8 id_data[8], int *busw)
74 -{
75 -       int extid, id_len;
76 -       /* The 3rd id byte holds MLC / multichip data */
77 -       chip->cellinfo = id_data[2];
78 -       /* The 4th id byte is the important one */
79 -       extid = id_data[3];
80 -
81 -       id_len = nand_id_len(id_data, 8);
82 -
83 -       /*
84 -        * Field definitions are in the following datasheets:
85 -        * Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32)
86 -        * New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44)
87 -        * Hynix MLC   (6 byte ID): Hynix H27UBG8T2B (p.22)
88 -        *
89 -        * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung
90 -        * ID to decide what to do.
91 -        */
92 -       if (id_len == 6 && id_data[0] == NAND_MFR_SAMSUNG &&
93 -                       id_data[5] != 0x00) {
94 -               /* Calc pagesize */
95 -               mtd->writesize = 2048 << (extid & 0x03);
96 -               extid >>= 2;
97 -               /* Calc oobsize */
98 -               switch (((extid >> 2) & 0x04) | (extid & 0x03)) {
99 -               case 1:
100 -                       mtd->oobsize = 128;
101 -                       break;
102 -               case 2:
103 -                       mtd->oobsize = 218;
104 -                       break;
105 -               case 3:
106 -                       mtd->oobsize = 400;
107 -                       break;
108 -               case 4:
109 -                       mtd->oobsize = 436;
110 -                       break;
111 -               case 5:
112 -                       mtd->oobsize = 512;
113 -                       break;
114 -               case 6:
115 -               default: /* Other cases are "reserved" (unknown) */
116 -                       mtd->oobsize = 640;
117 -                       break;
118 -               }
119 -               extid >>= 2;
120 -               /* Calc blocksize */
121 -               mtd->erasesize = (128 * 1024) <<
122 -                       (((extid >> 1) & 0x04) | (extid & 0x03));
123 -               *busw = 0;
124 -       } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX &&
125 -                       (chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
126 -               unsigned int tmp;
127 -
128 -               /* Calc pagesize */
129 -               mtd->writesize = 2048 << (extid & 0x03);
130 -               extid >>= 2;
131 -               /* Calc oobsize */
132 -               switch (((extid >> 2) & 0x04) | (extid & 0x03)) {
133 -               case 0:
134 -                       mtd->oobsize = 128;
135 -                       break;
136 -               case 1:
137 -                       mtd->oobsize = 224;
138 -                       break;
139 -               case 2:
140 -                       mtd->oobsize = 448;
141 -                       break;
142 -               case 3:
143 -                       mtd->oobsize = 64;
144 -                       break;
145 -               case 4:
146 -                       mtd->oobsize = 32;
147 -                       break;
148 -               case 5:
149 -                       mtd->oobsize = 16;
150 -                       break;
151 -               default:
152 -                       mtd->oobsize = 640;
153 -                       break;
154 -               }
155 -               extid >>= 2;
156 -               /* Calc blocksize */
157 -               tmp = ((extid >> 1) & 0x04) | (extid & 0x03);
158 -               if (tmp < 0x03)
159 -                       mtd->erasesize = (128 * 1024) << tmp;
160 -               else if (tmp == 0x03)
161 -                       mtd->erasesize = 768 * 1024;
162 -               else
163 -                       mtd->erasesize = (64 * 1024) << tmp;
164 -               *busw = 0;
165 -       } else {
166 -               /* Calc pagesize */
167 -               mtd->writesize = 1024 << (extid & 0x03);
168 -               extid >>= 2;
169 -               /* Calc oobsize */
170 -               mtd->oobsize = (8 << (extid & 0x01)) *
171 -                       (mtd->writesize >> 9);
172 -               extid >>= 2;
173 -               /* Calc blocksize. Blocksize is multiples of 64KiB */
174 -               mtd->erasesize = (64 * 1024) << (extid & 0x03);
175 -               extid >>= 2;
176 -               /* Get buswidth information */
177 -               *busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0;
178 -       }
179 -}
180 -
181 -/*
182 - * Old devices have chip data hardcoded in the device ID table. nand_decode_id
183 - * decodes a matching ID table entry and assigns the MTD size parameters for
184 - * the chip.
185 - */
186 -static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip,
187 -                               struct nand_flash_dev *type, u8 id_data[8],
188 -                               int *busw)
189 -{
190 -       int maf_id = id_data[0];
191 -
192 -       mtd->erasesize = type->erasesize;
193 -       mtd->writesize = type->pagesize;
194 -       mtd->oobsize = mtd->writesize / 32;
195 -       *busw = type->options & NAND_BUSWIDTH_16;
196 -
197 -       /*
198 -        * Check for Spansion/AMD ID + repeating 5th, 6th byte since
199 -        * some Spansion chips have erasesize that conflicts with size
200 -        * listed in nand_ids table.
201 -        * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39)
202 -        */
203 -       if (maf_id == NAND_MFR_AMD && id_data[4] != 0x00 && id_data[5] == 0x00
204 -                       && id_data[6] == 0x00 && id_data[7] == 0x00
205 -                       && mtd->writesize == 512) {
206 -               mtd->erasesize = 128 * 1024;
207 -               mtd->erasesize <<= ((id_data[3] & 0x03) << 1);
208 -       }
209 -}
210 -
211 -/*
212 - * Set the bad block marker/indicator (BBM/BBI) patterns according to some
213 - * heuristic patterns using various detected parameters (e.g., manufacturer,
214 - * page size, cell-type information).
215 - */
216 -static void nand_decode_bbm_options(struct mtd_info *mtd,
217 -                                   struct nand_chip *chip, u8 id_data[8])
218 -{
219 -       int maf_id = id_data[0];
220 -
221 -       /* Set the bad block position */
222 -       if (mtd->writesize > 512 || (chip->options & NAND_BUSWIDTH_16))
223 -               chip->badblockpos = NAND_LARGE_BADBLOCK_POS;
224 -       else
225 -               chip->badblockpos = NAND_SMALL_BADBLOCK_POS;
226 -
227 -       /*
228 -        * Bad block marker is stored in the last page of each block on Samsung
229 -        * and Hynix MLC devices; stored in first two pages of each block on
230 -        * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba,
231 -        * AMD/Spansion, and Macronix.  All others scan only the first page.
232 -        */
233 -       if ((chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
234 -                       (maf_id == NAND_MFR_SAMSUNG ||
235 -                        maf_id == NAND_MFR_HYNIX))
236 -               chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
237 -       else if ((!(chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
238 -                               (maf_id == NAND_MFR_SAMSUNG ||
239 -                                maf_id == NAND_MFR_HYNIX ||
240 -                                maf_id == NAND_MFR_TOSHIBA ||
241 -                                maf_id == NAND_MFR_AMD ||
242 -                                maf_id == NAND_MFR_MACRONIX)) ||
243 -                       (mtd->writesize == 2048 &&
244 -                        maf_id == NAND_MFR_MICRON))
245 -               chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
246 -}
247 -
248 -/*
249   * Get the flash and manufacturer id and lookup if the type is supported.
250   */
251  static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
252 @@ -3184,6 +2944,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
253  {
254         int i, maf_idx;
255         u8 id_data[8];
256 +       int ret;
257  
258         /* Select the device */
259         chip->select_chip(mtd, 0);
260 @@ -3210,8 +2971,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
261  
262         chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
263  
264 -       /* Read entire ID string */
265 -       for (i = 0; i < 8; i++)
266 +       for (i = 0; i < 2; i++)
267                 id_data[i] = chip->read_byte(mtd);
268  
269         if (id_data[0] != *maf_id || id_data[1] != *dev_id) {
270 @@ -3231,10 +2991,18 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
271         chip->onfi_version = 0;
272         if (!type->name || !type->pagesize) {
273                 /* Check is chip is ONFI compliant */
274 -               if (nand_flash_detect_onfi(mtd, chip, &busw))
275 +               ret = nand_flash_detect_onfi(mtd, chip, &busw);
276 +               if (ret)
277                         goto ident_done;
278         }
279  
280 +       chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
281 +
282 +       /* Read entire ID string */
283 +
284 +       for (i = 0; i < 8; i++)
285 +               id_data[i] = chip->read_byte(mtd);
286 +
287         if (!type->name)
288                 return ERR_PTR(-ENODEV);
289  
290 @@ -3247,10 +3015,82 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
291                 /* Set the pagesize, oobsize, erasesize by the driver */
292                 busw = chip->init_size(mtd, chip, id_data);
293         } else if (!type->pagesize) {
294 -               /* Decode parameters from extended ID */
295 -               nand_decode_ext_id(mtd, chip, id_data, &busw);
296 +               int extid;
297 +               /* The 3rd id byte holds MLC / multichip data */
298 +               chip->cellinfo = id_data[2];
299 +               /* The 4th id byte is the important one */
300 +               extid = id_data[3];
301 +
302 +               /*
303 +                * Field definitions are in the following datasheets:
304 +                * Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32)
305 +                * New style   (6 byte ID): Samsung K9GBG08U0M (p.40)
306 +                *
307 +                * Check for wraparound + Samsung ID + nonzero 6th byte
308 +                * to decide what to do.
309 +                */
310 +               if (id_data[0] == id_data[6] && id_data[1] == id_data[7] &&
311 +                               id_data[0] == NAND_MFR_SAMSUNG &&
312 +                               (chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
313 +                               id_data[5] != 0x00) {
314 +                       /* Calc pagesize */
315 +                       mtd->writesize = 2048 << (extid & 0x03);
316 +                       extid >>= 2;
317 +                       /* Calc oobsize */
318 +                       switch (extid & 0x03) {
319 +                       case 1:
320 +                               mtd->oobsize = 128;
321 +                               break;
322 +                       case 2:
323 +                               mtd->oobsize = 218;
324 +                               break;
325 +                       case 3:
326 +                               mtd->oobsize = 400;
327 +                               break;
328 +                       default:
329 +                               mtd->oobsize = 436;
330 +                               break;
331 +                       }
332 +                       extid >>= 2;
333 +                       /* Calc blocksize */
334 +                       mtd->erasesize = (128 * 1024) <<
335 +                               (((extid >> 1) & 0x04) | (extid & 0x03));
336 +                       busw = 0;
337 +               } else {
338 +                       /* Calc pagesize */
339 +                       mtd->writesize = 1024 << (extid & 0x03);
340 +                       extid >>= 2;
341 +                       /* Calc oobsize */
342 +                       mtd->oobsize = (8 << (extid & 0x01)) *
343 +                               (mtd->writesize >> 9);
344 +                       extid >>= 2;
345 +                       /* Calc blocksize. Blocksize is multiples of 64KiB */
346 +                       mtd->erasesize = (64 * 1024) << (extid & 0x03);
347 +                       extid >>= 2;
348 +                       /* Get buswidth information */
349 +                       busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0;
350 +               }
351         } else {
352 -               nand_decode_id(mtd, chip, type, id_data, &busw);
353 +               /*
354 +                * Old devices have chip data hardcoded in the device id table.
355 +                */
356 +               mtd->erasesize = type->erasesize;
357 +               mtd->writesize = type->pagesize;
358 +               mtd->oobsize = mtd->writesize / 32;
359 +               busw = type->options & NAND_BUSWIDTH_16;
360 +
361 +               /*
362 +                * Check for Spansion/AMD ID + repeating 5th, 6th byte since
363 +                * some Spansion chips have erasesize that conflicts with size
364 +                * listed in nand_ids table.
365 +                * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39)
366 +                */
367 +               if (*maf_id == NAND_MFR_AMD && id_data[4] != 0x00 &&
368 +                               id_data[5] == 0x00 && id_data[6] == 0x00 &&
369 +                               id_data[7] == 0x00 && mtd->writesize == 512) {
370 +                       mtd->erasesize = 128 * 1024;
371 +                       mtd->erasesize <<= ((id_data[3] & 0x03) << 1);
372 +               }
373         }
374         /* Get chip options, preserve non chip based options */
375         chip->options &= ~NAND_CHIPOPTIONS_MSK;
376 @@ -3284,8 +3124,6 @@ ident_done:
377                 return ERR_PTR(-EINVAL);
378         }
379  
380 -       nand_decode_bbm_options(mtd, chip, id_data);
381 -
382         /* Calculate the address shift from the page size */
383         chip->page_shift = ffs(mtd->writesize) - 1;
384         /* Convert chipsize to number of pages per chip -1 */
385 @@ -3302,6 +3140,33 @@ ident_done:
386  
387         chip->badblockbits = 8;
388  
389 +       /* Set the bad block position */
390 +       if (mtd->writesize > 512 || (busw & NAND_BUSWIDTH_16))
391 +               chip->badblockpos = NAND_LARGE_BADBLOCK_POS;
392 +       else
393 +               chip->badblockpos = NAND_SMALL_BADBLOCK_POS;
394 +
395 +       /*
396 +        * Bad block marker is stored in the last page of each block
397 +        * on Samsung and Hynix MLC devices; stored in first two pages
398 +        * of each block on Micron devices with 2KiB pages and on
399 +        * SLC Samsung, Hynix, Toshiba, AMD/Spansion, and Macronix.
400 +        * All others scan only the first page.
401 +        */
402 +       if ((chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
403 +                       (*maf_id == NAND_MFR_SAMSUNG ||
404 +                        *maf_id == NAND_MFR_HYNIX))
405 +               chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
406 +       else if ((!(chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
407 +                               (*maf_id == NAND_MFR_SAMSUNG ||
408 +                                *maf_id == NAND_MFR_HYNIX ||
409 +                                *maf_id == NAND_MFR_TOSHIBA ||
410 +                                *maf_id == NAND_MFR_AMD ||
411 +                                *maf_id == NAND_MFR_MACRONIX)) ||
412 +                       (mtd->writesize == 2048 &&
413 +                        *maf_id == NAND_MFR_MICRON))
414 +               chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
415 +
416         /* Check for AND chips with 4 page planes */
417         if (chip->options & NAND_4PAGE_ARRAY)
418                 chip->erase_cmd = multi_erase_cmd;