From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/4] mtd: Add hook to fix up kernel partitions
Date: Wed, 25 Nov 2020 06:20:10 +0100 [thread overview]
Message-ID: <20201125052011.20660-4-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20201125052011.20660-1-s.hauer@pengutronix.de>
Some drivers have special requirements for fixing up the partition
nodes for the kernel. This adds a hook to struct mtd_info that can
be used by drivers to replace the generic fixup with a special one.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/core.c | 30 +++++++++++++++++++++++++++++-
include/linux/mtd/mtd.h | 2 ++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index e21c71b816..af33ad665c 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -639,6 +639,34 @@ static int mtd_detect(struct device_d *dev)
return ret;
}
+static int mtd_partition_fixup_generic(struct mtd_info *mtd, struct device_node *root)
+{
+ struct cdev *cdev = &mtd->cdev;
+ struct device_node *np, *mtdnp = mtd_get_of_node(mtd);
+ char *name;
+
+ name = of_get_reproducible_name(mtdnp);
+ np = of_find_node_by_reproducible_name(root, name);
+ free(name);
+ if (!np) {
+ dev_err(&mtd->dev, "Cannot find nodepath %s, cannot fixup\n",
+ mtdnp->full_name);
+ return -EINVAL;
+ }
+
+ return of_fixup_partitions(np, cdev);
+}
+
+static int mtd_partition_fixup(struct device_node *root, void *ctx)
+{
+ struct mtd_info *mtd = ctx;
+
+ if (mtd->of_fixup)
+ return mtd->of_fixup(mtd, root);
+
+ return mtd_partition_fixup_generic(mtd, root);
+}
+
int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id)
{
struct mtddev_hook *hook;
@@ -706,7 +734,7 @@ int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id)
dev_add_param_string(&mtd->dev, "partitions", mtd_partition_set, mtd_partition_get, &mtd->partition_string, mtd);
if (IS_ENABLED(CONFIG_OFDEVICE) && np) {
of_parse_partitions(&mtd->cdev, np);
- ret = of_partitions_register_fixup(&mtd->cdev);
+ ret = of_register_fixup(mtd_partition_fixup, mtd);
if (ret)
goto err1;
}
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 0e2ff4526d..0d977fea25 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -206,6 +206,8 @@ struct mtd_info {
int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs);
int (*_block_markgood) (struct mtd_info *mtd, loff_t ofs);
+ int (*of_fixup)(struct mtd_info *mtd, struct device_node *root);
+
/* ECC status information */
struct mtd_ecc_stats ecc_stats;
/* Subpage shift (NAND) */
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2020-11-25 5:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-25 5:20 [PATCH 0/4] mtd: nand: Add special fixup kernel partitions for Denali Sascha Hauer
2020-11-25 5:20 ` [PATCH 1/4] mtd: Remove set but not used of_path Sascha Hauer
2020-11-25 5:20 ` [PATCH 2/4] of: partitions: export of_fixup_partitions Sascha Hauer
2020-11-25 5:20 ` Sascha Hauer [this message]
2020-11-25 5:20 ` [PATCH 4/4] mtd: nand: denali: cope with kernel device trees without chip subnodes 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=20201125052011.20660-4-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