* [PATCH] of: Add of_platform_depopulate() helper @ 2014-05-13 11:50 Pawel Moll [not found] ` <1399981836-24837-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Pawel Moll @ 2014-05-13 11:50 UTC (permalink / raw) To: Grant Likely, Rob Herring Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Pawel Moll 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> --- drivers/of/platform.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 5 +++++ 2 files changed, 57 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 2d0c8b7..b5c49c3 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -495,4 +495,56 @@ 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) +{ + int *parents_children_left = data; + int my_children_left = 0; + + /* Do not touch devices not populated from the device tree */ + if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) { + (*parents_children_left)++; + return 0; + } + + device_for_each_child(dev, &my_children_left, + of_platform_device_destroy); + if (my_children_left) { + (*parents_children_left)++; + 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 + (*parents_children_left)++; + + 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) +{ + int children_left = 0; + + 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
[parent not found: <1399981836-24837-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH] of: Add of_platform_depopulate() helper [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> 0 siblings, 1 reply; 5+ messages in thread From: Rob Herring @ 2014-05-13 13:19 UTC (permalink / raw) To: Pawel Moll Cc: Grant Likely, Rob Herring, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org On Tue, May 13, 2014 at 6:50 AM, Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org> wrote: > 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> > --- > drivers/of/platform.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ > include/linux/of_platform.h | 5 +++++ > 2 files changed, 57 insertions(+) > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > index 2d0c8b7..b5c49c3 100644 > --- a/drivers/of/platform.c > +++ b/drivers/of/platform.c > @@ -495,4 +495,56 @@ 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) > +{ > + int *parents_children_left = data; You are not really tracking how many children are left, so this can just be a bool. > + int my_children_left = 0; > + > + /* Do not touch devices not populated from the device tree */ > + if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) { > + (*parents_children_left)++; > + return 0; > + } > + > + device_for_each_child(dev, &my_children_left, > + of_platform_device_destroy); Can't you call of_platform_depopulate here? > + if (my_children_left) { > + (*parents_children_left)++; > + return 0; > + } -- 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <CAL_JsqLj5Jy1-fvtDYm=CH8J5R-okKyKxP4X-htONuzQWreVRQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [PATCH] of: Add of_platform_depopulate() helper [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 ` [PATCH v2] of/platform: " Pawel Moll 0 siblings, 1 reply; 5+ messages in thread From: Pawel Moll @ 2014-05-13 16:08 UTC (permalink / raw) To: Rob Herring Cc: grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org, Rob Herring, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org On Tue, 2014-05-13 at 14:19 +0100, Rob Herring wrote: > On Tue, May 13, 2014 at 6:50 AM, Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org> wrote: > > 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> > > --- > > drivers/of/platform.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ > > include/linux/of_platform.h | 5 +++++ > > 2 files changed, 57 insertions(+) > > > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > > index 2d0c8b7..b5c49c3 100644 > > --- a/drivers/of/platform.c > > +++ b/drivers/of/platform.c > > @@ -495,4 +495,56 @@ 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) > > +{ > > + int *parents_children_left = data; > > You are not really tracking how many children are left, so this can > just be a bool. That's true. > > + int my_children_left = 0; > > + > > + /* Do not touch devices not populated from the device tree */ > > + if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) { > > + (*parents_children_left)++; > > + return 0; > > + } > > + > > + device_for_each_child(dev, &my_children_left, > > + of_platform_device_destroy); > > Can't you call of_platform_depopulate here? ... and check its result instead of ? I guess I could. Will have a look how it looks like. Paweł -- 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] of/platform: Add of_platform_depopulate() helper 2014-05-13 16:08 ` Pawel Moll @ 2014-05-13 16:24 ` Pawel Moll [not found] ` <1399998294-24447-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Pawel Moll @ 2014-05-13 16:24 UTC (permalink / raw) To: Grant Likely, Rob Herring Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Pawel Moll 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
[parent not found: <1399998294-24447-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH v2] of/platform: Add of_platform_depopulate() helper [not found] ` <1399998294-24447-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org> @ 2014-05-14 11:08 ` Grant Likely 0 siblings, 0 replies; 5+ messages in thread From: Grant Likely @ 2014-05-14 11:08 UTC (permalink / raw) To: Rob Herring Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Pawel Moll On Tue, 13 May 2014 17:24:54 +0100, Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org> wrote: > 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). Nit: What's with the 50-column word wrap? 72 is the norm for commit text. Acked-by: Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> If you like you can merge this with your other series since it is dependent. > > 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-14 11:08 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 ` [PATCH v2] of/platform: " Pawel Moll [not found] ` <1399998294-24447-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org> 2014-05-14 11:08 ` Grant Likely
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).