From patchwork Tue Nov 1 17:51:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Mason X-Patchwork-Id: 9407783 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7AEEE60234 for ; Tue, 1 Nov 2016 17:55:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EDAA29902 for ; Tue, 1 Nov 2016 17:55:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 604BD29A89; Tue, 1 Nov 2016 17:55:10 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB6A229902 for ; Tue, 1 Nov 2016 17:55:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c1dFj-0002ic-2B; Tue, 01 Nov 2016 17:53:39 +0000 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c1dEN-0001wQ-VW for linux-arm-kernel@lists.infradead.org; Tue, 01 Nov 2016 17:52:18 +0000 Received: by mail-pf0-x231.google.com with SMTP id i88so5217961pfk.2 for ; Tue, 01 Nov 2016 10:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H+QmgKqDrwEs+PqQpi1E+Y6xJIt7ZWjj3cH2tl+3n3g=; b=FRgVq0WzuYehOWl5Om8Hb7TjSedaVwVh7/QBtY9surTj6hJR81p5UNQBqI97pERquv Nt67U4k6gA/oE24msjr76rOFvzxjm2l/bpvtWGvCIIxI2egDrG/GQLlgLoPePeSCedYf VhRlzo2/PCdfWqbZUq3U1dF3DqJflI3mV0teI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H+QmgKqDrwEs+PqQpi1E+Y6xJIt7ZWjj3cH2tl+3n3g=; b=QmxV8eKSsrsY1GZAQpYL5rEcQtcLjM8icxaSqv8jSrfSe1MbDtehP2Y6hVMHZiDE/V 5NvOdU1qNLQi0b2nQ800wssh9gfbzy+DGjaj9cO/d75UPBm6+f8sbbnWJdLIv/lI1FSt rh9/uycJTrXQzija0yDk0UqwQJdpxzbFROEiJ2y7nEHSE/N11GrjbF3VPTBgsuRhofeS /9B39lWfE7BUtXulktuQOfIErij9JWyo+izlpZhmKxBlP2id/BWEP1m8E0/VMS1swJgx v58RyetUekDFsLWZrblJGZsdCCy0uvhXSTi7X9y3Db11t+muKrxkjD0fCcnnLM1PGv8W zYLQ== X-Gm-Message-State: ABUngvfGCBe26dfnH8ssk4V2wmW7jNlG80fN0VeYQRZZ7KFBtTlzHPQiU6sQ+V4okEpyy6j7 X-Received: by 10.99.227.81 with SMTP id o17mr50382799pgj.69.1478022718029; Tue, 01 Nov 2016 10:51:58 -0700 (PDT) Received: from venom.rtp.broadcom.com ([216.31.219.19]) by smtp.gmail.com with ESMTPSA id k7sm43768072pan.8.2016.11.01.10.51.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Nov 2016 10:51:57 -0700 (PDT) From: Jon Mason To: David Miller , Rob Herring , Mark Rutland , Florian Fainelli Subject: [PATCH v3 4/6] net: ethernet: bgmac: device tree phy enablement Date: Tue, 1 Nov 2016 13:51:32 -0400 Message-Id: <1478022694-25308-5-git-send-email-jon.mason@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478022694-25308-1-git-send-email-jon.mason@broadcom.com> References: <1478022694-25308-1-git-send-email-jon.mason@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161101_105216_166261_4A4AD58A X-CRM114-Status: GOOD ( 18.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, rafal@milecki.pl, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Change the bgmac driver to allow for phy's defined by the device tree Signed-off-by: Jon Mason --- drivers/net/ethernet/broadcom/bgmac-bcma.c | 48 ++++++++++++++++++++++++ drivers/net/ethernet/broadcom/bgmac-platform.c | 48 +++++++++++++++++++++++- drivers/net/ethernet/broadcom/bgmac.c | 52 ++------------------------ drivers/net/ethernet/broadcom/bgmac.h | 7 ++++ 4 files changed, 105 insertions(+), 50 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bgmac-bcma.c b/drivers/net/ethernet/broadcom/bgmac-bcma.c index c16ec3a..3e3efde 100644 --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c @@ -80,6 +80,50 @@ static void bcma_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, u32 mask, bcma_maskset32(bgmac->bcma.cmn, offset, mask, set); } +static int bcma_phy_connect(struct bgmac *bgmac) +{ + struct phy_device *phy_dev; + char bus_id[MII_BUS_ID_SIZE + 3]; + + /* Connect to the PHY */ + snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id, + bgmac->phyaddr); + phy_dev = phy_connect(bgmac->net_dev, bus_id, bgmac_adjust_link, + PHY_INTERFACE_MODE_MII); + if (IS_ERR(phy_dev)) { + dev_err(bgmac->dev, "PHY connecton failed\n"); + return PTR_ERR(phy_dev); + } + + return 0; +} + +static int bcma_phy_direct_connect(struct bgmac *bgmac) +{ + struct fixed_phy_status fphy_status = { + .link = 1, + .speed = SPEED_1000, + .duplex = DUPLEX_FULL, + }; + struct phy_device *phy_dev; + int err; + + phy_dev = fixed_phy_register(PHY_POLL, &fphy_status, -1, NULL); + if (!phy_dev || IS_ERR(phy_dev)) { + dev_err(bgmac->dev, "Failed to register fixed PHY device\n"); + return -ENODEV; + } + + err = phy_connect_direct(bgmac->net_dev, phy_dev, bgmac_adjust_link, + PHY_INTERFACE_MODE_MII); + if (err) { + dev_err(bgmac->dev, "Connecting PHY failed\n"); + return err; + } + + return err; +} + static const struct bcma_device_id bgmac_bcma_tbl[] = { BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS), @@ -275,6 +319,10 @@ static int bgmac_probe(struct bcma_device *core) bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset; bgmac->get_bus_clock = bcma_bgmac_get_bus_clock; bgmac->cmn_maskset32 = bcma_bgmac_cmn_maskset32; + if (bgmac->mii_bus) + bgmac->phy_connect = bcma_phy_connect; + else + bgmac->phy_connect = bcma_phy_direct_connect; err = bgmac_enet_probe(bgmac); if (err) diff --git a/drivers/net/ethernet/broadcom/bgmac-platform.c b/drivers/net/ethernet/broadcom/bgmac-platform.c index be52f27..aed5dc5 100644 --- a/drivers/net/ethernet/broadcom/bgmac-platform.c +++ b/drivers/net/ethernet/broadcom/bgmac-platform.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "bgmac.h" @@ -86,6 +87,46 @@ static void platform_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, WARN_ON(1); } +static int platform_phy_connect(struct bgmac *bgmac) +{ + struct phy_device *phy_dev; + + phy_dev = of_phy_get_and_connect(bgmac->net_dev, bgmac->dev->of_node, + bgmac_adjust_link); + if (!phy_dev) { + dev_err(bgmac->dev, "Phy connect failed\n"); + return -ENODEV; + } + + return 0; +} + +static int platform_phy_direct_connect(struct bgmac *bgmac) +{ + struct fixed_phy_status fphy_status = { + .link = 1, + .speed = SPEED_1000, + .duplex = DUPLEX_FULL, + }; + struct phy_device *phy_dev; + int err; + + phy_dev = fixed_phy_register(PHY_POLL, &fphy_status, -1, NULL); + if (!phy_dev || IS_ERR(phy_dev)) { + dev_err(bgmac->dev, "Failed to register fixed PHY device\n"); + return -ENODEV; + } + + err = phy_connect_direct(bgmac->net_dev, phy_dev, bgmac_adjust_link, + PHY_INTERFACE_MODE_MII); + if (err) { + dev_err(bgmac->dev, "Connecting PHY failed\n"); + return err; + } + + return err; +} + static int bgmac_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -102,7 +143,6 @@ static int bgmac_probe(struct platform_device *pdev) /* Set the features of the 4707 family */ bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; bgmac->feature_flags |= BGMAC_FEAT_NO_RESET; - bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500; bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4; bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP; bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP; @@ -151,6 +191,12 @@ static int bgmac_probe(struct platform_device *pdev) bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset; bgmac->get_bus_clock = platform_bgmac_get_bus_clock; bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32; + if (of_parse_phandle(np, "phy-handle", 0)) { + bgmac->phy_connect = platform_phy_connect; + } else { + bgmac->phy_connect = platform_phy_direct_connect; + bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500; + } return bgmac_enet_probe(bgmac); } diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c index 856379c..4584958 100644 --- a/drivers/net/ethernet/broadcom/bgmac.c +++ b/drivers/net/ethernet/broadcom/bgmac.c @@ -1388,7 +1388,7 @@ static const struct ethtool_ops bgmac_ethtool_ops = { * MII **************************************************/ -static void bgmac_adjust_link(struct net_device *net_dev) +void bgmac_adjust_link(struct net_device *net_dev) { struct bgmac *bgmac = netdev_priv(net_dev); struct phy_device *phy_dev = net_dev->phydev; @@ -1411,50 +1411,7 @@ static void bgmac_adjust_link(struct net_device *net_dev) phy_print_status(phy_dev); } } - -static int bgmac_phy_connect_direct(struct bgmac *bgmac) -{ - struct fixed_phy_status fphy_status = { - .link = 1, - .speed = SPEED_1000, - .duplex = DUPLEX_FULL, - }; - struct phy_device *phy_dev; - int err; - - phy_dev = fixed_phy_register(PHY_POLL, &fphy_status, -1, NULL); - if (!phy_dev || IS_ERR(phy_dev)) { - dev_err(bgmac->dev, "Failed to register fixed PHY device\n"); - return -ENODEV; - } - - err = phy_connect_direct(bgmac->net_dev, phy_dev, bgmac_adjust_link, - PHY_INTERFACE_MODE_MII); - if (err) { - dev_err(bgmac->dev, "Connecting PHY failed\n"); - return err; - } - - return err; -} - -static int bgmac_phy_connect(struct bgmac *bgmac) -{ - struct phy_device *phy_dev; - char bus_id[MII_BUS_ID_SIZE + 3]; - - /* Connect to the PHY */ - snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, bgmac->mii_bus->id, - bgmac->phyaddr); - phy_dev = phy_connect(bgmac->net_dev, bus_id, &bgmac_adjust_link, - PHY_INTERFACE_MODE_MII); - if (IS_ERR(phy_dev)) { - dev_err(bgmac->dev, "PHY connecton failed\n"); - return PTR_ERR(phy_dev); - } - - return 0; -} +EXPORT_SYMBOL_GPL(bgmac_adjust_link); int bgmac_enet_probe(struct bgmac *info) { @@ -1507,10 +1464,7 @@ int bgmac_enet_probe(struct bgmac *info) netif_napi_add(net_dev, &bgmac->napi, bgmac_poll, BGMAC_WEIGHT); - if (!bgmac->mii_bus) - err = bgmac_phy_connect_direct(bgmac); - else - err = bgmac_phy_connect(bgmac); + err = bgmac_phy_connect(bgmac); if (err) { dev_err(bgmac->dev, "Cannot connect to phy\n"); goto err_dma_free; diff --git a/drivers/net/ethernet/broadcom/bgmac.h b/drivers/net/ethernet/broadcom/bgmac.h index 80836b4..ea52ac3 100644 --- a/drivers/net/ethernet/broadcom/bgmac.h +++ b/drivers/net/ethernet/broadcom/bgmac.h @@ -513,10 +513,12 @@ struct bgmac { u32 (*get_bus_clock)(struct bgmac *bgmac); void (*cmn_maskset32)(struct bgmac *bgmac, u16 offset, u32 mask, u32 set); + int (*phy_connect)(struct bgmac *bgmac); }; int bgmac_enet_probe(struct bgmac *info); void bgmac_enet_remove(struct bgmac *bgmac); +void bgmac_adjust_link(struct net_device *net_dev); struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr); void bcma_mdio_mii_unregister(struct mii_bus *mii_bus); @@ -583,4 +585,9 @@ static inline void bgmac_set(struct bgmac *bgmac, u16 offset, u32 set) { bgmac_maskset(bgmac, offset, ~0, set); } + +static inline int bgmac_phy_connect(struct bgmac *bgmac) +{ + return bgmac->phy_connect(bgmac); +} #endif /* _BGMAC_H */