From patchwork Mon Feb 8 16:34:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 12075979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D46BDC433DB for ; Mon, 8 Feb 2021 16:36:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7C93464E26 for ; Mon, 8 Feb 2021 16:36:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C93464E26 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:MIME-Version:Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=m/o0x/wDo8AyVJkdb8QS9HWUWfYlvMU2ToZ0jISDKMA=; b=Zn3/mlAv+J9aYRO0H0OS7bcFxa qKWnYb5gqNPLoBJeQBhmMOOepO9nmPEoP4irBgtIQQKHZQy9vfOiKBsYX258Hlb5jRYorvgNg798x 9b4+TptnofZQYk8FbwRmCmuV5yUNkSNBihDGRT8pbkR8EKxVknCw7kY2ajg8Z33ttQtglTqiyYQrT oslgCAPEA05Oq4qqqZEMKDczHmEKX5D2Z21t9pEmfc8hEHyex5E0yzLt8RbFnCEEN48xiEoDOF5Om ZPgXPTlD3VxNIoZdJLM2Dcq5PB4zB9JI76ckkmH4lmEW+qYLrYPwI5P9cEw+MT40R0bKCmrH9z3UC YNxSqfeg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l99VN-0000jf-KE; Mon, 08 Feb 2021 16:35:17 +0000 Received: from mail-am6eur05on2068.outbound.protection.outlook.com ([40.107.22.68] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l99VJ-0000hg-M6 for linux-arm-kernel@lists.infradead.org; Mon, 08 Feb 2021 16:35:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W4itXiPqRddSb0FFp0oFc3pQW58IW7rdMrm8//GS9m8RpSMDO+sjjoIW34Pv/JJrkdUsHQbo9wOVVOsva3CKB4ZCk7+TNKD53HcU6dNysgXtVZh5W7M5791tcj132OWlT1haT6TAWsWPQJSz/FQv5BXlS35RBmHFND2WRVdU9xtP2cQd63FZlC6iJ4jyJBNjMXduMMCNONWHNYZy7cw1f69Qe784+qDVBMZaexO8GGbsvr7rtabwByDQ0ywBa2YYvnu6Va+su79i18wjfBW8+zcrhQZzbx5qauw23SsbHGnWlLRHBVvX8FCFNXBfz5vM6BueeXgtpUNh48mV9odoXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZXYy4hoYFnIglhiBQ1rZZDE5cy13CtNfQF5ycNXVATA=; b=mwzLrEfgHolSBRook63gAf2yNGyNjsdiOPqK+qEmkcPvgNJetkkYdr8zUZTlpvD38NeSdG58d+kDd3zfhYNbxwEjtAvK/tbzBM7ZeQL+sL92nMwbFLGCvx+MCGwCErPQbSKPcQMX3+gef6ADO+ebk0z8TO810+lQjOVvTHoL4SiD1OxPwUtm9I5HunOUVN8YewtMn9YkLnhM3iIHlTYJHx8upYc/SOUj7ktQtDWEaQbOrwmLr4azspBF+YeDdIpffN+zif4aY18/25GlCyivTRGZI2kzLyaI7ZCgOOpat6kp/JYsC/hDqQh3UJ44YlJNkvidfKWjqjqs5g9jS9IF2Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZXYy4hoYFnIglhiBQ1rZZDE5cy13CtNfQF5ycNXVATA=; b=jnLGFf44BAgLkxCjfGQFI9jg27Wm7Os9Fu0VqZYuXAozE0TXRgYis3XLsAfXSvZtu70Bti/WI00P97JLXspmgbB3z8sTYbsYvamX3N6vHpmPPRnA+S9Va3oS35FcJTh9esxLeWG0Im26QGCp/8UwF3H9IGg4p0yiTKGJkIOC3C4= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8053.eurprd04.prod.outlook.com (2603:10a6:20b:2ad::12) by AM6PR0402MB3845.eurprd04.prod.outlook.com (2603:10a6:209:1b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17; Mon, 8 Feb 2021 16:35:09 +0000 Received: from AS8PR04MB8053.eurprd04.prod.outlook.com ([fe80::b8d2:f45a:dfd2:588e]) by AS8PR04MB8053.eurprd04.prod.outlook.com ([fe80::b8d2:f45a:dfd2:588e%4]) with mapi id 15.20.3805.038; Mon, 8 Feb 2021 16:35:09 +0000 From: Frank Li To: peter.chen@kernel.org, pawell@cadence.com, a-govindraju@ti.com, linux-imx@nxp.com, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, lznuaa@gmail.com Subject: [PATCH v2 1/1] usb: cdns3: add power lost support for system resume Date: Mon, 8 Feb 2021 10:34:50 -0600 Message-Id: <20210208163450.30374-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.24.0.rc1 X-Originating-IP: [64.157.242.222] X-ClientProxiedBy: BY3PR10CA0016.namprd10.prod.outlook.com (2603:10b6:a03:255::21) To AS8PR04MB8053.eurprd04.prod.outlook.com (2603:10a6:20b:2ad::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lizhi-Precision-Tower-5810.am.freescale.net (64.157.242.222) by BY3PR10CA0016.namprd10.prod.outlook.com (2603:10b6:a03:255::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Mon, 8 Feb 2021 16:35:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0c53d285-e888-4e15-60ac-08d8cc4f7f8e X-MS-TrafficTypeDiagnostic: AM6PR0402MB3845: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hlss+7O/YWk8SN6QQ+qcrj8L47atVXmI3Tfiq8xIE1yDfLG8FjIIW+m8kBCOm5fjnZI9rxiQSTNoK1RZIVusa8S1L+R77wmWf2LAQhfAnifbm2E+81sSD9aZzWlHJDuYc6fEpqkuuvfABVQ5R9buAwH8fOaGDGYpnv87im/MgwNg2Q47FlNYO2IRWk6DhLQFdoXlhjg4oLaeW0NOgbL5gMTnqrIXhn4C+C0awaZRSPwLfTupqIHUTR/efxOD68N8nMvTFIyQ2bGDjvtczLu51BuTyEc2x/PJf7ULQnG1G4Nlcp5fracj2DvI0/a9c2gwTii+KtaOOT48/DFN6OmWobBvoe4TPCDia+CYmOJ3sEe+UMxFDhvtGeDRfnVfWJpCXyalkIrW7z89xdqMTrp++gN0sMY8qZkY9/sShkfPR+H1oeG/aTv5n/OCk2paJG7rvExYtffE8o+Ha4kg9X1nZmxIdWuMaDVhl10V0pUoPkshakJIKGy5o1nJ5KkcfsFFhWBw6+mHLXB8+PxsL1u7Pw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8053.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(366004)(136003)(396003)(39860400002)(86362001)(478600001)(1076003)(26005)(6506007)(2906002)(8676002)(6486002)(6512007)(6666004)(2616005)(186003)(83380400001)(316002)(36756003)(52116002)(16526019)(8936002)(5660300002)(66946007)(956004)(66476007)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Bv/YW9OGAZI95mdFsSID+6Scnb3Hm7+onq39xwjqPdoFDbYaPN5cesgwv+yYdlgsej2tWhNjF/r7DDRyTvhkwh0an2RmdC6tcOIp+NbMO11If/z8X4E1KKDZOddFYOAjR7a3ESbmBnGvmB+AAeUnyIL3DtJ10jsOPYkarmT1NxNp9aw4ti2XmuBKuD/C8HkV3FKJeU6RXyi/Sd9aQoEvRp0HLBxlxl0IACNaD1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Y6nxZzQelp9xDdIrtbs1DWFJAZRl X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c53d285-e888-4e15-60ac-08d8cc4f7f8e X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8053.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2021 16:35:08.9117 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Fq5gFp7NafLpK7o0lz4dzgU0ykbQxFplJ2NxzOii0D4kkR+AAjmZuvRTLg7mmMDIdvl+HzNlq08UndcVreDm8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0402MB3845 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210208_113513_916576_F39F7C9F X-CRM114-Status: GOOD ( 21.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If the controller lost its power during the system suspend, we need to do all initialiation operations. Signed-off-by: Peter Chen Signed-off-by: Frank Li --- Change from v1 to v2: * Fix build error. * remove ret avariable in cdns_power_is_lost drivers/usb/cdns3/cdns3-gadget.c | 2 ++ drivers/usb/cdns3/cdns3-imx.c | 34 ++++++++++++++++++++++++++++++++ drivers/usb/cdns3/cdns3-plat.c | 22 ++++++++++++++++++++- drivers/usb/cdns3/core.c | 29 ++++++++++++++++++++++++++- drivers/usb/cdns3/drd.c | 16 +++++++++++++++ drivers/usb/cdns3/drd.h | 2 +- 6 files changed, 102 insertions(+), 3 deletions(-) diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c index 582bfeceedb4..44b7301b1888 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -3304,6 +3304,8 @@ static int cdns3_gadget_resume(struct cdns *cdns, bool hibernated) return 0; cdns3_gadget_config(priv_dev); + if (hibernated) + writel(USB_CONF_DEVEN, &priv_dev->regs->usb_conf); return 0; } diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c index 8f88eec0b0ea..708b51cc5844 100644 --- a/drivers/usb/cdns3/cdns3-imx.c +++ b/drivers/usb/cdns3/cdns3-imx.c @@ -361,6 +361,39 @@ static int cdns_imx_suspend(struct device *dev) return 0; } + + +/* Indicate if the controller was power lost before */ +static inline bool cdns_imx_is_power_lost(struct cdns_imx *data) +{ + u32 value; + + value = cdns_imx_readl(data, USB3_CORE_CTRL1); + if ((value & SW_RESET_MASK) == ALL_SW_RESET) + return true; + else + return false; +} + +static int cdns_imx_system_resume(struct device *dev) +{ + struct cdns_imx *data = dev_get_drvdata(dev); + int ret; + + ret = cdns_imx_resume(dev); + if (ret) + return ret; + + if (cdns_imx_is_power_lost(data)) { + dev_dbg(dev, "resume from power lost\n"); + ret = cdns_imx_noncore_init(data); + if (ret) + cdns_imx_suspend(dev); + } + + return ret; +} + #else static int cdns_imx_platform_suspend(struct device *dev, bool suspend, bool wakeup) @@ -372,6 +405,7 @@ static int cdns_imx_platform_suspend(struct device *dev, static const struct dev_pm_ops cdns_imx_pm_ops = { SET_RUNTIME_PM_OPS(cdns_imx_suspend, cdns_imx_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(cdns_imx_suspend, cdns_imx_system_resume) }; static const struct of_device_id cdns_imx_of_match[] = { diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c index 4b18e1c6a4bb..e61da57fe31a 100644 --- a/drivers/usb/cdns3/cdns3-plat.c +++ b/drivers/usb/cdns3/cdns3-plat.c @@ -19,6 +19,7 @@ #include "core.h" #include "gadget-export.h" +#include "drd.h" static int set_phy_power_on(struct cdns *cdns) { @@ -236,6 +237,17 @@ static int cdns3_controller_resume(struct device *dev, pm_message_t msg) if (!cdns->in_lpm) return 0; + if (cdns_power_is_lost(cdns)) { + phy_exit(cdns->usb2_phy); + ret = phy_init(cdns->usb2_phy); + if (ret) + return ret; + phy_exit(cdns->usb3_phy); + ret = phy_init(cdns->usb3_phy); + if (ret) + return ret; + } + ret = set_phy_power_on(cdns); if (ret) return ret; @@ -270,10 +282,18 @@ static int cdns3_plat_runtime_resume(struct device *dev) static int cdns3_plat_suspend(struct device *dev) { struct cdns *cdns = dev_get_drvdata(dev); + int ret; cdns_suspend(cdns); - return cdns3_controller_suspend(dev, PMSG_SUSPEND); + ret = cdns3_controller_suspend(dev, PMSG_SUSPEND); + if (ret) + return ret; + + if (device_may_wakeup(dev) && cdns->wakeup_irq) + enable_irq_wake(cdns->wakeup_irq); + + return ret; } static int cdns3_plat_resume(struct device *dev) diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index 199713769289..5d486c8a9d99 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -525,9 +525,36 @@ EXPORT_SYMBOL_GPL(cdns_suspend); int cdns_resume(struct cdns *cdns, u8 set_active) { struct device *dev = cdns->dev; + enum usb_role real_role; + bool role_changed = false; + int ret; + + if (cdns_power_is_lost(cdns)) { + if (cdns->role_sw) { + cdns->role = cdns_role_get(cdns->role_sw); + } else { + real_role = cdns_hw_role_state_machine(cdns); + if (real_role != cdns->role) { + ret = cdns_hw_role_switch(cdns); + if (ret) + return ret; + role_changed = true; + } + } + + if (!role_changed) { + if (cdns->role == USB_ROLE_HOST) + ret = cdns_drd_host_on(cdns); + else if (cdns->role == USB_ROLE_DEVICE) + ret = cdns_drd_gadget_on(cdns); + + if (ret) + return ret; + } + } if (cdns->roles[cdns->role]->resume) - cdns->roles[cdns->role]->resume(cdns, false); + cdns->roles[cdns->role]->resume(cdns, cdns_power_is_lost(cdns)); if (set_active) { pm_runtime_disable(dev); diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c index 605a413db727..8b04e030df4d 100644 --- a/drivers/usb/cdns3/drd.c +++ b/drivers/usb/cdns3/drd.c @@ -478,3 +478,19 @@ int cdns_drd_exit(struct cdns *cdns) return 0; } + + +/* Indicate the cdns3 core was power lost before */ +bool cdns_power_is_lost(struct cdns *cdns) +{ + int ret = false; + + if (cdns->version == CDNS3_CONTROLLER_V1) { + if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0))) + ret = true; + } else { + if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0))) + ret = true; + } + return ret; +} diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h index 9724acdecbbb..cbdf94f73ed9 100644 --- a/drivers/usb/cdns3/drd.h +++ b/drivers/usb/cdns3/drd.h @@ -215,5 +215,5 @@ int cdns_drd_gadget_on(struct cdns *cdns); void cdns_drd_gadget_off(struct cdns *cdns); int cdns_drd_host_on(struct cdns *cdns); void cdns_drd_host_off(struct cdns *cdns); - +bool cdns_power_is_lost(struct cdns *cdns); #endif /* __LINUX_CDNS3_DRD */