mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Teresa Gámez" <t.gamez@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCHv2 1/3] of: Add of_device_enable_and_register functions
Date: Mon, 3 Nov 2014 13:31:52 +0100	[thread overview]
Message-ID: <1415017914-43444-1-git-send-email-t.gamez@phytec.de> (raw)

Function to enable and register a disabled device.
The devices can be registered using the
device node with of_device_enable_and_register() or
with the device node name/path by using the
of_device_enable_and_register_by_name() function.

Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
---
v2:
- renamed functions

 drivers/of/platform.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 include/of.h          | 14 ++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index c417cfd..92ef534 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -197,6 +197,49 @@ static struct device_d *of_platform_device_create(struct device_node *np,
 	return NULL;
 }
 
+/**
+ * of_device_enable_and_register - Enable and register device
+ * @np: pointer to node to enable create device for
+ *
+ * Returns pointer to created platform device, or NULL if a device was not
+ * registered. Unavailable devices will not get registered.
+ */
+struct device_d *of_device_enable_and_register(struct device_node *np)
+{
+	struct device_d *dev;
+
+	of_device_enable(np);
+
+	dev = of_platform_device_create(np, NULL);
+	if (!dev)
+		return NULL;
+
+	return dev;
+}
+EXPORT_SYMBOL(of_device_enable_and_register);
+
+/**
+ * of_device_enable_and_register_by_name - Enable and register device by name
+ * @name: name or path of the device node
+ *
+ * Returns pointer to created platform device, or NULL if a device was not
+ * registered. Unavailable devices will not get registered.
+ */
+struct device_d *of_device_enable_and_register_by_name(const char *name)
+{
+	struct device_node *node;
+
+	node = of_find_node_by_name(NULL, name);
+	if (!node)
+		node = of_find_node_by_path(name);
+
+	if (!node)
+		return NULL;
+
+	return of_device_enable_and_register(node);
+}
+EXPORT_SYMBOL(of_device_enable_and_register_by_name);
+
 #ifdef CONFIG_ARM_AMBA
 static struct device_d *of_amba_device_create(struct device_node *np)
 {
diff --git a/include/of.h b/include/of.h
index 29694a9..7b93c58 100644
--- a/include/of.h
+++ b/include/of.h
@@ -227,6 +227,8 @@ extern int of_platform_populate(struct device_node *root,
 				const struct of_device_id *matches,
 				struct device_d *parent);
 extern struct device_d *of_find_device_by_node(struct device_node *np);
+extern struct device_d *of_device_enable_and_register(struct device_node *np);
+extern struct device_d *of_device_enable_and_register_by_name(const char *name);
 
 struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node);
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
@@ -582,6 +584,18 @@ static inline struct device_d *of_find_device_by_node(struct device_node *np)
 {
 	return NULL;
 }
+
+static inline struct device_d *of_device_enable_and_register(
+				struct device_node *np)
+{
+	return NULL;
+}
+
+static inline struct device_d *of_device_enable_and_register_by_name(
+				const char *name)
+{
+	return NULL;
+}
 #endif
 
 #define for_each_node_by_name(dn, name) \
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2014-11-03 12:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-03 12:31 Teresa Gámez [this message]
2014-11-03 12:31 ` [PATCHv2 2/3] ARM: am335x: Add register of boot devices Teresa Gámez
2014-11-03 14:45   ` Sascha Hauer
2014-11-03 12:31 ` [PATCHv2 3/3] ARM: am335x: phyCORE-AM335x: Create new dts for MLO Teresa Gámez

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=1415017914-43444-1-git-send-email-t.gamez@phytec.de \
    --to=t.gamez@phytec.de \
    --cc=barebox@lists.infradead.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