riscv: sophgo: Add ethernet support for SG2044
Subsystems (7)
Inochi Amaoto
maintainerv4 cover riscv: sophgo: Add ethernet support for SG2044
The ethernet controller of SG2044 is Synopsys DesignWare IP with custom clock. Add glue layer for it.
Changed from v3:
- https://lore.kernel.org/netdev/[email protected]/
1. rebase for 6.14.rc1
2. remove the dependency requirement as it was already merged into master.
Changed from RFC:
- https://lore.kernel.org/netdev/[email protected]/
1. patch 1: apply Krzysztof' tag
Changed from v2:
- https://lore.kernel.org/netdev/[email protected]/
1. patch 1: merge the first and the second bindings patch to show the all compatible change.
2. patch 2: use of_device_compatible_match helper function to perform check.
2. patch 3: remove unused include and sort the left.
3. patch 3: fix wrong variable usage in sophgo_dwmac_fix_mac_speed
4. patch 3: drop unused variable in the patch.
Changed from v1:
- https://lore.kernel.org/netdev/[email protected]/
1. patch 2: remove sophgo,syscon as this mac delay is resolved.
2. patch 2: apply all the properties unconditionally.
3. patch 4: remove sophgo,syscon code as this mac delay is resolved.
4. patch 4: use the helper function to compute rgmii clock.
5. patch 4: use remove instead of remove_new for the platform driver.
Inochi Amaoto (3):
dt-bindings: net: Add support for Sophgo SG2044 dwmac
net: stmmac: platform: Add snps,dwmac-5.30a IP compatible string
net: stmmac: Add glue layer for Sophgo SG2044 SoC
.../devicetree/bindings/net/snps,dwmac.yaml | 4 + .../bindings/net/sophgo,sg2044-dwmac.yaml | 124 ++++++++++++++++++ drivers/net/ethernet/stmicro/stmmac/Kconfig | 11 ++ drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../ethernet/stmicro/stmmac/dwmac-sophgo.c | 105 +++++++++++++++ .../ethernet/stmicro/stmmac/stmmac_platform.c | 17 ++- 6 files changed, 257 insertions(+), 5 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
--
2.48.1
Inochi Amaoto
maintainerPATCH v4 1/3 dt-bindings: net: Add support for Sophgo SG2044 dwmac
The GMAC IP on SG2044 is almost a standard Synopsys DesignWare MAC (version 5.30a) with some extra clock.
Add necessary compatible string for this device.
--- .../devicetree/bindings/net/snps,dwmac.yaml | 4 + .../bindings/net/sophgo,sg2044-dwmac.yaml | 124 ++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml
Documentation/devicetree/bindings/net/snps,dwmac.yaml +4 -0
@@ -32,6 +32,7 @@ select: - snps,dwmac-4.20a - snps,dwmac-5.10a - snps,dwmac-5.20 + - snps,dwmac-5.30a - snps,dwxgmac - snps,dwxgmac-2.10
@@ -98,8 +99,10 @@ properties: - snps,dwmac-4.20a - snps,dwmac-5.10a - snps,dwmac-5.20 + - snps,dwmac-5.30a - snps,dwxgmac - snps,dwxgmac-2.10 + - sophgo,sg2044-dwmac - starfive,jh7100-dwmac - starfive,jh7110-dwmac - thead,th1520-gmac
@@ -631,6 +634,7 @@ allOf: - snps,dwmac-4.20a - snps,dwmac-5.10a - snps,dwmac-5.20 + - snps,dwmac-5.30a - snps,dwxgmac - snps,dwxgmac-2.10 - st,spear600-gmac
Documentation/devicetree/bindings/net/sophgo,sg2044-dwmac.yaml new file +124 -0
124 lines not on this page · raw message
Signature · 1 line
2.48.1
Inochi Amaoto
maintainerPATCH v4 2/3 net: stmmac: platform: Add snps,dwmac-5.30a IP compatible string
In reply to Inochi AmaotoAdd "snps,dwmac-5.30a" compatible string for 5.30a version that can avoid to define some platform data in the glue layer.
--- .../ethernet/stmicro/stmmac/stmmac_platform.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +12 -5
@@ -405,6 +405,17 @@ static int stmmac_of_get_mac_mode(struct device_node *np)return -ENODEV ; } +/* Compatible string array for all gmac4 devices */ +static const char *const stmmac_gmac4_compats[] = { +"snps,dwmac-4.00" , +"snps,dwmac-4.10a" , +"snps,dwmac-4.20a" , +"snps,dwmac-5.10a" , +"snps,dwmac-5.20" , +"snps,dwmac-5.30a" , +NULL +}; +/** * stmmac_probe_config_dt - parse device-tree driver parameters * @pdev: platform_device structure
@@ -538,11 +549,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac) plat->pmt =1 ; } -if (of_device_is_compatible (np,"snps,dwmac-4.00" ) || -of_device_is_compatible (np,"snps,dwmac-4.10a" ) || -of_device_is_compatible (np,"snps,dwmac-4.20a" ) || -of_device_is_compatible (np,"snps,dwmac-5.10a" ) || -of_device_is_compatible (np,"snps,dwmac-5.20" )) { +if (of_device_compatible_match (np, stmmac_gmac4_compats)) { plat->has_gmac4 =1 ; plat->has_gmac =0 ; plat->pmt =1 ;
Signature · 1 line
2.48.1
Re: [PATCH net-next v4 2/3] net: stmmac: platform: Add snps,dwmac-5.30a IP compatible string
Quoted 34 lines · On dimanche 9 février 2025 02:30:51 heure normale d’Europe centrale Inochi…
Add "snps,dwmac-5.30a" compatible string for 5.30a version that can avoid to define some platform data in the glue layer.
Signed-off-by Inochi Amaoto <[email protected]>--- .../ethernet/stmicro/stmmac/stmmac_platform.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)(quoted diff) +0
-0
b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.cindexd0e61aa1a495..8dc3bd6946c6100644drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +11
-0@@ -405,6 +405,17 @@ static int stmmac_of_get_mac_mode(struct device_node *np) return -ENODEV; } +/* Compatible string array for all gmac4 devices */ +static const char *const stmmac_gmac4_compats[] = { +"snps,dwmac-4.00" , +"snps,dwmac-4.10a" , +"snps,dwmac-4.20a" , +"snps,dwmac-5.10a" , +"snps,dwmac-5.20" , +"snps,dwmac-5.30a" , +NULL +}; +/** * stmmac_probe_config_dt - parse device-tree driver parameters * @pdev: platform_device structure @@ -538,11 +549,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac) plat->pmt = 1; }
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c stmmac_probe_config_dt(struct platform_device *pdev, u8 · line 555
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +1
-5-if (of_device_is_compatible (np,"snps,dwmac-4.00" ) || -of_device_is_compatible (np,"snps,dwmac-4.10a" ) || -of_device_is_compatible (np,"snps,dwmac-4.20a" ) || -of_device_is_compatible (np,"snps,dwmac-5.10a" ) || -of_device_is_compatible (np,"snps,dwmac-5.20" )) { +if (of_device_compatible_match (np, stmmac_gmac4_compats)) { plat->has_gmac4 =1 ; plat->has_gmac =0 ; plat->pmt =1 ;
LGTM
Inochi Amaoto
maintainerPATCH v4 3/3 net: stmmac: Add glue layer for Sophgo SG2044 SoC
In reply to Inochi AmaotoAdds Sophgo dwmac driver support on the Sophgo SG2044 SoC.
--- 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
drivers/net/ethernet/stmicro/stmmac/Kconfig +11 -0
@@ -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)
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
@@ -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
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH net-next v4 3/3] net: stmmac: Add glue layer for Sophgo SG2044 SoC
Hello Inochi,
Quoted 1 line · On dimanche 9 février 2025 02:30:52 heure normale d’Europe centrale Inochi…
Adds Sophgo dwmac driver support on the Sophgo SG2044 SoC.
...
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 8
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +8
-0@@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Sophgo DWMAC platform driver +* +* Copyright (C) 2024 Inochi Amaoto <[email protected]> +*/ + +#include <linux/bits.h>
It doesn't look like this include is used, could you please remove it?
Quoted 16 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +12
-0+#include <linux/mod_devicetable.h> +#include <linux/phy.h> +#include <linux/platform_device.h> + +#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) +{
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +3
-0+struct sophgo_dwmac *dwmac = priv; +long rate; +int ret;
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 34
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +10
-0+ + 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",
nit: shouldn't this be "%ld"?
Quoted 22 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +22
-0+ 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;
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 66
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +10
-0+ 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;
nit: I think adding "struct device *dev = &pdev->dev;" here would be better than repeating "&pdev->dev" later on.
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 72
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +6
-0+int ret; + + ret =stmmac_get_platform_resources (pdev, &stmmac_res); +if (ret) +return dev_err_probe (&pdev->dev, ret, +"failed to get resources\n" );
This error message is a bit too vague, maybe replace it with "failed to get platform resources"?
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 77
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +5
-0+ + 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" );
This error message is a bit misleading IMO, I would replace it with something like "failed to parse device-tree parameters".
Quoted 18 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +18
-0+ + 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 = {
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 105
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +10
-0+ .name = "sophgo-dwmac", + .pm = &stmmac_pltfr_pm_ops, + .of_match_table = sophgo_dwmac_match, + }, +}; +module_platform_driver (sophgo_dwmac_driver); + +MODULE_AUTHOR ("Inochi Amaoto <[email protected]>" ); +MODULE_DESCRIPTION ("Sophgo DWMAC platform driver" ); +MODULE_LICENSE ("GPL" );
Thanks,
Signature · 3 lines
Romain Gantois, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Inochi Amaoto
maintainerRe: [PATCH net-next v4 3/3] net: stmmac: Add glue layer for Sophgo SG2044 SoC
Quoted 6 lines · Romain Gantois
Hello Inochi,
Quoted 1 line · On dimanche 9 février 2025 02:30:52 heure normale d’Europe centrale Inochi…
Adds Sophgo dwmac driver support on the Sophgo SG2044 SoC.
...
Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 8
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +8
-0@@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Sophgo DWMAC platform driver +* +* Copyright (C) 2024 Inochi Amaoto <[email protected]> +*/ + +#include <linux/bits.h> It doesn't look like this include is used, could you please remove it?
Thanks, I will. And I will add the miss headerlinux/clk.h and linux/module.h.
Quoted 20 lines
Quoted 20 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +12
-0+#include <linux/mod_devicetable.h> +#include <linux/phy.h> +#include <linux/platform_device.h> + +#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) +{
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +7
-0+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);
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 34
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +6
-0+return ; + } + + ret =clk_set_rate (dwmac->clk_tx, rate); +if (ret) + dev_err(dwmac->dev, "failed to set tx rate %lu: %pe\n",nit: shouldn't this be "%ld"?
Yeah, it is my mistake, I will fix it.
Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +27
-0+ 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 ; +}
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 66
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +5
-0+ +static int sophgo_dwmac_probe (struct platform_device *pdev) +{ +struct plat_stmmacenet_data *plat_dat; +struct stmmac_resources stmmac_res;nit: I think adding "struct device *dev =
&pdev->dev;" here would be better than repeating "&pdev->dev" later on.
Thanks, I will change that.
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 72
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +6
-0+int ret; + + ret =stmmac_get_platform_resources (pdev, &stmmac_res); +if (ret) +return dev_err_probe (&pdev->dev, ret, +"failed to get resources\n" );This error message is a bit too vague, maybe replace it with "failed to get platform resources"?
OK.
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 77
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +5
-0+ + 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" );This error message is a bit misleading IMO, I would replace it with something like "failed to parse device-tree parameters".
OK.
Quoted 35 lines
Quoted 18 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +18
-0+ + 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 = {drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c line 105
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c new file +10
-0+ .name = "sophgo-dwmac", + .pm = &stmmac_pltfr_pm_ops, + .of_match_table = sophgo_dwmac_match, + }, +}; +module_platform_driver (sophgo_dwmac_driver); + +MODULE_AUTHOR ("Inochi Amaoto <[email protected]>" ); +MODULE_DESCRIPTION ("Sophgo DWMAC platform driver" ); +MODULE_LICENSE ("GPL" );Thanks,
Signature · 3 lines
Romain Gantois, Bootlin Embedded Linux and Kernel engineering https://bootlin.com