]> www.infradead.org Git - users/hch/misc.git/commitdiff
net: stmmac: Add glue layer for Sophgo SG2044 SoC
authorInochi Amaoto <inochiama@gmail.com>
Fri, 7 Mar 2025 01:16:17 +0000 (09:16 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 8 Mar 2025 03:06:36 +0000 (19:06 -0800)
Adds Sophgo dwmac driver support on the Sophgo SG2044 SoC.

Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/20250307011623.440792-5-inochiama@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/stmicro/stmmac/Kconfig
drivers/net/ethernet/stmicro/stmmac/Makefile
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c [new file with mode: 0644]

index c5f94a67b3f2fdea1a74cafc0c6d52c51a3cccb6..3c820ef5677595e2b5c65274ab50b4bdcffec3e2 100644 (file)
@@ -181,6 +181,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)
index b26f0e79c2b3214c6f606b06c7f1bfa449d90ba6..594883fb416449b07531eca699275b629b699dc6 100644 (file)
@@ -24,6 +24,7 @@ obj-$(CONFIG_DWMAC_ROCKCHIP)  += dwmac-rk.o
 obj-$(CONFIG_DWMAC_RZN1)       += dwmac-rzn1.o
 obj-$(CONFIG_DWMAC_S32)                += dwmac-s32.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 (file)
index 0000000..3303784
--- /dev/null
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Sophgo DWMAC platform driver
+ *
+ * Copyright (C) 2024 Inochi Amaoto <inochiama@gmail.com>
+ */
+
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+
+#include "stmmac_platform.h"
+
+static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
+                                   struct plat_stmmacenet_data *plat_dat,
+                                   struct stmmac_resources *stmmac_res)
+{
+       plat_dat->clk_tx_i = devm_clk_get_enabled(&pdev->dev, "tx");
+       if (IS_ERR(plat_dat->clk_tx_i))
+               return dev_err_probe(&pdev->dev, PTR_ERR(plat_dat->clk_tx_i),
+                                    "failed to get tx clock\n");
+
+       plat_dat->flags |= STMMAC_FLAG_SPH_DISABLE;
+       plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
+       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;
+       struct device *dev = &pdev->dev;
+       int ret;
+
+       ret = stmmac_get_platform_resources(pdev, &stmmac_res);
+       if (ret)
+               return dev_err_probe(dev, ret,
+                                    "failed to get platform resources\n");
+
+       plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
+       if (IS_ERR(plat_dat))
+               return dev_err_probe(dev, PTR_ERR(plat_dat),
+                                    "failed to parse DT parameters\n");
+
+       ret = sophgo_sg2044_dwmac_init(pdev, plat_dat, &stmmac_res);
+       if (ret)
+               return ret;
+
+       return stmmac_dvr_probe(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 <inochiama@gmail.com>");
+MODULE_DESCRIPTION("Sophgo DWMAC platform driver");
+MODULE_LICENSE("GPL");