Skip to content

Commit 987351e

Browse files
atorguekishon
authored andcommitted
phy: core: Add consumer device link support
In order to enforce suspend/resume ordering, this commit creates link between phy consumers and phy devices. This link avoids to suspend phy before phy consumers. Signed-off-by: Alexandre Torgue <alexandre.torgue@st.com> [jonathanh@nvidia.com: Fix an abort when of_phy_get() returns error] Signed-off-by: Jonathan Hunter <jonathanh@nvidia.com> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
1 parent 24dbe0a commit 987351e

4 files changed

Lines changed: 53 additions & 9 deletions

File tree

‎drivers/phy/phy-core.c‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void devm_phy_release(struct device *dev, void *res)
2929
{
3030
struct phy *phy = *(struct phy **)res;
3131

32-
phy_put(phy);
32+
phy_put(dev, phy);
3333
}
3434

3535
static void devm_phy_provider_release(struct device *dev, void *res)
@@ -566,12 +566,12 @@ struct phy *of_phy_get(struct device_node *np, const char *con_id)
566566
EXPORT_SYMBOL_GPL(of_phy_get);
567567

568568
/**
569-
* phy_put() - release the PHY
570-
* @phy: the phy returned by phy_get()
569+
* of_phy_put() - release the PHY
570+
* @phy: the phy returned by of_phy_get()
571571
*
572-
* Releases a refcount the caller received from phy_get().
572+
* Releases a refcount the caller received from of_phy_get().
573573
*/
574-
void phy_put(struct phy *phy)
574+
void of_phy_put(struct phy *phy)
575575
{
576576
if (!phy || IS_ERR(phy))
577577
return;
@@ -584,6 +584,20 @@ void phy_put(struct phy *phy)
584584
module_put(phy->ops->owner);
585585
put_device(&phy->dev);
586586
}
587+
EXPORT_SYMBOL_GPL(of_phy_put);
588+
589+
/**
590+
* phy_put() - release the PHY
591+
* @dev: device that wants to release this phy
592+
* @phy: the phy returned by phy_get()
593+
*
594+
* Releases a refcount the caller received from phy_get().
595+
*/
596+
void phy_put(struct device *dev, struct phy *phy)
597+
{
598+
device_link_remove(dev, &phy->dev);
599+
of_phy_put(phy);
600+
}
587601
EXPORT_SYMBOL_GPL(phy_put);
588602

589603
/**
@@ -651,6 +665,7 @@ struct phy *phy_get(struct device *dev, const char *string)
651665
{
652666
int index = 0;
653667
struct phy *phy;
668+
struct device_link *link;
654669

655670
if (string == NULL) {
656671
dev_WARN(dev, "missing string\n");
@@ -672,6 +687,13 @@ struct phy *phy_get(struct device *dev, const char *string)
672687

673688
get_device(&phy->dev);
674689

690+
link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
691+
if (!link) {
692+
dev_err(dev, "failed to create device link to %s\n",
693+
dev_name(phy->dev.parent));
694+
return ERR_PTR(-EINVAL);
695+
}
696+
675697
return phy;
676698
}
677699
EXPORT_SYMBOL_GPL(phy_get);
@@ -765,6 +787,7 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
765787
const char *con_id)
766788
{
767789
struct phy **ptr, *phy;
790+
struct device_link *link;
768791

769792
ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
770793
if (!ptr)
@@ -776,6 +799,14 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
776799
devres_add(dev, ptr);
777800
} else {
778801
devres_free(ptr);
802+
return phy;
803+
}
804+
805+
link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
806+
if (!link) {
807+
dev_err(dev, "failed to create device link to %s\n",
808+
dev_name(phy->dev.parent));
809+
return ERR_PTR(-EINVAL);
779810
}
780811

781812
return phy;
@@ -798,6 +829,7 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
798829
int index)
799830
{
800831
struct phy **ptr, *phy;
832+
struct device_link *link;
801833

802834
ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
803835
if (!ptr)
@@ -819,6 +851,13 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
819851
*ptr = phy;
820852
devres_add(dev, ptr);
821853

854+
link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
855+
if (!link) {
856+
dev_err(dev, "failed to create device link to %s\n",
857+
dev_name(phy->dev.parent));
858+
return ERR_PTR(-EINVAL);
859+
}
860+
822861
return phy;
823862
}
824863
EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);

‎drivers/usb/renesas_usbhs/rcar2.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static int usbhs_rcar2_hardware_exit(struct platform_device *pdev)
3434
struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
3535

3636
if (priv->phy) {
37-
phy_put(priv->phy);
37+
phy_put(&pdev->dev, priv->phy);
3838
priv->phy = NULL;
3939
}
4040

‎drivers/usb/renesas_usbhs/rza2.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static int usbhs_rza2_hardware_exit(struct platform_device *pdev)
2929
{
3030
struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
3131

32-
phy_put(priv->phy);
32+
phy_put(&pdev->dev, priv->phy);
3333
priv->phy = NULL;
3434

3535
return 0;

‎include/linux/phy/phy.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
234234
const char *con_id);
235235
struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
236236
int index);
237-
void phy_put(struct phy *phy);
237+
void of_phy_put(struct phy *phy);
238+
void phy_put(struct device *dev, struct phy *phy);
238239
void devm_phy_put(struct device *dev, struct phy *phy);
239240
struct phy *of_phy_get(struct device_node *np, const char *con_id);
240241
struct phy *of_phy_simple_xlate(struct device *dev,
@@ -419,7 +420,11 @@ static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
419420
return ERR_PTR(-ENOSYS);
420421
}
421422

422-
static inline void phy_put(struct phy *phy)
423+
static inline void of_phy_put(struct phy *phy)
424+
{
425+
}
426+
427+
static inline void phy_put(struct device *dev, struct phy *phy)
423428
{
424429
}
425430

0 commit comments

Comments
 (0)