From patchwork Fri Aug 4 11:50:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhruva Gole X-Patchwork-Id: 131132 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp219661vqb; Fri, 4 Aug 2023 05:17:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnU+pP+bb3gtK90H9ccmNUP/0vPQsk7ZsqBrRyJ9oCNWiS97PJt0xYEXOYBYBRevAbVq/g X-Received: by 2002:a19:915c:0:b0:4fa:21d4:b3ca with SMTP id y28-20020a19915c000000b004fa21d4b3camr1149945lfj.2.1691151448379; Fri, 04 Aug 2023 05:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691151448; cv=none; d=google.com; s=arc-20160816; b=gVorzs01kjA9/e0mrx9FDhArFNGbh3ygdBOk/rGFcsejRZkaOYTNVfkvZx/omuHdGb c3Mlhb/ej6biuJOc9MutX7XaFRNYU76G0mquhfBerOblejMC+4mmU8UJeuds1YX2deBY uEjcOZWyJoIqn3fB0SFA5zBtLeJjJZQb0R3MpuK+e7wvrLeaCfo0BxX5TCLmImeJ6BBT jb97/F7w3Yai9REYq317lwMCvZimB92dxXPi4Ipg//hwj4T3vvQsVou8dgmURI2WQH5/ bLPTFTlKgQdZ9ReshDtJOu7HGvfnP1/MEQcqD1S++pd4hTUUpkBo/ZhUWfG43MfKVsAp eclw== 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=ryoxWjJtb+Uw+NimGpPuRuUrWlV6tOVEwnFSxurjAJQ=; fh=PwC0IhEEKxqCBb/XYIaFJPImivuUM3RDbFZoNPLL6NU=; b=yT6I0mWHHBG9OojC2ZKlTdTkkdzM41bnpx7K4BRm8BWIMcbgwqZCixAG8hjl8lWKtF mzRIjL/OcZrVi8Xz5eugxvvLWZ0cYRjizmyNRx9k5C9J2e2oqAOafa7rvppvr0J8Jf1c EUDVFJO4DypxOIUMfpG4jW4QEpeFOxCNsIMvjOXLdgdmKREFYdRNqjQTdwx1osFwU7JF OrRUDTOWrh/RdEh03lTqdTFnpeINA3naz8rUjMVs+CdlHrxVkiGQHXQAziHYeR+MjvEv rKmNpKbOkwskp5wit4XM88vz7QXqvArioVHKHq9x4wgSWwk9wkJDRKW8tm2z5utsHkVp fyiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=tIPAhEBe; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f23-20020aa7d857000000b005222b60fc67si1462638eds.303.2023.08.04.05.17.04; Fri, 04 Aug 2023 05:17:28 -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=tIPAhEBe; 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 S230506AbjHDLws (ORCPT + 99 others); Fri, 4 Aug 2023 07:52:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbjHDLwm (ORCPT ); Fri, 4 Aug 2023 07:52:42 -0400 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFB52128; Fri, 4 Aug 2023 04:52:40 -0700 (PDT) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 374BqZFa071741; Fri, 4 Aug 2023 06:52:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1691149955; bh=ryoxWjJtb+Uw+NimGpPuRuUrWlV6tOVEwnFSxurjAJQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=tIPAhEBeclDbtqOe5IUBd3tkdsA4mNLEdPwIjfPjP0OCqlPDj+cZvjaTYzlABz4tK MPep5UdklpmRUPlQ7yMtMJtA/mtAjsMwJ5cxu2hTZ5CvCZY68TPldr9HGdZ7qclSb3 RsoiZqp0xouIZq3V0ctYDsXKeri2XiupqIuEh9nI= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 374BqZZw009933 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 4 Aug 2023 06:52:35 -0500 Received: from DFLE113.ent.ti.com (10.64.6.34) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Fri, 4 Aug 2023 06:52:35 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE113.ent.ti.com (10.64.6.34) 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; Fri, 4 Aug 2023 06:52:35 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 374BqY1q130233; Fri, 4 Aug 2023 06:52:35 -0500 From: Dhruva Gole To: Nishanth Menon , Tero Kristo , "Santosh Shilimkar" CC: , , , , "Kevin Hilman" , Vignesh R , Dhruva Gole , Dave Gerlach , Vibhore Vardhan , Georgi Vlaev Subject: [PATCH V7 4/4] firmware: ti_sci: Add system suspend call Date: Fri, 4 Aug 2023 17:20:37 +0530 Message-ID: <20230804115037.754994-5-d-gole@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804115037.754994-1-d-gole@ti.com> References: <20230804115037.754994-1-d-gole@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773300820898460998 X-GMAIL-MSGID: 1773300820898460998 Introduce system suspend call that enables 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 --- changelog: We no longer need to do anything special during resume, hence remove the resume call 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 512338699153..9584015f2b19 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -3433,6 +3434,49 @@ 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_prepare_system_suspend(info); + if (ret) + return ret; + + return 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(ti_sci_pm_ops, ti_sci_suspend, NULL); + static int ti_sci_init_suspend(struct platform_device *pdev, struct ti_sci_info *info) { @@ -3673,6 +3717,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);