mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
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> Link: https://patch.msgid.link/20260728-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v13-1-ae811e2f0799@linaro.org Signed-off-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
This commit is contained in:
committed by
Abel Vesa
parent
aeefe24281
commit
2dc441aaf2
+69
-26
@@ -606,22 +606,55 @@ 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;
|
||||
|
||||
mutex_lock(&phy_provider_mutex);
|
||||
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_unlock;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&phy_provider_mutex);
|
||||
|
||||
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
|
||||
*
|
||||
* Returns the phy associated with the given phandle value,
|
||||
* after getting a refcount to it or -ENODEV if there is no such phy or
|
||||
* -EPROBE_DEFER if there is a phandle to the phy, but the device is
|
||||
* not yet loaded. This function uses of_xlate call back function provided
|
||||
* while registering the phy_provider to find the phy instance.
|
||||
* Returns the phy associated with the given phandle value after getting
|
||||
* a refcount to it; -ENODEV if there is no such phy or the phy is
|
||||
* disabled; -EPROBE_DEFER if the phy provider is not yet available.
|
||||
*/
|
||||
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;
|
||||
|
||||
ret = of_parse_phandle_with_args(np, "phys", "#phy-cells",
|
||||
@@ -635,26 +668,8 @@ static struct phy *_of_phy_get(struct device_node *np, int index)
|
||||
goto out_put_node;
|
||||
}
|
||||
|
||||
mutex_lock(&phy_provider_mutex);
|
||||
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_unlock;
|
||||
}
|
||||
phy = _of_phy_get_with_args(&args);
|
||||
|
||||
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);
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&phy_provider_mutex);
|
||||
out_put_node:
|
||||
of_node_put(args.np);
|
||||
|
||||
@@ -986,6 +1001,34 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
|
||||
}
|
||||
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;
|
||||
|
||||
if (!np)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
phy = _of_phy_get_with_args(&args);
|
||||
|
||||
if (IS_ERR(phy))
|
||||
return phy;
|
||||
|
||||
if (!try_module_get(phy->ops->owner))
|
||||
return ERR_PTR(-EPROBE_DEFER);
|
||||
|
||||
get_device(&phy->dev);
|
||||
|
||||
return phy;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(phy_get_by_of_node);
|
||||
|
||||
/**
|
||||
* phy_create() - create a new phy
|
||||
* @dev: device that is creating the new phy
|
||||
|
||||
@@ -284,6 +284,7 @@ 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);
|
||||
struct phy *phy_get_by_of_node(struct device_node *np);
|
||||
void of_phy_put(struct phy *phy);
|
||||
void phy_put(struct device *dev, struct phy *phy);
|
||||
void devm_phy_put(struct device *dev, struct phy *phy);
|
||||
@@ -493,6 +494,11 @@ static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
|
||||
return ERR_PTR(-ENOSYS);
|
||||
}
|
||||
|
||||
static inline struct phy *phy_get_by_of_node(struct device_node *np)
|
||||
{
|
||||
return ERR_PTR(-ENOSYS);
|
||||
}
|
||||
|
||||
static inline void of_phy_put(struct phy *phy)
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user