From patchwork Thu Nov 8 07:22:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Dongsheng" X-Patchwork-Id: 10673627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A72D61751 for ; Thu, 8 Nov 2018 07:23:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D6772A40E for ; Thu, 8 Nov 2018 07:23:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E2602A505; Thu, 8 Nov 2018 07:23:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F29762A40E for ; Thu, 8 Nov 2018 07:23:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726846AbeKHQ5g (ORCPT ); Thu, 8 Nov 2018 11:57:36 -0500 Received: from mx01.hxt-semitech.com ([223.203.96.7]:38421 "EHLO barracuda.hxt-semitech.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726814AbeKHQ5f (ORCPT ); Thu, 8 Nov 2018 11:57:35 -0500 X-ASG-Debug-ID: 1541661798-093b7e63fe00560001-I98ny2 Received: from HXTBJIDCEMVIW02.hxtcorp.net ([10.128.0.15]) by barracuda.hxt-semitech.com with ESMTP id R1OmgorWH8Odc76Z (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Thu, 08 Nov 2018 15:23:19 +0800 (CST) X-Barracuda-Envelope-From: dongsheng.wang@hxt-semitech.com Received: from arch.hxtcorp.net (10.64.6.141) by HXTBJIDCEMVIW02.hxtcorp.net (10.128.0.15) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 8 Nov 2018 15:22:45 +0800 From: Wang Dongsheng To: , CC: Wang Dongsheng , , , , , Subject: [RFC PATCH 2/3] net: qcom/emac: split phy_config to mdio bus create and get phy device Date: Thu, 8 Nov 2018 15:22:34 +0800 X-ASG-Orig-Subj: [RFC PATCH 2/3] net: qcom/emac: split phy_config to mdio bus create and get phy device Message-ID: <7964cfa6df086189a87613a93d6184ad596cca55.1541660504.git.dongsheng.wang@hxt-semitech.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: <20181029124044.GB9174@lunn.ch> MIME-Version: 1.0 X-Originating-IP: [10.64.6.141] X-ClientProxiedBy: HXTBJIDCEMVIW02.hxtcorp.net (10.128.0.15) To HXTBJIDCEMVIW02.hxtcorp.net (10.128.0.15) X-Barracuda-Connect: UNKNOWN[10.128.0.15] X-Barracuda-Start-Time: 1541661799 X-Barracuda-Encrypted: ECDHE-RSA-AES256-SHA384 X-Barracuda-URL: https://192.168.50.101:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at hxt-semitech.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: SPAM GLOBAL 1.0000 1.0000 4.3426 X-Barracuda-Spam-Score: 4.34 X-Barracuda-Spam-Status: No, SCORE=4.34 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.61411 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch separate emac_mdio_bus_create and emac_get_phydev from emac_phy_config, and do some codes clean. Signed-off-by: Wang Dongsheng --- drivers/net/ethernet/qualcomm/emac/emac-phy.c | 96 +++++++++++-------- 1 file changed, 56 insertions(+), 40 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/emac/emac-phy.c b/drivers/net/ethernet/qualcomm/emac/emac-phy.c index 53dbf1e163a8..8289fdda4be7 100644 --- a/drivers/net/ethernet/qualcomm/emac/emac-phy.c +++ b/drivers/net/ethernet/qualcomm/emac/emac-phy.c @@ -96,15 +96,15 @@ static int emac_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val) return 0; } -/* Configure the MDIO bus and connect the external PHY */ -int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt) +static int emac_mdio_bus_create(struct platform_device *pdev, + struct emac_adapter *adpt) { struct device_node *np = pdev->dev.of_node; struct mii_bus *mii_bus; int ret; /* Create the mii_bus object for talking to the MDIO bus */ - adpt->mii_bus = mii_bus = devm_mdiobus_alloc(&pdev->dev); + mii_bus = devm_mdiobus_alloc(&pdev->dev); if (!mii_bus) return -ENOMEM; @@ -115,50 +115,66 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt) mii_bus->parent = &pdev->dev; mii_bus->priv = adpt; - if (has_acpi_companion(&pdev->dev)) { - u32 phy_addr; - - ret = mdiobus_register(mii_bus); - if (ret) { - dev_err(&pdev->dev, "could not register mdio bus\n"); - return ret; - } - ret = device_property_read_u32(&pdev->dev, "phy-channel", - &phy_addr); - if (ret) - /* If we can't read a valid phy address, then assume - * that there is only one phy on this mdio bus. - */ - adpt->phydev = phy_find_first(mii_bus); - else - adpt->phydev = mdiobus_get_phy(mii_bus, phy_addr); - - /* of_phy_find_device() claims a reference to the phydev, - * so we do that here manually as well. When the driver - * later unloads, it can unilaterally drop the reference - * without worrying about ACPI vs DT. - */ - if (adpt->phydev) - get_device(&adpt->phydev->mdio.dev); - } else { - struct device_node *phy_np; - - ret = of_mdiobus_register(mii_bus, np); - if (ret) { - dev_err(&pdev->dev, "could not register mdio bus\n"); - return ret; - } + ret = of_mdiobus_register(mii_bus, has_acpi_companion(&pdev->dev) ? + NULL : np); + if (ret) + dev_err(&pdev->dev, "Could not register mdio bus\n"); + + adpt->mii_bus = ret ? NULL : mii_bus; + return ret; +} + +static int emac_get_phydev(struct platform_device *pdev, + struct emac_adapter *adpt) +{ + struct device_node *np = pdev->dev.of_node; + struct mii_bus *bus = adpt->mii_bus; + struct device_node *phy_np; + struct phy_device *phydev; + u32 phy_addr; + int ret; + + if (!has_acpi_companion(&pdev->dev)) { phy_np = of_parse_phandle(np, "phy-handle", 0); adpt->phydev = of_phy_find_device(phy_np); of_node_put(phy_np); + return adpt->phydev ? 0 : -ENODEV; } - if (!adpt->phydev) { - dev_err(&pdev->dev, "could not find external phy\n"); - mdiobus_unregister(mii_bus); + ret = device_property_read_u32(&pdev->dev, "phy-channel", + &phy_addr); + /* If we can't read a valid phy address, then assume + * that there is only one phy on this mdio bus. + */ + phydev = ret ? phy_find_first(bus) : mdiobus_get_phy(bus, phy_addr); + if (!phydev) return -ENODEV; - } + /* of_phy_find_device() claims a reference to the phydev, + * so we do that here manually as well. When the driver + * later unloads, it can unilaterally drop the reference + * without worrying about ACPI vs DT. + */ + get_device(&phydev->mdio.dev); + adpt->phydev = phydev; return 0; } + +/* Configure the MDIO bus and connect the external PHY */ +int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt) +{ + int ret; + + ret = emac_mdio_bus_create(pdev, adpt); + if (ret) + return ret; + + ret = emac_get_phydev(pdev, adpt); + if (ret) { + dev_err(&pdev->dev, "Could not find external phy\n"); + mdiobus_unregister(adpt->mii_bus); + } + + return ret; +}