From patchwork Thu Mar 6 11:14:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 14004281 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 AA654C282D1 for ; Thu, 6 Mar 2025 11:30:22 +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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xVEl7GGxVsvJAydmpEAK0z7cXYry+D3ir8zQb7r/A3k=; b=lmvlhV4Aqn7xaDBjS2B1Y7FFOX 3ay7QVdDD5dYbNosT32X52y4T1d2yZa6BNwvW4t3VBYVKdsIeJfHaIAUPNi32WpzArlMtDK4+7m1R g0EGR8e8CttkJ2xv4rR3D5fCPJRKWIDIaHC6MlPmGpmQkOcn5kWl6YiRsWRUzj4tSXfRi3l8LsYiJ j4f0t7N5NxF9Pum1PgIZT1h6Mb8l+SCkIQrHiu3BLbNCQxUE/3rlGKyd1JauNlld7nFCQ4/VehIin ieIO79TXPYr4R67eWw3wNHkSCa/c4HYQPXhrUJpWxZb/YFshLpOrtJpukNhowP9yEBn9EkuBgdibt cKggvpJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tq9QW-0000000Amav-1BrC; Thu, 06 Mar 2025 11:30:08 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tq9Cq-0000000Akbd-1Ucu for linux-arm-kernel@lists.infradead.org; Thu, 06 Mar 2025 11:16:01 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-abf45d8db04so77391266b.1 for ; Thu, 06 Mar 2025 03:15:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1741259759; x=1741864559; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=xVEl7GGxVsvJAydmpEAK0z7cXYry+D3ir8zQb7r/A3k=; b=NkNEFx5f0ueMCKTAQ4CkZ79z/aE6/tvZ83fWsDa75DvHAkgdxgl0Rc9n5QKHgd3kgw sduaOzz/TcONdzf1GIX2kygqfrsqa0eJG5pJeApv7EGwBZR5Yz7yHtdDBhy3VmUUVL5P yuRZOOtPe3bEOeyIXF9uqOuLX8Ur3W2syaO465Sh0Ob84q97QpSBkAY8/p8txBkJoMLk g2LHMPfHpDtN1/8GV/KpIrHtgb2WKYPxnmQ6m3ePBK3ptgzFpM7spnR0FDc62ptbaYQQ l6BryT+C4UXP43JASEz0L/UpiqEyDgskMkGK1y7ka/i3D51fH3VvNG1efw+EzXEaa/tc r67w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741259759; x=1741864559; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xVEl7GGxVsvJAydmpEAK0z7cXYry+D3ir8zQb7r/A3k=; b=b57HTo4CQaA/sOuZBMWrY1SRGg1hwXSR4ecaQi088ZDLw0gYSMXJ5Tfitdhs/JThqE P4eUJoskqO4xTMu7ODiLyXUpjVNlQUowtMemNsPgwJ2Q6fTZNwvwjA88nWSMVqQ9lANF tZMBt2pBRjMsWBeOvsTa3DkhMJ7C2Gf1JOMBf+Qjm6grV5cjSwpeO73OSUnsKgzcE6dT 2G/nuvNC7dOgErezSuUTCFHf2QTwLmHemU39lU9v+8cJwkIwTVffORTQJHQhOC6zXwaa w1CumfaqC0I+AVeuNGrJb3Yl36KzLckkaAFS/SciESm1x4dL8Z7I7GK+nQOom/Po6SSg myvA== X-Gm-Message-State: AOJu0YxBVriPY1AqGAubhjdxLyRNLGq9M3b5jEOIhgilIGjSk+3SQWDU sPNgJC6ddZbjUyEKF2mQrkC2TbJ4LQFzVHRG4yW++M7we3jaaIDjoXD+d7LbZAWGfSfY305661p Q X-Gm-Gg: ASbGnctLJeAmVqYLeO1KE/xAAJxdwGL+KL6bGN/gfmsiNJGsSCIpVWX7qDpF6XcF2lB nl/ICKJ0rCgjoVr3ucnLPN230dSIKHS+KHrkWkALq7vKwIAHHjPygW6kgDTjonGaWr2IKxG8cbW ZTOCxiZBueiQtqjBtB2VM4bmUV7sichPkNX3avzaVZySt1mOaUtr3HhDc1bS83QiAV+gw0szl7D +WF6+w+VQo8X/vfrBRSLydkjxjHCntBV0M0LWRPUdOOFi3i98wXCyQh5Zw+jR7Rch1SRWiF3gm+ bebZExRerxJgsJFNgEH00kfqFAVhxOovHEm5L/34Gg== X-Google-Smtp-Source: AGHT+IF3a3lHfhfzXs+A5h2hqn+LCqXVZ/19bMhntk0ZUTM1sIl49L5vTk6C51T88uqw26ghNIwGUw== X-Received: by 2002:a17:907:388b:b0:ac1:d878:f877 with SMTP id a640c23a62f3a-ac20dafe79cmr723201666b.49.1741259758456; Thu, 06 Mar 2025 03:15:58 -0800 (PST) Received: from localhost ([2001:4091:a245:8327:80ad:8144:3b07:4679]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-ac239481685sm80632766b.58.2025.03.06.03.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 03:15:58 -0800 (PST) From: Markus Schneider-Pargmann Date: Thu, 06 Mar 2025 12:14:40 +0100 Subject: [PATCH v5 02/13] firmware: ti_sci: Partial-IO support MIME-Version: 1.0 Message-Id: <20250306-topic-am62-partialio-v6-12-b4-v5-2-f9323d3744a2@baylibre.com> References: <20250306-topic-am62-partialio-v6-12-b4-v5-0-f9323d3744a2@baylibre.com> In-Reply-To: <20250306-topic-am62-partialio-v6-12-b4-v5-0-f9323d3744a2@baylibre.com> To: Nishanth Menon , Tero Kristo , Santosh Shilimkar , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Anand Gadiyar , Chandrasekar Ramakrishnan , Marc Kleine-Budde , Vincent Mailhol Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Vishal Mahaveer , Kevin Hilman , Dhruva Gole , Akashdeep Kaur , Kendall Willis , linux-can@vger.kernel.org, Markus Schneider-Pargmann X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6749; i=msp@baylibre.com; h=from:subject:message-id; bh=MCR8mlvD+LHlMEDeTvlAn1OwnFD8ckM/crgbFzyaGVA=; b=owGbwMvMwCGm0rPl0RXRdfaMp9WSGNJPNm+++XbfPBn+sy/Ws3dYFvO8jai5cWtJzOGfKfafT l8L/neAraOUhUGMg0FWTJHl7oeF7+rkri+IWPfIEWYOKxPIEAYuTgGYyBUGRobFLZYHpb+/Ml52 9Mq2kkx2E+G/Il4b//7MuOMtk/h93+UfDP8rpvWvMvF4w+S5eYphollgrvuKwv4k1jjF4P01LNv EXrMCAA== X-Developer-Key: i=msp@baylibre.com; a=openpgp; fpr=BADD88DB889FDC3E8A3D5FE612FA6A01E0A45B41 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250306_031600_401873_0CC81AE8 X-CRM114-Status: GOOD ( 26.73 ) 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 Add support for Partial-IO poweroff. In Partial-IO pins of a few hardware units can generate system wakeups while DDR memory is not powered resulting in a fresh boot of the system. These hardware units in the SoC are always powered so that some logic can detect pin activity. If the system supports Partial-IO as described in the fw capabilities, a sys_off handler is added. This sys_off handler decides if the poweroff is executed by entering normal poweroff or Partial-IO instead. The decision is made by checking if wakeup is enabled on all devices that may wake up the SoC from Partial-IO. The possible wakeup devices are found by checking which devices reference a "Partial-IO" system state in the list of wakeup-source system states. Only devices that are actually enabled by the user will be considered as an active wakeup source. If none of the wakeup sources is enabled the system will do a normal poweroff. If at least one wakeup source is enabled it will instead send a TI_SCI_MSG_PREPARE_SLEEP message from the sys_off handler. Sending this message will result in an immediate shutdown of the system. No execution is expected after this point. The code will wait for 5s and do an emergency_restart afterwards if Partial-IO wasn't entered at that point. A short documentation about Partial-IO can be found in section 6.2.4.5 of the TRM at https://www.ti.com/lit/pdf/spruiv7 Signed-off-by: Markus Schneider-Pargmann --- drivers/firmware/ti_sci.c | 127 +++++++++++++++++++++++++++++++++++++++++++++- drivers/firmware/ti_sci.h | 5 ++ 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 09d11e75e14e6a6a82f6d99ab1852c142aeb7e5f..a4b7869134779c58f4ef381a940455dea1f86153 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -6,6 +6,7 @@ * Nishanth Menon */ +#include "linux/stddef.h" #define pr_fmt(fmt) "%s: " fmt, __func__ #include @@ -3742,6 +3743,111 @@ static const struct dev_pm_ops ti_sci_pm_ops = { #endif }; +/* + * Enter Partial-IO, which disables everything including DDR with only a small + * logic being active for wakeup. + */ +static int ti_sci_enter_partial_io(struct ti_sci_info *info) +{ + struct ti_sci_msg_req_prepare_sleep *req; + struct ti_sci_xfer *xfer; + struct device *dev = info->dev; + int ret = 0; + + xfer = ti_sci_get_one_xfer(info, TI_SCI_MSG_PREPARE_SLEEP, + TI_SCI_FLAG_REQ_GENERIC_NORESPONSE, + sizeof(*req), sizeof(struct ti_sci_msg_hdr)); + 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 = TISCI_MSG_VALUE_SLEEP_MODE_PARTIAL_IO; + req->ctx_lo = 0; + req->ctx_hi = 0; + req->debug_flags = 0; + + dev_info(dev, "Entering Partial-IO because a powered wakeup-enabled device was found.\n"); + + ret = ti_sci_do_xfer(info, xfer); + if (ret) { + dev_err(dev, "Mbox send fail %d\n", ret); + goto fail; + } + +fail: + ti_sci_put_one_xfer(&info->minfo, xfer); + + return ret; +} + +/* + * Iterate all device nodes that have a wakeup-source property and check if one + * of the possible phandles points to a Partial-IO system state. If it + * does resolve the device node to an actual device and check if wakeup is + * enabled. + */ +static bool ti_sci_partial_io_wakeup_enabled(struct ti_sci_info *info) +{ + struct device_node *wakeup_node = NULL; + + for_each_node_with_property(wakeup_node, "wakeup-source") { + struct of_phandle_iterator it; + int err; + + of_for_each_phandle(&it, err, wakeup_node, "wakeup-source", NULL, 0) { + struct platform_device *pdev; + bool may_wakeup; + + if (of_property_match_string(it.node, "idle-state-name", "Partial-IO")) + continue; + + pdev = of_find_device_by_node(wakeup_node); + if (!pdev) + continue; + + may_wakeup = device_may_wakeup(&pdev->dev); + put_device(&pdev->dev); + + if (may_wakeup) { + dev_dbg(info->dev, "%pOF identified as wakeup source for Partial-IO\n", + wakeup_node); + of_node_put(it.node); + of_node_put(wakeup_node); + return true; + } + } + } + + return false; +} + +static int ti_sci_sys_off_handler(struct sys_off_data *data) +{ + struct ti_sci_info *info = data->cb_data; + bool enter_partial_io = ti_sci_partial_io_wakeup_enabled(info); + int ret; + + if (!enter_partial_io) + return NOTIFY_DONE; + + ret = ti_sci_enter_partial_io(info); + + if (ret) { + dev_err(info->dev, + "Failed to enter Partial-IO %pe, trying to do an emergency restart\n", + ERR_PTR(ret)); + emergency_restart(); + } + + mdelay(5000); + emergency_restart(); + + return NOTIFY_DONE; +} + /* Description for K2G */ static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = { .default_host_id = 2, @@ -3885,6 +3991,19 @@ static int ti_sci_probe(struct platform_device *pdev) goto out; } + if (info->fw_caps & MSG_FLAG_CAPS_LPM_PARTIAL_IO) { + ret = devm_register_sys_off_handler(dev, + SYS_OFF_MODE_POWER_OFF, + SYS_OFF_PRIO_FIRMWARE, + ti_sci_sys_off_handler, + info); + if (ret) { + dev_err(dev, "Failed to register sys_off_handler %pe\n", + ERR_PTR(ret)); + goto out; + } + } + 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, @@ -3894,7 +4013,13 @@ static int ti_sci_probe(struct platform_device *pdev) list_add_tail(&info->node, &ti_sci_list); mutex_unlock(&ti_sci_list_mutex); - return of_platform_populate(dev->of_node, NULL, NULL, dev); + ret = of_platform_populate(dev->of_node, NULL, NULL, dev); + if (ret) { + dev_err(dev, "platform_populate failed %pe\n", ERR_PTR(ret)); + goto out; + } + return 0; + out: if (!IS_ERR(info->chan_tx)) mbox_free_channel(info->chan_tx); diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h index 053387d7baa064498e6a208daa7f70040ef87281..dec9e20cbe5da8f6d9393d56bb9a1e73cb083a42 100644 --- a/drivers/firmware/ti_sci.h +++ b/drivers/firmware/ti_sci.h @@ -592,6 +592,11 @@ struct ti_sci_msg_resp_get_clock_freq { struct ti_sci_msg_req_prepare_sleep { struct ti_sci_msg_hdr hdr; +/* + * When sending perpare_sleep with MODE_PARTIAL_IO no response will be sent, + * no further steps are required. + */ +#define TISCI_MSG_VALUE_SLEEP_MODE_PARTIAL_IO 0x03 #define TISCI_MSG_VALUE_SLEEP_MODE_DM_MANAGED 0xfd u8 mode; u32 ctx_lo;