Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

firmware: ti_sci: Add system suspend and resume call

Introduce system suspend call that enables the ti_sci driver to support
low power mode when the user space issues a suspend to mem.

The following power management operations defined in the TISCI
Low Power Mode API [1] are implemented to support suspend and resume:

1) TISCI_MSG_PREPARE_SLEEP
Prepare the SOC for entering into a low power mode and
provide details to firmware about the state being entered.

2) TISCI_MSG_SET_IO_ISOLATION
Control the IO isolation for Low Power Mode.

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 being entered.

Sysfw version >= 10.00.04 support LPM_DM_MANAGED capability [2], where
Device Mgr firmware now manages which low power mode is chosen. Going
forward, this is the default configuration supported for TI AM62 family
of devices. The state chosen by the DM can be influenced by sending
constraints using the new LPM constraint APIs.

In case the firmware does not support LPM_DM_MANAGED mode, the mode
selection logic can be extended as needed. If no suspend-to-RAM modes
are supported, return without taking any action.

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.

Suspend has to be split into two parts, ti_sci_suspend() will send
the prepare sleep message to prepare suspend. ti_sci_suspend_noirq()
sets IO isolation which needs to be done as late as possible to avoid
any issues. On resume this has to be done as early as possible.

[1] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/pm/lpm.html

Co-developed-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Georgi Vlaev <g-vlaev@ti.com>
Signed-off-by: Dhruva Gole <d-gole@ti.com>
Signed-off-by: Vibhore Vardhan <vibhore@ti.com>
Signed-off-by: Kevin Hilman <khilman@baylibre.com>
Tested-by: Dhruva Gole <d-gole@ti.com>
Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
Tested-by: Roger Quadros <rogerq@kernel.org>
Link: https://lore.kernel.org/r/20241007-tisci-syssuspendresume-v13-3-ed54cd659a49@baylibre.com
Signed-off-by: Nishanth Menon <nm@ti.com>

authored by

Vibhore Vardhan and committed by
Nishanth Menon
ec24643b 055b6cfb

+242 -1
+194
drivers/firmware/ti_sci.c
··· 24 24 #include <linux/slab.h> 25 25 #include <linux/soc/ti/ti-msgmgr.h> 26 26 #include <linux/soc/ti/ti_sci_protocol.h> 27 + #include <linux/suspend.h> 27 28 #include <linux/sys_soc.h> 28 29 #include <linux/reboot.h> 29 30 ··· 1656 1655 } 1657 1656 1658 1657 /** 1658 + * ti_sci_cmd_prepare_sleep() - Prepare system for system suspend 1659 + * @handle: pointer to TI SCI handle 1660 + * @mode: Device identifier 1661 + * @ctx_lo: Low part of address for context save 1662 + * @ctx_hi: High part of address for context save 1663 + * @debug_flags: Debug flags to pass to firmware 1664 + * 1665 + * Return: 0 if all went well, else returns appropriate error value. 1666 + */ 1667 + static int ti_sci_cmd_prepare_sleep(const struct ti_sci_handle *handle, u8 mode, 1668 + u32 ctx_lo, u32 ctx_hi, u32 debug_flags) 1669 + { 1670 + struct ti_sci_info *info; 1671 + struct ti_sci_msg_req_prepare_sleep *req; 1672 + struct ti_sci_msg_hdr *resp; 1673 + struct ti_sci_xfer *xfer; 1674 + struct device *dev; 1675 + int ret = 0; 1676 + 1677 + if (IS_ERR(handle)) 1678 + return PTR_ERR(handle); 1679 + if (!handle) 1680 + return -EINVAL; 1681 + 1682 + info = handle_to_ti_sci_info(handle); 1683 + dev = info->dev; 1684 + 1685 + xfer = ti_sci_get_one_xfer(info, TI_SCI_MSG_PREPARE_SLEEP, 1686 + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, 1687 + sizeof(*req), sizeof(*resp)); 1688 + if (IS_ERR(xfer)) { 1689 + ret = PTR_ERR(xfer); 1690 + dev_err(dev, "Message alloc failed(%d)\n", ret); 1691 + return ret; 1692 + } 1693 + 1694 + req = (struct ti_sci_msg_req_prepare_sleep *)xfer->xfer_buf; 1695 + req->mode = mode; 1696 + req->ctx_lo = ctx_lo; 1697 + req->ctx_hi = ctx_hi; 1698 + req->debug_flags = debug_flags; 1699 + 1700 + ret = ti_sci_do_xfer(info, xfer); 1701 + if (ret) { 1702 + dev_err(dev, "Mbox send fail %d\n", ret); 1703 + goto fail; 1704 + } 1705 + 1706 + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; 1707 + 1708 + if (!ti_sci_is_response_ack(resp)) { 1709 + dev_err(dev, "Failed to prepare sleep\n"); 1710 + ret = -ENODEV; 1711 + } 1712 + 1713 + fail: 1714 + ti_sci_put_one_xfer(&info->minfo, xfer); 1715 + 1716 + return ret; 1717 + } 1718 + 1719 + /** 1659 1720 * ti_sci_msg_cmd_query_fw_caps() - Get the FW/SoC capabilities 1660 1721 * @handle: Pointer to TI SCI handle 1661 1722 * @fw_caps: Each bit in fw_caps indicating one FW/SOC capability ··· 1771 1708 1772 1709 if (fw_caps) 1773 1710 *fw_caps = resp->fw_caps; 1711 + 1712 + fail: 1713 + ti_sci_put_one_xfer(&info->minfo, xfer); 1714 + 1715 + return ret; 1716 + } 1717 + 1718 + /** 1719 + * ti_sci_cmd_set_io_isolation() - Enable IO isolation in LPM 1720 + * @handle: Pointer to TI SCI handle 1721 + * @state: The desired state of the IO isolation 1722 + * 1723 + * Return: 0 if all went well, else returns appropriate error value. 1724 + */ 1725 + static int ti_sci_cmd_set_io_isolation(const struct ti_sci_handle *handle, 1726 + u8 state) 1727 + { 1728 + struct ti_sci_info *info; 1729 + struct ti_sci_msg_req_set_io_isolation *req; 1730 + struct ti_sci_msg_hdr *resp; 1731 + struct ti_sci_xfer *xfer; 1732 + struct device *dev; 1733 + int ret = 0; 1734 + 1735 + if (IS_ERR(handle)) 1736 + return PTR_ERR(handle); 1737 + if (!handle) 1738 + return -EINVAL; 1739 + 1740 + info = handle_to_ti_sci_info(handle); 1741 + dev = info->dev; 1742 + 1743 + xfer = ti_sci_get_one_xfer(info, TI_SCI_MSG_SET_IO_ISOLATION, 1744 + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, 1745 + sizeof(*req), sizeof(*resp)); 1746 + if (IS_ERR(xfer)) { 1747 + ret = PTR_ERR(xfer); 1748 + dev_err(dev, "Message alloc failed(%d)\n", ret); 1749 + return ret; 1750 + } 1751 + req = (struct ti_sci_msg_req_set_io_isolation *)xfer->xfer_buf; 1752 + req->state = state; 1753 + 1754 + ret = ti_sci_do_xfer(info, xfer); 1755 + if (ret) { 1756 + dev_err(dev, "Mbox send fail %d\n", ret); 1757 + goto fail; 1758 + } 1759 + 1760 + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; 1761 + 1762 + if (!ti_sci_is_response_ack(resp)) { 1763 + dev_err(dev, "Failed to set IO isolation\n"); 1764 + ret = -ENODEV; 1765 + } 1774 1766 1775 1767 fail: 1776 1768 ti_sci_put_one_xfer(&info->minfo, xfer); ··· 3444 3326 return NOTIFY_BAD; 3445 3327 } 3446 3328 3329 + static int ti_sci_prepare_system_suspend(struct ti_sci_info *info) 3330 + { 3331 + /* 3332 + * Map and validate the target Linux suspend state to TISCI LPM. 3333 + * Default is to let Device Manager select the low power mode. 3334 + */ 3335 + switch (pm_suspend_target_state) { 3336 + case PM_SUSPEND_MEM: 3337 + if (info->fw_caps & MSG_FLAG_CAPS_LPM_DM_MANAGED) { 3338 + /* 3339 + * For the DM_MANAGED mode the context is reserved for 3340 + * internal use and can be 0 3341 + */ 3342 + return ti_sci_cmd_prepare_sleep(&info->handle, 3343 + TISCI_MSG_VALUE_SLEEP_MODE_DM_MANAGED, 3344 + 0, 0, 0); 3345 + } else { 3346 + /* DM Managed is not supported by the firmware. */ 3347 + dev_err(info->dev, "Suspend to memory is not supported by the firmware\n"); 3348 + return -EOPNOTSUPP; 3349 + } 3350 + break; 3351 + default: 3352 + /* 3353 + * Do not fail if we don't have action to take for a 3354 + * specific suspend mode. 3355 + */ 3356 + return 0; 3357 + } 3358 + } 3359 + 3360 + static int __maybe_unused ti_sci_suspend(struct device *dev) 3361 + { 3362 + struct ti_sci_info *info = dev_get_drvdata(dev); 3363 + int ret; 3364 + 3365 + ret = ti_sci_prepare_system_suspend(info); 3366 + if (ret) 3367 + return ret; 3368 + 3369 + return 0; 3370 + } 3371 + 3372 + static int __maybe_unused ti_sci_suspend_noirq(struct device *dev) 3373 + { 3374 + struct ti_sci_info *info = dev_get_drvdata(dev); 3375 + int ret = 0; 3376 + 3377 + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE); 3378 + if (ret) 3379 + return ret; 3380 + 3381 + return 0; 3382 + } 3383 + 3384 + static int __maybe_unused ti_sci_resume_noirq(struct device *dev) 3385 + { 3386 + struct ti_sci_info *info = dev_get_drvdata(dev); 3387 + int ret = 0; 3388 + 3389 + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_DISABLE); 3390 + if (ret) 3391 + return ret; 3392 + 3393 + return 0; 3394 + } 3395 + 3396 + static const struct dev_pm_ops ti_sci_pm_ops = { 3397 + #ifdef CONFIG_PM_SLEEP 3398 + .suspend = ti_sci_suspend, 3399 + .suspend_noirq = ti_sci_suspend_noirq, 3400 + .resume_noirq = ti_sci_resume_noirq, 3401 + #endif 3402 + }; 3403 + 3447 3404 /* Description for K2G */ 3448 3405 static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = { 3449 3406 .default_host_id = 2, ··· 3687 3494 .name = "ti-sci", 3688 3495 .of_match_table = of_match_ptr(ti_sci_of_match), 3689 3496 .suppress_bind_attrs = true, 3497 + .pm = &ti_sci_pm_ops, 3690 3498 }, 3691 3499 }; 3692 3500 module_platform_driver(ti_sci_driver);
+44 -1
drivers/firmware/ti_sci.h
··· 6 6 * The system works in a message response protocol 7 7 * See: https://software-dl.ti.com/tisci/esd/latest/index.html for details 8 8 * 9 - * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/ 9 + * Copyright (C) 2015-2024 Texas Instruments Incorporated - https://www.ti.com/ 10 10 */ 11 11 12 12 #ifndef __TI_SCI_H ··· 35 35 #define TI_SCI_MSG_SET_CLOCK_FREQ 0x010c 36 36 #define TI_SCI_MSG_QUERY_CLOCK_FREQ 0x010d 37 37 #define TI_SCI_MSG_GET_CLOCK_FREQ 0x010e 38 + 39 + /* Low Power Mode Requests */ 40 + #define TI_SCI_MSG_PREPARE_SLEEP 0x0300 41 + #define TI_SCI_MSG_SET_IO_ISOLATION 0x0307 38 42 39 43 /* Resource Management Requests */ 40 44 #define TI_SCI_MSG_GET_RESOURCE_RANGE 0x1500 ··· 569 565 struct ti_sci_msg_resp_get_clock_freq { 570 566 struct ti_sci_msg_hdr hdr; 571 567 u64 freq_hz; 568 + } __packed; 569 + 570 + /** 571 + * struct tisci_msg_req_prepare_sleep - Request for TISCI_MSG_PREPARE_SLEEP. 572 + * 573 + * @hdr TISCI header to provide ACK/NAK flags to the host. 574 + * @mode Low power mode to enter. 575 + * @ctx_lo Low 32-bits of physical pointer to address to use for context save. 576 + * @ctx_hi High 32-bits of physical pointer to address to use for context save. 577 + * @debug_flags Flags that can be set to halt the sequence during suspend or 578 + * resume to allow JTAG connection and debug. 579 + * 580 + * This message is used as the first step of entering a low power mode. It 581 + * allows configurable information, including which state to enter to be 582 + * easily shared from the application, as this is a non-secure message and 583 + * therefore can be sent by anyone. 584 + */ 585 + struct ti_sci_msg_req_prepare_sleep { 586 + struct ti_sci_msg_hdr hdr; 587 + 588 + #define TISCI_MSG_VALUE_SLEEP_MODE_DM_MANAGED 0xfd 589 + u8 mode; 590 + u32 ctx_lo; 591 + u32 ctx_hi; 592 + u32 debug_flags; 593 + } __packed; 594 + 595 + /** 596 + * struct tisci_msg_set_io_isolation_req - Request for TI_SCI_MSG_SET_IO_ISOLATION. 597 + * 598 + * @hdr: Generic header 599 + * @state: The deseared state of the IO isolation. 600 + * 601 + * This message is used to enable/disable IO isolation for low power modes. 602 + * Response is generic ACK / NACK message. 603 + */ 604 + struct ti_sci_msg_req_set_io_isolation { 605 + struct ti_sci_msg_hdr hdr; 606 + u8 state; 572 607 } __packed; 573 608 574 609 #define TI_SCI_IRQ_SECONDARY_HOST_INVALID 0xff
+4
include/linux/soc/ti/ti_sci_protocol.h
··· 195 195 u64 *current_freq); 196 196 }; 197 197 198 + /* TISCI LPM IO isolation control values */ 199 + #define TISCI_MSG_VALUE_IO_ENABLE 1 200 + #define TISCI_MSG_VALUE_IO_DISABLE 0 201 + 198 202 /** 199 203 * struct ti_sci_resource_desc - Description of TI SCI resource instance range. 200 204 * @start: Start index of the first resource range.