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: 13858602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9B48E67492 for ; Fri, 1 Nov 2024 01:50:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Xs2OmO5iVDrEfRJx9qSK0F7xo3LL9kb39GgX4OtRNiM=; b=Wg7MMBTgGTKLuv jn4z242ZJlnNEft9D6mqtbGY1NwFzQg9lgC8aXxc/+7Kl/D96wQGykA2SOV7GBGhrU65xkHs2eGPv hFwSbCQSo/bx8ksXRcHqQIWquKX21Y4RkQbevlOhz9qAFVPukFmtgX6sVOBVz7p7ONEvAW0vR98ZV 4k7uvBs71ytsJjL5FQ0j20A748GTx4jMkP8aCANwu9EFz4ys9DYUl+St013M22UJ0VXcEsGkgEXbf ASS5WE+mfNgLxuewv9JynIePyqVzpEYXQzy7DdX20GxGIHxWodWCnGMRCFlEZD34bJlJ3IyLLcZ3v uPOusffTFtCSjZGn4bOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t6goL-00000005Tgr-1wtZ; Fri, 01 Nov 2024 01:50:49 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t6ghq-00000005SMr-0Loz; Fri, 01 Nov 2024 01:44:07 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-7eab7622b61so1237626a12.1; 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=lists.infradead.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=WMBMJnDyQ/9062fWB4gOH5fh6BFQzgLqPmYQpRnw/CTH6S/zLcQwJlGUA9OIRjBajk 8Hhx/fmYjMdyv/vv8B6+n/Mgh1ns+6BU8lf7JE6PGCke8TdCYy/SwOWCoeHK8Q1E8Nn7 yqGK9T/9ilBO/pDhiNx8VvXkcqswKyGYGPVaUUwLXGkLYZugcdhRadmjHvIkhw1o3W+6 WWQfTuvGBOIEntchL54re91xNpgl1PhBOPJGppSJ9Kl6g7wQ6hegiPLODt6IxP2+Nqrk lK1axB9gImFqjInwyp+Olalvp6kUlutdy5VGP4d7DYg6Id8hC65I91Bwwc5G5UyK891l 3GPA== 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=sCtOGFhCZ7Szm3ZF36W/dEJrd+LiMgfffo0NW8K6H8Ipg2S4eIfwuTNq1sip0/0ip3 e7tLRjC3f/N7h2wZr1L4qD5kqj6ayZ4g9ug0C/5reMR+xD3uKvpHwUCraQOsxxxvbZR/ QM2zMhbN3VBwhmId9QWR764kkv1PT8iw6BDIQ7uXPawoIM0rIokqwSVrj3GoT8+dGYxS YFwHoqUVRO8gOukqGEXCVqq9KiYxWHJc0PS5BvOqfqThEWvg+zTBDF+aWyl9PRgCyYHk 9w+uRATNpcFO5+62UCikrze2/z00sXFsxvAKvZID0KdsENnc1mD6I8bxgKJs83a5WMww h3LA== X-Forwarded-Encrypted: i=1; AJvYcCWIcPMkL7A+DzVpmqhUv3ljrURfGUgn7OPcJNygLISNWAfmy5uKJnFFEdFFT0fMHYduOe077hEL9A7AR60=@lists.infradead.org, AJvYcCWfsOLQarixlswfHQ9O+C8vQTJI+Uc7gB2V5/JMzU/2BzsmlmQ7vwkzqFTnp3lHEXFmX7v7dTOekrJFbH/qiwQn@lists.infradead.org X-Gm-Message-State: AOJu0YyIvmZUxNbcGtcoeyiqwYQAh/f5ssGPPNzV/133M51owho4JcfG Zzx5IdIKq24NqA++v2Yb8US2lb/OT36L7l+XIH+vdjV0SzQWlN1/ 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241031_184406_711864_6E64A5E3 X-CRM114-Status: GOOD ( 21.69 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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");