Skip to contentSkip to conversation

phy: phy-can-transceiver: Ad-hoc cleanups and refactoring

PATCH Superseded Andy Shevchenko 2 participants 11 messages Feb 19 – Mar 17

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover phy: phy-can-transceiver: Ad-hoc cleanups and refactoring

The driver does two things that need to be addressed:
- includes subject to remove gpio.h
- checks for error code from device property APIs when it can be done in a robust way

This series addresses the above and adds a couple of additional refactoring.

Andy Shevchenko (4):
phy: phy-can-transceiver: Convert to use device property API
phy: phy-can-transceiver: Move OF ID table closer to their user
phy: phy-can-transceiver: Don't check for specific errors when parsing
properties
phy: phy-can-transceiver: Drop unused include

 drivers/phy/phy-can-transceiver.c | 86 ++++++++++++++++---------------
 1 file changed, 45 insertions(+), 41 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/4 phy: phy-can-transceiver: Convert to use device property API

It seems the driver is half-moved to use device property APIs. Finish that by converting everything to use that.

---
 drivers/phy/phy-can-transceiver.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/phy/phy-can-transceiver.c +4 -6
index 330356706ad7..f2259af4af8a 100644
@@ -5,9 +5,9 @@
  * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
  *
  */
-#include <linux/of.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/module.h>
 #include <linux/gpio.h>
 #include <linux/gpio/consumer.h>
@@ -130,7 +130,7 @@ MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids);
 static inline struct mux_state *
 devm_mux_state_get_optional(struct device *dev, const char *mux_name)
 {
-	if (!of_property_present(dev->of_node, "mux-states"))
+	if (!device_property_present(dev, "mux-states"))
 		return NULL;
 
 	return devm_mux_state_get(dev, mux_name);
@@ -162,7 +162,6 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
 	struct can_transceiver_phy *can_transceiver_phy;
 	struct can_transceiver_priv *priv;
 	const struct can_transceiver_data *drvdata;
-	const struct of_device_id *match;
 	struct phy *phy;
 	struct gpio_desc *silent_gpio;
 	struct gpio_desc *standby_gpio;
@@ -171,8 +170,7 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
 	u32 max_bitrate = 0;
 	int err, i, num_ch = 1;
 
-	match = of_match_node(can_transceiver_phy_ids, pdev->dev.of_node);
-	drvdata = match->data;
+	drvdata = device_get_match_data(dev);
 	if (drvdata->flags & CAN_TRANSCEIVER_DUAL_CH)
 		num_ch = 2;
 
@@ -197,7 +195,7 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
 		can_transceiver_phy = &priv->can_transceiver_phy[i];
 		can_transceiver_phy->priv = priv;
 
-		phy = devm_phy_create(dev, dev->of_node, &can_transceiver_phy_ops);
+		phy = devm_phy_create(dev, NULL, &can_transceiver_phy_ops);
 		if (IS_ERR(phy)) {
 			dev_err(dev, "failed to create can transceiver phy\n");
 			return PTR_ERR(phy);
Signature · 1 line
2.50.1
#2 lore raw

Re: [PATCH v1 1/4] phy: phy-can-transceiver: Convert to use device property API

Hi Andy,

Quoted 24 lines · Andy Shevchenko

It seems the driver is half-moved to use device property APIs. Finish that by converting everything to use that.

---
 drivers/phy/phy-can-transceiver.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/phy/phy-can-transceiver.c +1 -1
index 330356706ad7..f2259af4af8a 100644
@@ -5,9 +5,9 @@
  * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
  *
  */
-#include <linux/of.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/module.h>
 #include <linux/gpio.h>
 #include <linux/gpio/consumer.h>

drivers/phy/phy-can-transceiver.c MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids); · line 133

Quoted 5 lines
drivers/phy/phy-can-transceiver.c +1 -1
@@ -130,7 +130,7 @@ MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids);
 static inline struct mux_state *
 devm_mux_state_get_optional(struct device *dev, const char *mux_name)
 {
-	if (!of_property_present(dev->of_node, "mux-states"))
+	if (!device_property_present(dev, "mux-states"))

There's an entire saga with this function - devm_mux_state_get_optional(). Josua Mayer is preparing to move it to the MUX core, which will be a cross-tree series. Would you mind not touching this, to avoid complicating what is already
a complicated operation? It is going away anyway, and from what I can
see in Josua's last series, its implementation from drivers/mux/core.c
is already using device property APIs:
https://lore.kernel.org/linux-phy/[email protected]/

Quoted 22 lines
drivers/phy/phy-can-transceiver.c +1 -3
 		return NULL;
 
 	return devm_mux_state_get(dev, mux_name);
@@ -162,7 +162,6 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
 	struct can_transceiver_phy *can_transceiver_phy;
 	struct can_transceiver_priv *priv;
 	const struct can_transceiver_data *drvdata;
-	const struct of_device_id *match;
 	struct phy *phy;
 	struct gpio_desc *silent_gpio;
 	struct gpio_desc *standby_gpio;
@@ -171,8 +170,7 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
 	u32 max_bitrate = 0;
 	int err, i, num_ch = 1;
 
-	match = of_match_node(can_transceiver_phy_ids, pdev->dev.of_node);
-	drvdata = match->data;
+	drvdata = device_get_match_data(dev);
 	if (drvdata->flags & CAN_TRANSCEIVER_DUAL_CH)
 		num_ch = 2;
 

drivers/phy/phy-can-transceiver.c static int can_transceiver_phy_probe(struct platform_device *pdev) · line 198

Quoted 5 lines
drivers/phy/phy-can-transceiver.c +1 -1
@@ -197,7 +195,7 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
 		can_transceiver_phy = &priv->can_transceiver_phy[i];
 		can_transceiver_phy->priv = priv;
 
-		phy = devm_phy_create(dev, dev->of_node, &can_transceiver_phy_ops);
+		phy = devm_phy_create(dev, NULL, &can_transceiver_phy_ops);

It is not obvious why you replaced dev->of_node with NULL here. It doesn't appear correct. You seem to be breaking OF-based PHY lookups.

Quoted 7 lines
drivers/phy/phy-can-transceiver.c +0 -0
 		if (IS_ERR(phy)) {
 			dev_err(dev, "failed to create can transceiver phy\n");
 			return PTR_ERR(phy);
Signature · 1 line
2.50.1
#3 lore raw

Re: [PATCH v1 1/4] phy: phy-can-transceiver: Convert to use device property API

Quoted 1 line · Vladimir Oltean

On Thu, Feb 19, 2026 at 09:26:19PM +0100, Andy Shevchenko wrote:

...

Quoted 10 lines

drivers/phy/phy-can-transceiver.c MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids); · line 133

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-	if (!of_property_present(dev->of_node, "mux-states"))
+	if (!device_property_present(dev, "mux-states"))

There's an entire saga with this function - devm_mux_state_get_optional(). Josua Mayer is preparing to move it to the MUX core, which will be a cross-tree series. Would you mind not touching this, to avoid complicating what is already
a complicated operation? It is going away anyway, and from what I can
see in Josua's last series, its implementation from drivers/mux/core.c
is already using device property APIs:
https://lore.kernel.org/linux-phy/[email protected]/

Basically you ask me to postpone the series until that will be in. Since this file is a mess in terms of OF/fwnode API use in exchange I would like whoever is doing the other part to speed up a bit if possible.

I prefer to see cleaner solution to be applied sooner and last in a long distance, that's why I see either mine first but soon, or that first but also soon should be in. Can we try to achieve that?

...

Quoted 5 lines

drivers/phy/phy-can-transceiver.c static int can_transceiver_phy_probe(struct platform_device *pdev) · line 198

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-		phy = devm_phy_create(dev, dev->of_node, &can_transceiver_phy_ops);
+		phy = devm_phy_create(dev, NULL, &can_transceiver_phy_ops);

It is not obvious why you replaced dev->of_node with NULL here. It doesn't appear correct. You seem to be breaking OF-based PHY lookups.

It's the default. Yeah, I probably have to explain this in the commit message.

Basically all devm_phy_create(dev, dev->of_node, ...) for clarity should be converted to that approach. Or even better, a new (agnostic) API should take default fwnode from the same device.

		phy = devm_phy_create_simple(dev, &..._phy_ops);

// name was quickly chosen and may be not the best we can come up with

...

Thanks for the review!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v1 1/4] phy: phy-can-transceiver: Convert to use device property API

Quoted 16 lines · Andy Shevchenko
Quoted 1 line · Vladimir Oltean

On Thu, Feb 19, 2026 at 09:26:19PM +0100, Andy Shevchenko wrote:

...

Quoted 10 lines

drivers/phy/phy-can-transceiver.c MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids); · line 133

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-	if (!of_property_present(dev->of_node, "mux-states"))
+	if (!device_property_present(dev, "mux-states"))

There's an entire saga with this function - devm_mux_state_get_optional(). Josua Mayer is preparing to move it to the MUX core, which will be a cross-tree series. Would you mind not touching this, to avoid complicating what is already
a complicated operation? It is going away anyway, and from what I can
see in Josua's last series, its implementation from drivers/mux/core.c
is already using device property APIs:
https://lore.kernel.org/linux-phy/[email protected]/

Quoted 7 lines

Basically you ask me to postpone the series until that will be in. Since this file is a mess in terms of OF/fwnode API use in exchange I would like whoever is doing the other part to speed up a bit if possible.

I prefer to see cleaner solution to be applied sooner and last in a long distance, that's why I see either mine first but soon, or that first but also soon should be in. Can we try to achieve that?

The idea is that Ulf already expressed the availability to take the phy-can-transceiver patch through the mmc tree and provide back a tag to be pulled into linux-phy:
https://lore.kernel.org/linux-phy/CAPDyKFrtTaJ5fqqbGrE_K6SAdTZYUfp-BycGjtWs4SabwBysKA@mail.gmail.com/

If linux-phy takes your patch first, there will be a conflict when pulling the stable branch, and it won't be so fun, plus we can't even build-test Josua's submission on linux-phy, so that's obviously not great.

So yeah, I'm not requesting you to postpone the entire series, just not touch devm_mux_state_get_optional() and don't let it appear in your patch context.

Somebody will have to remove "#include <linux/of.h>" at the end of the whole process, but that's minor.

Quoted 9 lines

...

Quoted 5 lines

drivers/phy/phy-can-transceiver.c static int can_transceiver_phy_probe(struct platform_device *pdev) · line 198

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-		phy = devm_phy_create(dev, dev->of_node, &can_transceiver_phy_ops);
+		phy = devm_phy_create(dev, NULL, &can_transceiver_phy_ops);

It is not obvious why you replaced dev->of_node with NULL here. It doesn't appear correct. You seem to be breaking OF-based PHY lookups.

It's the default. Yeah, I probably have to explain this in the commit message.

Ah, ok. Found the "phy->dev.of_node = node ?: dev->of_node;" assignment. Sorry and noted, but please add it to the commit message too.

Quoted 7 lines

Basically all devm_phy_create(dev, dev->of_node, ...) for clarity should be converted to that approach. Or even better, a new (agnostic) API should take default fwnode from the same device.

		phy = devm_phy_create_simple(dev, &..._phy_ops);

// name was quickly chosen and may be not the best we can come up with

I agree in principle. PHY drivers shouldn't be given a function where they routinely have to set one of the arguments to NULL, but a simpler function without that argument.

But the phy-core.c doesn't support fwnode at all yet, it uses OF throughout. I think it would be preferable to leave this change to somebody who has business in that area.

(are you interested in PHYs with a fwnode for any particular reason, or just because the API is more "generic" just in case?)

#5 lore raw

Re: [PATCH v1 1/4] phy: phy-can-transceiver: Convert to use device property API

Quoted 3 lines · Vladimir Oltean
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Vladimir Oltean

On Thu, Feb 19, 2026 at 09:26:19PM +0100, Andy Shevchenko wrote:

...

Quoted 23 lines
Quoted 11 lines
Quoted 10 lines

drivers/phy/phy-can-transceiver.c MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids); · line 133

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-	if (!of_property_present(dev->of_node, "mux-states"))
+	if (!device_property_present(dev, "mux-states"))

There's an entire saga with this function - devm_mux_state_get_optional(). Josua Mayer is preparing to move it to the MUX core, which will be a cross-tree series. Would you mind not touching this, to avoid complicating what is already
a complicated operation? It is going away anyway, and from what I can
see in Josua's last series, its implementation from drivers/mux/core.c
is already using device property APIs:
https://lore.kernel.org/linux-phy/[email protected]/

Quoted 7 lines

Basically you ask me to postpone the series until that will be in. Since this file is a mess in terms of OF/fwnode API use in exchange I would like whoever is doing the other part to speed up a bit if possible.

I prefer to see cleaner solution to be applied sooner and last in a long distance, that's why I see either mine first but soon, or that first but also soon should be in. Can we try to achieve that?

The idea is that Ulf already expressed the availability to take the phy-can-transceiver patch through the mmc tree and provide back a tag to be pulled into linux-phy:
https://lore.kernel.org/linux-phy/CAPDyKFrtTaJ5fqqbGrE_K6SAdTZYUfp-BycGjtWs4SabwBysKA@mail.gmail.com/

Quoted 7 lines

If linux-phy takes your patch first, there will be a conflict when pulling the stable branch, and it won't be so fun, plus we can't even build-test Josua's submission on linux-phy, so that's obviously not great.

So yeah, I'm not requesting you to postpone the entire series, just not touch devm_mux_state_get_optional() and don't let it appear in your patch context.

Thanks for explanation. I prefer that Ulf's staff settles down first as it seems more important.

Quoted 11 lines

Somebody will have to remove "#include <linux/of.h>" at the end of the whole process, but that's minor.

Quoted 8 lines

...

Quoted 5 lines

drivers/phy/phy-can-transceiver.c static int can_transceiver_phy_probe(struct platform_device *pdev) · line 198

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-		phy = devm_phy_create(dev, dev->of_node, &can_transceiver_phy_ops);
+		phy = devm_phy_create(dev, NULL, &can_transceiver_phy_ops);

It is not obvious why you replaced dev->of_node with NULL here. It doesn't appear correct. You seem to be breaking OF-based PHY lookups.

Quoted 4 lines
Quoted 1 line

It's the default. Yeah, I probably have to explain this in the commit message.

Ah, ok. Found the "phy->dev.of_node = node ?: dev->of_node;" assignment. Sorry and noted, but please add it to the commit message too.

Sure.

Quoted 12 lines
Quoted 7 lines

Basically all devm_phy_create(dev, dev->of_node, ...) for clarity should be converted to that approach. Or even better, a new (agnostic) API should take default fwnode from the same device.

		phy = devm_phy_create_simple(dev, &..._phy_ops);

// name was quickly chosen and may be not the best we can come up with

I agree in principle. PHY drivers shouldn't be given a function where they routinely have to set one of the arguments to NULL, but a simpler function without that argument.

Quoted 6 lines

But the phy-core.c doesn't support fwnode at all yet, it uses OF throughout. I think it would be preferable to leave this change to somebody who has business in that area.

(are you interested in PHYs with a fwnode for any particular reason, or just because the API is more "generic" just in case?)

Because of inconsistency. This makes my mind blown and the code is not good for others to read and understand when it's inconsistent like this. That's it.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v1 1/4] phy: phy-can-transceiver: Convert to use device property API

Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Vladimir Oltean
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Vladimir Oltean

On Thu, Feb 19, 2026 at 09:26:19PM +0100, Andy Shevchenko wrote:

...

Quoted 27 lines
Quoted 27 lines
Quoted 11 lines
Quoted 10 lines

drivers/phy/phy-can-transceiver.c MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids); · line 133

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-	if (!of_property_present(dev->of_node, "mux-states"))
+	if (!device_property_present(dev, "mux-states"))

There's an entire saga with this function - devm_mux_state_get_optional(). Josua Mayer is preparing to move it to the MUX core, which will be a cross-tree series. Would you mind not touching this, to avoid complicating what is already
a complicated operation? It is going away anyway, and from what I can
see in Josua's last series, its implementation from drivers/mux/core.c
is already using device property APIs:
https://lore.kernel.org/linux-phy/[email protected]/

Quoted 7 lines

Basically you ask me to postpone the series until that will be in. Since this file is a mess in terms of OF/fwnode API use in exchange I would like whoever is doing the other part to speed up a bit if possible.

I prefer to see cleaner solution to be applied sooner and last in a long distance, that's why I see either mine first but soon, or that first but also soon should be in. Can we try to achieve that?

The idea is that Ulf already expressed the availability to take the phy-can-transceiver patch through the mmc tree and provide back a tag to be pulled into linux-phy:
https://lore.kernel.org/linux-phy/CAPDyKFrtTaJ5fqqbGrE_K6SAdTZYUfp-BycGjtWs4SabwBysKA@mail.gmail.com/

If linux-phy takes your patch first, there will be a conflict when pulling the stable branch, and it won't be so fun, plus we can't even build-test Josua's submission on linux-phy, so that's obviously not great.

Quoted 6 lines
Quoted 3 lines

So yeah, I'm not requesting you to postpone the entire series, just not touch devm_mux_state_get_optional() and don't let it appear in your patch context.

Thanks for explanation. I prefer that Ulf's staff settles down first as it seems more important.

Any news on that front?

Quoted 39 lines
Quoted 11 lines

Somebody will have to remove "#include <linux/of.h>" at the end of the whole process, but that's minor.

Quoted 8 lines

...

Quoted 5 lines

drivers/phy/phy-can-transceiver.c static int can_transceiver_phy_probe(struct platform_device *pdev) · line 198

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-		phy = devm_phy_create(dev, dev->of_node, &can_transceiver_phy_ops);
+		phy = devm_phy_create(dev, NULL, &can_transceiver_phy_ops);

It is not obvious why you replaced dev->of_node with NULL here. It doesn't appear correct. You seem to be breaking OF-based PHY lookups.

Quoted 4 lines
Quoted 1 line

It's the default. Yeah, I probably have to explain this in the commit message.

Ah, ok. Found the "phy->dev.of_node = node ?: dev->of_node;" assignment. Sorry and noted, but please add it to the commit message too.

Sure.

Quoted 12 lines
Quoted 7 lines

Basically all devm_phy_create(dev, dev->of_node, ...) for clarity should be converted to that approach. Or even better, a new (agnostic) API should take default fwnode from the same device.

		phy = devm_phy_create_simple(dev, &..._phy_ops);

// name was quickly chosen and may be not the best we can come up with

I agree in principle. PHY drivers shouldn't be given a function where they routinely have to set one of the arguments to NULL, but a simpler function without that argument.

Quoted 6 lines

But the phy-core.c doesn't support fwnode at all yet, it uses OF throughout. I think it would be preferable to leave this change to somebody who has business in that area.

(are you interested in PHYs with a fwnode for any particular reason, or just because the API is more "generic" just in case?)

Because of inconsistency. This makes my mind blown and the code is not good for others to read and understand when it's inconsistent like this. That's it.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

Re: [PATCH v1 1/4] phy: phy-can-transceiver: Convert to use device property API

Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Vladimir Oltean
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Vladimir Oltean

On Thu, Feb 19, 2026 at 09:26:19PM +0100, Andy Shevchenko wrote:

...

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 11 lines
Quoted 10 lines

drivers/phy/phy-can-transceiver.c MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids); · line 133

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-	if (!of_property_present(dev->of_node, "mux-states"))
+	if (!device_property_present(dev, "mux-states"))

There's an entire saga with this function - devm_mux_state_get_optional(). Josua Mayer is preparing to move it to the MUX core, which will be a cross-tree series. Would you mind not touching this, to avoid complicating what is already
a complicated operation? It is going away anyway, and from what I can
see in Josua's last series, its implementation from drivers/mux/core.c
is already using device property APIs:
https://lore.kernel.org/linux-phy/[email protected]/

Quoted 7 lines

Basically you ask me to postpone the series until that will be in. Since this file is a mess in terms of OF/fwnode API use in exchange I would like whoever is doing the other part to speed up a bit if possible.

I prefer to see cleaner solution to be applied sooner and last in a long distance, that's why I see either mine first but soon, or that first but also soon should be in. Can we try to achieve that?

The idea is that Ulf already expressed the availability to take the phy-can-transceiver patch through the mmc tree and provide back a tag to be pulled into linux-phy:
https://lore.kernel.org/linux-phy/CAPDyKFrtTaJ5fqqbGrE_K6SAdTZYUfp-BycGjtWs4SabwBysKA@mail.gmail.com/

If linux-phy takes your patch first, there will be a conflict when pulling the stable branch, and it won't be so fun, plus we can't even build-test Josua's submission on linux-phy, so that's obviously not great.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

So yeah, I'm not requesting you to postpone the entire series, just not touch devm_mux_state_get_optional() and don't let it appear in your patch context.

Thanks for explanation. I prefer that Ulf's staff settles down first as it seems more important.

Any news on that front?

Okay, I found the new patches in Linux Next.
I will respin my set based on that.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Somebody will have to remove "#include <linux/of.h>" at the end of the whole process, but that's minor.

...

Quoted 34 lines
Quoted 34 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

drivers/phy/phy-can-transceiver.c static int can_transceiver_phy_probe(struct platform_device *pdev) · line 198

Quoted 2 lines
drivers/phy/phy-can-transceiver.c +1 -1
-		phy = devm_phy_create(dev, dev->of_node, &can_transceiver_phy_ops);
+		phy = devm_phy_create(dev, NULL, &can_transceiver_phy_ops);

It is not obvious why you replaced dev->of_node with NULL here. It doesn't appear correct. You seem to be breaking OF-based PHY lookups.

It's the default. Yeah, I probably have to explain this in the commit message.

Ah, ok. Found the "phy->dev.of_node = node ?: dev->of_node;" assignment. Sorry and noted, but please add it to the commit message too.

Sure.

Quoted 12 lines
Quoted 7 lines

Basically all devm_phy_create(dev, dev->of_node, ...) for clarity should be converted to that approach. Or even better, a new (agnostic) API should take default fwnode from the same device.

		phy = devm_phy_create_simple(dev, &..._phy_ops);

// name was quickly chosen and may be not the best we can come up with

I agree in principle. PHY drivers shouldn't be given a function where they routinely have to set one of the arguments to NULL, but a simpler function without that argument.

Quoted 6 lines

But the phy-core.c doesn't support fwnode at all yet, it uses OF throughout. I think it would be preferable to leave this change to somebody who has business in that area.

(are you interested in PHYs with a fwnode for any particular reason, or just because the API is more "generic" just in case?)

Because of inconsistency. This makes my mind blown and the code is not good for others to read and understand when it's inconsistent like this. That's it.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

PATCH 2/4 phy: phy-can-transceiver: Move OF ID table closer to their user

In reply to Andy Shevchenko

There is no code that uses ID table directly, except the struct device_driver at the end of the file. Hence, move table closer to its user. It's always possible to access them via a pointer.

---
 drivers/phy/phy-can-transceiver.c | 59 +++++++++++++++----------------
 1 file changed, 29 insertions(+), 30 deletions(-)
drivers/phy/phy-can-transceiver.c +29 -30
index f2259af4af8a..dd08faf46837 100644
@@ -97,35 +97,6 @@ static const struct can_transceiver_data tja1057_drvdata = {
 	.flags = CAN_TRANSCEIVER_SILENT_PRESENT,
 };
 
-static const struct of_device_id can_transceiver_phy_ids[] = {
-	{
-		.compatible = "ti,tcan1042",
-		.data = &tcan1042_drvdata
-	},
-	{
-		.compatible = "ti,tcan1043",
-		.data = &tcan1043_drvdata
-	},
-	{
-		.compatible = "nxp,tja1048",
-		.data = &tja1048_drvdata
-	},
-	{
-		.compatible = "nxp,tja1051",
-		.data = &tja1051_drvdata
-	},
-	{
-		.compatible = "nxp,tja1057",
-		.data = &tja1057_drvdata
-	},
-	{
-		.compatible = "nxp,tjr1443",
-		.data = &tcan1043_drvdata
-	},
-	{ }
-};
-MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids);
-
 /* Temporary wrapper until the multiplexer subsystem supports optional muxes */
 static inline struct mux_state *
 devm_mux_state_get_optional(struct device *dev, const char *mux_name)
@@ -239,6 +210,35 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
 	return PTR_ERR_OR_ZERO(phy_provider);
 }
 
+static const struct of_device_id can_transceiver_phy_ids[] = {
+	{
+		.compatible = "ti,tcan1042",
+		.data = &tcan1042_drvdata
+	},
+	{
+		.compatible = "ti,tcan1043",
+		.data = &tcan1043_drvdata
+	},
+	{
+		.compatible = "nxp,tja1048",
+		.data = &tja1048_drvdata
+	},
+	{
+		.compatible = "nxp,tja1051",
+		.data = &tja1051_drvdata
+	},
+	{
+		.compatible = "nxp,tja1057",
+		.data = &tja1057_drvdata
+	},
+	{
+		.compatible = "nxp,tjr1443",
+		.data = &tcan1043_drvdata
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids);
+
 static struct platform_driver can_transceiver_phy_driver = {
 	.probe = can_transceiver_phy_probe,
 	.driver = {
@@ -246,7 +246,6 @@ static struct platform_driver can_transceiver_phy_driver = {
 		.of_match_table = can_transceiver_phy_ids,
 	},
 };
-
 module_platform_driver(can_transceiver_phy_driver);
 
 MODULE_AUTHOR("Faiz Abbas <[email protected]>");
Signature · 1 line
2.50.1
#9 lore raw

PATCH 3/4 phy: phy-can-transceiver: Don't check for specific errors when parsing properties

In reply to Andy Shevchenko

Instead of checking for the specific error codes (that can be considered a layering violation to some extent) check for the property existence first and then either parse it, or apply a default value.

With that, return an error when parsing of the existing property fails.

---
 drivers/phy/phy-can-transceiver.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/phy/phy-can-transceiver.c +11 -3
index dd08faf46837..ebce48ef217f 100644
@@ -138,8 +138,9 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
 	struct gpio_desc *standby_gpio;
 	struct gpio_desc *enable_gpio;
 	struct mux_state *mux_state;
-	u32 max_bitrate = 0;
 	int err, i, num_ch = 1;
+	const char *propname;
+	u32 max_bitrate;
 
 	drvdata = device_get_match_data(dev);
 	if (drvdata->flags & CAN_TRANSCEIVER_DUAL_CH)
@@ -158,8 +159,15 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
 
 	priv->mux_state = mux_state;
 
-	err = device_property_read_u32(dev, "max-bitrate", &max_bitrate);
-	if ((err != -EINVAL) && !max_bitrate)
+	propname = "max-bitrate";
+	if (device_property_present(dev, propname)) {
+		err = device_property_read_u32(dev, "max-bitrate", &max_bitrate);
+		if (err)
+			return dev_err_probe(dev, err, "failed to parse %s\n", propname);
+	} else {
+		max_bitrate = 0;
+	}
+	if (!max_bitrate)
 		dev_warn(dev, "Invalid value for transceiver max bitrate. Ignoring bitrate limit\n");
 
 	for (i = 0; i < num_ch; i++) {
Signature · 1 line
2.50.1
#10 lore raw

PATCH 4/4 phy: phy-can-transceiver: Drop unused include

In reply to Andy Shevchenko

This file does not use the symbols from the legacy <linux/gpio.h> header, so let's drop it.

---
 drivers/phy/phy-can-transceiver.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/phy/phy-can-transceiver.c +1 -2
index ebce48ef217f..ba40bad4ccb1 100644
@@ -5,12 +5,11 @@
  * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
  *
  */
+#include <linux/gpio/consumer.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/module.h>
-#include <linux/gpio.h>
-#include <linux/gpio/consumer.h>
 #include <linux/mux/consumer.h>
 
 struct can_transceiver_data {
Signature · 1 line
2.50.1