[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1401281193-27146-9-git-send-email-pantelis.antoniou@konsulko.com>
Date: Wed, 28 May 2014 15:46:32 +0300
From: Pantelis Antoniou <pantelis.antoniou@...sulko.com>
To: Grant Likely <grant.likely@...retlab.ca>
Cc: Rob Herring <robherring2@...il.com>,
Stephen Warren <swarren@...dotorg.org>,
Matt Porter <matt.porter@...aro.org>,
Koen Kooi <koen@...inion.thruhere.net>,
Alison Chaiken <Alison_Chaiken@...tor.com>,
Dinh Nguyen <dinh.linux@...il.com>,
Jan Lubbe <jluebbe@...net.de>,
Alexander Sverdlin <alexander.sverdlin@....com>,
Michael Stickel <ms@...able.de>,
Guenter Roeck <linux@...ck-us.net>,
Dirk Behme <dirk.behme@...il.com>,
Alan Tull <delicious.quinoa@...il.com>,
Sascha Hauer <s.hauer@...gutronix.de>,
Michael Bohan <mbohan@...eaurora.org>,
Ionut Nicu <ioan.nicu.ext@....com>,
Michal Simek <monstr@...str.eu>,
Matt Ranostay <mranostay@...il.com>,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
Pete Popov <pete.popov@...sulko.com>,
Dan Malek <dan.malek@...sulko.com>,
Georgi Vlaev <georgi.vlaev@...sulko.com>,
Pantelis Antoniou <pantelis.antoniou@...sulko.com>,
Pantelis Antoniou <panto@...oniou-consulting.com>
Subject: [PATCH v5 8/9] OF: spi: Add OF notifier handler
Add OF notifier handler needed for creating/destroying spi devices
according to dynamic runtime changes in the DT live tree.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@...sulko.com>
---
drivers/spi/spi.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 63 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a98d236..3d8feca 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2336,6 +2336,57 @@ EXPORT_SYMBOL_GPL(spi_write_then_read);
/*-------------------------------------------------------------------------*/
+#if IS_ENABLED(CONFIG_OF)
+
+static int of_spi_notify(struct notifier_block *nb,
+ unsigned long action, void *arg)
+{
+ struct device_node *dn;
+ struct spi_master *master;
+ struct spi_device *spi;
+
+ if (action == OF_RECONFIG_DYNAMIC_CREATE_DEV) {
+
+ dn = arg;
+
+ master = of_find_spi_master_by_node(dn->parent);
+ if (master == NULL)
+ return NOTIFY_OK; /* not for us */
+
+ spi = of_register_spi_device(master, dn);
+ put_device(&master->dev);
+
+ if (IS_ERR(spi)) {
+ pr_err("%s: failed to create for '%s'\n",
+ __func__, dn->full_name);
+ return notifier_from_errno(PTR_ERR(spi));
+ }
+
+ } else if (action == OF_RECONFIG_DYNAMIC_DESTROY_DEV) {
+
+ dn = arg;
+
+ /* find our device by node */
+ spi = of_find_spi_device_by_node(dn);
+ if (spi == NULL)
+ return NOTIFY_OK; /* no? not meant for us */
+
+ /* unregister takes one ref away */
+ spi_unregister_device(spi);
+
+ /* and put the reference of the find */
+ put_device(&spi->dev);
+
+ } else
+ return NOTIFY_OK;
+
+ return NOTIFY_STOP;
+}
+
+static struct notifier_block spi_of_notifier;
+
+#endif
+
static int __init spi_init(void)
{
int status;
@@ -2353,8 +2404,19 @@ static int __init spi_init(void)
status = class_register(&spi_master_class);
if (status < 0)
goto err2;
- return 0;
+#if IS_ENABLED(CONFIG_OF)
+ spi_of_notifier.notifier_call = of_spi_notify;
+ status = of_reconfig_notifier_register(&spi_of_notifier);
+ if (status)
+ goto err3;
+#endif
+
+ return 0;
+#if IS_ENABLED(CONFIG_OF)
+err3:
+ class_unregister(&spi_master_class);
+#endif
err2:
bus_unregister(&spi_bus_type);
err1:
--
1.7.12
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists