@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/soc/ti/ti-msgmgr.h>
#include <linux/soc/ti/ti_sci_protocol.h>
+#include <linux/suspend.h>
#include <linux/sys_soc.h>
#include <linux/reboot.h>
@@ -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);