Re: [PATCH v2 4/7] net: dwc_eth_qos: Add glue driver for GMAC on Rockchip RK3568
On Sun, Oct 1, 2023 at 10:17 PM Jonas Karlman wrote: > > Add a new glue driver for Rockchip SoCs, i.e RK3568, with a GMAC based > on Synopsys DWC Ethernet QoS IP. > > rk_gmac_ops was ported from linux commit: > 3bb3d6b1c195 ("net: stmmac: Add RK3566/RK3568 SoC support") > > Signed-off-by: Jonas Karlman > Reviewed-by: Kever Yang > --- > Cc: David Wu > Cc: Ezequiel Garcia > --- > v2: > - Add comment about ported code intentionally left close to 1:1 with linux > - Collect r-b tag > > drivers/net/Kconfig| 8 + > drivers/net/Makefile | 1 + > drivers/net/dwc_eth_qos.c | 8 +- > drivers/net/dwc_eth_qos.h | 2 + > drivers/net/dwc_eth_qos_rockchip.c | 357 + > 5 files changed, 374 insertions(+), 2 deletions(-) > create mode 100644 drivers/net/dwc_eth_qos_rockchip.c > > diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig > index 0ed39a61e4de..29304fd77759 100644 > --- a/drivers/net/Kconfig > +++ b/drivers/net/Kconfig > @@ -225,6 +225,14 @@ config DWC_ETH_QOS_IMX > The Synopsys Designware Ethernet QOS IP block with the specific > configuration used in IMX soc. > > +config DWC_ETH_QOS_ROCKCHIP > + bool "Synopsys DWC Ethernet QOS device support for Rockchip SoCs" > + depends on DWC_ETH_QOS > + select DM_ETH_PHY > + help > + The Synopsys Designware Ethernet QOS IP block with specific > + configuration used in Rockchip SoCs. > + > config DWC_ETH_QOS_STM32 > bool "Synopsys DWC Ethernet QOS device support for STM32" > depends on DWC_ETH_QOS > diff --git a/drivers/net/Makefile b/drivers/net/Makefile > index d4af253b6f28..1d444f5b4a69 100644 > --- a/drivers/net/Makefile > +++ b/drivers/net/Makefile > @@ -20,6 +20,7 @@ obj-$(CONFIG_DRIVER_DM9000) += dm9000x.o > 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_ROCKCHIP) += dwc_eth_qos_rockchip.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 > diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c > index 24fb3fac1f12..9fb98a2c3c74 100644 > --- a/drivers/net/dwc_eth_qos.c > +++ b/drivers/net/dwc_eth_qos.c > @@ -1707,7 +1707,12 @@ static const struct udevice_id eqos_ids[] = { > .data = (ulong)_imx_config > }, > #endif > - > +#if IS_ENABLED(CONFIG_DWC_ETH_QOS_ROCKCHIP) > + { > + .compatible = "rockchip,rk3568-gmac", > + .data = (ulong)_rockchip_config > + }, > +#endif > #if IS_ENABLED(CONFIG_DWC_ETH_QOS_QCOM) > { > .compatible = "qcom,qcs404-ethqos", > @@ -1720,7 +1725,6 @@ static const struct udevice_id eqos_ids[] = { > .data = (ulong)_jh7110_config > }, > #endif > - > { } > }; > > diff --git a/drivers/net/dwc_eth_qos.h b/drivers/net/dwc_eth_qos.h > index 06a082da72ef..e3222e1e17e5 100644 > --- a/drivers/net/dwc_eth_qos.h > +++ b/drivers/net/dwc_eth_qos.h > @@ -82,6 +82,7 @@ struct eqos_mac_regs { > #define EQOS_MAC_MDIO_ADDRESS_PA_SHIFT 21 > #define EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT16 > #define EQOS_MAC_MDIO_ADDRESS_CR_SHIFT 8 > +#define EQOS_MAC_MDIO_ADDRESS_CR_100_150 1 > #define EQOS_MAC_MDIO_ADDRESS_CR_20_35 2 > #define EQOS_MAC_MDIO_ADDRESS_CR_250_300 5 > #define EQOS_MAC_MDIO_ADDRESS_SKAP BIT(4) > @@ -287,5 +288,6 @@ void eqos_flush_buffer_generic(void *buf, size_t size); > int eqos_null_ops(struct udevice *dev); > > extern struct eqos_config eqos_imx_config; > +extern struct eqos_config eqos_rockchip_config; > extern struct eqos_config eqos_qcom_config; > extern struct eqos_config eqos_jh7110_config; > diff --git a/drivers/net/dwc_eth_qos_rockchip.c > b/drivers/net/dwc_eth_qos_rockchip.c > new file mode 100644 > index ..05edc098f50d > --- /dev/null > +++ b/drivers/net/dwc_eth_qos_rockchip.c > @@ -0,0 +1,357 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright Contributors to the U-Boot project. > + * > + * rk_gmac_ops ported from linux > drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c > + * > + * Ported code is intentionally left as close as possible with linux counter > + * part in order to simplify future porting of fixes and support for other > SoCs. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "dwc_eth_qos.h" > + > +struct rk_gmac_ops { > + const char *compatible; > + int (*set_to_rgmii)(struct udevice *dev, > + int tx_delay, int rx_delay); > + int (*set_to_rmii)(struct udevice *dev); > + int
[PATCH v2 4/7] net: dwc_eth_qos: Add glue driver for GMAC on Rockchip RK3568
Add a new glue driver for Rockchip SoCs, i.e RK3568, with a GMAC based on Synopsys DWC Ethernet QoS IP. rk_gmac_ops was ported from linux commit: 3bb3d6b1c195 ("net: stmmac: Add RK3566/RK3568 SoC support") Signed-off-by: Jonas Karlman Reviewed-by: Kever Yang --- Cc: David Wu Cc: Ezequiel Garcia --- v2: - Add comment about ported code intentionally left close to 1:1 with linux - Collect r-b tag drivers/net/Kconfig| 8 + drivers/net/Makefile | 1 + drivers/net/dwc_eth_qos.c | 8 +- drivers/net/dwc_eth_qos.h | 2 + drivers/net/dwc_eth_qos_rockchip.c | 357 + 5 files changed, 374 insertions(+), 2 deletions(-) create mode 100644 drivers/net/dwc_eth_qos_rockchip.c diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 0ed39a61e4de..29304fd77759 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -225,6 +225,14 @@ config DWC_ETH_QOS_IMX The Synopsys Designware Ethernet QOS IP block with the specific configuration used in IMX soc. +config DWC_ETH_QOS_ROCKCHIP + bool "Synopsys DWC Ethernet QOS device support for Rockchip SoCs" + depends on DWC_ETH_QOS + select DM_ETH_PHY + help + The Synopsys Designware Ethernet QOS IP block with specific + configuration used in Rockchip SoCs. + config DWC_ETH_QOS_STM32 bool "Synopsys DWC Ethernet QOS device support for STM32" depends on DWC_ETH_QOS diff --git a/drivers/net/Makefile b/drivers/net/Makefile index d4af253b6f28..1d444f5b4a69 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_DRIVER_DM9000) += dm9000x.o 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_ROCKCHIP) += dwc_eth_qos_rockchip.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 diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c index 24fb3fac1f12..9fb98a2c3c74 100644 --- a/drivers/net/dwc_eth_qos.c +++ b/drivers/net/dwc_eth_qos.c @@ -1707,7 +1707,12 @@ static const struct udevice_id eqos_ids[] = { .data = (ulong)_imx_config }, #endif - +#if IS_ENABLED(CONFIG_DWC_ETH_QOS_ROCKCHIP) + { + .compatible = "rockchip,rk3568-gmac", + .data = (ulong)_rockchip_config + }, +#endif #if IS_ENABLED(CONFIG_DWC_ETH_QOS_QCOM) { .compatible = "qcom,qcs404-ethqos", @@ -1720,7 +1725,6 @@ static const struct udevice_id eqos_ids[] = { .data = (ulong)_jh7110_config }, #endif - { } }; diff --git a/drivers/net/dwc_eth_qos.h b/drivers/net/dwc_eth_qos.h index 06a082da72ef..e3222e1e17e5 100644 --- a/drivers/net/dwc_eth_qos.h +++ b/drivers/net/dwc_eth_qos.h @@ -82,6 +82,7 @@ struct eqos_mac_regs { #define EQOS_MAC_MDIO_ADDRESS_PA_SHIFT 21 #define EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT16 #define EQOS_MAC_MDIO_ADDRESS_CR_SHIFT 8 +#define EQOS_MAC_MDIO_ADDRESS_CR_100_150 1 #define EQOS_MAC_MDIO_ADDRESS_CR_20_35 2 #define EQOS_MAC_MDIO_ADDRESS_CR_250_300 5 #define EQOS_MAC_MDIO_ADDRESS_SKAP BIT(4) @@ -287,5 +288,6 @@ void eqos_flush_buffer_generic(void *buf, size_t size); int eqos_null_ops(struct udevice *dev); extern struct eqos_config eqos_imx_config; +extern struct eqos_config eqos_rockchip_config; extern struct eqos_config eqos_qcom_config; extern struct eqos_config eqos_jh7110_config; diff --git a/drivers/net/dwc_eth_qos_rockchip.c b/drivers/net/dwc_eth_qos_rockchip.c new file mode 100644 index ..05edc098f50d --- /dev/null +++ b/drivers/net/dwc_eth_qos_rockchip.c @@ -0,0 +1,357 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright Contributors to the U-Boot project. + * + * rk_gmac_ops ported from linux drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c + * + * Ported code is intentionally left as close as possible with linux counter + * part in order to simplify future porting of fixes and support for other SoCs. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dwc_eth_qos.h" + +struct rk_gmac_ops { + const char *compatible; + int (*set_to_rgmii)(struct udevice *dev, + int tx_delay, int rx_delay); + int (*set_to_rmii)(struct udevice *dev); + int (*set_gmac_speed)(struct udevice *dev); + u32 regs[3]; +}; + +struct rockchip_platform_data { + struct reset_ctl_bulk resets; + const struct rk_gmac_ops *ops; + int id; + struct regmap *grf; +}; + +#define HIWORD_UPDATE(val, mask, shift) \ + ((val) << (shift) | (mask) << ((shift) + 16)) +