summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi.c
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-10-11 20:10:13 +0100
committerMark Brown <broonie@linaro.org>2013-10-11 20:10:13 +0100
commit2cc6e2e0c8157b9e6ed8dbe5c7284865f6afbd46 (patch)
treef50c505d9811d6fa2d9c042f2fdfa7ebcf79e158 /drivers/spi/spi.c
parentb158935f70b9c156903338053216dd0adf7ce31c (diff)
parentebd805cc14bec607e74795b7933570f240508cb4 (diff)
downloadlinux-2cc6e2e0c8157b9e6ed8dbe5c7284865f6afbd46.tar.gz
linux-2cc6e2e0c8157b9e6ed8dbe5c7284865f6afbd46.tar.bz2
linux-2cc6e2e0c8157b9e6ed8dbe5c7284865f6afbd46.zip
Merge remote-tracking branch 'spi/topic/s3c64xx' into spi-loop
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r--drivers/spi/spi.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 85c18d8a86b3..f37356c26b7d 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1370,6 +1370,41 @@ done:
}
EXPORT_SYMBOL_GPL(spi_register_master);
+static void devm_spi_unregister(struct device *dev, void *res)
+{
+ spi_unregister_master(*(struct spi_master **)res);
+}
+
+/**
+ * dev_spi_register_master - register managed SPI master controller
+ * @dev: device managing SPI master
+ * @master: initialized master, originally from spi_alloc_master()
+ * Context: can sleep
+ *
+ * Register a SPI device as with spi_register_master() which will
+ * automatically be unregister
+ */
+int devm_spi_register_master(struct device *dev, struct spi_master *master)
+{
+ struct spi_master **ptr;
+ int ret;
+
+ ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ ret = spi_register_master(master);
+ if (ret != 0) {
+ *ptr = master;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_spi_register_master);
+
static int __unregister(struct device *dev, void *null)
{
spi_unregister_device(to_spi_device(dev));