Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1935564rwo; Thu, 3 Aug 2023 02:02:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlGhMZXK/Q+CbZV807cBD0AjzClhehnh6r9SSCmd6yvFKQL590IAukB6yW8jN9CbMmmIzBB6 X-Received: by 2002:a05:6512:2521:b0:4f7:6775:2a66 with SMTP id be33-20020a056512252100b004f767752a66mr8273584lfb.53.1691053364060; Thu, 03 Aug 2023 02:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691053364; cv=none; d=google.com; s=arc-20160816; b=AKr5vxSi0gxUx2k5Lt2tfsvpj1aG2Tf8o8S3TjeT0VoMrfHSBHzZjHBS4hEJ2Ro302 wsA54Rr8rafTkLzzrKc/KtYH4OYlfwmIK5hkAapODTddgdLZg0Tes5bPmaXP4u3ScVU/ m0m58u0pD+SEuqQr8v2s/tHx7ySxt8pktFm/vTZ6Sxz3PqV1buyXEG0mo1PqitKqv/7r nRDc/G7eHK+xa9Egv5fz4Dr1TUGBSirNpz5VOpV2B6f7H2Tt6yIdT/6QKJ2aj/LTfgn6 qe+f+8ELaBaQvCdJ7zGZFBUWfRe8vQVpcc3Bq7dYv17JhmSH43YK+RE42pMo+KRzIYJK y2Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aMJt1BSQ70+nAqZv3DfY2aWRMBDxpF2RibSYxbtwTKA=; fh=Vg9tGsrSzBYx8afZkKO9cP133eyjyjLX5Jlv2NeJdBQ=; b=WUD/7kjNAnkPIBX93zpb/gXGmHsYAoKO7V1GoYf/CU+JBiEDcJWIcP+T+WuDTOHNKB eXPGjHpWaUIU/Wml0/aQyD8JQ+VbW73GZ7gIb7oj2ppZo+UT59fKn3z3tKEWl51PqgS1 w7iNdKJS694QTjb3bgfZaDqtVKhKBKnmph+Xc35xokMRb66YvRQmGcqtQS/TzVAmptNN qxwvRLeNYdfv/p1bCNH3pBq5Lvkz87QgaxcIVDfDkawT2DBXSJoQxytCe0kWESYStNEm jOzX6I8NtHqAeb9TQwtInghNnzkPYgYUyJk7qWb/2WVFcRViZv5UqUm91fg+8C/WqGY+ Cdow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=qOqh6TAk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dy4-20020a05640231e400b00522decb6c84si4301937edb.169.2023.08.03.02.02.19; Thu, 03 Aug 2023 02:02:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=qOqh6TAk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233582AbjHCGnw (ORCPT + 99 others); Thu, 3 Aug 2023 02:43:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233594AbjHCGno (ORCPT ); Thu, 3 Aug 2023 02:43:44 -0400 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAA9D3594; Wed, 2 Aug 2023 23:43:32 -0700 (PDT) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 3736hQQL092032; Thu, 3 Aug 2023 01:43:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1691045006; bh=aMJt1BSQ70+nAqZv3DfY2aWRMBDxpF2RibSYxbtwTKA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=qOqh6TAkfM6gYmvB99+yKIcp2eQdY3Na/uJ3F3InUuq+z3xExALC1sFefdq7xQCG4 wu07RWI34uY5EaFn8+FWSs72jr4JdoEn8zHw4b+mytcB7Fwb/wnbDoJh4ev74dJZC2 a5rlKD6mz2sYgeDWQUWJ3Io+yoC30l+7xJadrzdY= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 3736hQcP024916 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 3 Aug 2023 01:43:26 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Thu, 3 Aug 2023 01:43:26 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Thu, 3 Aug 2023 01:43:25 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 3736hPf8018756; Thu, 3 Aug 2023 01:43:25 -0500 From: Dhruva Gole To: Nishanth Menon , Tero Kristo , "Santosh Shilimkar" CC: , , , Viresh Kumar , "Praneeth Bajjuri" , Tony Lindgren , Dhruva Gole , Dave Gerlach , Vibhore Vardhan , Georgi Vlaev Subject: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support Date: Thu, 3 Aug 2023 12:12:47 +0530 Message-ID: <20230803064247.503036-5-d-gole@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230803064247.503036-1-d-gole@ti.com> References: <20230803064247.503036-1-d-gole@ti.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce system suspend resume calls that will allow the ti_sci driver to support deep sleep low power mode when the user space issues a suspend to mem. Also, write a ti_sci_prepare_system_suspend call to be used in the driver suspend handler to allow the system to identify the low power mode being entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information about the mode is being entered and the address for allocated memory for storing the context during Deep Sleep. We're using "pm_suspend_target_state" to map the kernel's target suspend state to SysFW low power mode. Make sure this is available only when CONFIG_SUSPEND is enabled. Co-developed-by: Dave Gerlach Signed-off-by: Dave Gerlach Signed-off-by: Vibhore Vardhan Signed-off-by: Georgi Vlaev Signed-off-by: Dhruva Gole --- drivers/firmware/ti_sci.c | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 0334ade19868..172b726e00a6 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "ti_sci.h" @@ -3521,6 +3522,67 @@ static int tisci_reboot_handler(struct notifier_block *nb, unsigned long mode, return NOTIFY_BAD; } +static int ti_sci_prepare_system_suspend(struct ti_sci_info *info) +{ +#if IS_ENABLED(CONFIG_SUSPEND) + u8 mode; + + /* Map and validate the target Linux suspend state to TISCI LPM. */ + switch (pm_suspend_target_state) { + case PM_SUSPEND_MEM: + /* S2MEM is not supported by the firmware. */ + if (!(info->fw_caps & MSG_FLAG_CAPS_LPM_DEEP_SLEEP)) + return 0; + mode = TISCI_MSG_VALUE_SLEEP_MODE_DEEP_SLEEP; + break; + default: + /* + * Do not fail if we don't have action to take for a + * specific suspend mode. + */ + return 0; + } + + return ti_sci_cmd_prepare_sleep(&info->handle, mode, + (u32)(info->ctx_mem_addr & 0xffffffff), + (u32)((u64)info->ctx_mem_addr >> 32), 0); +#else + return 0; +#endif +} + +static int ti_sci_suspend(struct device *dev) +{ + struct ti_sci_info *info = dev_get_drvdata(dev); + int ret; + + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE); + if (ret) + return ret; + dev_dbg(dev, "%s: set I/O isolation: %d\n", __func__, ret); + + ret = ti_sci_prepare_system_suspend(info); + if (ret) + return ret; + + return 0; +} + +static int ti_sci_resume(struct device *dev) +{ + struct ti_sci_info *info = dev_get_drvdata(dev); + int ret; + + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_DISABLE); + if (ret) + return ret; + dev_dbg(dev, "%s: disable I/O isolation: %d\n", __func__, ret); + + return 0; +} + +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) { @@ -3759,6 +3821,7 @@ static struct platform_driver ti_sci_driver = { .driver = { .name = "ti-sci", .of_match_table = of_match_ptr(ti_sci_of_match), + .pm = &ti_sci_pm_ops, }, }; module_platform_driver(ti_sci_driver); -- 2.34.1