From patchwork Sat Dec 17 18:21:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9479083 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 ED59260237 for ; Sat, 17 Dec 2016 18:22:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0EC3284D8 for ; Sat, 17 Dec 2016 18:22:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2F29284CB; Sat, 17 Dec 2016 18:22:42 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 7E0FC284CB for ; Sat, 17 Dec 2016 18:22:42 +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 1cIJcw-0002lu-KR; Sat, 17 Dec 2016 18:22:34 +0000 Received: from mail-wj0-x243.google.com ([2a00:1450:400c:c01::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cIJcM-0002W0-SF; Sat, 17 Dec 2016 18:22:00 +0000 Received: by mail-wj0-x243.google.com with SMTP id he10so18520285wjc.2; Sat, 17 Dec 2016 10:21:38 -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=lDCTvSJvmz0isb4vIdDbXTksOmktgbuSQ60mJ0BB3+E=; b=QBfA8TG2+of09J5B3sA26oYApl8jBMTGPr8lyi/Xbrg2Tz5wbPl91Z0ARlYaJ3ifqS hR+gh90BmytsUOh+saUOTLKyUxHwW4kDNiXRjB4BIM1mlzcF04XrDJd9wus0Rz3U1MIW dcpKYkQBdQehNin3y9IYN8kVpO/tUHNVJ2jH6gRbyeEkbP2+ssuCsuY8ZZXpuyPeRo1K 5HM+/PTnvGEjOpVlnfRqKElB51oXBEYtPHLY0fEzxTtvirD8lYL7/aMtqnchCqOmn9F1 f02xEGoNbRx9IDFFm1zVjhk8qj012pZexb6WwJjjFRHCu99+12w1LrOfTh/5kD+Fffd9 EW8Q== 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=lDCTvSJvmz0isb4vIdDbXTksOmktgbuSQ60mJ0BB3+E=; b=YdaBVhzusfytj6C7mAi7sdaiT12guSpj31K9wYzIril/EMV/V4+pRXdNYyqWHKIygd I1XCDf/AEK3eSk9Pk1gp0QV9DcpOQMC+dIseWL83KwwgkclRJhw9NmDUbvd6UQMkwfnB NzTq2SoVnsoTTWSyOSeJJ+IwF6PFAgZQ3kDIk+QCYLxizw1avbU9x21QhVnqfRgo0hsV aFiET63wNsWHro+nHu1kYnhubR5qdAM/QgqrKKbXqveL+d7CX3yeV5c5BuH/C8BYdw0o lhJd9QnEPzcQMpw/+1oH4nBXk4i2sU1MYb+lCZ2P1af3c2UVN01Y3kfBEp3xgAFc3rsK 9d3g== X-Gm-Message-State: AIkVDXLnRKXIIyPGq2rFhF4mXceDAlNl7AYq0qCfmMHwHjDwvH00K1BDW+84qSbzGxtu7w== X-Received: by 10.194.133.169 with SMTP id pd9mr7284724wjb.199.1481998896928; Sat, 17 Dec 2016 10:21:36 -0800 (PST) Received: from blackbox.darklights.net (p5DE38254.dip0.t-ipconnect.de. [93.227.130.84]) by smtp.googlemail.com with ESMTPSA id wg8sm12484420wjb.42.2016.12.17.10.21.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Dec 2016 10:21:36 -0800 (PST) From: Martin Blumenstingl To: davem@davemloft.net, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-amlogic@lists.infradead.org, robh+dt@kernel.org, mark.rutland@arm.com, carlo@caione.org, khilman@baylibre.com Subject: [PATCH net-next v4 2/2] net: stmmac: dwmac-meson8b: make the RGMII TX delay configurable Date: Sat, 17 Dec 2016 19:21:19 +0100 Message-Id: <20161217182119.4037-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161217182119.4037-1-martin.blumenstingl@googlemail.com> References: <20161202233238.17561-1-martin.blumenstingl@googlemail.com> <20161217182119.4037-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161217_102159_124425_C1940773 X-CRM114-Status: GOOD ( 13.73 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , peppe.cavallaro@st.com, alexandre.torgue@st.com, linux-arm-kernel@lists.infradead.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 | 21 +++++++++++++++------ 1 file changed, 15 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..db970cd6600f 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: @@ -282,6 +285,12 @@ static int meson8b_dwmac_probe(struct platform_device *pdev) dev_err(&pdev->dev, "missing phy-mode property\n"); ret = -EINVAL; goto err_remove_config_dt; + } else if (dwmac->phy_mode != PHY_INTERFACE_MODE_RMII) { + /* ignore errors as this is an optional property - by default + * we assume a TX delay of 0ns. + */ + of_property_read_u32(pdev->dev.of_node, "amlogic,tx-delay-ns", + &dwmac->tx_delay_ns); } ret = meson8b_init_clk(dwmac);