public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq@kernel.org>
To: joe.hershberger@ni.com, nm@ti.com
Cc: rfried.dev@gmail.com, r-gunasekaran@ti.com, s-vadapalli@ti.com,
	mripard@kernel.org, sjg@chromium.org, pbrobinson@gmail.com,
	srk@ti.com, u-boot@lists.denx.de,
	Roger Quadros <rogerq@kernel.org>
Subject: [PATCH v2 2/4] net: ti: am65-cpsw-nuss: Get port mode register from standard "phys" property
Date: Sat, 22 Jul 2023 22:31:49 +0300	[thread overview]
Message-ID: <20230722193151.117345-3-rogerq@kernel.org> (raw)
In-Reply-To: <20230722193151.117345-1-rogerq@kernel.org>

Approved DT binding has the port mode register in the
"phys" property. Get it from there instead of the custom
"cpsw-phy-sel" property.

This will allow us to keep DT in sync with Linux.

Signed-off-by: Roger Quadros <rogerq@kernel.org>
---
 drivers/net/ti/am65-cpsw-nuss.c | 63 +++++++++++++++++++--------------
 1 file changed, 37 insertions(+), 26 deletions(-)

diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
index ee46676ec8..ce52106e52 100644
--- a/drivers/net/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ti/am65-cpsw-nuss.c
@@ -102,7 +102,6 @@ struct am65_cpsw_common {
 	fdt_addr_t		cpsw_base;
 	fdt_addr_t		mdio_base;
 	fdt_addr_t		ale_base;
-	fdt_addr_t		gmii_sel;
 
 	struct clk		fclk;
 	struct power_domain	pwrdmn;
@@ -232,18 +231,37 @@ out:
 
 #define AM65_GMII_SEL_RGMII_IDMODE	BIT(4)
 
-static void am65_cpsw_gmii_sel_k3(struct am65_cpsw_priv *priv,
-				  phy_interface_t phy_mode, int slave)
+static int am65_cpsw_gmii_sel_k3(struct am65_cpsw_priv *priv,
+				 phy_interface_t phy_mode)
 {
-	struct am65_cpsw_common	*common = priv->cpsw_common;
-	fdt_addr_t gmii_sel = common->gmii_sel + AM65_GMII_SEL_PORT_OFFS(slave);
-	u32 reg;
-	u32 mode = 0;
+	struct udevice *dev = priv->dev;
+	u32 offset, reg, phandle;
 	bool rgmii_id = false;
+	fdt_addr_t gmii_sel;
+	u32 mode = 0;
+	ofnode node;
+	int ret;
+
+	ret = ofnode_read_u32(dev_ofnode(dev), "phys", &phandle);
+	if (ret)
+		return ret;
+
+	ret = ofnode_read_u32_index(dev_ofnode(dev), "phys", 1, &offset);
+	if (ret)
+		return ret;
+
+	node = ofnode_get_by_phandle(phandle);
+	if (!ofnode_valid(node))
+		return -ENODEV;
+
+	gmii_sel = ofnode_get_addr(node);
+	if (gmii_sel == FDT_ADDR_T_NONE)
+		return -ENODEV;
 
+	gmii_sel += AM65_GMII_SEL_PORT_OFFS(offset);
 	reg = readl(gmii_sel);
 
-	dev_dbg(common->dev, "old gmii_sel: %08x\n", reg);
+	dev_dbg(dev, "old gmii_sel: %08x\n", reg);
 
 	switch (phy_mode) {
 	case PHY_INTERFACE_MODE_RMII:
@@ -262,7 +280,7 @@ static void am65_cpsw_gmii_sel_k3(struct am65_cpsw_priv *priv,
 		break;
 
 	default:
-		dev_warn(common->dev,
+		dev_warn(dev,
 			 "Unsupported PHY mode: %u. Defaulting to MII.\n",
 			 phy_mode);
 		/* fallthrough */
@@ -275,15 +293,19 @@ static void am65_cpsw_gmii_sel_k3(struct am65_cpsw_priv *priv,
 		mode |= AM65_GMII_SEL_RGMII_IDMODE;
 
 	reg = mode;
-	dev_dbg(common->dev, "gmii_sel PHY mode: %u, new gmii_sel: %08x\n",
+	dev_dbg(dev, "gmii_sel PHY mode: %u, new gmii_sel: %08x\n",
 		phy_mode, reg);
 	writel(reg, gmii_sel);
 
 	reg = readl(gmii_sel);
-	if (reg != mode)
-		dev_err(common->dev,
+	if (reg != mode) {
+		dev_err(dev,
 			"gmii_sel PHY mode NOT SET!: requested: %08x, gmii_sel: %08x\n",
 			mode, reg);
+		return 0;
+	}
+
+	return 0;
 }
 
 static int am65_cpsw_start(struct udevice *dev)
@@ -708,7 +730,9 @@ static int am65_cpsw_port_probe(struct udevice *dev)
 	if (ret)
 		goto out;
 
-	am65_cpsw_gmii_sel_k3(priv, pdata->phy_interface, priv->port_id);
+	ret = am65_cpsw_gmii_sel_k3(priv, pdata->phy_interface);
+	if (ret)
+		goto out;
 
 	ret = am65_cpsw_mdio_init(dev);
 	if (ret)
@@ -803,19 +827,6 @@ static int am65_cpsw_probe_nuss(struct udevice *dev)
 				   AM65_CPSW_CPSW_NU_PORT_MACSL_OFFSET;
 	}
 
-	node = dev_read_subnode(dev, "cpsw-phy-sel");
-	if (!ofnode_valid(node)) {
-		dev_err(dev, "can't find cpsw-phy-sel\n");
-		ret = -ENOENT;
-		goto out;
-	}
-
-	cpsw_common->gmii_sel = ofnode_get_addr(node);
-	if (cpsw_common->gmii_sel == FDT_ADDR_T_NONE) {
-		dev_err(dev, "failed to get gmii_sel base\n");
-		goto out;
-	}
-
 	cpsw_common->bus_freq =
 			dev_read_u32_default(dev, "bus_freq",
 					     AM65_CPSW_MDIO_BUS_FREQ_DEF);
-- 
2.34.1


  parent reply	other threads:[~2023-07-22 19:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-22 19:31 [PATCH v2 0/4] net: ti: am65-cpsw-nuss: Drop custom properties Roger Quadros
2023-07-22 19:31 ` [PATCH v2 1/4] net: ti: am65-cpsw-nuss: Use approved property to get efuse address Roger Quadros
2023-07-27  8:02   ` Nishanth Menon
2023-07-28 16:49   ` Tom Rini
2023-07-22 19:31 ` Roger Quadros [this message]
2023-07-27  8:02   ` [PATCH v2 2/4] net: ti: am65-cpsw-nuss: Get port mode register from standard "phys" property Nishanth Menon
2023-07-28 16:49   ` Tom Rini
2023-07-22 19:31 ` [RFC PATCH v2 3/4] arm: dts: k3-am625-sk-u-boot.dtsi: drop mac_efuse Roger Quadros
2023-07-22 19:31 ` [RFC PATCH v2 4/4] arm: dts: k3-am625-sk-u-boot.dtsi: drop cpsw-phy-sel property Roger Quadros
2023-07-24  8:29 ` [PATCH v2 0/4] net: ti: am65-cpsw-nuss: Drop custom properties Maxime Ripard
2023-07-28 12:58 ` Marcel Ziswiler

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=20230722193151.117345-3-rogerq@kernel.org \
    --to=rogerq@kernel.org \
    --cc=joe.hershberger@ni.com \
    --cc=mripard@kernel.org \
    --cc=nm@ti.com \
    --cc=pbrobinson@gmail.com \
    --cc=r-gunasekaran@ti.com \
    --cc=rfried.dev@gmail.com \
    --cc=s-vadapalli@ti.com \
    --cc=sjg@chromium.org \
    --cc=srk@ti.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