diff options
| author | Bryan O'Donoghue <bryan.odonoghue@linaro.org> | 2026-09-18 14:56:37 +0100 |
|---|---|---|
| committer | Vinod Koul <vkoul@kernel.org> | 2026-09-23 18:00:28 +0530 |
| commit | 1b7ef606894ac81b5d95b51fe05475a3aedba411 (patch) | |
| tree | 1b23811f6fa2a6f4cfa3dcc61398ab7b2e061e19 /drivers/phy | |
| parent | df4cdf0a63cccb51f121aea7ea52796fac94d0c5 (diff) | |
| download | linux-next-1b7ef606894ac81b5d95b51fe05475a3aedba411.tar.gz linux-next-1b7ef606894ac81b5d95b51fe05475a3aedba411.zip | |
phy: core: Add phy_get_by_of_node()
Add new function phy_get_by_of_node() allowing lookup of a phy by
device_node. Separates existing logic in _of_phy_get() into an internal
helper method _of_phy_get_with_args() to allow for reuse in new method.
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://patch.msgid.link/20260918-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v20-2-dc244e124e71@linaro.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Diffstat (limited to 'drivers/phy')
| -rw-r--r-- | drivers/phy/phy-core.c | 83 |
1 files changed, 65 insertions, 18 deletions
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 89addd732bff..42c27a2b4515 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -607,6 +607,38 @@ int phy_validate(struct phy *phy, enum phy_mode mode, int submode, EXPORT_SYMBOL_GPL(phy_validate); /** + * _of_phy_get_with_args() - lookup and obtain a reference to a phy by of_phandle_args + * @args: of_phandle_args to the phy + * + * Returns: the phy from the provider's of_xlate, -ENODEV if disabled, + * -EPROBE_DEFER if the provider is not yet registered. + */ +static struct phy *_of_phy_get_with_args(struct of_phandle_args *args) +{ + struct phy *phy; + struct phy_provider *phy_provider; + + lockdep_assert_held(&phy_provider_mutex); + + phy_provider = of_phy_provider_lookup(args->np); + if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) + return ERR_PTR(-EPROBE_DEFER); + + if (!of_device_is_available(args->np)) { + dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); + phy = ERR_PTR(-ENODEV); + goto out_put_module; + } + + phy = phy_provider->of_xlate(phy_provider->dev, args); + +out_put_module: + module_put(phy_provider->owner); + + return phy; +} + +/** * _of_phy_get() - lookup and obtain a reference to a phy by phandle * @np: device_node for which to get the phy * @index: the index of the phy @@ -620,8 +652,7 @@ EXPORT_SYMBOL_GPL(phy_validate); static struct phy *_of_phy_get(struct device_node *np, int index) { int ret; - struct phy_provider *phy_provider; - struct phy *phy = NULL; + struct phy *phy; struct of_phandle_args args; lockdep_assert_held(&phy_provider_mutex); @@ -637,22 +668,7 @@ static struct phy *_of_phy_get(struct device_node *np, int index) goto out_put_node; } - phy_provider = of_phy_provider_lookup(args.np); - if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) { - phy = ERR_PTR(-EPROBE_DEFER); - goto out_put_node; - } - - if (!of_device_is_available(args.np)) { - dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); - phy = ERR_PTR(-ENODEV); - goto out_put_module; - } - - phy = phy_provider->of_xlate(phy_provider->dev, &args); - -out_put_module: - module_put(phy_provider->owner); + phy = _of_phy_get_with_args(&args); out_put_node: of_node_put(args.np); @@ -1002,6 +1018,37 @@ out_unlock: EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index); /** + * phy_get_by_of_node() - lookup and obtain a reference to a phy by device_node + * @np: node containing the phy + * + * Returns: the phy associated with the device node or ERR_PTR. + */ +struct phy *phy_get_by_of_node(struct device_node *np) +{ + struct of_phandle_args args = { .np = np, .args_count = 0 }; + struct phy *phy; + + mutex_lock(&phy_provider_mutex); + + phy = _of_phy_get_with_args(&args); + if (IS_ERR(phy)) + goto out_unlock; + + if (!try_module_get(phy->ops->owner)) { + phy = ERR_PTR(-EPROBE_DEFER); + goto out_unlock; + } + + get_device(&phy->dev); + +out_unlock: + mutex_unlock(&phy_provider_mutex); + + return phy; +} +EXPORT_SYMBOL_GPL(phy_get_by_of_node); + +/** * phy_create() - create a new phy * @dev: device that is creating the new phy * @node: device node of the phy |
