phy: Add devm_of_phy_optional_get() helper
Subsystems (14)
v2 cover phy: Add devm_of_phy_optional_get() helper
Hi Vinod et al,
While there exist several optional_get() PHY helper functions, there is no optional variant of devm_of_phy_get(), leading to several drivers implementing this theirselves, sometimes in buggy ways.
Hence this series, after two cleanup patches, introduces a devm_of_phy_optional_get() helper(), and converts existing users of devm_of_phy_get() where appropriate.
Changes compared to v1[1]:
- Incorporate "[PATCH v2 1/9] phy: Remove unused phy_optional_get()", as it touches the same documentation,
- New patch "[PATCH v2 2/9] doc: phy: Document devm_of_phy_get()",
- Print an error message in case of failure, as requested by RobH,
- Update Documentation,
- Clarify removed checks for -ENODEV and -ENOSYS,
- Remove error printing in case of real failures from callers,
- Rebase am65-cpsw change on top of commit 854617f52ab42418 ("net:
ethernet: ti: am65-cpsw: Handle -EPROBE_DEFER for Serdes PHY") in net-next (next-20230123 and later),
- Add Reviewed-by, Acked-by.
Most of this series been compile-tested only, but the new helper itself has been tested with a new user[2].
Thanks for your comments!
[1] "[PATCH treewide 0/7] phy: Add devm_of_phy_optional_get() helper"
https://lore.kernel.org/r/[email protected] [2] "[PATCH 12/12] can: rcar_canfd: Add transceiver support" https://lore.kernel.org/r/e825b50a843ffe40e33f34e4d858c07c1b2ff259.1674499048.git.geert+renesas@glider.be
Geert Uytterhoeven (9):
phy: Remove unused phy_optional_get()
doc: phy: Document devm_of_phy_get()
phy: Add devm_of_phy_optional_get() helper
net: fman: memac: Convert to devm_of_phy_optional_get()
net: lan966x: Convert to devm_of_phy_optional_get()
net: ethernet: ti: am65-cpsw: Convert to devm_of_phy_optional_get()
PCI: tegra: Convert to devm_of_phy_optional_get()
usb: host: ehci-exynos: Convert to devm_of_phy_optional_get()
usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()
Documentation/driver-api/phy/phy.rst | 24 +++++---- .../net/ethernet/freescale/fman/fman_memac.c | 9 ++-- .../ethernet/microchip/lan966x/lan966x_main.c | 5 +- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 8 ++- drivers/pci/controller/pci-tegra.c | 5 +- drivers/phy/phy-core.c | 51 +++++++++++-------- drivers/usb/host/ehci-exynos.c | 23 +++------ drivers/usb/host/ohci-exynos.c | 23 +++------ include/linux/phy/phy.h | 16 +++--- 9 files changed, 75 insertions(+), 89 deletions(-)
Signature · 12 lines
2.34.1
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus TorvaldsPATCH v2 1/9 phy: Remove unused phy_optional_get()
There were never any upstream users of this function since its introduction almost 10 years ago.
Besides, the dummy for phy_optional_get() should have returned NULL instead of an error code.
---
This is v2 of "phy: Return NULL if the PHY is optional (part two)".
--- Documentation/driver-api/phy/phy.rst | 11 +++++------ drivers/phy/phy-core.c | 21 --------------------- include/linux/phy/phy.h | 7 ------- 3 files changed, 5 insertions(+), 34 deletions(-)
Documentation/driver-api/phy/phy.rst +5 -6
@@ -103,7 +103,6 @@ it. This framework provides the following APIs to get a reference to the PHY. :: struct phy *phy_get(struct device *dev, const char *string); - struct phy *phy_optional_get(struct device *dev, const char *string); struct phy *devm_phy_get(struct device *dev, const char *string); struct phy *devm_phy_optional_get(struct device *dev, const char *string);
@@ -111,15 +110,15 @@ it. This framework provides the following APIs to get a reference to the PHY. struct device_node *np, int index); -phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can -be used to get the PHY. In the case of dt boot, the string arguments +phy_get, devm_phy_get and devm_phy_optional_get can be used to get the PHY. +In the case of dt boot, the string arguments should contain the phy name as given in the dt data and in the case of non-dt boot, it should contain the label of the PHY. The two devm_phy_get associates the device with the PHY using devres on successful PHY get. On driver detach, release function is invoked on -the devres data and devres data is freed. phy_optional_get and -devm_phy_optional_get should be used when the phy is optional. These -two functions will never return -ENODEV, but instead returns NULL when +the devres data and devres data is freed. +devm_phy_optional_get should be used when the phy is optional. This +function will never return -ENODEV, but instead returns NULL when the phy cannot be found.Some generic drivers, such as ehci, may use multiple phys and for such drivers referencing phy(s) by name(s) does not make sense. In this case, devm_of_phy_get_by_index can be used to get a phy reference based on
drivers/phy/phy-core.c +0 -21
@@ -766,27 +766,6 @@ struct phy *phy_get(struct device *dev, const char *string) }EXPORT_SYMBOL_GPL (phy_get); -/** -* phy_optional_get() - lookup and obtain a reference to an optional phy. -* @dev: device that requests this phy -* @string: the phy name as given in the dt data or the name of the controller -* port for non-dt case -* -* Returns the phy driver, after getting a refcount to it; or -* NULL if there is no such phy. The caller is responsible for -* calling phy_put() to release that count. -*/ -struct phy *phy_optional_get (struct device *dev,const char *string) -{ -struct phy *phy =phy_get (dev, string); - -if (PTR_ERR (phy) == -ENODEV ) - phy =NULL ; - -return phy; -} -EXPORT_SYMBOL_GPL (phy_optional_get); -/** * devm_phy_get() - lookup and obtain a reference to a phy. * @dev: device that requests this phy
include/linux/phy/phy.h +0 -7
@@ -250,7 +250,6 @@ static inline void phy_set_bus_width(struct phy *phy, int bus_width) phy->attrs.bus_width = bus_width; }struct phy *phy_get (struct device *dev,const char *string); -struct phy *phy_optional_get (struct device *dev,const char *string);struct phy *devm_phy_get (struct device *dev,const char *string);struct phy *devm_phy_optional_get (struct device *dev,const char *string); struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
@@ -426,12 +425,6 @@ static inline struct phy *phy_get(struct device *dev, const char *string)return ERR_PTR (-ENOSYS ); } -static inline struct phy *phy_optional_get (struct device *dev, -const char *string) -{ -return ERR_PTR (-ENOSYS ); -} -static inline struct phy *devm_phy_get (struct device *dev,const char *string) {return ERR_PTR (-ENOSYS );
Signature · 1 line
2.34.1
PATCH v2 2/9 doc: phy: Document devm_of_phy_get()
In reply to Geert UytterhoevenAdd the missing documentation for devm_of_phy_get(), which was forgotten when the function was introduced.
---
v2:
- New.
--- Documentation/driver-api/phy/phy.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
Documentation/driver-api/phy/phy.rst +6 -4
@@ -106,6 +106,8 @@ it. This framework provides the following APIs to get a reference to the PHY. struct phy *devm_phy_get(struct device *dev, const char *string); struct phy *devm_phy_optional_get(struct device *dev, const char *string); + struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, + const char *con_id); struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, int index);
@@ -119,10 +121,10 @@ successful PHY get. On driver detach, release function is invoked on the devres data and devres data is freed. devm_phy_optional_get should be used when the phy is optional. This function will never return -ENODEV, but instead returns NULL when -the phy cannot be found.Some generic drivers, such as ehci, may use multiple -phys and for such drivers referencing phy(s) by name(s) does not make sense. In -this case, devm_of_phy_get_by_index can be used to get a phy reference based on -the index. +the phy cannot be found. +Some generic drivers, such as ehci, may use multiple phys. In this case, +devm_of_phy_get or devm_of_phy_get_by_index can be used to get a phy +reference based on name or index. It should be noted that NULL is a valid phy reference. All phy consumer calls on the NULL phy become NOPs. That is the release calls,
Signature · 1 line
2.34.1
PATCH v2 3/9 phy: Add devm_of_phy_optional_get() helper
In reply to Geert UytterhoevenAdd an optional variant of devm_of_phy_get() that also takes care of printing real errors, so drivers no longer have to open-code this operation.
---
v2:
- Print an error message in case of failure, as requested by RobH,
- Update Documentation.
--- Documentation/driver-api/phy/phy.rst | 7 +++++-- drivers/phy/phy-core.c | 30 ++++++++++++++++++++++++++++ include/linux/phy/phy.h | 9 +++++++++ 3 files changed, 44 insertions(+), 2 deletions(-)
Documentation/driver-api/phy/phy.rst +5 -2
@@ -108,6 +108,9 @@ it. This framework provides the following APIs to get a reference to the PHY. const char *string); struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, const char *con_id); + struct phy *devm_of_phy_optional_get(struct device *dev, + struct device_node *np, + const char *con_id); struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, int index);
@@ -119,8 +122,8 @@ non-dt boot, it should contain the label of the PHY. The two devm_phy_get associates the device with the PHY using devres on successful PHY get. On driver detach, release function is invoked on the devres data and devres data is freed. -devm_phy_optional_get should be used when the phy is optional. This -function will never return -ENODEV, but instead returns NULL when +The _optional_get variants should be used when the phy is optional. These +functions will never return -ENODEV, but instead return NULL when the phy cannot be found. Some generic drivers, such as ehci, may use multiple phys. In this case, devm_of_phy_get or devm_of_phy_get_by_index can be used to get a phy
drivers/phy/phy-core.c +30 -0
@@ -858,6 +858,36 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, }EXPORT_SYMBOL_GPL (devm_of_phy_get); +/** +* devm_of_phy_optional_get() - lookup and obtain a reference to an optional +* phy. +* @dev: device that requests this phy +* @np: node containing the phy +* @con_id: name of the phy from device's point of view +* +* Gets the phy using of_phy_get(), and associates a device with it using +* devres. On driver detach, release function is invoked on the devres data, +* then, devres data is freed. This differs to devm_of_phy_get() in +* that if the phy does not exist, it is not considered an error and +* -ENODEV will not be returned. Instead the NULL phy is returned, +* which can be passed to all other phy consumer calls. +*/ +struct phy *devm_of_phy_optional_get (struct device *dev,struct device_node *np, +const char *con_id) +{ +struct phy *phy =devm_of_phy_get (dev, np, con_id); + +if (PTR_ERR (phy) == -ENODEV ) + phy =NULL ; + +if (IS_ERR (phy)) +dev_err_probe (dev,PTR_ERR (phy),"failed to get PHY %pOF:%s" , + np, con_id); + +return phy; +} +EXPORT_SYMBOL_GPL (devm_of_phy_optional_get); +/** * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index. * @dev: device that requests this phy
include/linux/phy/phy.h +9 -0
@@ -254,6 +254,8 @@ struct phy *devm_phy_get(struct device *dev, const char *string);struct phy *devm_phy_optional_get (struct device *dev,const char *string);struct phy *devm_of_phy_get (struct device *dev,struct device_node *np,const char *con_id); +struct phy *devm_of_phy_optional_get (struct device *dev,struct device_node *np, +const char *con_id);struct phy *devm_of_phy_get_by_index (struct device *dev,struct device_node *np,int index);void of_phy_put (struct phy *phy);
@@ -443,6 +445,13 @@ static inline struct phy *devm_of_phy_get(struct device *dev,return ERR_PTR (-ENOSYS ); } +static inline struct phy *devm_of_phy_optional_get (struct device *dev, +struct device_node *np, +const char *con_id) +{ +return NULL ; +} +static inline struct phy *devm_of_phy_get_by_index (struct device *dev,struct device_node *np,int index)
Signature · 1 line
2.34.1
PATCH v2 4/9 net: fman: memac: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse the new devm_of_phy_optional_get() helper instead of open-coding the same operation.
As devm_of_phy_optional_get() returns NULL if either the PHY cannot be found, or if support for the PHY framework is not enabled, it is no longer needed to check for -ENODEV or -ENOSYS.
---
v2:
- Add Reviewed-by,
- Clarify removed checks for -ENODEV and -ENOSYS,
- Remove error printing in case of real failures.
--- drivers/net/ethernet/freescale/fman/fman_memac.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/freescale/fman/fman_memac.c +4 -5
@@ -1152,13 +1152,12 @@ int memac_initialization(struct mac_device *mac_dev,else memac->sgmii_pcs = pcs; - memac->serdes =devm_of_phy_get (mac_dev->dev, mac_node,"serdes" ); - err =PTR_ERR (memac->serdes); -if (err == -ENODEV || err == -ENOSYS ) { + memac->serdes =devm_of_phy_optional_get (mac_dev->dev, mac_node, +"serdes" ); +if (!memac->serdes) {dev_dbg (mac_dev->dev,"could not get (optional) serdes\n" ); - memac->serdes =NULL ; }else if (IS_ERR (memac->serdes)) { -dev_err_probe (mac_dev->dev, err,"could not get serdes\n" ); + err =PTR_ERR (memac->serdes); goto _return_fm_mac_free; }
Signature · 1 line
2.34.1
PATCH v2 5/9 net: lan966x: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse the new devm_of_phy_optional_get() helper instead of open-coding the same operation.
---
v2:
- Add Reviewed-by.
--- drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_main.c +2 -3
@@ -1147,9 +1147,8 @@ static int lan966x_probe(struct platform_device *pdev) lan966x->ports[p]->config.portmode = phy_mode; lan966x->ports[p]->fwnode =fwnode_handle_get (portnp); - serdes =devm_of_phy_get (lan966x->dev,to_of_node (portnp),NULL ); -if (PTR_ERR (serdes) == -ENODEV ) - serdes =NULL ; + serdes =devm_of_phy_optional_get (lan966x->dev, +to_of_node (portnp),NULL );if (IS_ERR (serdes)) { err =PTR_ERR (serdes); goto cleanup_ports;
Signature · 1 line
2.34.1
PATCH v2 6/9 net: ethernet: ti: am65-cpsw: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse the new devm_of_phy_optional_get() helper instead of open-coding the same operation.
---
v2:
- Rebase on top of commit 854617f52ab42418 ("net: ethernet: ti:
am65-cpsw: Handle -EPROBE_DEFER for Serdes PHY") in net-next (next-20230123 and later).
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +3 -5
@@ -1460,11 +1460,9 @@ static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *porstruct phy *phy;int ret; - phy =devm_of_phy_get (dev, port_np, name); -if (PTR_ERR (phy) == -ENODEV ) -return 0 ; -if (IS_ERR (phy)) -return PTR_ERR (phy); + phy =devm_of_phy_optional_get (dev, port_np, name); +if (IS_ERR_OR_NULL (phy)) +return PTR_ERR_OR_ZERO (phy);/* Serdes PHY exists. Store it. */ port->slave.serdes_phy = phy;
Signature · 1 line
2.34.1
Re: [PATCH v2 6/9] net: ethernet: ti: am65-cpsw: Convert to devm_of_phy_optional_get()
Quoted 19 lines · Geert Uytterhoeven
Use the new
devm_of_phy_optional_get()helper instead of open-coding the same operation.Signed-off-by Geert Uytterhoeven <[email protected]>---
v2:
- Rebase on top of commit854617f52ab42418("net: ethernet: ti:
am65-cpsw: Handle -EPROBE_DEFER for Serdes PHY") in net-next (next-20230123 and later).--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/net/ethernet/ti/am65-cpsw-nuss.c +0
-0@@ -1460,11 +1460,9 @@ static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *porstruct phy *phy;
drivers/net/ethernet/ti/am65-cpsw-nuss.c static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *por · line 1465
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +3
-5int ret; - phy =devm_of_phy_get (dev, port_np, name); -if (PTR_ERR (phy) == -ENODEV ) -return 0 ; -if (IS_ERR (phy)) -return PTR_ERR (phy); + phy =devm_of_phy_optional_get (dev, port_np, name); +if (IS_ERR_OR_NULL (phy)) +return PTR_ERR_OR_ZERO (phy);
Regards,
Siddharth.
Signature · 3 lines
linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
Vinod Koul
maintainerRe: [PATCH v2 6/9] net: ethernet: ti: am65-cpsw: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenQuoted 9 lines · Geert Uytterhoeven
Use the new
devm_of_phy_optional_get()helper instead of open-coding the same operation.Signed-off-by Geert Uytterhoeven <[email protected]>---
v2:
- Rebase on top of commit854617f52ab42418("net: ethernet: ti:
am65-cpsw: Handle -EPROBE_DEFER for Serdes PHY") in net-next (next-20230123 and later).
I was trying to apply this on rc1, so ofcourse this fails for me? How do we resolve this?
I can skip this patch, provide a tag for this to be pulled into -net tree
Quoted 25 lines
--- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/net/ethernet/ti/am65-cpsw-nuss.c +3
-5@@ -1460,11 +1460,9 @@ static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *porstruct phy *phy;int ret; - phy =devm_of_phy_get (dev, port_np, name); -if (PTR_ERR (phy) == -ENODEV ) -return 0 ; -if (IS_ERR (phy)) -return PTR_ERR (phy); + phy =devm_of_phy_optional_get (dev, port_np, name); +if (IS_ERR_OR_NULL (phy)) +return PTR_ERR_OR_ZERO (phy);/* Serdes PHY exists. Store it. */ port->slave.serdes_phy = phy;Signature · 1 line
2.34.1
Signature · 1 line
~Vinod
Re: [PATCH v2 6/9] net: ethernet: ti: am65-cpsw: Convert to devm_of_phy_optional_get()
Hi Vinod,
Quoted 11 lines · Vinod Koul
Quoted 9 lines · Geert Uytterhoeven
Use the new
devm_of_phy_optional_get()helper instead of open-coding the same operation.Signed-off-by Geert Uytterhoeven <[email protected]>---
v2:
- Rebase on top of commit854617f52ab42418("net: ethernet: ti:
am65-cpsw: Handle -EPROBE_DEFER for Serdes PHY") in net-next (next-20230123 and later).
Quoted 5 lines
I was trying to apply this on rc1, so ofcourse this fails for me? How do we resolve this?
I can skip this patch, provide a tag for this to be pulled into -net tree
Thanks, that's one option.
The other option is to postpone this patch, and apply it after v6.3-rc1.
Thanks!
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +3
-5@@ -1460,11 +1460,9 @@ static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *porstruct phy *phy;int ret; - phy =devm_of_phy_get (dev, port_np, name); -if (PTR_ERR (phy) == -ENODEV ) -return 0 ; -if (IS_ERR (phy)) -return PTR_ERR (phy); + phy =devm_of_phy_optional_get (dev, port_np, name); +if (IS_ERR_OR_NULL (phy)) +return PTR_ERR_OR_ZERO (phy);
Quoted 2 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *por · line 1468
Quoted 2 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +0
-0/* Serdes PHY exists. Store it. */ port->slave.serdes_phy = phy;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Signature · 3 lines
linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
Vinod Koul
maintainerRe: [PATCH v2 6/9] net: ethernet: ti: am65-cpsw: Convert to devm_of_phy_optional_get()
Quoted 14 lines · Geert Uytterhoeven
Hi Vinod,
Quoted 11 lines · Vinod Koul
Quoted 9 lines · Geert Uytterhoeven
Use the new
devm_of_phy_optional_get()helper instead of open-coding the same operation.Signed-off-by Geert Uytterhoeven <[email protected]>---
v2:
- Rebase on top of commit854617f52ab42418("net: ethernet: ti:
am65-cpsw: Handle -EPROBE_DEFER for Serdes PHY") in net-next (next-20230123 and later).
Quoted 8 lines
Quoted 5 lines
I was trying to apply this on rc1, so ofcourse this fails for me? How do we resolve this?
I can skip this patch, provide a tag for this to be pulled into -net tree
Thanks, that's one option.
The other option is to postpone this patch, and apply it after v6.3-rc1.
Okay, done
Signature · 1 line
~Vinod
PATCH v2 7/9 PCI: tegra: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse the new devm_of_phy_optional_get() helper instead of open-coding the same operation.
---
v2:
- Add Acked-by.
--- drivers/pci/controller/pci-tegra.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/pci/controller/pci-tegra.c +1 -4
@@ -1330,12 +1330,9 @@ static struct phy *devm_of_phy_optional_get_index(struct device *dev,if (!name)return ERR_PTR (-ENOMEM ); - phy =devm_of_phy_get (dev, np, name); + phy =devm_of_phy_optional_get (dev, np, name);kfree (name); -if (PTR_ERR (phy) == -ENODEV ) - phy =NULL ; -return phy; }
Signature · 1 line
2.34.1
PATCH v2 8/9 usb: host: ehci-exynos: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse the new devm_of_phy_optional_get() helper instead of open-coding the same operation.
As devm_of_phy_optional_get() returns NULL if either the PHY cannot be found, or if support for the PHY framework is not enabled, it is no longer needed to check for -ENODEV or -ENOSYS.
This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.
---
v2:
- Add Reviewed-by,
- Clarify removed checks for -ENODEV and -ENOSYS,
- Remove error printing in case of real failures.
--- drivers/usb/host/ehci-exynos.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
drivers/usb/host/ehci-exynos.c +6 -17
@@ -80,19 +80,11 @@ static int exynos_ehci_get_phy(struct device *dev,return -EINVAL ; } - phy =devm_of_phy_get (dev, child,NULL ); + phy =devm_of_phy_optional_get (dev, child,NULL ); exynos_ehci->phy[phy_number] = phy;if (IS_ERR (phy)) { - ret =PTR_ERR (phy); -if (ret == -EPROBE_DEFER ) { -of_node_put (child); -return ret; - }else if (ret != -ENOSYS && ret != -ENODEV ) { -dev_err (dev, -"Error retrieving usb2 phy: %d\n" , ret); -of_node_put (child); -return ret; - } +of_node_put (child); +return PTR_ERR (phy); } }
@@ -108,12 +100,10 @@ static int exynos_ehci_phy_enable(struct device *dev)int ret =0 ;for (i =0 ; ret ==0 && i <PHY_NUMBER ; i++) -if (!IS_ERR (exynos_ehci->phy[i])) - ret =phy_power_on (exynos_ehci->phy[i]); + ret =phy_power_on (exynos_ehci->phy[i]);if (ret)for (i--; i >=0 ; i--) -if (!IS_ERR (exynos_ehci->phy[i])) -phy_power_off (exynos_ehci->phy[i]); +phy_power_off (exynos_ehci->phy[i]);return ret; }
@@ -125,8 +115,7 @@ static void exynos_ehci_phy_disable(struct device *dev)int i;for (i =0 ; i <PHY_NUMBER ; i++) -if (!IS_ERR (exynos_ehci->phy[i])) -phy_power_off (exynos_ehci->phy[i]); +phy_power_off (exynos_ehci->phy[i]); }static void exynos_setup_vbus_gpio (struct device *dev)
Signature · 1 line
2.34.1
Re: [PATCH v2 8/9] usb: host: ehci-exynos: Convert to devm_of_phy_optional_get()
Quoted 7 lines · Geert Uytterhoeven
Use the new
devm_of_phy_optional_get()helper instead of open-coding the same operation.As
devm_of_phy_optional_get()returns NULL if either the PHY cannot be found, or if support for the PHY framework is not enabled, it is no longer needed to check for-ENODEVor-ENOSYS.
Quoted 5 lines
This lets us drop several checks for
IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.Signed-off-by Geert Uytterhoeven <[email protected]>Reviewed-by Greg Kroah-Hartman <[email protected]>
PATCH v2 9/9 usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse the new devm_of_phy_optional_get() helper instead of open-coding the same operation.
As devm_of_phy_optional_get() returns NULL if either the PHY cannot be found, or if support for the PHY framework is not enabled, it is no longer needed to check for -ENODEV or -ENOSYS.
This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.
---
v2:
- Add Acked-by,
- Clarify removed checks for -ENODEV and -ENOSYS,
- Remove error printing in case of real failures.
--- drivers/usb/host/ohci-exynos.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
drivers/usb/host/ohci-exynos.c +6 -17
@@ -69,19 +69,11 @@ static int exynos_ohci_get_phy(struct device *dev,return -EINVAL ; } - phy =devm_of_phy_get (dev, child,NULL ); + phy =devm_of_phy_optional_get (dev, child,NULL ); exynos_ohci->phy[phy_number] = phy;if (IS_ERR (phy)) { - ret =PTR_ERR (phy); -if (ret == -EPROBE_DEFER ) { -of_node_put (child); -return ret; - }else if (ret != -ENOSYS && ret != -ENODEV ) { -dev_err (dev, -"Error retrieving usb2 phy: %d\n" , ret); -of_node_put (child); -return ret; - } +of_node_put (child); +return PTR_ERR (phy); } }
@@ -97,12 +89,10 @@ static int exynos_ohci_phy_enable(struct device *dev)int ret =0 ;for (i =0 ; ret ==0 && i <PHY_NUMBER ; i++) -if (!IS_ERR (exynos_ohci->phy[i])) - ret =phy_power_on (exynos_ohci->phy[i]); + ret =phy_power_on (exynos_ohci->phy[i]);if (ret)for (i--; i >=0 ; i--) -if (!IS_ERR (exynos_ohci->phy[i])) -phy_power_off (exynos_ohci->phy[i]); +phy_power_off (exynos_ohci->phy[i]);return ret; }
@@ -114,8 +104,7 @@ static void exynos_ohci_phy_disable(struct device *dev)int i;for (i =0 ; i <PHY_NUMBER ; i++) -if (!IS_ERR (exynos_ohci->phy[i])) -phy_power_off (exynos_ohci->phy[i]); +phy_power_off (exynos_ohci->phy[i]); }static int exynos_ohci_probe (struct platform_device *pdev)
Signature · 1 line
2.34.1
Re: [PATCH v2 9/9] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()
Quoted 7 lines · Geert Uytterhoeven
Use the new
devm_of_phy_optional_get()helper instead of open-coding the same operation.As
devm_of_phy_optional_get()returns NULL if either the PHY cannot be found, or if support for the PHY framework is not enabled, it is no longer needed to check for-ENODEVor-ENOSYS.
Quoted 5 lines
This lets us drop several checks for
IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.Signed-off-by Geert Uytterhoeven <[email protected]>Acked-by Alan Stern <[email protected]>
Hi Vinod,
Quoted 21 lines · Geert Uytterhoeven
While there exist several
optional_get()PHY helper functions, there is no optional variant ofdevm_of_phy_get(), leading to several drivers implementing this theirselves, sometimes in buggy ways.Hence this series, after two cleanup patches, introduces a
devm_of_phy_optional_get()helper(), and converts existing users ofdevm_of_phy_get()where appropriate.Changes compared to v1[1]:
- Incorporate "[PATCH v2 1/9] phy: Remove unusedphy_optional_get()", as it touches the same documentation,
- New patch "[PATCH v2 2/9] doc: phy: Documentdevm_of_phy_get()",
- Print an error message in case of failure, as requested by RobH,
- Update Documentation,
- Clarify removed checks for-ENODEVand-ENOSYS,
- Remove error printing in case of real failures from callers,
- Rebase am65-cpsw change on top of commit854617f52ab42418("net:
ethernet: ti: am65-cpsw: Handle -EPROBE_DEFER for Serdes PHY") in net-next (next-20230123 and later),
- Add Reviewed-by, Acked-by.
Quoted 2 lines
Most of this series been compile-tested only, but the new helper itself has been tested with a new user[2].
Are you happy with this? This series (at least patch 3) is a dependency for [2], and in [3] you said you could apply it and create an immutable branch.
Thanks!
Quoted 4 lines
[1] "[PATCH treewide 0/7] phy: Add
devm_of_phy_optional_get()helper"https://lore.kernel.org/r/[email protected] [2] "[PATCH 12/12] can: rcar_canfd: Add transceiver support" https://lore.kernel.org/r/e825b50a843ffe40e33f34e4d858c07c1b2ff259.1674499048.git.geert+renesas@glider.be
[3] https://lore.kernel.org/all/Y8kmG+jB%2Fs7stebA@matsya
Quoted 11 lines
Geert Uytterhoeven (9):
phy: Remove unusedphy_optional_get()
doc: phy: Documentdevm_of_phy_get()
phy: Adddevm_of_phy_optional_get()helper
net: fman: memac: Convert todevm_of_phy_optional_get()
net: lan966x: Convert todevm_of_phy_optional_get()
net: ethernet: ti: am65-cpsw: Convert todevm_of_phy_optional_get()
PCI: tegra: Convert todevm_of_phy_optional_get()
usb: host: ehci-exynos: Convert todevm_of_phy_optional_get()
usb: host: ohci-exynos: Convert todevm_of_phy_optional_get()
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Vinod Koul
maintainerQuoted 9 lines · Geert Uytterhoeven
Hi Vinod et al,
While there exist several
optional_get()PHY helper functions, there is no optional variant ofdevm_of_phy_get(), leading to several drivers implementing this theirselves, sometimes in buggy ways.Hence this series, after two cleanup patches, introduces a
devm_of_phy_optional_get()helper(), and converts existing users ofdevm_of_phy_get()where appropriate.
Applied and pushed to tag phy-devm_of_phy_optional_get
The following changes since commit 1b929c02afd37871d5afb9d498426f83432e71c2:
Linux 6.2-rc1 (2022-12-25 13:41:39 -0800)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy.git tags/phy-devm_of_phy_optional_get
for you to fetch changes up to 41a435e30eb007ca2c8f71db734af6ec3509af4d:
usb: host: ohci-exynos: Convert to devm_of_phy_optional_get() (2023-02-03 11:19:35 +0530)
----------------------------------------------------------------
Phy tag for new devm_of_phy_optional_get() API
----------------------------------------------------------------
Geert Uytterhoeven (8):
phy: Remove unused phy_optional_get()
doc: phy: Document devm_of_phy_get()
phy: Add devm_of_phy_optional_get() helper
net: fman: memac: Convert to devm_of_phy_optional_get()
net: lan966x: Convert to devm_of_phy_optional_get()
PCI: tegra: Convert to devm_of_phy_optional_get()
usb: host: ehci-exynos: Convert to devm_of_phy_optional_get()
usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()
Documentation/driver-api/phy/phy.rst | 24 ++++++++++++++---------- drivers/net/ethernet/freescale/fman/fman_memac.c | 9 ++++----- drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 5 ++--- drivers/pci/controller/pci-tegra.c | 5 +---- drivers/phy/phy-core.c | 51 ++++++++++++++++++++++++++++++--------------------- drivers/usb/host/ehci-exynos.c | 23 ++++++----------------- drivers/usb/host/ohci-exynos.c | 23 ++++++----------------- include/linux/phy/phy.h | 16 +++++++++------- 8 files changed, 72 insertions(+), 84 deletions(-)
Quoted 91 lines
Thanks!
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +3
-5@@ -1460,11 +1460,9 @@ static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *porstruct phy *phy;int ret; - phy =devm_of_phy_get (dev, port_np, name); -if (PTR_ERR (phy) == -ENODEV ) -return 0 ; -if (IS_ERR (phy)) -return PTR_ERR (phy); + phy =devm_of_phy_optional_get (dev, port_np, name); +if (IS_ERR_OR_NULL (phy)) +return PTR_ERR_OR_ZERO (phy);Quoted 2 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *por · line 1468
Quoted 2 lines
drivers/net/ethernet/ti/am65-cpsw-nuss.c +0
-0/* Serdes PHY exists. Store it. */ port->slave.serdes_phy = phy;Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus TorvaldsChanges compared to v1[1]:
- Incorporate "[PATCH v2 1/9] phy: Remove unusedphy_optional_get()", as it touches the same documentation,
- New patch "[PATCH v2 2/9] doc: phy: Documentdevm_of_phy_get()",
- Print an error message in case of failure, as requested by RobH,
- Update Documentation,
- Clarify removed checks for-ENODEVand-ENOSYS,
- Remove error printing in case of real failures from callers,
- Rebase am65-cpsw change on top of commit854617f52ab42418("net:
ethernet: ti: am65-cpsw: Handle -EPROBE_DEFER for Serdes PHY") in net-next (next-20230123 and later),
- Add Reviewed-by, Acked-by.Most of this series been compile-tested only, but the new helper itself has been tested with a new user[2].
Thanks for your comments!
[1] "[PATCH treewide 0/7] phy: Add
devm_of_phy_optional_get()helper"https://lore.kernel.org/r/[email protected] [2] "[PATCH 12/12] can: rcar_canfd: Add transceiver support" https://lore.kernel.org/r/e825b50a843ffe40e33f34e4d858c07c1b2ff259.1674499048.git.geert+renesas@glider.beGeert Uytterhoeven (9):
phy: Remove unusedphy_optional_get()
doc: phy: Documentdevm_of_phy_get()
phy: Adddevm_of_phy_optional_get()helper
net: fman: memac: Convert todevm_of_phy_optional_get()
net: lan966x: Convert todevm_of_phy_optional_get()
net: ethernet: ti: am65-cpsw: Convert todevm_of_phy_optional_get()
PCI: tegra: Convert todevm_of_phy_optional_get()
usb: host: ehci-exynos: Convert todevm_of_phy_optional_get()
usb: host: ohci-exynos: Convert todevm_of_phy_optional_get()Documentation/driver-api/phy/phy.rst | 24 +++++---- .../net/ethernet/freescale/fman/fman_memac.c | 9 ++-- .../ethernet/microchip/lan966x/lan966x_main.c | 5 +- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 8 ++- drivers/pci/controller/pci-tegra.c | 5 +- drivers/phy/phy-core.c | 51 +++++++++++-------- drivers/usb/host/ehci-exynos.c | 23 +++------ drivers/usb/host/ohci-exynos.c | 23 +++------ include/linux/phy/phy.h | 16 +++--- 9 files changed, 75 insertions(+), 89 deletions(-)Signature · 12 lines
2.34.1 Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Signature · 1 line
~Vinod