U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Chintan Vankar <c-vankar@ti.com>
To: Michael Walle <mwalle@kernel.org>,
	Matthias Schiffer <matthias.schiffer@ew.tq-group.com>,
	MD Danish Anwar <danishanwar@ti.com>,
	Roger Quadros <rogerq@kernel.org>, Hari Nagalla <hnagalla@ti.com>,
	"Manorit Chawdhry" <m-chawdhry@ti.com>,
	Jonathan Humphreys <j-humphreys@ti.com>,
	Santhosh Kumar K <s-k6@ti.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Neha Malcom Francis <n-francis@ti.com>,
	Andreas Dannenberg <dannenberg@ti.com>, Andrew Davis <afd@ti.com>,
	"Alexander Sverdlin" <alexander.sverdlin@siemens.com>,
	Joao Paulo Goncalves <joao.goncalves@toradex.com>,
	Kishon Vijay Abraham I <kishon@ti.com>,
	"Chintan Vankar" <c-vankar@ti.com>,
	Wadim Egorov <w.egorov@phytec.de>,
	Ramon Fried <rfried.dev@gmail.com>,
	Joe Hershberger <joe.hershberger@ni.com>,
	"Jayesh Choudhary" <j-choudhary@ti.com>,
	Vaishnav Achath <vaishnav.a@ti.com>, "Bryan Brattlof" <bb@ti.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Tom Rini <trini@konsulko.com>
Cc: <s-vadapalli@ti.com>, <u-boot@lists.denx.de>
Subject: [PATCH v3 01/15] net: ti: am65-cpsw-nuss: Define bind method for CPSW driver
Date: Tue, 25 Feb 2025 17:18:49 +0530	[thread overview]
Message-ID: <20250225114903.2080616-2-c-vankar@ti.com> (raw)
In-Reply-To: <20250225114903.2080616-1-c-vankar@ti.com>

CPSW driver is defined as UCLASS_MISC driver which needs to be probed
explicitly. Define bind method for CPSW driver to scan and bind
ethernet-ports with UCLASS_ETH driver which will eventually probe CPSW
driver and avoids probing CPSW driver explicitly.

Signed-off-by: Chintan Vankar <c-vankar@ti.com>
---

Link to v2:
https://lore.kernel.org/r/20250219104831.2315464-3-c-vankar@ti.com/

Changes from v2 to v3:
- Removed if condition not required in CPSW driver as suggested by
  Alexander Sverdlin.

 drivers/net/ti/am65-cpsw-nuss.c | 120 ++++++++++++++++++--------------
 1 file changed, 67 insertions(+), 53 deletions(-)

diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
index c70b42f6bcc..10513cf92f2 100644
--- a/drivers/net/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ti/am65-cpsw-nuss.c
@@ -667,6 +667,59 @@ static int am65_cpsw_ofdata_parse_phy(struct udevice *dev)
 	return 0;
 }
 
+static int am65_cpsw_probe_nuss(struct udevice *dev)
+{
+	struct am65_cpsw_common *cpsw_common = dev_get_priv(dev);
+	int ret, i;
+
+	cpsw_common->dev = dev;
+	cpsw_common->ss_base = dev_read_addr(dev);
+	if (cpsw_common->ss_base == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	ret = power_domain_get_by_index(dev, &cpsw_common->pwrdmn, 0);
+	if (ret) {
+		dev_err(dev, "failed to get pwrdmn: %d\n", ret);
+		return ret;
+	}
+
+	ret = clk_get_by_name(dev, "fck", &cpsw_common->fclk);
+	if (ret) {
+		power_domain_free(&cpsw_common->pwrdmn);
+		dev_err(dev, "failed to get clock %d\n", ret);
+		return ret;
+	}
+
+	cpsw_common->cpsw_base = cpsw_common->ss_base + AM65_CPSW_CPSW_NU_BASE;
+	cpsw_common->ale_base = cpsw_common->cpsw_base +
+				AM65_CPSW_CPSW_NU_ALE_BASE;
+
+	for (i = 0; i < AM65_CPSW_CPSWNU_MAX_PORTS; i++) {
+		struct am65_cpsw_port *port = &cpsw_common->ports[i];
+
+		port->port_base = cpsw_common->cpsw_base +
+				  AM65_CPSW_CPSW_NU_PORTS_OFFSET +
+				  (i * AM65_CPSW_CPSW_NU_PORTS_OFFSET);
+		port->port_sgmii_base = cpsw_common->ss_base +
+					(i * AM65_CPSW_SGMII_BASE);
+		port->macsl_base = port->port_base +
+				   AM65_CPSW_CPSW_NU_PORT_MACSL_OFFSET;
+	}
+
+	cpsw_common->bus_freq =
+			dev_read_u32_default(dev, "bus_freq",
+					     AM65_CPSW_MDIO_BUS_FREQ_DEF);
+
+	dev_info(dev, "K3 CPSW: nuss_ver: 0x%08X cpsw_ver: 0x%08X ale_ver: 0x%08X Ports:%u\n",
+		 readl(cpsw_common->ss_base),
+		 readl(cpsw_common->cpsw_base),
+		 readl(cpsw_common->ale_base),
+		 cpsw_common->port_num);
+
+	power_domain_free(&cpsw_common->pwrdmn);
+	return ret;
+}
+
 static int am65_cpsw_port_probe(struct udevice *dev)
 {
 	struct am65_cpsw_priv *priv = dev_get_priv(dev);
@@ -697,45 +750,30 @@ out:
 	return ret;
 }
 
-static int am65_cpsw_probe_nuss(struct udevice *dev)
+static int am65_cpsw_nuss_bind(struct udevice *dev)
 {
 	struct am65_cpsw_common *cpsw_common = dev_get_priv(dev);
-	ofnode ports_np, node;
-	int ret, i;
+	struct uclass_driver *drv;
 	struct udevice *port_dev;
+	ofnode ports_np, node;
+	int ret;
 
-	cpsw_common->dev = dev;
-	cpsw_common->ss_base = dev_read_addr(dev);
-	if (cpsw_common->ss_base == FDT_ADDR_T_NONE)
-		return -EINVAL;
-
-	ret = power_domain_get_by_index(dev, &cpsw_common->pwrdmn, 0);
-	if (ret) {
-		dev_err(dev, "failed to get pwrdmn: %d\n", ret);
-		return ret;
-	}
-
-	ret = clk_get_by_name(dev, "fck", &cpsw_common->fclk);
-	if (ret) {
-		power_domain_free(&cpsw_common->pwrdmn);
-		dev_err(dev, "failed to get clock %d\n", ret);
-		return ret;
+	drv = lists_uclass_lookup(UCLASS_ETH);
+	if (!drv) {
+		puts("Cannot find eth driver");
+		return -ENOENT;
 	}
 
-	cpsw_common->cpsw_base = cpsw_common->ss_base + AM65_CPSW_CPSW_NU_BASE;
-	cpsw_common->ale_base = cpsw_common->cpsw_base +
-				AM65_CPSW_CPSW_NU_ALE_BASE;
-
+	cpsw_common->dev = dev;
 	ports_np = dev_read_subnode(dev, "ethernet-ports");
 	if (!ofnode_valid(ports_np)) {
-		ret = -ENOENT;
-		goto out;
+		return -ENOENT;
 	}
 
 	ofnode_for_each_subnode(node, ports_np) {
 		const char *node_name;
-		u32 port_id;
 		bool disabled;
+		u32 port_id;
 
 		node_name = ofnode_get_name(node);
 
@@ -745,14 +783,13 @@ static int am65_cpsw_probe_nuss(struct udevice *dev)
 		if (ret) {
 			dev_err(dev, "%s: failed to get port_id (%d)\n",
 				node_name, ret);
-			goto out;
+			return ret;
 		}
 
 		if (port_id >= AM65_CPSW_CPSWNU_MAX_PORTS) {
 			dev_err(dev, "%s: invalid port_id (%d)\n",
 				node_name, port_id);
-			ret = -EINVAL;
-			goto out;
+			return -EINVAL;
 		}
 		cpsw_common->port_num++;
 
@@ -768,30 +805,6 @@ static int am65_cpsw_probe_nuss(struct udevice *dev)
 			dev_err(dev, "Failed to bind to %s node\n", ofnode_get_name(node));
 	}
 
-	for (i = 0; i < AM65_CPSW_CPSWNU_MAX_PORTS; i++) {
-		struct am65_cpsw_port *port = &cpsw_common->ports[i];
-
-		port->port_base = cpsw_common->cpsw_base +
-				  AM65_CPSW_CPSW_NU_PORTS_OFFSET +
-				  (i * AM65_CPSW_CPSW_NU_PORTS_OFFSET);
-		port->port_sgmii_base = cpsw_common->ss_base +
-					(i * AM65_CPSW_SGMII_BASE);
-		port->macsl_base = port->port_base +
-				   AM65_CPSW_CPSW_NU_PORT_MACSL_OFFSET;
-	}
-
-	cpsw_common->bus_freq =
-			dev_read_u32_default(dev, "bus_freq",
-					     AM65_CPSW_MDIO_BUS_FREQ_DEF);
-
-	dev_info(dev, "K3 CPSW: nuss_ver: 0x%08X cpsw_ver: 0x%08X ale_ver: 0x%08X Ports:%u\n",
-		 readl(cpsw_common->ss_base),
-		 readl(cpsw_common->cpsw_base),
-		 readl(cpsw_common->ale_base),
-		 cpsw_common->port_num);
-
-out:
-	power_domain_free(&cpsw_common->pwrdmn);
 	return ret;
 }
 
@@ -806,6 +819,7 @@ U_BOOT_DRIVER(am65_cpsw_nuss) = {
 	.name	= "am65_cpsw_nuss",
 	.id	= UCLASS_MISC,
 	.of_match = am65_cpsw_nuss_ids,
+	.bind	= am65_cpsw_nuss_bind,
 	.probe	= am65_cpsw_probe_nuss,
 	.priv_auto = sizeof(struct am65_cpsw_common),
 };
-- 
2.34.1


  reply	other threads:[~2025-02-25 11:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25 11:48 [PATCH v3 00/15] Add support for Ethboot for AM68-SK, AM62p-SK Chintan Vankar
2025-02-25 11:48 ` Chintan Vankar [this message]
2025-02-27 10:26   ` [PATCH v3 01/15] net: ti: am65-cpsw-nuss: Define bind method for CPSW driver Roger Quadros
2025-03-04  4:45     ` Vankar, Chintan
2025-02-25 11:48 ` [PATCH v3 02/15] arm: mach-k3: am62x: am625_init: Remove explicit probing of " Chintan Vankar
2025-02-27 10:42   ` Roger Quadros
2025-02-25 11:48 ` [PATCH v3 03/15] arm: mach-k3: j721s2: Update SoC auto-gen data to enable Ethernet boot Chintan Vankar
2025-02-26  7:43   ` Neha Malcom Francis
2025-02-25 11:48 ` [PATCH v3 04/15] arm: mach-k3: j721s2_spl: Alias Ethernet boot to CPGMAC Chintan Vankar
2025-02-25 11:48 ` [PATCH v3 05/15] net: ti: Kconfig: Enable SPL_SYSCON config for CPSW Chintan Vankar
2025-02-25 13:39   ` Sverdlin, Alexander
2025-02-25 11:48 ` [PATCH v3 06/15] configs: am68: Add configs for enabling Ethboot in R5SPL Chintan Vankar
2025-02-25 11:48 ` [PATCH v3 07/15] configs: am68: Enable configs required for Ethernet boot Chintan Vankar
2025-02-25 11:48 ` [PATCH v3 08/15] arm: mach-k3: am62p: Update SoC auto-gen data to enable CPSW boot Chintan Vankar
2025-02-25 11:48 ` [PATCH v3 09/15] board: ti: am62px: evm: Enable cache for AM62p Chintan Vankar
2025-02-25 11:48 ` [PATCH v3 10/15] configs: am62p: Add configs for enabling ETHBOOT in R5SPL Chintan Vankar
2025-02-25 11:48 ` [PATCH v3 11/15] configs: am62p: Enable configs required for Ethboot Chintan Vankar
2025-02-25 11:49 ` [PATCH v3 12/15] arch: arm: mach-k3: r5: j722s: Update SoC autogenerated data to enable Ethernet boot Chintan Vankar
2025-02-25 11:49 ` [PATCH v3 13/15] board: ti: j722s: evm: Enable cache for J722s Chintan Vankar
2025-02-25 15:43   ` Sverdlin, Alexander
2025-02-25 11:49 ` [PATCH v3 14/15] configs: j722s_evm_r5: Add configs to enable Ethboot in R5SPL Chintan Vankar
2025-02-25 11:49 ` [PATCH v3 15/15] configs: j722s_evm_a53: Enable configs required for Ethernet boot Chintan Vankar

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=20250225114903.2080616-2-c-vankar@ti.com \
    --to=c-vankar@ti.com \
    --cc=afd@ti.com \
    --cc=alexander.sverdlin@siemens.com \
    --cc=bb@ti.com \
    --cc=danishanwar@ti.com \
    --cc=dannenberg@ti.com \
    --cc=hnagalla@ti.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=j-choudhary@ti.com \
    --cc=j-humphreys@ti.com \
    --cc=joao.goncalves@toradex.com \
    --cc=joe.hershberger@ni.com \
    --cc=kishon@ti.com \
    --cc=m-chawdhry@ti.com \
    --cc=matthias.schiffer@ew.tq-group.com \
    --cc=mwalle@kernel.org \
    --cc=n-francis@ti.com \
    --cc=rfried.dev@gmail.com \
    --cc=rogerq@kernel.org \
    --cc=s-k6@ti.com \
    --cc=s-vadapalli@ti.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vaishnav.a@ti.com \
    --cc=vigneshr@ti.com \
    --cc=w.egorov@phytec.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