From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C12A9C5472D for ; Mon, 26 Aug 2024 16:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:CC:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+tBVzV0riob7xfH4wlOcVf38jJoFf60E+6QObXwL9I0=; b=tvlhhReL9uvv0J5pADst3heSQL JihktPoxZGvqxFitWmXtMZWUzBnOv/jTf9HYk+ezXk7Y77urL7tGnFqsHDK3xIV5OcxnbEs7LoCL/ uZxjNZtziGNrdhX2lk3VpVa4dLtT6JcFSB4jSy3LHNWs1Yo+j4C9fEo93W0k2GXwX6ry3FTuhBIeP zFU5a/0YW2YW/5UBE+VyQWbjMcphKjuHPq9ZnanhDdGfpCqzTSxmhECDOE5cfI8AYS9/nDb/eSTpm h7hpHtf2JKlGfekmJx7zWYQavgqTFRXBh9abphU7zMrImSdfHGwF6HNZXboZ6cYLCCKff/QX/HTfT G0U//QUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sich3-000000081iB-3HXK; Mon, 26 Aug 2024 16:35:49 +0000 Received: from fllv0015.ext.ti.com ([198.47.19.141]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sicgG-000000081aD-1QX1 for linux-arm-kernel@lists.infradead.org; Mon, 26 Aug 2024 16:35:01 +0000 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 47QGYueK119717; Mon, 26 Aug 2024 11:34:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1724690096; bh=+tBVzV0riob7xfH4wlOcVf38jJoFf60E+6QObXwL9I0=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=tk5lgmQ5OTGRtDF63kdHdK1MKwnXDA/timSK06H7fQGGTcUzuHbuLmp0uepDwxChT yTksf6r17R/F7DiBZ7roHGDTun6p2Dx/4NZKgO4CI1uPDV34fsR0x25IhwE0gCxxbo UUYkjpHktFUDWkr8EpxGt6MXlK0P5TQ/bWBsfCgI= Received: from DFLE101.ent.ti.com (dfle101.ent.ti.com [10.64.6.22]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 47QGYu6R044969 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 26 Aug 2024 11:34:56 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 26 Aug 2024 11:34:55 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE101.ent.ti.com (10.64.6.22) 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; Mon, 26 Aug 2024 11:34:55 -0500 Received: from localhost (uda0133052.dhcp.ti.com [128.247.81.232]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 47QGYtqc071677; Mon, 26 Aug 2024 11:34:55 -0500 Date: Mon, 26 Aug 2024 11:34:55 -0500 From: Nishanth Menon To: Kevin Hilman CC: Tero Kristo , Santosh Shilimkar , , , Vibhore Vardhan , Dhruva Gole , Akashdeep Kaur , Markus Schneider-Pargmann Subject: Re: [PATCH v10 2/4] firmware: ti_sci: Add system suspend and resume call Message-ID: <20240826163455.bp3a6lxtimiquzq5@ascertain> References: <20240814-lpm-constraints-firmware-msp-v10-0-bee4314bbdc8@baylibre.com> <20240814-lpm-constraints-firmware-msp-v10-2-bee4314bbdc8@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20240814-lpm-constraints-firmware-msp-v10-2-bee4314bbdc8@baylibre.com> X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240826_093500_500505_212E8CAA X-CRM114-Status: GOOD ( 27.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 08:39-20240814, Kevin Hilman wrote: > From: Vibhore Vardhan > [...] > + * > + * Return: 0 if all went well, else returns appropriate error value. > + */ > +static int ti_sci_cmd_prepare_sleep(const struct ti_sci_handle *handle, u8 mode, > + u32 ctx_lo, u32 ctx_hi, u32 debug_flags) > +{ > + struct ti_sci_info *info; > + struct ti_sci_msg_req_prepare_sleep *req; > + struct ti_sci_msg_hdr *resp; > + struct ti_sci_xfer *xfer; > + struct device *dev; > + int ret = 0; > + > + if (IS_ERR(handle)) > + return PTR_ERR(handle); > + if (!handle) > + return -EINVAL; > + > + info = handle_to_ti_sci_info(handle); > + dev = info->dev; > + > + xfer = ti_sci_get_one_xfer(info, TI_SCI_MSG_PREPARE_SLEEP, > + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, > + sizeof(*req), sizeof(*resp)); > + if (IS_ERR(xfer)) { > + ret = PTR_ERR(xfer); > + dev_err(dev, "Message alloc failed(%d)\n", ret); > + return ret; > + } > + > + req = (struct ti_sci_msg_req_prepare_sleep *)xfer->xfer_buf; > + req->mode = mode; > + req->ctx_lo = ctx_lo; > + req->ctx_hi = ctx_hi; > + req->debug_flags = debug_flags; > + > + ret = ti_sci_do_xfer(info, xfer); > + if (ret) { > + dev_err(dev, "Mbox send fail %d\n", ret); > + goto fail; > + } > + > + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; > + > + ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV; Here and other functions: I think adding a dev_err for a NAKed message is probably useful for debug. > + > +fail: > + ti_sci_put_one_xfer(&info->minfo, xfer); > + > + return ret; > +} > + > /** > * ti_sci_msg_cmd_query_fw_caps() - Get the FW/SoC capabilities > * @handle: Pointer to TI SCI handle > @@ -1710,6 +1770,58 @@ static int ti_sci_msg_cmd_query_fw_caps(const struct ti_sci_handle *handle, > return ret; > } > > +/** > + * ti_sci_cmd_set_io_isolation() - Enable IO isolation in LPM > + * @handle: Pointer to TI SCI handle > + * @state: The desired state of the IO isolation > + * > + * Return: 0 if all went well, else returns appropriate error value. > + */ > +static int ti_sci_cmd_set_io_isolation(const struct ti_sci_handle *handle, > + u8 state) I probably might have preferred to have set_io_isolation as a different patch, but OK, it is not too hard to see the hookup commonality. > +{ > + struct ti_sci_info *info; > + struct ti_sci_msg_req_set_io_isolation *req; > + struct ti_sci_msg_hdr *resp; > + struct ti_sci_xfer *xfer; > + struct device *dev; > + int ret = 0; > + > + if (IS_ERR(handle)) > + return PTR_ERR(handle); > + if (!handle) > + return -EINVAL; > + > + info = handle_to_ti_sci_info(handle); > + dev = info->dev; > + > + xfer = ti_sci_get_one_xfer(info, TI_SCI_MSG_SET_IO_ISOLATION, > + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, > + sizeof(*req), sizeof(*resp)); > + if (IS_ERR(xfer)) { > + ret = PTR_ERR(xfer); > + dev_err(dev, "Message alloc failed(%d)\n", ret); > + return ret; > + } > + req = (struct ti_sci_msg_req_set_io_isolation *)xfer->xfer_buf; > + req->state = state; > + > + ret = ti_sci_do_xfer(info, xfer); > + if (ret) { > + dev_err(dev, "Mbox send fail %d\n", ret); > + goto fail; > + } > + > + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; > + > + ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV; here as well. > + > +fail: > + ti_sci_put_one_xfer(&info->minfo, xfer); > + > + return ret; > +} > + > static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle) > { > struct ti_sci_info *info; > @@ -3321,6 +3433,79 @@ static int tisci_reboot_handler(struct sys_off_data *data) > return NOTIFY_BAD; > } > > +#ifdef CONFIG_SUSPEND > +static int ti_sci_prepare_system_suspend(struct ti_sci_info *info) > +{ > + u8 mode; > + > + /* > + * Map and validate the target Linux suspend state to TISCI LPM. > + * Default is to let Device Manager select the low power mode. > + */ > + switch (pm_suspend_target_state) { > + case PM_SUSPEND_MEM: > + if (info->fw_caps & MSG_FLAG_CAPS_LPM_DM_MANAGED) > + mode = TISCI_MSG_VALUE_SLEEP_MODE_DM_MANAGED; > + else > + /* DM Managed is not supported by the firmware. */ dev_err print is useful for debug? > + return -EOPNOTSUPP; > + 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, 0, 0, 0); Umm.. context address is 0x0? > +} > + > +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 int ti_sci_suspend_noirq(struct device *dev) > +{ > + struct ti_sci_info *info = dev_get_drvdata(dev); > + int ret = 0; > + > + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE); > + if (ret) > + return ret; Does this add any value here? > + dev_dbg(dev, "%s: set isolation: %d\n", __func__, ret); > + > + return 0; > +} > + > +static int ti_sci_resume_noirq(struct device *dev) > +{ > + struct ti_sci_info *info = dev_get_drvdata(dev); > + int ret = 0; > + > + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_DISABLE); > + if (ret) > + return ret; Same.. > + dev_dbg(dev, "%s: disable isolation: %d\n", __func__, ret); > + > + return 0; > +} > + > +static const struct dev_pm_ops ti_sci_pm_ops = { > + .suspend = ti_sci_suspend, > + .suspend_noirq = ti_sci_suspend_noirq, > + .resume_noirq = ti_sci_resume_noirq, > +}; > +#endif /* CONFIG_SUSPEND */ Mostly, I am seeing usage with CONFIG_PM_SLEEP instead of CONFIG_SUSPEND. is that a better option? and further, usage tends to be as follows: static int __maybe_unused ti_sci_resume_noirq(struct device *dev) static const struct dev_pm_ops ti_sci_pm_ops = { #ifdef CONFIG_PM_SLEEP .suspend = ti_sci_suspend, .suspend_noirq = ti_sci_suspend_noirq, .resume_noirq = ti_sci_resume_noirq, #endif }; Keeps the #ifdeffery just localized to one place. Thoughts? > + > /* Description for K2G */ > static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = { > .default_host_id = 2, > @@ -3490,6 +3675,9 @@ static struct platform_driver ti_sci_driver = { > .name = "ti-sci", > .of_match_table = of_match_ptr(ti_sci_of_match), > .suppress_bind_attrs = true, > +#ifdef CONFIG_SUSPEND > + .pm = &ti_sci_pm_ops, > +#endif > }, > }; > module_platform_driver(ti_sci_driver); [...] -- Regards, Nishanth Menon Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3 1A34 DDB5 849D 1736 249D