Add Ethernet driver for StarFive JH7110 SoC
Subsystems (4)
cover Add Ethernet driver for StarFive JH7110 SoC
This series adds ethernet support for the StarFive JH7110 RISC-V SoC. The series includes PHY and MAC drivers. The PHY model is YT8531 (from Motorcomm Inc), and the MAC version is dwmac-5.20 (from Synopsys DesignWare).
The implementation of the phy driver is ported from linux, but it has been adjusted for the u-boot framework.
The PHY and MAC driver has been tested on the StarFive VisionFive 2 1.2A and 1.3B boards and works normally.
For more information and support,you can visit RVspace wiki[1].
This patchset should be applied after the patchset [2].
[1] https://wiki.rvspace.org/
[2] https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/
Yanhong Wang (5):
net: phy: Add driver for Motorcomm yt8531 gigabit ethernet phy
net: dwc_eth_qos: Add StarFive ethernet driver glue layer
riscv: dts: jh7110: Add ethernet device tree nodes
riscv: dts: starfive: Add phy clock delay configuration for StarFive
VisionFive2 board
configs: starfive: Enable ethernet configuration for StarFive
VisionFive 2
.../jh7110-starfive-visionfive-2-v1.2a.dts | 13 + .../jh7110-starfive-visionfive-2-v1.3b.dts | 27 ++ .../dts/jh7110-starfive-visionfive-2.dtsi | 34 ++ arch/riscv/dts/jh7110.dtsi | 69 +++ configs/starfive_visionfive2_defconfig | 13 + drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/dwc_eth_qos.c | 6 + drivers/net/dwc_eth_qos.h | 2 + drivers/net/dwc_eth_qos_starfive.c | 306 +++++++++++++ drivers/net/phy/Kconfig | 6 + drivers/net/phy/Makefile | 1 + drivers/net/phy/motorcomm.c | 409 ++++++++++++++++++ drivers/net/phy/phy.c | 4 +- include/phy.h | 1 + 15 files changed, 898 insertions(+), 1 deletion(-) create mode 100644 drivers/net/dwc_eth_qos_starfive.c create mode 100644 drivers/net/phy/motorcomm.c
base-commit: 3ad7642443aee9369726844ffcfe5b9ae68c259e
Signature · 1 line
2.17.1
PATCH 1/5 net: phy: Add driver for Motorcomm yt8531 gigabit ethernet phy
Add a driver for the motorcomm yt8531 gigabit ethernet phy. We have verified the driver on StarFive VisionFive2 board.
--- drivers/net/phy/Kconfig | 6 + drivers/net/phy/Makefile | 1 + drivers/net/phy/motorcomm.c | 409 ++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 4 +- include/phy.h | 1 + 5 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 drivers/net/phy/motorcomm.c
drivers/net/phy/Kconfig +6 -0
@@ -212,6 +212,12 @@ config PHY_MICREL_KSZ8XXX endif # PHY_MICREL +config PHY_MOTORCOMM + tristate "Motorcomm PHYs" + help + Enables support for Motorcomm network PHYs. + Currently supports the YT8531 Gigabit Ethernet PHYs. + config PHY_MSCC bool "Microsemi Corp Ethernet PHYs support"
drivers/net/phy/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_PHY_MARVELL) += marvell.o obj-$(CONFIG_PHY_MICREL_KSZ8XXX) += micrel_ksz8xxx.o obj-$(CONFIG_PHY_MICREL_KSZ90X1) += micrel_ksz90x1.o obj-$(CONFIG_PHY_MESON_GXL) += meson-gxl.o +obj-$(CONFIG_PHY_MOTORCOMM) += motorcomm.o obj-$(CONFIG_PHY_NATSEMI) += natsemi.o obj-$(CONFIG_PHY_NXP_C45_TJA11XX) += nxp-c45-tja11xx.o obj-$(CONFIG_PHY_NXP_TJA11XX) += nxp-tja11xx.o
drivers/net/phy/motorcomm.c new file +409 -0
409 lines not on this page · raw message
drivers/net/phy/phy.c +3 -1
@@ -570,6 +570,9 @@ int phy_init(void)#endif #ifdef CONFIG_PHY_XILINX_GMII2RGMII phy_xilinx_gmii2rgmii_init (); +#endif +#ifdef CONFIG_PHY_MOTORCOMM +phy_motorcomm_init ();#endif genphy_init ();
@@ -755,7 +758,6 @@ static struct phy_device *create_phy_by_mask(struct mii_dev *bus,while (phy_mask) {int addr =ffs (phy_mask) -1 ;int r =get_phy_id (bus, addr, devad, &phy_id); -/* * If the PHY ID is flat 0 we ignore it. There are C45 PHYs * that return all 0s for C22 reads (like Aquantia AQR112) and
include/phy.h +1 -0
@@ -344,6 +344,7 @@ int phy_mscc_init(void);int phy_fixed_init (void );int phy_ncsi_init (void );int phy_xilinx_gmii2rgmii_init (void ); +int phy_motorcomm_init (void );int board_phy_config (struct phy_device *phydev);int get_phy_id (struct mii_dev *bus,int addr,int devad,u32 *phy_id);
Signature · 1 line
2.17.1
Re: [PATCH v1 1/5] net: phy: Add driver for Motorcomm yt8531 gigabit ethernet phy
Hi Yanhong,
Quoted 51 lines · Yanhong Wang
Add a driver for the motorcomm yt8531 gigabit ethernet phy. We have verified the driver on StarFive VisionFive2 board.
Signed-off-by Yanhong Wang <[email protected]>--- drivers/net/phy/Kconfig | 6 + drivers/net/phy/Makefile | 1 + drivers/net/phy/motorcomm.c | 409 ++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 4 +- include/phy.h | 1 + 5 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 drivers/net/phy/motorcomm.cdrivers/net/phy/Kconfig +6
-0@@ -212,6 +212,12 @@ config PHY_MICREL_KSZ8XXX endif # PHY_MICREL +config PHY_MOTORCOMM + tristate "Motorcomm PHYs" + help + Enables support for Motorcomm network PHYs. + Currently supports the YT8531 Gigabit Ethernet PHYs. + config PHY_MSCC bool "Microsemi Corp Ethernet PHYs support"drivers/net/phy/Makefile +1
-0@@ -23,6 +23,7 @@ obj-$(CONFIG_PHY_MARVELL) += marvell.o obj-$(CONFIG_PHY_MICREL_KSZ8XXX) += micrel_ksz8xxx.o obj-$(CONFIG_PHY_MICREL_KSZ90X1) += micrel_ksz90x1.o obj-$(CONFIG_PHY_MESON_GXL) += meson-gxl.o +obj-$(CONFIG_PHY_MOTORCOMM) += motorcomm.o obj-$(CONFIG_PHY_NATSEMI) += natsemi.o obj-$(CONFIG_PHY_NXP_C45_TJA11XX) += nxp-c45-tja11xx.o obj-$(CONFIG_PHY_NXP_TJA11XX) += nxp-tja11xx.odrivers/net/phy/motorcomm.c new file +2
-0@@ -0,0 +1,409 @@ +// SPDX-License-Identifier: GPL-2.0+ +/*
[..]
drivers/net/phy/motorcomm.c line 150
Quoted 13 lines
drivers/net/phy/motorcomm.c new file +13
-0+static u32 ytphy_get_delay_reg_value (struct phy_device *phydev, +const char *prop_name, +const struct ytphy_cfg_reg_map *tbl, +int tb_size, +u16 *rxc_dly_en, +u32 dflt) +{ +int tb_size_half = tb_size /2 ; +u32 val; +int i; + +if (ofnode_read_u32 (phydev->node, prop_name, &val)) + goto err_dts_val;
Please move to your ofdata_to_plat() method.
Also, use dev_read_u32() when you have a device.
[.]
Quoted 9 lines
drivers/net/phy/motorcomm.c new file +9
-0+static int yt8531_startup (struct phy_device *phydev) +{ +bool tx_clk_adj_enabled = false; +bool tx_clk_1000_inverted = false; +bool tx_clk_100_inverted = false; +bool tx_clk_10_inverted = false; +u16 val =0 ; +int ret; +
drivers/net/phy/motorcomm.c line 283
Quoted 10 lines
drivers/net/phy/motorcomm.c new file +10
-0+ ret =genphy_update_link (phydev); +if (ret) +return ret; + + ret =yt8531_parse_status (phydev); +if (ret) +return ret; + +if (ofnode_read_bool (phydev->node,"motorcomm,tx-clk-adj-enabled" )) + tx_clk_adj_enabled = true;
priv->tx_clk_adj_enabled = ofnode_read_bool(...)
Please fix globally
Regards,
Simon
Re: [PATCH v1 1/5] net: phy: Add driver for Motorcomm yt8531 gigabit ethernet phy
Quoted 74 lines · Simon Glass
Hi Yanhong,
Quoted 51 lines · Yanhong Wang
Add a driver for the motorcomm yt8531 gigabit ethernet phy. We have verified the driver on StarFive VisionFive2 board.
Signed-off-by Yanhong Wang <[email protected]>--- drivers/net/phy/Kconfig | 6 + drivers/net/phy/Makefile | 1 + drivers/net/phy/motorcomm.c | 409 ++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 4 +- include/phy.h | 1 + 5 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 drivers/net/phy/motorcomm.cdrivers/net/phy/Kconfig +6
-0@@ -212,6 +212,12 @@ config PHY_MICREL_KSZ8XXX endif # PHY_MICREL +config PHY_MOTORCOMM + tristate "Motorcomm PHYs" + help + Enables support for Motorcomm network PHYs. + Currently supports the YT8531 Gigabit Ethernet PHYs. + config PHY_MSCC bool "Microsemi Corp Ethernet PHYs support"drivers/net/phy/Makefile +1
-0@@ -23,6 +23,7 @@ obj-$(CONFIG_PHY_MARVELL) += marvell.o obj-$(CONFIG_PHY_MICREL_KSZ8XXX) += micrel_ksz8xxx.o obj-$(CONFIG_PHY_MICREL_KSZ90X1) += micrel_ksz90x1.o obj-$(CONFIG_PHY_MESON_GXL) += meson-gxl.o +obj-$(CONFIG_PHY_MOTORCOMM) += motorcomm.o obj-$(CONFIG_PHY_NATSEMI) += natsemi.o obj-$(CONFIG_PHY_NXP_C45_TJA11XX) += nxp-c45-tja11xx.o obj-$(CONFIG_PHY_NXP_TJA11XX) += nxp-tja11xx.odrivers/net/phy/motorcomm.c new file +2
-0@@ -0,0 +1,409 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* [..]
drivers/net/phy/motorcomm.c line 150
Quoted 13 lines
drivers/net/phy/motorcomm.c new file +13
-0+static u32 ytphy_get_delay_reg_value (struct phy_device *phydev, +const char *prop_name, +const struct ytphy_cfg_reg_map *tbl, +int tb_size, +u16 *rxc_dly_en, +u32 dflt) +{ +int tb_size_half = tb_size /2 ; +u32 val; +int i; + +if (ofnode_read_u32 (phydev->node, prop_name, &val)) + goto err_dts_val;Please move to your
ofdata_to_plat()method.
Quoted 4 lines
Also, use
dev_read_u32()when you have a device.[.]
Thanks. I will define a platform data structure for saving device-related configurations in the next version.
Quoted 22 lines
Quoted 9 lines
drivers/net/phy/motorcomm.c new file +9
-0+static int yt8531_startup (struct phy_device *phydev) +{ +bool tx_clk_adj_enabled = false; +bool tx_clk_1000_inverted = false; +bool tx_clk_100_inverted = false; +bool tx_clk_10_inverted = false; +u16 val =0 ; +int ret; +drivers/net/phy/motorcomm.c line 283
Quoted 10 lines
drivers/net/phy/motorcomm.c new file +10
-0+ ret =genphy_update_link (phydev); +if (ret) +return ret; + + ret =yt8531_parse_status (phydev); +if (ret) +return ret; + +if (ofnode_read_bool (phydev->node,"motorcomm,tx-clk-adj-enabled" )) + tx_clk_adj_enabled = true;
priv->tx_clk_adj_enabled=ofnode_read_bool(...)
Quoted 2 lines
Please fix globally
Ok. I will fixed.
Quoted 2 lines
Regards,
Simon
Re: [PATCH v1 1/5] net: phy: Add driver for Motorcomm yt8531 gigabit ethernet phy
In reply to Simon GlassQuoted 74 lines · Simon Glass
Hi Yanhong,
Quoted 51 lines · Yanhong Wang
Add a driver for the motorcomm yt8531 gigabit ethernet phy. We have verified the driver on StarFive VisionFive2 board.
Signed-off-by Yanhong Wang <[email protected]>--- drivers/net/phy/Kconfig | 6 + drivers/net/phy/Makefile | 1 + drivers/net/phy/motorcomm.c | 409 ++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 4 +- include/phy.h | 1 + 5 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 drivers/net/phy/motorcomm.cdrivers/net/phy/Kconfig +6
-0@@ -212,6 +212,12 @@ config PHY_MICREL_KSZ8XXX endif # PHY_MICREL +config PHY_MOTORCOMM + tristate "Motorcomm PHYs" + help + Enables support for Motorcomm network PHYs. + Currently supports the YT8531 Gigabit Ethernet PHYs. + config PHY_MSCC bool "Microsemi Corp Ethernet PHYs support"drivers/net/phy/Makefile +1
-0@@ -23,6 +23,7 @@ obj-$(CONFIG_PHY_MARVELL) += marvell.o obj-$(CONFIG_PHY_MICREL_KSZ8XXX) += micrel_ksz8xxx.o obj-$(CONFIG_PHY_MICREL_KSZ90X1) += micrel_ksz90x1.o obj-$(CONFIG_PHY_MESON_GXL) += meson-gxl.o +obj-$(CONFIG_PHY_MOTORCOMM) += motorcomm.o obj-$(CONFIG_PHY_NATSEMI) += natsemi.o obj-$(CONFIG_PHY_NXP_C45_TJA11XX) += nxp-c45-tja11xx.o obj-$(CONFIG_PHY_NXP_TJA11XX) += nxp-tja11xx.odrivers/net/phy/motorcomm.c new file +2
-0@@ -0,0 +1,409 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* [..]
drivers/net/phy/motorcomm.c line 150
Quoted 13 lines
drivers/net/phy/motorcomm.c new file +13
-0+static u32 ytphy_get_delay_reg_value (struct phy_device *phydev, +const char *prop_name, +const struct ytphy_cfg_reg_map *tbl, +int tb_size, +u16 *rxc_dly_en, +u32 dflt) +{ +int tb_size_half = tb_size /2 ; +u32 val; +int i; + +if (ofnode_read_u32 (phydev->node, prop_name, &val)) + goto err_dts_val;Please move to your
ofdata_to_plat()method.
Quoted 4 lines
Also, use
dev_read_u32()when you have a device.[.]
The ethernet-phy@x node is a sub-node of the ethernet@y node, and the phy driver is not registered through U_BOOT_DRIVER, there is no matching dev structure, so the method dev_read_u32() unavailable.
The phy driver is not registered through U_BOOT_DRIVER, and the of_to_plat() method in the driver structure unavailable.
Quoted 13 lines
Quoted 13 lines
drivers/net/phy/motorcomm.c new file +13
-0+static int yt8531_startup (struct phy_device *phydev) +{ +bool tx_clk_adj_enabled = false; +bool tx_clk_1000_inverted = false; +bool tx_clk_100_inverted = false; +bool tx_clk_10_inverted = false; +u16 val =0 ; +int ret; + + ret =genphy_update_link (phydev); +if (ret) +return ret; +
Quoted 9 lines
drivers/net/phy/motorcomm.c line 283
Quoted 6 lines
drivers/net/phy/motorcomm.c new file +6
-0+ ret =yt8531_parse_status (phydev); +if (ret) +return ret; + +if (ofnode_read_bool (phydev->node,"motorcomm,tx-clk-adj-enabled" )) + tx_clk_adj_enabled = true;
priv->tx_clk_adj_enabled=ofnode_read_bool(...)
Define a motorocomm_priv structure to save the configuration of phy, roughly as follows:
motorocomm_priv = malloc(...);phydev->priv = motorocomm_priv; motorocomm_priv->tx_clk_adj_enabled = ofnode_read_bool(...);
Is this ok?
Quoted 4 lines
Please fix globally
Regards,
Simon
PATCH 2/5 net: dwc_eth_qos: Add StarFive ethernet driver glue layer
In reply to Yanhong WangThe StarFive ETHQOS hardware has its own clock and reset,so add a corresponding glue driver to configure them.
--- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/dwc_eth_qos.c | 6 + drivers/net/dwc_eth_qos.h | 2 + drivers/net/dwc_eth_qos_starfive.c | 306 +++++++++++++++++++++++++++++ 5 files changed, 322 insertions(+) create mode 100644 drivers/net/dwc_eth_qos_starfive.c
drivers/net/Kconfig +7 -0
@@ -249,6 +249,13 @@ config DWC_ETH_QOS_QCOM The Synopsys Designware Ethernet QOS IP block with specific configuration used in Qcom QCS404 SoC. +config DWC_ETH_QOS_STARFIVE + bool "Synopsys DWC Ethernet QOS device support for STARFIVE" + depends on DWC_ETH_QOS + help + The Synopsys Designware Ethernet QOS IP block with specific + configuration used in STARFIVE JH7110 soc. + config E1000 bool "Intel PRO/1000 Gigabit Ethernet support" depends on PCI
drivers/net/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_DSA_SANDBOX) += dsa_sandbox.o obj-$(CONFIG_DWC_ETH_QOS) += dwc_eth_qos.o obj-$(CONFIG_DWC_ETH_QOS_IMX) += dwc_eth_qos_imx.o obj-$(CONFIG_DWC_ETH_QOS_QCOM) += dwc_eth_qos_qcom.o +obj-$(CONFIG_DWC_ETH_QOS_STARFIVE) += dwc_eth_qos_starfive.o obj-$(CONFIG_E1000) += e1000.o obj-$(CONFIG_E1000_SPI) += e1000_spi.o obj-$(CONFIG_EEPRO100) += eepro100.o
drivers/net/dwc_eth_qos.c +6 -0
@@ -1718,6 +1718,12 @@ static const struct udevice_id eqos_ids[] = { .data = (ulong)&eqos_qcom_config },#endif +#if IS_ENABLED (CONFIG_DWC_ETH_QOS_STARFIVE ) + { + .compatible = "starfive,jh7110-dwmac", + .data = (ulong)&eqos_jh7110_config + }, +#endif { } };
drivers/net/dwc_eth_qos.h +2 -0
@@ -279,6 +279,7 @@ struct eqos_priv {bool clk_ck_enabled;unsigned int tx_fifo_sz, rx_fifo_sz;u32 reset_delays[3 ]; +struct reset_ctl reset_ahb; };void eqos_inval_desc_generic (void *desc);
@@ -289,3 +290,4 @@ int eqos_null_ops(struct udevice *dev);extern struct eqos_config eqos_imx_config;extern struct eqos_config eqos_qcom_config; +extern struct eqos_config eqos_jh7110_config;
drivers/net/dwc_eth_qos_starfive.c new file +306 -0
306 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v1 2/5] net: dwc_eth_qos: Add StarFive ethernet driver glue layer
Hi Yanhong,
Quoted 58 lines · Yanhong Wang
The StarFive ETHQOS hardware has its own clock and reset,so add a corresponding glue driver to configure them.
Signed-off-by Yanhong Wang <[email protected]>--- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/dwc_eth_qos.c | 6 + drivers/net/dwc_eth_qos.h | 2 + drivers/net/dwc_eth_qos_starfive.c | 306 +++++++++++++++++++++++++++++ 5 files changed, 322 insertions(+) create mode 100644 drivers/net/dwc_eth_qos_starfive.c[..]
drivers/net/dwc_eth_qos_starfive.c new file +36
-0@@ -0,0 +1,306 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2023 StarFive Technology Co., Ltd. +* Author: Yanhong Wang<[email protected]> +*/ + +#include <common.h> +#include <asm/cache.h> +#include <asm/gpio.h> +#include <clk.h> +#include <dm.h> +#include <eth_phy.h> +#include <regmap.h> +#include <reset.h> +#include <syscon.h> + +#include "dwc_eth_qos.h" + +#define STARFIVE_DWMAC_PHY_INFT_RGMII 0x1 +#define STARFIVE_DWMAC_PHY_INFT_RMII 0x4 +#define STARFIVE_DWMAC_PHY_INFT_FIELD 0x7U + +static int eqos_interface_init_jh7110 (struct udevice *dev, +phy_interface_t interface_type) +{ +struct regmap *regmap; +struct ofnode_phandle_args args; +unsigned int mode; +int ret; + +switch (interface_type) { +case PHY_INTERFACE_MODE_RMII : + mode =STARFIVE_DWMAC_PHY_INFT_RMII ; +break ; + +case PHY_INTERFACE_MODE_RGMII :
drivers/net/dwc_eth_qos_starfive.c line 46
Quoted 10 lines
drivers/net/dwc_eth_qos_starfive.c new file +10
-0+case PHY_INTERFACE_MODE_RGMII_ID : + mode =STARFIVE_DWMAC_PHY_INFT_RGMII ; +break ; + +default : +return -EINVAL ; + } + + ret =dev_read_phandle_with_args (dev,"starfive,syscon" ,NULL , +2 ,0 , &args);
You must read the DT in an ofdata_to_plat() method (or probe() if that doesn't suit). Put it in a struct.
You must not read it constantly at runtime throughout your driver. It is slow and error-prone.
[..]
Quoted 12 lines
drivers/net/dwc_eth_qos_starfive.c new file +11
-1+ +struct eqos_config __maybe_unused eqos_jh7110_config = { + .reg_access_always_ok = false, + .mdio_wait =10 , + .swr_wait =50 , + .config_mac =EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB , + .config_mac_mdio =EQOS_MAC_MDIO_ADDRESS_CR_250_300 , + .axi_bus_width =EQOS_AXI_WIDTH_64 , + .interface = dev_read_phy_mode, + .ops = &eqos_jh7110_ops +}; --
Quoted 2 lines
2.17.1
What is that data for? Please add a comment.
Regards,
SImom
Re: [PATCH v1 2/5] net: dwc_eth_qos: Add StarFive ethernet driver glue layer
Quoted 76 lines · Simon Glass
Hi Yanhong,
Quoted 58 lines · Yanhong Wang
The StarFive ETHQOS hardware has its own clock and reset,so add a corresponding glue driver to configure them.
Signed-off-by Yanhong Wang <[email protected]>--- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/dwc_eth_qos.c | 6 + drivers/net/dwc_eth_qos.h | 2 + drivers/net/dwc_eth_qos_starfive.c | 306 +++++++++++++++++++++++++++++ 5 files changed, 322 insertions(+) create mode 100644 drivers/net/dwc_eth_qos_starfive.c[..]
drivers/net/dwc_eth_qos_starfive.c new file +36
-0@@ -0,0 +1,306 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2023 StarFive Technology Co., Ltd. +* Author: Yanhong Wang<[email protected]> +*/ + +#include <common.h> +#include <asm/cache.h> +#include <asm/gpio.h> +#include <clk.h> +#include <dm.h> +#include <eth_phy.h> +#include <regmap.h> +#include <reset.h> +#include <syscon.h> + +#include "dwc_eth_qos.h" + +#define STARFIVE_DWMAC_PHY_INFT_RGMII 0x1 +#define STARFIVE_DWMAC_PHY_INFT_RMII 0x4 +#define STARFIVE_DWMAC_PHY_INFT_FIELD 0x7U + +static int eqos_interface_init_jh7110 (struct udevice *dev, +phy_interface_t interface_type) +{ +struct regmap *regmap; +struct ofnode_phandle_args args; +unsigned int mode; +int ret; + +switch (interface_type) { +case PHY_INTERFACE_MODE_RMII : + mode =STARFIVE_DWMAC_PHY_INFT_RMII ; +break ; + +case PHY_INTERFACE_MODE_RGMII :drivers/net/dwc_eth_qos_starfive.c line 46
Quoted 10 lines
drivers/net/dwc_eth_qos_starfive.c new file +10
-0+case PHY_INTERFACE_MODE_RGMII_ID : + mode =STARFIVE_DWMAC_PHY_INFT_RGMII ; +break ; + +default : +return -EINVAL ; + } + + ret =dev_read_phandle_with_args (dev,"starfive,syscon" ,NULL , +2 ,0 , &args);You must read the DT in an
ofdata_to_plat()method (orprobe()if that doesn't suit). Put it in a struct.
Quoted 4 lines
You must not read it constantly at runtime throughout your driver. It is slow and error-prone.
[..]
Thanks. I will define a platform data structure for saving device-related configurations in the next version.
Quoted 8 lines
Quoted 8 lines
drivers/net/dwc_eth_qos_starfive.c new file +8
-0+ +struct eqos_config __maybe_unused eqos_jh7110_config = { + .reg_access_always_ok = false, + .mdio_wait =10 , + .swr_wait =50 , + .config_mac =EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB , + .config_mac_mdio =EQOS_MAC_MDIO_ADDRESS_CR_250_300 , + .axi_bus_width =EQOS_AXI_WIDTH_64 ,
Quoted 9 lines
Quoted 6 lines
drivers/net/dwc_eth_qos_starfive.c new file +3
-1+ .interface = dev_read_phy_mode, + .ops = &eqos_jh7110_ops +}; --2.17.1
What is that data for? Please add a comment.
The definition of these parameters refers to IMX platform, I will double confirm whether the definition of these parameters is accurate, and add corresponding comments in the next version.
Quoted 2 lines
Regards,
SImom
PATCH 3/5 riscv: dts: jh7110: Add ethernet device tree nodes
In reply to Yanhong WangAdd ethernet device tree node to support StarFive ethernet driver for the JH7110 RISC-V SoC.
--- arch/riscv/dts/jh7110.dtsi | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
arch/riscv/dts/jh7110.dtsi +69 -0
@@ -244,6 +244,13 @@ #clock-cells = <0>; }; + stmmac_axi_setup: stmmac-axi-config { + snps,lpi_en; + snps,wr_osr_lmt = <4>; + snps,rd_osr_lmt = <4>; + snps,blen = <256 128 64 32 0 0 0>; + }; + soc { compatible = "simple-bus"; interrupt-parent = <&plic>;
@@ -548,6 +555,68 @@ status = "disabled"; }; + gmac0: ethernet@16030000 { + compatible = "starfive,jh7110-dwmac", "snps,dwmac-5.20"; + reg = <0x0 0x16030000 0x0 0x10000>; + clocks = <&aoncrg JH7110_AONCLK_GMAC0_AXI>, + <&aoncrg JH7110_AONCLK_GMAC0_AHB>, + <&syscrg JH7110_SYSCLK_GMAC0_PTP>, + <&aoncrg JH7110_AONCLK_GMAC0_TX_INV>, + <&syscrg JH7110_SYSCLK_GMAC0_GTXC>; + clock-names = "stmmaceth", "pclk", "ptp_ref", + "tx", "gtx"; + resets = <&aoncrg JH7110_AONRST_GMAC0_AXI>, + <&aoncrg JH7110_AONRST_GMAC0_AHB>; + reset-names = "stmmaceth", "ahb"; + interrupts = <7>, <6>, <5>; + interrupt-names = "macirq", "eth_wake_irq", "eth_lpi"; + snps,multicast-filter-bins = <64>; + snps,perfect-filter-entries = <8>; + rx-fifo-depth = <2048>; + tx-fifo-depth = <2048>; + snps,fixed-burst; + snps,no-pbl-x8; + snps,force_thresh_dma_mode; + snps,axi-config = <&stmmac_axi_setup>; + snps,tso; + snps,en-tx-lpi-clockgating; + snps,txpbl = <16>; + snps,rxpbl = <16>; + starfive,syscon = <&aon_syscon 0xc 0x12>; + status = "disabled"; + }; + + gmac1: ethernet@16040000 { + compatible = "starfive,jh7110-dwmac", "snps,dwmac-5.20"; + reg = <0x0 0x16040000 0x0 0x10000>; + clocks = <&syscrg JH7110_SYSCLK_GMAC1_AXI>, + <&syscrg JH7110_SYSCLK_GMAC1_AHB>, + <&syscrg JH7110_SYSCLK_GMAC1_PTP>, + <&syscrg JH7110_SYSCLK_GMAC1_TX_INV>, + <&syscrg JH7110_SYSCLK_GMAC1_GTXC>; + clock-names = "stmmaceth", "pclk", "ptp_ref", + "tx", "gtx"; + resets = <&syscrg JH7110_SYSRST_GMAC1_AXI>, + <&syscrg JH7110_SYSRST_GMAC1_AHB>; + reset-names = "stmmaceth", "ahb"; + interrupts = <78>, <77>, <76>; + interrupt-names = "macirq", "eth_wake_irq", "eth_lpi"; + snps,multicast-filter-bins = <64>; + snps,perfect-filter-entries = <8>; + rx-fifo-depth = <2048>; + tx-fifo-depth = <2048>; + snps,fixed-burst; + snps,no-pbl-x8; + snps,force_thresh_dma_mode; + snps,axi-config = <&stmmac_axi_setup>; + snps,tso; + snps,en-tx-lpi-clockgating; + snps,txpbl = <16>; + snps,rxpbl = <16>; + starfive,syscon = <&sys_syscon 0x90 0x2>; + status = "disabled"; + }; + aoncrg: clock-controller@17000000 { compatible = "starfive,jh7110-aoncrg"; reg = <0x0 0x17000000 0x0 0x10000>;
Signature · 1 line
2.17.1
PATCH 4/5 riscv: dts: starfive: Add phy clock delay configuration for StarFive VisionFive2 board
In reply to Yanhong WangThe StarFive VisionFive2 board include 1.2A and 1.3B version.
v1.3B uses motorcomm YT8531(rgmii-id phy) x2, phy clock need delay and inverse configurations.
v1.2A gmac0 uses motorcomm YT8531(rgmii-id) PHY, and needs phy clock delay configurations.
v1.2A gmac1 uses motorcomm YT8512(rmii) PHY, and needs to switch rx and tx to external clock sources.
--- .../jh7110-starfive-visionfive-2-v1.2a.dts | 13 +++++++ .../jh7110-starfive-visionfive-2-v1.3b.dts | 27 +++++++++++++++ .../dts/jh7110-starfive-visionfive-2.dtsi | 34 +++++++++++++++++++ 3 files changed, 74 insertions(+)
arch/riscv/dts/jh7110-starfive-visionfive-2-v1.2a.dts +13 -0
@@ -10,3 +10,16 @@ model = "StarFive VisionFive 2 v1.2A"; compatible = "starfive,visionfive-2-v1.2a", "starfive,jh7110"; }; + +&gmac1 { + phy-mode = "rmii"; + assigned-clocks = <&syscrg JH7110_SYSCLK_GMAC1_TX>, + <&syscrg JH7110_SYSCLK_GMAC1_RX>; + assigned-clock-parents = <&syscrg JH7110_SYSCLK_GMAC1_RMII_RTX>, + <&syscrg JH7110_SYSCLK_GMAC1_RMII_RTX>; +}; + +&phy0 { + rx-internal-delay-ps = <1900>; + tx-internal-delay-ps = <1350>; +};
arch/riscv/dts/jh7110-starfive-visionfive-2-v1.3b.dts +27 -0
@@ -10,3 +10,30 @@ model = "StarFive VisionFive 2 v1.3B"; compatible = "starfive,visionfive-2-v1.3b", "starfive,jh7110"; }; + +&gmac0 { + starfive,tx-use-rgmii-clk; + assigned-clocks = <&aoncrg JH7110_AONCLK_GMAC0_TX>; + assigned-clock-parents = <&aoncrg JH7110_AONCLK_GMAC0_RMII_RTX>; +}; + +&gmac1 { + starfive,tx-use-rgmii-clk; + assigned-clocks = <&syscrg JH7110_SYSCLK_GMAC1_TX>; + assigned-clock-parents = <&syscrg JH7110_SYSCLK_GMAC1_RMII_RTX>; +}; + +&phy0 { + motorcomm,tx-clk-adj-enabled; + motorcomm,tx-clk-100-inverted; + motorcomm,tx-clk-1000-inverted; + rx-internal-delay-ps = <1900>; + tx-internal-delay-ps = <1500>; +}; + +&phy1 { + motorcomm,tx-clk-adj-enabled; + motorcomm,tx-clk-100-inverted; + rx-internal-delay-ps = <0>; + tx-internal-delay-ps = <0>; +};
arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi +34 -0
@@ -17,6 +17,8 @@ i2c2 = &i2c2; i2c5 = &i2c5; i2c6 = &i2c6; + ethernet0 = &gmac0; + ethernet1 = &gmac1; }; chosen {
@@ -317,3 +319,35 @@ assigned-clock-parents = <&osc>; assigned-clock-rates = <0>; }; + +&gmac0 { + phy-handle = <&phy0>; + phy-mode = "rgmii-id"; + status = "okay"; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,dwmac-mdio"; + + phy0: ethernet-phy@0 { + reg = <0>; + }; + }; +}; + +&gmac1 { + phy-handle = <&phy1>; + phy-mode = "rgmii-id"; + status = "okay"; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + compatible = "snps,dwmac-mdio"; + + phy1: ethernet-phy@1 { + reg = <0>; + }; + }; +};
Signature · 1 line
2.17.1
PATCH 5/5 configs: starfive: Enable ethernet configuration for StarFive VisionFive 2
In reply to Yanhong WangEnable DWC_ETH_QOS and PHY_MOTORCOMM configuration to support ethernet function for StarFive VisionFive 2 board.
--- configs/starfive_visionfive2_defconfig | 13 +++++++++++++ 1 file changed, 13 insertions(+)
configs/starfive_visionfive2_defconfig +13 -0
@@ -52,6 +52,9 @@ CONFIG_SYS_BOOTM_LEN=0x4000000 CONFIG_CMD_MEMINFO=y CONFIG_CMD_TFTPPUT=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y +CONFIG_NET_RANDOM_ETHADDR=y +CONFIG_REGMAP=y +CONFIG_SYSCON=y CONFIG_SPL_CLK_COMPOSITE_CCF=y CONFIG_CLK_COMPOSITE_CCF=y CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +68,15 @@ CONFIG_SPI_FLASH_EON=y CONFIG_SPI_FLASH_GIGADEVICE=y CONFIG_SPI_FLASH_ISSI=y CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_PHY_MOTORCOMM=y +# CONFIG_PHY_MSCC is not set +CONFIG_DM_MDIO=y +CONFIG_DM_ETH_PHY=y +CONFIG_DWC_ETH_QOS=y +CONFIG_DWC_ETH_QOS_STARFIVE=y +CONFIG_RGMII=y +# CONFIG_MII is not set +CONFIG_RMII=y CONFIG_PINCTRL=y CONFIG_PINCONF=y CONFIG_SPL_PINCTRL=y
@@ -72,6 +84,7 @@ CONFIG_SPL_PINCONF=y CONFIG_SPL_PINCTRL_STARFIVE=y CONFIG_SPL_PINCTRL_STARFIVE_JH7110=y CONFIG_PINCTRL_STARFIVE=y +# CONFIG_POWER is not set # CONFIG_RAM_SIFIVE is not set CONFIG_SYS_NS16550=y CONFIG_CADENCE_QSPI=y
Signature · 1 line
2.17.1
Quoted 10 lines · On Fri, 17 Mar 2023 09:05:31 +0800 Yanhong Wang…
This series adds ethernet support for the StarFive JH7110 RISC-V SoC. The series includes PHY and MAC drivers. The PHY model is YT8531 (from Motorcomm Inc), and the MAC version is dwmac-5.20 (from Synopsys DesignWare).
The implementation of the phy driver is ported from linux, but it has been adjusted for the u-boot framework.
The PHY and MAC driver has been tested on the StarFive VisionFive 2 1.2A and 1.3B boards and works normally.
At least a smoke test here succeeded as well, I'm seeing replies to DHCP. However:
| Model: StarFive VisionFive 2 v1.3B
[...]
| Net: | Warning: ethernet@16040000 (eth1) using random MAC address - e2:b9:39:bd:92:24 | | Warning: ethernet@16030000 (eth0) using random MAC address - 22:da:dc:e6:2c:17 | eth0: ethernet@16030000, eth1: ethernet@16040000
[...]
What's missing to read the correct MACs from the EEPROM?
Torsten
Quoted 19 lines · Torsten Duwe
Quoted 10 lines · On Fri, 17 Mar 2023 09:05:31 +0800 Yanhong Wang…
This series adds ethernet support for the StarFive JH7110 RISC-V SoC. The series includes PHY and MAC drivers. The PHY model is YT8531 (from Motorcomm Inc), and the MAC version is dwmac-5.20 (from Synopsys DesignWare).
The implementation of the phy driver is ported from linux, but it has been adjusted for the u-boot framework.
The PHY and MAC driver has been tested on the StarFive VisionFive 2 1.2A and 1.3B boards and works normally.
At least a smoke test here succeeded as well, I'm seeing replies to DHCP. However:
| Model: StarFive VisionFive 2 v1.3B
[...]
Quoted 9 lines
| Net: | Warning: ethernet@16040000 (eth1) using random MAC address - e2:b9:39:bd:92:24 | | Warning: ethernet@16030000 (eth0) using random MAC address - 22:da:dc:e6:2c:17 | eth0: ethernet@16030000, eth1: ethernet@16040000[...]
What's missing to read the correct MACs from the EEPROM?
The minimum system of u-boot supporting JH7110 does not contain EEPROM and cannot read the MAC address from EEPROM, so enable the CONFIG_NET_RANDOM_ETHADDR, EEPROM will be supported in the future, and the MAC address will be read from EEPROM.
Quoted 3 lines
Torsten
Quoted 5 lines · On Mon, 27 Mar 2023 10:22:37 +0800 yanhong wang…
Quoted 1 line · Torsten Duwe
What's missing to read the correct MACs from the EEPROM?
The minimum system of u-boot supporting JH7110 does not contain EEPROM
[...]
Thanks for the info!
Torsten