From patchwork Tue Nov 21 15:17:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 1866885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZSgX4pMrz1yRV for ; Wed, 22 Nov 2023 02:18:15 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4SZSgT3V1hz3clw for ; Wed, 22 Nov 2023 02:18:13 +1100 (AEDT) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=fail (SPF fail - not authorized) smtp.mailfrom=nuvoton.com (client-ip=212.199.177.27; helo=herzl.nuvoton.co.il; envelope-from=tomer.maimon@nuvoton.com; receiver=lists.ozlabs.org) Received: from herzl.nuvoton.co.il (unknown [212.199.177.27]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4SZSg852mSz2xHT for ; Wed, 22 Nov 2023 02:17:52 +1100 (AEDT) Received: from NTILML01.nuvoton.com (212.199.177.18.static.012.net.il [212.199.177.18]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 3ALFHfev026532 for ; Tue, 21 Nov 2023 17:17:41 +0200 Received: from NTHCCAS04.nuvoton.com (10.1.8.29) by NTILML01.nuvoton.com (10.190.1.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.14; Tue, 21 Nov 2023 17:17:40 +0200 Received: from NTHCCAS01.nuvoton.com (10.1.8.28) by NTHCCAS04.nuvoton.com (10.1.8.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.14; Tue, 21 Nov 2023 23:17:38 +0800 Received: from taln58.nuvoton.co.il (10.191.1.178) by NTHCCAS01.nuvoton.com (10.1.8.28) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 21 Nov 2023 23:17:38 +0800 Received: from taln60.nuvoton.co.il (taln60 [10.191.1.180]) by taln58.nuvoton.co.il (Postfix) with ESMTP id BD5805F63D; Tue, 21 Nov 2023 17:17:36 +0200 (IST) Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 50B72235CE25; Tue, 21 Nov 2023 17:17:36 +0200 (IST) From: Tomer Maimon To: , , , , , , , , , , , , , , , Subject: [PATCH v1 1/2] dt-bindings: net: Add support NPCM dwmac Date: Tue, 21 Nov 2023 17:17:32 +0200 Message-ID: <20231121151733.2015384-2-tmaimon77@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231121151733.2015384-1-tmaimon77@gmail.com> References: <20231121151733.2015384-1-tmaimon77@gmail.com> MIME-Version: 1.0 X-NotSetDelaration: True X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Tomer Maimon , netdev@vger.kernel.org, openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Add documentation to describe Nuvoton BMC NPCM dwmac driver(sgmii). Signed-off-by: Tomer Maimon --- .../bindings/net/nuvoton,npcm8xx-sgmii.yaml | 72 +++++++++++++++++++ .../devicetree/bindings/net/snps,dwmac.yaml | 1 + 2 files changed, 73 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/nuvoton,npcm8xx-sgmii.yaml diff --git a/Documentation/devicetree/bindings/net/nuvoton,npcm8xx-sgmii.yaml b/Documentation/devicetree/bindings/net/nuvoton,npcm8xx-sgmii.yaml new file mode 100644 index 000000000000..6a5f2cade7c9 --- /dev/null +++ b/Documentation/devicetree/bindings/net/nuvoton,npcm8xx-sgmii.yaml @@ -0,0 +1,72 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/nuvoton,npcm8xx-sgmii.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton NPCM DWMAC SGMII Ethernet controller + +maintainers: + - Tomer Maimon + +select: + properties: + compatible: + contains: + enum: + - nuvoton,npcm8xx-sgmii + required: + - compatible + +allOf: + - $ref: snps,dwmac.yaml# + +properties: + compatible: + oneOf: + - items: + - enum: + - nuvoton,npcm8xx-sgmii + - const: snps,dwmac-3.50a + reg: + items: + - description: + The first range represent DWMAC controller registers. + - description: + The second range represent PCS configuration registers. + + clocks: + items: + - description: GMAC main clock + + clock-names: + items: + - const: stmmaceth + +required: + - compatible + - reg + - clocks + - clock-names + +unevaluatedProperties: false + +examples: + - | + #include + #include + + ahb { + #address-cells = <2>; + #size-cells = <2>; + + gmac0: ethernet@f0802000 { + compatible = "nuvoton,npcm8xx-sgmii","snps,dwmac-3.50a"; + reg = <0x0 0xf0802000 0x0 0x2000>, <0x0 0xf0780000 0x0 0x200>; + interrupts = ; + interrupt-names = "macirq"; + clocks = <&clk NPCM8XX_CLK_AHB>; + clock-names = "stmmaceth"; + phy-mode = "rgmii-id"; + }; + }; diff --git a/Documentation/devicetree/bindings/net/snps,dwmac.yaml b/Documentation/devicetree/bindings/net/snps,dwmac.yaml index 5c2769dc689a..ba52dbc85144 100644 --- a/Documentation/devicetree/bindings/net/snps,dwmac.yaml +++ b/Documentation/devicetree/bindings/net/snps,dwmac.yaml @@ -66,6 +66,7 @@ properties: - ingenic,x2000-mac - loongson,ls2k-dwmac - loongson,ls7a-dwmac + - nuvoton,npcm8xx-sgmii - qcom,qcs404-ethqos - qcom,sa8775p-ethqos - qcom,sc8280xp-ethqos From patchwork Tue Nov 21 15:17:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 1866887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZShh0dW1z1yRV for ; Wed, 22 Nov 2023 02:19:16 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4SZShg6rJvz3dSl for ; Wed, 22 Nov 2023 02:19:15 +1100 (AEDT) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=fail (SPF fail - not authorized) smtp.mailfrom=nuvoton.com (client-ip=212.199.177.27; helo=herzl.nuvoton.co.il; envelope-from=tomer.maimon@nuvoton.com; receiver=lists.ozlabs.org) Received: from herzl.nuvoton.co.il (unknown [212.199.177.27]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4SZSg91LFBz3c2L for ; Wed, 22 Nov 2023 02:17:51 +1100 (AEDT) Received: from NTILML01.nuvoton.com (212.199.177.18.static.012.net.il [212.199.177.18]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 3ALFHfUh026535 for ; Tue, 21 Nov 2023 17:17:42 +0200 Received: from NTHCCAS02.nuvoton.com (10.1.9.121) by NTILML01.nuvoton.com (10.190.1.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 21 Nov 2023 17:17:41 +0200 Received: from NTHCCAS01.nuvoton.com (10.1.8.28) by NTHCCAS02.nuvoton.com (10.1.9.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 21 Nov 2023 23:17:39 +0800 Received: from taln58.nuvoton.co.il (10.191.1.178) by NTHCCAS01.nuvoton.com (10.1.8.28) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 21 Nov 2023 23:17:39 +0800 Received: from taln60.nuvoton.co.il (taln60 [10.191.1.180]) by taln58.nuvoton.co.il (Postfix) with ESMTP id B26A35F63F; Tue, 21 Nov 2023 17:17:37 +0200 (IST) Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 9EC7B235CE27; Tue, 21 Nov 2023 17:17:36 +0200 (IST) From: Tomer Maimon To: , , , , , , , , , , , , , , , Subject: [PATCH v1 2/2] net: stmmac: Add NPCM support Date: Tue, 21 Nov 2023 17:17:33 +0200 Message-ID: <20231121151733.2015384-3-tmaimon77@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231121151733.2015384-1-tmaimon77@gmail.com> References: <20231121151733.2015384-1-tmaimon77@gmail.com> MIME-Version: 1.0 X-NotSetDelaration: True X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Tomer Maimon , netdev@vger.kernel.org, openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Add Nuvoton NPCM BMC SoCs support to STMMAC dwmac driver. And modify MAINTAINERS to add a new F: entry for this driver. Signed-off-by: Tomer Maimon --- MAINTAINERS | 1 + drivers/net/ethernet/stmicro/stmmac/Kconfig | 9 ++ drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../net/ethernet/stmicro/stmmac/dwmac-npcm.c | 121 ++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-npcm.c diff --git a/MAINTAINERS b/MAINTAINERS index 5c9f868e13b6..43059c7d00c7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2507,6 +2507,7 @@ F: arch/arm64/boot/dts/nuvoton/ F: drivers/*/*/*npcm* F: drivers/*/*npcm* F: drivers/rtc/rtc-nct3018y.c +F: drivers/net/ethernet/stmicro/stmmac/dwmac-npcm.c F: include/dt-bindings/clock/nuvoton,npcm7xx-clock.h F: include/dt-bindings/clock/nuvoton,npcm845-clk.h diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index a2b9e289aa36..2487a674d0d3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -121,6 +121,15 @@ config DWMAC_MESON the stmmac device driver. This driver is used for Meson6, Meson8, Meson8b and GXBB SoCs. +config DWMAC_NPCM + tristate "Nuvoton NPCM dwmac support" + depends on OF && (ARCH_NPCM || COMPILE_TEST) + help + Support for Ethernet controller on Nuvoton NPCM BMC SoCs. + + This selects the Nuvoton NPCM BMC SoC glue layer support for + the stmmac device driver. This driver is used for NPCM8xx SoCs. + config DWMAC_QCOM_ETHQOS tristate "Qualcomm ETHQOS support" default ARCH_QCOM diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile index 80e598bd4255..1c86c8ca39f0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Makefile +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_DWMAC_IPQ806X) += dwmac-ipq806x.o obj-$(CONFIG_DWMAC_LPC18XX) += dwmac-lpc18xx.o obj-$(CONFIG_DWMAC_MEDIATEK) += dwmac-mediatek.o obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o dwmac-meson8b.o +obj-$(CONFIG_DWMAC_NPCM) += dwmac-npcm.o obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-ethqos.o obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-altr-socfpga.o diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-npcm.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-npcm.c new file mode 100644 index 000000000000..dbb857661142 --- /dev/null +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-npcm.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (c) 2023 Nuvoton Technology corporation. + +#include +#include +#include +#include +#include +#include +#include + +#include "stmmac_platform.h" + +#define IND_AC_BA_REG 0x1FE +#define SR_MII_CTRL 0x3E0000 + +#define PCS_SR_MII_CTRL_REG 0x0 +#define PCS_SPEED_SELECT6 BIT(6) +#define PCS_AN_ENABLE BIT(12) +#define PCS_SPEED_SELECT13 BIT(13) +#define PCS_RST BIT(15) + +#define PCS_MASK_SPEED 0xDFBF + +struct npcm_dwmac { + void __iomem *reg; +}; + +static void npcm_dwmac_fix_mac_speed(void *priv, unsigned int speed, + unsigned int mode) +{ + struct npcm_dwmac *dwmac = priv; + u16 val; + + iowrite16((u16)(SR_MII_CTRL >> 9), dwmac->reg + IND_AC_BA_REG); + val = ioread16(dwmac->reg + PCS_SR_MII_CTRL_REG); + val &= PCS_MASK_SPEED; + + switch (speed) { + case SPEED_1000: + val |= PCS_SPEED_SELECT6; + break; + case SPEED_100: + val |= PCS_SPEED_SELECT13; + break; + case SPEED_10: + break; + } + + iowrite16(val, dwmac->reg + PCS_SR_MII_CTRL_REG); +} + +void npcm_dwmac_pcs_init(struct npcm_dwmac *dwmac, struct device *dev, + struct plat_stmmacenet_data *plat_dat) +{ + u16 val; + + iowrite16((u16)(SR_MII_CTRL >> 9), dwmac->reg + IND_AC_BA_REG); + val = ioread16(dwmac->reg + PCS_SR_MII_CTRL_REG); + val |= PCS_RST; + iowrite16(val, dwmac->reg + PCS_SR_MII_CTRL_REG); + + while (val & PCS_RST) + val = ioread16(dwmac->reg + PCS_SR_MII_CTRL_REG); + + val &= ~(PCS_AN_ENABLE); + iowrite16(val, dwmac->reg + PCS_SR_MII_CTRL_REG); +} + +static int npcm_dwmac_probe(struct platform_device *pdev) +{ + struct plat_stmmacenet_data *plat_dat; + struct stmmac_resources stmmac_res; + struct npcm_dwmac *dwmac; + int ret; + + 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); + + dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + if (!dwmac) + ret = -ENOMEM; + + dwmac->reg = devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(dwmac->reg)) + ret = PTR_ERR(dwmac->reg); + + npcm_dwmac_pcs_init(dwmac, &pdev->dev, plat_dat); + + plat_dat->has_gmac = true; + plat_dat->bsp_priv = dwmac; + plat_dat->fix_mac_speed = npcm_dwmac_fix_mac_speed; + + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); +} + +static const struct of_device_id npcm_dwmac_match[] = { + { .compatible = "nuvoton,npcm8xx-sgmii" }, + { } +}; +MODULE_DEVICE_TABLE(of, npcm_dwmac_match); + +static struct platform_driver npcm_dwmac_driver = { + .probe = npcm_dwmac_probe, + .remove_new = stmmac_pltfr_remove, + .driver = { + .name = "npcm-dwmac", + .pm = &stmmac_pltfr_pm_ops, + .of_match_table = npcm_dwmac_match, + }, +}; +module_platform_driver(npcm_dwmac_driver); + +MODULE_AUTHOR("Tomer Maimon "); +MODULE_DESCRIPTION("Nuvoton NPCM DWMAC glue layer"); +MODULE_LICENSE("GPL v2");