Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp230054ybg; Tue, 2 Jun 2020 22:31:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeN55y9mkbuZ5v8dj2D479XIZbAL7iU9U9J7+ksFSFikZsFU2qhom99eDQ7Q4dy3V/F+Mo X-Received: by 2002:aa7:d957:: with SMTP id l23mr17743421eds.206.1591162275956; Tue, 02 Jun 2020 22:31:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591162275; cv=none; d=google.com; s=arc-20160816; b=OQSywEcrkp90+8uwWav/xTNYqW/seVrQ3Du4lZHL1NE8A7K18IZT3UlHBHT5Bs421I 9TS6wgEnyKJSnVDQknw3NeYU3Uc2Xq0JziJ4a/X9ZzpDM4pcA6lGZIJpRqcHBVIFcSLr v+FT+ySNZ6t4/U6TEWRnIx3ZjuBcjD5um9vgYXvJV3NKM4ztI0HC23Cw6vsGFOb8oroq B/qFHSk7CyyD7UaMW+qGZtXkE2q/hCQbWUSFU6mdUumuPZtxx4yrKu5pfbYBsfuJ0p+5 zXJZyTWQihirJI2jWu+cxWX87gUlAx5/fNs3I75J28IDZkM5xoE4wtbnq6+DbdZUZ2y6 rQSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=mawcpTGjOeqIk/I1TLMVeSpg+bI2vWYDclySJESkmHM=; b=tGY03kReE6X4cFMEE9TeboPlOvG1X2DEi78IewlqZ2gAM3cwsCxT70Nf6aEkj0k01f xAquyD/28mD3tZNMTsypYWct+adaC4HwcgZCsfqm18xwJfIinCBmv7+zLFTPXirggACx YlbkigLQYrWeb/U381U9EWqg9Fa4HJ8kIfvm245cnPibNggJ4qBrQ4ihthxA/e/QhBFj v32TGouQ/lO8V3+2VDl7ja7+lAfHe2TRqPtsx61tdbuLIUEuPrQndKI6nMaUcJt5qiay nFKU4h15XEIs11RVQze6Bflm5ZVCCVwYa8EYfg7ufB51rxqgdbGWtDsZaqWZKb/Np1VL Y29g== 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 lh7si560410ejb.106.2020.06.02.22.30.53; Tue, 02 Jun 2020 22:31:15 -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 S1725917AbgFCF0Y (ORCPT + 99 others); Wed, 3 Jun 2020 01:26:24 -0400 Received: from inva021.nxp.com ([92.121.34.21]:59932 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbgFCF0M (ORCPT ); Wed, 3 Jun 2020 01:26:12 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 0A148200D77; Wed, 3 Jun 2020 07:26:11 +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 98B55200D29; Wed, 3 Jun 2020 07:26:07 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 00434402E8; Wed, 3 Jun 2020 13:26:02 +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 1/3] mailbox: imx: Add context save/restore for suspend/resume Date: Wed, 3 Jun 2020 13:15:42 +0800 Message-Id: <1591161344-12885-2-git-send-email-Anson.Huang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1591161344-12885-1-git-send-email-Anson.Huang@nxp.com> References: <1591161344-12885-1-git-send-email-Anson.Huang@nxp.com> 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 From: Dong Aisheng 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, Anson fixes this by checking whether restore is actually needed when resume. Signed-off-by: Dong Aisheng 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 bd69ecf..da90a8e 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; }; @@ -589,12 +591,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