From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796108429; b=Lb/NdGICuHKT0hmmiZrPV7BgY9B+Xa2f6XNqDNZDtQHRFh4EbmZ0N8pMK00JvtKfgZGD Ty/O1GDJwp7NSNUzgLjLIt6h9a2famzPAWavlgdHWR58CrLjyiVQ38H2bcmbQD5TaI9Ba pNBeN5BJxG424W3hWBGiyTDit+qqTOjiCcudMTuvaC19qzWrJQFS/90bVg8sijG75xWw6 ltOy6KfYNNGD4wZ3EkIkx4h5eEqkv5g50BNrf36IR3QF1GzjIueUhbwJ/z3KwK8Tn3qRE nf5jsNnFDaUCTglxPOX9uYI0reG0yyZfJkYfSlns6jIrhlhfbNRgN63Uw+7FgWLqMtg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796108429; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=XGzcpTXXY7slCNdtoWFcPm/P/jZv125TXCsiU07xIHQ=; b=1+272N1POKNTGKG4mWId6VCB4WId7viWYCSQE9pt0VNTUeu76LRwbgwxkTO8tTzmICCh xpeu8saJnw2zlKrZsTpCWqlP4sTGXBucTFoEm1V+LCpoFRn5j8LGjVvxLJvxYHz+MnAv+ tDzV8hx4c1ujmJjUBoNfMFe9a2rzi4pjEdb3MDoZvmC0yJZuTJ1xUzZLXCmpTlo3STmMQ B3hNKSAQNf7b/a/KxiQtxwyui+U2X5oH+VKBzrZlqX/tu9kxChQPFrHjCkeDwAijSgtTv Q2ClkeU0ILWQ7SQWAeCesKYxuc3XUGUFkvRTMimlCDiRIixZFFxnvl7jc+KOlB0Yn8g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=f7AtfnO6; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7FAC606A697; Tue, 1 Dec 2026 07:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=f7AtfnO6 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796108429; b=F44ZLK0fK1b+J85EXGjClZGLjs3jom91tWODdaSV5fn3+2d5oAHHMlXHkaRcjiXkkRgs Dhgp3heejed5yL+4HbXoJmzhp2DD8/i6egjgEioSZOibmYBoIUHksrDPWUGK+DWJTVbKu Ongt0TC43Pkv7axw4syPZw/1tMU+BwfrcY9FeccDZrnoeqGABYN6N9y5jedneHIHJJQEZ bcf2G3nhFG6vPJTz1ia5h++bVLvj8AtlGxga4uY1bbPNeNjOX9mtEfVVdokBrCJBJxNvR Sk4xP0HVjnx9f6wwVunKXPPEfbYVLCtu8DAXxOUhbMMSzEImHoduSzB+vT2CCBNQd0A== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796108429; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=XGzcpTXXY7slCNdtoWFcPm/P/jZv125TXCsiU07xIHQ=; b=nmpE/vWiLaI0ebtlgnw/CQSWik39Llq1DAWNEtUUsW2NjOXqoh28R5cZWVGSL2mFVvo6 33CEAXe78s2ZoBcuMZnTOyKgQ9/lk5fqG3oDTSX3XXfx2rLIOX/270YjXJlWMOMD/+FEv wAZ9KrYuUQWwhqtngIlsaQwN5TSB4volX9PMNlXCqcweERURgUud0obOUvKv+zOeEzvdc +Drd+JSWQ1nnNNfdfyfkajWxnJC7wlBtacU9tKE84dO/dmkjf+w/PPZcVMZVP468wchx0 ZUzvjHhKbNlEqUZFVujnYRKZ5L0TA88cS9S6HG6eGYExqAtQBHMSGgzResezm1Gpiwg== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 7D5311F00898; Tue, 1 Dec 2026 07:00:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796108429; bh=XGzcpTXXY7slCNdtoWFcPm/P/jZv125TXCsiU07xIHQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=f7AtfnO6KTM1GyKAOsJ6TogD5NrE3aSecA0ixqks3hi4qWzc+tynv4bsgz3HsxIWY 2YJt8E6spNx+ylCtC8kia4PkzfSP7pQq3s7f8dE786oUF3zxna/8fYm+Q4dcJxbZtN RVmlEZ/xvlufGyhCd24rHJctRfxvRR/NLkPds7gL+f9GJvnuGhDdMHuddhZXEgpkea 1ii7e8NSuT7KgpBwfstDYy7bCJj+sYKERkFbOig3KxlcudpjJYM3GHews9mJbDferX nCYxzkuTyCM3J34vligNpmtiRQyxrcH8nA7/CXrTze/P5paWvHqWVWkw6lFkK3RDTP fx/utoHmhnalQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 07ADA4EC25; Tue, 1 Dec 2026 07:00:28 +0000 (UTC) From: Joseph Telaak via B4 Relay Date: Tue, 01 Dec 2026 02:00:27 -0500 Subject: [PATCH net-next v2 3/3] net: stmmac: Add Siflower SF19A2890 glue X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261201-sf19a2890-gmac-v2-3-8d2c513db496@telaak.dev> References: <20261201-sf19a2890-gmac-v2-0-8d2c513db496@telaak.dev> In-Reply-To: <20261201-sf19a2890-gmac-v2-0-8d2c513db496@telaak.dev> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Richard Cochran , Alexandre Torgue , Jose Abreu , Maxime Chevallier , Maxime Coquelin Cc: Chuanhong Guo , Russell King , linux-mips@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Joseph Telaak X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796108426; l=8506; i=joseph@telaak.dev; s=20261104; h=from:subject:message-id; bh=R+n40ptiojasJ0ujsrBir+4FeZ9XX4vOCakTvhU36tw=; b=zGORDooQgrhpk1MLsXCO9RH5mlUt44k834OVIZh54Oe1T4GcqOAIoAa/aMXwMIFak5GwDekgR frBHsEJhPJqCnyxJWNbwkz2IDHfilqE7hVLSavF1mWrLgIesa9JUXfn X-Developer-Key: i=joseph@telaak.dev; a=ed25519; pk=oQI+UfddlZ0wK2ac4WKOGNjUl1ZEN8j9ZVFSqEDoNP0= X-Endpoint-Received: by B4 Relay for joseph@telaak.dev/20261104 with auth_id=1404 X-Original-From: Joseph Telaak Reply-To: joseph@telaak.dev Content-Transfer-Encoding: 7bit From: Joseph Telaak Add the glue for the DesignWare GMAC of the Siflower SF19A2890. The interface type is set in the GMAC's configuration block through the set_phy_intf_sel hook, and so are the RGMII clock delays. Siflower calibrates the delay lines of each unit at the factory and stores the settings in flash as four hex digits, TX and then RX. The glue programs them from the rgmii-delay nvmem cell and sets has_internal_tx_delay and has_internal_rx_delay, so stmmac takes the delays off the mode it passes on. Without a calibration it leaves the lines as the bootloader set them. Based on Chuanhong Guo's driver from OpenWrt and his siflower-7.1 branch, which read the same calibration. That driver also set STMMAC_FLAG_HAS_INTEGRATED_PCS, because the core reports a PCS that does not work in RGMII mode; stmmac now uses the integrated PCS only for SGMII, and the flag is gone. Signed-off-by: Joseph Telaak --- MAINTAINERS | 1 + drivers/net/ethernet/stmicro/stmmac/Kconfig | 12 ++ drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../net/ethernet/stmicro/stmmac/dwmac-sf19a2890.c | 167 +++++++++++++++++++++ 4 files changed, 181 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index c279b28bce86..c659c4e5cce2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25825,6 +25825,7 @@ M: Joseph Telaak L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/siflower,sf19a2890-gmac.yaml +F: drivers/net/ethernet/stmicro/stmmac/dwmac-sf19a2890.c SILEAD TOUCHSCREEN DRIVER M: Hans de Goede diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index c6559e749c0c..3175f3c2bbc9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -201,6 +201,18 @@ config DWMAC_S32 SOCs GMAC ethernet controller, ie. S32G2xx, S32G3xx and S32R45. +config DWMAC_SF19A2890 + tristate "Siflower SF19A2890 GMAC support" + default MACH_SIFLOWER_MIPS + depends on OF && (MACH_SIFLOWER_MIPS || COMPILE_TEST) + help + Support for the Ethernet controller of the Siflower SF19A2890 SoC. + + This selects the SF19A2890 glue layer support for the stmmac + device driver. It sets the interface type and the RGMII clock + delays, from the unit's factory calibration, in the GMAC's + configuration block. + config DWMAC_SOCFPGA tristate "SOCFPGA dwmac support" default ARCH_INTEL_SOCFPGA diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile index b16a456b730e..9330de094202 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Makefile +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_DWMAC_RENESAS_GBETH) += dwmac-renesas-gbeth.o obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o obj-$(CONFIG_DWMAC_RZN1) += dwmac-rzn1.o obj-$(CONFIG_DWMAC_S32) += dwmac-s32.o +obj-$(CONFIG_DWMAC_SF19A2890) += dwmac-sf19a2890.o obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-altr-socfpga.o obj-$(CONFIG_DWMAC_SOPHGO) += dwmac-sophgo.o obj-$(CONFIG_DWMAC_SPACEMIT) += dwmac-spacemit.o diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sf19a2890.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sf19a2890.c new file mode 100644 index 000000000000..d53f8fbede71 --- /dev/null +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sf19a2890.c @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Siflower SF19A2890 GMAC glue + * + * The SF19A2890 has a DWMAC 3.73a. Its interface type and RGMII clock delays + * are set in a register block of its own. + * + * Based on the driver by Chuanhong Guo . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stmmac_platform.h" + +/* GMAC configuration block */ +#define SF19A2890_GMAC_MISC 0x0 +#define SF19A2890_PHY_INTF_SEL GENMASK(2, 0) +#define SF19A2890_GMAC_TX_DELAY 0x4 +#define SF19A2890_GMAC_RX_DELAY 0x8 +#define SF19A2890_GMAC_RX_DELAY_EN 0xc + +/* The factory calibration: four hex digits, the TX setting and then RX */ +#define SF19A2890_DELAY_CAL_LEN 4 +#define SF19A2890_DELAY_CAL_TX GENMASK(15, 8) +#define SF19A2890_DELAY_CAL_RX GENMASK(7, 0) + +struct sf19a2890_gmac { + void __iomem *cfg; +}; + +static int sf19a2890_gmac_set_phy_intf_sel(void *bsp_priv, u8 phy_intf_sel) +{ + struct sf19a2890_gmac *gmac = bsp_priv; + u32 val; + + if (phy_intf_sel != PHY_INTF_SEL_GMII_MII && + phy_intf_sel != PHY_INTF_SEL_RGMII && + phy_intf_sel != PHY_INTF_SEL_RMII) + return -EINVAL; + + val = readl(gmac->cfg + SF19A2890_GMAC_MISC); + val &= ~SF19A2890_PHY_INTF_SEL; + val |= FIELD_PREP(SF19A2890_PHY_INTF_SEL, phy_intf_sel); + writel(val, gmac->cfg + SF19A2890_GMAC_MISC); + + return 0; +} + +/* + * The delay lines are calibrated per unit at the factory, in their own steps. + * Without a calibration, keep what the bootloader set. + */ +static int sf19a2890_gmac_set_delays(struct device *dev, + struct sf19a2890_gmac *gmac, + struct plat_stmmacenet_data *plat_dat) +{ + char str[SF19A2890_DELAY_CAL_LEN + 1] = {}; + struct nvmem_cell *cell; + size_t len; + void *buf; + u16 cal; + + cell = devm_nvmem_cell_get(dev, "rgmii-delay"); + if (IS_ERR(cell)) { + if (PTR_ERR(cell) == -ENOENT) + return 0; + return dev_err_probe(dev, PTR_ERR(cell), + "failed to get the delay calibration\n"); + } + + buf = nvmem_cell_read(cell, &len); + if (IS_ERR(buf)) + return dev_err_probe(dev, PTR_ERR(buf), + "failed to read the delay calibration\n"); + + memcpy(str, buf, min(len, sizeof(str) - 1)); + kfree(buf); + + /* An uncalibrated unit reads back erased flash */ + if (len != SF19A2890_DELAY_CAL_LEN || kstrtou16(str, 16, &cal)) { + dev_warn(dev, "no valid delay calibration, keeping the bootloader's\n"); + return 0; + } + + writel(FIELD_GET(SF19A2890_DELAY_CAL_TX, cal), + gmac->cfg + SF19A2890_GMAC_TX_DELAY); + writel(FIELD_GET(SF19A2890_DELAY_CAL_RX, cal), + gmac->cfg + SF19A2890_GMAC_RX_DELAY); + /* With RX_DELAY_EN clear, the RX delay line is bypassed */ + writel(1, gmac->cfg + SF19A2890_GMAC_RX_DELAY_EN); + + /* The MAC adds the delays, so stmmac must not ask the PHY for them */ + plat_dat->has_internal_tx_delay = true; + plat_dat->has_internal_rx_delay = true; + + return 0; +} + +static int sf19a2890_gmac_probe(struct platform_device *pdev) +{ + struct plat_stmmacenet_data *plat_dat; + struct stmmac_resources stmmac_res; + struct device *dev = &pdev->dev; + struct sf19a2890_gmac *gmac; + struct clk *clk; + int ret; + + gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL); + if (!gmac) + return -ENOMEM; + + gmac->cfg = devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(gmac->cfg)) + return dev_err_probe(dev, PTR_ERR(gmac->cfg), + "failed to map the configuration block\n"); + + clk = devm_clk_get_enabled(dev, "byp_ref"); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), + "failed to enable the byp_ref clock\n"); + + ret = stmmac_get_platform_resources(pdev, &stmmac_res); + if (ret) + return ret; + + plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac); + if (IS_ERR(plat_dat)) + return PTR_ERR(plat_dat); + + ret = sf19a2890_gmac_set_delays(dev, gmac, plat_dat); + if (ret) + return ret; + + plat_dat->bsp_priv = gmac; + plat_dat->set_phy_intf_sel = sf19a2890_gmac_set_phy_intf_sel; + + return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res); +} + +static const struct of_device_id sf19a2890_gmac_match[] = { + { .compatible = "siflower,sf19a2890-gmac" }, + { } +}; +MODULE_DEVICE_TABLE(of, sf19a2890_gmac_match); + +static struct platform_driver sf19a2890_gmac_driver = { + .probe = sf19a2890_gmac_probe, + .driver = { + .name = "sf19a2890-gmac", + .pm = &stmmac_pltfr_pm_ops, + .of_match_table = sf19a2890_gmac_match, + }, +}; +module_platform_driver(sf19a2890_gmac_driver); + +MODULE_DESCRIPTION("Siflower SF19A2890 GMAC glue"); +MODULE_LICENSE("GPL"); -- Git-155)