All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v5 0/3] Add support for QSGMII mode for J721e CPSW9G to am65-cpsw driver
@ 2022-11-09  4:22 ` Siddharth Vadapalli
  0 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-09  4:22 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk, s-vadapalli

Add compatible to am65-cpsw driver for J721e CPSW9G, which contains 8
external ports and 1 internal host port.

Add support to power on and power off the SERDES PHY which is used by the
CPSW MAC.

=========
Changelog
=========
v4 -> v5:
1. Update subject of all patches in the series to "PATCH net-next".
2. Rebase series on net-next tree.

v3 -> v4:
1. Fix subject of patch-1/3, updating it to:
   "dt-bindings: net: ti: k3-am654-cpsw-nuss: Add J721e CPSW9G support"
   and collect Reviewed-by tag.
2. Rebase series on linux-next tree tagged: next-20221107.

v2 -> v3:
1. Run 'make DT_CHECKER_FLAGS=-m dt_binding_check' and fix errors and
   warnings corresponding to the patch for:
   Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml
   with the latest dt-schema and yamllint.

v1 -> v2:
1. Drop all patches corresponding to SGMII mode. This is done since I do
   not have a method to test SGMII in the standard mode which uses an
   SGMII PHY. The previous series used SGMII in a fixed-link mode,
   bypassing the SGMII PHY. I will post the SGMII patches in a future
   series after testing them.
2. Drop all patches corresponding to fixed-link in the am65-cpsw driver.
   This is done since PHYLINK takes care of fixed-link automatically and
   there is no need to deal with fixed-link in a custom fashion.
3. Fix indentation errors in k3-am65-cpsw-nuss.yaml.
4. Remove the stale code which tries to power on and power off the CPSW
   MAC's phy, since the CPSW MAC's phy driver does not support it.
5. Rename the function "am65_cpsw_init_phy()" to
   "am65_cpsw_init_serdes_phy()", to indicate that the phy corresponds to
   the SERDES.
6. Invoke "am65_cpsw_disable_serdes_phy()" as a part of the cleanup that
   is associated with the "am65_cpsw_nuss_remove()" function.

v4:
https://lore.kernel.org/r/20221108080606.124596-1-s-vadapalli@ti.com/
v3:
https://lore.kernel.org/r/20221026090957.180592-1-s-vadapalli@ti.com/
v2:
https://lore.kernel.org/r/20221018085810.151327-1-s-vadapalli@ti.com/
v1:
https://lore.kernel.org/r/20220914095053.189851-1-s-vadapalli@ti.com/

Siddharth Vadapalli (3):
  dt-bindings: net: ti: k3-am654-cpsw-nuss: Add J721e CPSW9G support
  net: ethernet: ti: am65-cpsw: Enable QSGMII mode for J721e CPSW9G
  net: ethernet: ti: am65-cpsw: Add support for SERDES configuration

 .../bindings/net/ti,k3-am654-cpsw-nuss.yaml   | 33 ++++++++-
 drivers/net/ethernet/ti/am65-cpsw-nuss.c      | 73 +++++++++++++++++++
 2 files changed, 102 insertions(+), 4 deletions(-)

-- 
2.25.1


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

* [PATCH net-next v5 0/3] Add support for QSGMII mode for J721e CPSW9G to am65-cpsw driver
@ 2022-11-09  4:22 ` Siddharth Vadapalli
  0 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-09  4:22 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk, s-vadapalli

Add compatible to am65-cpsw driver for J721e CPSW9G, which contains 8
external ports and 1 internal host port.

Add support to power on and power off the SERDES PHY which is used by the
CPSW MAC.

=========
Changelog
=========
v4 -> v5:
1. Update subject of all patches in the series to "PATCH net-next".
2. Rebase series on net-next tree.

v3 -> v4:
1. Fix subject of patch-1/3, updating it to:
   "dt-bindings: net: ti: k3-am654-cpsw-nuss: Add J721e CPSW9G support"
   and collect Reviewed-by tag.
2. Rebase series on linux-next tree tagged: next-20221107.

v2 -> v3:
1. Run 'make DT_CHECKER_FLAGS=-m dt_binding_check' and fix errors and
   warnings corresponding to the patch for:
   Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml
   with the latest dt-schema and yamllint.

v1 -> v2:
1. Drop all patches corresponding to SGMII mode. This is done since I do
   not have a method to test SGMII in the standard mode which uses an
   SGMII PHY. The previous series used SGMII in a fixed-link mode,
   bypassing the SGMII PHY. I will post the SGMII patches in a future
   series after testing them.
2. Drop all patches corresponding to fixed-link in the am65-cpsw driver.
   This is done since PHYLINK takes care of fixed-link automatically and
   there is no need to deal with fixed-link in a custom fashion.
3. Fix indentation errors in k3-am65-cpsw-nuss.yaml.
4. Remove the stale code which tries to power on and power off the CPSW
   MAC's phy, since the CPSW MAC's phy driver does not support it.
5. Rename the function "am65_cpsw_init_phy()" to
   "am65_cpsw_init_serdes_phy()", to indicate that the phy corresponds to
   the SERDES.
6. Invoke "am65_cpsw_disable_serdes_phy()" as a part of the cleanup that
   is associated with the "am65_cpsw_nuss_remove()" function.

v4:
https://lore.kernel.org/r/20221108080606.124596-1-s-vadapalli@ti.com/
v3:
https://lore.kernel.org/r/20221026090957.180592-1-s-vadapalli@ti.com/
v2:
https://lore.kernel.org/r/20221018085810.151327-1-s-vadapalli@ti.com/
v1:
https://lore.kernel.org/r/20220914095053.189851-1-s-vadapalli@ti.com/

Siddharth Vadapalli (3):
  dt-bindings: net: ti: k3-am654-cpsw-nuss: Add J721e CPSW9G support
  net: ethernet: ti: am65-cpsw: Enable QSGMII mode for J721e CPSW9G
  net: ethernet: ti: am65-cpsw: Add support for SERDES configuration

 .../bindings/net/ti,k3-am654-cpsw-nuss.yaml   | 33 ++++++++-
 drivers/net/ethernet/ti/am65-cpsw-nuss.c      | 73 +++++++++++++++++++
 2 files changed, 102 insertions(+), 4 deletions(-)

-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH net-next v5 1/3] dt-bindings: net: ti: k3-am654-cpsw-nuss: Add J721e CPSW9G support
  2022-11-09  4:22 ` Siddharth Vadapalli
@ 2022-11-09  4:22   ` Siddharth Vadapalli
  -1 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-09  4:22 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk, s-vadapalli

Update bindings for TI K3 J721e SoC which contains 9 ports (8 external
ports) CPSW9G module and add compatible for it.

Changes made:
    - Add new compatible ti,j721e-cpswxg-nuss for CPSW9G.
    - Extend pattern properties for new compatible.
    - Change maximum number of CPSW ports to 8 for new compatible.

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 .../bindings/net/ti,k3-am654-cpsw-nuss.yaml   | 33 ++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml b/Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml
index 821974815dec..900063411a20 100644
--- a/Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml
+++ b/Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml
@@ -57,6 +57,7 @@ properties:
       - ti,am654-cpsw-nuss
       - ti,j7200-cpswxg-nuss
       - ti,j721e-cpsw-nuss
+      - ti,j721e-cpswxg-nuss
       - ti,am642-cpsw-nuss
 
   reg:
@@ -111,7 +112,7 @@ properties:
         const: 0
 
     patternProperties:
-      "^port@[1-4]$":
+      "^port@[1-8]$":
         type: object
         description: CPSWxG NUSS external ports
 
@@ -121,7 +122,7 @@ properties:
         properties:
           reg:
             minimum: 1
-            maximum: 4
+            maximum: 8
             description: CPSW port number
 
           phys:
@@ -186,12 +187,36 @@ allOf:
         properties:
           compatible:
             contains:
-              const: ti,j7200-cpswxg-nuss
+              const: ti,j721e-cpswxg-nuss
     then:
       properties:
         ethernet-ports:
           patternProperties:
-            "^port@[3-4]$": false
+            "^port@[5-8]$": false
+            "^port@[1-4]$":
+              properties:
+                reg:
+                  minimum: 1
+                  maximum: 4
+
+  - if:
+      not:
+        properties:
+          compatible:
+            contains:
+              enum:
+                - ti,j721e-cpswxg-nuss
+                - ti,j7200-cpswxg-nuss
+    then:
+      properties:
+        ethernet-ports:
+          patternProperties:
+            "^port@[3-8]$": false
+            "^port@[1-2]$":
+              properties:
+                reg:
+                  minimum: 1
+                  maximum: 2
 
 additionalProperties: false
 
-- 
2.25.1


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

* [PATCH net-next v5 1/3] dt-bindings: net: ti: k3-am654-cpsw-nuss: Add J721e CPSW9G support
@ 2022-11-09  4:22   ` Siddharth Vadapalli
  0 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-09  4:22 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk, s-vadapalli

Update bindings for TI K3 J721e SoC which contains 9 ports (8 external
ports) CPSW9G module and add compatible for it.

Changes made:
    - Add new compatible ti,j721e-cpswxg-nuss for CPSW9G.
    - Extend pattern properties for new compatible.
    - Change maximum number of CPSW ports to 8 for new compatible.

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 .../bindings/net/ti,k3-am654-cpsw-nuss.yaml   | 33 ++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml b/Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml
index 821974815dec..900063411a20 100644
--- a/Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml
+++ b/Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml
@@ -57,6 +57,7 @@ properties:
       - ti,am654-cpsw-nuss
       - ti,j7200-cpswxg-nuss
       - ti,j721e-cpsw-nuss
+      - ti,j721e-cpswxg-nuss
       - ti,am642-cpsw-nuss
 
   reg:
@@ -111,7 +112,7 @@ properties:
         const: 0
 
     patternProperties:
-      "^port@[1-4]$":
+      "^port@[1-8]$":
         type: object
         description: CPSWxG NUSS external ports
 
@@ -121,7 +122,7 @@ properties:
         properties:
           reg:
             minimum: 1
-            maximum: 4
+            maximum: 8
             description: CPSW port number
 
           phys:
@@ -186,12 +187,36 @@ allOf:
         properties:
           compatible:
             contains:
-              const: ti,j7200-cpswxg-nuss
+              const: ti,j721e-cpswxg-nuss
     then:
       properties:
         ethernet-ports:
           patternProperties:
-            "^port@[3-4]$": false
+            "^port@[5-8]$": false
+            "^port@[1-4]$":
+              properties:
+                reg:
+                  minimum: 1
+                  maximum: 4
+
+  - if:
+      not:
+        properties:
+          compatible:
+            contains:
+              enum:
+                - ti,j721e-cpswxg-nuss
+                - ti,j7200-cpswxg-nuss
+    then:
+      properties:
+        ethernet-ports:
+          patternProperties:
+            "^port@[3-8]$": false
+            "^port@[1-2]$":
+              properties:
+                reg:
+                  minimum: 1
+                  maximum: 2
 
 additionalProperties: false
 
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH net-next v5 2/3] net: ethernet: ti: am65-cpsw: Enable QSGMII mode for J721e CPSW9G
  2022-11-09  4:22 ` Siddharth Vadapalli
@ 2022-11-09  4:22   ` Siddharth Vadapalli
  -1 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-09  4:22 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk, s-vadapalli

CPSW9G in J721e supports additional modes like QSGMII.
Add new compatible for J721e in am65-cpsw driver.

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index 75429ff0c200..bc9f29d10c22 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -2681,11 +2681,19 @@ static const struct am65_cpsw_pdata j7200_cpswxg_pdata = {
 	.extra_modes = BIT(PHY_INTERFACE_MODE_QSGMII),
 };
 
+static const struct am65_cpsw_pdata j721e_cpswxg_pdata = {
+	.quirks = 0,
+	.ale_dev_id = "am64-cpswxg",
+	.fdqring_mode = K3_RINGACC_RING_MODE_MESSAGE,
+	.extra_modes = BIT(PHY_INTERFACE_MODE_QSGMII),
+};
+
 static const struct of_device_id am65_cpsw_nuss_of_mtable[] = {
 	{ .compatible = "ti,am654-cpsw-nuss", .data = &am65x_sr1_0},
 	{ .compatible = "ti,j721e-cpsw-nuss", .data = &j721e_pdata},
 	{ .compatible = "ti,am642-cpsw-nuss", .data = &am64x_cpswxg_pdata},
 	{ .compatible = "ti,j7200-cpswxg-nuss", .data = &j7200_cpswxg_pdata},
+	{ .compatible = "ti,j721e-cpswxg-nuss", .data = &j721e_cpswxg_pdata},
 	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, am65_cpsw_nuss_of_mtable);
-- 
2.25.1


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

* [PATCH net-next v5 2/3] net: ethernet: ti: am65-cpsw: Enable QSGMII mode for J721e CPSW9G
@ 2022-11-09  4:22   ` Siddharth Vadapalli
  0 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-09  4:22 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk, s-vadapalli

CPSW9G in J721e supports additional modes like QSGMII.
Add new compatible for J721e in am65-cpsw driver.

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index 75429ff0c200..bc9f29d10c22 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -2681,11 +2681,19 @@ static const struct am65_cpsw_pdata j7200_cpswxg_pdata = {
 	.extra_modes = BIT(PHY_INTERFACE_MODE_QSGMII),
 };
 
+static const struct am65_cpsw_pdata j721e_cpswxg_pdata = {
+	.quirks = 0,
+	.ale_dev_id = "am64-cpswxg",
+	.fdqring_mode = K3_RINGACC_RING_MODE_MESSAGE,
+	.extra_modes = BIT(PHY_INTERFACE_MODE_QSGMII),
+};
+
 static const struct of_device_id am65_cpsw_nuss_of_mtable[] = {
 	{ .compatible = "ti,am654-cpsw-nuss", .data = &am65x_sr1_0},
 	{ .compatible = "ti,j721e-cpsw-nuss", .data = &j721e_pdata},
 	{ .compatible = "ti,am642-cpsw-nuss", .data = &am64x_cpswxg_pdata},
 	{ .compatible = "ti,j7200-cpswxg-nuss", .data = &j7200_cpswxg_pdata},
+	{ .compatible = "ti,j721e-cpswxg-nuss", .data = &j721e_cpswxg_pdata},
 	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, am65_cpsw_nuss_of_mtable);
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH net-next v5 3/3] net: ethernet: ti: am65-cpsw: Add support for SERDES configuration
  2022-11-09  4:22 ` Siddharth Vadapalli
@ 2022-11-09  4:22   ` Siddharth Vadapalli
  -1 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-09  4:22 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk, s-vadapalli

Use PHY framework APIs to initialize the SERDES PHY connected to CPSW MAC.

Define the functions am65_cpsw_disable_phy(), am65_cpsw_enable_phy(),
am65_cpsw_disable_serdes_phy() and am65_cpsw_enable_serdes_phy().

Power on and initialize the SerDes PHY in am65_cpsw_nuss_init_slave_ports()
by invoking am65_cpsw_enable_serdes_phy().

Power off the SerDes PHY in am65_cpsw_nuss_remove() by invoking
am65_cpsw_disable_serdes_phy().

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 65 ++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index bc9f29d10c22..83349d24a0e6 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -1444,6 +1444,65 @@ static const struct net_device_ops am65_cpsw_nuss_netdev_ops = {
 	.ndo_setup_tc           = am65_cpsw_qos_ndo_setup_tc,
 };
 
+static void am65_cpsw_disable_phy(struct phy *phy)
+{
+	phy_power_off(phy);
+	phy_exit(phy);
+}
+
+static int am65_cpsw_enable_phy(struct phy *phy)
+{
+	int ret;
+
+	ret = phy_init(phy);
+	if (ret < 0)
+		return ret;
+
+	ret = phy_power_on(phy);
+	if (ret < 0) {
+		phy_exit(phy);
+		return ret;
+	}
+
+	return 0;
+}
+
+static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common)
+{
+	struct device_node *node, *port_np;
+	struct device *dev = common->dev;
+	const char *name = "serdes-phy";
+	struct phy *phy;
+
+	node = of_get_child_by_name(dev->of_node, "ethernet-ports");
+
+	for_each_child_of_node(node, port_np) {
+		phy = devm_of_phy_get(dev, port_np, name);
+		am65_cpsw_disable_phy(phy);
+	}
+}
+
+static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *port_np)
+{
+	const char *name = "serdes-phy";
+	struct phy *phy;
+	int ret;
+
+	phy = devm_of_phy_get(dev, port_np, name);
+	if (PTR_ERR(phy) == -ENODEV)
+		return 0;
+
+	ret =  am65_cpsw_enable_phy(phy);
+	if (ret < 0)
+		goto err_phy;
+
+	return 0;
+
+err_phy:
+	devm_phy_put(dev, phy);
+	return ret;
+}
+
 static void am65_cpsw_nuss_mac_config(struct phylink_config *config, unsigned int mode,
 				      const struct phylink_link_state *state)
 {
@@ -1941,6 +2000,11 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
 			goto of_node_put;
 		}
 
+		/* Initialize the phy for the port */
+		ret = am65_cpsw_init_serdes_phy(dev, port_np);
+		if (ret)
+			return ret;
+
 		port->slave.mac_only =
 				of_property_read_bool(port_np, "ti,mac-only");
 
@@ -2868,6 +2932,7 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev)
 
 	am65_cpsw_nuss_phylink_cleanup(common);
 	am65_cpsw_unregister_devlink(common);
+	am65_cpsw_disable_serdes_phy(common);
 	am65_cpsw_unregister_notifiers(common);
 
 	/* must unregister ndevs here because DD release_driver routine calls
-- 
2.25.1


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

* [PATCH net-next v5 3/3] net: ethernet: ti: am65-cpsw: Add support for SERDES configuration
@ 2022-11-09  4:22   ` Siddharth Vadapalli
  0 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-09  4:22 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk, s-vadapalli

Use PHY framework APIs to initialize the SERDES PHY connected to CPSW MAC.

Define the functions am65_cpsw_disable_phy(), am65_cpsw_enable_phy(),
am65_cpsw_disable_serdes_phy() and am65_cpsw_enable_serdes_phy().

Power on and initialize the SerDes PHY in am65_cpsw_nuss_init_slave_ports()
by invoking am65_cpsw_enable_serdes_phy().

Power off the SerDes PHY in am65_cpsw_nuss_remove() by invoking
am65_cpsw_disable_serdes_phy().

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 65 ++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index bc9f29d10c22..83349d24a0e6 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -1444,6 +1444,65 @@ static const struct net_device_ops am65_cpsw_nuss_netdev_ops = {
 	.ndo_setup_tc           = am65_cpsw_qos_ndo_setup_tc,
 };
 
+static void am65_cpsw_disable_phy(struct phy *phy)
+{
+	phy_power_off(phy);
+	phy_exit(phy);
+}
+
+static int am65_cpsw_enable_phy(struct phy *phy)
+{
+	int ret;
+
+	ret = phy_init(phy);
+	if (ret < 0)
+		return ret;
+
+	ret = phy_power_on(phy);
+	if (ret < 0) {
+		phy_exit(phy);
+		return ret;
+	}
+
+	return 0;
+}
+
+static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common)
+{
+	struct device_node *node, *port_np;
+	struct device *dev = common->dev;
+	const char *name = "serdes-phy";
+	struct phy *phy;
+
+	node = of_get_child_by_name(dev->of_node, "ethernet-ports");
+
+	for_each_child_of_node(node, port_np) {
+		phy = devm_of_phy_get(dev, port_np, name);
+		am65_cpsw_disable_phy(phy);
+	}
+}
+
+static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *port_np)
+{
+	const char *name = "serdes-phy";
+	struct phy *phy;
+	int ret;
+
+	phy = devm_of_phy_get(dev, port_np, name);
+	if (PTR_ERR(phy) == -ENODEV)
+		return 0;
+
+	ret =  am65_cpsw_enable_phy(phy);
+	if (ret < 0)
+		goto err_phy;
+
+	return 0;
+
+err_phy:
+	devm_phy_put(dev, phy);
+	return ret;
+}
+
 static void am65_cpsw_nuss_mac_config(struct phylink_config *config, unsigned int mode,
 				      const struct phylink_link_state *state)
 {
@@ -1941,6 +2000,11 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
 			goto of_node_put;
 		}
 
+		/* Initialize the phy for the port */
+		ret = am65_cpsw_init_serdes_phy(dev, port_np);
+		if (ret)
+			return ret;
+
 		port->slave.mac_only =
 				of_property_read_bool(port_np, "ti,mac-only");
 
@@ -2868,6 +2932,7 @@ static int am65_cpsw_nuss_remove(struct platform_device *pdev)
 
 	am65_cpsw_nuss_phylink_cleanup(common);
 	am65_cpsw_unregister_devlink(common);
+	am65_cpsw_disable_serdes_phy(common);
 	am65_cpsw_unregister_notifiers(common);
 
 	/* must unregister ndevs here because DD release_driver routine calls
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH net-next v5 3/3] net: ethernet: ti: am65-cpsw: Add support for SERDES configuration
  2022-11-09  4:22   ` Siddharth Vadapalli
@ 2022-11-10 13:06     ` Paolo Abeni
  -1 siblings, 0 replies; 12+ messages in thread
From: Paolo Abeni @ 2022-11-10 13:06 UTC (permalink / raw)
  To: Siddharth Vadapalli, davem, edumazet, kuba, robh+dt,
	krzysztof.kozlowski, krzysztof.kozlowski+dt, linux,
	vladimir.oltean, vigneshr, nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk

hello,

On Wed, 2022-11-09 at 09:52 +0530, Siddharth Vadapalli wrote:
[...]

> +static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common)
> +{
> +	struct device_node *node, *port_np;
> +	struct device *dev = common->dev;
> +	const char *name = "serdes-phy";
> +	struct phy *phy;
> +
> +	node = of_get_child_by_name(dev->of_node, "ethernet-ports");
> +
> +	for_each_child_of_node(node, port_np) {
> +		phy = devm_of_phy_get(dev, port_np, name);

The above will try to allocate some memory and can fail. Even if the
the following code will handle a NULL ptr, the phy will not be
disabled.

I think it's better if you cache the serdes phy ptr in
am65_cpsw_init_serdes_phy() and you use such reference here, without
resorting to devm_of_phy_get().

Cheers,

Paolo


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

* Re: [PATCH net-next v5 3/3] net: ethernet: ti: am65-cpsw: Add support for SERDES configuration
@ 2022-11-10 13:06     ` Paolo Abeni
  0 siblings, 0 replies; 12+ messages in thread
From: Paolo Abeni @ 2022-11-10 13:06 UTC (permalink / raw)
  To: Siddharth Vadapalli, davem, edumazet, kuba, robh+dt,
	krzysztof.kozlowski, krzysztof.kozlowski+dt, linux,
	vladimir.oltean, vigneshr, nsekhar
  Cc: netdev, devicetree, linux-kernel, linux-arm-kernel, srk

hello,

On Wed, 2022-11-09 at 09:52 +0530, Siddharth Vadapalli wrote:
[...]

> +static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common)
> +{
> +	struct device_node *node, *port_np;
> +	struct device *dev = common->dev;
> +	const char *name = "serdes-phy";
> +	struct phy *phy;
> +
> +	node = of_get_child_by_name(dev->of_node, "ethernet-ports");
> +
> +	for_each_child_of_node(node, port_np) {
> +		phy = devm_of_phy_get(dev, port_np, name);

The above will try to allocate some memory and can fail. Even if the
the following code will handle a NULL ptr, the phy will not be
disabled.

I think it's better if you cache the serdes phy ptr in
am65_cpsw_init_serdes_phy() and you use such reference here, without
resorting to devm_of_phy_get().

Cheers,

Paolo


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH net-next v5 3/3] net: ethernet: ti: am65-cpsw: Add support for SERDES configuration
  2022-11-10 13:06     ` Paolo Abeni
@ 2022-11-17 10:16       ` Siddharth Vadapalli
  -1 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-17 10:16 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: davem, edumazet, kuba, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar, netdev, devicetree, linux-kernel, linux-arm-kernel, srk,
	s-vadapalli

Hello Paolo,

On 10/11/22 18:36, Paolo Abeni wrote:
> hello,
> 
> On Wed, 2022-11-09 at 09:52 +0530, Siddharth Vadapalli wrote:
> [...]
> 
>> +static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common)
>> +{
>> +	struct device_node *node, *port_np;
>> +	struct device *dev = common->dev;
>> +	const char *name = "serdes-phy";
>> +	struct phy *phy;
>> +
>> +	node = of_get_child_by_name(dev->of_node, "ethernet-ports");
>> +
>> +	for_each_child_of_node(node, port_np) {
>> +		phy = devm_of_phy_get(dev, port_np, name);
> 
> The above will try to allocate some memory and can fail. Even if the
> the following code will handle a NULL ptr, the phy will not be
> disabled.
> 
> I think it's better if you cache the serdes phy ptr in
> am65_cpsw_init_serdes_phy() and you use such reference here, without
> resorting to devm_of_phy_get().

Thank you for reviewing the patch. I plan on creating a new "struct
phy*" member named "serdes_phy" in the struct "am65_cpsw_slave_data"
defined in the file "am65-cpsw-nuss.h", and store the SerDes phy in this
member, during the execution of the am65_cpsw_init_serdes_phy()
function. Please let me know if I can proceed with this implementation.

Regards,
Siddharth.

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

* Re: [PATCH net-next v5 3/3] net: ethernet: ti: am65-cpsw: Add support for SERDES configuration
@ 2022-11-17 10:16       ` Siddharth Vadapalli
  0 siblings, 0 replies; 12+ messages in thread
From: Siddharth Vadapalli @ 2022-11-17 10:16 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: davem, edumazet, kuba, robh+dt, krzysztof.kozlowski,
	krzysztof.kozlowski+dt, linux, vladimir.oltean, vigneshr,
	nsekhar, netdev, devicetree, linux-kernel, linux-arm-kernel, srk,
	s-vadapalli

Hello Paolo,

On 10/11/22 18:36, Paolo Abeni wrote:
> hello,
> 
> On Wed, 2022-11-09 at 09:52 +0530, Siddharth Vadapalli wrote:
> [...]
> 
>> +static void am65_cpsw_disable_serdes_phy(struct am65_cpsw_common *common)
>> +{
>> +	struct device_node *node, *port_np;
>> +	struct device *dev = common->dev;
>> +	const char *name = "serdes-phy";
>> +	struct phy *phy;
>> +
>> +	node = of_get_child_by_name(dev->of_node, "ethernet-ports");
>> +
>> +	for_each_child_of_node(node, port_np) {
>> +		phy = devm_of_phy_get(dev, port_np, name);
> 
> The above will try to allocate some memory and can fail. Even if the
> the following code will handle a NULL ptr, the phy will not be
> disabled.
> 
> I think it's better if you cache the serdes phy ptr in
> am65_cpsw_init_serdes_phy() and you use such reference here, without
> resorting to devm_of_phy_get().

Thank you for reviewing the patch. I plan on creating a new "struct
phy*" member named "serdes_phy" in the struct "am65_cpsw_slave_data"
defined in the file "am65-cpsw-nuss.h", and store the SerDes phy in this
member, during the execution of the am65_cpsw_init_serdes_phy()
function. Please let me know if I can proceed with this implementation.

Regards,
Siddharth.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-11-17 10:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09  4:22 [PATCH net-next v5 0/3] Add support for QSGMII mode for J721e CPSW9G to am65-cpsw driver Siddharth Vadapalli
2022-11-09  4:22 ` Siddharth Vadapalli
2022-11-09  4:22 ` [PATCH net-next v5 1/3] dt-bindings: net: ti: k3-am654-cpsw-nuss: Add J721e CPSW9G support Siddharth Vadapalli
2022-11-09  4:22   ` Siddharth Vadapalli
2022-11-09  4:22 ` [PATCH net-next v5 2/3] net: ethernet: ti: am65-cpsw: Enable QSGMII mode for J721e CPSW9G Siddharth Vadapalli
2022-11-09  4:22   ` Siddharth Vadapalli
2022-11-09  4:22 ` [PATCH net-next v5 3/3] net: ethernet: ti: am65-cpsw: Add support for SERDES configuration Siddharth Vadapalli
2022-11-09  4:22   ` Siddharth Vadapalli
2022-11-10 13:06   ` Paolo Abeni
2022-11-10 13:06     ` Paolo Abeni
2022-11-17 10:16     ` Siddharth Vadapalli
2022-11-17 10:16       ` Siddharth Vadapalli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.