mtd: rawnand: ingenic: Add ooblayout for the Qi Ben Nanonote
authorPaul Cercueil <paul@crapouillou.net>
Tue, 19 Mar 2019 14:54:02 +0000 (15:54 +0100)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 8 Apr 2019 08:21:06 +0000 (10:21 +0200)
The Ben Nanonote from Qi Hardware expects a specific OOB layout on its
NAND.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/nand/raw/ingenic/ingenic_nand.c

index a2450e1..d32d68e 100644 (file)
@@ -72,6 +72,41 @@ static inline struct ingenic_nfc *to_ingenic_nfc(struct nand_controller *ctrl)
        return container_of(ctrl, struct ingenic_nfc, controller);
 }
 
+static int qi_lb60_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct nand_ecc_ctrl *ecc = &chip->ecc;
+
+       if (section || !ecc->total)
+               return -ERANGE;
+
+       oobregion->length = ecc->total;
+       oobregion->offset = 12;
+
+       return 0;
+}
+
+static int qi_lb60_ooblayout_free(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct nand_ecc_ctrl *ecc = &chip->ecc;
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->length = mtd->oobsize - ecc->total - 12;
+       oobregion->offset = 12 + ecc->total;
+
+       return 0;
+}
+
+const struct mtd_ooblayout_ops qi_lb60_ooblayout_ops = {
+       .ecc = qi_lb60_ooblayout_ecc,
+       .free = qi_lb60_ooblayout_free,
+};
+
 static int jz4725b_ooblayout_ecc(struct mtd_info *mtd, int section,
                                 struct mtd_oob_region *oobregion)
 {
@@ -247,7 +282,11 @@ static int ingenic_nand_attach_chip(struct nand_chip *chip)
                return -EINVAL;
        }
 
-       mtd_set_ooblayout(mtd, nfc->soc_info->oob_layout);
+       /* For legacy reasons we use a different layout on the qi,lb60 board. */
+       if (of_machine_is_compatible("qi,lb60"))
+               mtd_set_ooblayout(mtd, &qi_lb60_ooblayout_ops);
+       else
+               mtd_set_ooblayout(mtd, nfc->soc_info->oob_layout);
 
        return 0;
 }