From patchwork Tue Sep 20 07:59:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 9341129 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 471356077A for ; Tue, 20 Sep 2016 08:00:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B00D28F16 for ; Tue, 20 Sep 2016 08:00:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F4F329CBC; Tue, 20 Sep 2016 08:00:02 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham 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 9BE2E29CC2 for ; Tue, 20 Sep 2016 08:00:00 +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 1bmFyB-00034V-BL; Tue, 20 Sep 2016 07:59:59 +0000 Received: from [210.61.82.183] (helo=mailgw01.mediatek.com) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bmFy8-00031q-Lf for linux-mediatek@lists.infradead.org; Tue, 20 Sep 2016 07:59:57 +0000 Received: from mtkhts07.mediatek.inc [(172.21.101.69)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1177973887; Tue, 20 Sep 2016 15:59:33 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkhts07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 14.3.266.1; Tue, 20 Sep 2016 15:59:31 +0800 From: To: , Subject: [PATCH net-next 1/3] net: ethernet: mediatek: add extension of phy-mode for TRGMII Date: Tue, 20 Sep 2016 15:59:18 +0800 Message-ID: <1474358360-29901-2-git-send-email-sean.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1474358360-29901-1-git-send-email-sean.wang@mediatek.com> References: <1474358360-29901-1-git-send-email-sean.wang@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160920_005957_021180_43C9F4C8 X-CRM114-Status: GOOD ( 15.57 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nbd@openwrt.org, keyhaede@gmail.com, netdev@vger.kernel.org, Sean Wang , linux-mediatek@lists.infradead.org, objelf@gmail.com Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Wang adds PHY-mode "trgmii" as an extension for the operation mode of the PHY interface, TRGMII can be compatible with RGMII, so the extended mode doesn't really have effects on the target MAC and PHY, is used as the indication if the current MAC is connected to an internal switch or external PHY respectively by the given configuration on the board and then to perform the corresponding setup on TRGMII hardware module. Signed-off-by: Sean Wang --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 24 ++++++++++++++++++++++-- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 3 +++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index ca6b501..a0e338b 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -135,6 +135,26 @@ static int mtk_mdio_read(struct mii_bus *bus, int phy_addr, int phy_reg) return _mtk_mdio_read(eth, phy_addr, phy_reg); } +static int mtk_of_get_phy_mode(struct mtk_mac *mac, struct device_node *np) +{ + int phy_mode, err; + const char *pm; + + phy_mode = of_get_phy_mode(np); + + if (phy_mode >= 0) + return phy_mode; + err = of_property_read_string(np, "phy-mode", &pm); + if (err < 0) + return err; + if (!strcasecmp(pm, "trgmii")) { + mac->trgmii = true; + /* TRGMII could be compatible with RGMII */ + return PHY_INTERFACE_MODE_RGMII; + } else + return -ENODEV; +} + static void mtk_phy_link_adjust(struct net_device *dev) { struct mtk_mac *mac = netdev_priv(dev); @@ -207,7 +227,7 @@ static int mtk_phy_connect_node(struct mtk_eth *eth, struct mtk_mac *mac, return -EINVAL; } addr = be32_to_cpu(*_addr); - phy_mode = of_get_phy_mode(phy_node); + phy_mode = mtk_of_get_phy_mode(mac, phy_node); if (phy_mode < 0) { dev_err(eth->dev, "incorrect phy-mode %d\n", phy_mode); return -EINVAL; @@ -243,7 +263,7 @@ static int mtk_phy_connect(struct mtk_mac *mac) if (!np) return -ENODEV; - switch (of_get_phy_mode(np)) { + switch (mtk_of_get_phy_mode(mac, np)) { case PHY_INTERFACE_MODE_RGMII_TXID: case PHY_INTERFACE_MODE_RGMII_RXID: case PHY_INTERFACE_MODE_RGMII_ID: diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index 7c5e534..e3b9525 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -529,6 +529,8 @@ struct mtk_eth { * @hw: Backpointer to our main datastruture * @hw_stats: Packet statistics counter * @phy_dev: The attached PHY if available + * @trgmii Indicate if the MAC uses TRGMII connected to internal + switch */ struct mtk_mac { int id; @@ -539,6 +541,7 @@ struct mtk_mac { struct phy_device *phy_dev; __be32 hwlro_ip[MTK_MAX_LRO_IP_CNT]; int hwlro_ip_cnt; + bool trgmii; }; /* the struct describing the SoC. these are declared in the soc_xyz.c files */