mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] mtd: nand: denali: Make partition binding configurable
Date: Wed, 10 Jan 2024 14:15:57 +0100	[thread overview]
Message-ID: <20240110131557.1289602-1-s.hauer@pengutronix.de> (raw)

The binding for the denali NAND driver changed over time. Originally the
partitions were placed directly under the controller node. Nowadays
there is an additional chip node between the controller node and the
partitions. So what originally was:

nand: nand@ff900000 {
	compatible = "altr,socfpga-denali-nand";
	partitions {
		...
	};
};

has now become:

nand: nand@ff900000 {
	compatible = "altr,socfpga-denali-nand";
	nand@0 {
		partitions {
			...
		};
	};
};

The new binding has been introduced with Linux-5.2 and after a grace
period it has been made mandatory in Linux-5.5. We want however to be
able to start old Kernels supporting only the old binding as well, so
make the binding we fix up the kernel device tree with configurable.

This introduces the globalvar nandx.denali_partition_binding with three
different settings:

chip: Fixup the Kernel device tree according to the new binding. This is
      the default
controller: Fixup the Kernel device tree according to the old binding
auto: When the Kernel device tree has a "nand@0" node then use the new
      binding, otherwise use the old binding.

The previous (only) implemented default before this patch was "auto".
This deliberately is changed with this patch as Kernels older than
Linux-5.2 are quite old already and likely contains the least surprises
for the user.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/nand/nand_denali_dt.c | 67 ++++++++++++++++++++++++++-----
 1 file changed, 56 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/nand_denali_dt.c b/drivers/mtd/nand/nand_denali_dt.c
index cf902fe6c4..d21cdc9756 100644
--- a/drivers/mtd/nand/nand_denali_dt.c
+++ b/drivers/mtd/nand/nand_denali_dt.c
@@ -14,6 +14,7 @@
 #include <io.h>
 #include <of_mtd.h>
 #include <errno.h>
+#include <globalvar.h>
 
 #include <linux/clk.h>
 #include <linux/spinlock.h>
@@ -43,6 +44,18 @@ static const struct denali_dt_data denali_socfpga_data = {
 	.ecc_caps = &denali_socfpga_ecc_caps,
 };
 
+enum of_binding_name {
+	DENALI_OF_BINDING_CHIP,
+	DENALI_OF_BINDING_CONTROLLER,
+	DENALI_OF_BINDING_AUTO,
+};
+
+static const char *denali_of_binding_names[] = {
+	"chip", "controller", "auto"
+};
+
+static int denali_of_binding;
+
 /*
  * Older versions of the kernel driver require the partition nodes
  * to be direct subnodes of the controller node. Starting with Kernel
@@ -70,26 +83,50 @@ static int denali_partition_fixup(struct mtd_info *mtd, struct device_node *root
 							struct denali_controller,
 							controller);
 	struct device_node *np, *mtdnp = mtd_get_of_node(mtd);
+	struct device_node *chip_np, *controller_np;
 	char *name;
 
 	name = of_get_reproducible_name(mtdnp);
-	np = of_find_node_by_reproducible_name(root, name);
+	chip_np = of_find_node_by_reproducible_name(root, name);
 	free(name);
 
-	if (np) {
-		dev_info(denali->dev, "Fixing up chip node %pOF\n", np);
-	} else {
-		name = of_get_reproducible_name(mtdnp->parent);
-		np = of_find_node_by_reproducible_name(root, name);
-		free(name);
+	name = of_get_reproducible_name(mtdnp->parent);
+	controller_np = of_find_node_by_reproducible_name(root, name);
+	free(name);
 
-		if (np)
-			dev_info(denali->dev, "Fixing up controller node %pOF\n", np);
-	}
+	if (!controller_np)
+		return -EINVAL;
+
+	switch (denali_of_binding) {
+	case DENALI_OF_BINDING_CHIP:
+		if (chip_np) {
+			np = chip_np;
+		} else {
+			np = of_new_node(controller_np, mtdnp->name);
+			of_property_write_u32(np, "reg", 0);
+			chip_np = np;
+		}
+		break;
+	case DENALI_OF_BINDING_CONTROLLER:
+		np = controller_np;
+		break;
+	case DENALI_OF_BINDING_AUTO:
+	default:
+		np = chip_np ? chip_np : controller_np;
+		break;
+	};
 
 	if (!np)
 		return -EINVAL;
 
+	dev_info(denali->dev, "Fixing up %s node %pOF\n",
+		 chip_np ? "chip" : "controller", np);
+
+	if (!chip_np) {
+		of_property_write_bool(np, "#size-cells", false);
+		of_property_write_bool(np, "#address-cells", false);
+	}
+
 	return of_fixup_partitions(np, &mtd->cdev);
 }
 
@@ -123,7 +160,15 @@ static int denali_dt_chip_init(struct denali_controller *denali,
 		nand_set_flash_node(&dchip->chip, chip_np);
 	}
 
-	return denali_chip_init(denali, dchip);
+	ret = denali_chip_init(denali, dchip);
+	if (ret)
+		return ret;
+
+	dev_add_param_enum(&dchip->chip.base.mtd.dev, "denali_partition_binding",
+			   NULL, NULL,  &denali_of_binding, denali_of_binding_names,
+			   ARRAY_SIZE(denali_of_binding_names), NULL);
+
+	return 0;
 }
 
 static int denali_dt_probe(struct device *ofdev)
-- 
2.39.2




             reply	other threads:[~2024-01-10 13:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10 13:15 Sascha Hauer [this message]
2024-01-19  6:42 ` Sascha Hauer

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=20240110131557.1289602-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox