Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp173228ybg; Sun, 31 May 2020 20:59:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNW2gki7hY9MSt4WZOYWqf1xfiHHYpRrPh1AzgZuQOA5dLXM1K2YhekS9BnDucQu0ZfyFs X-Received: by 2002:a17:906:4442:: with SMTP id i2mr18877630ejp.509.1590983995856; Sun, 31 May 2020 20:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590983995; cv=none; d=google.com; s=arc-20160816; b=lUzpbm01hg7mfj2kqfwEbYdDjZPJq/ks1+C00po+Z/32EftTW5Scq1QbwhMHOzhSHZ ZpN0ImF/PltJ9Rew/GxLWynw5NV5GxCL6DnE7GBtte00z9ydet0tlnJ+Av+KDOT75Wnj xOc60bBOddiCDIjQIA2pKWto5euJxmFcxbDUWw5QmLuTfyWmLHS3B4MCP9iXNbJQqUsi pKIMSQvu233YpVcQP+O6c60MKVwE7wl38vBmFvyxTfZwUGGLf40az/mKgqIh/MxMxhAG ZfA8l5NM2o+SSBZHV5F2SQWdSMqM3MOyIZI3mvLA5pzR4DJWvDQTX6IiLBbe7DrxGEXv MeEQ== 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=5DPX1G5Z5WTrGJp5S3j7PN1MWfwvj9Y0zoGjcCU7Kzw=; b=u4MyEB6zXdf/qCr1rawBvvqZs+IYfI87bLTVx3DyNs4CCfj9dEqNYe5I5/Dv26Fhzd RFQVuH6nO0H9jvz4ury6K3dJuPrE79WRm1SkGEaka+uq4n4Q6bU3GY/i3mqUQwQcwJ8O Q72VIFTMC9+ow6BerD646amr3LnBiQGO6Xq7tURUI1PdqMIJ0W5nrskq9VULP4eSsfn0 QjK6IZ/VtNNrBHyO9dg2mGOjIhecCCfcW97Wh+F5Ciu/hAFQbPRrcWqPmN8x/m+lGYt4 piAy1kG/0r1BvQmoWsrB+Bu+9XO0gwea6hu7Cq/8wUbffqn9GVofEXtwjgcgAGaMl30K VokQ== 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 r25si8902177edt.337.2020.05.31.20.59.33; Sun, 31 May 2020 20:59:55 -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 S1726951AbgFAD5u (ORCPT + 99 others); Sun, 31 May 2020 23:57:50 -0400 Received: from inva021.nxp.com ([92.121.34.21]:34702 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726002AbgFAD5t (ORCPT ); Sun, 31 May 2020 23:57:49 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id BEDF320043F; Mon, 1 Jun 2020 05:57:47 +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 4FEA32001B8; Mon, 1 Jun 2020 05:57:44 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 9EC89402A7; Mon, 1 Jun 2020 11:57:39 +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 V2] mailbox: imx: Add context save/restore for suspend/resume Date: Mon, 1 Jun 2020 11:47:28 +0800 Message-Id: <1590983248-7203-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 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 --- Changes since V1: - change the author and add more fix note in commit log. --- 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