summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2016-04-25 22:37:00 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2016-04-28 07:44:04 +0200
commitbd55401e972d630338d3326373f8aef9d204faaf (patch)
tree7108cc0cf9c6e89824fa2065b59b7c35bb754f7e
parent9aa9049cfd999c4a885f214c4d6dfb5eb4bc7bf7 (diff)
downloadbarebox-bd55401e972d630338d3326373f8aef9d204faaf.tar.gz
barebox-bd55401e972d630338d3326373f8aef9d204faaf.tar.xz
OF: Port of_match_device() and of_device_get_match_data()
Port of_match_device() and of_device_get_match_data() from Linux kernel code. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Acked-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/of/Makefile2
-rw-r--r--drivers/of/device.c33
-rw-r--r--include/of_device.h48
3 files changed, 82 insertions, 1 deletions
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 0dc2f8d63e..f31bb293fb 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 0000000000..e2c3c02d27
--- /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 0000000000..e84fc9c377
--- /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 */