From patchwork Sun Jan 22 22:02:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9531487 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 518CE604A0 for ; Sun, 22 Jan 2017 22:04:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DFFB27CF9 for ; Sun, 22 Jan 2017 22:04:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3213E27DCE; Sun, 22 Jan 2017 22:04:28 +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=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B323927EED for ; Sun, 22 Jan 2017 22:04:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cVQFK-0002Xs-Nz; Sun, 22 Jan 2017 22:04:22 +0000 Received: from mail-wm0-f68.google.com ([74.125.82.68]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cVQFG-0002Hz-29 for linux-amlogic@lists.infradead.org; Sun, 22 Jan 2017 22:04:20 +0000 Received: by mail-wm0-f68.google.com with SMTP id r144so21904393wme.0 for ; Sun, 22 Jan 2017 14:03:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dd0M5VmDxG79xdbVhDPUKyQOGEI8urxKGnV82r84IFg=; b=H04kPqgYRWxJWF2jZVmq/Nxg/xCPu2UQjlpLINsRN8z03JEsVOnPus212K/zTh+BGK IrUBE7/uwg7AcdZPiVSfF2SX15GketSSd7QSvFibLCjLNOe3Sik8Ed7LVmtTNnqBM2x6 JQm7HyJuct0ytcYrEnT1mmScxMcTQe0G9qqbPq+Gy50vSbjboq7hZc0eZ9BARCTbdQ2P XoAWgPY9W1KfBnX4PGPs8pJKEBNRplgpMaRUggsCanVos4FRMV+19IEt2jvlkqDj1tlb Gldc7v6SqnytJ3agI7Asn9i17cNuMCJpBOf1ZK2yoKNRWVKFwENzDZbPd5zI6b1nDYFA fQwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dd0M5VmDxG79xdbVhDPUKyQOGEI8urxKGnV82r84IFg=; b=PzvBGQoN9loHHHt8Dk6ooFQkrqb/dQC55PADc4hGtFNLt86T3cE0uE0Ce3t1A4GwJS otFlcwC/JMJGAjiTILPVwQRfgsRhiA9GOU4hHHgrvvQ40C9YkVHR5L5G15Jfk/HzTJy2 mJ1llz5MoJgYQ/H/et90HsWAaxwAFxzRAwk32b3OVL3spqiVujyXeuNAHFIIpEIIWChd p3ebalTHjduLST7WFeOdOdr6ctDEJOg0RI8txMxq+9Sfkrx9hIFrch3666FfuLdWUnKM DExyo++yPnGStpj+HG17z+E29w/jC3itRIIQjY5UMufHYFuHxdtAHypzGPPnHACmimlg cu4Q== X-Gm-Message-State: AIkVDXKIEp0ZyTsirFS8z/m+8U85MysdSQD0WkxzFhreRnTig2+4yES963ff/rciB7KLmw== X-Received: by 10.28.1.216 with SMTP id 207mr12192791wmb.7.1485122577577; Sun, 22 Jan 2017 14:02:57 -0800 (PST) Received: from blackbox.darklights.net (p200300DCD3E0200408A0F52CBA7B1138.dip0.t-ipconnect.de. [2003:dc:d3e0:2004:8a0:f52c:ba7b:1138]) by smtp.googlemail.com with ESMTPSA id 53sm11393859wrt.20.2017.01.22.14.02.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Jan 2017 14:02:57 -0800 (PST) From: Martin Blumenstingl To: davem@davemloft.net, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-amlogic@lists.infradead.org Subject: [PATCH net-next v5 2/2] net: stmmac: dwmac-meson8b: make the RGMII TX delay configurable Date: Sun, 22 Jan 2017 23:02:46 +0100 Message-Id: <20170122220246.13602-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170122220246.13602-1-martin.blumenstingl@googlemail.com> References: <20161217182119.4037-1-martin.blumenstingl@googlemail.com> <20170122220246.13602-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170122_140418_255913_8D03F2C3 X-CRM114-Status: GOOD ( 12.26 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, narmstrong@baylibre.com, Martin Blumenstingl , khilman@baylibre.com, robh+dt@kernel.org, carlo@caione.org MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Prior to this patch we were using a hardcoded RGMII TX clock delay of 2ns (= 1/4 cycle of the 125MHz RGMII TX clock). This value works for many boards, but unfortunately not for all (due to the way the actual circuit is designed, sometimes because the TX delay is enabled in the PHY, etc.). Making the TX delay on the MAC side configurable allows us to support all possible hardware combinations. This allows fixing a compatibility issue on some boards, where the RTL8211F PHY is configured to generate the TX delay. We can now turn off the TX delay in the MAC, because otherwise we would be applying the delay twice (which results in non-working TX traffic). Signed-off-by: Martin Blumenstingl Tested-by: Neil Armstrong --- drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c index ffaed1f35efe..8840a360a0b7 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c @@ -35,10 +35,6 @@ #define PRG_ETH0_TXDLY_SHIFT 5 #define PRG_ETH0_TXDLY_MASK GENMASK(6, 5) -#define PRG_ETH0_TXDLY_OFF (0x0 << PRG_ETH0_TXDLY_SHIFT) -#define PRG_ETH0_TXDLY_QUARTER (0x1 << PRG_ETH0_TXDLY_SHIFT) -#define PRG_ETH0_TXDLY_HALF (0x2 << PRG_ETH0_TXDLY_SHIFT) -#define PRG_ETH0_TXDLY_THREE_QUARTERS (0x3 << PRG_ETH0_TXDLY_SHIFT) /* divider for the result of m250_sel */ #define PRG_ETH0_CLK_M250_DIV_SHIFT 7 @@ -69,6 +65,8 @@ struct meson8b_dwmac { struct clk_divider m25_div; struct clk *m25_div_clk; + + u32 tx_delay_ns; }; static void meson8b_dwmac_mask_bits(struct meson8b_dwmac *dwmac, u32 reg, @@ -179,6 +177,7 @@ static int meson8b_init_prg_eth(struct meson8b_dwmac *dwmac) { int ret; unsigned long clk_rate; + u8 tx_dly_val; switch (dwmac->phy_mode) { case PHY_INTERFACE_MODE_RGMII: @@ -196,9 +195,13 @@ static int meson8b_init_prg_eth(struct meson8b_dwmac *dwmac) meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_INVERTED_RMII_CLK, 0); - /* TX clock delay - all known boards use a 1/4 cycle delay */ + /* TX clock delay in ns = "8ns / 4 * tx_dly_val" (where + * 8ns are exactly one cycle of the 125MHz RGMII TX clock): + * 0ns = 0x0, 2ns = 0x1, 4ns = 0x2, 6ns = 0x3 + */ + tx_dly_val = dwmac->tx_delay_ns >> 1; meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TXDLY_MASK, - PRG_ETH0_TXDLY_QUARTER); + tx_dly_val << PRG_ETH0_TXDLY_SHIFT); break; case PHY_INTERFACE_MODE_RMII: @@ -284,6 +287,11 @@ static int meson8b_dwmac_probe(struct platform_device *pdev) goto err_remove_config_dt; } + /* use 2ns as fallback since this value was previously hardcoded */ + if (of_property_read_u32(pdev->dev.of_node, "amlogic,tx-delay-ns", + &dwmac->tx_delay_ns)) + dwmac->tx_delay_ns = 2; + ret = meson8b_init_clk(dwmac); if (ret) goto err_remove_config_dt;