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 commit is contained in:
Marco Felsch 2018-09-25 11:42:29 +02:00 committed by Mark Brown
parent 5b394b2ddf
commit 5f143af750
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
2 changed files with 21 additions and 3 deletions

View File

@ -3314,20 +3314,23 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#if IS_ENABLED(CONFIG_OF_DYNAMIC) #if IS_ENABLED(CONFIG_OF)
static int __spi_of_device_match(struct device *dev, void *data) static int __spi_of_device_match(struct device *dev, void *data)
{ {
return dev->of_node == data; return dev->of_node == data;
} }
/* must call put_device() when done with returned spi_device device */ /* 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, struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
__spi_of_device_match); __spi_of_device_match);
return dev ? to_spi_device(dev) : NULL; return dev ? to_spi_device(dev) : NULL;
} }
EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
#endif /* IS_ENABLED(CONFIG_OF) */
#if IS_ENABLED(CONFIG_OF_DYNAMIC)
static int __spi_of_controller_match(struct device *dev, const void *data) static int __spi_of_controller_match(struct device *dev, const void *data)
{ {
return dev->of_node == data; return dev->of_node == data;

View File

@ -1277,7 +1277,6 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
{ return 0; } { return 0; }
#endif #endif
/* If you're hotplugging an adapter with devices (parport, usb, etc) /* If you're hotplugging an adapter with devices (parport, usb, etc)
* use spi_new_device() to describe each device. You can also call * use spi_new_device() to describe each device. You can also call
* spi_unregister_device() to start making that device vanish, but * spi_unregister_device() to start making that device vanish, but
@ -1309,6 +1308,22 @@ spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer)
return list_is_last(&xfer->transfer_list, &ctlr->cur_msg->transfers); return list_is_last(&xfer->transfer_list, &ctlr->cur_msg->transfers);
} }
/* OF support code */
#if IS_ENABLED(CONFIG_OF)
/* 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);
#else
static inline struct spi_device *
of_find_spi_device_by_node(struct device_node *node)
{
return NULL;
}
#endif /* IS_ENABLED(CONFIG_OF) */
/* Compatibility layer */ /* Compatibility layer */
#define spi_master spi_controller #define spi_master spi_controller