Skip to contentSkip to conversation

phy: ti: gmii-sel: Allow parent to not be syscon node

PATCH Superseded Andrew Davis 3 participants 5 messages May 15, 2023 – Jul 10, 2023 Generic PHY framework

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 phy: ti: gmii-sel: Allow parent to not be syscon node

If the parent node is not a syscon type, then fallback and check if we can get a regmap from our own node. This no longer forces us to make the parent of this node a syscon node when that might not be appropriate.

---
 drivers/phy/ti/phy-gmii-sel.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/phy/ti/phy-gmii-sel.c +6 -3
index 8c667819c39a..1e67ed9a5cf6 100644
@@ -435,9 +435,12 @@ static int phy_gmii_sel_probe(struct platform_device *pdev)
 
 	priv->regmap = syscon_node_to_regmap(node->parent);
 	if (IS_ERR(priv->regmap)) {
-		ret = PTR_ERR(priv->regmap);
-		dev_err(dev, "Failed to get syscon %d\n", ret);
-		return ret;
+		priv->regmap = device_node_to_regmap(node);
+		if (IS_ERR(priv->regmap)) {
+			ret = PTR_ERR(priv->regmap);
+			dev_err(dev, "Failed to get syscon %d\n", ret);
+			return ret;
+		}
 	}
 
 	ret = phy_gmii_sel_init_ports(priv);
Signature · 7 lines
2.39.2


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#1 lore raw

Andrew,

Quoted 4 lines · Andrew Davis

If the parent node is not a syscon type, then fallback and check if we can get a regmap from our own node. This no longer forces us to make the parent of this node a syscon node when that might not be appropriate.

Could you please let me know in which cases it is appropriate versus in which cases it isn't? Is syscon_node_to_regmap() being retained for backward compatibility until the device-tree nodes are cleaned up across all devices?

Quoted 11 lines
---
 drivers/phy/ti/phy-gmii-sel.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/phy/ti/phy-gmii-sel.c +0 -0
index 8c667819c39a..1e67ed9a5cf6 100644

drivers/phy/ti/phy-gmii-sel.c static int phy_gmii_sel_probe(struct platform_device *pdev) · line 438

Quoted 7 lines
drivers/phy/ti/phy-gmii-sel.c +1 -3
@@ -435,9 +435,12 @@ static int phy_gmii_sel_probe(struct platform_device *pdev)
 
 	priv->regmap = syscon_node_to_regmap(node->parent);
 	if (IS_ERR(priv->regmap)) {
-		ret = PTR_ERR(priv->regmap);
-		dev_err(dev, "Failed to get syscon %d\n", ret);
-		return ret;
+		priv->regmap = device_node_to_regmap(node);

If device_node_to_regmap() can always be used with the corresponding changes made to the device-tree nodes, wouldn't it be better to use it directly instead of using it as a fallback? (This is based on the assumption that syscon_node_to_regmap() is only being retained until the device-tree nodes are cleaned up to work with device_node_to_regmap()).

Quoted 8 lines
drivers/phy/ti/phy-gmii-sel.c +5 -0
+		if (IS_ERR(priv->regmap)) {
+			ret = PTR_ERR(priv->regmap);
+			dev_err(dev, "Failed to get syscon %d\n", ret);
+			return ret;
+		}
 	}
 
 	ret = phy_gmii_sel_init_ports(priv);
Signature · 7 lines
Regards,
Siddharth.

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#2 lore raw
Quoted 10 lines · Siddharth Vadapalli

Andrew,

Quoted 4 lines · Andrew Davis

If the parent node is not a syscon type, then fallback and check if we can get a regmap from our own node. This no longer forces us to make the parent of this node a syscon node when that might not be appropriate.

Could you please let me know in which cases it is appropriate versus in which cases it isn't?

Use of syscon nodes should be discouraged, in most cases they can and should be avoided. The only time we would need to have a syscon parent is when the register space contains multiple sub-devices with bit level interleaving.

Most devices should never need syscon, we overuse syscon due to driver like this that have no other option than to make the parent device a syscon node.

Quoted 3 lines

Is syscon_node_to_regmap() being retained for backward compatibility until the device-tree nodes are cleaned up across all devices?

Yes, the old way is left only for backwards compatibility.

Quoted 12 lines
Quoted 12 lines
---
  drivers/phy/ti/phy-gmii-sel.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
drivers/phy/ti/phy-gmii-sel.c +0 -0
index 8c667819c39a..1e67ed9a5cf6 100644
@@ -435,9 +435,12 @@ static int phy_gmii_sel_probe(struct platform_device *pdev)
 
Quoted 13 lines

drivers/phy/ti/phy-gmii-sel.c static int phy_gmii_sel_probe(struct platform_device *pdev) · line 438

Quoted 6 lines
drivers/phy/ti/phy-gmii-sel.c +1 -3
  	priv->regmap = syscon_node_to_regmap(node->parent);
  	if (IS_ERR(priv->regmap)) {
-		ret = PTR_ERR(priv->regmap);
-		dev_err(dev, "Failed to get syscon %d\n", ret);
-		return ret;
+		priv->regmap = device_node_to_regmap(node);

If device_node_to_regmap() can always be used with the corresponding changes made to the device-tree nodes, wouldn't it be better to use it directly instead of using it as a fallback? (This is based on the assumption that syscon_node_to_regmap() is only being retained until the device-tree nodes are cleaned up to work with device_node_to_regmap()).

Yes, that could work too. I was trying to make the minimal changes here, but if we feel it works better we can have the default be to check the self node first.

Andrew

Quoted 9 lines
Quoted 8 lines
drivers/phy/ti/phy-gmii-sel.c +5 -0
+		if (IS_ERR(priv->regmap)) {
+			ret = PTR_ERR(priv->regmap);
+			dev_err(dev, "Failed to get syscon %d\n", ret);
+			return ret;
+		}
  	}
 
  	ret = phy_gmii_sel_init_ports(priv);
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#3 lore raw
In reply to Andrew Davis

Hi Andrew,

Quoted 4 lines · Andrew Davis

If the parent node is not a syscon type, then fallback and check if we can get a regmap from our own node. This no longer forces us to make the parent of this node a syscon node when that might not be appropriate.

Trying to understand the motive for this and if it is better to introduce a "syscon = <&syscon_node>" property instead which makes it fool proof for all cases.

Quoted 26 lines
---
 drivers/phy/ti/phy-gmii-sel.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/phy/ti/phy-gmii-sel.c +6 -3
index 8c667819c39a..1e67ed9a5cf6 100644
@@ -435,9 +435,12 @@ static int phy_gmii_sel_probe(struct platform_device *pdev)
 
 	priv->regmap = syscon_node_to_regmap(node->parent);
 	if (IS_ERR(priv->regmap)) {
-		ret = PTR_ERR(priv->regmap);
-		dev_err(dev, "Failed to get syscon %d\n", ret);
-		return ret;
+		priv->regmap = device_node_to_regmap(node);
+		if (IS_ERR(priv->regmap)) {
+			ret = PTR_ERR(priv->regmap);
+			dev_err(dev, "Failed to get syscon %d\n", ret);
+			return ret;
+		}
 	}
 
 	ret = phy_gmii_sel_init_ports(priv);
Signature · 7 lines
cheers,
-roger

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#4 lore raw
Quoted 12 lines · Roger Quadros

Hi Andrew,

Quoted 4 lines · Andrew Davis

If the parent node is not a syscon type, then fallback and check if we can get a regmap from our own node. This no longer forces us to make the parent of this node a syscon node when that might not be appropriate.

Trying to understand the motive for this and if it is better to introduce a "syscon = <&syscon_node>" property instead which makes it fool proof for all cases.

My motivation is to reduce our overuse of syscon nodes, IMHO syscon is almost always a broken design in DT and goes against the standard usage.

Some drivers like this one force us to make the parent node a syscon device, even what that is not needed otherwise (the register space is standalone and the standard DT "reg" property can be used to describe the device register space).

Using "syscon = <&syscon_node>" could be a useful option for devices when syscon is actually needed. But I think that should only be used when the whole node itself cannot be made a child of the syscon node, making it a child when we can is better for DT organization vs. having a bunch of top-level nodes that point around to their register spaces with phandles.

Andrew

Quoted 27 lines
Quoted 26 lines
---
  drivers/phy/ti/phy-gmii-sel.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
drivers/phy/ti/phy-gmii-sel.c +6 -3
index 8c667819c39a..1e67ed9a5cf6 100644
@@ -435,9 +435,12 @@ static int phy_gmii_sel_probe(struct platform_device *pdev)
 
  	priv->regmap = syscon_node_to_regmap(node->parent);
  	if (IS_ERR(priv->regmap)) {
-		ret = PTR_ERR(priv->regmap);
-		dev_err(dev, "Failed to get syscon %d\n", ret);
-		return ret;
+		priv->regmap = device_node_to_regmap(node);
+		if (IS_ERR(priv->regmap)) {
+			ret = PTR_ERR(priv->regmap);
+			dev_err(dev, "Failed to get syscon %d\n", ret);
+			return ret;
+		}
  	}
 
  	ret = phy_gmii_sel_init_ports(priv);
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy