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 
190a1e3f5fc3713464b0cbf3ae8c35e3f185a353..f8270d2aa206412989d025502ddf297bc2d433dd
 100644
--- a/drivers/firmware/ti_sci.c
+++ b/drivers/firmware/ti_sci.c
@@ -2608,6 +2608,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
@@ -2625,6 +2660,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;
@@ -2689,6 +2725,8 @@ static void ti_sci_setup_ops(struct ti_sci_info *info)
        fwl_ops->set_fwl_region = ti_sci_cmd_set_fwl_region;
        fwl_ops->get_fwl_region = ti_sci_cmd_get_fwl_region;
        fwl_ops->change_fwl_owner = ti_sci_cmd_change_fwl_owner;
+
+       lpm_ops->restore_context = ti_sci_cmd_restore_context;
 }
 
 /**
diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h
index 
bb8bc7beeadbed5415eb4450735d488de019e9af..e8fdc652b855e9057b734c3e4f526e380d0b78bd
 100644
--- a/drivers/firmware/ti_sci.h
+++ b/drivers/firmware/ti_sci.h
@@ -43,6 +43,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
@@ -1530,4 +1533,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 
8e4c43cef3111412b5d894ad29152dde92822a64..1bf261368ca23ab03c60d25732b3e1f7d368b0ec
 100644
--- a/include/linux/soc/ti/ti_sci_protocol.h
+++ b/include/linux/soc/ti/ti_sci_protocol.h
@@ -594,6 +594,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
@@ -615,6 +623,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.47.2

Reply via email to