All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
To: gregkh@linuxfoundation.org, robh+dt@kernel.org,
	mark.rutland@arm.com, frowand.list@gmail.com
Cc: heikki.krogerus@linux.intel.com, hdegoede@redhat.com,
	andy.shevchenko@gmail.com, p.zabel@pengutronix.de,
	linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	devicetree@vger.kernel.org,
	Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Subject: [PATCH/RFC 04/11] of: platform: add device connection parsing
Date: Wed, 18 Apr 2018 17:09:58 +0900	[thread overview]
Message-ID: <1524039005-30618-5-git-send-email-yoshihiro.shimoda.uh@renesas.com> (raw)
In-Reply-To: <1524039005-30618-1-git-send-email-yoshihiro.shimoda.uh@renesas.com>

This patch adds device connection parsing in of_platform_populate().

TODO:
 - How to free the devcon memories?
 - How to remove the devcon instances?

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/of/platform.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h    |  1 +
 2 files changed, 67 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index c00d81d..41c018d 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -17,6 +17,7 @@
 #include <linux/slab.h>
 #include <linux/of_address.h>
 #include <linux/of_device.h>
+#include <linux/of_graph.h>
 #include <linux/of_iommu.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
@@ -326,6 +327,63 @@ static const struct of_dev_auxdata *of_dev_lookup(const struct of_dev_auxdata *l
 	return NULL;
 }
 
+static int of_parse_device_connection(struct device_node *np)
+{
+	struct device_node *child_ep, *parent, *remote_parent;
+	struct platform_device *pdev, *remote_pdev;
+	struct device_connection *devcon = NULL;
+	const char *id;
+
+	if (of_node_check_flag(np, OF_DEVICE_CONNECTED)) {
+		pr_debug("%s() - skipping %pOF, already device connected\n",
+			__func__, np);
+		return 0;
+	}
+
+	of_node_set_flag(np, OF_DEVICE_CONNECTED);
+
+	for_each_endpoint_of_node(np, child_ep) {
+		if (of_property_read_string(child_ep, "device-connection-id",
+					    &id) < 0)
+			continue;
+
+		remote_parent = of_graph_get_remote_port_parent(child_ep);
+		if (!remote_parent)
+			return 0;
+
+		parent = of_graph_get_port_parent(child_ep);
+		if (!parent)
+			return 0;
+
+		pdev = of_find_device_by_node(parent);
+		if (!pdev)
+			return 0;
+
+		/*
+		 * WARN_ON in really_probe() may happen if devm_kzalloc is
+		 * used. TODO: How to free this?
+		 */
+		devcon = kzalloc(sizeof(*devcon), GFP_KERNEL);
+		if (!devcon)
+			return -ENOMEM;
+
+		devcon->id = id;
+		remote_pdev = of_find_device_by_node(remote_parent);
+		if (!remote_pdev) {
+			kfree(devcon);
+			return 0;
+		}
+
+		devcon->endpoint[0] = dev_name(&pdev->dev);
+		devcon->endpoint[1] = dev_name(&remote_pdev->dev);
+
+		/* TODO: How to remove the connection? */
+		device_connection_add(devcon);
+	}
+
+	return 0;
+}
+
 /**
  * of_platform_bus_create() - Create a device for a node and its children.
  * @bus: device node of the bus to instantiate
@@ -477,6 +535,14 @@ int of_platform_populate(struct device_node *root,
 	}
 	of_node_set_flag(root, OF_POPULATED_BUS);
 
+	for_each_child_of_node(root, child) {
+		rc = of_parse_device_connection(child);
+		if (rc) {
+			of_node_put(child);
+			break;
+		}
+	}
+
 	of_node_put(root);
 	return rc;
 }
diff --git a/include/linux/of.h b/include/linux/of.h
index 4d25e4f..30aa103 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -143,6 +143,7 @@ static inline void of_node_put(struct device_node *node) { }
 #define OF_DETACHED	2 /* node has been detached from the device tree */
 #define OF_POPULATED	3 /* device already created for the node */
 #define OF_POPULATED_BUS	4 /* of_platform_populate recursed to children of this node */
+#define OF_DEVICE_CONNECTED	5 /* checked devcon on of_platform_populate */
 
 #define OF_BAD_ADDR	((u64)-1)
 
-- 
1.9.1

WARNING: multiple messages have this Message-ID (diff)
From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
To: gregkh@linuxfoundation.org, robh+dt@kernel.org,
	mark.rutland@arm.com, frowand.list@gmail.com
Cc: heikki.krogerus@linux.intel.com, hdegoede@redhat.com,
	andy.shevchenko@gmail.com, p.zabel@pengutronix.de,
	linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	devicetree@vger.kernel.org,
	Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Subject: [PATCH/RFC,04/11] of: platform: add device connection parsing
Date: Wed, 18 Apr 2018 17:09:58 +0900	[thread overview]
Message-ID: <1524039005-30618-5-git-send-email-yoshihiro.shimoda.uh@renesas.com> (raw)

This patch adds device connection parsing in of_platform_populate().

TODO:
 - How to free the devcon memories?
 - How to remove the devcon instances?

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/of/platform.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h    |  1 +
 2 files changed, 67 insertions(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index c00d81d..41c018d 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -17,6 +17,7 @@
 #include <linux/slab.h>
 #include <linux/of_address.h>
 #include <linux/of_device.h>
+#include <linux/of_graph.h>
 #include <linux/of_iommu.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
@@ -326,6 +327,63 @@ static const struct of_dev_auxdata *of_dev_lookup(const struct of_dev_auxdata *l
 	return NULL;
 }
 
+static int of_parse_device_connection(struct device_node *np)
+{
+	struct device_node *child_ep, *parent, *remote_parent;
+	struct platform_device *pdev, *remote_pdev;
+	struct device_connection *devcon = NULL;
+	const char *id;
+
+	if (of_node_check_flag(np, OF_DEVICE_CONNECTED)) {
+		pr_debug("%s() - skipping %pOF, already device connected\n",
+			__func__, np);
+		return 0;
+	}
+
+	of_node_set_flag(np, OF_DEVICE_CONNECTED);
+
+	for_each_endpoint_of_node(np, child_ep) {
+		if (of_property_read_string(child_ep, "device-connection-id",
+					    &id) < 0)
+			continue;
+
+		remote_parent = of_graph_get_remote_port_parent(child_ep);
+		if (!remote_parent)
+			return 0;
+
+		parent = of_graph_get_port_parent(child_ep);
+		if (!parent)
+			return 0;
+
+		pdev = of_find_device_by_node(parent);
+		if (!pdev)
+			return 0;
+
+		/*
+		 * WARN_ON in really_probe() may happen if devm_kzalloc is
+		 * used. TODO: How to free this?
+		 */
+		devcon = kzalloc(sizeof(*devcon), GFP_KERNEL);
+		if (!devcon)
+			return -ENOMEM;
+
+		devcon->id = id;
+		remote_pdev = of_find_device_by_node(remote_parent);
+		if (!remote_pdev) {
+			kfree(devcon);
+			return 0;
+		}
+
+		devcon->endpoint[0] = dev_name(&pdev->dev);
+		devcon->endpoint[1] = dev_name(&remote_pdev->dev);
+
+		/* TODO: How to remove the connection? */
+		device_connection_add(devcon);
+	}
+
+	return 0;
+}
+
 /**
  * of_platform_bus_create() - Create a device for a node and its children.
  * @bus: device node of the bus to instantiate
@@ -477,6 +535,14 @@ int of_platform_populate(struct device_node *root,
 	}
 	of_node_set_flag(root, OF_POPULATED_BUS);
 
+	for_each_child_of_node(root, child) {
+		rc = of_parse_device_connection(child);
+		if (rc) {
+			of_node_put(child);
+			break;
+		}
+	}
+
 	of_node_put(root);
 	return rc;
 }
diff --git a/include/linux/of.h b/include/linux/of.h
index 4d25e4f..30aa103 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -143,6 +143,7 @@ static inline void of_node_put(struct device_node *node) { }
 #define OF_DETACHED	2 /* node has been detached from the device tree */
 #define OF_POPULATED	3 /* device already created for the node */
 #define OF_POPULATED_BUS	4 /* of_platform_populate recursed to children of this node */
+#define OF_DEVICE_CONNECTED	5 /* checked devcon on of_platform_populate */
 
 #define OF_BAD_ADDR	((u64)-1)
 

  parent reply	other threads:[~2018-04-18  8:09 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-18  8:09 [PATCH/RFC 00/11] add support for R-Car USB3.0 role switch Yoshihiro Shimoda
2018-04-18  8:09 ` [PATCH/RFC 01/11] Documentation: of: Add device-connection-id property Yoshihiro Shimoda
2018-04-18  8:09   ` [PATCH/RFC,01/11] " Yoshihiro Shimoda
2018-04-24 14:33   ` [PATCH/RFC 01/11] " Rob Herring
2018-04-24 14:33     ` [PATCH/RFC,01/11] " Rob Herring
2018-04-25  9:09     ` [PATCH/RFC 01/11] " Yoshihiro Shimoda
2018-04-25  9:09       ` [PATCH/RFC,01/11] " Yoshihiro Shimoda
2018-04-18  8:09 ` [PATCH/RFC 02/11] dt-bindings: usb: add usb role switch driver Yoshihiro Shimoda
2018-04-18  8:09   ` [PATCH/RFC,02/11] " Yoshihiro Shimoda
2018-04-24 14:35   ` [PATCH/RFC 02/11] " Rob Herring
2018-04-24 14:35     ` [PATCH/RFC,02/11] " Rob Herring
2018-04-18  8:09 ` [PATCH/RFC 03/11] dt-bindings: usb: add Renesas R-Car USB 3.0 " Yoshihiro Shimoda
2018-04-18  8:09   ` [PATCH/RFC,03/11] " Yoshihiro Shimoda
2018-04-18  8:09 ` Yoshihiro Shimoda [this message]
2018-04-18  8:09   ` [PATCH/RFC,04/11] of: platform: add device connection parsing Yoshihiro Shimoda
2018-04-24 12:33   ` [PATCH/RFC 04/11] " Heikki Krogerus
2018-04-24 12:33     ` [PATCH/RFC,04/11] " Heikki Krogerus
2018-04-25  8:59     ` [PATCH/RFC 04/11] " Yoshihiro Shimoda
2018-04-25  8:59       ` [PATCH/RFC,04/11] " Yoshihiro Shimoda
2018-04-18  8:09 ` [PATCH/RFC 05/11] usb: common: roles: add fwnode graph parsing Yoshihiro Shimoda
2018-04-18  8:09   ` [PATCH/RFC,05/11] " Yoshihiro Shimoda
2018-04-18  8:10 ` [PATCH/RFC 06/11] usb: common: roles: Allow if the parent dev_name matches Yoshihiro Shimoda
2018-04-18  8:10   ` [PATCH/RFC,06/11] " Yoshihiro Shimoda
2018-04-18  8:10 ` [PATCH/RFC 07/11] usb: common: roles: add getting device pointer APIs Yoshihiro Shimoda
2018-04-18  8:10   ` [PATCH/RFC,07/11] " Yoshihiro Shimoda
2018-04-18  8:10 ` [PATCH/RFC 08/11] usb: role: rcar-usb3-role-switch: add support for R-Car SoCs Yoshihiro Shimoda
2018-04-18  8:10   ` [PATCH/RFC,08/11] " Yoshihiro Shimoda
2018-04-18  8:47   ` [PATCH/RFC 08/11] " Geert Uytterhoeven
2018-04-18  8:47     ` [PATCH/RFC,08/11] " Geert Uytterhoeven
2018-04-18  8:10 ` [PATCH/RFC 09/11] usb: gadget: udc: renesas_usb3: add support for a usb role switch Yoshihiro Shimoda
2018-04-18  8:10   ` [PATCH/RFC,09/11] " Yoshihiro Shimoda
2018-04-18  8:10 ` [PATCH/RFC 10/11] arm64: dts: renesas: r8a7795: add OF graph for " Yoshihiro Shimoda
2018-04-18  8:10   ` [PATCH/RFC,10/11] " Yoshihiro Shimoda
2018-04-18  8:10 ` [PATCH/RFC 11/11] arm64: dts: renesas: r8a7795: salvator-xs: " Yoshihiro Shimoda
2018-04-18  8:10   ` [PATCH/RFC,11/11] " Yoshihiro Shimoda

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=1524039005-30618-5-git-send-email-yoshihiro.shimoda.uh@renesas.com \
    --to=yoshihiro.shimoda.uh@renesas.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.