All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Jonker <jbx6244@gmail.com>
To: dario.binacchi@amarulasolutions.com,
	michael@amarulasolutions.com, sjg@chromium.org
Cc: philipp.tomsich@vrull.eu, kever.yang@rock-chips.com,
	u-boot@lists.denx.de, yifeng.zhao@rock-chips.com
Subject: [PATCH v4 08/11] mtd: nand: raw: rockchip_nfc: add layout structure
Date: Sat, 18 Feb 2023 16:28:23 +0100	[thread overview]
Message-ID: <cb03350b-1502-b8c4-354c-09465af94efe@gmail.com> (raw)
In-Reply-To: <f3dba231-4a55-0a94-dfab-5cab1419d132@gmail.com>

The MTD framework in U-boot is not identical for drivers ported
from Linux. The rockchip_nfc driver was ported with OOB ops functions
while the framework expects a layout structure per chip.
Fix by adding a structure with OOB data and remove unused functions.

Signed-off-by: Johan Jonker <jbx6244@gmail.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
---
 drivers/mtd/nand/raw/rockchip_nfc.c | 61 ++++++++++-------------------
 1 file changed, 20 insertions(+), 41 deletions(-)

diff --git a/drivers/mtd/nand/raw/rockchip_nfc.c b/drivers/mtd/nand/raw/rockchip_nfc.c
index a8ec6bfc..ab13e52c 100644
--- a/drivers/mtd/nand/raw/rockchip_nfc.c
+++ b/drivers/mtd/nand/raw/rockchip_nfc.c
@@ -814,47 +814,9 @@ static void rk_nfc_disable_clks(struct rk_nfc *nfc)
 	clk_disable_unprepare(nfc->ahb_clk);
 }

-static int rk_nfc_ooblayout_free(struct mtd_info *mtd, int section,
-				 struct mtd_oob_region *oob_region)
-{
-	struct nand_chip *chip = mtd_to_nand(mtd);
-	struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
-
-	if (section)
-		return -ERANGE;
-
-	/*
-	 * The beginning of the OOB area stores the reserved data for the NFC,
-	 * the size of the reserved data is NFC_SYS_DATA_SIZE bytes.
-	 */
-	oob_region->length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
-	oob_region->offset = NFC_SYS_DATA_SIZE + 2;
-
-	return 0;
-}
-
-static int rk_nfc_ooblayout_ecc(struct mtd_info *mtd, int section,
-				struct mtd_oob_region *oob_region)
-{
-	struct nand_chip *chip = mtd_to_nand(mtd);
-	struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
-
-	if (section)
-		return -ERANGE;
-
-	oob_region->length = mtd->oobsize - rknand->metadata_size;
-	oob_region->offset = rknand->metadata_size;
-
-	return 0;
-}
-
-static const struct mtd_ooblayout_ops rk_nfc_ooblayout_ops = {
-	.rfree = rk_nfc_ooblayout_free,
-	.ecc = rk_nfc_ooblayout_ecc,
-};
-
 static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)
 {
+	struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
 	const u8 *strengths = nfc->cfg->ecc_strengths;
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	struct nand_ecc_ctrl *ecc = &chip->ecc;
@@ -892,6 +854,21 @@ static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)
 	ecc->steps = mtd->writesize / ecc->size;
 	ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * chip->ecc.size), 8);

+	if (ecc->bytes * ecc->steps > mtd->oobsize - rknand->metadata_size)
+		return -EINVAL;
+
+	ecc->layout = kzalloc(sizeof(*ecc->layout), GFP_KERNEL);
+	if (!ecc->layout)
+		return -ENOMEM;
+
+	ecc->layout->eccbytes = ecc->bytes * ecc->steps;
+
+	for (i = 0; i < ecc->layout->eccbytes; i++)
+		ecc->layout->eccpos[i] = rknand->metadata_size + i;
+
+	ecc->layout->oobfree[0].length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
+	ecc->layout->oobfree[0].offset = NFC_SYS_DATA_SIZE + 2;
+
 	return 0;
 }

@@ -969,7 +946,6 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
 	chip->bbt_options = NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
 	chip->options |= NAND_NO_SUBPAGE_WRITE | NAND_USE_BOUNCE_BUFFER;

-	mtd_set_ooblayout(mtd, &rk_nfc_ooblayout_ops);
 	rk_nfc_hw_init(nfc);
 	ret = nand_scan_ident(mtd, nsels, NULL);
 	if (ret)
@@ -998,13 +974,16 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)

 	if (!nfc->page_buf) {
 		nfc->page_buf = kzalloc(NFC_MAX_PAGE_SIZE, GFP_KERNEL);
-		if (!nfc->page_buf)
+		if (!nfc->page_buf) {
+			kfree(ecc->layout);
 			return -ENOMEM;
+		}
 	}

 	if (!nfc->oob_buf) {
 		nfc->oob_buf = kzalloc(NFC_MAX_OOB_SIZE, GFP_KERNEL);
 		if (!nfc->oob_buf) {
+			kfree(ecc->layout);
 			kfree(nfc->page_buf);
 			nfc->page_buf = NULL;
 			return -ENOMEM;
--
2.20.1


  parent reply	other threads:[~2023-02-18 15:29 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-18 15:23 [PATCH v4 00/11] Fixes for Rockchip NFC driver part 1 Johan Jonker
2023-02-18 15:26 ` [PATCH v4 01/11] include: fdtdec: decouple fdt_addr_t and phys_addr_t size Johan Jonker
2023-02-23  0:47   ` Kever Yang
2023-02-23 14:06     ` [PATCH v1] spi: spi-aspeed-smc: convert devfdt_get_addr_index output to phys_addr_t Johan Jonker
2023-02-25  9:26       ` Michael Nazzareno Trimarchi
2023-02-25  9:50         ` Johan Jonker
2023-02-25  9:53           ` Michael Nazzareno Trimarchi
2023-02-25 11:40             ` Michael Nazzareno Trimarchi
2023-02-25  9:11     ` [PATCH v4 01/11] include: fdtdec: decouple fdt_addr_t and phys_addr_t size Johan Jonker
2023-02-25  9:15       ` Michael Nazzareno Trimarchi
2023-02-25  9:20         ` Johan Jonker
2023-02-25 11:43     ` [PATCH v2 1/2] core: fdtaddr: add devfdt_get_addr_size_index_ptr function Johan Jonker
2023-02-25 11:44       ` [PATCH v2 2/2] spi: spi-aspeed-smc: use devfdt_get_addr_index_ptr Johan Jonker
2023-02-25 11:47         ` Michael Nazzareno Trimarchi
2023-02-25 11:47       ` [PATCH v2 1/2] core: fdtaddr: add devfdt_get_addr_size_index_ptr function Michael Nazzareno Trimarchi
2023-02-25 16:52         ` Michael Nazzareno Trimarchi
2023-02-25 19:16     ` [RFC PATCH v1 1/4] drivers: use dev_read_addr_index_ptr when cast to pointer Johan Jonker
2023-02-25 19:19       ` [RFC PATCH v1 2/4] drivers: use dev_read_addr_ptr " Johan Jonker
2023-02-25 23:05         ` Johan Jonker
2023-02-25 19:19       ` [RFC PATCH v1 3/4] drivers: use devfdt_get_addr_size_index_ptr " Johan Jonker
2023-02-25 20:39         ` Michael Nazzareno Trimarchi
2023-02-27 15:17         ` Dario Binacchi
2023-02-25 19:19       ` [RFC PATCH v1 4/4] drivers: use devfdt_get_addr_index_ptr " Johan Jonker
2023-02-25 20:40         ` Michael Nazzareno Trimarchi
2023-02-25 20:37       ` [RFC PATCH v1 1/4] drivers: use dev_read_addr_index_ptr " Michael Nazzareno Trimarchi
2023-02-18 15:26 ` [PATCH v4 02/11] include: dm: ofnode: fix headers Johan Jonker
2023-02-18 15:27 ` [PATCH v4 03/11] core: remap: convert regmap_init_mem_plat() input to phys_addr_t Johan Jonker
2023-02-22  7:59   ` Kever Yang
2023-02-18 15:27 ` [PATCH v4 04/11] rockchip: adc: rockchip-saradc: use dev_read_addr_ptr Johan Jonker
2023-02-22  8:00   ` Kever Yang
2023-02-18 15:27 ` [PATCH v4 05/11] rockchip: timer: dw-apb-timer: convert dev_read_addr output to phys_addr_t Johan Jonker
2023-02-18 15:27 ` [PATCH v4 06/11] mtd: nand: raw: rockchip_nfc: use dev_read_addr_ptr Johan Jonker
2023-02-18 15:28 ` [PATCH v4 07/11] mtd: nand: raw: rockchip_nfc: remove the compatible string "rockchip,rk3308-nfc" Johan Jonker
2023-02-18 15:28 ` Johan Jonker [this message]
2023-02-18 15:28 ` [PATCH v4 09/11] mtd: nand: raw: rockchip_nfc: add flash_node to chip structure Johan Jonker
2023-02-18 15:28 ` [PATCH v4 10/11] mtd: nand: add support for the Sandisk SDTNQGAMA chip Johan Jonker
2023-02-18 15:29 ` [PATCH v4 11/11] mtd: nand: raw: rockchip_nfc: fix oobfree offset and description Johan Jonker
2023-02-22  8:01   ` Kever Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cb03350b-1502-b8c4-354c-09465af94efe@gmail.com \
    --to=jbx6244@gmail.com \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=kever.yang@rock-chips.com \
    --cc=michael@amarulasolutions.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=yifeng.zhao@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.