This patch adds code to be able to call TI_SCI_MSG_MIN_CONTEXT_RESTORE.
The context needs to be restored after booting SPL when resuming from
IO+DDR.

Signed-off-by: Markus Schneider-Pargmann <m...@baylibre.com>
---
 drivers/firmware/ti_sci.c              | 38 ++++++++++++++++++++++++++++++++++
 drivers/firmware/ti_sci.h              | 14 +++++++++++++
 include/linux/soc/ti/ti_sci_protocol.h |  9 ++++++++
 3 files changed, 61 insertions(+)

diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
index 
8013afef304dfb70ab14150ddc49d43ebebb5902..2083f3811862b23db093320d47afea919b761057
 100644
--- a/drivers/firmware/ti_sci.c
+++ b/drivers/firmware/ti_sci.c
@@ -2708,6 +2708,41 @@ static int ti_sci_cmd_change_fwl_owner(const struct 
ti_sci_handle *handle,
        return ret;
 }
 
+static int ti_sci_cmd_restore_context(const struct ti_sci_handle *handle, u64 
ctx_addr)
+{
+       struct ti_sci_msg_min_restore_context_req req;
+       struct ti_sci_msg_hdr *resp;
+       struct ti_sci_info *info;
+       struct ti_sci_xfer *xfer;
+       int ret = 0;
+
+       if (IS_ERR(handle))
+               return PTR_ERR(handle);
+       if (!handle)
+               return -EINVAL;
+
+       info = handle_to_ti_sci_info(handle);
+
+       xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_MIN_CONTEXT_RESTORE,
+                                    TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
+                                    (u32 *)&req, sizeof(req), sizeof(*resp));
+       if (IS_ERR(xfer)) {
+               ret = PTR_ERR(xfer);
+               return ret;
+       }
+
+       req.ctx_lo = (u32)(ctx_addr & 0xffffffff);
+       req.ctx_hi = (u32)(ctx_addr >> 32);
+
+       ret = ti_sci_do_xfer(info, xfer);
+       if (ret) {
+               dev_err(info->dev, "Failed restoring context %d\n", ret);
+               return ret;
+       }
+
+       return ret;
+}
+
 /*
  * ti_sci_setup_ops() - Setup the operations structures
  * @info:      pointer to TISCI pointer
@@ -2726,6 +2761,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info)
        struct ti_sci_rm_psil_ops *psilops = &ops->rm_psil_ops;
        struct ti_sci_rm_udmap_ops *udmap_ops = &ops->rm_udmap_ops;
        struct ti_sci_fwl_ops *fwl_ops = &ops->fwl_ops;
+       struct ti_sci_lpm_ops *lpm_ops = &ops->lpm_ops;
 
        bops->board_config = ti_sci_cmd_set_board_config;
        bops->board_config_rm = ti_sci_cmd_set_board_config_rm;
@@ -2793,6 +2829,8 @@ static void ti_sci_setup_ops(struct ti_sci_info *info)
 
        fw_ops->get_dm_version = ti_sci_cmd_get_dm_version;
        fw_ops->query_dm_cap = ti_sci_cmd_query_dm_cap;
+
+       lpm_ops->restore_context = ti_sci_cmd_restore_context;
 }
 
 /**
diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h
index 
ce50bf6800eb1fee70a872d8ae648b1a9582b681..e0e7c229deda20bf638a5e33f0225d8a35a01779
 100644
--- a/drivers/firmware/ti_sci.h
+++ b/drivers/firmware/ti_sci.h
@@ -45,6 +45,9 @@
 #define TI_SCI_MSG_QUERY_CLOCK_FREQ    0x010d
 #define TI_SCI_MSG_GET_CLOCK_FREQ      0x010e
 
+/* Low Power Mode Requests */
+#define TI_SCI_MSG_MIN_CONTEXT_RESTORE 0x0308
+
 /* Processor Control Messages */
 #define TISCI_MSG_PROC_REQUEST         0xc000
 #define TISCI_MSG_PROC_RELEASE         0xc001
@@ -1572,4 +1575,15 @@ struct ti_sci_msg_fwl_change_owner_info_resp {
        u16                     owner_permission_bits;
 } __packed;
 
+/**
+ * struct ti_sci_msg_min_restore_context_req - Request to restore context from 
DDR
+ *
+ * @hdr:               Generic Header
+ */
+struct ti_sci_msg_min_restore_context_req {
+       struct ti_sci_msg_hdr   hdr;
+       u32                     ctx_lo;
+       u32                     ctx_hi;
+} __packed;
+
 #endif /* __TI_SCI_H */
diff --git a/include/linux/soc/ti/ti_sci_protocol.h 
b/include/linux/soc/ti/ti_sci_protocol.h
index 
52696763ecf6bc2336e796978e1cc02896db13ab..cb9798c8546617bcea9cc0f49f19c70e1e2c16f1
 100644
--- a/include/linux/soc/ti/ti_sci_protocol.h
+++ b/include/linux/soc/ti/ti_sci_protocol.h
@@ -632,6 +632,14 @@ struct ti_sci_fwl_ops {
        int (*change_fwl_owner)(const struct ti_sci_handle *handle, struct 
ti_sci_msg_fwl_owner *owner);
 };
 
+/**
+ * struct ti_sci_lpm_ops - Low Power Mode operations
+ * @restore_context: Request restoring context from DDR.
+ */
+struct ti_sci_lpm_ops {
+       int (*restore_context)(const struct ti_sci_handle *handle, u64 
ctx_addr);
+};
+
 /**
  * struct ti_sci_ops - Function support for TI SCI
  * @board_ops: Miscellaneous operations
@@ -654,6 +662,7 @@ struct ti_sci_ops {
        struct ti_sci_rm_psil_ops rm_psil_ops;
        struct ti_sci_rm_udmap_ops rm_udmap_ops;
        struct ti_sci_fwl_ops fwl_ops;
+       struct ti_sci_lpm_ops lpm_ops;
 };
 
 /**

-- 
2.49.0

Reply via email to