spi: make OF helper available for others

This change “spi: make OF helper available for others” in Linux kernel is authored by Marco Felsch <m.felsch [at] pengutronix.de> on Tue Sep 25 11:42:29 2018 +0200.

spi: make OF helper available for others

The of_find_spi_device_by_node() helper function is useful for other
modules too. Export the funciton as GPL like all other spi helper
functions and make it available if CONFIG_OF is enabled, because it isn't
related to the CONFIG_OF_DYNAMIC context. Finally add a stub if
CONFIG_OF isn't enabled, so others must not care about it.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit 5f143af.

There are 24 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/spi/spi.c       |  7 +++++--
 include/linux/spi/spi.h | 17 ++++++++++++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ec395a6..f939f58 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3314,20 +3314,23 @@ int spi_write_then_read(struct spi_device *spi,
 static int __spi_of_device_match(struct device *dev, void *data)
 	return dev->of_node == data;
 /* must call put_device() when done with returned spi_device device */
-static struct spi_device *of_find_spi_device_by_node(struct device_node *node)
+struct spi_device *of_find_spi_device_by_node(struct device_node *node)
 	struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
 	return dev ? to_spi_device(dev) : NULL;
+#endif /* IS_ENABLED(CONFIG_OF) */
 static int __spi_of_controller_match(struct device *dev, const void *data)
 	return dev->of_node == data;
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index a64235e..e9ebfcd 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1277,7 +1277,6 @@ struct spi_board_info {
 	{ return 0; }
 /* If you're hotplugging an adapter with devices (parport, usb, etc)
  * use spi_new_device() to describe each device.  You can also call
  * spi_unregister_device() to start making that device vanish, but
@@ -1309,6 +1308,22 @@ struct spi_board_info {
 	return list_is_last(&xfer->transfer_list, &ctlr->cur_msg->transfers);
+/* OF support code */
+/* must call put_device() when done with returned spi_device device */
+extern struct spi_device *
+of_find_spi_device_by_node(struct device_node *node);
+static inline struct spi_device *
+of_find_spi_device_by_node(struct device_node *node)
+	return NULL;
+#endif /* IS_ENABLED(CONFIG_OF) */
 /* Compatibility layer */
 #define spi_master			spi_controller

The commit for this change in Linux stable tree is 5f143af (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *