Netdev List
 help / color / mirror / Atom feed
From: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>
To: <timur@kernel.org>, <andrew@lunn.ch>
Cc: <davem@davemloft.net>,
	Wang Dongsheng <dongsheng.wang@hxt-semitech.com>,
	<yu.zheng@hxt-semitech.com>, <netdev@vger.kernel.org>
Subject: [PATCH v2 4/4] net: qcom/emac: add acpi shared mdio bus support
Date: Mon, 17 Sep 2018 16:55:46 +0800	[thread overview]
Message-ID: <1537174546-34642-2-git-send-email-dongsheng.wang@hxt-semitech.com> (raw)
In-Reply-To: <1537174546-34642-1-git-send-email-dongsheng.wang@hxt-semitech.com>

Parsing _DSD package "mdio-device".

Signed-off-by: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>
---
 drivers/net/ethernet/qualcomm/emac/emac-phy.c | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/drivers/net/ethernet/qualcomm/emac/emac-phy.c b/drivers/net/ethernet/qualcomm/emac/emac-phy.c
index 4f98f9a0ed54..7a96bcf15d3f 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac-phy.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac-phy.c
@@ -97,6 +97,51 @@ static int emac_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val)
 	return 0;
 }
 
+static int acpi_device_match(struct device *dev, void *fwnode)
+{
+	return dev->fwnode == fwnode;
+}
+
+static int emac_acpi_get_shared_bus(struct platform_device *pdev,
+				    struct mii_bus **bus)
+{
+	struct fwnode_reference_args args;
+	struct fwnode_handle *fw_node;
+
+	struct device *shared_dev;
+	struct net_device *shared_netdev;
+	struct emac_adapter *shared_adpt;
+	int ret;
+
+	if (!has_acpi_companion(&pdev->dev))
+		return -ENODEV;
+
+	fw_node = acpi_fwnode_handle(ACPI_COMPANION(&pdev->dev));
+	ret = acpi_node_get_property_reference(fw_node, "mdio-device", 0,
+					       &args);
+	if (ACPI_FAILURE(ret) || !is_acpi_device_node(args.fwnode)) {
+		dev_err(&pdev->dev, "Missing mdio-device property\n");
+		return -ENODEV;
+	}
+
+	shared_dev = bus_find_device(&platform_bus_type, NULL,
+				     args.fwnode,
+				     acpi_device_match);
+	if (!shared_dev)
+		return -EPROBE_DEFER;
+
+	shared_netdev = dev_get_drvdata(shared_dev);
+	if (!shared_netdev)
+		return -EPROBE_DEFER;
+
+	shared_adpt = netdev_priv(shared_netdev);
+	if (!shared_adpt->mii_bus)
+		return -EPROBE_DEFER;
+
+	*bus = shared_adpt->mii_bus;
+	return 0;
+}
+
 static int emac_of_get_shared_bus(struct platform_device *pdev,
 				  struct mii_bus **bus)
 {
@@ -137,6 +182,12 @@ static int emac_of_get_shared_bus(struct platform_device *pdev,
 static int __do_get_emac_mido_shared_bus(struct platform_device *pdev,
 					 struct emac_adapter *adpt)
 {
+	int ret;
+
+	ret = emac_acpi_get_shared_bus(pdev, &adpt->mii_bus);
+	if (adpt->mii_bus || ret == -EPROBE_DEFER)
+		return ret;
+
 	return emac_of_get_shared_bus(pdev, &adpt->mii_bus);
 }
 
-- 
2.18.0

      reply	other threads:[~2018-09-17 14:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-17  8:55 [PATCH v2 3/4] net: qcom/emac: add of shared mdio bus support Wang Dongsheng
2018-09-17  8:55 ` Wang Dongsheng [this message]

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=1537174546-34642-2-git-send-email-dongsheng.wang@hxt-semitech.com \
    --to=dongsheng.wang@hxt-semitech.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=timur@kernel.org \
    --cc=yu.zheng@hxt-semitech.com \
    /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