]> xenbits.xensource.com Git - people/julieng/linux-arm.git/commitdiff
net, thunder, bgx: Rework driver to support ACPI binding.
authorTomasz Nowicki <tomasz.nowicki@linaro.org>
Tue, 16 Dec 2014 17:06:53 +0000 (18:06 +0100)
committerJulien Grall <julien.grall@citrix.com>
Mon, 28 Sep 2015 11:05:21 +0000 (12:05 +0100)
Additional functionality aims to find out which PHYs belong to which
BGX instance in the ACPI way.

Signed-off-by: Tomasz Nowicki <tomasz.nowicki@linaro.org>
Signed-off-by: Robert Richter <rrichter@cavium.com>
Signed-off-by: Vadim Lomovtsev <Vadim.Lomovtsev@caviumnetworks.com>
drivers/net/ethernet/cavium/thunder/thunder_bgx.c

index 6f6f8731dbdbd9a6e07b76833c284bf0e56660be..71ffec33f00f4a1452c1abf46a7fa4013bd73bac 100644 (file)
@@ -869,6 +869,17 @@ static void bgx_get_qlm_mode(struct bgx *bgx)
 
 #ifdef CONFIG_ACPI
 
+static int bgx_match_phy_id(struct device *dev, void *data)
+{
+       struct phy_device *phydev = to_phy_device(dev);
+       u32 *phy_id = data;
+
+       if (phydev->addr == *phy_id)
+               return 1;
+
+       return 0;
+}
+
 static int acpi_get_mac_address(struct acpi_device *adev, u8 *dst)
 {
        u8 mac[ETH_ALEN];
@@ -889,23 +900,38 @@ out:
        return ret;
 }
 
-/* Currently only sets the MAC address. */
 static acpi_status bgx_acpi_register_phy(acpi_handle handle,
                                         u32 lvl, void *context, void **rv)
 {
+       struct acpi_reference_args args;
        struct bgx *bgx = context;
        struct acpi_device *adev;
+       struct device *phy_dev;
+       u32 phy_id;
 
        if (acpi_bus_get_device(handle, &adev))
-               goto out;
+               return AE_OK;
 
-       acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac);
+       if (acpi_dev_get_property_reference(adev, "phy-handle", 0, &args))
+               return AE_OK;
 
-       SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev);
+       if (acpi_dev_prop_read_single(args.adev, "phy-channel", DEV_PROP_U32,
+                                       &phy_id))
+               return AE_OK;
 
+       phy_dev = bus_find_device(&mdio_bus_type, NULL, (void *)&phy_id,
+                                 bgx_match_phy_id);
+       if (!phy_dev)
+               return AE_OK;
+
+       SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev);
+       bgx->lmac[bgx->lmac_count].phydev = to_phy_device(phy_dev);
        bgx->lmac[bgx->lmac_count].lmacid = bgx->lmac_count;
-out:
+
+       acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac);
+
        bgx->lmac_count++;
+
        return AE_OK;
 }