1 From d00358d7a1c50718232799e1ee10955bcd73795a Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari@gmail.com>
3 Date: Tue, 12 May 2020 09:57:33 +0200
4 Subject: [PATCH] mtd: rawnand: brcmnand: improve hamming oob layout
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 The current code generates 8 oob sections:
23 Change it by merging continuous sections:
34 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
35 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
36 Link: https://lore.kernel.org/linux-mtd/20200512075733.745374-3-noltari@gmail.com
38 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 35 +++++++++++-------------
39 1 file changed, 16 insertions(+), 19 deletions(-)
41 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
42 +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
43 @@ -1003,33 +1003,30 @@ static int brcmnand_hamming_ooblayout_fr
44 struct brcmnand_cfg *cfg = &host->hwcfg;
45 int sas = cfg->spare_area_size << cfg->sector_size_1k;
46 int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
49 - if (section >= sectors * 2)
50 + if (section > sectors)
53 - oobregion->offset = (section / 2) * sas;
54 + next = (section * sas);
55 + if (section < sectors)
59 - oobregion->offset += 9;
60 - oobregion->length = 7;
62 + oobregion->offset = ((section - 1) * sas) + 9;
64 - oobregion->length = 6;
66 - /* First sector of each page may have BBI */
69 - * Small-page NAND use byte 6 for BBI while large-page
70 - * NAND use bytes 0 and 1.
72 - if (cfg->page_size > 512) {
73 - oobregion->offset += 2;
74 - oobregion->length -= 2;
76 - oobregion->length--;
78 + if (cfg->page_size > 512) {
79 + /* Large page NAND uses first 2 bytes for BBI */
80 + oobregion->offset = 2;
82 + /* Small page NAND uses last byte before ECC for BBI */
83 + oobregion->offset = 0;
88 + oobregion->length = next - oobregion->offset;