public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Moritz Fischer <moritz.fischer@ettus.com>
To: dwmw2@infradead.org
Cc: computersforpeace@gmail.com, linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org, moritz.fischer.private@gmail.com,
	Moritz Fischer <moritz.fischer@ettus.com>
Subject: [PATCH] mtd: Adding of_mtd_info_get to get mtd_info from devicetree
Date: Wed, 11 May 2016 10:47:39 -0700	[thread overview]
Message-ID: <1462988859-32240-1-git-send-email-moritz.fischer@ettus.com> (raw)

This allows for getting a struct mtd_info from a node pointer,
allowing mtd devices to e.g. store serial numbers or MAC addresses.

Signed-off-by: Moritz Fischer <moritz.fischer@ettus.com>
---
 drivers/mtd/mtdcore.c   | 21 +++++++++++++++++++++
 include/linux/mtd/mtd.h |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 3096251..3d0ae65 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -363,6 +363,27 @@ unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
 EXPORT_SYMBOL_GPL(mtd_mmap_capabilities);
 #endif
 
+static int mtd_of_node_match(struct device *dev, const void *data)
+{
+	return dev->of_node == data;
+}
+
+struct mtd_info *of_mtd_info_get(struct device_node *node)
+{
+	struct mtd_info *mtd;
+	struct device *d;
+	int ret = -ENODEV;
+
+	d = class_find_device(&mtd_class, NULL, node, mtd_of_node_match);
+	if (!d)
+		return ERR_PTR(-ENODEV);
+
+	mtd = container_of(d, struct mtd_info, dev);
+
+	return mtd;
+}
+EXPORT_SYMBOL_GPL(of_mtd_info_get);
+
 static int mtd_reboot_notifier(struct notifier_block *n, unsigned long state,
 			       void *cmd)
 {
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 7712721..cce6cc7 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -264,6 +264,8 @@ static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd)
 	return mtd->dev.of_node;
 }
 
+struct mtd_info *of_mtd_info_get(struct device_node *node);
+
 static inline int mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops)
 {
 	return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;
-- 
2.5.5

             reply	other threads:[~2016-05-11 17:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-11 17:47 Moritz Fischer [this message]
2016-05-16  7:55 ` [PATCH] mtd: Adding of_mtd_info_get to get mtd_info from devicetree Boris Brezillon
2016-05-16  8:05   ` Boris Brezillon
2016-05-16 16:30     ` Moritz Fischer
2016-05-16 17:14       ` Boris Brezillon

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=1462988859-32240-1-git-send-email-moritz.fischer@ettus.com \
    --to=moritz.fischer@ettus.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=moritz.fischer.private@gmail.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