Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2333424ybz; Thu, 23 Apr 2020 16:12:37 -0700 (PDT) X-Google-Smtp-Source: APiQypIePKtygPcjvRsK1W0ivJwYSAXXYP+nzR6d205UzRPa0qan2lVW+YELCy7B7ouZE5Y3qZHv X-Received: by 2002:aa7:d5d5:: with SMTP id d21mr5076772eds.160.1587683557393; Thu, 23 Apr 2020 16:12:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587683557; cv=none; d=google.com; s=arc-20160816; b=vgfiB/0UvPlK3zJ2irLIDA4Iojuwg/gDKM7/lRB/OZyEtsZkMn8Cbdhu0DZjOJH4E5 pZvCYyePfG3iN9vgR+oQmtp2NEzCpuXeRCgEU+qAyHgAur7WKC5imoFFDtJkQcIPrR99 w1WThRDMmtuoYcsI50PmjedkG3DDmW3Nj7MWWR+qfZkSaVDZ0hDajreU8WJmEwlxkucu mDoXYnqi3mAm1onOdxIJ9hLsgHYMAeEsOGAznSHGEQnMNsfeXxHSIIf2Usi5iinsuu8W IbWdjUeb6gJmGZhn4GUw51fr4g+zdnuae2mZyFrD6xmNBxmyQ5SqauZPLt7DEoXnts90 /qyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=rMWI+2ByaptyWGjVCxyvVBTN/XxnwtfMAOXlYLLNUBE=; b=J3MJKB9aAffiz1xJwkcjYTpcJC+V3lXyoKZuKC3/C695cVdFxC78nOVDThFYJe22nW t17zVxE3swyZn/xymymJqg1xqqFNXy0zBCryT/+q0+nl9NMEyiKnVBXRhZ1YFuPuK793 tXMeAi+59nmJpRtW8xbgt8kC07MrPB7qib1TemNep+g3QnxrZCIgLG5hIRhjCBddUmVV BSmFZKeC4StCf2wIUC8GV7FpdbSqB0472TUjLfzKp0hE5X8HnwdI1z6hlvzdO6Pe1SEU bISfvrB2Q3S7WctNes0bkr27TffFUYv1OcMIinTcBdFUFJckcLaB0ob7qYT1qdeeWT6m tsCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oz14si2013258ejb.51.2020.04.23.16.12.14; Thu, 23 Apr 2020 16:12:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729085AbgDWXJv (ORCPT + 99 others); Thu, 23 Apr 2020 19:09:51 -0400 Received: from inva021.nxp.com ([92.121.34.21]:55406 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728296AbgDWXJr (ORCPT ); Thu, 23 Apr 2020 19:09:47 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 8AB5E20013D; Fri, 24 Apr 2020 01:09:45 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 16560200143; Fri, 24 Apr 2020 01:09:42 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 7513240246; Fri, 24 Apr 2020 07:09:37 +0800 (SGT) From: Anson Huang To: jassisinghbrar@gmail.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Linux-imx@nxp.com Subject: [PATCH] mailbox: imx: Add context save/restore for suspend/resume Date: Fri, 24 Apr 2020 07:01:11 +0800 Message-Id: <1587682871-528-1-git-send-email-Anson.Huang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For "mem" mode suspend on i.MX8 SoCs, MU settings could be lost because its power is off, so save/restore is needed for MU settings during suspend/resume. However, the restore can ONLY be done when MU settings are actually lost, for the scenario of settings NOT lost in "freeze" mode suspend, since there could be still IPC going on multiple CPUs, restoring the MU settings could overwrite the TIE by mistake and cause system freeze, so need to make sure ONLY restore the MU settings when it is powered off. Signed-off-by: Anson Huang --- drivers/mailbox/imx-mailbox.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/mailbox/imx-mailbox.c b/drivers/mailbox/imx-mailbox.c index 97bf0ac..b53cf63 100644 --- a/drivers/mailbox/imx-mailbox.c +++ b/drivers/mailbox/imx-mailbox.c @@ -67,6 +67,8 @@ struct imx_mu_priv { struct clk *clk; int irq; + u32 xcr; + bool side_b; }; @@ -583,12 +585,45 @@ static const struct of_device_id imx_mu_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, imx_mu_dt_ids); +static int imx_mu_suspend_noirq(struct device *dev) +{ + struct imx_mu_priv *priv = dev_get_drvdata(dev); + + priv->xcr = imx_mu_read(priv, priv->dcfg->xCR); + + return 0; +} + +static int imx_mu_resume_noirq(struct device *dev) +{ + struct imx_mu_priv *priv = dev_get_drvdata(dev); + + /* + * ONLY restore MU when context lost, the TIE could + * be set during noirq resume as there is MU data + * communication going on, and restore the saved + * value will overwrite the TIE and cause MU data + * send failed, may lead to system freeze. This issue + * is observed by testing freeze mode suspend. + */ + if (!imx_mu_read(priv, priv->dcfg->xCR)) + imx_mu_write(priv, priv->xcr, priv->dcfg->xCR); + + return 0; +} + +static const struct dev_pm_ops imx_mu_pm_ops = { + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(imx_mu_suspend_noirq, + imx_mu_resume_noirq) +}; + static struct platform_driver imx_mu_driver = { .probe = imx_mu_probe, .remove = imx_mu_remove, .driver = { .name = "imx_mu", .of_match_table = imx_mu_dt_ids, + .pm = &imx_mu_pm_ops, }, }; module_platform_driver(imx_mu_driver); -- 2.7.4