linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Gerlach <d-gerlach@ti.com>
To: Rob Herring <robh+dt@kernel.org>,
	Santosh Shilimkar <ssantosh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Tero Kristo <kristo@kernel.org>, Nishanth Menon <nm@ti.com>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Dave Gerlach <d-gerlach@ti.com>
Subject: [PATCH 4/6] firmware: ti_sci: Introduce ti,ctx-memory-region for reserved LPM memory
Date: Thu, 21 Apr 2022 15:36:57 -0500	[thread overview]
Message-ID: <20220421203659.27853-5-d-gerlach@ti.com> (raw)
In-Reply-To: <20220421203659.27853-1-d-gerlach@ti.com>

A reserved memory region in DDR must be used during low power modes for
saving of some system context when using the ti_sci firmware, so
introduce a property to allow providing this in the device tree so that
it can be read and shared with the firmware.

Also send a TISCI_MSG_PREPARE_SUSPEND message to the firmware during
probe to determine if system suspend is supported and if
ti_sci_init_suspend should be called based on the response received.

Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
---
 drivers/firmware/ti_sci.c | 45 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
index 4b0f747251c8..1c2000b40e8f 100644
--- a/drivers/firmware/ti_sci.c
+++ b/drivers/firmware/ti_sci.c
@@ -17,6 +17,7 @@
 #include <linux/mailbox_client.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/semaphore.h>
 #include <linux/slab.h>
 #include <linux/soc/ti/ti-msgmgr.h>
@@ -96,6 +97,8 @@ struct ti_sci_desc {
  * @minfo:	Message info
  * @node:	list head
  * @host_id:	Host ID
+ * @mem_ctx_lo: Low word of address used for low power context memory
+ * @mem_ctx_hi: High word of address used for low power context memory
  * @users:	Number of users of this instance
  * @is_suspending: Flag set to indicate in suspend path.
  */
@@ -114,6 +117,8 @@ struct ti_sci_info {
 	struct ti_sci_xfers_info minfo;
 	struct list_head node;
 	u8 host_id;
+	u32 mem_ctx_lo;
+	u32 mem_ctx_hi;
 	/* protected by ti_sci_list_mutex */
 	int users;
 	bool is_suspending;
@@ -3374,6 +3379,29 @@ static int ti_sci_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(ti_sci_pm_ops, ti_sci_suspend, ti_sci_resume);
 
+static int ti_sci_init_suspend(struct platform_device *pdev, struct ti_sci_info *info)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *rmem_np;
+	struct reserved_mem *rmem;
+
+	rmem_np = of_parse_phandle(dev->of_node, "ti,ctx-memory-region", 0);
+	if (!rmem_np) {
+		dev_warn(dev, "ti,ctx-memory-region is required for suspend but not provided.\n");
+		return -EINVAL;
+	}
+
+	rmem = of_reserved_mem_lookup(rmem_np);
+	of_node_put(rmem_np);
+	if (!rmem)
+		return -EINVAL;
+
+	info->mem_ctx_lo = (rmem->base & 0xFFFFFFFF);
+	info->mem_ctx_hi = (rmem->base >> 32);
+
+	return 0;
+}
+
 /* Description for K2G */
 static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = {
 	.default_host_id = 2,
@@ -3526,6 +3554,23 @@ static int ti_sci_probe(struct platform_device *pdev)
 		}
 	}
 
+	/*
+	 * Attempt to call prepare_sleep, this will be NAK'd if suspend is not
+	 * supported by firmware in use, in which case we will not attempt to
+	 * init suspend.
+	 */
+	ret = ti_sci_cmd_prepare_sleep(&info->handle, 0, info->mem_ctx_lo,
+				       info->mem_ctx_hi, 0);
+	if (!ret) {
+		ret = ti_sci_init_suspend(pdev, info);
+		if (ret)
+			dev_warn(dev,
+				 "ti_sci_init_suspend failed, mem suspend will be non-functional.\n");
+	}
+
+	/* Suspend is an optional feature, reset return value and continue. */
+	ret = 0;
+
 	dev_info(dev, "ABI: %d.%d (firmware rev 0x%04x '%s')\n",
 		 info->handle.version.abi_major, info->handle.version.abi_minor,
 		 info->handle.version.firmware_revision,
-- 
2.35.0


  parent reply	other threads:[~2022-04-21 20:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-21 20:36 [PATCH 0/6] firmware: ti_sci: Introduce system suspend support Dave Gerlach
2022-04-21 20:36 ` [PATCH 1/6] dt-bindings: ti,sci: Add ti,ctx-memory-region property Dave Gerlach
2022-04-22 19:02   ` Andrew Davis
2022-04-22 19:02     ` Andrew Davis
2022-04-22 19:10     ` Dave Gerlach
2022-04-23 13:36       ` Nishanth Menon
2022-04-25 20:24         ` Dave Gerlach
2022-04-26  3:28           ` Nishanth Menon
2022-05-02 20:14   ` Rob Herring
2022-04-21 20:36 ` [PATCH 2/6] dt-bindings: ti,sci: Add lpm region and ti,lpm-firmware-name Dave Gerlach
2022-05-02 20:15   ` Rob Herring
2022-04-21 20:36 ` [PATCH 3/6] firmware: ti_sci: Introduce Power Management Ops Dave Gerlach
2022-04-21 20:36 ` Dave Gerlach [this message]
2022-04-21 20:36 ` [PATCH 5/6] firmware: ti_sci: Use dt provided fw name and address to load at suspend time Dave Gerlach
2022-04-21 20:36 ` [PATCH 6/6] firmware: ti_sci: Introduce prepare system suspend call Dave Gerlach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220421203659.27853-5-d-gerlach@ti.com \
    --to=d-gerlach@ti.com \
    --cc=devicetree@vger.kernel.org \
    --cc=kristo@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=robh+dt@kernel.org \
    --cc=ssantosh@kernel.org \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).