Skip to content

Commit 34cca0c

Browse files
tlebgregkh
authored andcommitted
usb: xhci: change xhci_resume() parameters to explicit the desired info
Previous signature was: int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg); Internally, it extracted two information out of the message: - whether we are after hibernation: msg.event == PM_EVENT_RESTORE, - whether this is an auto resume: msg.event == PM_EVENT_AUTO_RESUME. First bulletpoint is somewhat wrong: driver wants to know if the device did lose power, it doesn't care about hibernation per se. Knowing that, refactor to ask upper layers the right questions: (1) "did we lose power?" and, (2) "is this an auto resume?". Change the signature to: int xhci_resume(struct xhci_hcd *xhci, bool power_lost, bool is_auto_resume); The goal is to allow some upper layers (cdns3-plat) to tell us when power was lost after system-wise suspend. Note that lost_power is ORed at the start of xhci_resume() to xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend. It is simpler to keep those checks inside of xhci_resume() instead of doing them at each caller of xhci_resume(). Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> Link: https://lore.kernel.org/r/20250205-s2r-cdns-v7-7-13658a271c3c@bootlin.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9925aa4 commit 34cca0c

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

drivers/usb/host/xhci-histb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static int __maybe_unused xhci_histb_resume(struct device *dev)
355355
if (!device_may_wakeup(dev))
356356
xhci_histb_host_enable(histb);
357357

358-
return xhci_resume(xhci, PMSG_RESUME);
358+
return xhci_resume(xhci, false, false);
359359
}
360360

361361
static const struct dev_pm_ops xhci_histb_pm_ops = {

drivers/usb/host/xhci-pci.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,10 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
807807

808808
static int xhci_pci_resume(struct usb_hcd *hcd, pm_message_t msg)
809809
{
810-
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
811-
struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
810+
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
811+
struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
812+
bool power_lost = msg.event == PM_EVENT_RESTORE;
813+
bool is_auto_resume = msg.event == PM_EVENT_AUTO_RESUME;
812814

813815
reset_control_reset(xhci->reset);
814816

@@ -839,7 +841,7 @@ static int xhci_pci_resume(struct usb_hcd *hcd, pm_message_t msg)
839841
if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
840842
xhci_pme_quirk(hcd);
841843

842-
return xhci_resume(xhci, msg);
844+
return xhci_resume(xhci, power_lost, is_auto_resume);
843845
}
844846

845847
static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup)

drivers/usb/host/xhci-plat.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static int xhci_plat_suspend(struct device *dev)
479479
return 0;
480480
}
481481

482-
static int xhci_plat_resume_common(struct device *dev, struct pm_message pmsg)
482+
static int xhci_plat_resume_common(struct device *dev, bool power_lost)
483483
{
484484
struct usb_hcd *hcd = dev_get_drvdata(dev);
485485
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
@@ -501,7 +501,7 @@ static int xhci_plat_resume_common(struct device *dev, struct pm_message pmsg)
501501
if (ret)
502502
goto disable_clks;
503503

504-
ret = xhci_resume(xhci, pmsg);
504+
ret = xhci_resume(xhci, power_lost, false);
505505
if (ret)
506506
goto disable_clks;
507507

@@ -522,12 +522,12 @@ static int xhci_plat_resume_common(struct device *dev, struct pm_message pmsg)
522522

523523
static int xhci_plat_resume(struct device *dev)
524524
{
525-
return xhci_plat_resume_common(dev, PMSG_RESUME);
525+
return xhci_plat_resume_common(dev, false);
526526
}
527527

528528
static int xhci_plat_restore(struct device *dev)
529529
{
530-
return xhci_plat_resume_common(dev, PMSG_RESTORE);
530+
return xhci_plat_resume_common(dev, true);
531531
}
532532

533533
static int __maybe_unused xhci_plat_runtime_suspend(struct device *dev)
@@ -548,7 +548,7 @@ static int __maybe_unused xhci_plat_runtime_resume(struct device *dev)
548548
struct usb_hcd *hcd = dev_get_drvdata(dev);
549549
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
550550

551-
return xhci_resume(xhci, PMSG_AUTO_RESUME);
551+
return xhci_resume(xhci, false, true);
552552
}
553553

554554
const struct dev_pm_ops xhci_plat_pm_ops = {

drivers/usb/host/xhci-tegra.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ static int tegra_xusb_exit_elpg(struct tegra_xusb *tegra, bool is_auto_resume)
22872287
if (wakeup)
22882288
tegra_xhci_disable_phy_sleepwalk(tegra);
22892289

2290-
err = xhci_resume(xhci, is_auto_resume ? PMSG_AUTO_RESUME : PMSG_RESUME);
2290+
err = xhci_resume(xhci, false, is_auto_resume);
22912291
if (err < 0) {
22922292
dev_err(tegra->dev, "failed to resume XHCI: %d\n", err);
22932293
goto disable_phy;

drivers/usb/host/xhci.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -994,16 +994,14 @@ EXPORT_SYMBOL_GPL(xhci_suspend);
994994
* This is called when the machine transition from S3/S4 mode.
995995
*
996996
*/
997-
int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg)
997+
int xhci_resume(struct xhci_hcd *xhci, bool power_lost, bool is_auto_resume)
998998
{
999-
bool hibernated = (msg.event == PM_EVENT_RESTORE);
1000999
u32 command, temp = 0;
10011000
struct usb_hcd *hcd = xhci_to_hcd(xhci);
10021001
int retval = 0;
10031002
bool comp_timer_running = false;
10041003
bool pending_portevent = false;
10051004
bool suspended_usb3_devs = false;
1006-
bool reinit_xhc = false;
10071005

10081006
if (!hcd->state)
10091007
return 0;
@@ -1022,10 +1020,10 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg)
10221020

10231021
spin_lock_irq(&xhci->lock);
10241022

1025-
if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend)
1026-
reinit_xhc = true;
1023+
if (xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend)
1024+
power_lost = true;
10271025

1028-
if (!reinit_xhc) {
1026+
if (!power_lost) {
10291027
/*
10301028
* Some controllers might lose power during suspend, so wait
10311029
* for controller not ready bit to clear, just as in xHC init.
@@ -1065,12 +1063,12 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg)
10651063
/* re-initialize the HC on Restore Error, or Host Controller Error */
10661064
if ((temp & (STS_SRE | STS_HCE)) &&
10671065
!(xhci->xhc_state & XHCI_STATE_REMOVING)) {
1068-
reinit_xhc = true;
1069-
if (!xhci->broken_suspend)
1066+
if (!power_lost)
10701067
xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp);
1068+
power_lost = true;
10711069
}
10721070

1073-
if (reinit_xhc) {
1071+
if (power_lost) {
10741072
if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
10751073
!(xhci_all_ports_seen_u0(xhci))) {
10761074
del_timer_sync(&xhci->comp_mode_recovery_timer);
@@ -1168,8 +1166,7 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg)
11681166

11691167
pending_portevent = xhci_pending_portevent(xhci);
11701168

1171-
if (suspended_usb3_devs && !pending_portevent &&
1172-
msg.event == PM_EVENT_AUTO_RESUME) {
1169+
if (suspended_usb3_devs && !pending_portevent && is_auto_resume) {
11731170
msleep(120);
11741171
pending_portevent = xhci_pending_portevent(xhci);
11751172
}

drivers/usb/host/xhci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id);
18801880
int xhci_ext_cap_init(struct xhci_hcd *xhci);
18811881

18821882
int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup);
1883-
int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg);
1883+
int xhci_resume(struct xhci_hcd *xhci, bool power_lost, bool is_auto_resume);
18841884

18851885
irqreturn_t xhci_irq(struct usb_hcd *hcd);
18861886
irqreturn_t xhci_msi_irq(int irq, void *hcd);

0 commit comments

Comments
 (0)