From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: <vigneshr@ti.com>, <richard@nod.at>, <miquel.raynal@bootlin.com>,
<joern@lazybastard.org>
Cc: <kernel@axis.com>, <linux-kernel@vger.kernel.org>,
<linux-mtd@lists.infradead.org>, <devicetree@vger.kernel.org>,
<frowand.list@gmail.com>, <krzysztof.kozlowski@canonical.com>,
<robh+dt@kernel.org>,
Vincent Whitchurch <vincent.whitchurch@axis.com>
Subject: [PATCH 1/4] mtd: core: Check devicetree alias for index
Date: Mon, 7 Mar 2022 15:15:46 +0100 [thread overview]
Message-ID: <20220307141549.2732179-2-vincent.whitchurch@axis.com> (raw)
In-Reply-To: <20220307141549.2732179-1-vincent.whitchurch@axis.com>
Allow the MTD index to be specified via a devicetree alias, so that the
number does not just depend on probe order. This is useful to allow
pseudo-devices like phram to be optionally used on systems, without
having this affect the numbering of the real hardware MTD devices.
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
drivers/mtd/mtdcore.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index bd4b31023c82..37c8b1b5db26 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -590,9 +590,10 @@ static int mtd_nvmem_add(struct mtd_info *mtd)
int add_mtd_device(struct mtd_info *mtd)
{
+ struct device_node *np = mtd_get_of_node(mtd);
struct mtd_info *master = mtd_get_master(mtd);
struct mtd_notifier *not;
- int i, error;
+ int i, error, ofidx;
/*
* May occur, for instance, on buggy drivers which call
@@ -631,7 +632,13 @@ int add_mtd_device(struct mtd_info *mtd)
mutex_lock(&mtd_table_mutex);
- i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
+ ofidx = -1;
+ if (np)
+ ofidx = of_alias_get_id(np, "mtd");
+ if (ofidx >= 0)
+ i = idr_alloc(&mtd_idr, mtd, ofidx, ofidx + 1, GFP_KERNEL);
+ else
+ i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
if (i < 0) {
error = i;
goto fail_locked;
--
2.34.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2022-03-07 14:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-07 14:15 [PATCH 0/4] mtd: phram improvements Vincent Whitchurch
2022-03-07 14:15 ` Vincent Whitchurch [this message]
2022-03-07 14:15 ` [PATCH 2/4] dt-bindings: reserved-memory: Add phram Vincent Whitchurch
2022-03-10 20:58 ` Rob Herring
2022-03-11 10:13 ` Vincent Whitchurch
2022-03-07 14:15 ` [PATCH 3/4] mtd: phram: Allow probing via reserved-memory Vincent Whitchurch
2022-03-07 14:15 ` [PATCH 4/4] mtd: phram: Allow cached mappings Vincent Whitchurch
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=20220307141549.2732179-2-vincent.whitchurch@axis.com \
--to=vincent.whitchurch@axis.com \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=joern@lazybastard.org \
--cc=kernel@axis.com \
--cc=krzysztof.kozlowski@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=robh+dt@kernel.org \
--cc=vigneshr@ti.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox