From: Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>
To: Grant Likely
<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>
Subject: [PATCH v2] of/platform: Add of_platform_depopulate() helper
Date: Tue, 13 May 2014 17:24:54 +0100 [thread overview]
Message-ID: <1399998294-24447-1-git-send-email-pawel.moll@arm.com> (raw)
In-Reply-To: <1399997324.3657.35.camel@hornet>
Drivers can us of_platform_populate() to create
platform devices for children of the device
main node (this can particularly happen in case
of MFD devices). Unfortunately, there was no
standard way of removing such sub-devices when
the main one is being removed.
This patch adds of_platform_depopulate() as
a complementary operation for the _populate()
one. It removes all platform and amba devices
that have been created from the Device Tree,
but leaves all other ones untouched (returning
-EBUSY in such case).
Signed-off-by: Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>
---
Changes since v1:
- using bool rather than int to signal remaining children
- recursing using of_platform_depopulate() itself
drivers/of/platform.c | 50 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/of_platform.h | 5 +++++
2 files changed, 55 insertions(+)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 236f47e..3b51e04 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -495,4 +495,54 @@ int of_platform_populate(struct device_node *root,
return rc;
}
EXPORT_SYMBOL_GPL(of_platform_populate);
+
+static int of_platform_device_destroy(struct device *dev, void *data)
+{
+ bool *children_left = data;
+
+ /* Do not touch devices not populated from the device tree */
+ if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) {
+ *children_left = true;
+ return 0;
+ }
+
+ /* Recurse, but don't touch this device if it has any children left */
+ if (of_platform_depopulate(dev) != 0) {
+ *children_left = true;
+ return 0;
+ }
+
+ if (dev->bus == &platform_bus_type)
+ platform_device_unregister(to_platform_device(dev));
+ else if (dev->bus == &amba_bustype)
+ amba_device_unregister(to_amba_device(dev));
+ else
+ *children_left = true;
+
+ return 0;
+}
+
+/**
+ * of_platform_depopulate() - Remove devices populated from device tree
+ * @parent: device which childred will be removed
+ *
+ * Complementary to of_platform_populate(), this function removes children
+ * of the given device (and, recurrently, their children) that have been
+ * created from their respective device tree nodes (and only those,
+ * leaving others - eg. manually created - unharmed).
+ *
+ * Returns 0 when all children devices have been removed or
+ * -EBUSY when some children remained.
+ */
+int of_platform_depopulate(struct device *parent)
+{
+ bool children_left = false;
+
+ device_for_each_child(parent, &children_left,
+ of_platform_device_destroy);
+
+ return children_left ? -EBUSY : 0;
+}
+EXPORT_SYMBOL_GPL(of_platform_depopulate);
+
#endif /* CONFIG_OF_ADDRESS */
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 05cb4a9..b1010ee 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -72,6 +72,7 @@ extern int of_platform_populate(struct device_node *root,
const struct of_device_id *matches,
const struct of_dev_auxdata *lookup,
struct device *parent);
+extern int of_platform_depopulate(struct device *parent);
#else
static inline int of_platform_populate(struct device_node *root,
const struct of_device_id *matches,
@@ -80,6 +81,10 @@ static inline int of_platform_populate(struct device_node *root,
{
return -ENODEV;
}
+static inline int of_platform_depopulate(struct device *parent)
+{
+ return -ENODEV;
+}
#endif
#endif /* _LINUX_OF_PLATFORM_H */
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-05-13 16:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-13 11:50 [PATCH] of: Add of_platform_depopulate() helper Pawel Moll
[not found] ` <1399981836-24837-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>
2014-05-13 13:19 ` Rob Herring
[not found] ` <CAL_JsqLj5Jy1-fvtDYm=CH8J5R-okKyKxP4X-htONuzQWreVRQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-05-13 16:08 ` Pawel Moll
2014-05-13 16:24 ` Pawel Moll [this message]
[not found] ` <1399998294-24447-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>
2014-05-14 11:08 ` [PATCH v2] of/platform: " Grant Likely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1399998294-24447-1-git-send-email-pawel.moll@arm.com \
--to=pawel.moll-5wv7dgnigg8@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).