Commit a411679f authored by Boris Brezillon's avatar Boris Brezillon

mtd: onenand: switch to mtd_ooblayout_ops

Implementing the mtd_ooblayout_ops interface is the new way of exposing
ECC/OOB layout to MTD users. Modify the onenand drivers to switch to this
approach.
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
parent 421e81c4
...@@ -68,21 +68,33 @@ MODULE_PARM_DESC(otp, "Corresponding behaviour of OneNAND in OTP" ...@@ -68,21 +68,33 @@ MODULE_PARM_DESC(otp, "Corresponding behaviour of OneNAND in OTP"
* flexonenand_oob_128 - oob info for Flex-Onenand with 4KB page * flexonenand_oob_128 - oob info for Flex-Onenand with 4KB page
* For now, we expose only 64 out of 80 ecc bytes * For now, we expose only 64 out of 80 ecc bytes
*/ */
static struct nand_ecclayout flexonenand_oob_128 = { static int flexonenand_ooblayout_ecc(struct mtd_info *mtd, int section,
.eccbytes = 64, struct mtd_oob_region *oobregion)
.eccpos = { {
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, if (section > 7)
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, return -ERANGE;
38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, oobregion->offset = (section * 16) + 6;
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, oobregion->length = 10;
86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
102, 103, 104, 105 return 0;
}, }
.oobfree = {
{2, 4}, {18, 4}, {34, 4}, {50, 4}, static int flexonenand_ooblayout_free(struct mtd_info *mtd, int section,
{66, 4}, {82, 4}, {98, 4}, {114, 4} struct mtd_oob_region *oobregion)
} {
if (section > 7)
return -ERANGE;
oobregion->offset = (section * 16) + 2;
oobregion->length = 4;
return 0;
}
static const struct mtd_ooblayout_ops flexonenand_ooblayout_ops = {
.ecc = flexonenand_ooblayout_ecc,
.free = flexonenand_ooblayout_free,
}; };
/* /*
...@@ -91,56 +103,77 @@ static struct nand_ecclayout flexonenand_oob_128 = { ...@@ -91,56 +103,77 @@ static struct nand_ecclayout flexonenand_oob_128 = {
* Based on specification: * Based on specification:
* 4Gb M-die OneNAND Flash (KFM4G16Q4M, KFN8G16Q4M). Rev. 1.3, Apr. 2010 * 4Gb M-die OneNAND Flash (KFM4G16Q4M, KFN8G16Q4M). Rev. 1.3, Apr. 2010
* *
* For eccpos we expose only 64 bytes out of 72 (see struct nand_ecclayout) */
* static int onenand_ooblayout_128_ecc(struct mtd_info *mtd, int section,
* oobfree uses the spare area fields marked as struct mtd_oob_region *oobregion)
* "Managed by internal ECC logic for Logical Sector Number area" {
*/ if (section > 7)
static struct nand_ecclayout onenand_oob_128 = { return -ERANGE;
.eccbytes = 64,
.eccpos = { oobregion->offset = (section * 16) + 7;
7, 8, 9, 10, 11, 12, 13, 14, 15, oobregion->length = 9;
23, 24, 25, 26, 27, 28, 29, 30, 31,
39, 40, 41, 42, 43, 44, 45, 46, 47, return 0;
55, 56, 57, 58, 59, 60, 61, 62, 63, }
71, 72, 73, 74, 75, 76, 77, 78, 79,
87, 88, 89, 90, 91, 92, 93, 94, 95, static int onenand_ooblayout_128_free(struct mtd_info *mtd, int section,
103, 104, 105, 106, 107, 108, 109, 110, 111, struct mtd_oob_region *oobregion)
119 {
}, if (section >= 8)
.oobfree = { return -ERANGE;
{2, 3}, {18, 3}, {34, 3}, {50, 3},
{66, 3}, {82, 3}, {98, 3}, {114, 3} /*
} * free bytes are using the spare area fields marked as
* "Managed by internal ECC logic for Logical Sector Number area"
*/
oobregion->offset = (section * 16) + 2;
oobregion->length = 3;
return 0;
}
static const struct mtd_ooblayout_ops onenand_oob_128_ooblayout_ops = {
.ecc = onenand_ooblayout_128_ecc,
.free = onenand_ooblayout_128_free,
}; };
/** /**
* onenand_oob_64 - oob info for large (2KB) page * onenand_oob_32_64 - oob info for large (2KB) page
*/ */
static struct nand_ecclayout onenand_oob_64 = { static int onenand_ooblayout_32_64_ecc(struct mtd_info *mtd, int section,
.eccbytes = 20, struct mtd_oob_region *oobregion)
.eccpos = { {
8, 9, 10, 11, 12, if (section > 3)
24, 25, 26, 27, 28, return -ERANGE;
40, 41, 42, 43, 44,
56, 57, 58, 59, 60, oobregion->offset = (section * 16) + 8;
}, oobregion->length = 5;
.oobfree = {
{2, 3}, {14, 2}, {18, 3}, {30, 2}, return 0;
{34, 3}, {46, 2}, {50, 3}, {62, 2} }
static int onenand_ooblayout_32_64_free(struct mtd_info *mtd, int section,
struct mtd_oob_region *oobregion)
{
int sections = (mtd->oobsize / 32) * 2;
if (section >= sections)
return -ERANGE;
if (section & 1) {
oobregion->offset = ((section - 1) * 16) + 14;
oobregion->length = 2;
} else {
oobregion->offset = (section * 16) + 2;
oobregion->length = 3;
} }
};
/** return 0;
* onenand_oob_32 - oob info for middle (1KB) page }
*/
static struct nand_ecclayout onenand_oob_32 = { static const struct mtd_ooblayout_ops onenand_oob_32_64_ooblayout_ops = {
.eccbytes = 10, .ecc = onenand_ooblayout_32_64_ecc,
.eccpos = { .free = onenand_ooblayout_32_64_free,
8, 9, 10, 11, 12,
24, 25, 26, 27, 28,
},
.oobfree = { {2, 3}, {14, 2}, {18, 3}, {30, 2} }
}; };
static const unsigned char ffchars[] = { static const unsigned char ffchars[] = {
...@@ -3957,22 +3990,22 @@ int onenand_scan(struct mtd_info *mtd, int maxchips) ...@@ -3957,22 +3990,22 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
switch (mtd->oobsize) { switch (mtd->oobsize) {
case 128: case 128:
if (FLEXONENAND(this)) { if (FLEXONENAND(this)) {
this->ecclayout = &flexonenand_oob_128; mtd_set_ooblayout(mtd, &flexonenand_ooblayout_ops);
mtd->subpage_sft = 0; mtd->subpage_sft = 0;
} else { } else {
this->ecclayout = &onenand_oob_128; mtd_set_ooblayout(mtd, &onenand_oob_128_ooblayout_ops);
mtd->subpage_sft = 2; mtd->subpage_sft = 2;
} }
if (ONENAND_IS_NOP_1(this)) if (ONENAND_IS_NOP_1(this))
mtd->subpage_sft = 0; mtd->subpage_sft = 0;
break; break;
case 64: case 64:
this->ecclayout = &onenand_oob_64; mtd_set_ooblayout(mtd, &onenand_oob_32_64_ooblayout_ops);
mtd->subpage_sft = 2; mtd->subpage_sft = 2;
break; break;
case 32: case 32:
this->ecclayout = &onenand_oob_32; mtd_set_ooblayout(mtd, &onenand_oob_32_64_ooblayout_ops);
mtd->subpage_sft = 1; mtd->subpage_sft = 1;
break; break;
...@@ -3981,7 +4014,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips) ...@@ -3981,7 +4014,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
__func__, mtd->oobsize); __func__, mtd->oobsize);
mtd->subpage_sft = 0; mtd->subpage_sft = 0;
/* To prevent kernel oops */ /* To prevent kernel oops */
this->ecclayout = &onenand_oob_32; mtd_set_ooblayout(mtd, &onenand_oob_32_64_ooblayout_ops);
break; break;
} }
...@@ -3997,7 +4030,6 @@ int onenand_scan(struct mtd_info *mtd, int maxchips) ...@@ -3997,7 +4030,6 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
mtd->oobavail = ret; mtd->oobavail = ret;
mtd_set_ecclayout(mtd, this->ecclayout);
mtd->ecc_strength = 1; mtd->ecc_strength = 1;
/* Fill in remaining MTD driver data */ /* Fill in remaining MTD driver data */
......
...@@ -80,7 +80,6 @@ struct onenand_bufferram { ...@@ -80,7 +80,6 @@ struct onenand_bufferram {
* @page_buf: [INTERN] page main data buffer * @page_buf: [INTERN] page main data buffer
* @oob_buf: [INTERN] page oob data buffer * @oob_buf: [INTERN] page oob data buffer
* @subpagesize: [INTERN] holds the subpagesize * @subpagesize: [INTERN] holds the subpagesize
* @ecclayout: [REPLACEABLE] the default ecc placement scheme
* @bbm: [REPLACEABLE] pointer to Bad Block Management * @bbm: [REPLACEABLE] pointer to Bad Block Management
* @priv: [OPTIONAL] pointer to private chip date * @priv: [OPTIONAL] pointer to private chip date
*/ */
...@@ -134,7 +133,6 @@ struct onenand_chip { ...@@ -134,7 +133,6 @@ struct onenand_chip {
#endif #endif
int subpagesize; int subpagesize;
struct nand_ecclayout *ecclayout;
void *bbm; void *bbm;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment