riscv: spacemit: Add ethernet support for K3
Subsystems (8)
Inochi Amaoto
maintainercover riscv: spacemit: Add ethernet support for K3
Add initial support for ethernet controller of the Spacemit K3 SoC. This ethernet controller is almost a standard Synopsys DesignWare MAC (version 5.40a). This controller require a syscon device to configure some basic features, like interface type and internal delay.
Inochi Amaoto (3):
dt-bindings: net: Add support for Spacemit K3 dwmac
net: stmmac: platform: Add snps,dwmac-5.40a IP compatible string
net: stmmac: Add glue layer for Spacemit K3 SoC
.../devicetree/bindings/net/snps,dwmac.yaml | 3 + .../bindings/net/spacemit,k3-dwmac.yaml | 107 +++++++++ drivers/net/ethernet/stmicro/stmmac/Kconfig | 12 + drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../ethernet/stmicro/stmmac/dwmac-spacemit.c | 224 ++++++++++++++++++ .../ethernet/stmicro/stmmac/stmmac_platform.c | 1 + 6 files changed, 348 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c
--
2.52.0
Inochi Amaoto
maintainerPATCH 2/3 net: stmmac: platform: Add snps,dwmac-5.40a IP compatible string
Add compatible string for 5.40a version that can avoid to define some platform data in the glue layer.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +1 -0
@@ -396,6 +396,7 @@ static const char * const stmmac_gmac4_compats[] = {"snps,dwmac-5.10a" ,"snps,dwmac-5.20" ,"snps,dwmac-5.30a" , +"snps,dwmac-5.40a" , NULL };
Signature · 1 line
2.52.0
Inochi Amaoto
maintainerPATCH 3/3 net: stmmac: Add glue layer for Spacemit K3 SoC
In reply to Inochi AmaotoAdds Spacemit dwmac driver support on the Spacemit K3 SoC.
--- drivers/net/ethernet/stmicro/stmmac/Kconfig | 12 + drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../ethernet/stmicro/stmmac/dwmac-spacemit.c | 224 ++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c
drivers/net/ethernet/stmicro/stmmac/Kconfig +12 -0
@@ -216,6 +216,18 @@ config DWMAC_SOPHGO for the stmmac device driver. This driver is used for the ethernet controllers on various Sophgo SoCs. +config DWMAC_SPACEMIT + tristate "Spacemit dwmac support" + depends on OF && (ARCH_SPACEMIT || COMPILE_TEST) + select MFD_SYSCON + default m if ARCH_SPACEMIT + help + Support for ethernet controllers on Spacemit RISC-V SoCs + + This selects the Spacemit platform specific glue layer support + for the stmmac device driver. This driver is used for the + Spacemit K3 ethernet controllers. + config DWMAC_STARFIVE tristate "StarFive dwmac support" depends on OF && (ARCH_STARFIVE || COMPILE_TEST)
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
@@ -27,6 +27,7 @@ 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_SPACEMIT) += dwmac-spacemit.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-spacemit.c new file +224 -0
224 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
Quoted 1 line · Inochi Amaoto
Adds Spacemit dwmac driver support on the Spacemit K3 SoC.
Some more information would be useful. E.g. describing why you need to fix the RGMII mode.
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +11
-0+/* ctrl register bits */ +#define PHY_INTF_RGMII BIT(3) +#define PHY_INTF_MII BIT(4) + +#define WAKE_IRQ_EN BIT(9) +#define PHY_IRQ_EN BIT(12) + +/* dline register bits */ +#define RGMII_RX_DLINE_EN BIT(0) +#define RGMII_RX_DLINE_STEP GENMASK(5, 4) +#define RGMII_RX_DLINE_CODE GENMASK(15, 8)
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 40
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +10
-0+#define RGMII_TX_DLINE_EN BIT(16) +#define RGMII_TX_DLINE_STEP GENMASK(21, 20) +#define RGMII_TX_DLINE_CODE GENMASK(31, 24) + +#define MAX_DLINE_DELAY_CODE 0xff + +struct spacemit_dwmac { +struct device *dev; +struct clk *tx; +};
This structure seems unused.
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +9
-0+ +/* Note: the delay step value is at 0.1ps */ +static const unsigned int k3_delay_step_10x[4 ] = { +367 ,493 ,559 ,685 +}; + +static int spacemit_dwmac_set_delay(struct regmap *apmu, + unsigned int dline_offset, + unsigned int tx_code, unsigned int tx_config,
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 59
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +10
-0+ unsigned int rx_code, unsigned int rx_config) +{ + unsigned int mask, val; + + mask =RGMII_RX_DLINE_STEP |RGMII_TX_DLINE_CODE |RGMII_TX_DLINE_EN | +RGMII_TX_DLINE_STEP |RGMII_RX_DLINE_CODE |RGMII_RX_DLINE_EN ; + val =FIELD_PREP (RGMII_TX_DLINE_CODE , tx_config) | +FIELD_PREP (RGMII_TX_DLINE_CODE , tx_code) |RGMII_TX_DLINE_EN | +FIELD_PREP (RGMII_TX_DLINE_CODE , rx_config) | +FIELD_PREP (RGMII_RX_DLINE_CODE , rx_code) |RGMII_RX_DLINE_EN ;
These FIELD_PREP() fields look wrong. Did you mean to use DLINE_CODE both tx_config and tx_code, and did you mean to use TX_DLINE_CODE for rx_config ?
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 183
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+ 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" );
You set plat_dat->clk_tx_i, but you don't point plat_dat->set_clk_tx_rate at anything, which means the stmmac core does nothing with this.
Given the last two points, has RGMII mode been tested on this hardware?
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Inochi Amaoto
maintainerRe: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
Quoted 6 lines · Russell King (Oracle)
Quoted 1 line · Inochi Amaoto
Adds Spacemit dwmac driver support on the Spacemit K3 SoC.
Some more information would be useful. E.g. describing why you need to fix the RGMII mode.
OK. I will add this.
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +15
-0+/* ctrl register bits */ +#define PHY_INTF_RGMII BIT(3) +#define PHY_INTF_MII BIT(4) + +#define WAKE_IRQ_EN BIT(9) +#define PHY_IRQ_EN BIT(12) + +/* dline register bits */ +#define RGMII_RX_DLINE_EN BIT(0) +#define RGMII_RX_DLINE_STEP GENMASK(5, 4) +#define RGMII_RX_DLINE_CODE GENMASK(15, 8) +#define RGMII_TX_DLINE_EN BIT(16) +#define RGMII_TX_DLINE_STEP GENMASK(21, 20) +#define RGMII_TX_DLINE_CODE GENMASK(31, 24) +
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 40
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +6
-0+#define MAX_DLINE_DELAY_CODE 0xff + +struct spacemit_dwmac { +struct device *dev; +struct clk *tx; +};This structure seems unused.
Yeah, I forgot this, will remove in the next version.
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +15
-0+ +/* Note: the delay step value is at 0.1ps */ +static const unsigned int k3_delay_step_10x[4 ] = { +367 ,493 ,559 ,685 +}; + +static int spacemit_dwmac_set_delay (struct regmap *apmu, +unsigned int dline_offset, +unsigned int tx_code,unsigned int tx_config, +unsigned int rx_code,unsigned int rx_config) +{ +unsigned int mask, val; + + mask =RGMII_RX_DLINE_STEP |RGMII_TX_DLINE_CODE |RGMII_TX_DLINE_EN | +RGMII_TX_DLINE_STEP |RGMII_RX_DLINE_CODE |RGMII_RX_DLINE_EN ;
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 59
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+ val =FIELD_PREP (RGMII_TX_DLINE_CODE , tx_config) | +FIELD_PREP (RGMII_TX_DLINE_CODE , tx_code) |RGMII_TX_DLINE_EN | +FIELD_PREP (RGMII_TX_DLINE_CODE , rx_config) | +FIELD_PREP (RGMII_RX_DLINE_CODE , rx_code) |RGMII_RX_DLINE_EN ;These
FIELD_PREP()fields look wrong. Did you mean to useDLINE_CODEbothtx_configandtx_code, and did you mean to useTX_DLINE_CODEforrx_config?
This should be RGMII_TX_DLINE_CODE. This is a copy paste error, I will fix it.
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 183
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+ 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" );You set
plat_dat->clk_tx_i, but you don't pointplat_dat->set_clk_tx_rateat anything, which means the stmmac core does nothing with this.
Yes, the vendor told me that the internal tx clock rate will be auto changed when the speed rate is changed. So no software interaction is needed.
Quoted 3 lines
Given the last two points, has RGMII mode been tested on this hardware?
In fact I only tested the rgmii-id, which does not change the internal id. I will try the rgmii mode.
Regards,
Inochi
Inochi Amaoto
maintainerPATCH 1/3 dt-bindings: net: Add support for Spacemit K3 dwmac
In reply to Inochi AmaotoThe GMAC IP on Spacemit K3 is almost a standard Synopsys DesignWare MAC (version 5.40a) with some extra clock.
Add necessary compatible string for this device.
--- .../devicetree/bindings/net/snps,dwmac.yaml | 3 + .../bindings/net/spacemit,k3-dwmac.yaml | 107 ++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml
Documentation/devicetree/bindings/net/snps,dwmac.yaml +3 -0
@@ -34,6 +34,7 @@ select: - snps,dwmac-5.10a - snps,dwmac-5.20 - snps,dwmac-5.30a + - snps,dwmac-5.40a - snps,dwxgmac - snps,dwxgmac-2.10
@@ -108,6 +109,7 @@ properties: - snps,dwmac-5.10a - snps,dwmac-5.20 - snps,dwmac-5.30a + - snps,dwmac-5.40a - snps,dwxgmac - snps,dwxgmac-2.10 - sophgo,sg2042-dwmac
@@ -653,6 +655,7 @@ allOf: - snps,dwmac-5.10a - snps,dwmac-5.20 - snps,dwmac-5.30a + - snps,dwmac-5.40a - snps,dwxgmac - snps,dwxgmac-2.10 - st,spear600-gmac
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml new file +107 -0
107 lines not on this page · raw message
Signature · 7 lines
2.52.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH net-next 1/3] dt-bindings: net: Add support for Spacemit K3 dwmac
Quoted 11 lines · Inochi Amaoto
The GMAC IP on Spacemit K3 is almost a standard Synopsys DesignWare MAC (version 5.40a) with some extra clock.
Add necessary compatible string for this device.
Signed-off-by Inochi Amaoto <[email protected]>--- .../devicetree/bindings/net/snps,dwmac.yaml | 3 + .../bindings/net/spacemit,k3-dwmac.yaml | 107 ++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml
...
Quoted 5 lines
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml new file +0
-0
...
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml line 35
Quoted 7 lines
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml new file +7
-0+ clocks: + minItems: 3 + items: + - description: GMAC main clock + - description: PTP clock + - description: TX clock + - description: PHY clock
Why does the MAC require "phy" clock? Shouldn't this be handled in PHY driver instead, or I get its meaning wrong?
Also, I don't see "phy" clock is acquired anywhere in the driver. Is it really necessary for the MAC?
Best regards,
Yao Zi
Re: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
In reply to Inochi AmaotoQuoted 9 lines · Inochi Amaoto
Adds Spacemit dwmac driver support on the Spacemit K3 SoC.
Signed-off-by Inochi Amaoto <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/Kconfig | 12 + drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../ethernet/stmicro/stmmac/dwmac-spacemit.c | 224 ++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c
...
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +0
-0
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 10
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +10
-0@@ -0,0 +1,224 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Spacemit DWMAC platform driver +* +* Copyright (C) 2026 Inochi Amaoto <[email protected]> +*/ + +#include <linux/clk.h> +#include <linux/mfd/syscon.h> +#include <linux/math.h>
These are the only two headers listed out-of-order. Is this intended?
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +6
-0+#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/property.h> +#include <linux/regmap.h>
...
Quoted 17 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +17
-0+static int spacemit_dwmac_detected_delay_value (unsigned int delay, +unsigned int *config) +{ +int i; +int code, best_code =0 ; +unsigned int best_delay =0 ; +unsigned int best_config =0 ; + +if (delay ==0 ) +return 0 ; + +for (i =0 ; i <ARRAY_SIZE (k3_delay_step_10x); i++) { +unsigned int step = k3_delay_step_10x[i]; + +for (code =1 ; code <=MAX_DLINE_DELAY_CODE ; code++) { +/* +* Note K3 require a specific factor for calculate
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 90
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +10
-0+* the delay, in this scenario it is 0.9. So the +* formula is code * step / 10 * 0.9 +*/ +unsigned int tmp = code * step *9 /10 /10 ; + +if (abs (tmp - delay) <abs (best_delay - delay)) { + best_code = code; + best_delay = tmp; + best_config = i; + }
Is the inner loop really necessary? Could it be replaced by
this_code = DIV_ROUND_CLOSEST(delay * 10 * 10, step * 9); this_delay = this_code * step * 9 / 10 / 10;
Then comparing abs(this_delay - delay) and abs(best_delay - delay)?
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +7
-0+ } + } + + *config = best_config; + +return best_code; +}
...
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 137
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +12
-0+static int spacemit_dwmac_update_ifconfig (struct plat_stmmacenet_data *plat_dat, +struct stmmac_resources *stmmac_res, +struct regmap *apmu, +unsigned int ctrl_offset) +{ +unsigned int mask =PHY_INTF_MII |PHY_INTF_RGMII |WAKE_IRQ_EN ; +unsigned int val =0 ; + +switch (plat_dat->phy_interface) { +case PHY_INTERFACE_MODE_MII : + val |=PHY_INTF_MII ; +break ;
The OR operation seems unnecessary and could be replaced with an assignment. Same for PHY_INTERFACE_MODE_RGMII's case.
Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +14
-0+ +case PHY_INTERFACE_MODE_RMII : +break ; + +case PHY_INTERFACE_MODE_RGMII : +case PHY_INTERFACE_MODE_RGMII_ID : +case PHY_INTERFACE_MODE_RGMII_RXID : +case PHY_INTERFACE_MODE_RGMII_TXID : + val |=PHY_INTF_RGMII ; +break ; + +default : +return -EOPNOTSUPP ; + }
...
Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+static int spacemit_dwmac_probe (struct platform_device *pdev) +{
...
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 196
Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+of_property_read_u32 (pdev->dev.of_node,"tx-internal-delay-ps" , &tx_delay); +of_property_read_u32 (pdev->dev.of_node,"rx-internal-delay-ps" , &rx_delay);
According to of.h, of_property_read_u32, which in turn calls of_property_read_u32_array, could fail with -ENODATA if there's no value associated with the property. Should the case be handled?
Regards,
Yao Zi
Re: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
Quoted 6 lines · Yao Zi
Quoted 2 lines · Inochi Amaoto
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+static int spacemit_dwmac_probe (struct platform_device *pdev) +{...
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 196
Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+of_property_read_u32 (pdev->dev.of_node,"tx-internal-delay-ps" , &tx_delay); +of_property_read_u32 (pdev->dev.of_node,"rx-internal-delay-ps" , &rx_delay);According to
of.h,of_property_read_u32, which in turn callsof_property_read_u32_array, could fail with-ENODATAif there's no value associated with the property. Should the case be handled?
You cut too much. This had:
unsigned int tx_delay = 0; unsigned int rx_delay = 0;
at the start of the function.
of_property_read_u32_array() says:
* @out_values: pointer to return value, modified only if return value is 0.
and of_property_read_u32() passes &tx_delay or &rx_delay to this. Thus, if any error occurs, these will be zero. In other words, a missing property is equivalent to setting these to zero, which is entirely reasonable.
However, "unsigned int" _may_ be type equivalent to "u32", but really these should be "u32" if of_property_read_u32_array() is used.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
In reply to Yao ZiHi Yao,
Quoted 19 lines · Yao Zi
Quoted 9 lines · Inochi Amaoto
Adds Spacemit dwmac driver support on the Spacemit K3 SoC.
Signed-off-by Inochi Amaoto <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/Kconfig | 12 + drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../ethernet/stmicro/stmmac/dwmac-spacemit.c | 224 ++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c...
Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+static int spacemit_dwmac_probe (struct platform_device *pdev) +{...
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 196
Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+of_property_read_u32 (pdev->dev.of_node,"tx-internal-delay-ps" , &tx_delay); +of_property_read_u32 (pdev->dev.of_node,"rx-internal-delay-ps" , &rx_delay);According to
of.h,of_property_read_u32, which in turn callsof_property_read_u32_array, could fail with-ENODATAif there's no value associated with the property. Should the case be handled?
I think it should be safe, see the comment
*
* The out_values is modified only if a valid u64 value can be decoded. */
static inline int of_property_read_u64_array(const struct device_node *np,
const char *propname, u64 *out_values, size_t sz)
{
..
if the function fail then it will use default value which assigned already at initialization stage.
Signature · 1 line
Yixun Lan (dlan)
Inochi Amaoto
maintainerRe: [PATCH net-next 1/3] dt-bindings: net: Add support for Spacemit K3 dwmac
In reply to Yao ZiQuoted 31 lines · Yao Zi
Quoted 11 lines · Inochi Amaoto
The GMAC IP on Spacemit K3 is almost a standard Synopsys DesignWare MAC (version 5.40a) with some extra clock.
Add necessary compatible string for this device.
Signed-off-by Inochi Amaoto <[email protected]>--- .../devicetree/bindings/net/snps,dwmac.yaml | 3 + .../bindings/net/spacemit,k3-dwmac.yaml | 107 ++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml...
Quoted 5 lines
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml new file +0
-0...
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml line 35
Quoted 7 lines
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml new file +7
-0+ clocks: + minItems: 3 + items: + - description: GMAC main clock + - description: PTP clock + - description: TX clock + - description: PHY clock
Quoted 3 lines
Why does the MAC require "phy" clock? Shouldn't this be handled in PHY driver instead, or I get its meaning wrong?
IIRC, the "phy" clock is used to pass the phy from the mac core, I will double check if it is possible to connect to the phy directly.
Quoted 3 lines
Also, I don't see "phy" clock is acquired anywhere in the driver. Is it really necessary for the MAC?
This is a mistake, I remove this by accident, if it is necessary, I will add this in the next version.
Regards,
Inochi
Inochi Amaoto
maintainerRe: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
In reply to Yao ZiQuoted 23 lines · Yao Zi
Quoted 9 lines · Inochi Amaoto
Adds Spacemit dwmac driver support on the Spacemit K3 SoC.
Signed-off-by Inochi Amaoto <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/Kconfig | 12 + drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../ethernet/stmicro/stmmac/dwmac-spacemit.c | 224 ++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c...
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0@@ -0,0 +1,224 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Spacemit DWMAC platform driver +*
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 10
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +6
-0+* Copyright (C) 2026 Inochi Amaoto <[email protected]> +*/ + +#include <linux/clk.h> +#include <linux/mfd/syscon.h> +#include <linux/math.h> These are the only two headers listed out-of-order. Is this intended?
I will fix this.
Quoted 39 lines
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +6
-0+#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/property.h> +#include <linux/regmap.h> ...
Quoted 17 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +17
-0+static int spacemit_dwmac_detected_delay_value (unsigned int delay, +unsigned int *config) +{ +int i; +int code, best_code =0 ; +unsigned int best_delay =0 ; +unsigned int best_config =0 ; + +if (delay ==0 ) +return 0 ; + +for (i =0 ; i <ARRAY_SIZE (k3_delay_step_10x); i++) { +unsigned int step = k3_delay_step_10x[i]; + +for (code =1 ; code <=MAX_DLINE_DELAY_CODE ; code++) { +/* +* Note K3 require a specific factor for calculate drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 90
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +10
-0+* the delay, in this scenario it is 0.9. So the +* formula is code * step / 10 * 0.9 +*/ +unsigned int tmp = code * step *9 /10 /10 ; + +if (abs (tmp - delay) <abs (best_delay - delay)) { + best_code = code; + best_delay = tmp; + best_config = i; + }Is the inner loop really necessary? Could it be replaced by
Quoted 5 lines
this_code = DIV_ROUND_CLOSEST(delay * 10 * 10, step * 9); this_delay = this_code * step * 9 / 10 / 10;Then comparing
abs(this_delay - delay)andabs(best_delay - delay)?
This is a good idea, thanks.
Quoted 10 lines
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +7
-0+ } + } + + *config = best_config; + +return best_code; +}...
Quoted 16 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 137
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +12
-0+static int spacemit_dwmac_update_ifconfig (struct plat_stmmacenet_data *plat_dat, +struct stmmac_resources *stmmac_res, +struct regmap *apmu, +unsigned int ctrl_offset) +{ +unsigned int mask =PHY_INTF_MII |PHY_INTF_RGMII |WAKE_IRQ_EN ; +unsigned int val =0 ; + +switch (plat_dat->phy_interface) { +case PHY_INTERFACE_MODE_MII : + val |=PHY_INTF_MII ; +break ;The OR operation seems unnecessary and could be replaced with an assignment. Same for PHY_INTERFACE_MODE_RGMII's case.
That's tree, an assignment is better than the OR operation, I will change this in the next version.
Quoted 31 lines
Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +14
-0+ +case PHY_INTERFACE_MODE_RMII : +break ; + +case PHY_INTERFACE_MODE_RGMII : +case PHY_INTERFACE_MODE_RGMII_ID : +case PHY_INTERFACE_MODE_RGMII_RXID : +case PHY_INTERFACE_MODE_RGMII_TXID : + val |=PHY_INTF_RGMII ; +break ; + +default : +return -EOPNOTSUPP ; + }...
Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+static int spacemit_dwmac_probe (struct platform_device *pdev) +{...
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 196
Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+of_property_read_u32 (pdev->dev.of_node,"tx-internal-delay-ps" , &tx_delay); +of_property_read_u32 (pdev->dev.of_node,"rx-internal-delay-ps" , &rx_delay);According to
of.h,of_property_read_u32, which in turn callsof_property_read_u32_array, could fail with-ENODATAif there's no value associated with the property. Should the case be handled?Regards,
Yao Zi
Inochi Amaoto
maintainerRe: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
In reply to Russell King (Oracle)Quoted 25 lines · Russell King (Oracle)
Quoted 6 lines · Yao Zi
Quoted 2 lines · Inochi Amaoto
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+static int spacemit_dwmac_probe (struct platform_device *pdev) +{...
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 196
Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +2
-0+of_property_read_u32 (pdev->dev.of_node,"tx-internal-delay-ps" , &tx_delay); +of_property_read_u32 (pdev->dev.of_node,"rx-internal-delay-ps" , &rx_delay);According to
of.h,of_property_read_u32, which in turn callsof_property_read_u32_array, could fail with-ENODATAif there's no value associated with the property. Should the case be handled?You cut too much. This had:
unsigned int tx_delay = 0; unsigned int rx_delay = 0;at the start of the function.
of_property_read_u32_array()says:* @out_values: pointer to return value, modified only if return value is 0.
Quoted 8 lines
and
of_property_read_u32()passes&tx_delayor&rx_delayto this. Thus, if any error occurs, these will be zero. In other words, a missing property is equivalent to setting these to zero, which is entirely reasonable.However, "unsigned int" _may_ be type equivalent to "u32", but really these should be "u32" if
of_property_read_u32_array()is used.
Good catch! I always treat "unsigned int" to "u32" implictly, I will change to u32 for as an precise type.
Regards,
Inochi
Re: [PATCH net-next 1/3] dt-bindings: net: Add support for Spacemit K3 dwmac
In reply to Inochi AmaotoQuoted 2 lines
IIRC, the "phy" clock is used to pass the phy from the mac core, I will double check if it is possible to connect to the phy directly.
Are you saying this is the reference clock output from the MAC being fed to the PHY? That would be a clock provider, not a clock consumer.
Or is it the reference clock output from the PHY going to the MAC? Then the MAC would be a consumer.
And there are some designs which have a third party generate the clock, and both the MAC and the PHY consume it.
Andrew
Re: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
In reply to Inochi Amaotodrivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 45
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+/* Note: the delay step value is at 0.1ps */ +static const unsigned int k3_delay_step_10x[4 ] = { +367 ,493 ,559 ,685 +};
Am i reading it correctly that RGMII delays are limited to these four values?
If so, please add this list to the DT binding.
Quoted 19 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +19
-0+static int spacemit_dwmac_detected_delay_value (unsigned int delay, +unsigned int *config) +{ +int i; +int code, best_code =0 ; +unsigned int best_delay =0 ; +unsigned int best_config =0 ; + +if (delay ==0 ) +return 0 ; + +for (i =0 ; i <ARRAY_SIZE (k3_delay_step_10x); i++) { +unsigned int step = k3_delay_step_10x[i]; + +for (code =1 ; code <=MAX_DLINE_DELAY_CODE ; code++) { +/* +* Note K3 require a specific factor for calculate +* the delay, in this scenario it is 0.9. So the +* formula is code * step / 10 * 0.9
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 92
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +10
-0+*/ +unsigned int tmp = code * step *9 /10 /10 ; + +if (abs (tmp - delay) <abs (best_delay - delay)) { + best_code = code; + best_delay = tmp; + best_config = i; + } + } + }
With the four values listed in DT, i would make this a straight match, not the nearest, and return -EINVAL otherwise.
Andrew
Inochi Amaoto
maintainerRe: [PATCH net-next 1/3] dt-bindings: net: Add support for Spacemit K3 dwmac
In reply to Andrew LunnQuoted 12 lines · Andrew Lunn
Quoted 2 lines
IIRC, the "phy" clock is used to pass the phy from the mac core, I will double check if it is possible to connect to the phy directly.
Are you saying this is the reference clock output from the MAC being fed to the PHY? That would be a clock provider, not a clock consumer.
Or is it the reference clock output from the PHY going to the MAC? Then the MAC would be a consumer.
And there are some designs which have a third party generate the clock, and both the MAC and the PHY consume it.
I have confirmed the clock is directly from the the clock tree and is consumed only by the PHY. It seems like I have got a wrong information about this. So let's remove it and let the phy consume the clock if it use this clock.
Regards,
Inochi
Inochi Amaoto
maintainerRe: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
In reply to Andrew LunnQuoted 10 lines · Andrew Lunn
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 45
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+/* Note: the delay step value is at 0.1ps */ +static const unsigned int k3_delay_step_10x[4 ] = { +367 ,493 ,559 ,685 +};Am i reading it correctly that RGMII delays are limited to these four values?
If so, please add this list to the DT binding.
No, these value are just adjustment interval, and it is also controlled by another code register, the final delay is calculated by the following formula:
delay = delay_step * delay_code * 0.9;
So the delay configuration needs to be calculated instead of directly assigned.
Quoted 33 lines
Quoted 19 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +19
-0+static int spacemit_dwmac_detected_delay_value (unsigned int delay, +unsigned int *config) +{ +int i; +int code, best_code =0 ; +unsigned int best_delay =0 ; +unsigned int best_config =0 ; + +if (delay ==0 ) +return 0 ; + +for (i =0 ; i <ARRAY_SIZE (k3_delay_step_10x); i++) { +unsigned int step = k3_delay_step_10x[i]; + +for (code =1 ; code <=MAX_DLINE_DELAY_CODE ; code++) { +/* +* Note K3 require a specific factor for calculate +* the delay, in this scenario it is 0.9. So the +* formula is code * step / 10 * 0.9 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 92
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +10
-0+*/ +unsigned int tmp = code * step *9 /10 /10 ; + +if (abs (tmp - delay) <abs (best_delay - delay)) { + best_code = code; + best_delay = tmp; + best_config = i; + } + } + }With the four values listed in DT, i would make this a straight match, not the nearest, and return
-EINVALotherwise.
Quoted 1 line
Andrew
Regards,
Inochi
Re: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
Quoted 12 lines · Inochi Amaoto
Quoted 10 lines · Andrew Lunn
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 45
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+/* Note: the delay step value is at 0.1ps */ +static const unsigned int k3_delay_step_10x[4 ] = { +367 ,493 ,559 ,685 +};Am i reading it correctly that RGMII delays are limited to these four values?
If so, please add this list to the DT binding.
Quoted 8 lines
No, these value are just adjustment interval, and it is also controlled by another code register, the final delay is calculated by the following formula:
delay =
delay_step*delay_code* 0.9;So the delay configuration needs to be calculated instead of directly assigned.
O.K.
So what is the actual range? Can is do 1000ps? 2000ps? 3000ps? Should there be a basic range check to avoid dumb typos?
Andrew
Inochi Amaoto
maintainerRe: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
Quoted 19 lines · Andrew Lunn
Quoted 18 lines · Inochi Amaoto
Quoted 10 lines · Andrew Lunn
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 45
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+/* Note: the delay step value is at 0.1ps */ +static const unsigned int k3_delay_step_10x[4 ] = { +367 ,493 ,559 ,685 +};Am i reading it correctly that RGMII delays are limited to these four values?
If so, please add this list to the DT binding.
No, these value are just adjustment interval, and it is also controlled by another code register, the final delay is calculated by the following formula:
delay =
delay_step*delay_code* 0.9;
Quoted 7 lines
Quoted 2 lines
So the delay configuration needs to be calculated instead of directly assigned.
O.K.
So what is the actual range? Can is do 1000ps? 2000ps? 3000ps? Should there be a basic range check to avoid dumb typos?
It can have a pretty big ranges, and I was told the total delay is fine to work between [1200, 2800]. I guess it is fine for us to check the upper limit?
Regards,
Inochi
Re: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
In reply to Inochi AmaotoQuoted 12 lines · Inochi Amaoto
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 59
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +6
-0+ mask =RGMII_RX_DLINE_STEP |RGMII_TX_DLINE_CODE |RGMII_TX_DLINE_EN | +RGMII_TX_DLINE_STEP |RGMII_RX_DLINE_CODE |RGMII_RX_DLINE_EN ; + val =FIELD_PREP (RGMII_TX_DLINE_CODE , tx_config) | +FIELD_PREP (RGMII_TX_DLINE_CODE , tx_code) |RGMII_TX_DLINE_EN | +FIELD_PREP (RGMII_TX_DLINE_CODE , rx_config) | +FIELD_PREP (RGMII_RX_DLINE_CODE , rx_code) |RGMII_RX_DLINE_EN ;These
FIELD_PREP()fields look wrong. Did you mean to useDLINE_CODEbothtx_configandtx_code, and did you mean to useTX_DLINE_CODEforrx_config?
Quoted 2 lines
This should be
RGMII_TX_DLINE_CODE. This is a copy paste error, I will fix it.
Are you sure?
In that case, please change this to:
val = FIELD_PREP(RGMII_TX_DLINE_CODE, tx_config | tx_code |
rx_config | rx_code) |
RGMII_TX_DLINE_EN | RGMII_RX_DLINE_EN;
If that isn't what you meant, then your reply is wrong, and it seems you're confused, which makes me then question how reliable your replies are.
Quoted 10 lines
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 183
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+ 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" );You set
plat_dat->clk_tx_i, but you don't pointplat_dat->set_clk_tx_rateat anything, which means the stmmac core does nothing with this.
Quoted 3 lines
Yes, the vendor told me that the internal tx clock rate will be auto changed when the speed rate is changed. So no software interaction is needed.
Please do not assign a clock to clk_tx_i that is not the dwmac clk_tx_i input. clk_tx_i is a name used by the Synopsys DWMAC for a specific clock.
As you don't need to do anything with it other than to get and enable it, consider using just a local variable here.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Inochi Amaoto
maintainerRe: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
Quoted 20 lines · Russell King (Oracle)
Quoted 12 lines · Inochi Amaoto
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 59
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +6
-0+ mask =RGMII_RX_DLINE_STEP |RGMII_TX_DLINE_CODE |RGMII_TX_DLINE_EN | +RGMII_TX_DLINE_STEP |RGMII_RX_DLINE_CODE |RGMII_RX_DLINE_EN ; + val =FIELD_PREP (RGMII_TX_DLINE_CODE , tx_config) | +FIELD_PREP (RGMII_TX_DLINE_CODE , tx_code) |RGMII_TX_DLINE_EN | +FIELD_PREP (RGMII_TX_DLINE_CODE , rx_config) | +FIELD_PREP (RGMII_RX_DLINE_CODE , rx_code) |RGMII_RX_DLINE_EN ;These
FIELD_PREP()fields look wrong. Did you mean to useDLINE_CODEbothtx_configandtx_code, and did you mean to useTX_DLINE_CODEforrx_config?Quoted 2 lines
This should be
RGMII_TX_DLINE_CODE. This is a copy paste error, I will fix it.Are you sure?
In that case, please change this to:
Quoted 8 lines
val = FIELD_PREP(RGMII_TX_DLINE_CODE,
tx_config|tx_code|
rx_config|rx_code) |
RGMII_TX_DLINE_EN|RGMII_RX_DLINE_EN;If that isn't what you meant, then your reply is wrong, and it seems you're confused, which makes me then question how reliable your replies are.
That's wrong, I think I have reply it in a wrong way, it should be
RGMII_TX_DLINE_STEP -> tx_configRGMII_TX_DLINE_CODE -> tx_codeRGMII_RX_DLINE_STEP -> rx_configRGMII_RX_DLINE_CODE -> rx_code
The RGMII_[RX|TX]_DLINE_STEP register selects which step is used for rx/tx delay. The RGMII_[RX|TX]_DLINE_CODE register provides the factor used for calculating the delay. These register are computed in the spacemit_dwmac_detected_delay_value(). And finally we can got a delay with "code * step / 10 * 0.9" for both rx and tx.
Quoted 14 lines
Quoted 10 lines
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 183
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+ 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" );You set
plat_dat->clk_tx_i, but you don't pointplat_dat->set_clk_tx_rateat anything, which means the stmmac core does nothing with this.Quoted 3 lines
Yes, the vendor told me that the internal tx clock rate will be auto changed when the speed rate is changed. So no software interaction is needed.
Quoted 7 lines
Please do not assign a clock to
clk_tx_ithat is not the dwmacclk_tx_iinput.clk_tx_iis a name used by the Synopsys DWMAC for a specific clock.As you don't need to do anything with it other than to get and enable it, consider using just a local variable here.
OK, I will use a local variable here.
Regards,
Inochi
Inochi Amaoto
maintainerRe: [PATCH net-next 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC
In reply to Russell King (Oracle)Quoted 20 lines · Russell King (Oracle)
Quoted 12 lines · Inochi Amaoto
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 59
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +6
-0+ mask =RGMII_RX_DLINE_STEP |RGMII_TX_DLINE_CODE |RGMII_TX_DLINE_EN | +RGMII_TX_DLINE_STEP |RGMII_RX_DLINE_CODE |RGMII_RX_DLINE_EN ; + val =FIELD_PREP (RGMII_TX_DLINE_CODE , tx_config) | +FIELD_PREP (RGMII_TX_DLINE_CODE , tx_code) |RGMII_TX_DLINE_EN | +FIELD_PREP (RGMII_TX_DLINE_CODE , rx_config) | +FIELD_PREP (RGMII_RX_DLINE_CODE , rx_code) |RGMII_RX_DLINE_EN ;These
FIELD_PREP()fields look wrong. Did you mean to useDLINE_CODEbothtx_configandtx_code, and did you mean to useTX_DLINE_CODEforrx_config?Quoted 2 lines
This should be
RGMII_TX_DLINE_CODE. This is a copy paste error, I will fix it.Are you sure?
In that case, please change this to:
Quoted 8 lines
val = FIELD_PREP(RGMII_TX_DLINE_CODE,
tx_config|tx_code|
rx_config|rx_code) |
RGMII_TX_DLINE_EN|RGMII_RX_DLINE_EN;If that isn't what you meant, then your reply is wrong, and it seems you're confused, which makes me then question how reliable your replies are.
That's wrong, I think I have reply it in a wrong way, it should be
RGMII_TX_DLINE_STEP -> tx_configRGMII_TX_DLINE_CODE -> tx_codeRGMII_RX_DLINE_STEP -> rx_configRGMII_RX_DLINE_CODE -> rx_code
The RGMII_[RX|TX]_DLINE_STEP register selects which step is used for rx/tx delay. The RGMII_[RX|TX]_DLINE_CODE register provides the factor used for calculating the delay. These register are computed in the spacemit_dwmac_detected_delay_value(). And finally we can got a delay with "code * step / 10 * 0.9" for both rx and tx.
Regards,
Inochi
Quoted 24 lines
Quoted 10 lines
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 183
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +4
-0+ 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" );You set
plat_dat->clk_tx_i, but you don't pointplat_dat->set_clk_tx_rateat anything, which means the stmmac core does nothing with this.Quoted 3 lines
Yes, the vendor told me that the internal tx clock rate will be auto changed when the speed rate is changed. So no software interaction is needed.
Please do not assign a clock to
clk_tx_ithat is not the dwmacclk_tx_iinput.clk_tx_iis a name used by the Synopsys DWMAC for a specific clock.As you don't need to do anything with it other than to get and enable it, consider using just a local variable here.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!