Skip to content

Commit b5d682f

Browse files
Kamil Debskikishon
authored andcommitted
phy: core: Add devm_of_phy_get to phy-core
Adding devm_of_phy_get will allow to get phys by supplying a pointer to the struct device_node instead of struct device. Signed-off-by: Kamil Debski <k.debski@samsung.com> Reviewed-by: Tomasz Figa <t.figa@samsung.com> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
1 parent 0b3f3b2 commit b5d682f

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎drivers/phy/phy-core.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,37 @@ struct phy *devm_phy_optional_get(struct device *dev, const char *string)
525525
}
526526
EXPORT_SYMBOL_GPL(devm_phy_optional_get);
527527

528+
/**
529+
* devm_of_phy_get() - lookup and obtain a reference to a phy.
530+
* @dev: device that requests this phy
531+
* @np: node containing the phy
532+
* @con_id: name of the phy from device's point of view
533+
*
534+
* Gets the phy using of_phy_get(), and associates a device with it using
535+
* devres. On driver detach, release function is invoked on the devres data,
536+
* then, devres data is freed.
537+
*/
538+
struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
539+
const char *con_id)
540+
{
541+
struct phy **ptr, *phy;
542+
543+
ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
544+
if (!ptr)
545+
return ERR_PTR(-ENOMEM);
546+
547+
phy = of_phy_get(np, con_id);
548+
if (!IS_ERR(phy)) {
549+
*ptr = phy;
550+
devres_add(dev, ptr);
551+
} else {
552+
devres_free(ptr);
553+
}
554+
555+
return phy;
556+
}
557+
EXPORT_SYMBOL_GPL(devm_of_phy_get);
558+
528559
/**
529560
* phy_create() - create a new phy
530561
* @dev: device that is creating the new phy

‎include/linux/phy/phy.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ struct phy *phy_get(struct device *dev, const char *string);
149149
struct phy *phy_optional_get(struct device *dev, const char *string);
150150
struct phy *devm_phy_get(struct device *dev, const char *string);
151151
struct phy *devm_phy_optional_get(struct device *dev, const char *string);
152+
struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
153+
const char *con_id);
152154
void phy_put(struct phy *phy);
153155
void devm_phy_put(struct device *dev, struct phy *phy);
154156
struct phy *of_phy_get(struct device_node *np, const char *con_id);
@@ -252,6 +254,13 @@ static inline struct phy *devm_phy_optional_get(struct device *dev,
252254
return ERR_PTR(-ENOSYS);
253255
}
254256

257+
static inline struct phy *devm_of_phy_get(struct device *dev,
258+
struct device_node *np,
259+
const char *con_id)
260+
{
261+
return ERR_PTR(-ENOSYS);
262+
}
263+
255264
static inline void phy_put(struct phy *phy)
256265
{
257266
}

0 commit comments

Comments
 (0)