[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1537174546-34642-2-git-send-email-dongsheng.wang@hxt-semitech.com>
Date: Mon, 17 Sep 2018 16:55:46 +0800
From: Wang Dongsheng <dongsheng.wang@...-semitech.com>
To: <timur@...nel.org>, <andrew@...n.ch>
CC: <davem@...emloft.net>,
Wang Dongsheng <dongsheng.wang@...-semitech.com>,
<yu.zheng@...-semitech.com>, <netdev@...r.kernel.org>
Subject: [PATCH v2 4/4] net: qcom/emac: add acpi shared mdio bus support
Parsing _DSD package "mdio-device".
Signed-off-by: Wang Dongsheng <dongsheng.wang@...-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
Powered by blists - more mailing lists