Loading Documentation/driver-api/phy/phy.rst +14 −10 Original line number Diff line number Diff line Loading @@ -103,27 +103,31 @@ 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); 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); 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 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 devres data and devres data is freed. 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 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, Loading drivers/net/ethernet/freescale/fman/fman_memac.c +4 −5 Original line number Diff line number Diff line Loading @@ -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; } Loading drivers/net/ethernet/microchip/lan966x/lan966x_main.c +2 −3 Original line number Diff line number Diff line Loading @@ -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; Loading drivers/pci/controller/pci-tegra.c +1 −4 Original line number Diff line number Diff line Loading @@ -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; } Loading drivers/phy/phy-core.c +30 −21 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -879,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 Loading Loading
Documentation/driver-api/phy/phy.rst +14 −10 Original line number Diff line number Diff line Loading @@ -103,27 +103,31 @@ 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); 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); 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 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 devres data and devres data is freed. 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 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, Loading
drivers/net/ethernet/freescale/fman/fman_memac.c +4 −5 Original line number Diff line number Diff line Loading @@ -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; } Loading
drivers/net/ethernet/microchip/lan966x/lan966x_main.c +2 −3 Original line number Diff line number Diff line Loading @@ -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; Loading
drivers/pci/controller/pci-tegra.c +1 −4 Original line number Diff line number Diff line Loading @@ -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; } Loading
drivers/phy/phy-core.c +30 −21 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -879,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 Loading