Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1326578

[PATCH v2 33/51] mtd: nand: fsl_elbc: switch to mtd_ooblayout_ops

From Boris Brezillon <boris.brezillon@free-electrons.com>
Newsgroups linux.kernel
Subject [PATCH v2 33/51] mtd: nand: fsl_elbc: switch to mtd_ooblayout_ops
Date 2016-02-04 11:20 +0100
Message-ID <qYpb6-7ep-47@gated-at.bofh.it> (permalink)
References <qYp1n-7ay-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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/fsl_elbc_nand.c | 83 +++++++++++++++++++++++-----------------
 1 file changed, 47 insertions(+), 36 deletions(-)

diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 059d5f7..487eae0 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -79,32 +79,53 @@ struct fsl_elbc_fcm_ctrl {
 
 /* These map to the positions used by the FCM hardware ECC generator */
 
-/* Small Page FLASH with FMR[ECCM] = 0 */
-static struct nand_ecclayout fsl_elbc_oob_sp_eccm0 = {
-	.eccbytes = 3,
-	.eccpos = {6, 7, 8},
-	.oobfree = { {0, 5}, {9, 7} },
-};
+static int fsl_elbc_ooblayout_ecc(struct mtd_info *mtd, int section,
+				  struct mtd_oob_region *oobregion)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+	struct fsl_elbc_mtd *priv = nand_get_controller_data(chip);
 
-/* Small Page FLASH with FMR[ECCM] = 1 */
-static struct nand_ecclayout fsl_elbc_oob_sp_eccm1 = {
-	.eccbytes = 3,
-	.eccpos = {8, 9, 10},
-	.oobfree = { {0, 5}, {6, 2}, {11, 5} },
-};
+	if (section >= chip->ecc.steps)
+		return -ERANGE;
 
-/* Large Page FLASH with FMR[ECCM] = 0 */
-static struct nand_ecclayout fsl_elbc_oob_lp_eccm0 = {
-	.eccbytes = 12,
-	.eccpos = {6, 7, 8, 22, 23, 24, 38, 39, 40, 54, 55, 56},
-	.oobfree = { {1, 5}, {9, 13}, {25, 13}, {41, 13}, {57, 7} },
-};
+	oobregion->offset = (16 * section) + 6;
+	if (priv->fmr & FMR_ECCM)
+		oobregion->offset += 2;
 
-/* Large Page FLASH with FMR[ECCM] = 1 */
-static struct nand_ecclayout fsl_elbc_oob_lp_eccm1 = {
-	.eccbytes = 12,
-	.eccpos = {8, 9, 10, 24, 25, 26, 40, 41, 42, 56, 57, 58},
-	.oobfree = { {1, 7}, {11, 13}, {27, 13}, {43, 13}, {59, 5} },
+	oobregion->length = chip->ecc.bytes;
+
+	return 0;
+}
+
+static int fsl_elbc_ooblayout_free(struct mtd_info *mtd, int section,
+				   struct mtd_oob_region *oobregion)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+	struct fsl_elbc_mtd *priv = nand_get_controller_data(chip);
+
+	if (section > chip->ecc.steps)
+		return -ERANGE;
+
+	if (!section) {
+		oobregion->offset = 0;
+		if (mtd->writesize > 512)
+			oobregion->offset++;
+		oobregion->length = (priv->fmr & FMR_ECCM) ? 7 : 5;
+	} else {
+		oobregion->offset = (16 * section) -
+				    ((priv->fmr & FMR_ECCM) ? 5 : 7);
+		if (section < chip->ecc.steps)
+			oobregion->length = 13;
+		else
+			oobregion->length = mtd->oobsize - oobregion->offset;
+	}
+
+	return 0;
+}
+
+static const struct mtd_ooblayout_ops fsl_elbc_ooblayout_ops = {
+	.ecc = fsl_elbc_ooblayout_ecc,
+	.free = fsl_elbc_ooblayout_free,
 };
 
 /*
@@ -657,8 +678,8 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
 	        chip->ecc.bytes);
 	dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.total = %d\n",
 	        chip->ecc.total);
-	dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.layout = %p\n",
-	        chip->ecc.layout);
+	dev_dbg(priv->dev, "fsl_elbc_init: mtd->ooblayout = %p\n",
+		mtd->ooblayout);
 	dev_dbg(priv->dev, "fsl_elbc_init: mtd->flags = %08x\n", mtd->flags);
 	dev_dbg(priv->dev, "fsl_elbc_init: mtd->size = %lld\n", mtd->size);
 	dev_dbg(priv->dev, "fsl_elbc_init: mtd->erasesize = %d\n",
@@ -675,14 +696,6 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
 	} else if (mtd->writesize == 2048) {
 		priv->page_size = 1;
 		setbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS);
-		/* adjust ecc setup if needed */
-		if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) ==
-		    BR_DECC_CHK_GEN) {
-			chip->ecc.size = 512;
-			chip->ecc.layout = (priv->fmr & FMR_ECCM) ?
-			                   &fsl_elbc_oob_lp_eccm1 :
-			                   &fsl_elbc_oob_lp_eccm0;
-		}
 	} else {
 		dev_err(priv->dev,
 		        "fsl_elbc_init: page size %d is not supported\n",
@@ -780,9 +793,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 	if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) ==
 	    BR_DECC_CHK_GEN) {
 		chip->ecc.mode = NAND_ECC_HW;
-		/* put in small page settings and adjust later if needed */
-		chip->ecc.layout = (priv->fmr & FMR_ECCM) ?
-				&fsl_elbc_oob_sp_eccm1 : &fsl_elbc_oob_sp_eccm0;
+		mtd_set_ooblayout(mtd, &fsl_elbc_ooblayout_ops);
 		chip->ecc.size = 512;
 		chip->ecc.bytes = 3;
 		chip->ecc.strength = 1;
-- 
2.1.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 00/51] mtd: rework ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:10 +0100
  [PATCH v2 17/51] mtd: onenand: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:10 +0100
  [PATCH v2 48/51] mtd: onenand: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:10 +0100
  [PATCH v2 49/51] staging: mt29f_spinand: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:10 +0100
  [PATCH v2 34/51] mtd: nand: fsl_ifc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 29/51] mtd: nand: davinci: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 26/51] mtd: nand: bf5xx: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 31/51] mtd: nand: diskonchip: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 32/51] mtd: nand: docg4: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 24/51] mtd: nand: jz4740: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 38/51] mtd: nand: jz4780: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 40/51] mtd: nand: mxc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 35/51] mtd: nand: fsmc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 47/51] mtd: nand: vf610: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 46/51] mtd: nand: sunxi: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 23/51] mtd: nand: sharpsl: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 50/51] mtd: nand: kill the ecc->layout field Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 39/51] mtd: nand: lpc32xx: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 30/51] mtd: nand: denali: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 33/51] mtd: nand: fsl_elbc: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 44/51] mtd: nand: sh_flctl: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 42/51] mtd: nand: pxa3xx: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 36/51] mtd: nand: gpmi: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 41/51] mtd: nand: omap2: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:20 +0100
  [PATCH v2 25/51] mtd: nand: atmel: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 19/51] mtd: create an mtd_ooblayout_ops struct to ease ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 02/51] mtd: create an mtd_oobavail() helper and make use of it Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 01/51] mtd: kill the ecclayout->oobavail field Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 28/51] mtd: nand: cafe: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 05/51] mtd: add mtd_ooblayout_xxx() helper functions Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
    Re: [PATCH v2 05/51] mtd: add mtd_ooblayout_xxx() helper functions Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-05 08:40 +0100
    Re: [PATCH v2 05/51] mtd: add mtd_ooblayout_xxx() helper functions Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-05 10:30 +0100
  [PATCH v2 15/51] mtd: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 08/51] mtd: nand: atmel: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 18/51] mtd: docg3: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
    Re: [PATCH v2 18/51] mtd: docg3: use mtd_set_ecclayout() where appropriate Robert Jarzmik <robert.jarzmik@free.fr> - 2016-02-06 23:00 +0100
  [PATCH v2 14/51] mtd: add mtd_set_ecclayout() helper function Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 27/51] mtd: nand: brcm: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 10/51] mtd: nand: gpmi: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 13/51] mtd: onenand: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 16/51] mtd: nand: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 21/51] mtd: nand: implement the default mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 12/51] mtd: nand: omap2: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 11/51] mtd: nand: lpc32xx: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 22/51] mtd: nand: bch: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:30 +0100
  [PATCH v2 04/51] mtd: nand: simplify nand_bch_init() usage Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:40 +0100
  [PATCH v2 03/51] mtd: mtdswap: remove useless if (!mtd->ecclayout) test Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:40 +0100
  [PATCH v2 06/51] mtd: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:40 +0100
  [PATCH v2 07/51] mtd: nand: core: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:40 +0100
    Re: [PATCH v2 07/51] mtd: nand: core: use mtd_ooblayout_xxx()  helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-05 10:40 +0100
  [PATCH v2 09/51] mtd: nand: fsl_ifc: use mtd_ooblayout_xxx() helpers where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-04 11:40 +0100

csiph-web