Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2069059pxb; Sat, 14 Nov 2020 12:03:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxRlclRfIe6m2mpdLj8ClEryEkZpKar3Iu1OFmVzmn+Hat7wmMVBza6JNduRMjdghutJyN X-Received: by 2002:a50:e149:: with SMTP id i9mr8986341edl.56.1605384214957; Sat, 14 Nov 2020 12:03:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605384214; cv=none; d=google.com; s=arc-20160816; b=NDntVjHAACnxteZL5IYMs9Gw23i+4FDd0Pzf9LW9gdrVHO1N35fzzQR0rOhaxw7VEP Av/5Cf/w6RdZf/yjnBgx5GaYJMqEVdKil6m7jTpq3JUj7jgCiVbjWkstWljg5di5gT9a tDt6nlug8CIanzLcjkrGNgk+yTk/vrWkj6XHkn05YwKTb46zp3xN7OGz48ffwcMtezdS earRXJ8CkL60nr+EGLiG20jbUNeb6FithJ6egWPysm4UkL7FnNVgC1O/4JXZGE3UQM6b jsR5rVITMr/2GR3tHOOkJjfJ0fVB/RWvO8tXzDctfpQKyqgC+KInX6ynOhH2d/luUz2m Ymcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w4KSCu27l61jUmMvpofG000bGUgTYBDrDcAVkMbuCyA=; b=Ylwd8wu9/60Y30f3vkRUUZxHo8NDu1Qfy2YgpncIZDoP3jh4f2U3xg+EST/x3sLb29 RHMp/IblO6017S1pg5eK6Uq6B5FambWRTBL9noHtM8C4Mxp+1afiG1UDgLdwNwqFAXSm TqLd6MYpi85DMNFWuTNu950suadN72Trp4dZLvRjXLBpdy3ivhC5ST/YwoP8c0fy//0X ovxv4SsMXhL+4CP8/rGGIvKoIIo0rLqriNYAgL4B9VO4DOSwstYddeGR7GtV4uL9Rnvp CjQi+aT188zWO6bHGF9WFkQdKKI0AlkWMMs+BvHg6bCG9WeErvI6uwxEGV3TQQfusU2I iI9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20161025 header.b=df1iiyg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce10si10524454edb.515.2020.11.14.12.03.12; Sat, 14 Nov 2020 12:03:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@googlemail.com header.s=20161025 header.b=df1iiyg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726476AbgKNUBy (ORCPT + 99 others); Sat, 14 Nov 2020 15:01:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbgKNUBx (ORCPT ); Sat, 14 Nov 2020 15:01:53 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78CB2C0613D2; Sat, 14 Nov 2020 12:01:53 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id d142so19822129wmd.4; Sat, 14 Nov 2020 12:01:53 -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 :mime-version:content-transfer-encoding; bh=w4KSCu27l61jUmMvpofG000bGUgTYBDrDcAVkMbuCyA=; b=df1iiyg4RObmAz6QqEy/oZPHW8DWWG/RColzjhlKYrQg7ZJLAafNl84K5Ci7Gg8mEY t0RzAt9YobM37tHebL1M6oVNF9sjMKtuT4BmuEZmzaZW9RTUigUC7dhR085dOTAWZcbq 6GjIskkHp3my2xaxquushjDsVSeP5XW7o0QElyVPXaqea8GuE38jQJzasvgT52jupqOK AlyILAVDOaONhl7FWFzhz/gxU4n7JX/zQLZyK0I/5xCK5l1IQxTiQHsrwEizO0W6sUL6 kxGrQUJ5MaqCLTaLwK3MMWF/2mgJ9/hQWvRaHTN3llRg8PBc59T6md65s/a2nmYY2q5L QMZQ== 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:mime-version:content-transfer-encoding; bh=w4KSCu27l61jUmMvpofG000bGUgTYBDrDcAVkMbuCyA=; b=oUe/AgMcntvQZapv/w6YPVXzjwoL3ggQm7EPpKPurX4aNa3vfH+bjYimxgtZJfZ2d4 u5MQKz6FYBv5GJIMQfcQY2+PHw605RoCBexmnjGaJ6ZGL+Ji1nPGj7IIUGDYEsHVEVzz 9lRUl2nzoUZNS1lQABJolTP5D95sHexk4Qt/qgvxF8YC+KLdhT5M29aWrrOnroOBmPzZ EZH9gB7NbyfCdz5PQSMf0W9v+uGZgxWAnyk3LoEIDTA7ddBb2dttl+M688h5czjSuTwr GS9TOBN7FfEGVvOJ5oP+Rwk+bSLD8zp8kxuZwGRtF3CVzcGfEJlrEsIlJP4VDe0tcoYJ FWJQ== X-Gm-Message-State: AOAM532BZqUxtkRtETihF2MCsv7tjQXQ7E+U75CFVDzZmQpE0sp4Iml6 mNNSYKxGivHfrEp4/r7kLVKoBy/qLkD0SQ== X-Received: by 2002:a7b:c5c6:: with SMTP id n6mr8276033wmk.131.1605384112102; Sat, 14 Nov 2020 12:01:52 -0800 (PST) Received: from localhost.localdomain (p4fc3ea77.dip0.t-ipconnect.de. [79.195.234.119]) by smtp.googlemail.com with ESMTPSA id g138sm14342953wme.39.2020.11.14.12.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Nov 2020 12:01:51 -0800 (PST) From: Martin Blumenstingl To: davem@davemloft.net, kuba@kernel.org, linux-amlogic@lists.infradead.org, devicetree@vger.kernel.org, robh+dt@kernel.org Cc: jianxin.pan@amlogic.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, khilman@baylibre.com, narmstrong@baylibre.com, jbrunet@baylibre.com, andrew@lunn.ch, Martin Blumenstingl Subject: [PATCH RFC v1 4/4] net: stmmac: dwmac-meson8b: add support for the RGMII RX delay on G12A Date: Sat, 14 Nov 2020 21:01:04 +0100 Message-Id: <20201114200104.4148283-5-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201114200104.4148283-1-martin.blumenstingl@googlemail.com> References: <20201114200104.4148283-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Amlogic Meson G12A (and newer: G12B, SM1) SoCs have a more advanced RX delay logic. Instead of fine-tuning the delay in the nanoseconds range it now allows tuning in 200 picosecond steps. This support comes with new bits in the PRG_ETH1[19:16] register. Add support for validating the RGMII RX delay as well as configuring the register accordingly on these platforms. Signed-off-by: Martin Blumenstingl --- .../ethernet/stmicro/stmmac/dwmac-meson8b.c | 63 ++++++++++++++----- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c index a6e2077ed871..ae081fbc0552 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c @@ -69,10 +69,21 @@ */ #define PRG_ETH0_ADJ_SKEW GENMASK(24, 20) +#define PRG_ETH1 0x4 + +/* Defined for adding a delay to the input RX_CLK for better timing. + * Each step is 200ps. These bits are used with external RGMII PHYs + * because RGMII RX only has the small window. cfg_rxclk_dly can + * adjust the window between RX_CLK and RX_DATA and improve the stability + * of "rx data valid". + */ +#define PRG_ETH1_CFG_RXCLK_DLY GENMASK(19, 16) + struct meson8b_dwmac; struct meson8b_dwmac_data { int (*set_phy_mode)(struct meson8b_dwmac *dwmac); + bool has_prg_eth1_rgmii_rx_delay; }; struct meson8b_dwmac { @@ -270,30 +281,35 @@ static int meson8b_devm_clk_prepare_enable(struct meson8b_dwmac *dwmac, static int meson8b_init_rgmii_delays(struct meson8b_dwmac *dwmac) { - u32 tx_dly_config, rx_dly_config, delay_config; + u32 tx_dly_config, rx_adj_config, cfg_rxclk_dly, delay_config; int ret; + rx_adj_config = 0; + cfg_rxclk_dly = 0; tx_dly_config = FIELD_PREP(PRG_ETH0_TXDLY_MASK, dwmac->tx_delay_ns >> 1); - if (dwmac->rx_delay_ps == 2000) - rx_dly_config = PRG_ETH0_ADJ_ENABLE | PRG_ETH0_ADJ_SETUP; - else - rx_dly_config = 0; + if (dwmac->data->has_prg_eth1_rgmii_rx_delay) + cfg_rxclk_dly = FIELD_PREP(PRG_ETH1_CFG_RXCLK_DLY, + dwmac->rx_delay_ps / 200); + else if (dwmac->rx_delay_ps == 2000) + rx_adj_config = PRG_ETH0_ADJ_ENABLE | PRG_ETH0_ADJ_SETUP; switch (dwmac->phy_mode) { case PHY_INTERFACE_MODE_RGMII: - delay_config = tx_dly_config | rx_dly_config; + delay_config = tx_dly_config | rx_adj_config; break; case PHY_INTERFACE_MODE_RGMII_RXID: delay_config = tx_dly_config; + cfg_rxclk_dly = 0; break; case PHY_INTERFACE_MODE_RGMII_TXID: - delay_config = rx_dly_config; + delay_config = rx_adj_config; break; case PHY_INTERFACE_MODE_RGMII_ID: case PHY_INTERFACE_MODE_RMII: delay_config = 0; + cfg_rxclk_dly = 0; break; default: dev_err(dwmac->dev, "unsupported phy-mode %s\n", @@ -301,7 +317,7 @@ static int meson8b_init_rgmii_delays(struct meson8b_dwmac *dwmac) return -EINVAL; } - if (rx_dly_config & PRG_ETH0_ADJ_ENABLE) { + if (rx_adj_config & PRG_ETH0_ADJ_ENABLE) { if (!dwmac->timing_adj_clk) { dev_err(dwmac->dev, "The timing-adjustment clock is mandatory for the RX delay re-timing\n"); @@ -323,6 +339,9 @@ static int meson8b_init_rgmii_delays(struct meson8b_dwmac *dwmac) PRG_ETH0_ADJ_DELAY | PRG_ETH0_ADJ_SKEW, delay_config); + meson8b_dwmac_mask_bits(dwmac, PRG_ETH1, PRG_ETH1_CFG_RXCLK_DLY, + cfg_rxclk_dly); + return 0; } @@ -424,11 +443,20 @@ static int meson8b_dwmac_probe(struct platform_device *pdev) dwmac->rx_delay_ps *= 1000; } - if (dwmac->rx_delay_ps != 0 && dwmac->rx_delay_ps != 2000) { - dev_err(&pdev->dev, - "The only allowed RX delays values are: 0ps, 2000ps"); - ret = -EINVAL; - goto err_remove_config_dt; + if (dwmac->data->has_prg_eth1_rgmii_rx_delay) { + if (dwmac->rx_delay_ps != 0 && dwmac->rx_delay_ps != 2000) { + dev_err(dwmac->dev, + "The only allowed RGMII RX delays values are: 0ps, 2000ps"); + ret = -EINVAL; + goto err_remove_config_dt; + } + } else { + if (dwmac->rx_delay_ps > 3000 || dwmac->rx_delay_ps % 200) { + dev_err(dwmac->dev, + "The RGMII RX delay range is 0..3000ps in 200ps steps"); + ret = -EINVAL; + goto err_remove_config_dt; + } } dwmac->timing_adj_clk = devm_clk_get_optional(dwmac->dev, @@ -470,10 +498,17 @@ static int meson8b_dwmac_probe(struct platform_device *pdev) static const struct meson8b_dwmac_data meson8b_dwmac_data = { .set_phy_mode = meson8b_set_phy_mode, + .has_prg_eth1_rgmii_rx_delay = false, }; static const struct meson8b_dwmac_data meson_axg_dwmac_data = { .set_phy_mode = meson_axg_set_phy_mode, + .has_prg_eth1_rgmii_rx_delay = false, +}; + +static const struct meson8b_dwmac_data meson_g12a_dwmac_data = { + .set_phy_mode = meson_axg_set_phy_mode, + .has_prg_eth1_rgmii_rx_delay = true, }; static const struct of_device_id meson8b_dwmac_match[] = { @@ -495,7 +530,7 @@ static const struct of_device_id meson8b_dwmac_match[] = { }, { .compatible = "amlogic,meson-g12a-dwmac", - .data = &meson_axg_dwmac_data, + .data = &meson_g12a_dwmac_data, }, { } }; -- 2.29.2