From: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: Rob Herring <robherring2@gmail.com>,
Stephen Warren <swarren@wwwdotorg.org>,
Matt Porter <matt.porter@linaro.org>,
Koen Kooi <koen@dominion.thruhere.net>,
Alison Chaiken <Alison_Chaiken@mentor.com>,
Dinh Nguyen <dinh.linux@gmail.com>, Jan Lubbe <jluebbe@lasnet.de>,
Alexander Sverdlin <alexander.sverdlin@nsn.com>,
Michael Stickel <ms@mycable.de>,
Guenter Roeck <linux@roeck-us.net>,
Dirk Behme <dirk.behme@gmail.com>,
Alan Tull <delicious.quinoa@gmail.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Michael Bohan <mbohan@codeaurora.org>,
Ionut Nicu <ioan.nicu.ext@nsn.com>,
Michal Simek <monstr@monstr.eu>,
Matt Ranostay <mranostay@gmail.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Pete Popov <pete.popov@konsulko.com>,
Dan Malek <dan.malek@konsulko.com>,
Georgi Vlaev <georgi.vlaev@konsulko.com>,
Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
Pantelis Antoniou <panto@antoniou-consulting.com>
Subject: [PATCH v4 4/8] OF: platform: Add overlay bus handler
Date: Fri, 4 Apr 2014 15:43:57 +0300 [thread overview]
Message-ID: <1396615441-29630-5-git-send-email-pantelis.antoniou@konsulko.com> (raw)
In-Reply-To: <1396615441-29630-1-git-send-email-pantelis.antoniou@konsulko.com>
Add the bus handler registration needed for performing overlays
containing platform devices.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
---
drivers/base/platform.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 95 insertions(+), 3 deletions(-)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index e714709..bf5b429 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -922,6 +922,86 @@ struct bus_type platform_bus_type = {
};
EXPORT_SYMBOL_GPL(platform_bus_type);
+#ifdef CONFIG_OF_OVERLAY
+
+static int platform_handler_create(struct of_overlay_device_entry *de,
+ int revert)
+{
+ struct device_node *dn;
+ struct platform_device *pdev_parent, *pdev;
+
+ if (!de || !de->np)
+ return -ENOTSUPP;
+
+ dn = de->np;
+
+ /* verify that the parent is a bus */
+ if (!of_match_node(of_default_bus_match_table, dn->parent))
+ return -ENOTSUPP;
+
+ /* pdev_parent may be NULL when there is no bus platform device */
+ pdev_parent = of_find_device_by_node(dn->parent);
+ pdev = of_platform_device_create(dn, NULL,
+ pdev_parent ? &pdev_parent->dev : NULL);
+ of_dev_put(pdev_parent);
+
+ if (pdev == NULL) {
+ pr_err("%s: failed to create platform device "
+ "for '%s'\n",
+ __func__, dn->full_name);
+ /* of_platform_device_create tosses the real error code */
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int platform_handler_remove(struct of_overlay_device_entry *de,
+ int revert)
+{
+ struct device_node *dn;
+ struct platform_device *pdev;
+
+ if (!de || !de->np)
+ return -ENOTSUPP;
+
+ dn = de->np;
+
+ pdev = of_find_device_by_node(dn);
+ if (pdev == NULL)
+ return -ENOTSUPP;
+
+ /* unregister takes one ref away */
+ platform_device_unregister(pdev);
+
+ /* and put the reference of the find */
+ of_dev_put(pdev);
+
+ return 0;
+}
+
+static const struct of_overlay_handler_ops platform_handler_ops = {
+ .create = platform_handler_create,
+ .remove = platform_handler_remove,
+};
+
+static struct of_overlay_handler platform_handler = {
+ .name = "platform",
+ .ops = &platform_handler_ops,
+};
+
+static int __init platform_bus_handler_register(void)
+{
+ return of_overlay_handler_register(&platform_handler);
+}
+
+#else
+static inline int platform_bus_handler_register(void)
+{
+ return 0;
+}
+#endif
+
int __init platform_bus_init(void)
{
int error;
@@ -930,10 +1010,22 @@ int __init platform_bus_init(void)
error = device_register(&platform_bus);
if (error)
- return error;
- error = bus_register(&platform_bus_type);
+ goto err_out;
+
+ error = bus_register(&platform_bus_type);
if (error)
- device_unregister(&platform_bus);
+ goto err_unreg_dev;
+
+ error = platform_bus_handler_register();
+ if (error)
+ goto err_unreg_bus;
+
+ return 0;
+err_unreg_bus:
+ bus_unregister(&platform_bus_type);
+err_unreg_dev:
+ device_unregister(&platform_bus);
+err_out:
return error;
}
--
1.7.12
next prev parent reply other threads:[~2014-04-04 12:46 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-04 12:43 [PATCH v4 0/8] Introducing (yet again) Device Tree Overlays Pantelis Antoniou
2014-04-04 12:43 ` [PATCH v4 1/8] OF: Introduce Device Tree resolve support Pantelis Antoniou
2014-04-04 12:43 ` [PATCH v4 2/8] OF: Introduce DT overlay support Pantelis Antoniou
2014-05-14 10:08 ` Grant Likely
2014-05-14 12:11 ` Michael Stickel
2014-05-14 15:49 ` Grant Likely
2014-05-14 16:13 ` Guenter Roeck
2014-05-15 7:14 ` Pantelis Antoniou
2014-05-14 13:03 ` Geert Uytterhoeven
2014-05-14 13:18 ` Guenter Roeck
2014-05-15 7:15 ` Pantelis Antoniou
2014-05-14 15:34 ` Grant Likely
2014-05-15 7:12 ` Pantelis Antoniou
2014-05-15 7:20 ` Geert Uytterhoeven
2014-05-16 10:58 ` Grant Likely
2014-05-16 11:52 ` Geert Uytterhoeven
2014-05-20 5:50 ` Grant Likely
2014-05-20 7:38 ` Geert Uytterhoeven
2014-05-26 10:48 ` Grant Likely
2014-05-26 10:57 ` Geert Uytterhoeven
2014-05-26 11:08 ` Pantelis Antoniou
2014-05-26 11:23 ` Grant Likely
2014-05-26 11:55 ` Pantelis Antoniou
2014-05-26 15:09 ` Sebastian Reichel
2014-05-26 15:14 ` Guenter Roeck
2014-05-26 23:00 ` Sebastian Reichel
2014-05-26 15:14 ` Pantelis Antoniou
2014-05-26 21:33 ` Grant Likely
2014-05-26 21:44 ` Geert Uytterhoeven
2014-05-26 23:47 ` Guenter Roeck
2014-05-27 12:11 ` Grant Likely
2014-05-26 22:36 ` Sebastian Reichel
2014-05-26 23:42 ` Guenter Roeck
2014-05-27 0:32 ` Sebastian Reichel
2014-05-27 0:54 ` Guenter Roeck
2014-05-27 12:12 ` Grant Likely
2014-05-27 12:24 ` Pantelis Antoniou
2014-05-27 15:21 ` Guenter Roeck
2014-05-27 15:38 ` Pantelis Antoniou
2014-05-27 17:52 ` Geert Uytterhoeven
2014-05-27 18:22 ` Guenter Roeck
2014-05-27 20:11 ` Grant Likely
2014-05-20 12:27 ` Pantelis Antoniou
2014-05-15 14:18 ` Grant Likely
2014-04-04 12:43 ` [PATCH v4 3/8] OF: DT-Overlay configfs interface Pantelis Antoniou
2014-04-04 12:43 ` Pantelis Antoniou [this message]
2014-04-04 12:43 ` [PATCH v4 5/8] of: i2c: Export single device registration method Pantelis Antoniou
2014-04-04 12:43 ` [PATCH v4 6/8] OF: i2c: Add overlay bus handler Pantelis Antoniou
2014-04-04 12:44 ` [PATCH v4 7/8] OF: spi: " Pantelis Antoniou
2014-04-04 12:44 ` [PATCH v4 8/8] OF: selftest: Add overlay self-test support Pantelis Antoniou
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=1396615441-29630-5-git-send-email-pantelis.antoniou@konsulko.com \
--to=pantelis.antoniou@konsulko.com \
--cc=Alison_Chaiken@mentor.com \
--cc=alexander.sverdlin@nsn.com \
--cc=dan.malek@konsulko.com \
--cc=delicious.quinoa@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dinh.linux@gmail.com \
--cc=dirk.behme@gmail.com \
--cc=georgi.vlaev@konsulko.com \
--cc=grant.likely@secretlab.ca \
--cc=ioan.nicu.ext@nsn.com \
--cc=jluebbe@lasnet.de \
--cc=koen@dominion.thruhere.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=matt.porter@linaro.org \
--cc=mbohan@codeaurora.org \
--cc=monstr@monstr.eu \
--cc=mranostay@gmail.com \
--cc=ms@mycable.de \
--cc=panto@antoniou-consulting.com \
--cc=pete.popov@konsulko.com \
--cc=robherring2@gmail.com \
--cc=s.hauer@pengutronix.de \
--cc=swarren@wwwdotorg.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).