mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/3] Add i.MX9 EQOS networking support
@ 2023-11-10 13:02 Sascha Hauer
  2023-11-10 13:02 ` [PATCH 1/3] net: eqos: rename i.MX8 driver glue code to i.MX Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-11-10 13:02 UTC (permalink / raw)
  To: Barebox List

Like some i.MX8M variants the i.MX9 also has a designware EQOS network
controller. This series adjusts the glue code to make the driver
available on i.MX9.

Sascha

Sascha Hauer (3):
  net: eqos: rename i.MX8 driver glue code to i.MX
  net: eqos: imx: move common stuff to probe()
  net: eqos: Add i.MX93 support

 arch/arm/configs/imx_v8_defconfig   |   2 +-
 arch/arm/configs/multi_v8_defconfig |   2 +-
 drivers/net/Kconfig                 |   8 +-
 drivers/net/Makefile                |   2 +-
 drivers/net/designware_imx.c        | 269 ++++++++++++++++++++++++++++
 drivers/net/designware_imx8.c       | 195 --------------------
 6 files changed, 276 insertions(+), 202 deletions(-)
 create mode 100644 drivers/net/designware_imx.c
 delete mode 100644 drivers/net/designware_imx8.c

-- 
2.39.2




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] net: eqos: rename i.MX8 driver glue code to i.MX
  2023-11-10 13:02 [PATCH 0/3] Add i.MX9 EQOS networking support Sascha Hauer
@ 2023-11-10 13:02 ` Sascha Hauer
  2023-11-13  7:19   ` Ahmad Fatoum
  2023-11-10 13:02 ` [PATCH 2/3] net: eqos: imx: move common stuff to probe() Sascha Hauer
  2023-11-10 13:02 ` [PATCH 3/3] net: eqos: Add i.MX93 support Sascha Hauer
  2 siblings, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2023-11-10 13:02 UTC (permalink / raw)
  To: Barebox List

The i.MX8 glue code for the designware ethernet driver will be used by
i.MX9 as well. Rename the file accordingly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/configs/imx_v8_defconfig             |  2 +-
 arch/arm/configs/multi_v8_defconfig           |  2 +-
 drivers/net/Kconfig                           |  6 +-
 drivers/net/Makefile                          |  2 +-
 .../{designware_imx8.c => designware_imx.c}   | 58 +++++++++----------
 5 files changed, 35 insertions(+), 35 deletions(-)
 rename drivers/net/{designware_imx8.c => designware_imx.c} (73%)

diff --git a/arch/arm/configs/imx_v8_defconfig b/arch/arm/configs/imx_v8_defconfig
index 8084e72ea0..66dab8c4a7 100644
--- a/arch/arm/configs/imx_v8_defconfig
+++ b/arch/arm/configs/imx_v8_defconfig
@@ -92,7 +92,7 @@ CONFIG_NET_NETCONSOLE=y
 CONFIG_OFDEVICE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_SERIAL_DEV_BUS=y
-CONFIG_DRIVER_NET_DESIGNWARE_IMX8=y
+CONFIG_DRIVER_NET_DESIGNWARE_IMX=y
 CONFIG_DRIVER_NET_FEC_IMX=y
 CONFIG_DP83867_PHY=y
 CONFIG_MICREL_PHY=y
diff --git a/arch/arm/configs/multi_v8_defconfig b/arch/arm/configs/multi_v8_defconfig
index 9c538e698d..2599519351 100644
--- a/arch/arm/configs/multi_v8_defconfig
+++ b/arch/arm/configs/multi_v8_defconfig
@@ -141,7 +141,7 @@ CONFIG_SERIAL_AMBA_PL011=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SERIAL_CADENCE=y
 CONFIG_VIRTIO_CONSOLE=y
-CONFIG_DRIVER_NET_DESIGNWARE_IMX8=y
+CONFIG_DRIVER_NET_DESIGNWARE_IMX=y
 CONFIG_DRIVER_NET_DESIGNWARE_ROCKCHIP=y
 CONFIG_DRIVER_NET_FEC_IMX=y
 CONFIG_DRIVER_NET_MACB=y
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 1c89cf9e41..9be03cf20c 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -107,14 +107,14 @@ config DRIVER_NET_DESIGNWARE_EQOS
 	  This option enables support for the Synopsys
 	  Designware Ethernet Quality-of-Service (GMAC4).
 
-config DRIVER_NET_DESIGNWARE_IMX8
-	bool "Designware EQOS i.MX8 Ethernet driver"
+config DRIVER_NET_DESIGNWARE_IMX
+	bool "Designware EQOS i.MX Ethernet driver"
 	depends on HAS_DMA && COMMON_CLK && OFTREE && (ARCH_IMX8M || COMPILE_TEST)
 	select DRIVER_NET_DESIGNWARE_EQOS
 	select MFD_SYSCON
 	help
 	  This option enables support for the Designware EQOS MAC implemented on
-	  the NXP i.MX8 SoCs.
+	  the NXP i.MX SoCs.
 
 config DRIVER_NET_DESIGNWARE_STM32
 	bool "STM32 Designware Ethernet driver"
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 1a272d9158..697b5bdfb7 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -15,7 +15,7 @@ obj-$(CONFIG_DRIVER_NET_DESIGNWARE_GENERIC) += designware_generic.o
 obj-$(CONFIG_DRIVER_NET_DESIGNWARE_SOCFPGA) += designware_socfpga.o
 obj-$(CONFIG_DRIVER_NET_DESIGNWARE_STARFIVE) += designware_starfive.o
 obj-$(CONFIG_DRIVER_NET_DESIGNWARE_EQOS) += designware_eqos.o
-obj-$(CONFIG_DRIVER_NET_DESIGNWARE_IMX8) += designware_imx8.o
+obj-$(CONFIG_DRIVER_NET_DESIGNWARE_IMX) += designware_imx.o
 obj-$(CONFIG_DRIVER_NET_DESIGNWARE_STM32) += designware_stm32.o
 obj-$(CONFIG_DRIVER_NET_DESIGNWARE_TEGRA186) += designware_tegra186.o
 obj-$(CONFIG_DRIVER_NET_DESIGNWARE_ROCKCHIP) += designware_rockchip.o
diff --git a/drivers/net/designware_imx8.c b/drivers/net/designware_imx.c
similarity index 73%
rename from drivers/net/designware_imx8.c
rename to drivers/net/designware_imx.c
index 73a16d5e65..00164fa7c7 100644
--- a/drivers/net/designware_imx8.c
+++ b/drivers/net/designware_imx.c
@@ -18,7 +18,7 @@
 #define GPR_ENET_QOS_RGMII_EN		BIT(21)
 
 
-struct eqos_imx8_priv {
+struct eqos_imx_priv {
 	struct device *dev;
 	struct clk_bulk_data *clks;
 	int num_clks;
@@ -28,25 +28,25 @@ struct eqos_imx8_priv {
 };
 
 enum { CLK_STMMACETH, CLK_PCLK, CLK_PTP_REF, CLK_TX};
-static const struct clk_bulk_data imx8_clks[] = {
+static const struct clk_bulk_data imx_clks[] = {
 	[CLK_STMMACETH] = { .id = "stmmaceth" },
 	[CLK_PCLK]      = { .id = "pclk" },
 	[CLK_PTP_REF]   = { .id = "ptp_ref" },
 	[CLK_TX]        = { .id = "tx" },
 };
 
-static unsigned long eqos_get_csr_clk_rate_imx8(struct eqos *eqos)
+static unsigned long eqos_get_csr_clk_rate_imx(struct eqos *eqos)
 {
-	struct eqos_imx8_priv *priv = eqos->priv;
+	struct eqos_imx_priv *priv = eqos->priv;
 
 	return clk_get_rate(priv->clks[CLK_PCLK].clk);
 }
 
 
-static void eqos_adjust_link_imx8(struct eth_device *edev)
+static void eqos_adjust_link_imx(struct eth_device *edev)
 {
 	struct eqos *eqos = edev->priv;
-	struct eqos_imx8_priv *priv = eqos->priv;
+	struct eqos_imx_priv *priv = eqos->priv;
 	unsigned long rate;
 	int ret;
 
@@ -74,9 +74,9 @@ static void eqos_adjust_link_imx8(struct eth_device *edev)
 	eqos_adjust_link(edev);
 }
 
-static void eqos_imx8_set_interface_mode(struct eqos *eqos)
+static void eqos_imx_set_interface_mode(struct eqos *eqos)
 {
-	struct eqos_imx8_priv *priv = eqos->priv;
+	struct eqos_imx_priv *priv = eqos->priv;
 	struct device_node *np = priv->dev->device_node;
 	int val;
 
@@ -109,10 +109,10 @@ static void eqos_imx8_set_interface_mode(struct eqos *eqos)
 			   GPR_ENET_QOS_INTF_MODE_MASK, val);
 }
 
-static int eqos_init_imx8(struct device *dev, struct eqos *eqos)
+static int eqos_init_imx(struct device *dev, struct eqos *eqos)
 {
 	struct device_node *np = dev->device_node;
-	struct eqos_imx8_priv *priv = eqos->priv;
+	struct eqos_imx_priv *priv = eqos->priv;
 	int ret;
 
 	priv->dev = dev;
@@ -132,9 +132,9 @@ static int eqos_init_imx8(struct device *dev, struct eqos *eqos)
 		}
 	}
 
-	priv->num_clks = ARRAY_SIZE(imx8_clks);
+	priv->num_clks = ARRAY_SIZE(imx_clks);
 	priv->clks = xmalloc(priv->num_clks * sizeof(*priv->clks));
-	memcpy(priv->clks, imx8_clks, sizeof imx8_clks);
+	memcpy(priv->clks, imx_clks, sizeof imx_clks);
 
 	ret = clk_bulk_get(dev, priv->num_clks, priv->clks);
 	if (ret) {
@@ -148,31 +148,31 @@ static int eqos_init_imx8(struct device *dev, struct eqos *eqos)
 		return ret;
 	}
 
-	eqos_imx8_set_interface_mode(eqos);
+	eqos_imx_set_interface_mode(eqos);
 
 	return 0;
 }
 
-static struct eqos_ops imx8_ops = {
-	.init = eqos_init_imx8,
+static struct eqos_ops imx_ops = {
+	.init = eqos_init_imx,
 	.get_ethaddr = eqos_get_ethaddr,
 	.set_ethaddr = eqos_set_ethaddr,
-	.adjust_link = eqos_adjust_link_imx8,
-	.get_csr_clk_rate = eqos_get_csr_clk_rate_imx8,
+	.adjust_link = eqos_adjust_link_imx,
+	.get_csr_clk_rate = eqos_get_csr_clk_rate_imx,
 
 	.clk_csr = EQOS_MDIO_ADDR_CR_250_300,
 	.config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB,
 };
 
-static int eqos_probe_imx8(struct device *dev)
+static int eqos_probe_imx(struct device *dev)
 {
-	return eqos_probe(dev, &imx8_ops, xzalloc(sizeof(struct eqos_imx8_priv)));
+	return eqos_probe(dev, &imx_ops, xzalloc(sizeof(struct eqos_imx_priv)));
 }
 
-static void eqos_remove_imx8(struct device *dev)
+static void eqos_remove_imx(struct device *dev)
 {
 	struct eqos *eqos = dev->priv;
-	struct eqos_imx8_priv *priv = eqos->priv;
+	struct eqos_imx_priv *priv = eqos->priv;
 
 	eqos_remove(dev);
 
@@ -180,16 +180,16 @@ static void eqos_remove_imx8(struct device *dev)
 	clk_bulk_put(priv->num_clks, priv->clks);
 }
 
-static __maybe_unused struct of_device_id eqos_imx8_ids[] = {
+static __maybe_unused struct of_device_id eqos_imx_ids[] = {
 	{ .compatible = "nxp,imx8mp-dwmac-eqos"},
 	{ /* sentinel */ }
 };
-MODULE_DEVICE_TABLE(of, eqos_imx8_ids);
+MODULE_DEVICE_TABLE(of, eqos_imx_ids);
 
-static struct driver eqos_imx8_driver = {
-	.name = "eqos-imx8",
-	.probe = eqos_probe_imx8,
-	.remove = eqos_remove_imx8,
-	.of_compatible = DRV_OF_COMPAT(eqos_imx8_ids),
+static struct driver eqos_imx_driver = {
+	.name = "eqos-imx",
+	.probe = eqos_probe_imx,
+	.remove = eqos_remove_imx,
+	.of_compatible = DRV_OF_COMPAT(eqos_imx_ids),
 };
-device_platform_driver(eqos_imx8_driver);
+device_platform_driver(eqos_imx_driver);
-- 
2.39.2




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] net: eqos: imx: move common stuff to probe()
  2023-11-10 13:02 [PATCH 0/3] Add i.MX9 EQOS networking support Sascha Hauer
  2023-11-10 13:02 ` [PATCH 1/3] net: eqos: rename i.MX8 driver glue code to i.MX Sascha Hauer
@ 2023-11-10 13:02 ` Sascha Hauer
  2023-11-10 13:02 ` [PATCH 3/3] net: eqos: Add i.MX93 support Sascha Hauer
  2 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-11-10 13:02 UTC (permalink / raw)
  To: Barebox List

eqos_init_imx() currently is i.MX8 specific, but some stuff can be used
by i.MX9 as well. Move that to probe().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/designware_imx.c | 50 ++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 22 deletions(-)

diff --git a/drivers/net/designware_imx.c b/drivers/net/designware_imx.c
index 00164fa7c7..13bca42c25 100644
--- a/drivers/net/designware_imx.c
+++ b/drivers/net/designware_imx.c
@@ -115,11 +115,6 @@ static int eqos_init_imx(struct device *dev, struct eqos *eqos)
 	struct eqos_imx_priv *priv = eqos->priv;
 	int ret;
 
-	priv->dev = dev;
-
-	if (of_get_property(np, "snps,rmii_refclk_ext", NULL))
-		priv->rmii_refclk_ext = true;
-
 	if (of_device_is_compatible(np, "nxp,imx8mp-dwmac-eqos")) {
 		priv->intf_regmap = syscon_regmap_lookup_by_phandle(np, "intf_mode");
 		if (IS_ERR(priv->intf_regmap))
@@ -132,22 +127,6 @@ static int eqos_init_imx(struct device *dev, struct eqos *eqos)
 		}
 	}
 
-	priv->num_clks = ARRAY_SIZE(imx_clks);
-	priv->clks = xmalloc(priv->num_clks * sizeof(*priv->clks));
-	memcpy(priv->clks, imx_clks, sizeof imx_clks);
-
-	ret = clk_bulk_get(dev, priv->num_clks, priv->clks);
-	if (ret) {
-		dev_err(dev, "Failed to get clks: %s\n", strerror(-ret));
-		return ret;
-	}
-
-	ret = clk_bulk_enable(priv->num_clks, priv->clks);
-	if (ret) {
-		dev_err(dev, "Failed to enable clks: %s\n", strerror(-ret));
-		return ret;
-	}
-
 	eqos_imx_set_interface_mode(eqos);
 
 	return 0;
@@ -166,7 +145,34 @@ static struct eqos_ops imx_ops = {
 
 static int eqos_probe_imx(struct device *dev)
 {
-	return eqos_probe(dev, &imx_ops, xzalloc(sizeof(struct eqos_imx_priv)));
+	struct device_node *np = dev->device_node;
+	struct eqos_imx_priv *priv;
+	int ret;
+
+	priv = xzalloc(sizeof(*priv));
+
+	priv->dev = dev;
+
+	if (of_get_property(np, "snps,rmii_refclk_ext", NULL))
+		priv->rmii_refclk_ext = true;
+
+	priv->num_clks = ARRAY_SIZE(imx_clks);
+	priv->clks = xmalloc(priv->num_clks * sizeof(*priv->clks));
+	memcpy(priv->clks, imx_clks, sizeof imx_clks);
+
+	ret = clk_bulk_get(dev, priv->num_clks, priv->clks);
+	if (ret) {
+		dev_err(dev, "Failed to get clks: %s\n", strerror(-ret));
+		return ret;
+	}
+
+	ret = clk_bulk_enable(priv->num_clks, priv->clks);
+	if (ret) {
+		dev_err(dev, "Failed to enable clks: %s\n", strerror(-ret));
+		return ret;
+	}
+
+	return eqos_probe(dev, &imx_ops, priv);
 }
 
 static void eqos_remove_imx(struct device *dev)
-- 
2.39.2




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] net: eqos: Add i.MX93 support
  2023-11-10 13:02 [PATCH 0/3] Add i.MX9 EQOS networking support Sascha Hauer
  2023-11-10 13:02 ` [PATCH 1/3] net: eqos: rename i.MX8 driver glue code to i.MX Sascha Hauer
  2023-11-10 13:02 ` [PATCH 2/3] net: eqos: imx: move common stuff to probe() Sascha Hauer
@ 2023-11-10 13:02 ` Sascha Hauer
  2 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-11-10 13:02 UTC (permalink / raw)
  To: Barebox List

Add the compatible entries and i.MX93 specific init code to make the
driver usable on i.MX93.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/Kconfig          |   2 +-
 drivers/net/designware_imx.c | 124 +++++++++++++++++++++++++++--------
 2 files changed, 97 insertions(+), 29 deletions(-)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 9be03cf20c..86d1c21856 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -109,7 +109,7 @@ config DRIVER_NET_DESIGNWARE_EQOS
 
 config DRIVER_NET_DESIGNWARE_IMX
 	bool "Designware EQOS i.MX Ethernet driver"
-	depends on HAS_DMA && COMMON_CLK && OFTREE && (ARCH_IMX8M || COMPILE_TEST)
+	depends on HAS_DMA && COMMON_CLK && OFTREE && (ARCH_IMX8M || ARCH_IMX93 || COMPILE_TEST)
 	select DRIVER_NET_DESIGNWARE_EQOS
 	select MFD_SYSCON
 	help
diff --git a/drivers/net/designware_imx.c b/drivers/net/designware_imx.c
index 13bca42c25..c281d3b64b 100644
--- a/drivers/net/designware_imx.c
+++ b/drivers/net/designware_imx.c
@@ -17,6 +17,17 @@
 #define GPR_ENET_QOS_CLK_TX_CLK_SEL	BIT(20)
 #define GPR_ENET_QOS_RGMII_EN		BIT(21)
 
+#define MX93_GPR_ENET_QOS_INTF_MODE_MASK	GENMASK(3, 0)
+#define MX93_GPR_ENET_QOS_INTF_MASK		GENMASK(3, 1)
+#define MX93_GPR_ENET_QOS_INTF_SEL_MII		(0x0 << 1)
+#define MX93_GPR_ENET_QOS_INTF_SEL_RMII		(0x4 << 1)
+#define MX93_GPR_ENET_QOS_INTF_SEL_RGMII	(0x1 << 1)
+#define MX93_GPR_ENET_QOS_CLK_GEN_EN		(0x1 << 0)
+
+struct eqos_imx_soc_data {
+	int (*set_interface_mode)(struct eqos *eqos);
+	bool mac_rgmii_txclk_auto_adj;
+};
 
 struct eqos_imx_priv {
 	struct device *dev;
@@ -25,6 +36,7 @@ struct eqos_imx_priv {
 	struct regmap *intf_regmap;
 	u32 intf_reg_off;
 	bool rmii_refclk_ext;
+	struct eqos_imx_soc_data *soc_data;
 };
 
 enum { CLK_STMMACETH, CLK_PCLK, CLK_PTP_REF, CLK_TX};
@@ -42,15 +54,13 @@ static unsigned long eqos_get_csr_clk_rate_imx(struct eqos *eqos)
 	return clk_get_rate(priv->clks[CLK_PCLK].clk);
 }
 
-
-static void eqos_adjust_link_imx(struct eth_device *edev)
+static int eqos_set_txclk(struct eqos *eqos, int speed)
 {
-	struct eqos *eqos = edev->priv;
 	struct eqos_imx_priv *priv = eqos->priv;
 	unsigned long rate;
 	int ret;
 
-	switch (edev->phydev->speed) {
+	switch (speed) {
 	case SPEED_10:
 		rate = 2500000;
 		break;
@@ -61,28 +71,33 @@ static void eqos_adjust_link_imx(struct eth_device *edev)
 		rate = 125000000;
 		break;
 	default:
-		dev_err(priv->dev, "unknown speed value for GMAC speed=%d",
-			edev->phydev->speed);
-		return;
+		dev_err(priv->dev, "unknown speed value for GMAC speed=%d", speed);
+		return -EINVAL;
 	}
 
 	ret = clk_set_rate(priv->clks[CLK_TX].clk, rate);
 	if (ret)
-		dev_err(priv->dev, "set TX clk rate %ld failed %d\n",
-			rate, ret);
+		dev_err(priv->dev, "set TX clk rate %ld failed %d\n", rate, ret);
+
+	return ret;
+}
+
+static void eqos_adjust_link_imx(struct eth_device *edev)
+{
+	struct eqos *eqos = edev->priv;
+	struct eqos_imx_priv *priv = eqos->priv;
+
+	if (!priv->soc_data->mac_rgmii_txclk_auto_adj)
+		eqos_set_txclk(eqos, edev->phydev->speed);
 
 	eqos_adjust_link(edev);
 }
 
-static void eqos_imx_set_interface_mode(struct eqos *eqos)
+static int eqos_imx8mp_set_interface_mode(struct eqos *eqos)
 {
 	struct eqos_imx_priv *priv = eqos->priv;
-	struct device_node *np = priv->dev->device_node;
 	int val;
 
-	if (!of_device_is_compatible(np, "nxp,imx8mp-dwmac-eqos"))
-		return;
-
 	switch (eqos->interface) {
 	case PHY_INTERFACE_MODE_MII:
 		val = GPR_ENET_QOS_INTF_SEL_MII;
@@ -100,34 +115,65 @@ static void eqos_imx_set_interface_mode(struct eqos *eqos)
 		break;
 	default:
 		dev_err(priv->dev, "no valid interface mode found!\n");
-		return;
+		return -EINVAL;
 	}
 
 	val |= GPR_ENET_QOS_CLK_GEN_EN;
 
-	regmap_update_bits(priv->intf_regmap, priv->intf_reg_off,
-			   GPR_ENET_QOS_INTF_MODE_MASK, val);
+	return regmap_update_bits(priv->intf_regmap, priv->intf_reg_off,
+				  GPR_ENET_QOS_INTF_MODE_MASK, val);
 }
 
+static int eqos_imx93_set_interface_mode(struct eqos *eqos)
+{
+	struct eqos_imx_priv *priv = eqos->priv;
+
+	int val;
+
+	switch (eqos->interface) {
+	case PHY_INTERFACE_MODE_MII:
+		val = MX93_GPR_ENET_QOS_INTF_SEL_MII;
+		break;
+	case PHY_INTERFACE_MODE_RMII:
+		val = MX93_GPR_ENET_QOS_INTF_SEL_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 = MX93_GPR_ENET_QOS_INTF_SEL_RGMII;
+		break;
+	default:
+		dev_dbg(priv->dev, "imx dwmac doesn't support %d interface\n",
+			 eqos->interface);
+		return -EINVAL;
+	}
+
+	val |= MX93_GPR_ENET_QOS_CLK_GEN_EN;
+
+	return regmap_update_bits(priv->intf_regmap, priv->intf_reg_off,
+				  MX93_GPR_ENET_QOS_INTF_MODE_MASK, val);
+};
+
 static int eqos_init_imx(struct device *dev, struct eqos *eqos)
 {
 	struct device_node *np = dev->device_node;
 	struct eqos_imx_priv *priv = eqos->priv;
 	int ret;
 
-	if (of_device_is_compatible(np, "nxp,imx8mp-dwmac-eqos")) {
-		priv->intf_regmap = syscon_regmap_lookup_by_phandle(np, "intf_mode");
-		if (IS_ERR(priv->intf_regmap))
-			return PTR_ERR(priv->intf_regmap);
+	priv->intf_regmap = syscon_regmap_lookup_by_phandle(np, "intf_mode");
+	if (IS_ERR(priv->intf_regmap))
+		return PTR_ERR(priv->intf_regmap);
 
-		ret = of_property_read_u32_index(np, "intf_mode", 1, &priv->intf_reg_off);
-		if (ret) {
-			dev_err(dev, "Can't get intf mode reg offset (%d)\n", ret);
-			return ret;
-		}
+	ret = of_property_read_u32_index(np, "intf_mode", 1, &priv->intf_reg_off);
+	if (ret) {
+		dev_err(dev, "Can't get intf mode reg offset (%d)\n", ret);
+		return ret;
 	}
 
-	eqos_imx_set_interface_mode(eqos);
+	ret = priv->soc_data->set_interface_mode(eqos);
+	if (ret)
+		return ret;
 
 	return 0;
 }
@@ -146,11 +192,17 @@ static struct eqos_ops imx_ops = {
 static int eqos_probe_imx(struct device *dev)
 {
 	struct device_node *np = dev->device_node;
+	struct eqos_imx_soc_data *soc_data;
 	struct eqos_imx_priv *priv;
 	int ret;
 
+	ret = dev_get_drvdata(dev, (const void **)&soc_data);
+	if (ret)
+		return ret;
+
 	priv = xzalloc(sizeof(*priv));
 
+	priv->soc_data = soc_data;
 	priv->dev = dev;
 
 	if (of_get_property(np, "snps,rmii_refclk_ext", NULL))
@@ -186,8 +238,24 @@ static void eqos_remove_imx(struct device *dev)
 	clk_bulk_put(priv->num_clks, priv->clks);
 }
 
+static struct eqos_imx_soc_data imx93_soc_data = {
+	.set_interface_mode = eqos_imx93_set_interface_mode,
+	.mac_rgmii_txclk_auto_adj = true,
+};
+
+static struct eqos_imx_soc_data imx8mp_soc_data = {
+	.set_interface_mode = eqos_imx8mp_set_interface_mode,
+	.mac_rgmii_txclk_auto_adj = false,
+};
+
 static __maybe_unused struct of_device_id eqos_imx_ids[] = {
-	{ .compatible = "nxp,imx8mp-dwmac-eqos"},
+	{
+		.compatible = "nxp,imx93-dwmac-eqos",
+		.data = &imx93_soc_data,
+	}, {
+		.compatible = "nxp,imx8mp-dwmac-eqos",
+		.data = &imx8mp_soc_data,
+	},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, eqos_imx_ids);
-- 
2.39.2




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] net: eqos: rename i.MX8 driver glue code to i.MX
  2023-11-10 13:02 ` [PATCH 1/3] net: eqos: rename i.MX8 driver glue code to i.MX Sascha Hauer
@ 2023-11-13  7:19   ` Ahmad Fatoum
  0 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-11-13  7:19 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On 10.11.23 14:02, Sascha Hauer wrote:
> The i.MX8 glue code for the designware ethernet driver will be used by
> i.MX9 as well. Rename the file accordingly.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/configs/imx_v8_defconfig             |  2 +-
>  arch/arm/configs/multi_v8_defconfig           |  2 +-
>  drivers/net/Kconfig                           |  6 +-
>  drivers/net/Makefile                          |  2 +-
>  .../{designware_imx8.c => designware_imx.c}   | 58 +++++++++----------
>  5 files changed, 35 insertions(+), 35 deletions(-)
>  rename drivers/net/{designware_imx8.c => designware_imx.c} (73%)
> 
> diff --git a/arch/arm/configs/imx_v8_defconfig b/arch/arm/configs/imx_v8_defconfig
> index 8084e72ea0..66dab8c4a7 100644
> --- a/arch/arm/configs/imx_v8_defconfig
> +++ b/arch/arm/configs/imx_v8_defconfig
> @@ -92,7 +92,7 @@ CONFIG_NET_NETCONSOLE=y
>  CONFIG_OFDEVICE=y
>  CONFIG_OF_BAREBOX_DRIVERS=y
>  CONFIG_SERIAL_DEV_BUS=y
> -CONFIG_DRIVER_NET_DESIGNWARE_IMX8=y
> +CONFIG_DRIVER_NET_DESIGNWARE_IMX=y
>  CONFIG_DRIVER_NET_FEC_IMX=y
>  CONFIG_DP83867_PHY=y
>  CONFIG_MICREL_PHY=y
> diff --git a/arch/arm/configs/multi_v8_defconfig b/arch/arm/configs/multi_v8_defconfig
> index 9c538e698d..2599519351 100644
> --- a/arch/arm/configs/multi_v8_defconfig
> +++ b/arch/arm/configs/multi_v8_defconfig
> @@ -141,7 +141,7 @@ CONFIG_SERIAL_AMBA_PL011=y
>  CONFIG_DRIVER_SERIAL_NS16550=y
>  CONFIG_DRIVER_SERIAL_CADENCE=y
>  CONFIG_VIRTIO_CONSOLE=y
> -CONFIG_DRIVER_NET_DESIGNWARE_IMX8=y
> +CONFIG_DRIVER_NET_DESIGNWARE_IMX=y
>  CONFIG_DRIVER_NET_DESIGNWARE_ROCKCHIP=y
>  CONFIG_DRIVER_NET_FEC_IMX=y
>  CONFIG_DRIVER_NET_MACB=y
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index 1c89cf9e41..9be03cf20c 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -107,14 +107,14 @@ config DRIVER_NET_DESIGNWARE_EQOS
>  	  This option enables support for the Synopsys
>  	  Designware Ethernet Quality-of-Service (GMAC4).
>  
> -config DRIVER_NET_DESIGNWARE_IMX8
> -	bool "Designware EQOS i.MX8 Ethernet driver"
> +config DRIVER_NET_DESIGNWARE_IMX
> +	bool "Designware EQOS i.MX Ethernet driver"
>  	depends on HAS_DMA && COMMON_CLK && OFTREE && (ARCH_IMX8M || COMPILE_TEST)
>  	select DRIVER_NET_DESIGNWARE_EQOS
>  	select MFD_SYSCON

Please add an imply of a def_bool, so existing users with i.MX8MP defconfigs
don't lose driver support on an olddefconfig.

>  	help
>  	  This option enables support for the Designware EQOS MAC implemented on
> -	  the NXP i.MX8 SoCs.
> +	  the NXP i.MX SoCs.
>  
>  config DRIVER_NET_DESIGNWARE_STM32
>  	bool "STM32 Designware Ethernet driver"
> diff --git a/drivers/net/Makefile b/drivers/net/Makefile
> index 1a272d9158..697b5bdfb7 100644
> --- a/drivers/net/Makefile
> +++ b/drivers/net/Makefile
> @@ -15,7 +15,7 @@ obj-$(CONFIG_DRIVER_NET_DESIGNWARE_GENERIC) += designware_generic.o
>  obj-$(CONFIG_DRIVER_NET_DESIGNWARE_SOCFPGA) += designware_socfpga.o
>  obj-$(CONFIG_DRIVER_NET_DESIGNWARE_STARFIVE) += designware_starfive.o
>  obj-$(CONFIG_DRIVER_NET_DESIGNWARE_EQOS) += designware_eqos.o
> -obj-$(CONFIG_DRIVER_NET_DESIGNWARE_IMX8) += designware_imx8.o
> +obj-$(CONFIG_DRIVER_NET_DESIGNWARE_IMX) += designware_imx.o
>  obj-$(CONFIG_DRIVER_NET_DESIGNWARE_STM32) += designware_stm32.o
>  obj-$(CONFIG_DRIVER_NET_DESIGNWARE_TEGRA186) += designware_tegra186.o
>  obj-$(CONFIG_DRIVER_NET_DESIGNWARE_ROCKCHIP) += designware_rockchip.o
> diff --git a/drivers/net/designware_imx8.c b/drivers/net/designware_imx.c
> similarity index 73%
> rename from drivers/net/designware_imx8.c
> rename to drivers/net/designware_imx.c
> index 73a16d5e65..00164fa7c7 100644
> --- a/drivers/net/designware_imx8.c
> +++ b/drivers/net/designware_imx.c
> @@ -18,7 +18,7 @@
>  #define GPR_ENET_QOS_RGMII_EN		BIT(21)
>  
>  
> -struct eqos_imx8_priv {
> +struct eqos_imx_priv {
>  	struct device *dev;
>  	struct clk_bulk_data *clks;
>  	int num_clks;
> @@ -28,25 +28,25 @@ struct eqos_imx8_priv {
>  };
>  
>  enum { CLK_STMMACETH, CLK_PCLK, CLK_PTP_REF, CLK_TX};
> -static const struct clk_bulk_data imx8_clks[] = {
> +static const struct clk_bulk_data imx_clks[] = {
>  	[CLK_STMMACETH] = { .id = "stmmaceth" },
>  	[CLK_PCLK]      = { .id = "pclk" },
>  	[CLK_PTP_REF]   = { .id = "ptp_ref" },
>  	[CLK_TX]        = { .id = "tx" },
>  };
>  
> -static unsigned long eqos_get_csr_clk_rate_imx8(struct eqos *eqos)
> +static unsigned long eqos_get_csr_clk_rate_imx(struct eqos *eqos)
>  {
> -	struct eqos_imx8_priv *priv = eqos->priv;
> +	struct eqos_imx_priv *priv = eqos->priv;
>  
>  	return clk_get_rate(priv->clks[CLK_PCLK].clk);
>  }
>  
>  
> -static void eqos_adjust_link_imx8(struct eth_device *edev)
> +static void eqos_adjust_link_imx(struct eth_device *edev)
>  {
>  	struct eqos *eqos = edev->priv;
> -	struct eqos_imx8_priv *priv = eqos->priv;
> +	struct eqos_imx_priv *priv = eqos->priv;
>  	unsigned long rate;
>  	int ret;
>  
> @@ -74,9 +74,9 @@ static void eqos_adjust_link_imx8(struct eth_device *edev)
>  	eqos_adjust_link(edev);
>  }
>  
> -static void eqos_imx8_set_interface_mode(struct eqos *eqos)
> +static void eqos_imx_set_interface_mode(struct eqos *eqos)
>  {
> -	struct eqos_imx8_priv *priv = eqos->priv;
> +	struct eqos_imx_priv *priv = eqos->priv;
>  	struct device_node *np = priv->dev->device_node;
>  	int val;
>  
> @@ -109,10 +109,10 @@ static void eqos_imx8_set_interface_mode(struct eqos *eqos)
>  			   GPR_ENET_QOS_INTF_MODE_MASK, val);
>  }
>  
> -static int eqos_init_imx8(struct device *dev, struct eqos *eqos)
> +static int eqos_init_imx(struct device *dev, struct eqos *eqos)
>  {
>  	struct device_node *np = dev->device_node;
> -	struct eqos_imx8_priv *priv = eqos->priv;
> +	struct eqos_imx_priv *priv = eqos->priv;
>  	int ret;
>  
>  	priv->dev = dev;
> @@ -132,9 +132,9 @@ static int eqos_init_imx8(struct device *dev, struct eqos *eqos)
>  		}
>  	}
>  
> -	priv->num_clks = ARRAY_SIZE(imx8_clks);
> +	priv->num_clks = ARRAY_SIZE(imx_clks);
>  	priv->clks = xmalloc(priv->num_clks * sizeof(*priv->clks));
> -	memcpy(priv->clks, imx8_clks, sizeof imx8_clks);
> +	memcpy(priv->clks, imx_clks, sizeof imx_clks);
>  
>  	ret = clk_bulk_get(dev, priv->num_clks, priv->clks);
>  	if (ret) {
> @@ -148,31 +148,31 @@ static int eqos_init_imx8(struct device *dev, struct eqos *eqos)
>  		return ret;
>  	}
>  
> -	eqos_imx8_set_interface_mode(eqos);
> +	eqos_imx_set_interface_mode(eqos);
>  
>  	return 0;
>  }
>  
> -static struct eqos_ops imx8_ops = {
> -	.init = eqos_init_imx8,
> +static struct eqos_ops imx_ops = {
> +	.init = eqos_init_imx,
>  	.get_ethaddr = eqos_get_ethaddr,
>  	.set_ethaddr = eqos_set_ethaddr,
> -	.adjust_link = eqos_adjust_link_imx8,
> -	.get_csr_clk_rate = eqos_get_csr_clk_rate_imx8,
> +	.adjust_link = eqos_adjust_link_imx,
> +	.get_csr_clk_rate = eqos_get_csr_clk_rate_imx,
>  
>  	.clk_csr = EQOS_MDIO_ADDR_CR_250_300,
>  	.config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB,
>  };
>  
> -static int eqos_probe_imx8(struct device *dev)
> +static int eqos_probe_imx(struct device *dev)
>  {
> -	return eqos_probe(dev, &imx8_ops, xzalloc(sizeof(struct eqos_imx8_priv)));
> +	return eqos_probe(dev, &imx_ops, xzalloc(sizeof(struct eqos_imx_priv)));
>  }
>  
> -static void eqos_remove_imx8(struct device *dev)
> +static void eqos_remove_imx(struct device *dev)
>  {
>  	struct eqos *eqos = dev->priv;
> -	struct eqos_imx8_priv *priv = eqos->priv;
> +	struct eqos_imx_priv *priv = eqos->priv;
>  
>  	eqos_remove(dev);
>  
> @@ -180,16 +180,16 @@ static void eqos_remove_imx8(struct device *dev)
>  	clk_bulk_put(priv->num_clks, priv->clks);
>  }
>  
> -static __maybe_unused struct of_device_id eqos_imx8_ids[] = {
> +static __maybe_unused struct of_device_id eqos_imx_ids[] = {
>  	{ .compatible = "nxp,imx8mp-dwmac-eqos"},
>  	{ /* sentinel */ }
>  };
> -MODULE_DEVICE_TABLE(of, eqos_imx8_ids);
> +MODULE_DEVICE_TABLE(of, eqos_imx_ids);
>  
> -static struct driver eqos_imx8_driver = {
> -	.name = "eqos-imx8",
> -	.probe = eqos_probe_imx8,
> -	.remove = eqos_remove_imx8,
> -	.of_compatible = DRV_OF_COMPAT(eqos_imx8_ids),
> +static struct driver eqos_imx_driver = {
> +	.name = "eqos-imx",
> +	.probe = eqos_probe_imx,
> +	.remove = eqos_remove_imx,
> +	.of_compatible = DRV_OF_COMPAT(eqos_imx_ids),
>  };
> -device_platform_driver(eqos_imx8_driver);
> +device_platform_driver(eqos_imx_driver);

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-13  7:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-10 13:02 [PATCH 0/3] Add i.MX9 EQOS networking support Sascha Hauer
2023-11-10 13:02 ` [PATCH 1/3] net: eqos: rename i.MX8 driver glue code to i.MX Sascha Hauer
2023-11-13  7:19   ` Ahmad Fatoum
2023-11-10 13:02 ` [PATCH 2/3] net: eqos: imx: move common stuff to probe() Sascha Hauer
2023-11-10 13:02 ` [PATCH 3/3] net: eqos: Add i.MX93 support Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox