diff mbox

[RFC,11/28] net: dsa: Add slave component matches based on a phandle to the slave.

Message ID 1450875402-20740-12-git-send-email-andrew@lunn.ch
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Andrew Lunn Dec. 23, 2015, 12:56 p.m. UTC
Switch devices are component slaves. Such devices have a "switch"
property in the DSA device tree which is a phandle to the switch
device. Add a component match on the device node.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/dsa.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index be8e181f161b..8b89eece6b52 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -871,18 +871,25 @@  static int dsa_bind(struct device *dev)
 	return dsa_setup_dst(dst, dst->master_netdev, dev);
 }
 
+static int compare_of(struct device *dev, void *data)
+{
+	return dev->of_node == data;
+}
+
 static int dsa_probe(struct platform_device *pdev)
 {
 	struct dsa_platform_data *pd = pdev->dev.platform_data;
+	struct device_node *np = pdev->dev.of_node;
 	struct component_match *match = NULL;
+	struct device_node *chip;
 	struct net_device *dev;
 	struct dsa_switch_tree *dst;
-	int ret;
+	int i, ret;
 
 	pr_notice_once("Distributed Switch Architecture driver version %s\n",
 		       dsa_driver_version);
 
-	if (pdev->dev.of_node) {
+	if (np) {
 		pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL);
 		if (!pd)
 			return -ENOMEM;
@@ -926,6 +933,12 @@  static int dsa_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, dst);
 
+	for (i = 0; i < pd->nr_chips; i++) {
+		chip = pd->chip[i].of_chip;
+		if (chip)
+			component_match_add(&pdev->dev, &match, compare_of,
+					    chip);
+	}
 
 	return component_master_add_with_match(&pdev->dev, &dsa_ops, match);