public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: u-boot@lists.denx.de
Subject: [RFC PATCH 3/3] net: tsec: convert fsl_pq_mdio to DM_MDIO
Date: Sun,  3 May 2020 21:52:27 +0300	[thread overview]
Message-ID: <20200503185227.28731-4-olteanv@gmail.com> (raw)
In-Reply-To: <20200503185227.28731-1-olteanv@gmail.com>

From: Vladimir Oltean <vladimir.oltean@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@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

  parent reply	other threads:[~2020-05-03 18:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-03 18:52 [RFC PATCH 0/3] DM_MDIO for fsl_tsec driver Vladimir Oltean
2020-05-03 18:52 ` [RFC PATCH 1/3] phy: make phy_connect_fixed work with a null mdio bus Vladimir Oltean
2020-05-04  6:08   ` Z.q. Hou
2020-05-03 18:52 ` [RFC PATCH 2/3] configs: enable DM_MDIO for LS1021A-TWR and LS1021A-TSN Vladimir Oltean
2020-05-03 18:52 ` Vladimir Oltean [this message]
2020-05-04  6:22   ` [RFC PATCH 3/3] net: tsec: convert fsl_pq_mdio to DM_MDIO Z.q. Hou
2020-05-04  8:06     ` Vladimir Oltean
2020-05-05  9:34   ` Madalin Bucur
2020-07-15 10:37     ` Priyanka Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200503185227.28731-4-olteanv@gmail.com \
    --to=olteanv@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox