From patchwork Thu Feb 18 22:51:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhi Li X-Patchwork-Id: 12094475 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=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 B133AC433DB for ; Thu, 18 Feb 2021 22:53:17 +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 4366D601FD for ; Thu, 18 Feb 2021 22:53:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4366D601FD 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:References:In-Reply-To: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:List-Owner; bh=KUwfai7ArJhU3RNPL/gPcrYDU843HQtnp0wAmhIuSC4=; b=VjOmf/FN3WFkAbDGbVFIyQqdEm khbKI74q/y51I4dib3H/LA1IDXkuTgkRb8bViY2bxi7aI8wH5jGJXj4j6AUATQbtpU/6aMQnraX7x vfNHR1KakknIgjKyrEk76Fc4+T463MTCbMdzLzJj6ycwFhjQRUOvDn0+Z1E92hUlHmIw/Ml56CE5+ pZF6BR1vD/jjva2LhXh2DcaY0fdVlF0u+N5WXApmq2vWrWlVEpZu5YdrrLYjdJ+FulPwX0fT2oB6X tZUwyeByjLhCB/DbO9sf8DCauatPqJejAmXVaudVhuNI6YpBFy0bDnxRIO2Qe3qKBNSLn22poLPhR 358/f0AQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCs8r-0005qQ-N1; Thu, 18 Feb 2021 22:51:25 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCs8l-0005p3-JV for linux-arm-kernel@lists.infradead.org; Thu, 18 Feb 2021 22:51:20 +0000 Received: by mail-oi1-x233.google.com with SMTP id d20so3843732oiw.10 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:in-reply-to:references:mime-version :content-transfer-encoding; bh=27lLcd8WXrkNtN8G+fjBJhZZsmXHnYheIamI7TvMRVI=; b=ZrKj3UZTxTwNKSPrQrzsMQLqYOVv7Sbcoj7SpGmjrPpBTAK8S1JpmYAxsrBbH6DBK4 Zje18OYXGR33O2R7vnOTFleOc+njj31qZjRW0zzEFJC9BAVcuf/KeJPElYYn2gabsg0q 77NIarsmw/VyX+wA7fWOL63LGT39yyxXDI8N2WVlPZG8Xgti/lIG72Q5T8ndgqJixHCg ZYPsZesC/EIDEwc2hi5IYMP3dCzpozrOn0KZEkgJR+hh4am476IJFTvMO9lWHHfaSaqj WX7Ei1FbtSfrSf68ZoiBFF0tGUydXrJLG3VvJE9uXnunt1/OWFgpxPEeh6RFXsa707yk KLzA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=27lLcd8WXrkNtN8G+fjBJhZZsmXHnYheIamI7TvMRVI=; b=TL5ga3ZovgB+tYthFZONCuQsZyL4Vea0vaK28333E90Nl3ZmAorNii7cy3qbgovI4R dHNDaBVJKKjiLRdsqs+exBSOh1c9CAo1XZe6C6L7SjrshxAnhwrDa1GrmCDJlGPfbCxp 4bvenP7KXd22kFnys9naozXoP00/otEjQuS9oGlZzSC/Pv+iQyGAXIEY1/tWUgmAg1ej LNkVjqj99aFsAzEfsknOaiE+WS/0Q8YxugTNNggHd5zLrSzhU5aNu9hVYfywDTYTrzdD Xa6EXE0YxpgiAh2E818dV+7HfGrdHxbxyi3WsTAAcfply25hZoVuGLi6dXRvc9BK03rB 1pKg== X-Gm-Message-State: AOAM5320MwOaJCtlAs3tbBuMFzUwspi7r3Tune7Jw3AXvVZvpD6MintT nNyk7aMg5IqK13uFuOtCtX8= X-Google-Smtp-Source: ABdhPJzp7a5+n83EvrzAqI9EgnkR1aKhwTGzePcbzDhqxwSEZYhKg3ZkxQQ8Mzy/1ELuDPLhTtWEyQ== X-Received: by 2002:aca:1a17:: with SMTP id a23mr4462059oia.172.1613688674449; Thu, 18 Feb 2021 14:51:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Feb 2021 14:51:14 -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 v1 2/2] usb: cdns3: imx: add power lost support for system resume Date: Thu, 18 Feb 2021 16:51:09 -0600 Message-Id: <20210218225109.265730-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218225109.265730-1-Frank.Li@nxp.com> References: <20210218225109.265730-1-Frank.Li@nxp.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210218_175119_699404_00F1C13A X-CRM114-Status: GOOD ( 14.86 ) 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 From: Frank Li imx need special handle when controller lost power Signed-off-by: Peter Chen Signed-off-by: Frank Li --- split imx part drivers/usb/cdns3/cdns3-imx.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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[] = {