From patchwork Fri Nov 1 01:43:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inochi Amaoto X-Patchwork-Id: 13858594 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECF968615A; Fri, 1 Nov 2024 01:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730425451; cv=none; b=ZyK+wP+xPIpgR0LDrhnX/OdBywhCKLiLx1/LKw/T/1KULEczaZxgNCqti+/MdeeZ+XhFqBlrTGKzoxH0yMqhwI5ST44MkkmLCXf6oM4w9GT4PtIbyyACkoombeAJv39uHbRTMF0qi3nRQBt0Cbl7m8nHxokZoqJ8vYOPk6dPY08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730425451; c=relaxed/simple; bh=EyXf5SHMkWNNdAkgndgdeF4CpDJYSuEG3jVFZ4mal8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jOxhnAtPR1wbwn3YxGZAZ/YMvP2yLp+Gm0Xb0dwHVLJPFrOmjWACxmRelr3ATfBju/+aG77kjc7Juvj/E2h9FbvxEqD6RHu0nrKX0qST/A6dTVC6WZedpX+XoSfgkMYoENgcqzzBWEqNFqK0hRDn99YNhE8c0xjOJ/xcKq0yr+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eQtDw36Y; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eQtDw36Y" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7db238d07b3so1203392a12.2; Thu, 31 Oct 2024 18:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730425445; x=1731030245; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q61+EZuwNAUrMd8RAaYUfGL0d1Lz2giuMYEfNJvU2Dg=; b=eQtDw36YRcygyYm4CHxmO0odnyjWatdOLfIWysfRKAo/lwkZORJjhd1Hi0Lohe2tMg gIych4TEcpSbCN+HS4+03MCDswuUTCvQxUUEOEI0geQSGY4AGWUpb9mbD0n5a9x+j9zw 1sPsciKq/IPx4RnJzddk4fyLmAfGgdJhmpZlSmiL2cJuOp5FTSsVRwfj2LbBFX/HIBCL IofqmtXHyAHU2Sx+QBDsyBOdTl7phLH5K/c7C6ZX+wDu7PToA7dIa9j+qCYq9UEUXHHU Z24zyhEaVD1LP5vzCybb8Asen7gL9LQYxl0Sc6Aqc/CEqdK3UrncdLoRpNaEcBDCMlV/ 3nwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730425445; x=1731030245; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q61+EZuwNAUrMd8RAaYUfGL0d1Lz2giuMYEfNJvU2Dg=; b=ZCTOIOBStS2H7JXwN9SmBegh0hQho1T/xx18GwsyZXJbIsZY5NUsLyxmBvLrinpOOw P+8cIxT4oVD0WITIuPt5riM6/klJafnIDOtvD0fnWcdF4V4aLGzi1jsvOaG8AirTqjF0 /fI0B0VvkLgtzUGk0x3wrjWK5C7WgAyDXYhf0pEhCRmFUZnL97HhXy/s0fUaO/lMzUym /aRoVzgqZi7pcJ/wM1SL/bBJkD4DnSQRjSKcr544yzJ8Ke4GnLz584B9dstBmlZn0/MZ HawwtkKePgBmk/j3QW6My8bg/AJi06p5ppjngPjK0Kh4KonScHYd8kDsmYrjD7sM0a9a PWCg== X-Forwarded-Encrypted: i=1; AJvYcCUhrj6Ys0RAMXFXxB6CRKB+4t5eQh4FHgm42ZRLe/dNlXI/Cq7IBPoEa7K4kZ9IWsvEOowEOLkIy44O66jT@vger.kernel.org, AJvYcCUlK6/2RsYe8YTzJ+z4D+97GVy7tzBN75Bnprv1NNWC5UftSG2sHSJ6AGTFQT1fOOZDaaeFXXM9@vger.kernel.org, AJvYcCVHX/rtPFDmPGgEmIURTQ/GqLc2fftp0+vGb12RNi8TgzwwPJDyoYIj4fZucKfIlN6wYaCGuDS+2NUA@vger.kernel.org X-Gm-Message-State: AOJu0YyXsUKEqRM13PqLx1za8mxrDHSuEM0ax5JVvDWsppejl07o3J/X 5mpyb/J0vCwuNP9GPJt9G5grEzpIVL5Jl/uOlT/rA0iJLWUrsHhH X-Google-Smtp-Source: AGHT+IHuQlXeDzxBjV0qHdNAUW/L4HbcBenlLkY5FwGEDvFKXThiyZ6Be/Uxw/pMTfPZF0B8P7/cyQ== X-Received: by 2002:a05:6a20:e188:b0:1d9:2994:ca27 with SMTP id adf61e73a8af0-1d9a84d17aemr28269194637.36.1730425445001; Thu, 31 Oct 2024 18:44:05 -0700 (PDT) Received: from localhost ([2001:da8:7001:11::cb]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e93da983edsm1785417a91.4.2024.10.31.18.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 18:44:04 -0700 (PDT) From: Inochi Amaoto To: Chen Wang , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Inochi Amaoto , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Richard Cochran , Paul Walmsley , Palmer Dabbelt , Albert Ou , Giuseppe Cavallaro Cc: Yixun Lan , Longbin Li , Inochi Amaoto , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org Subject: [PATCH RFC net-next 3/3] net: stmmac: Add glue layer for Sophgo SG2044 SoC Date: Fri, 1 Nov 2024 09:43:27 +0800 Message-ID: <20241101014327.513732-4-inochiama@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241101014327.513732-1-inochiama@gmail.com> References: <20241101014327.513732-1-inochiama@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Adds Sophgo dwmac driver support on the Sophgo SG2044 SoC. Signed-off-by: Inochi Amaoto --- drivers/net/ethernet/stmicro/stmmac/Kconfig | 11 ++ drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../ethernet/stmicro/stmmac/dwmac-sophgo.c | 105 ++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index 05cc07b8f48c..bc44b21c593f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -169,6 +169,17 @@ config DWMAC_SOCFPGA for the stmmac device driver. This driver is used for arria5 and cyclone5 FPGA SoCs. +config DWMAC_SOPHGO + tristate "Sophgo dwmac support" + depends on OF && (ARCH_SOPHGO || COMPILE_TEST) + default m if ARCH_SOPHGO + help + Support for ethernet controllers on Sophgo RISC-V SoCs + + This selects the Sophgo SoC specific glue layer support + for the stmmac device driver. This driver is used for the + ethernet controllers on various Sophgo SoCs. + config DWMAC_STARFIVE tristate "StarFive dwmac support" depends on OF && (ARCH_STARFIVE || COMPILE_TEST) diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile index c2f0e91f6bf8..e1287b53047b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Makefile +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile @@ -23,6 +23,7 @@ obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-ethqos.o obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o obj-$(CONFIG_DWMAC_RZN1) += dwmac-rzn1.o obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-altr-socfpga.o +obj-$(CONFIG_DWMAC_SOPHGO) += dwmac-sophgo.o obj-$(CONFIG_DWMAC_STARFIVE) += dwmac-starfive.o obj-$(CONFIG_DWMAC_STI) += dwmac-sti.o obj-$(CONFIG_DWMAC_STM32) += dwmac-stm32.o diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file mode 100644 index 000000000000..a4997cc0294a --- /dev/null +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Sophgo DWMAC platform driver + * + * Copyright (C) 2024 Inochi Amaoto + */ + +#include +#include +#include +#include + +#include "stmmac_platform.h" + +struct sophgo_dwmac { + struct device *dev; + struct clk *clk_tx; +}; + +static void sophgo_dwmac_fix_mac_speed(void *priv, unsigned int speed, unsigned int mode) +{ + struct sophgo_dwmac *dwmac = priv; + long rate; + int ret; + + rate = rgmii_clock(speed); + if (rate < 0) { + dev_err(dwmac->dev, "invalid speed %u\n", speed); + return; + } + + ret = clk_set_rate(dwmac->clk_tx, rate); + if (ret) + dev_err(dwmac->dev, "failed to set tx rate %lu: %pe\n", + rate, ERR_PTR(ret)); +} + +static int sophgo_sg2044_dwmac_init(struct platform_device *pdev, + struct plat_stmmacenet_data *plat_dat, + struct stmmac_resources *stmmac_res) +{ + struct sophgo_dwmac *dwmac; + + dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); + if (!dwmac) + return -ENOMEM; + + dwmac->clk_tx = devm_clk_get_enabled(&pdev->dev, "tx"); + if (IS_ERR(dwmac->clk_tx)) + return dev_err_probe(&pdev->dev, PTR_ERR(dwmac->clk_tx), + "failed to get tx clock\n"); + + dwmac->dev = &pdev->dev; + plat_dat->bsp_priv = dwmac; + plat_dat->flags |= STMMAC_FLAG_SPH_DISABLE; + plat_dat->fix_mac_speed = sophgo_dwmac_fix_mac_speed; + plat_dat->multicast_filter_bins = 0; + plat_dat->unicast_filter_entries = 1; + + return 0; +} + +static int sophgo_dwmac_probe(struct platform_device *pdev) +{ + struct plat_stmmacenet_data *plat_dat; + struct stmmac_resources stmmac_res; + int ret; + + ret = stmmac_get_platform_resources(pdev, &stmmac_res); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "failed to get resources\n"); + + plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac); + if (IS_ERR(plat_dat)) + return dev_err_probe(&pdev->dev, PTR_ERR(plat_dat), + "dt configuration failed\n"); + + ret = sophgo_sg2044_dwmac_init(pdev, plat_dat, &stmmac_res); + if (ret) + return ret; + + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); +} + +static const struct of_device_id sophgo_dwmac_match[] = { + { .compatible = "sophgo,sg2044-dwmac" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, sophgo_dwmac_match); + +static struct platform_driver sophgo_dwmac_driver = { + .probe = sophgo_dwmac_probe, + .remove = stmmac_pltfr_remove, + .driver = { + .name = "sophgo-dwmac", + .pm = &stmmac_pltfr_pm_ops, + .of_match_table = sophgo_dwmac_match, + }, +}; +module_platform_driver(sophgo_dwmac_driver); + +MODULE_AUTHOR("Inochi Amaoto "); +MODULE_DESCRIPTION("Sophgo DWMAC platform driver"); +MODULE_LICENSE("GPL");