Skip to content

Commit 2cf2581

Browse files
nxpfrankliPeter Chen
authored andcommitted
usb: cdns3: add power lost support for system resume
If the controller lost its power during the system suspend, we need to do all initialiation operations. Signed-off-by: Peter Chen <[email protected]> Signed-off-by: Frank Li <[email protected]> Signed-off-by: Peter Chen <[email protected]>
1 parent 14d34d2 commit 2cf2581

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

drivers/usb/cdns3/cdns3-gadget.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,6 +3304,8 @@ static int cdns3_gadget_resume(struct cdns *cdns, bool hibernated)
33043304
return 0;
33053305

33063306
cdns3_gadget_config(priv_dev);
3307+
if (hibernated)
3308+
writel(USB_CONF_DEVEN, &priv_dev->regs->usb_conf);
33073309

33083310
return 0;
33093311
}

drivers/usb/cdns3/cdns3-plat.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "core.h"
2121
#include "gadget-export.h"
22+
#include "drd.h"
2223

2324
static int set_phy_power_on(struct cdns *cdns)
2425
{
@@ -236,6 +237,18 @@ static int cdns3_controller_resume(struct device *dev, pm_message_t msg)
236237
if (!cdns->in_lpm)
237238
return 0;
238239

240+
if (cdns_power_is_lost(cdns)) {
241+
phy_exit(cdns->usb2_phy);
242+
ret = phy_init(cdns->usb2_phy);
243+
if (ret)
244+
return ret;
245+
246+
phy_exit(cdns->usb3_phy);
247+
ret = phy_init(cdns->usb3_phy);
248+
if (ret)
249+
return ret;
250+
}
251+
239252
ret = set_phy_power_on(cdns);
240253
if (ret)
241254
return ret;
@@ -270,10 +283,18 @@ static int cdns3_plat_runtime_resume(struct device *dev)
270283
static int cdns3_plat_suspend(struct device *dev)
271284
{
272285
struct cdns *cdns = dev_get_drvdata(dev);
286+
int ret;
273287

274288
cdns_suspend(cdns);
275289

276-
return cdns3_controller_suspend(dev, PMSG_SUSPEND);
290+
ret = cdns3_controller_suspend(dev, PMSG_SUSPEND);
291+
if (ret)
292+
return ret;
293+
294+
if (device_may_wakeup(dev) && cdns->wakeup_irq)
295+
enable_irq_wake(cdns->wakeup_irq);
296+
297+
return ret;
277298
}
278299

279300
static int cdns3_plat_resume(struct device *dev)

drivers/usb/cdns3/core.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,36 @@ EXPORT_SYMBOL_GPL(cdns_suspend);
525525
int cdns_resume(struct cdns *cdns, u8 set_active)
526526
{
527527
struct device *dev = cdns->dev;
528+
enum usb_role real_role;
529+
bool role_changed = false;
530+
int ret;
531+
532+
if (cdns_power_is_lost(cdns)) {
533+
if (cdns->role_sw) {
534+
cdns->role = cdns_role_get(cdns->role_sw);
535+
} else {
536+
real_role = cdns_hw_role_state_machine(cdns);
537+
if (real_role != cdns->role) {
538+
ret = cdns_hw_role_switch(cdns);
539+
if (ret)
540+
return ret;
541+
role_changed = true;
542+
}
543+
}
544+
545+
if (!role_changed) {
546+
if (cdns->role == USB_ROLE_HOST)
547+
ret = cdns_drd_host_on(cdns);
548+
else if (cdns->role == USB_ROLE_DEVICE)
549+
ret = cdns_drd_gadget_on(cdns);
550+
551+
if (ret)
552+
return ret;
553+
}
554+
}
528555

529556
if (cdns->roles[cdns->role]->resume)
530-
cdns->roles[cdns->role]->resume(cdns, false);
557+
cdns->roles[cdns->role]->resume(cdns, cdns_power_is_lost(cdns));
531558

532559
if (set_active) {
533560
pm_runtime_disable(dev);

drivers/usb/cdns3/drd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,18 @@ int cdns_drd_exit(struct cdns *cdns)
478478

479479
return 0;
480480
}
481+
482+
483+
/* Indicate the cdns3 core was power lost before */
484+
bool cdns_power_is_lost(struct cdns *cdns)
485+
{
486+
if (cdns->version == CDNS3_CONTROLLER_V1) {
487+
if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0)))
488+
return true;
489+
} else {
490+
if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0)))
491+
return true;
492+
}
493+
return false;
494+
}
495+
EXPORT_SYMBOL_GPL(cdns_power_is_lost);

drivers/usb/cdns3/drd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,5 @@ int cdns_drd_gadget_on(struct cdns *cdns);
215215
void cdns_drd_gadget_off(struct cdns *cdns);
216216
int cdns_drd_host_on(struct cdns *cdns);
217217
void cdns_drd_host_off(struct cdns *cdns);
218-
218+
bool cdns_power_is_lost(struct cdns *cdns);
219219
#endif /* __LINUX_CDNS3_DRD */

0 commit comments

Comments
 (0)