[RFC PATCH 3/3] net: tsec: convert fsl_pq_mdio to DM_MDIO

Vladimir Oltean olteanv at gmail.com
Sun May 3 20:52:27 CEST 2020


From: Vladimir Oltean <vladimir.oltean at nxp.com>

For the platforms on which the eTSEC driver uses DM_ETH, convert its
MDIO controller code to also use DM_MDIO.

Note that for handling the TBI PHY (the MAC PCS for SGMII), we still
don't register a udevice for it, since we can drive it locally and there
is no point in doing otherwise.

Signed-off-by: Vladimir Oltean <vladimir.oltean at nxp.com>
---
 drivers/net/fsl_mdio.c | 66 ++++++++++++++++++++++++++++++++++++++----
 drivers/net/tsec.c     | 50 ++++++++++----------------------
 include/fsl_mdio.h     |  4 +--
 3 files changed, 78 insertions(+), 42 deletions(-)

diff --git a/drivers/net/fsl_mdio.c b/drivers/net/fsl_mdio.c
index 894b52ee66f4..284508062c8e 100644
--- a/drivers/net/fsl_mdio.c
+++ b/drivers/net/fsl_mdio.c
@@ -8,9 +8,11 @@
 #include <common.h>
 #include <miiphy.h>
 #include <phy.h>
+#include <miiphy.h>
 #include <fsl_mdio.h>
 #include <asm/io.h>
 #include <linux/errno.h>
+#include <tsec.h>
 
 void tsec_local_mdio_write(struct tsec_mii_mng __iomem *phyregs, int port_addr,
 		int dev_addr, int regnum, int value)
@@ -56,11 +58,8 @@ int tsec_local_mdio_read(struct tsec_mii_mng __iomem *phyregs, int port_addr,
 	return value;
 }
 
-static int fsl_pq_mdio_reset(struct mii_dev *bus)
+int fsl_pq_mdio_reset(struct tsec_mii_mng __iomem *regs)
 {
-	struct tsec_mii_mng __iomem *regs =
-		(struct tsec_mii_mng __iomem *)bus->priv;
-
 	/* Reset MII (due to new addresses) */
 	out_be32(&regs->miimcfg, MIIMCFG_RESET_MGMT);
 
@@ -72,6 +71,7 @@ static int fsl_pq_mdio_reset(struct mii_dev *bus)
 	return 0;
 }
 
+#ifndef CONFIG_DM_MDIO
 int tsec_phy_read(struct mii_dev *bus, int addr, int dev_addr, int regnum)
 {
 	struct tsec_mii_mng __iomem *phyregs =
@@ -91,6 +91,11 @@ int tsec_phy_write(struct mii_dev *bus, int addr, int dev_addr, int regnum,
 	return 0;
 }
 
+static int tsec_mdio_reset(struct mii_dev *bus)
+{
+	return fsl_pq_mdio_reset(bus->priv);
+}
+
 int fsl_pq_mdio_init(bd_t *bis, struct fsl_pq_mdio_info *info)
 {
 	struct mii_dev *bus = mdio_alloc();
@@ -102,10 +107,61 @@ int fsl_pq_mdio_init(bd_t *bis, struct fsl_pq_mdio_info *info)
 
 	bus->read = tsec_phy_read;
 	bus->write = tsec_phy_write;
-	bus->reset = fsl_pq_mdio_reset;
+	bus->reset = tsec_mdio_reset;
 	strcpy(bus->name, info->name);
 
 	bus->priv = (void *)info->regs;
 
 	return mdio_register(bus);
 }
+#endif
+
+#ifdef CONFIG_DM_MDIO
+static int dm_fsl_pq_mdio_read(struct udevice *dev, int addr, int devad,
+			       int reg)
+{
+	struct fsl_pq_mdio_info *info = dev_get_priv(dev);
+
+	return tsec_local_mdio_read(info->regs, addr, devad, reg);
+}
+
+static int dm_fsl_pq_mdio_write(struct udevice *dev, int addr, int devad,
+				int reg, u16 val)
+{
+	struct fsl_pq_mdio_info *info = dev_get_priv(dev);
+
+	tsec_local_mdio_write(info->regs, addr, devad, reg, val);
+
+	return 0;
+}
+
+static int fsl_pq_mdio_probe(struct udevice *dev)
+{
+	struct fsl_pq_mdio_info *info = dev_get_priv(dev);
+	fdt_addr_t reg;
+
+	reg = devfdt_get_addr(dev);
+	info->regs = map_physmem(reg + TSEC_MDIO_REGS_OFFSET, 0, MAP_NOCACHE);
+
+	return fsl_pq_mdio_reset(info->regs);
+}
+
+static const struct mdio_ops fsl_pq_mdio_ops = {
+	.read			= dm_fsl_pq_mdio_read,
+	.write			= dm_fsl_pq_mdio_write,
+};
+
+static const struct udevice_id fsl_pq_mdio_ids[] = {
+	{ .compatible = "fsl,etsec2-mdio" },
+	{ }
+};
+
+U_BOOT_DRIVER(fsl_pq_mdio) = {
+	.name			= "fsl_pq_mdio",
+	.id			= UCLASS_MDIO,
+	.of_match		= fsl_pq_mdio_ids,
+	.probe			= fsl_pq_mdio_probe,
+	.ops			= &fsl_pq_mdio_ops,
+	.priv_auto_alloc_size	= sizeof(struct fsl_pq_mdio_info),
+};
+#endif
diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c
index 842cddf2297a..93f151a8a6db 100644
--- a/drivers/net/tsec.c
+++ b/drivers/net/tsec.c
@@ -15,6 +15,7 @@
 #include <command.h>
 #include <tsec.h>
 #include <fsl_mdio.h>
+#include <miiphy.h>
 #include <linux/errno.h>
 #include <asm/processor.h>
 #include <asm/io.h>
@@ -679,8 +680,15 @@ static int init_phy(struct tsec_private *priv)
 	if (priv->interface == PHY_INTERFACE_MODE_SGMII)
 		tsec_configure_serdes(priv);
 
+#ifdef CONFIG_DM_ETH
+	if (ofnode_valid(ofnode_find_subnode(priv->dev->node, "fixed-link")))
+		phydev = phy_connect(NULL, 0, priv->dev, priv->interface);
+	else
+		phydev = dm_eth_phy_connect(priv->dev);
+#else
 	phydev = phy_connect(priv->bus, priv->phyaddr, priv->dev,
 			     priv->interface);
+#endif
 	if (!phydev)
 		return 0;
 
@@ -785,14 +793,17 @@ int tsec_standard_init(bd_t *bis)
 	return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info));
 }
 #else /* CONFIG_DM_ETH */
+
+#ifndef CONFIG_DM_MDIO
+#error "TSEC with DM_ETH also requires DM_MDIO"
+#endif
+
 int tsec_probe(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
 	struct tsec_private *priv = dev_get_priv(dev);
-	struct tsec_mii_mng __iomem *ext_phyregs_mii;
 	struct ofnode_phandle_args phandle_args;
 	u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE;
-	struct fsl_pq_mdio_info mdio_info;
 	const char *phy_mode;
 	fdt_addr_t reg;
 	ofnode parent;
@@ -801,31 +812,6 @@ int tsec_probe(struct udevice *dev)
 	pdata->iobase = (phys_addr_t)dev_read_addr(dev);
 	priv->regs = dev_remap_addr(dev);
 
-	if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
-				       &phandle_args)) {
-		printf("phy-handle does not exist under tsec %s\n", dev->name);
-		return -ENOENT;
-	} else {
-		int reg = ofnode_read_u32_default(phandle_args.node, "reg", 0);
-
-		priv->phyaddr = reg;
-	}
-
-	parent = ofnode_get_parent(phandle_args.node);
-	if (!ofnode_valid(parent)) {
-		printf("No parent node for PHY?\n");
-		return -ENOENT;
-	}
-
-	reg = ofnode_get_addr_index(parent, 0);
-	if (reg == FDT_ADDR_T_NONE) {
-		printf("No 'reg' property of MII for external PHY\n");
-		return -ENOENT;
-	}
-
-	ext_phyregs_mii = map_physmem(reg + TSEC_MDIO_REGS_OFFSET, 0,
-				      MAP_NOCACHE);
-
 	ret = dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0,
 					 &phandle_args);
 	if (ret == 0) {
@@ -860,14 +846,10 @@ int tsec_probe(struct udevice *dev)
 
 	/* Initialize flags */
 	priv->flags = TSEC_GIGABIT;
-	if (priv->interface == PHY_INTERFACE_MODE_SGMII)
+	if (priv->interface == PHY_INTERFACE_MODE_SGMII) {
 		priv->flags |= TSEC_SGMII;
-
-	mdio_info.regs = ext_phyregs_mii;
-	mdio_info.name = (char *)dev->name;
-	ret = fsl_pq_mdio_init(NULL, &mdio_info);
-	if (ret)
-		return ret;
+		fsl_pq_mdio_reset(priv->phyregs_sgmii);
+	}
 
 	/* Reset the MAC */
 	setbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
diff --git a/include/fsl_mdio.h b/include/fsl_mdio.h
index b87346ce7ca1..11a6d588aff3 100644
--- a/include/fsl_mdio.h
+++ b/include/fsl_mdio.h
@@ -46,9 +46,7 @@ void tsec_local_mdio_write(struct tsec_mii_mng __iomem *phyregs, int port_addr,
 		int dev_addr, int reg, int value);
 int tsec_local_mdio_read(struct tsec_mii_mng __iomem *phyregs, int port_addr,
 		int dev_addr, int regnum);
-int tsec_phy_read(struct mii_dev *bus, int addr, int dev_addr, int regnum);
-int tsec_phy_write(struct mii_dev *bus, int addr, int dev_addr, int regnum,
-		u16 value);
+int fsl_pq_mdio_reset(struct tsec_mii_mng __iomem *regs);
 int memac_mdio_write(struct mii_dev *bus, int port_addr, int dev_addr,
 		int regnum, u16 value);
 int memac_mdio_read(struct mii_dev *bus, int port_addr, int dev_addr,
-- 
2.17.1



More information about the U-Boot mailing list