Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4289953ybb; Tue, 14 Apr 2020 04:28:06 -0700 (PDT) X-Google-Smtp-Source: APiQypIsUsbjbzKitYIyq329q1HicPDXbgJqGc8fKGrMoC8VTg7xAyonyoTq2wU8ErP5RZHn09Wy X-Received: by 2002:a17:906:18a1:: with SMTP id c1mr19291220ejf.344.1586863686154; Tue, 14 Apr 2020 04:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586863686; cv=none; d=google.com; s=arc-20160816; b=Q/UJ4qUGOrqOpuk9PfwRr4wTL+Qy2Y8/cUSaGmpA4gyJK+7m/KGltqjYZY+kOU/TRb TUNwFeHaJlqZVy4J3pZSy7Gzo+jHvXq0IvdjlPdPJpSbQPKKeWY5fRGJdTgdNcIR9QSv U/GMeciNm7kCynh0uRPiOm5lXgjYpqX5g9UwoQz/USd6uemoYfAsUnSlNYLuArSb4Bz9 oLUhD+ZW9Tp2s6N/rS7CeAScLX0aAFMT0fRec8cZzzEDU7QkQtSzWrOCsCYw7apipP+O Y1tXdg5jVdTDp/fZpO89zOFZ5WHiNaHJ/QtzSL3UX5tFMsZByr5bvJHQYZs2lOGtt4ZW ACLQ== 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=SqdRwjK7xHleJr0e6Q+ImSGuSNZdG5VlfLj9l8fyQec=; b=gb/DUCWg0KNLl+nRkRT/KP1xNusx9HImQA1xjicQ7n7q7k5lkmreNF6N1f11Br+kdl kogpYa/CYZRKoDFsaBheHXYm5t4XmAbBVuGJHzGnzm1DXeU1YunmpkNNjRXY1GHcKta4 ce2rgTG4rZIimG6V0wEqe+rfZFjhatoRSVhNRuTMH+0a16aJOHIaj3ZEKWEujjLbJUi3 cA4WzpldPOYUEDLvSkdfReGJTRaXNaEG21dyLVhMYvx74QPsWJGzknfkwhl999mUVUH5 urOoVUULotkvkdCVs58AJGRl0jaqFp0TQAVMnZLxPFB/zOr7cwqMK5A04oIa3vbjVOZM W4jg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for 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 a4si9028560edn.451.2020.04.14.04.27.42; Tue, 14 Apr 2020 04:28:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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: best guess record for 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 S1729511AbgDMMde (ORCPT + 99 others); Mon, 13 Apr 2020 08:33:34 -0400 Received: from inva020.nxp.com ([92.121.34.13]:45686 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728392AbgDMMdd (ORCPT ); Mon, 13 Apr 2020 08:33:33 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id C61851A16F6; Mon, 13 Apr 2020 14:33:31 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 528DB1A0020; Mon, 13 Apr 2020 14:33:28 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id C7814402B4; Mon, 13 Apr 2020 20:33:23 +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: Support runtime PM Date: Mon, 13 Apr 2020 20:25:30 +0800 Message-Id: <1586780730-6117-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 Some power hungry sub-systems like VPU has its own MUs which also use mailbox driver, current mailbox driver uses platform driver model and MU's power will be ON after driver probed and left ON there, it may cause the whole sub-system can NOT enter lower power mode, take VPU driver for example, it has runtime PM support, but due to its MU always ON, the VPU sub-system will be always ON and consume many power during kernel idle. To save power in kernel idle, mailbox driver needs to support runtime PM in order to power off MU when it is unused. However, the runtime suspend/resume can ONLY be implemented in mailbox's .shutdown/.startup callback, so its consumer needs to call mbox_request_channel()/mbox_free_channel() in consumer driver's runtime PM callback, then the MU's power will be ON/OFF along with consumer's runtime PM status. Signed-off-by: Anson Huang --- drivers/mailbox/imx-mailbox.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/mailbox/imx-mailbox.c b/drivers/mailbox/imx-mailbox.c index 7906624..97bf0ac 100644 --- a/drivers/mailbox/imx-mailbox.c +++ b/drivers/mailbox/imx-mailbox.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #define IMX_MU_xSR_GIPn(x) BIT(28 + (3 - (x))) @@ -287,6 +288,7 @@ static int imx_mu_startup(struct mbox_chan *chan) struct imx_mu_con_priv *cp = chan->con_priv; int ret; + pm_runtime_get_sync(priv->dev); if (cp->type == IMX_MU_TYPE_TXDB) { /* Tx doorbell don't have ACK support */ tasklet_init(&cp->txdb_tasklet, imx_mu_txdb_tasklet, @@ -323,6 +325,7 @@ static void imx_mu_shutdown(struct mbox_chan *chan) if (cp->type == IMX_MU_TYPE_TXDB) { tasklet_kill(&cp->txdb_tasklet); + pm_runtime_put_sync(priv->dev); return; } @@ -341,6 +344,7 @@ static void imx_mu_shutdown(struct mbox_chan *chan) } free_irq(priv->irq, chan); + pm_runtime_put_sync(priv->dev); } static const struct mbox_chan_ops imx_mu_ops = { @@ -508,7 +512,27 @@ static int imx_mu_probe(struct platform_device *pdev) platform_set_drvdata(pdev, priv); - return devm_mbox_controller_register(dev, &priv->mbox); + ret = devm_mbox_controller_register(dev, &priv->mbox); + if (ret) + return ret; + + pm_runtime_enable(dev); + + ret = pm_runtime_get_sync(dev); + if (ret < 0) { + pm_runtime_put_noidle(dev); + goto disable_runtime_pm; + } + + ret = pm_runtime_put_sync(dev); + if (ret < 0) + goto disable_runtime_pm; + + return 0; + +disable_runtime_pm: + pm_runtime_disable(dev); + return ret; } static int imx_mu_remove(struct platform_device *pdev) @@ -516,6 +540,7 @@ static int imx_mu_remove(struct platform_device *pdev) struct imx_mu_priv *priv = platform_get_drvdata(pdev); clk_disable_unprepare(priv->clk); + pm_runtime_disable(priv->dev); return 0; } -- 2.7.4