Skip to content

Commit ab87603

Browse files
khfengdavem330
authored andcommitted
net: wwan: t7xx: Ensure init is completed before system sleep
When the system attempts to sleep while mtk_t7xx is not ready, the driver cannot put the device to sleep: [ 12.472918] mtk_t7xx 0000:57:00.0: [PM] Exiting suspend, modem in invalid state [ 12.472936] mtk_t7xx 0000:57:00.0: PM: pci_pm_suspend(): t7xx_pci_pm_suspend+0x0/0x20 [mtk_t7xx] returns -14 [ 12.473678] mtk_t7xx 0000:57:00.0: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x1b0 returns -14 [ 12.473711] mtk_t7xx 0000:57:00.0: PM: failed to suspend async: error -14 [ 12.764776] PM: Some devices failed to suspend, or early wake event detected Mediatek confirmed the device can take a rather long time to complete its initialization, so wait for up to 20 seconds until init is done. Signed-off-by: Kai-Heng Feng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9ba9485 commit ab87603

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

drivers/net/wwan/t7xx/t7xx_pci.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#define T7XX_PCI_IREG_BASE 0
4646
#define T7XX_PCI_EREG_BASE 2
4747

48+
#define T7XX_INIT_TIMEOUT 20
4849
#define PM_SLEEP_DIS_TIMEOUT_MS 20
4950
#define PM_ACK_TIMEOUT_MS 1500
5051
#define PM_AUTOSUSPEND_MS 20000
@@ -96,6 +97,7 @@ static int t7xx_pci_pm_init(struct t7xx_pci_dev *t7xx_dev)
9697
spin_lock_init(&t7xx_dev->md_pm_lock);
9798
init_completion(&t7xx_dev->sleep_lock_acquire);
9899
init_completion(&t7xx_dev->pm_sr_ack);
100+
init_completion(&t7xx_dev->init_done);
99101
atomic_set(&t7xx_dev->md_pm_state, MTK_PM_INIT);
100102

101103
device_init_wakeup(&pdev->dev, true);
@@ -124,6 +126,7 @@ void t7xx_pci_pm_init_late(struct t7xx_pci_dev *t7xx_dev)
124126
pm_runtime_mark_last_busy(&t7xx_dev->pdev->dev);
125127
pm_runtime_allow(&t7xx_dev->pdev->dev);
126128
pm_runtime_put_noidle(&t7xx_dev->pdev->dev);
129+
complete_all(&t7xx_dev->init_done);
127130
}
128131

129132
static int t7xx_pci_pm_reinit(struct t7xx_pci_dev *t7xx_dev)
@@ -529,6 +532,20 @@ static void t7xx_pci_shutdown(struct pci_dev *pdev)
529532
__t7xx_pci_pm_suspend(pdev);
530533
}
531534

535+
static int t7xx_pci_pm_prepare(struct device *dev)
536+
{
537+
struct pci_dev *pdev = to_pci_dev(dev);
538+
struct t7xx_pci_dev *t7xx_dev;
539+
540+
t7xx_dev = pci_get_drvdata(pdev);
541+
if (!wait_for_completion_timeout(&t7xx_dev->init_done, T7XX_INIT_TIMEOUT * HZ)) {
542+
dev_warn(dev, "Not ready for system sleep.\n");
543+
return -ETIMEDOUT;
544+
}
545+
546+
return 0;
547+
}
548+
532549
static int t7xx_pci_pm_suspend(struct device *dev)
533550
{
534551
return __t7xx_pci_pm_suspend(to_pci_dev(dev));
@@ -555,6 +572,7 @@ static int t7xx_pci_pm_runtime_resume(struct device *dev)
555572
}
556573

557574
static const struct dev_pm_ops t7xx_pci_pm_ops = {
575+
.prepare = t7xx_pci_pm_prepare,
558576
.suspend = t7xx_pci_pm_suspend,
559577
.resume = t7xx_pci_pm_resume,
560578
.resume_noirq = t7xx_pci_pm_resume_noirq,

drivers/net/wwan/t7xx/t7xx_pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct t7xx_pci_dev {
6969
struct t7xx_modem *md;
7070
struct t7xx_ccmni_ctrl *ccmni_ctlb;
7171
bool rgu_pci_irq_en;
72+
struct completion init_done;
7273

7374
/* Low Power Items */
7475
struct list_head md_pm_entities;

0 commit comments

Comments
 (0)