Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Kamil Debski and committed by
Kishon Vijay Abraham I
b5d682f4 0b3f3b2c

+40
+31
drivers/phy/phy-core.c
··· 526 526 EXPORT_SYMBOL_GPL(devm_phy_optional_get); 527 527 528 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 + 559 + /** 529 560 * phy_create() - create a new phy 530 561 * @dev: device that is creating the new phy 531 562 * @ops: function pointers for performing phy operations
+9
include/linux/phy/phy.h
··· 149 149 struct phy *phy_optional_get(struct device *dev, const char *string); 150 150 struct phy *devm_phy_get(struct device *dev, const char *string); 151 151 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); 152 154 void phy_put(struct phy *phy); 153 155 void devm_phy_put(struct device *dev, struct phy *phy); 154 156 struct phy *of_phy_get(struct device_node *np, const char *con_id); ··· 250 248 251 249 static inline struct phy *devm_phy_optional_get(struct device *dev, 252 250 const char *string) 251 + { 252 + return ERR_PTR(-ENOSYS); 253 + } 254 + 255 + static inline struct phy *devm_of_phy_get(struct device *dev, 256 + struct device_node *np, 257 + const char *con_id) 253 258 { 254 259 return ERR_PTR(-ENOSYS); 255 260 }