Skip to content

Commit

Permalink
usb: xhci-mtk: check return value in suspend/resume hooks
Browse files Browse the repository at this point in the history
Return error number if encounter errors during suspend and resume.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Link: https://lore.kernel.org/r/1618031406-15347-1-git-send-email-chunfeng.yun@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Chunfeng Yun authored and Greg Kroah-Hartman committed Apr 14, 2021
1 parent 1373fef commit 82dad9f
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions drivers/usb/host/xhci-mtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,47 +641,64 @@ static int xhci_mtk_remove(struct platform_device *dev)
return 0;
}

/*
* if ip sleep fails, and all clocks are disabled, access register will hang
* AHB bus, so stop polling roothubs to avoid regs access on bus suspend.
* and no need to check whether ip sleep failed or not; this will cause SPM
* to wake up system immediately after system suspend complete if ip sleep
* fails, it is what we wanted.
*/
static int __maybe_unused xhci_mtk_suspend(struct device *dev)
{
struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);
struct usb_hcd *hcd = mtk->hcd;
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
int ret;

xhci_dbg(xhci, "%s: stop port polling\n", __func__);
clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
del_timer_sync(&hcd->rh_timer);
clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);
del_timer_sync(&xhci->shared_hcd->rh_timer);

xhci_mtk_host_disable(mtk);
ret = xhci_mtk_host_disable(mtk);
if (ret)
goto restart_poll_rh;

xhci_mtk_clks_disable(mtk);
usb_wakeup_set(mtk, true);
return 0;

restart_poll_rh:
xhci_dbg(xhci, "%s: restart port polling\n", __func__);
set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);
usb_hcd_poll_rh_status(xhci->shared_hcd);
set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
usb_hcd_poll_rh_status(hcd);
return ret;
}

static int __maybe_unused xhci_mtk_resume(struct device *dev)
{
struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);
struct usb_hcd *hcd = mtk->hcd;
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
int ret;

usb_wakeup_set(mtk, false);
xhci_mtk_clks_enable(mtk);
xhci_mtk_host_enable(mtk);
ret = xhci_mtk_clks_enable(mtk);
if (ret)
goto enable_wakeup;

ret = xhci_mtk_host_enable(mtk);
if (ret)
goto disable_clks;

xhci_dbg(xhci, "%s: restart port polling\n", __func__);
set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);
usb_hcd_poll_rh_status(xhci->shared_hcd);
set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
usb_hcd_poll_rh_status(hcd);
return 0;

disable_clks:
xhci_mtk_clks_disable(mtk);
enable_wakeup:
usb_wakeup_set(mtk, true);
return ret;
}

static const struct dev_pm_ops xhci_mtk_pm_ops = {
Expand Down

0 comments on commit 82dad9f

Please sign in to comment.