bcm63xx: smp: add NAND support
[openwrt/openwrt.git] / target / linux / bcm63xx / patches-5.4 / 437-mtd-rawnand-brcmnand-improve-hamming-oob-layout.patch
1 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
2 +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
3 @@ -1003,33 +1003,30 @@ static int brcmnand_hamming_ooblayout_fr
4 struct brcmnand_cfg *cfg = &host->hwcfg;
5 int sas = cfg->spare_area_size << cfg->sector_size_1k;
6 int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
7 + u32 next;
8
9 - if (section >= sectors * 2)
10 + if (section > sectors)
11 return -ERANGE;
12
13 - oobregion->offset = (section / 2) * sas;
14 + next = (section * sas);
15 + if (section < sectors)
16 + next += 6;
17
18 - if (section & 1) {
19 - oobregion->offset += 9;
20 - oobregion->length = 7;
21 + if (section) {
22 + oobregion->offset = ((section - 1) * sas) + 9;
23 } else {
24 - oobregion->length = 6;
25 -
26 - /* First sector of each page may have BBI */
27 - if (!section) {
28 - /*
29 - * Small-page NAND use byte 6 for BBI while large-page
30 - * NAND use bytes 0 and 1.
31 - */
32 - if (cfg->page_size > 512) {
33 - oobregion->offset += 2;
34 - oobregion->length -= 2;
35 - } else {
36 - oobregion->length--;
37 - }
38 + if (cfg->page_size > 512) {
39 + /* Large page NAND uses first 2 bytes for BBI */
40 + oobregion->offset = 2;
41 + } else {
42 + /* Small page NAND uses last byte before ECC for BBI */
43 + oobregion->offset = 0;
44 + next--;
45 }
46 }
47
48 + oobregion->length = next - oobregion->offset;
49 +
50 return 0;
51 }
52