Skip to content

Commit cc94cc1

Browse files
committed
Merge tag 'phy-devm_of_phy_optional_get' into next
Merge tag phy-devm_of_phy_optional_get into next to bring in the new devm_of_phy_optional_get() API and users
2 parents 05bd183 + 41a435e commit cc94cc1

File tree

8 files changed

+72
-84
lines changed

8 files changed

+72
-84
lines changed

Documentation/driver-api/phy/phy.rst

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,31 @@ it. This framework provides the following APIs to get a reference to the PHY.
103103
::
104104

105105
struct phy *phy_get(struct device *dev, const char *string);
106-
struct phy *phy_optional_get(struct device *dev, const char *string);
107106
struct phy *devm_phy_get(struct device *dev, const char *string);
108107
struct phy *devm_phy_optional_get(struct device *dev,
109108
const char *string);
109+
struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
110+
const char *con_id);
111+
struct phy *devm_of_phy_optional_get(struct device *dev,
112+
struct device_node *np,
113+
const char *con_id);
110114
struct phy *devm_of_phy_get_by_index(struct device *dev,
111115
struct device_node *np,
112116
int index);
113117

114-
phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can
115-
be used to get the PHY. In the case of dt boot, the string arguments
118+
phy_get, devm_phy_get and devm_phy_optional_get can be used to get the PHY.
119+
In the case of dt boot, the string arguments
116120
should contain the phy name as given in the dt data and in the case of
117121
non-dt boot, it should contain the label of the PHY. The two
118122
devm_phy_get associates the device with the PHY using devres on
119123
successful PHY get. On driver detach, release function is invoked on
120-
the devres data and devres data is freed. phy_optional_get and
121-
devm_phy_optional_get should be used when the phy is optional. These
122-
two functions will never return -ENODEV, but instead returns NULL when
123-
the phy cannot be found.Some generic drivers, such as ehci, may use multiple
124-
phys and for such drivers referencing phy(s) by name(s) does not make sense. In
125-
this case, devm_of_phy_get_by_index can be used to get a phy reference based on
126-
the index.
124+
the devres data and devres data is freed.
125+
The _optional_get variants should be used when the phy is optional. These
126+
functions will never return -ENODEV, but instead return NULL when
127+
the phy cannot be found.
128+
Some generic drivers, such as ehci, may use multiple phys. In this case,
129+
devm_of_phy_get or devm_of_phy_get_by_index can be used to get a phy
130+
reference based on name or index.
127131

128132
It should be noted that NULL is a valid phy reference. All phy
129133
consumer calls on the NULL phy become NOPs. That is the release calls,

drivers/net/ethernet/freescale/fman/fman_memac.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,13 +1152,12 @@ int memac_initialization(struct mac_device *mac_dev,
11521152
else
11531153
memac->sgmii_pcs = pcs;
11541154

1155-
memac->serdes = devm_of_phy_get(mac_dev->dev, mac_node, "serdes");
1156-
err = PTR_ERR(memac->serdes);
1157-
if (err == -ENODEV || err == -ENOSYS) {
1155+
memac->serdes = devm_of_phy_optional_get(mac_dev->dev, mac_node,
1156+
"serdes");
1157+
if (!memac->serdes) {
11581158
dev_dbg(mac_dev->dev, "could not get (optional) serdes\n");
1159-
memac->serdes = NULL;
11601159
} else if (IS_ERR(memac->serdes)) {
1161-
dev_err_probe(mac_dev->dev, err, "could not get serdes\n");
1160+
err = PTR_ERR(memac->serdes);
11621161
goto _return_fm_mac_free;
11631162
}
11641163

drivers/net/ethernet/microchip/lan966x/lan966x_main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,9 +1147,8 @@ static int lan966x_probe(struct platform_device *pdev)
11471147
lan966x->ports[p]->config.portmode = phy_mode;
11481148
lan966x->ports[p]->fwnode = fwnode_handle_get(portnp);
11491149

1150-
serdes = devm_of_phy_get(lan966x->dev, to_of_node(portnp), NULL);
1151-
if (PTR_ERR(serdes) == -ENODEV)
1152-
serdes = NULL;
1150+
serdes = devm_of_phy_optional_get(lan966x->dev,
1151+
to_of_node(portnp), NULL);
11531152
if (IS_ERR(serdes)) {
11541153
err = PTR_ERR(serdes);
11551154
goto cleanup_ports;

drivers/pci/controller/pci-tegra.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,12 +1330,9 @@ static struct phy *devm_of_phy_optional_get_index(struct device *dev,
13301330
if (!name)
13311331
return ERR_PTR(-ENOMEM);
13321332

1333-
phy = devm_of_phy_get(dev, np, name);
1333+
phy = devm_of_phy_optional_get(dev, np, name);
13341334
kfree(name);
13351335

1336-
if (PTR_ERR(phy) == -ENODEV)
1337-
phy = NULL;
1338-
13391336
return phy;
13401337
}
13411338

drivers/phy/phy-core.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -766,27 +766,6 @@ struct phy *phy_get(struct device *dev, const char *string)
766766
}
767767
EXPORT_SYMBOL_GPL(phy_get);
768768

769-
/**
770-
* phy_optional_get() - lookup and obtain a reference to an optional phy.
771-
* @dev: device that requests this phy
772-
* @string: the phy name as given in the dt data or the name of the controller
773-
* port for non-dt case
774-
*
775-
* Returns the phy driver, after getting a refcount to it; or
776-
* NULL if there is no such phy. The caller is responsible for
777-
* calling phy_put() to release that count.
778-
*/
779-
struct phy *phy_optional_get(struct device *dev, const char *string)
780-
{
781-
struct phy *phy = phy_get(dev, string);
782-
783-
if (PTR_ERR(phy) == -ENODEV)
784-
phy = NULL;
785-
786-
return phy;
787-
}
788-
EXPORT_SYMBOL_GPL(phy_optional_get);
789-
790769
/**
791770
* devm_phy_get() - lookup and obtain a reference to a phy.
792771
* @dev: device that requests this phy
@@ -879,6 +858,36 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
879858
}
880859
EXPORT_SYMBOL_GPL(devm_of_phy_get);
881860

861+
/**
862+
* devm_of_phy_optional_get() - lookup and obtain a reference to an optional
863+
* phy.
864+
* @dev: device that requests this phy
865+
* @np: node containing the phy
866+
* @con_id: name of the phy from device's point of view
867+
*
868+
* Gets the phy using of_phy_get(), and associates a device with it using
869+
* devres. On driver detach, release function is invoked on the devres data,
870+
* then, devres data is freed. This differs to devm_of_phy_get() in
871+
* that if the phy does not exist, it is not considered an error and
872+
* -ENODEV will not be returned. Instead the NULL phy is returned,
873+
* which can be passed to all other phy consumer calls.
874+
*/
875+
struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np,
876+
const char *con_id)
877+
{
878+
struct phy *phy = devm_of_phy_get(dev, np, con_id);
879+
880+
if (PTR_ERR(phy) == -ENODEV)
881+
phy = NULL;
882+
883+
if (IS_ERR(phy))
884+
dev_err_probe(dev, PTR_ERR(phy), "failed to get PHY %pOF:%s",
885+
np, con_id);
886+
887+
return phy;
888+
}
889+
EXPORT_SYMBOL_GPL(devm_of_phy_optional_get);
890+
882891
/**
883892
* devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index.
884893
* @dev: device that requests this phy

drivers/usb/host/ehci-exynos.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,11 @@ static int exynos_ehci_get_phy(struct device *dev,
8080
return -EINVAL;
8181
}
8282

83-
phy = devm_of_phy_get(dev, child, NULL);
83+
phy = devm_of_phy_optional_get(dev, child, NULL);
8484
exynos_ehci->phy[phy_number] = phy;
8585
if (IS_ERR(phy)) {
86-
ret = PTR_ERR(phy);
87-
if (ret == -EPROBE_DEFER) {
88-
of_node_put(child);
89-
return ret;
90-
} else if (ret != -ENOSYS && ret != -ENODEV) {
91-
dev_err(dev,
92-
"Error retrieving usb2 phy: %d\n", ret);
93-
of_node_put(child);
94-
return ret;
95-
}
86+
of_node_put(child);
87+
return PTR_ERR(phy);
9688
}
9789
}
9890

@@ -108,12 +100,10 @@ static int exynos_ehci_phy_enable(struct device *dev)
108100
int ret = 0;
109101

110102
for (i = 0; ret == 0 && i < PHY_NUMBER; i++)
111-
if (!IS_ERR(exynos_ehci->phy[i]))
112-
ret = phy_power_on(exynos_ehci->phy[i]);
103+
ret = phy_power_on(exynos_ehci->phy[i]);
113104
if (ret)
114105
for (i--; i >= 0; i--)
115-
if (!IS_ERR(exynos_ehci->phy[i]))
116-
phy_power_off(exynos_ehci->phy[i]);
106+
phy_power_off(exynos_ehci->phy[i]);
117107

118108
return ret;
119109
}
@@ -125,8 +115,7 @@ static void exynos_ehci_phy_disable(struct device *dev)
125115
int i;
126116

127117
for (i = 0; i < PHY_NUMBER; i++)
128-
if (!IS_ERR(exynos_ehci->phy[i]))
129-
phy_power_off(exynos_ehci->phy[i]);
118+
phy_power_off(exynos_ehci->phy[i]);
130119
}
131120

132121
static void exynos_setup_vbus_gpio(struct device *dev)

drivers/usb/host/ohci-exynos.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,11 @@ static int exynos_ohci_get_phy(struct device *dev,
6969
return -EINVAL;
7070
}
7171

72-
phy = devm_of_phy_get(dev, child, NULL);
72+
phy = devm_of_phy_optional_get(dev, child, NULL);
7373
exynos_ohci->phy[phy_number] = phy;
7474
if (IS_ERR(phy)) {
75-
ret = PTR_ERR(phy);
76-
if (ret == -EPROBE_DEFER) {
77-
of_node_put(child);
78-
return ret;
79-
} else if (ret != -ENOSYS && ret != -ENODEV) {
80-
dev_err(dev,
81-
"Error retrieving usb2 phy: %d\n", ret);
82-
of_node_put(child);
83-
return ret;
84-
}
75+
of_node_put(child);
76+
return PTR_ERR(phy);
8577
}
8678
}
8779

@@ -97,12 +89,10 @@ static int exynos_ohci_phy_enable(struct device *dev)
9789
int ret = 0;
9890

9991
for (i = 0; ret == 0 && i < PHY_NUMBER; i++)
100-
if (!IS_ERR(exynos_ohci->phy[i]))
101-
ret = phy_power_on(exynos_ohci->phy[i]);
92+
ret = phy_power_on(exynos_ohci->phy[i]);
10293
if (ret)
10394
for (i--; i >= 0; i--)
104-
if (!IS_ERR(exynos_ohci->phy[i]))
105-
phy_power_off(exynos_ohci->phy[i]);
95+
phy_power_off(exynos_ohci->phy[i]);
10696

10797
return ret;
10898
}
@@ -114,8 +104,7 @@ static void exynos_ohci_phy_disable(struct device *dev)
114104
int i;
115105

116106
for (i = 0; i < PHY_NUMBER; i++)
117-
if (!IS_ERR(exynos_ohci->phy[i]))
118-
phy_power_off(exynos_ohci->phy[i]);
107+
phy_power_off(exynos_ohci->phy[i]);
119108
}
120109

121110
static int exynos_ohci_probe(struct platform_device *pdev)

include/linux/phy/phy.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,12 @@ static inline void phy_set_bus_width(struct phy *phy, int bus_width)
250250
phy->attrs.bus_width = bus_width;
251251
}
252252
struct phy *phy_get(struct device *dev, const char *string);
253-
struct phy *phy_optional_get(struct device *dev, const char *string);
254253
struct phy *devm_phy_get(struct device *dev, const char *string);
255254
struct phy *devm_phy_optional_get(struct device *dev, const char *string);
256255
struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
257256
const char *con_id);
257+
struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np,
258+
const char *con_id);
258259
struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
259260
int index);
260261
void of_phy_put(struct phy *phy);
@@ -426,12 +427,6 @@ static inline struct phy *phy_get(struct device *dev, const char *string)
426427
return ERR_PTR(-ENOSYS);
427428
}
428429

429-
static inline struct phy *phy_optional_get(struct device *dev,
430-
const char *string)
431-
{
432-
return ERR_PTR(-ENOSYS);
433-
}
434-
435430
static inline struct phy *devm_phy_get(struct device *dev, const char *string)
436431
{
437432
return ERR_PTR(-ENOSYS);
@@ -450,6 +445,13 @@ static inline struct phy *devm_of_phy_get(struct device *dev,
450445
return ERR_PTR(-ENOSYS);
451446
}
452447

448+
static inline struct phy *devm_of_phy_optional_get(struct device *dev,
449+
struct device_node *np,
450+
const char *con_id)
451+
{
452+
return NULL;
453+
}
454+
453455
static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
454456
struct device_node *np,
455457
int index)

0 commit comments

Comments
 (0)