Skip to content

Commit d0b806f

Browse files
marcusfolkessonmiquelraynal
authored andcommitted
mtd: rawnand: davinci: add ROM supported OOB layout
Add support for the OOB layout used by the ROM bootloader. The same layout is used by both Keystone [1] and OMAPL138/DA850 [2] which currently is the only users of davinci-nand. Only select this layout if the `nand-is-boot-medium` property is set. This to avoid breaking any existing devices out there. [1] https://www.ti.com/lit/ug/spruhj3/spruhj3.pdf [2] https://www.ti.com/lit/an/sprab41f/sprab41f.pdf Signed-off-by: Marcus Folkesson <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 6df2d95 commit d0b806f

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

drivers/mtd/nand/raw/davinci_nand.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,44 @@ static const struct mtd_ooblayout_ops hwecc4_small_ooblayout_ops = {
488488
.free = hwecc4_ooblayout_small_free,
489489
};
490490

491+
static int hwecc4_ooblayout_large_ecc(struct mtd_info *mtd, int section,
492+
struct mtd_oob_region *oobregion)
493+
{
494+
struct nand_device *nand = mtd_to_nanddev(mtd);
495+
unsigned int total_ecc_bytes = nand->ecc.ctx.total;
496+
int nregions = total_ecc_bytes / 10; /* 10 bytes per chunk */
497+
498+
if (section >= nregions)
499+
return -ERANGE;
500+
501+
oobregion->offset = (section * 16) + 6;
502+
oobregion->length = 10;
503+
504+
return 0;
505+
}
506+
507+
static int hwecc4_ooblayout_large_free(struct mtd_info *mtd, int section,
508+
struct mtd_oob_region *oobregion)
509+
{
510+
struct nand_device *nand = mtd_to_nanddev(mtd);
511+
unsigned int total_ecc_bytes = nand->ecc.ctx.total;
512+
int nregions = total_ecc_bytes / 10; /* 10 bytes per chunk */
513+
514+
/* First region is used for BBT */
515+
if (section >= (nregions - 1))
516+
return -ERANGE;
517+
518+
oobregion->offset = ((section + 1) * 16);
519+
oobregion->length = 6;
520+
521+
return 0;
522+
}
523+
524+
static const struct mtd_ooblayout_ops hwecc4_large_ooblayout_ops = {
525+
.ecc = hwecc4_ooblayout_large_ecc,
526+
.free = hwecc4_ooblayout_large_free,
527+
};
528+
491529
#if defined(CONFIG_OF)
492530
static const struct of_device_id davinci_nand_of_match[] = {
493531
{.compatible = "ti,davinci-nand", },
@@ -650,9 +688,12 @@ static int davinci_nand_attach_chip(struct nand_chip *chip)
650688
mtd_set_ooblayout(mtd,
651689
&hwecc4_small_ooblayout_ops);
652690
} else if (chunks == 4 || chunks == 8) {
653-
mtd_set_ooblayout(mtd,
654-
nand_get_large_page_ooblayout());
655691
chip->ecc.read_page = nand_read_page_hwecc_oob_first;
692+
693+
if (chip->options & NAND_IS_BOOT_MEDIUM)
694+
mtd_set_ooblayout(mtd, &hwecc4_large_ooblayout_ops);
695+
else
696+
mtd_set_ooblayout(mtd, nand_get_large_page_ooblayout());
656697
} else {
657698
return -EIO;
658699
}

0 commit comments

Comments
 (0)