mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Fabio Estevam <fabio.estevam@freescale.com>,
	Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 2/9] OF: Port of_match_device() and of_device_get_match_data()
Date: Mon, 25 Apr 2016 22:37:00 -0700	[thread overview]
Message-ID: <1461649027-5046-3-git-send-email-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <1461649027-5046-1-git-send-email-andrew.smirnov@gmail.com>

Port of_match_device() and of_device_get_match_data() from Linux kernel
code.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/of/Makefile |  2 +-
 drivers/of/device.c | 33 +++++++++++++++++++++++++++++++++
 include/of_device.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 drivers/of/device.c
 create mode 100644 include/of_device.h

diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 0dc2f8d..f31bb29 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,4 +1,4 @@
-obj-y += address.o base.o fdt.o platform.o
+obj-y += address.o base.o fdt.o platform.o device.o
 obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o
 obj-$(CONFIG_OF_GPIO) += of_gpio.o
 obj-$(CONFIG_OF_PCI) += of_pci.o
diff --git a/drivers/of/device.c b/drivers/of/device.c
new file mode 100644
index 0000000..e2c3c02
--- /dev/null
+++ b/drivers/of/device.c
@@ -0,0 +1,33 @@
+#include <common.h>
+#include <of.h>
+
+
+/**
+ * of_match_device - Tell if a struct device matches an of_device_id list
+ * @ids: array of of device match structures to search in
+ * @dev: the of device structure to match against
+ *
+ * Used by a driver to check whether an platform_device present in the
+ * system is in its list of supported devices.
+ */
+const struct of_device_id *of_match_device(const struct of_device_id *matches,
+					   const struct device_d *dev)
+{
+	if ((!matches) || (!dev->device_node))
+		return NULL;
+
+	return of_match_node(matches, dev->device_node);
+}
+EXPORT_SYMBOL(of_match_device);
+
+const void *of_device_get_match_data(const struct device_d *dev)
+{
+	const struct of_device_id *match;
+
+	match = of_match_device(dev->driver->of_compatible, dev);
+	if (!match)
+		return NULL;
+
+	return match->data;
+}
+EXPORT_SYMBOL(of_device_get_match_data);
diff --git a/include/of_device.h b/include/of_device.h
new file mode 100644
index 0000000..e84fc9c
--- /dev/null
+++ b/include/of_device.h
@@ -0,0 +1,48 @@
+#ifndef __OF_DEVICE_H
+#define __OF_DEVICE_H
+
+#include <driver.h>
+#include <of.h>
+
+
+#ifdef CONFIG_OFTREE
+extern const struct of_device_id *of_match_device(
+	const struct of_device_id *matches, const struct device_d *dev);
+
+/**
+ * of_driver_match_device - Tell if a driver's of_match_table matches a device.
+ * @drv: the device_driver structure to test
+ * @dev: the device structure to match against
+ */
+static inline int of_driver_match_device(struct device_d *dev,
+					 const struct driver_d *drv)
+{
+	return of_match_device(drv->of_compatible, dev) != NULL;
+}
+
+extern const void *of_device_get_match_data(const struct device_d *dev);
+
+#else /* CONFIG_OF */
+
+static inline int of_driver_match_device(struct device_d *dev,
+					 const struct device_d *drv)
+{
+	return 0;
+}
+
+static inline const void *of_device_get_match_data(const struct device_d *dev)
+{
+	return NULL;
+}
+
+static inline const struct of_device_id *__of_match_device(
+		const struct of_device_id *matches, const struct device_d *dev)
+{
+	return NULL;
+}
+#define of_match_device(matches, dev)	\
+	__of_match_device(of_match_ptr(matches), (dev))
+
+#endif /* CONFIG_OF */
+
+#endif /* _LINUX_OF_DEVICE_H */
-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-04-26  5:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-26  5:36 [PATCH 0/9] i.MX6Q+ fixes plus number of latest Kernel changes Andrey Smirnov
2016-04-26  5:36 ` [PATCH 1/9] PCI: imx6: Simplify imx6_pcie_remove() Andrey Smirnov
2016-04-26  5:37 ` Andrey Smirnov [this message]
2016-04-26  5:37 ` [PATCH 3/9] PCI: imx6: Add proper i.MX6+ reset sequence Andrey Smirnov
2016-04-26  5:37 ` [PATCH 4/9] PCI: imx6: Rename imx6_pcie_start_link() to imx6_pcie_establish_link() Andrey Smirnov
2016-05-04 21:53   ` Bjorn Helgaas
2016-04-26  5:37 ` [PATCH 5/9] PCI: imx6: Simplify a trivial if-return sequence Andrey Smirnov
2016-04-26  5:37 ` [PATCH 6/9] PCI: imx6: Move imx6_pcie_reset_phy() near other PHY handling functions Andrey Smirnov
2016-04-26  5:37 ` [PATCH 7/9] PCI: imx6: Move PHY reset into imx6_pcie_establish_link() Andrey Smirnov
2016-04-26  5:37 ` [PATCH 8/9] PCI: imx6: Remove broken Gen2 workaround Andrey Smirnov
2016-04-26  5:37 ` [PATCH 9/9] PCI: imx6: Add DT bindings to configure PHY Tx driver settings Andrey Smirnov
2016-04-27  9:05 ` [PATCH 0/9] i.MX6Q+ fixes plus number of latest Kernel changes Lucas Stach
2016-04-28  5:45 ` 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=1461649027-5046-3-git-send-email-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=fabio.estevam@freescale.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