Skip to content

Commit 98bc06c

Browse files
alcoopergregkh
authored andcommitted
phy: usb: Leave some clocks running during suspend
[ Upstream commit 42fed57 ] The PHY client driver does a phy_exit() call on suspend or rmmod and the PHY driver needs to know the difference because some clocks need to be kept running for suspend but can be shutdown on unbind/rmmod (or if there are no PHY clients at all). The fix is to use a PM notifier so the driver can tell if a PHY client is calling exit() because of a system suspend or a driver unbind/rmmod. Signed-off-by: Al Cooper <alcooperx@gmail.com> Acked-by: Florian Fainelli <f.fainelli@gmail.com> Link: https://lore.kernel.org/r/20211201180653.35097-2-alcooperx@gmail.com Signed-off-by: Vinod Koul <vkoul@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 717f2fa commit 98bc06c

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎drivers/phy/broadcom/phy-brcm-usb.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/soc/brcmstb/brcmstb.h>
1818
#include <dt-bindings/phy/phy.h>
1919
#include <linux/mfd/syscon.h>
20+
#include <linux/suspend.h>
2021

2122
#include "phy-brcm-usb-init.h"
2223

@@ -69,12 +70,35 @@ struct brcm_usb_phy_data {
6970
int init_count;
7071
int wake_irq;
7172
struct brcm_usb_phy phys[BRCM_USB_PHY_ID_MAX];
73+
struct notifier_block pm_notifier;
74+
bool pm_active;
7275
};
7376

7477
static s8 *node_reg_names[BRCM_REGS_MAX] = {
7578
"crtl", "xhci_ec", "xhci_gbl", "usb_phy", "usb_mdio", "bdc_ec"
7679
};
7780

81+
static int brcm_pm_notifier(struct notifier_block *notifier,
82+
unsigned long pm_event,
83+
void *unused)
84+
{
85+
struct brcm_usb_phy_data *priv =
86+
container_of(notifier, struct brcm_usb_phy_data, pm_notifier);
87+
88+
switch (pm_event) {
89+
case PM_HIBERNATION_PREPARE:
90+
case PM_SUSPEND_PREPARE:
91+
priv->pm_active = true;
92+
break;
93+
case PM_POST_RESTORE:
94+
case PM_POST_HIBERNATION:
95+
case PM_POST_SUSPEND:
96+
priv->pm_active = false;
97+
break;
98+
}
99+
return NOTIFY_DONE;
100+
}
101+
78102
static irqreturn_t brcm_usb_phy_wake_isr(int irq, void *dev_id)
79103
{
80104
struct phy *gphy = dev_id;
@@ -90,6 +114,9 @@ static int brcm_usb_phy_init(struct phy *gphy)
90114
struct brcm_usb_phy_data *priv =
91115
container_of(phy, struct brcm_usb_phy_data, phys[phy->id]);
92116

117+
if (priv->pm_active)
118+
return 0;
119+
93120
/*
94121
* Use a lock to make sure a second caller waits until
95122
* the base phy is inited before using it.
@@ -119,6 +146,9 @@ static int brcm_usb_phy_exit(struct phy *gphy)
119146
struct brcm_usb_phy_data *priv =
120147
container_of(phy, struct brcm_usb_phy_data, phys[phy->id]);
121148

149+
if (priv->pm_active)
150+
return 0;
151+
122152
dev_dbg(&gphy->dev, "EXIT\n");
123153
if (phy->id == BRCM_USB_PHY_2_0)
124154
brcm_usb_uninit_eohci(&priv->ini);
@@ -484,6 +514,9 @@ static int brcm_usb_phy_probe(struct platform_device *pdev)
484514
if (err)
485515
return err;
486516

517+
priv->pm_notifier.notifier_call = brcm_pm_notifier;
518+
register_pm_notifier(&priv->pm_notifier);
519+
487520
mutex_init(&priv->mutex);
488521

489522
/* make sure invert settings are correct */
@@ -524,7 +557,10 @@ static int brcm_usb_phy_probe(struct platform_device *pdev)
524557

525558
static int brcm_usb_phy_remove(struct platform_device *pdev)
526559
{
560+
struct brcm_usb_phy_data *priv = dev_get_drvdata(&pdev->dev);
561+
527562
sysfs_remove_group(&pdev->dev.kobj, &brcm_usb_phy_group);
563+
unregister_pm_notifier(&priv->pm_notifier);
528564

529565
return 0;
530566
}
@@ -535,6 +571,7 @@ static int brcm_usb_phy_suspend(struct device *dev)
535571
struct brcm_usb_phy_data *priv = dev_get_drvdata(dev);
536572

537573
if (priv->init_count) {
574+
dev_dbg(dev, "SUSPEND\n");
538575
priv->ini.wake_enabled = device_may_wakeup(dev);
539576
if (priv->phys[BRCM_USB_PHY_3_0].inited)
540577
brcm_usb_uninit_xhci(&priv->ini);
@@ -574,6 +611,7 @@ static int brcm_usb_phy_resume(struct device *dev)
574611
* Uninitialize anything that wasn't previously initialized.
575612
*/
576613
if (priv->init_count) {
614+
dev_dbg(dev, "RESUME\n");
577615
if (priv->wake_irq >= 0)
578616
disable_irq_wake(priv->wake_irq);
579617
brcm_usb_init_common(&priv->ini);

0 commit comments

Comments
 (0)