From patchwork Thu Feb 18 22:51:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhi Li X-Patchwork-Id: 12094477 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=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 625CBC433E6 for ; Thu, 18 Feb 2021 22:53:19 +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 E6BB2601FD for ; Thu, 18 Feb 2021 22:53:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6BB2601FD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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=Vply6HVAdiay4KYHwRh/YPrVdEnVCOfV9N4DJM32aQ4=; b=fociY1YAY7djg3gDFFd5Yhy7Dv jZHdTyd1ChxS/Q1hSJpRUUNtc3ee6suWivLSJH59L8KXSa/9lGWZCpj8OEVC3kqpPrAOGlpURSuqu 4q3OHbKktLxQw23T02flOmx12vT3bIXuyrWdNDW+z9nmTeqyMksGPnnWxpYrtexb6DhEopJSHxpxa LpICnM+/UaikZ+i8fICDHtE6sZ6Gn8YUQRya4BWsITEiNj040jD9iVkYnSoI8xV0Sc202EUzCselc uwTNUqpViHF9hmzLcqYFwNrgig60o2quSzRRRIaVolRZLZCxkzHWMRJhRNuh6d8vzrjWL2qIjkYxK jBU1yPZg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCs8n-0005q4-RF; Thu, 18 Feb 2021 22:51:21 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCs8k-0005os-3N for linux-arm-kernel@lists.infradead.org; Thu, 18 Feb 2021 22:51:20 +0000 Received: by mail-oi1-x22d.google.com with SMTP id l3so3883971oii.2 for ; Thu, 18 Feb 2021 14:51:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=KFcJoiKZXYEKcUqZgw11Kykzp6Wc04vfEn+1BSxyZ8k=; b=o8JmSOb9770yWlKEBlJNf1aNPtBLM/hMrQTYrowLkREkSnomeVA55OdyxbxvMsO0j6 N6g5fPEPMVmYuODZxjPKVEcmqlG6QnC0TKIR7j+wtSOo/8fWfKpiNt8KeRvYAkhavDf6 MIfKIX6eARMoxWjmdtgQ6Ld1XEfbbWaZjOHUgBy8PsjVNJSOQFzq2xhr9V1KmgZhjvWe QaRgnnTebmO1W8n1t0cyrXHr1ZAiOPtt6fUJF2vLLAc1Dl5fc6buNIW/BNcpV6e9Tao2 zRd1C8f2f4Ul66b3zbF3fVdmR8PivJOBEBgBk2fR5y+nfKyiMo8M0Or6rrB42zqO8GT2 HKlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=KFcJoiKZXYEKcUqZgw11Kykzp6Wc04vfEn+1BSxyZ8k=; b=iViwRlIZ35tdrluZfp/2fD7mcav+2jXrFebwsH5fxVGzSgmnKO7XK9HICpnjSvpPAS +JGEX+ggFGClZPKDjqKuRfcIWDAV+LykzxNWWRPOcJxdqjpXZUmRaEsxTU4sNMx8gOvz o6qm5RqIO8EcrrY3j5waxZK9xWJ/E9gZpmkZikw3d0ytexX9+6iS1aSgBmy6RlOwO5A3 WMZ9hqYc1u1ZXcmpKwnN2tcAqzTkr4MrkwYQ+3vwcatldIriOkxzp+tq725tlyjJQORT UgA7YzhndJLBNkD/FVc6xT/WUmKDXxRW+8EVmePRJh81kJB29q2h2cDQWRoRpjs7Mr3U QOGw== X-Gm-Message-State: AOAM532kLc0gbDlW8w5tVqN1BiXWU2mWjuIwYHVGNR1Lb+V2H8GCiWW0 VxswfvKho5uewmC0nj/CA0E= X-Google-Smtp-Source: ABdhPJwsGr3q18jcwzQwvSIdryVmONllKdT7hmMt8K46aRTuVl9U78UiKyZIlQP3q6Qi+d8lv2TaQg== X-Received: by 2002:a05:6808:8fb:: with SMTP id d27mr4430745oic.57.1613688673561; Thu, 18 Feb 2021 14:51:13 -0800 (PST) Received: from localhost.localdomain (072-177-087-193.res.spectrum.com. [72.177.87.193]) by smtp.gmail.com with ESMTPSA id 88sm1318282oto.3.2021.02.18.14.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Feb 2021 14:51:13 -0800 (PST) From: Frank Li X-Google-Original-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 Subject: [PATCH v4 1/2] usb: cdns3: add power lost support for system resume Date: Thu, 18 Feb 2021 16:51:08 -0600 Message-Id: <20210218225109.265730-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210218_175118_230859_BFE87BB9 X-CRM114-Status: GOOD ( 20.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 v3 to v4 - add an empty line Change from v1 to v3. - fix build error - remove ret variable at cdns_is_power_lost drivers/usb/cdns3/cdns3-gadget.c | 2 ++ drivers/usb/cdns3/cdns3-plat.c | 23 ++++++++++++++++++++++- drivers/usb/cdns3/core.c | 29 ++++++++++++++++++++++++++++- drivers/usb/cdns3/drd.c | 16 ++++++++++++++++ drivers/usb/cdns3/drd.h | 2 +- 5 files changed, 69 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-plat.c b/drivers/usb/cdns3/cdns3-plat.c index 4b18e1c6a4bb..e1deeada425c 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,18 @@ 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 +283,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..1213c540deb3 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) +{ + if (cdns->version == CDNS3_CONTROLLER_V1) { + if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0))) + return true; + } else { + if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0))) + return true; + } + return false; +} + +EXPORT_SYMBOL_GPL(cdns_power_is_lost); 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 */