From patchwork Fri Dec 2 23:32:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9459385 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 8BD606074E for ; Fri, 2 Dec 2016 23:34:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D8AD28585 for ; Fri, 2 Dec 2016 23:34:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7143D28599; Fri, 2 Dec 2016 23:34:22 +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 B4B6028585 for ; Fri, 2 Dec 2016 23:34:21 +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 1cCxLJ-0001Yw-Ji; Fri, 02 Dec 2016 23:34:13 +0000 Received: from mail-wj0-x244.google.com ([2a00:1450:400c:c01::244]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cCxKX-0000Y6-KU; Fri, 02 Dec 2016 23:33:27 +0000 Received: by mail-wj0-x244.google.com with SMTP id xy5so32006069wjc.1; Fri, 02 Dec 2016 15:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZOeycCDKb6LtPYkQlJI7FhMBW83XNAgHiHE07yT6vaA=; b=gYcW5Oi2YhgeDPQ7TX3Dq18Yy6Bqj1pnkmJYhJZVbLuF1AxwlslzjYflNREhI8nK+2 HnZMfrq/lUa8KzNRizjimD5ieU+/JCIgXTpI/0vCg1oF+i5b39x5++rgQpE5htsfIUkZ 26+uSE9J8stAPkYPxJlGkigp7AeZFthn7wkcAcx96KSgHS5BBHPXb48VO9NTJYQ2mj/v 2/23LhTX4f2GSNklSqXtPshr6sNcPpt1KgadeteyeVaTwiYG6Isoh1Er7ZG2ZVcPH8o1 vXkYrT1aEbNfjoOY1fbzhhiyFsaEeoL7UWD3S0CEERw2aGT5LSSDCZM61Peyk/xJr1zs O41A== 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=ZOeycCDKb6LtPYkQlJI7FhMBW83XNAgHiHE07yT6vaA=; b=fBgbYDeyeeRPwwuXTP9lezEqe6JexFG7Shmh007LcmJze3NR+pPJQAFKAT0+GXHAYX k1c37Iw0a5pR5IEaHn5OxLik/liEcijHJR9VRh1QsAFmfozvdv6iiWSxch74pRMz7LSY L+t+7kT+nyKGvrOpePlKtZH5zKKrjt5EFFofNwb9vdB7YDEFDLMoYVzEbQO8GKEBp8CA Nc540Jti8n8Dw0QADTWEb3IpV6e4q7LtqGdkAuNUZEF22Oua7nNL2FfGCynVZftZCXFq EWjVu3feKcUw/d8aXP091W/6pIjuguyQUHCi7/daRM+HOIK79qw0SuKn2u8ulTNKXeIZ w+dQ== X-Gm-Message-State: AKaTC03jgcQGh4aexImobFq+SMlcm1sq8qsB1e8jdg7HaXpMKelzzGWPjvAplXCpSz9sJw== X-Received: by 10.194.235.198 with SMTP id uo6mr47695720wjc.40.1480721583765; Fri, 02 Dec 2016 15:33:03 -0800 (PST) Received: from blackbox.darklights.net (p200300DCD3F345041935DCECF29CCAC0.dip0.t-ipconnect.de. [2003:dc:d3f3:4504:1935:dcec:f29c:cac0]) by smtp.googlemail.com with ESMTPSA id y4sm7890363wjp.0.2016.12.02.15.33.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Dec 2016 15:33:03 -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 v3 2/2] net: stmmac: dwmac-meson8b: make the RGMII TX delay configurable Date: Sat, 3 Dec 2016 00:32:38 +0100 Message-Id: <20161202233238.17561-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161202233238.17561-1-martin.blumenstingl@googlemail.com> References: <20161125130156.17879-1-martin.blumenstingl@googlemail.com> <20161202233238.17561-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161202_153325_912311_1519E6DB X-CRM114-Status: GOOD ( 14.63 ) 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 250e4ce..dad31b0 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: @@ -277,6 +280,12 @@ static int meson8b_dwmac_probe(struct platform_device *pdev) if (dwmac->phy_mode < 0) { dev_err(&pdev->dev, "missing phy-mode property\n"); return -EINVAL; + } 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);