Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1343697
| From | Boris Brezillon <boris.brezillon@free-electrons.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v3 47/52] mtd: nand: sunxi: switch to mtd_ooblayout_ops |
| Date | 2016-02-26 02:20 +0100 |
| Message-ID | <r6fez-40K-27@gated-at.bofh.it> (permalink) |
| References | <r6eVb-3Cr-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Implementing the mtd_ooblayout_ops interface is the new way of exposing
ECC/OOB layout to MTD users.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/mtd/nand/sunxi_nand.c | 114 +++++++++++++++++++-----------------------
1 file changed, 52 insertions(+), 62 deletions(-)
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index b5ea6b3..24cce87 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -212,12 +212,9 @@ struct sunxi_nand_chip_sel {
* sunxi HW ECC infos: stores information related to HW ECC support
*
* @mode: the sunxi ECC mode field deduced from ECC requirements
- * @layout: the OOB layout depending on the ECC requirements and the
- * selected ECC mode
*/
struct sunxi_nand_hw_ecc {
int mode;
- struct nand_ecclayout layout;
};
/*
@@ -1257,6 +1254,57 @@ static int sunxi_nand_chip_init_timings(struct sunxi_nand_chip *chip,
return sunxi_nand_chip_set_timings(chip, timings);
}
+static int sunxi_nand_ooblayout_ecc(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *oobregion)
+{
+ struct nand_chip *nand = mtd_to_nand(mtd);
+ struct nand_ecc_ctrl *ecc = &nand->ecc;
+
+ if (section >= ecc->steps)
+ return -ERANGE;
+
+ oobregion->offset = section * (ecc->bytes + 4) + 4;
+ oobregion->length = ecc->bytes;
+
+ return 0;
+}
+
+static int sunxi_nand_ooblayout_free(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *oobregion)
+{
+ struct nand_chip *nand = mtd_to_nand(mtd);
+ struct nand_ecc_ctrl *ecc = &nand->ecc;
+
+ if (section > ecc->steps)
+ return -ERANGE;
+
+ /*
+ * The first 2 bytes are used for BB markers, hence we
+ * only have 2 bytes available in the first user data
+ * section.
+ */
+ if (!section && ecc->mode == NAND_ECC_HW) {
+ oobregion->offset = 2;
+ oobregion->length = 2;
+
+ return 0;
+ }
+
+ oobregion->offset = section * (ecc->bytes + 4);
+
+ if (section < ecc->steps)
+ oobregion->length = 4;
+ else
+ oobregion->offset = mtd->oobsize - oobregion->offset;
+
+ return 0;
+}
+
+static const struct mtd_ooblayout_ops sunxi_nand_ooblayout_ops = {
+ .ecc = sunxi_nand_ooblayout_ecc,
+ .free = sunxi_nand_ooblayout_free,
+};
+
static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
struct nand_ecc_ctrl *ecc,
struct device_node *np)
@@ -1266,7 +1314,6 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
struct sunxi_nand_hw_ecc *data;
- struct nand_ecclayout *layout;
int nsectors;
int ret;
int i;
@@ -1295,7 +1342,6 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
/* HW ECC always work with even numbers of ECC bytes */
ecc->bytes = ALIGN(ecc->bytes, 2);
- layout = &data->layout;
nsectors = mtd->writesize / ecc->size;
if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) {
@@ -1303,9 +1349,7 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
goto err;
}
- layout->eccbytes = (ecc->bytes * nsectors);
-
- ecc->layout = layout;
+ mtd_set_ooblayout(mtd, &sunxi_nand_ooblayout_ops);
ecc->priv = data;
return 0;
@@ -1325,9 +1369,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd,
struct nand_ecc_ctrl *ecc,
struct device_node *np)
{
- struct nand_ecclayout *layout;
- int nsectors;
- int i, j;
int ret;
ret = sunxi_nand_hw_common_ecc_ctrl_init(mtd, ecc, np);
@@ -1336,40 +1377,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd,
ecc->read_page = sunxi_nfc_hw_ecc_read_page;
ecc->write_page = sunxi_nfc_hw_ecc_write_page;
- layout = ecc->layout;
- nsectors = mtd->writesize / ecc->size;
-
- for (i = 0; i < nsectors; i++) {
- if (i) {
- layout->oobfree[i].offset =
- layout->oobfree[i - 1].offset +
- layout->oobfree[i - 1].length +
- ecc->bytes;
- layout->oobfree[i].length = 4;
- } else {
- /*
- * The first 2 bytes are used for BB markers, hence we
- * only have 2 bytes available in the first user data
- * section.
- */
- layout->oobfree[i].length = 2;
- layout->oobfree[i].offset = 2;
- }
-
- for (j = 0; j < ecc->bytes; j++)
- layout->eccpos[(ecc->bytes * i) + j] =
- layout->oobfree[i].offset +
- layout->oobfree[i].length + j;
- }
-
- if (mtd->oobsize > (ecc->bytes + 4) * nsectors) {
- layout->oobfree[nsectors].offset =
- layout->oobfree[nsectors - 1].offset +
- layout->oobfree[nsectors - 1].length +
- ecc->bytes;
- layout->oobfree[nsectors].length = mtd->oobsize -
- ((ecc->bytes + 4) * nsectors);
- }
return 0;
}
@@ -1378,9 +1385,6 @@ static int sunxi_nand_hw_syndrome_ecc_ctrl_init(struct mtd_info *mtd,
struct nand_ecc_ctrl *ecc,
struct device_node *np)
{
- struct nand_ecclayout *layout;
- int nsectors;
- int i;
int ret;
ret = sunxi_nand_hw_common_ecc_ctrl_init(mtd, ecc, np);
@@ -1391,15 +1395,6 @@ static int sunxi_nand_hw_syndrome_ecc_ctrl_init(struct mtd_info *mtd,
ecc->read_page = sunxi_nfc_hw_syndrome_ecc_read_page;
ecc->write_page = sunxi_nfc_hw_syndrome_ecc_write_page;
- layout = ecc->layout;
- nsectors = mtd->writesize / ecc->size;
-
- for (i = 0; i < (ecc->bytes * nsectors); i++)
- layout->eccpos[i] = i;
-
- layout->oobfree[0].length = mtd->oobsize - i;
- layout->oobfree[0].offset = i;
-
return 0;
}
@@ -1411,7 +1406,6 @@ static void sunxi_nand_ecc_cleanup(struct nand_ecc_ctrl *ecc)
sunxi_nand_hw_common_ecc_ctrl_cleanup(ecc);
break;
case NAND_ECC_NONE:
- kfree(ecc->layout);
default:
break;
}
@@ -1445,10 +1439,6 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc,
return ret;
break;
case NAND_ECC_NONE:
- ecc->layout = kzalloc(sizeof(*ecc->layout), GFP_KERNEL);
- if (!ecc->layout)
- return -ENOMEM;
- ecc->layout->oobfree[0].length = mtd->oobsize;
case NAND_ECC_SOFT:
break;
default:
--
2.1.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v3 00/52] mtd: rework ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 04/52] mtd: nand: simplify nand_bch_init() usage Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 01/52] mtd: kill the ecclayout->oobavail field Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 05/52] mtd: add mtd_ooblayout_xxx() helper functions Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 03/52] mtd: mtdswap: remove useless if (!mtd->ecclayout) test Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 02/52] mtd: create an mtd_oobavail() helper and make use of it Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:00 +0100
[PATCH v3 11/52] mtd: nand: lpc32xx: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 22/52] mtd: nand: bch: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 28/52] mtd: nand: cafe: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 40/52] mtd: nand: lpc32xx: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 24/52] mtd: nand: jz4740: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 20/52] mtd: docg3: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 36/52] mtd: nand: fsmc: get rid of the fsmc_nand_eccplace struct Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 21/52] mtd: nand: implement the default mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 16/52] mtd: nand: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 19/52] mtd: create an mtd_ooblayout_ops struct to ease ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 12/52] mtd: nand: omap2: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 15/52] mtd: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 26/52] mtd: nand: bf5xx: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 27/52] mtd: nand: brcm: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 44/52] mtd: nand: s3c2410: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 13/52] mtd: onenand: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 45/52] mtd: nand: sh_flctl: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 25/52] mtd: nand: atmel: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 31/52] mtd: nand: diskonchip: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 34/52] mtd: nand: fsl_ifc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 41/52] mtd: nand: mxc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 42/52] mtd: nand: omap2: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 43/52] mtd: nand: pxa3xx: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 32/52] mtd: nand: docg4: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 14/52] mtd: add mtd_set_ecclayout() helper function Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 23/52] mtd: nand: sharpsl: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 39/52] mtd: nand: jz4780: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
Re: [PATCH v3 39/52] mtd: nand: jz4780: switch to mtd_ooblayout_ops Harvey Hunt <harvey.hunt@imgtec.com> - 2016-02-29 11:50 +0100
[PATCH v3 29/52] mtd: nand: davinci: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 30/52] mtd: nand: denali: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 17/52] mtd: onenand: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 18/52] mtd: docg3: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 33/52] mtd: nand: fsl_elbc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:10 +0100
[PATCH v3 48/52] mtd: nand: vf610: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
Re: [PATCH v3 48/52] mtd: nand: vf610: switch to mtd_ooblayout_ops Stefan Agner <stefan@agner.ch> - 2016-02-26 20:50 +0100
Re: [PATCH v3 48/52] mtd: nand: vf610: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 21:50 +0100
[PATCH v3 38/52] mtd: nand: hisi504: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 06/52] mtd: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 52/52] mtd: kill the nand_ecclayout struct Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 47/52] mtd: nand: sunxi: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 51/52] mtd: nand: kill the ecc->layout field Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 49/52] mtd: onenand: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 46/52] mtd: nand: sm_common: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 37/52] mtd: nand: gpmi: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 50/52] staging: mt29f_spinand: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
[PATCH v3 35/52] mtd: nand: fsmc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 02:20 +0100
Re: [PATCH v3 00/52] mtd: rework ECC layout definition Stefan Agner <stefan@agner.ch> - 2016-02-26 02:40 +0100
Re: [PATCH v3 00/52] mtd: rework ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-26 03:50 +0100
csiph-web