From patchwork Mon Oct 21 10:36:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inochi Amaoto X-Patchwork-Id: 13843899 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 35006D0E6F0 for ; Mon, 21 Oct 2024 10:44:29 +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=Q+EIGr2EEBuuitvEv2VrHgYjdDVHee41rqUgshPB5Ls=; b=EUTt7hWatEBFXl PBidUMPk1PRkDrU1uWZbkUAv2wF7RUhqKrN34hvIFKjDXynOW1WTpIMkef8DYoUnjQ6kA8xSg//B0 Q2QqnwmDzyUQV4Z1eX2SeanEAuIkSE060IjxZbHoVhdhz6aMHQS6mOEV632PEElTLRyGhgBQkvRxW +AI/z9nPZldQSdpUso0CrAKsUuWCZHhHpRDSTA5KBEUz47qsAtaI4sBnKnM1zXKe5VSGSoCh31BnF OIVjTQqLi5YrlJ2or849DO57UvLRVISay34B1Swl2Fql8rPlqZylB7mJJs4X5WrgB51Q1m5o5f8nI 2wFNwp+ykOEYkuYIu89g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t2ptg-00000006vuS-0waZ; Mon, 21 Oct 2024 10:44:24 +0000 Received: from mail-yb1-xb36.google.com ([2607:f8b0:4864:20::b36]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t2pmV-00000006uWF-1uC8; Mon, 21 Oct 2024 10:37:00 +0000 Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-e2974743675so3779566276.1; Mon, 21 Oct 2024 03:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729507017; x=1730111817; 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=svclsiCEeUb5+9t03qJl3db9yymwfO2bBzTcRxMC9P8=; b=J/ZR0CwmZ/QW+Ubkdi7ijlpa+qgzUbQmvB0+icjS+zfxELTR2k6uyUixqnfHl5TPR8 YPJayjqRERa5M87j2Ew//CuT9rrpsSstB5LZl9f4yRT6YZRqRlp3efLnWAOFjESDZ453 W2KboZ6t0LTffZwidkvPTpaLpdtvE0dRDnkh79OGko39t6yPHJUww8buZ198aVkG/Fvw k7ULAGrXCa8uLLlhwGySNdObtD3E7cOIFwtor7K4PF4s1cedQlzLN92y/uSXu0g0IHTT O25xFp/xrnJy0Ks/sTsJAV6zz1Q13OoCgvib9oVMcY5Otk+oI/Inr40PN4TIZroKP46A ex9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729507017; x=1730111817; 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=svclsiCEeUb5+9t03qJl3db9yymwfO2bBzTcRxMC9P8=; b=f3zicsqHX0nItH+qvwoC+PRbrlBuaiGqtJDslA41JJnTpP7Ydi+/Ut9gMKSqCxGeOP PeNx7oZLde5mz6QZUb+JzwdQCQ8KkeFKDiCmJBtuVjCwdaSqhvOF74tGSv3OThtdJJio K9Pg4SQxMra28SSBn47mSMGpPoaZHf31zhwZ/KNEX2Bb7L55en8JDOJGgf2Vxog5JH7g UkCRyT+6grJaw4/7sk+3m3MppcDPlPAkKFXiM2IV4ZW7uAmd9yH5PAA38sgczbBGom1l zgkGnMd9zww0+QFZSx16H4KMTP81GNsUOQqs2F8+dhjJyOU+bkzrlm9ahKL80cvO0kc+ a0hQ== X-Forwarded-Encrypted: i=1; AJvYcCVeWZjrMbIRLBji8q8JcTs1DmjS/ASzScpnqZ3b5pCfiRaOw6H9YoMr3IuDcQpIDF2WuHucrrAsddNeQLs=@lists.infradead.org, AJvYcCXDWGgBltQ8SpO21Z1AEgM36wElvzbh9YOkniIKP2C5jzHY0GY/3VIooaosqA2QjU99QE6MAKI0TQZbHJhwBgTp@lists.infradead.org X-Gm-Message-State: AOJu0Ywuy9MM1KdXQQgIaChz8PMzDUIhfhluVq2BhpHgcHbWD73THfk6 FnYI7GBsis0QLmHi3vrDOXXuKO7tlpJHMcIUEow6Fclb1akKmjAD X-Google-Smtp-Source: AGHT+IHlrA+/dcj1vd4lrPU9QHu+0p+ysA9RIWhCRIkhzXUN8cuwR3GxzlOFB2/p619LdCBVuIUTOA== X-Received: by 2002:a05:6902:1b8b:b0:e29:1572:6d03 with SMTP id 3f1490d57ef6-e2bb16cf119mr9061983276.47.1729507015417; Mon, 21 Oct 2024 03:36:55 -0700 (PDT) Received: from localhost ([2001:da8:7001:11::cb]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaeabd8dc8sm2772799a12.77.2024.10.21.03.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 03:36:55 -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 , 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 4/4] net: stmmac: Add glue layer for Sophgo SG2044 SoC Date: Mon, 21 Oct 2024 18:36:17 +0800 Message-ID: <20241021103617.653386-5-inochiama@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241021103617.653386-1-inochiama@gmail.com> References: <20241021103617.653386-1-inochiama@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_033659_517500_180C0437 X-CRM114-Status: GOOD ( 22.50 ) 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 | 132 ++++++++++++++++++ 3 files changed, 144 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..83c67c061182 --- /dev/null +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Sophgo DWMAC platform driver + * + * Copyright (C) 2024 Inochi Amaoto + * + */ + +#include +#include +#include +#include +#include +#include + +#include "stmmac_platform.h" + +struct sophgo_dwmac { + struct device *dev; + struct clk *clk_tx; +}; + +#define DWMAC_SG2044_FLAG_USE_RX_DELAY BIT(16) + +static void sophgo_dwmac_fix_mac_speed(void *priv, unsigned int speed, unsigned int mode) +{ + struct sophgo_dwmac *dwmac = priv; + unsigned long rate; + int ret; + + switch (speed) { + case SPEED_1000: + rate = 125000000; + break; + case SPEED_100: + rate = 25000000; + break; + case SPEED_10: + rate = 2500000; + break; + default: + dev_err(dwmac->dev, "invalid speed %u\n", speed); + break; + } + + ret = clk_set_rate(dwmac->clk_tx, rate); + if (ret) + dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate); +} + +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; + struct regmap *regmap; + unsigned int args[2]; + int ret; + + 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"); + + regmap = syscon_regmap_lookup_by_phandle_args(pdev->dev.of_node, + "sophgo,syscon", + 2, args); + if (IS_ERR(regmap)) + return dev_err_probe(&pdev->dev, PTR_ERR(regmap), + "failed to get the regmap\n"); + + ret = regmap_set_bits(regmap, args[0], DWMAC_SG2044_FLAG_USE_RX_DELAY); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "failed to set the phy rx delay\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_new = 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_LICENSE("GPL"); +MODULE_DESCRIPTION("Sophgo DWMAC platform driver");