[PATCH 3/4] of_spi: New function spi_of_node_to_master

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Michael Hennerich <michael.hennerich@xxxxxxxxxx>

look up master associated with of_node

Signed-off-by: Michael Hennerich <michael.hennerich@xxxxxxxxxx>
---
 drivers/of/of_spi.c     |   28 ++++++++++++++++++++++++++++
 drivers/spi/spi.c       |    4 ++--
 include/linux/of_spi.h  |    1 +
 include/linux/spi/spi.h |    2 ++
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/drivers/of/of_spi.c b/drivers/of/of_spi.c
index 6dbc074..f3dee01 100644
--- a/drivers/of/of_spi.c
+++ b/drivers/of/of_spi.c
@@ -97,3 +97,31 @@ void of_register_spi_devices(struct spi_master *master)
 	}
 }
 EXPORT_SYMBOL(of_register_spi_devices);
+
+static int __spi_master_of_match(struct device *dev, void *data)
+{
+	struct device_node *of_node = data;
+	return dev->of_node == of_node;
+}
+
+/**
+ * spi_of_node_to_master - look up master associated with of_node
+ * @of_node: pointer to the device tree node.
+ * Context: can sleep
+ *
+ * Returns a pointer to the relevant spi_master, or NULL if there is
+ * no such master registered.
+ */
+struct spi_master *spi_of_node_to_master(struct device_node *of_node)
+{
+	struct device *dev;
+	struct spi_master *master = NULL;
+
+	dev = class_find_device(&spi_master_class, NULL, of_node,
+				__spi_master_of_match);
+	if (dev)
+		master = container_of(dev, struct spi_master, dev);
+
+	return master;
+}
+EXPORT_SYMBOL_GPL(spi_of_node_to_master);
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b2ccdea..6f63a8e 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -515,12 +515,12 @@ static void spi_master_release(struct device *dev)
 	kfree(master);
 }
 
-static struct class spi_master_class = {
+struct class spi_master_class = {
 	.name		= "spi_master",
 	.owner		= THIS_MODULE,
 	.dev_release	= spi_master_release,
 };
-
+EXPORT_SYMBOL_GPL(spi_master_class);
 
 /**
  * spi_alloc_master - allocate SPI master controller
diff --git a/include/linux/of_spi.h b/include/linux/of_spi.h
index 9e3e70f..e1bafd2 100644
--- a/include/linux/of_spi.h
+++ b/include/linux/of_spi.h
@@ -13,6 +13,7 @@
 
 #if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE)
 extern void of_register_spi_devices(struct spi_master *master);
+extern struct spi_master *spi_of_node_to_master(struct device_node *of_node);
 #else
 static inline void of_register_spi_devices(struct spi_master *master)
 {
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 176fce9..62e566e 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -805,4 +805,6 @@ spi_unregister_device(struct spi_device *spi)
 extern const struct spi_device_id *
 spi_get_device_id(const struct spi_device *sdev);
 
+extern struct class spi_master_class;
+
 #endif /* __LINUX_SPI_H */
-- 
1.7.0.4


--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux