Skip to content

Commit 441a681

Browse files
shimodaykishon
authored andcommitted
phy: rcar-gen3-usb2: fix implementation for runtime PM
This patch fixes an issue that this driver doesn't take care of the runtime PM. This code assumed that devm_phy_create() called pm_runtime_enable(dev), but it misunderstood the dev_phy_create()'s specification. This driver should call its own pm_runtime_enable() before dev_phy_create(). Fixes: f3b5a8d ("phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver") Signed-off-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
1 parent 7dfa302 commit 441a681

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

drivers/phy/phy-rcar-gen3-usb2.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/of_address.h>
2121
#include <linux/phy/phy.h>
2222
#include <linux/platform_device.h>
23+
#include <linux/pm_runtime.h>
2324
#include <linux/regulator/consumer.h>
2425
#include <linux/workqueue.h>
2526

@@ -395,7 +396,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
395396
struct rcar_gen3_chan *channel;
396397
struct phy_provider *provider;
397398
struct resource *res;
398-
int irq;
399+
int irq, ret = 0;
399400

400401
if (!dev->of_node) {
401402
dev_err(dev, "This driver needs device tree\n");
@@ -434,17 +435,24 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
434435
}
435436
}
436437

437-
/* devm_phy_create() will call pm_runtime_enable(dev); */
438+
/*
439+
* devm_phy_create() will call pm_runtime_enable(&phy->dev);
440+
* And then, phy-core will manage runtime pm for this device.
441+
*/
442+
pm_runtime_enable(dev);
438443
channel->phy = devm_phy_create(dev, NULL, &rcar_gen3_phy_usb2_ops);
439444
if (IS_ERR(channel->phy)) {
440445
dev_err(dev, "Failed to create USB2 PHY\n");
441-
return PTR_ERR(channel->phy);
446+
ret = PTR_ERR(channel->phy);
447+
goto error;
442448
}
443449

444450
channel->vbus = devm_regulator_get_optional(dev, "vbus");
445451
if (IS_ERR(channel->vbus)) {
446-
if (PTR_ERR(channel->vbus) == -EPROBE_DEFER)
447-
return PTR_ERR(channel->vbus);
452+
if (PTR_ERR(channel->vbus) == -EPROBE_DEFER) {
453+
ret = PTR_ERR(channel->vbus);
454+
goto error;
455+
}
448456
channel->vbus = NULL;
449457
}
450458

@@ -454,15 +462,22 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
454462
provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
455463
if (IS_ERR(provider)) {
456464
dev_err(dev, "Failed to register PHY provider\n");
465+
ret = PTR_ERR(provider);
466+
goto error;
457467
} else if (channel->has_otg) {
458468
int ret;
459469

460470
ret = device_create_file(dev, &dev_attr_role);
461471
if (ret < 0)
462-
return ret;
472+
goto error;
463473
}
464474

465-
return PTR_ERR_OR_ZERO(provider);
475+
return 0;
476+
477+
error:
478+
pm_runtime_disable(dev);
479+
480+
return ret;
466481
}
467482

468483
static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
@@ -472,6 +487,8 @@ static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
472487
if (channel->has_otg)
473488
device_remove_file(&pdev->dev, &dev_attr_role);
474489

490+
pm_runtime_disable(&pdev->dev);
491+
475492
return 0;
476493
};
477494

0 commit comments

Comments
 (0)